contract_approval.go 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755
  1. package contract
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/shopspring/decimal"
  7. "github.com/tealeg/xlsx"
  8. "hongze/hz_crm_api/controllers"
  9. "hongze/hz_crm_api/models"
  10. "hongze/hz_crm_api/models/company"
  11. "hongze/hz_crm_api/models/contract"
  12. "hongze/hz_crm_api/models/contract/request"
  13. "hongze/hz_crm_api/models/contract/response"
  14. "hongze/hz_crm_api/services"
  15. contractService "hongze/hz_crm_api/services/contract"
  16. "hongze/hz_crm_api/utils"
  17. "os"
  18. "path/filepath"
  19. "strconv"
  20. "strings"
  21. "time"
  22. )
  23. // 审批流管理
  24. type ContractApprovalController struct {
  25. controllers.BaseAuthController
  26. }
  27. // @Title 提交申请
  28. // @Description 提交申请接口
  29. // @Param ContractId query int true "合同id编号"
  30. // @Success Ret=200 申请成功
  31. // @router /approval/apply [get]
  32. func (this *ContractApprovalController) Apply() {
  33. br := new(models.BaseResponse).Init()
  34. defer func() {
  35. this.Data["json"] = br
  36. this.ServeJSON()
  37. }()
  38. sysUser := this.SysUser
  39. if sysUser == nil {
  40. br.Msg = "请登录"
  41. br.ErrMsg = "请登录,SysUser Is Empty"
  42. br.Ret = 408
  43. return
  44. }
  45. //合同id编号
  46. contractId, err := this.GetInt("ContractId")
  47. if err != nil {
  48. br.Msg = "获取合同编号失败"
  49. br.ErrMsg = "获取合同编号失败,err:" + err.Error()
  50. return
  51. }
  52. if contractId <= 0 {
  53. br.Msg = "请传入合同编号"
  54. br.ErrMsg = "请传入合同编号"
  55. return
  56. }
  57. err, errMsg := contractService.Apply(contractId)
  58. if err != nil {
  59. br.Msg = "发起审批失败!"
  60. if errMsg != "" {
  61. br.Msg = errMsg
  62. }
  63. br.ErrMsg = "发起审批失败,Err:" + err.Error()
  64. return
  65. }
  66. br.Ret = 200
  67. br.Success = true
  68. br.Msg = "申请成功"
  69. }
  70. // List
  71. // @Title 审批单列表
  72. // @Description 审批单列表接口
  73. // @Param ContractBusinessType query string false "合同业务类型,枚举值:'业务合同','代付合同',不传默认是全部"
  74. // @Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
  75. // @Param Status query string false "合同状态,枚举值:'待审批','已审批','已驳回','已撤回'"
  76. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  77. // @Param SellerId query string false "选择的销售id"
  78. // @Param Keyword query string false "搜索关键字"
  79. // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  80. // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  81. // @Param IsExport query bool false "是否导出excel,默认是false"
  82. // @Success 200 {object} response.ContractApprovalListResp
  83. // @router /approval/list [get]
  84. func (this *ContractApprovalController) List() {
  85. br := new(models.BaseResponse).Init()
  86. defer func() {
  87. this.Data["json"] = br
  88. this.ServeJSON()
  89. }()
  90. sysUser := this.SysUser
  91. if sysUser == nil {
  92. br.Msg = "请登录"
  93. br.ErrMsg = "请登录,SysUser Is Empty"
  94. br.Ret = 408
  95. return
  96. }
  97. //合同类型、产品类型、合同状态、更新时间、所选销售
  98. //关键字:合同编号、客户名称,社会信用码
  99. contractBusinessType := this.GetString("ContractBusinessType") //合同业务类型
  100. contractType := this.GetString("ContractType")
  101. status := this.GetString("Status")
  102. productId, _ := this.GetInt("ProductId")
  103. sellerIds := this.GetString("SellerId")
  104. keyword := this.GetString("Keyword")
  105. modifyStartTime := this.GetString("ModifyStartTime")
  106. modifyEndTime := this.GetString("ModifyEndTime")
  107. childCondition := ""
  108. condition := ""
  109. childPars := make([]interface{}, 0)
  110. pars := make([]interface{}, 0)
  111. productSlice := make([]int, 0) //需要下载的 产品 切片
  112. //如果不是超管或者合规,那么只能查看自己的合同
  113. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { //权益管理员
  114. condition += ` AND c.product_id = ? `
  115. pars = append(pars, 2)
  116. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN { //ficc管理员
  117. condition += ` AND c.product_id = ? `
  118. pars = append(pars, 1)
  119. } else {
  120. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  121. condition += ` AND c.seller_id = ? `
  122. pars = append(pars, sysUser.AdminId)
  123. }
  124. }
  125. //合同类型、、更新时间、所选销售
  126. //关键字:合同编号、客户名称,社会信用码
  127. if contractType != "" {
  128. condition += ` AND c.contract_type = ? `
  129. pars = append(pars, contractType)
  130. }
  131. //合同业务类型
  132. if contractBusinessType != "" {
  133. condition += ` AND c.contract_business_type = ? `
  134. pars = append(pars, contractBusinessType)
  135. }
  136. //审批状态
  137. if status != "" {
  138. //childCondition += ` AND status = ? `
  139. //childPars = append(childPars, status)
  140. if status == "已审批" {
  141. condition += ` AND c.status in ("已审批","已驳回") `
  142. } else {
  143. condition += ` AND c.status = ? `
  144. pars = append(pars, status)
  145. }
  146. } else {
  147. //childCondition += ` AND status != "已撤回" `
  148. condition += ` AND c.status not in ("已撤回","待提交") `
  149. }
  150. //产品类型
  151. if productId > 0 {
  152. condition += ` AND c.product_id = ? `
  153. pars = append(pars, productId)
  154. productSlice = append(productSlice, productId)
  155. } else {
  156. nowProductId := services.GetProductId(sysUser.RoleTypeCode)
  157. if nowProductId > 0 {
  158. productSlice = append(productSlice, nowProductId)
  159. } else {
  160. productSlice = append(productSlice, 1)
  161. productSlice = append(productSlice, 2)
  162. }
  163. }
  164. //所选销售
  165. if sellerIds != "" {
  166. condition += ` AND c.seller_id IN (` + sellerIds + `) `
  167. }
  168. //更新开始时间
  169. //更新开始时间
  170. if modifyStartTime != "" {
  171. condition += ` AND a.modify_time >= ? `
  172. pars = append(pars, modifyStartTime)
  173. }
  174. //更新结束时间
  175. if modifyEndTime != "" {
  176. condition += ` AND a.modify_time <= ? `
  177. pars = append(pars, modifyEndTime)
  178. }
  179. //关键字
  180. if keyword != "" {
  181. condition += ` AND (c.contract_code LIKE '%` + keyword + `%' OR c.company_name LIKE '%` + keyword + `%' OR c.credit_code LIKE '%` + keyword + `%' ) `
  182. }
  183. pageSize, _ := this.GetInt("PageSize")
  184. currentIndex, _ := this.GetInt("CurrentIndex")
  185. var startSize int
  186. if pageSize <= 0 {
  187. pageSize = utils.PageSize20
  188. }
  189. if currentIndex <= 0 {
  190. currentIndex = 1
  191. }
  192. startSize = paging.StartIndex(currentIndex, pageSize)
  193. //是否导出报表
  194. isExport, _ := this.GetBool("IsExport")
  195. if isExport {
  196. pageSize = 10000
  197. currentIndex = 1
  198. }
  199. total, err := contract.GetContractApprovalListCount(condition, pars)
  200. if err != nil {
  201. br.Msg = "获取失败"
  202. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  203. return
  204. }
  205. list, err := contract.GetContractApprovalList(childCondition, condition, childPars, pars, startSize, pageSize)
  206. if err != nil {
  207. br.Msg = "获取审批列表失败!"
  208. br.ErrMsg = "获取审批列表失败,Err:" + err.Error()
  209. return
  210. }
  211. if len(list) > 0 {
  212. contractApprovalIdSlice := make([]string, 0)
  213. for i := 0; i < len(list); i++ {
  214. contractApprovalIdSlice = append(contractApprovalIdSlice, strconv.Itoa(list[i].ContractApprovalId))
  215. }
  216. contractApprovalIdStr := strings.Join(contractApprovalIdSlice, ",")
  217. //获取审批流列表数据
  218. contractApprovalRecordList, err := contract.GetContractApprovalRecordList(contractApprovalIdStr, sysUser.AdminId)
  219. if err != nil {
  220. br.Msg = "获取审批流列表失败!"
  221. br.ErrMsg = "获取审批流列表失败,Err:" + err.Error()
  222. return
  223. }
  224. contractApprovalRecordMap := make(map[int]*contract.ContractApprovalRecord)
  225. for i := 0; i < len(contractApprovalRecordList); i++ {
  226. contractApprovalRecordMap[contractApprovalRecordList[i].ContractApprovalId] = contractApprovalRecordList[i]
  227. }
  228. for i := 0; i < len(list); i++ {
  229. item := list[i]
  230. list[i].StartDateStr = item.StartDate.Format(utils.FormatDate)
  231. list[i].EndDateStr = item.EndDate.Format(utils.FormatDate)
  232. list[i].CreateTimeStr = item.CreateTime.Format(utils.FormatDateTime)
  233. list[i].ModifyTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
  234. list[i].ApproveTimeStr = item.ApproveTime.Format(utils.FormatDateTime)
  235. list[i].CheckBackFileTimeStr = item.CheckBackFileTime.Format(utils.FormatDateTime)
  236. list[i].InvalidTimeStr = item.InvalidTime.Format(utils.FormatDateTime)
  237. list[i].RescindTimeStr = item.RescindTime.Format(utils.FormatDateTime)
  238. //合同操作权限
  239. var opButton contract.ContractButton
  240. var contractDetail contract.ContractDetail
  241. jsonErr := json.Unmarshal([]byte(list[i].ContractDetail), &contractDetail)
  242. if jsonErr != nil {
  243. br.Msg = "审批合同数据转换失败!"
  244. br.ErrMsg = "审批合同数据转换失败,Err:" + jsonErr.Error()
  245. return
  246. }
  247. list[i].ContractInfo = contractDetail
  248. //校验最新审批流数据
  249. if contractApprovalRecord, has := contractApprovalRecordMap[item.ContractApprovalId]; has {
  250. //审批流id
  251. list[i].ContractApprovalRecordId = contractApprovalRecord.ContractApprovalRecordId
  252. //审批时间
  253. list[i].ApproveTime = contractApprovalRecord.ApproveTime
  254. list[i].ApproveTimeStr = contractApprovalRecord.ApproveTime.Format(utils.FormatDateTime)
  255. //判断是否有操作权限
  256. list[i].Status = contractApprovalRecord.Status
  257. //判断是否处于待审批状态
  258. if contractApprovalRecord.Status == "待审批" {
  259. //如果不是审批者,那么不能审批操作
  260. if contractApprovalRecord.NodeType != "check" {
  261. continue
  262. }
  263. //如果没有指定审批人的话
  264. if contractApprovalRecord.ApproveUserId <= 0 {
  265. //判断是否与审批角色一致,如果一致,那么允许操作审批
  266. if contractApprovalRecord.ApproveRoleTypeCode == sysUser.RoleTypeCode {
  267. opButton.Approval = true
  268. }
  269. } else if contractApprovalRecord.ApproveUserId == sysUser.AdminId {
  270. //如果指定审批人就是自己的话,那么操作审批
  271. opButton.Approval = true
  272. }
  273. }
  274. }
  275. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_COMPLIANCE {
  276. if item.ContractStatus == "已审批" {
  277. opButton.CheckBackFile = true
  278. }
  279. if item.ContractStatus == "已签回" {
  280. opButton.RescindFile = true
  281. opButton.CheckBackFile = true
  282. }
  283. }
  284. //合同状态(突然说要改成展示合同状态,那就根据业务需求,改成返回:合同状态咯)
  285. list[i].Status = item.ContractStatus
  286. //合同操作权限
  287. list[i].OpButton = opButton
  288. }
  289. }
  290. page := paging.GetPaging(currentIndex, pageSize, total)
  291. //导出excel
  292. if isExport {
  293. contractApprovalListExport(this, list, productSlice, br)
  294. return
  295. }
  296. br.Ret = 200
  297. br.Success = true
  298. br.Msg = "获取成功"
  299. br.Data = response.ContractApprovalListResp{
  300. List: list,
  301. Paging: page,
  302. }
  303. }
  304. // ContractApprovalListExport 导出审批列表
  305. func contractApprovalListExport(this *ContractApprovalController, list []*contract.ContractApprovalList, productSlice []int, br *models.BaseResponse) {
  306. sysUser := this.SysUser
  307. if sysUser == nil {
  308. br.Msg = "请登录"
  309. br.ErrMsg = "请登录,SysUser Is Empty"
  310. br.Ret = 408
  311. return
  312. }
  313. fmt.Println("list len:", len(list))
  314. //获取合同套餐服务列表
  315. serviceTemplateList, err := contract.GetAllContractServiceTemplateList()
  316. if err != nil {
  317. br.Msg = "获取合同套餐服务列表失败!"
  318. br.ErrMsg = "获取合同套餐服务列表失败,Err:" + err.Error()
  319. return
  320. }
  321. templateTitleMap := make(map[int]string)
  322. for _, serviceTemplate := range serviceTemplateList {
  323. templateTitleMap[serviceTemplate.ServiceTemplateId] = serviceTemplate.Title
  324. }
  325. //业务合同的关联合同id集合
  326. businessContractIdList := make([]string, 0)
  327. //代付合同的关联合同id集合
  328. paymentOnBehalfContractIdList := make([]string, 0)
  329. //所有合同id集合(用于查询服务内容)
  330. allServiceContractIdList := make([]string, 0)
  331. //基础合同的关联合同数据
  332. contractRelationMap := make(map[int][]*contract.RelationContractList)
  333. for _, v := range list {
  334. allServiceContractIdList = append(allServiceContractIdList, fmt.Sprint(v.ContractId))
  335. switch v.ContractBusinessType {
  336. case "业务合同":
  337. businessContractIdList = append(businessContractIdList, fmt.Sprint(v.ContractId))
  338. case "代付合同":
  339. paymentOnBehalfContractIdList = append(paymentOnBehalfContractIdList, fmt.Sprint(v.ContractId))
  340. }
  341. }
  342. //业务合同的关联合同
  343. if len(businessContractIdList) > 0 {
  344. contractIdStr := strings.Join(businessContractIdList, ",")
  345. businessContractList, err := contract.GetContractRelationListByRelationContractIds(contractIdStr)
  346. if err != nil {
  347. br.Msg = "获取失败"
  348. br.ErrMsg = "获取业务关联合同失败,Err:" + err.Error()
  349. return
  350. }
  351. for _, v := range businessContractList {
  352. //代付合同id
  353. allServiceContractIdList = append(allServiceContractIdList, fmt.Sprint(v.PaymentOnBehalfContractId))
  354. if _, ok := contractRelationMap[v.ContractId]; ok {
  355. contractRelationMap[v.ContractId] = append(contractRelationMap[v.ContractId], v)
  356. } else {
  357. tmpList := make([]*contract.RelationContractList, 0)
  358. contractRelationMap[v.ContractId] = append(tmpList, v)
  359. }
  360. }
  361. }
  362. //代付合同的关联合同
  363. if len(paymentOnBehalfContractIdList) > 0 {
  364. paymentOnBehalfContractIdStr := strings.Join(paymentOnBehalfContractIdList, ",")
  365. paymentOnBehalfContractList, err := contract.GetContractRelationListByPaymentOnBehalfContractIds(paymentOnBehalfContractIdStr)
  366. if err != nil {
  367. br.Msg = "获取失败"
  368. br.ErrMsg = "获取代付关联合同失败,Err:" + err.Error()
  369. return
  370. }
  371. for _, v := range paymentOnBehalfContractList {
  372. //业务合同id
  373. allServiceContractIdList = append(allServiceContractIdList, fmt.Sprint(v.ContractId))
  374. if _, ok := contractRelationMap[v.PaymentOnBehalfContractId]; ok {
  375. contractRelationMap[v.PaymentOnBehalfContractId] = append(contractRelationMap[v.PaymentOnBehalfContractId], v)
  376. } else {
  377. tmpList := make([]*contract.RelationContractList, 0)
  378. contractRelationMap[v.PaymentOnBehalfContractId] = append(tmpList, v)
  379. }
  380. }
  381. }
  382. //获取合同详情
  383. serviceListMap := make(map[int][]*contract.ContractServiceAndDetail, 0)
  384. if len(allServiceContractIdList) > 0 {
  385. allRelationIdStr := strings.Join(allServiceContractIdList, ",")
  386. tmpServiceList, err := contract.GetContractServiceAndDetailListByIds(allRelationIdStr)
  387. if err != nil {
  388. br.Msg = "获取失败"
  389. br.ErrMsg = "获取关联合同服务详情失败,Err:" + err.Error()
  390. return
  391. }
  392. allContractServiceIdList := make([]string, 0)
  393. serviceDetailListMap := make(map[int][]*contract.ContractServiceDetail, 0)
  394. for _, service := range tmpServiceList {
  395. if service.HasDetail == "是" {
  396. allContractServiceIdList = append(allContractServiceIdList, strconv.Itoa(service.ContractServiceId))
  397. }
  398. }
  399. if len(allContractServiceIdList) > 0 {
  400. allContractServiceIdStr := strings.Join(allContractServiceIdList, ",")
  401. list, detailErr := contract.GetContractServiceDetailListByServiceIds(allContractServiceIdStr)
  402. if detailErr != nil {
  403. br.Msg = "获取失败"
  404. br.ErrMsg = "查找合同服务详情异常,Err:" + err.Error()
  405. return
  406. }
  407. for _, v := range list {
  408. if _, ok := serviceDetailListMap[v.ContractServiceId]; ok {
  409. serviceDetailListMap[v.ContractServiceId] = append(serviceDetailListMap[v.ContractServiceId], v)
  410. } else {
  411. tmpList := make([]*contract.ContractServiceDetail, 0)
  412. serviceDetailListMap[v.ContractServiceId] = append(tmpList, v)
  413. }
  414. }
  415. }
  416. for _, service := range tmpServiceList {
  417. if service.HasDetail == "是" {
  418. if serviceDetailList, ok := serviceDetailListMap[service.ContractServiceId]; ok {
  419. service.DetailList = serviceDetailList
  420. }
  421. //套餐名称
  422. if title, ok := templateTitleMap[service.ServiceTemplateId]; ok {
  423. service.Title = title
  424. }
  425. }
  426. //服务列表
  427. if _, ok := serviceListMap[service.ContractId]; ok {
  428. serviceListMap[service.ContractId] = append(serviceListMap[service.ContractId], service)
  429. } else {
  430. tmpList := make([]*contract.ContractServiceAndDetail, 0)
  431. serviceListMap[service.ContractId] = append(tmpList, service)
  432. }
  433. }
  434. }
  435. //生成excel文件
  436. dir, err := os.Executable()
  437. exPath := filepath.Dir(dir)
  438. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  439. xlsxFile := xlsx.NewFile()
  440. if err != nil {
  441. br.Msg = "生成文件失败"
  442. br.ErrMsg = "生成文件失败"
  443. return
  444. }
  445. //设置默认字体和文字大小
  446. xlsx.SetDefaultFont(12, "宋体")
  447. //定义边框样式
  448. border := xlsx.NewBorder("thin", "thin", "thin", "thin")
  449. //定义文字排版样式
  450. alignment := xlsx.Alignment{
  451. Horizontal: "center",
  452. Vertical: "center",
  453. WrapText: true,
  454. }
  455. //普通样式
  456. style := xlsx.NewStyle()
  457. style.Alignment = alignment
  458. style.ApplyAlignment = true
  459. style.Border = *border
  460. //标红文字,便于查看哪些产品被勾选
  461. redStyle := xlsx.NewStyle()
  462. redStyle.Alignment = alignment
  463. redStyle.ApplyAlignment = true
  464. redStyle.Font.Color = "ff0000"
  465. //定义底色需要标黄的 单元格颜色
  466. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  467. redStyle.Fill = redFill
  468. redStyle.Border = *border
  469. //标题样式
  470. titleStyle := xlsx.NewStyle()
  471. titleFont := xlsx.NewFont(14, "宋体")
  472. titleFont.Bold = true
  473. titleStyle.Font = *titleFont
  474. titleStyle.Alignment = alignment
  475. titleStyle.Border = *border
  476. //titleStyle.ApplyAlignment = true
  477. //表头
  478. headerStyle := xlsx.NewStyle()
  479. headerFont := xlsx.NewFont(12, "宋体")
  480. headerFont.Bold = true
  481. headerStyle.Font = *headerFont
  482. headerStyle.Alignment = alignment
  483. headerStyle.ApplyAlignment = true
  484. headerStyle.Border = *border
  485. defer func() {
  486. os.Remove(downLoadnFilePath)
  487. }()
  488. //遍历所拥有的的产品权限,然后插入到对应的sheet表单中
  489. for pidIndex := 0; pidIndex < len(productSlice); pidIndex++ {
  490. productId := productSlice[pidIndex]
  491. //表单名称
  492. sheetName := "合同数据"
  493. switch productId {
  494. case 1:
  495. sheetName = "ficc合同信息"
  496. case 2:
  497. sheetName = "权益合同信息"
  498. }
  499. //新增一个sheet表单
  500. sheel, err := xlsxFile.AddSheet(sheetName)
  501. if err != nil {
  502. br.Msg = "新增Sheet失败"
  503. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  504. return
  505. }
  506. //设置列宽
  507. sheel.SetColWidth(0, 0, 28)
  508. sheel.SetColWidth(1, 1, 30)
  509. sheel.SetColWidth(2, 2, 18)
  510. sheel.SetColWidth(3, 3, 18)
  511. sheel.SetColWidth(4, 4, 35)
  512. sheel.SetColWidth(5, 6, 20)
  513. sheel.SetColWidth(7, 7, 40)
  514. //合同信息列
  515. endContractInfoColIndex := 9
  516. sheel.SetColWidth(8, 8, 40)
  517. sheel.SetColWidth(9, 9, 40)
  518. //权限列
  519. sheel.SetColWidth(endContractInfoColIndex, endContractInfoColIndex+18, 30)
  520. //标题行
  521. titleRow := sheel.AddRow()
  522. titleRow.SetHeight(30)
  523. //合同信息列
  524. titleCell := titleRow.AddCell()
  525. titleCell.HMerge = 7 //向右合并列数,不包括自身列
  526. //遍历去添加需要合并的列
  527. for i := 0; i < 7; i++ {
  528. titleRow.AddCell()
  529. }
  530. //报表标题名称
  531. titleCell.SetValue("合同信息")
  532. titleCell.SetStyle(titleStyle)
  533. startI := 8
  534. customStartCellI := 8
  535. serviceSlice := make([]string, 0)
  536. serviceCellMap := make(map[string]int)
  537. //获取所有套餐列表
  538. {
  539. serviceList, err := getServiceTemplateList(productId)
  540. if err != nil {
  541. br.Msg = "查询套餐类型失败"
  542. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  543. return
  544. }
  545. for i := 0; i < len(serviceList); i++ {
  546. //需要向右合并添加的列数
  547. addCellNum := 0
  548. item := serviceList[i]
  549. //套餐服务列
  550. servicesCell := titleRow.AddCell()
  551. //套餐名称
  552. servicesCell.SetValue(item.Title)
  553. servicesCell.SetStyle(titleStyle)
  554. //ficc小套餐
  555. if item.ServiceTemplateId == 2 {
  556. productPermission := make(map[int]string)
  557. productPermission[1] = "每日宏观商品复盘"
  558. productPermission[2] = "能化专栏《化里化外》"
  559. productPermission[3] = "股债日评"
  560. productPermission[4] = "黑色专栏《知白守黑》"
  561. productPermission[5] = "有色专栏《有声有色》"
  562. for id, name := range productPermission {
  563. key := fmt.Sprint(item.ServiceTemplateId, "_product_permission_", id)
  564. serviceCellMap[key] = startI
  565. serviceSlice = append(serviceSlice, name)
  566. startI++
  567. addCellNum++
  568. }
  569. permissionList := make([]*company.PermissionSetItem, 0)
  570. allPermissions, permissionMap, e := services.GetBaseFiccPermissionSetItem()
  571. if e != nil {
  572. br.Msg = "查询基础权限失败"
  573. br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
  574. return
  575. }
  576. //遍历获取
  577. for _, v := range allPermissions {
  578. if v.ParentId == 0 {
  579. items, ok := permissionMap[v.ChartPermissionId]
  580. if ok {
  581. permissionList = append(permissionList, items...)
  582. }
  583. }
  584. }
  585. /*for _, v := range utils.PermissionFiccClassifyArr {
  586. items, err := company.GetPermissionSetItems(1, v)
  587. if err != nil {
  588. br.Msg = "获取失败"
  589. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  590. return
  591. }
  592. permissionList = append(permissionList, items...)
  593. }*/
  594. //权限列表
  595. for j := 0; j < len(permissionList); j++ {
  596. key := fmt.Sprint(item.ServiceTemplateId, "_permission_", permissionList[j].ChartPermissionId)
  597. serviceCellMap[key] = startI
  598. serviceSlice = append(serviceSlice, permissionList[j].PermissionName)
  599. startI++
  600. addCellNum++
  601. }
  602. //因为自己本身有一列了,所以在最后增加列的时候,需要减去自身列
  603. addCellNum = addCellNum - 1
  604. if addCellNum > 0 {
  605. for tmpAddCellNum := 0; tmpAddCellNum < addCellNum; tmpAddCellNum++ {
  606. titleRow.AddCell()
  607. }
  608. servicesCell.HMerge = addCellNum //向右合并列数,不包括自身列
  609. }
  610. continue
  611. } else {
  612. if item.Children != nil && len(item.Children) > 0 {
  613. for j := 0; j < len(item.Children); j++ {
  614. key := fmt.Sprint("service_template_", item.Children[j].ServiceTemplateId)
  615. serviceCellMap[key] = startI
  616. serviceSlice = append(serviceSlice, item.Children[j].Title)
  617. startI++
  618. addCellNum++
  619. }
  620. //因为自己本身有一列了,所以在最后增加列的时候,需要减去自身列
  621. addCellNum = addCellNum - 1
  622. if addCellNum > 0 {
  623. for tmpAddCellNum := 0; tmpAddCellNum < addCellNum; tmpAddCellNum++ {
  624. titleRow.AddCell()
  625. }
  626. servicesCell.HMerge = addCellNum //向右合并列数,不包括自身列
  627. }
  628. } else {
  629. key := fmt.Sprint("service_template_", item.ServiceTemplateId)
  630. serviceCellMap[key] = startI
  631. serviceSlice = append(serviceSlice, item.Title)
  632. startI++
  633. }
  634. }
  635. }
  636. }
  637. //表头
  638. headerRow := sheel.AddRow()
  639. headerRow.SetHeight(24)
  640. //合同基础信息
  641. {
  642. codeHeaderCell := headerRow.AddCell()
  643. codeHeaderCell.SetValue("合同编号")
  644. codeHeaderCell.SetStyle(headerStyle)
  645. companyHeaderCell := headerRow.AddCell()
  646. companyHeaderCell.SetValue("客户名称")
  647. companyHeaderCell.SetStyle(headerStyle)
  648. typeHeaderCell := headerRow.AddCell()
  649. typeHeaderCell.SetValue("合同类型")
  650. typeHeaderCell.SetStyle(headerStyle)
  651. priceHeaderCell := headerRow.AddCell()
  652. priceHeaderCell.SetValue("合同金额")
  653. priceHeaderCell.SetStyle(headerStyle)
  654. dateHeaderCell := headerRow.AddCell()
  655. dateHeaderCell.SetValue("合同有效期")
  656. dateHeaderCell.SetStyle(headerStyle)
  657. sellerHeaderCell := headerRow.AddCell()
  658. sellerHeaderCell.SetValue("销售")
  659. sellerHeaderCell.SetStyle(headerStyle)
  660. payHeaderCell := headerRow.AddCell()
  661. payHeaderCell.SetValue("付款方")
  662. payHeaderCell.SetStyle(headerStyle)
  663. useHeaderCell := headerRow.AddCell()
  664. useHeaderCell.SetValue("实际使用方")
  665. useHeaderCell.SetStyle(headerStyle)
  666. statusHeaderCell := headerRow.AddCell()
  667. statusHeaderCell.SetValue("合同状态")
  668. statusHeaderCell.SetStyle(headerStyle)
  669. remarkHeaderCell := headerRow.AddCell()
  670. remarkHeaderCell.SetValue("备注")
  671. remarkHeaderCell.SetStyle(headerStyle)
  672. }
  673. //添加服务套餐名称
  674. for _, service := range serviceSlice {
  675. cell := headerRow.AddCell()
  676. cell.SetValue(service)
  677. cell.SetStyle(headerStyle)
  678. }
  679. for _, v := range list {
  680. //如果当前合同不是该产品
  681. if v.ProductId != productId {
  682. continue
  683. }
  684. dataRow := sheel.AddRow()
  685. dataRow.SetHeight(24)
  686. //合同基础信息
  687. {
  688. codeCell := dataRow.AddCell()
  689. codeCell.SetValue(v.ContractCode)
  690. codeCell.SetStyle(style)
  691. companyCell := dataRow.AddCell()
  692. companyCell.SetValue(v.CompanyName)
  693. companyCell.SetStyle(style)
  694. typeCell := dataRow.AddCell()
  695. typeCell.SetValue(v.ContractType)
  696. typeCell.SetStyle(style)
  697. priceCell := dataRow.AddCell()
  698. priceCell.SetValue(v.Price)
  699. priceCell.SetStyle(style)
  700. dateCell := dataRow.AddCell()
  701. dateCell.SetValue(fmt.Sprint(v.StartDate.Format(utils.FormatDate), " 至 ", v.EndDate.Format(utils.FormatDate)))
  702. dateCell.SetStyle(style)
  703. sellerCell := dataRow.AddCell()
  704. sellerCell.SetValue(v.SellerName)
  705. sellerCell.SetStyle(style)
  706. //付款方
  707. payStr := v.PayChannel
  708. payCell := dataRow.AddCell()
  709. if v.ContractBusinessType == "业务合同" {
  710. if relationContractList, ok := contractRelationMap[v.ContractId]; ok {
  711. payCompanyNameList := make([]string, 0)
  712. for _, relationContract := range relationContractList {
  713. payCompanyNameList = append(payCompanyNameList, relationContract.CompanyName)
  714. }
  715. payStr = strings.Join(payCompanyNameList, ",")
  716. }
  717. } else {
  718. payStr = v.CompanyName
  719. }
  720. payCell.SetValue(payStr)
  721. payCell.SetStyle(style)
  722. //使用方
  723. useStr := ``
  724. useCell := dataRow.AddCell()
  725. if v.ContractBusinessType == "代付合同" {
  726. if relationContractList, ok := contractRelationMap[v.ContractId]; ok {
  727. payCompanyNameList := make([]string, 0)
  728. for _, relationContract := range relationContractList {
  729. payCompanyNameList = append(payCompanyNameList, relationContract.CompanyName)
  730. }
  731. useStr = strings.Join(payCompanyNameList, ",")
  732. }
  733. } else {
  734. useStr = v.CompanyName
  735. }
  736. useCell.SetValue(useStr)
  737. useCell.SetStyle(style)
  738. statusCell := dataRow.AddCell()
  739. statusCell.SetValue(v.Status)
  740. statusCell.SetStyle(style)
  741. //备注:该字段由三部分拼接:服务内容中的补充内容+赠送时间+优惠金额
  742. //补充内容直接取该字段内容;
  743. //赠送时间以年为单位,超过整年的月份作为赠送月份,如14个月即为赠送2个月;
  744. //优惠金额等于原价-优惠后价格=优惠价格
  745. //补充内容
  746. var remark string
  747. if v.Remark != "" {
  748. remark += "补充内容:" + v.Remark
  749. }
  750. //赠送时间
  751. //合同结束日期与合同开始日期的时间差(小时差)
  752. newDecimal := decimal.NewFromFloat(v.EndDate.Sub(v.StartDate).Hours())
  753. //分母为365天 * 24 小时
  754. newDecimal2 := decimal.NewFromInt(24 * 365)
  755. //计算出来相差多少年,保留一位小数(四舍五入)
  756. numYearDecimal := newDecimal.Div(newDecimal2).Round(1).Mul(decimal.NewFromInt(10))
  757. //如果大于1年,那么才去判断是否赠送
  758. numYear, _ := numYearDecimal.Float64()
  759. if numYear > 10 {
  760. //获取多出来的整数年数据
  761. numYearDecimal = numYearDecimal.Mod(decimal.NewFromInt(10)).Div(decimal.NewFromInt(10))
  762. //计算赠送出来的月份
  763. numMonthDecimal := numYearDecimal.Mul(decimal.NewFromInt(12)).Round(0)
  764. numMonth, _ := numMonthDecimal.Float64()
  765. if numMonth > 0 {
  766. if remark != "" {
  767. remark += ";"
  768. }
  769. remark += "赠送时间为:" + numMonthDecimal.String() + "个月"
  770. }
  771. }
  772. //优惠金额
  773. if v.OriginalPrice > v.Price {
  774. differencePrice := v.OriginalPrice - v.Price
  775. differencePriceDecimal := decimal.NewFromFloat(differencePrice)
  776. if remark != "" {
  777. remark += ";"
  778. }
  779. remark += "优惠金额:" + differencePriceDecimal.String() + "元。"
  780. }
  781. remarkCell := dataRow.AddCell()
  782. remarkCell.SetValue(remark)
  783. remarkCell.SetStyle(style)
  784. }
  785. //服务套餐
  786. {
  787. cellServiceMap := make(map[int]string)
  788. for _, cellI := range serviceCellMap {
  789. cellServiceMap[cellI] = "否"
  790. }
  791. //如果没有服务那么就进入下一个循环
  792. tmpService, ok := serviceListMap[v.ContractId]
  793. if !ok {
  794. continue
  795. }
  796. if tmpService != nil && len(tmpService) > 0 {
  797. permissionValues := []string{
  798. "FICC周报", "商品双周报+线上电话会讨论会<br/>(由弘则的研究员主持线上讨论)", "数据点评", "深度月报:包括宏观经济月报和下游草根调研月报+电话会讨论会<br/>(由弘则的研究员主持线上讨论)",
  799. }
  800. for _, item := range tmpService {
  801. //ficc小套餐
  802. if item.ServiceTemplateId == 2 {
  803. for _, detail := range item.DetailList {
  804. var tableCel request.AddContractServiceDetailReq
  805. tmpErr := json.Unmarshal([]byte(detail.Col1), &tableCel)
  806. if tmpErr != nil {
  807. err = tmpErr
  808. return
  809. }
  810. if tableCel.Value == "商品复盘" {
  811. var tableCel2 request.AddContractServiceDetailReq
  812. //获取品种列数据
  813. tmpErr := contractService.GetProductCelData(*detail, &tableCel2)
  814. if tmpErr != nil {
  815. err = tmpErr
  816. return
  817. }
  818. //tableCel2.Tag
  819. for _, serviceId := range tableCel2.ValueId {
  820. key := fmt.Sprint(item.ServiceTemplateId, "_product_permission_", serviceId)
  821. if cellI, ok := serviceCellMap[key]; ok {
  822. cellServiceMap[cellI] = "是"
  823. }
  824. }
  825. } else if strings.Contains(strings.Join(permissionValues, ","), tableCel.Value) {
  826. //获取品种列数据
  827. var tableCel2 request.AddContractServiceDetailReq
  828. tmpErr := contractService.GetProductCelData(*detail, &tableCel2)
  829. if tmpErr != nil {
  830. err = tmpErr
  831. return
  832. }
  833. for _, serviceId := range tableCel2.ValueId {
  834. key := fmt.Sprint(item.ServiceTemplateId, "_permission_", serviceId)
  835. if cellI, ok := serviceCellMap[key]; ok {
  836. cellServiceMap[cellI] = "是"
  837. }
  838. }
  839. }
  840. }
  841. } else {
  842. key := fmt.Sprint("service_template_", item.ServiceTemplateId)
  843. if cellI, ok := serviceCellMap[key]; ok {
  844. cellServiceMap[cellI] = "是"
  845. }
  846. }
  847. }
  848. }
  849. //遍历所有套餐
  850. for tmpStartCellI := customStartCellI; tmpStartCellI < startI; tmpStartCellI++ {
  851. servicesCell := dataRow.AddCell()
  852. cellValue, ok := cellServiceMap[tmpStartCellI]
  853. if ok == false {
  854. cellValue = "否"
  855. }
  856. servicesCell.SetValue(cellValue)
  857. if cellValue == "是" { //勾选了话,标红处理
  858. servicesCell.SetStyle(redStyle)
  859. } else {
  860. servicesCell.SetStyle(style)
  861. }
  862. }
  863. }
  864. }
  865. }
  866. err = xlsxFile.Save(downLoadnFilePath)
  867. if err != nil {
  868. br.Msg = "保存文件失败"
  869. br.ErrMsg = "保存文件失败"
  870. return
  871. }
  872. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  873. downloadFileName := "合同列表" + randStr + ".xlsx"
  874. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  875. br.Ret = 200
  876. br.Success = true
  877. br.Msg = "导出成功"
  878. }
  879. // @Title 合同列表数据导出
  880. // @Description 合同列表数据导出接口
  881. // @Description 合同列表接口
  882. // @Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
  883. // @Param ContractStatus query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废'"
  884. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  885. // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  886. // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  887. // @Param SellerId query string false "选择的销售id"
  888. // @Param Keyword query string false "搜索关键字"
  889. // @Success 200 {object} response.ContractListResp
  890. // @router /approval/export [get]
  891. func (this *ContractApprovalController) Export() {
  892. br := new(models.BaseResponse).Init()
  893. defer func() {
  894. this.Data["json"] = br
  895. this.ServeJSON()
  896. }()
  897. sysUser := this.SysUser
  898. if sysUser == nil {
  899. br.Msg = "请登录"
  900. br.ErrMsg = "请登录,SysUser Is Empty"
  901. br.Ret = 408
  902. return
  903. }
  904. contractType := this.GetString("ContractType")
  905. contractStatus := this.GetString("ContractStatus")
  906. productId, _ := this.GetInt("ProductId")
  907. modifyStartTime := this.GetString("ModifyStartTime")
  908. modifyEndTime := this.GetString("ModifyEndTime")
  909. sellerIds := this.GetString("SellerId")
  910. keyword := this.GetString("Keyword")
  911. condition := ""
  912. pars := make([]interface{}, 0)
  913. //如果不是超管或者合规,那么只能查看自己的合同
  914. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  915. condition += ` AND product_id = 1 AND status not in ("待提交","已撤回") `
  916. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  917. condition += ` AND product_id = 2 AND status not in ("待提交","已撤回") `
  918. } else {
  919. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  920. condition += ` AND seller_id = ? `
  921. pars = append(pars, sysUser.AdminId)
  922. }
  923. }
  924. //需要下载的 产品 切片
  925. productSlice := make([]int, 0)
  926. //合同类型、、更新时间、所选销售
  927. //关键字:合同编号、客户名称,社会信用码
  928. if contractType != "" {
  929. condition += ` AND contract_type = ? `
  930. pars = append(pars, contractType)
  931. }
  932. //合同状态
  933. if contractStatus != "" {
  934. if contractStatus == "已审批" {
  935. condition += ` AND status in ("已审批","已驳回") `
  936. } else {
  937. condition += ` AND status = ? `
  938. pars = append(pars, contractStatus)
  939. }
  940. } else {
  941. //condition += ` AND status != "已撤回" `
  942. condition += ` AND status not in ("已撤回","待提交") `
  943. }
  944. //产品类型
  945. if productId > 0 {
  946. condition += ` AND product_id = ? `
  947. pars = append(pars, productId)
  948. productSlice = append(productSlice, productId)
  949. } else {
  950. nowProductId := services.GetProductId(sysUser.RoleTypeCode)
  951. if nowProductId > 0 {
  952. productSlice = append(productSlice, nowProductId)
  953. } else {
  954. productSlice = append(productSlice, 1)
  955. productSlice = append(productSlice, 2)
  956. }
  957. }
  958. //所选销售
  959. if sellerIds != "" {
  960. condition += ` AND seller_id IN (` + sellerIds + `) `
  961. }
  962. //更新开始时间
  963. if modifyStartTime != "" {
  964. condition += ` AND modify_time >= ? `
  965. pars = append(pars, modifyStartTime)
  966. }
  967. //更新结束时间
  968. if modifyEndTime != "" {
  969. condition += ` AND modify_time <= ? `
  970. pars = append(pars, modifyEndTime)
  971. }
  972. //关键字
  973. if keyword != "" {
  974. condition += ` AND (contract_code LIKE '%` + keyword + `%' OR company_name LIKE '%` + keyword + `%' OR credit_code LIKE '%` + keyword + `%' ) `
  975. }
  976. //取 一万 条合同数据
  977. list, err := contract.GetContractList(condition, "", pars, 0, 10000)
  978. if err != nil {
  979. br.Msg = "获取合同列表失败!"
  980. br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
  981. return
  982. }
  983. //获取合同套餐服务列表
  984. serviceTemplateList, err := contract.GetAllContractServiceTemplateList()
  985. if err != nil {
  986. br.Msg = "获取合同套餐服务列表失败!"
  987. br.ErrMsg = "获取合同套餐服务列表失败,Err:" + err.Error()
  988. return
  989. }
  990. templateTitleMap := make(map[int]string)
  991. for _, serviceTemplate := range serviceTemplateList {
  992. templateTitleMap[serviceTemplate.ServiceTemplateId] = serviceTemplate.Title
  993. }
  994. for i := 0; i < len(list); i++ {
  995. item := list[i]
  996. list[i].StartDateStr = item.StartDate.Format(utils.FormatDate)
  997. list[i].EndDateStr = item.EndDate.Format(utils.FormatDate)
  998. list[i].CreateTimeStr = item.CreateTime.Format(utils.FormatDateTime)
  999. list[i].ModifyTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
  1000. //服务列表
  1001. serviceList, err := contract.GetContractServiceAndDetailList(item.ContractId)
  1002. if err != nil {
  1003. br.Msg = "获取失败"
  1004. br.ErrMsg = "查找合同服务异常,Err:" + err.Error()
  1005. return
  1006. }
  1007. for i := 0; len(serviceList) > i; i++ {
  1008. if serviceList[i].HasDetail == "是" {
  1009. list, detailErr := contract.GetContractServiceDetailListByServiceId(serviceList[i].ContractServiceId)
  1010. if detailErr != nil {
  1011. br.Msg = "获取失败"
  1012. br.ErrMsg = "查找合同服务详情异常,Err:" + err.Error()
  1013. return
  1014. }
  1015. //套餐名称
  1016. serviceList[i].DetailList = list
  1017. if title, ok := templateTitleMap[serviceList[i].ServiceTemplateId]; ok {
  1018. serviceList[i].Title = title
  1019. }
  1020. }
  1021. }
  1022. list[i].Service = serviceList
  1023. }
  1024. //生成excel文件
  1025. dir, err := os.Executable()
  1026. exPath := filepath.Dir(dir)
  1027. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1028. xlsxFile := xlsx.NewFile()
  1029. if err != nil {
  1030. br.Msg = "生成文件失败"
  1031. br.ErrMsg = "生成文件失败"
  1032. return
  1033. }
  1034. //设置默认字体和文字大小
  1035. xlsx.SetDefaultFont(12, "宋体")
  1036. //定义边框样式
  1037. border := xlsx.NewBorder("thin", "thin", "thin", "thin")
  1038. //定义文字排版样式
  1039. alignment := xlsx.Alignment{
  1040. Horizontal: "center",
  1041. Vertical: "center",
  1042. WrapText: true,
  1043. }
  1044. //普通样式
  1045. style := xlsx.NewStyle()
  1046. style.Alignment = alignment
  1047. style.ApplyAlignment = true
  1048. style.Border = *border
  1049. //标红文字,便于查看哪些产品被勾选
  1050. redStyle := xlsx.NewStyle()
  1051. redStyle.Alignment = alignment
  1052. redStyle.ApplyAlignment = true
  1053. redStyle.Font.Color = "ff0000"
  1054. //定义底色需要标黄的 单元格颜色
  1055. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  1056. redStyle.Fill = redFill
  1057. redStyle.Border = *border
  1058. //标题样式
  1059. titleStyle := xlsx.NewStyle()
  1060. titleFont := xlsx.NewFont(14, "宋体")
  1061. titleFont.Bold = true
  1062. titleStyle.Font = *titleFont
  1063. titleStyle.Alignment = alignment
  1064. titleStyle.Border = *border
  1065. //titleStyle.ApplyAlignment = true
  1066. //表头
  1067. headerStyle := xlsx.NewStyle()
  1068. headerFont := xlsx.NewFont(12, "宋体")
  1069. headerFont.Bold = true
  1070. headerStyle.Font = *headerFont
  1071. headerStyle.Alignment = alignment
  1072. headerStyle.ApplyAlignment = true
  1073. headerStyle.Border = *border
  1074. defer func() {
  1075. os.Remove(downLoadnFilePath)
  1076. }()
  1077. //遍历所拥有的的产品权限,然后插入到对应的sheet表单中
  1078. for pidIndex := 0; pidIndex < len(productSlice); pidIndex++ {
  1079. productId = productSlice[pidIndex]
  1080. //表单名称
  1081. sheetName := "合同数据"
  1082. switch productId {
  1083. case 1:
  1084. sheetName = "ficc合同信息"
  1085. case 2:
  1086. sheetName = "权益合同信息"
  1087. }
  1088. //新增一个sheet表单
  1089. sheel, err := xlsxFile.AddSheet(sheetName)
  1090. if err != nil {
  1091. br.Msg = "新增Sheet失败"
  1092. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1093. return
  1094. }
  1095. //设置列宽
  1096. sheel.SetColWidth(0, 0, 28)
  1097. sheel.SetColWidth(1, 1, 30)
  1098. sheel.SetColWidth(2, 2, 18)
  1099. sheel.SetColWidth(3, 3, 18)
  1100. sheel.SetColWidth(4, 4, 35)
  1101. sheel.SetColWidth(5, 6, 20)
  1102. sheel.SetColWidth(7, 7, 40)
  1103. sheel.SetColWidth(7, 35, 30)
  1104. //标题行
  1105. titleRow := sheel.AddRow()
  1106. titleRow.SetHeight(30)
  1107. //合同信息列
  1108. titleCell := titleRow.AddCell()
  1109. titleCell.HMerge = 7 //向右合并列数,不包括自身列
  1110. //遍历去添加需要合并的列
  1111. for i := 0; i < 7; i++ {
  1112. titleRow.AddCell()
  1113. }
  1114. //报表标题名称
  1115. titleCell.SetValue("合同信息")
  1116. titleCell.SetStyle(titleStyle)
  1117. startI := 8
  1118. customStartCellI := 8
  1119. serviceSlice := make([]string, 0)
  1120. serviceCellMap := make(map[string]int)
  1121. //获取所有套餐列表
  1122. {
  1123. serviceList, err := getServiceTemplateList(productId)
  1124. if err != nil {
  1125. br.Msg = "查询套餐类型失败"
  1126. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1127. return
  1128. }
  1129. for i := 0; i < len(serviceList); i++ {
  1130. //需要向右合并添加的列数
  1131. addCellNum := 0
  1132. item := serviceList[i]
  1133. //套餐服务列
  1134. servicesCell := titleRow.AddCell()
  1135. //套餐名称
  1136. servicesCell.SetValue(item.Title)
  1137. servicesCell.SetStyle(titleStyle)
  1138. //ficc小套餐
  1139. if item.ServiceTemplateId == 2 {
  1140. productPermission := make(map[int]string)
  1141. productPermission[1] = "每日宏观商品复盘"
  1142. productPermission[2] = "能化专栏《化里化外》"
  1143. productPermission[3] = "股债日评"
  1144. productPermission[4] = "黑色专栏《知白守黑》"
  1145. productPermission[5] = "有色专栏《有声有色》"
  1146. for id, name := range productPermission {
  1147. key := fmt.Sprint(item.ServiceTemplateId, "_product_permission_", id)
  1148. serviceCellMap[key] = startI
  1149. serviceSlice = append(serviceSlice, name)
  1150. startI++
  1151. addCellNum++
  1152. }
  1153. permissionList := make([]*company.PermissionSetItem, 0)
  1154. allPermissions, permissionMap, e := services.GetBaseFiccPermissionSetItem()
  1155. if e != nil {
  1156. br.Msg = "查询基础权限失败"
  1157. br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
  1158. return
  1159. }
  1160. //遍历获取
  1161. for _, v := range allPermissions {
  1162. if v.ParentId == 0 {
  1163. items, ok := permissionMap[v.ChartPermissionId]
  1164. if ok {
  1165. permissionList = append(permissionList, items...)
  1166. }
  1167. }
  1168. }
  1169. /*for _, v := range utils.PermissionFiccClassifyArr {
  1170. items, err := company.GetPermissionSetItems(1, v)
  1171. if err != nil {
  1172. br.Msg = "获取失败"
  1173. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  1174. return
  1175. }
  1176. permissionList = append(permissionList, items...)
  1177. }
  1178. */
  1179. //权限列表
  1180. for j := 0; j < len(permissionList); j++ {
  1181. key := fmt.Sprint(item.ServiceTemplateId, "_permission_", permissionList[j].ChartPermissionId)
  1182. serviceCellMap[key] = startI
  1183. serviceSlice = append(serviceSlice, permissionList[j].PermissionName)
  1184. startI++
  1185. addCellNum++
  1186. }
  1187. //因为自己本身有一列了,所以在最后增加列的时候,需要减去自身列
  1188. addCellNum = addCellNum - 1
  1189. if addCellNum > 0 {
  1190. for tmpAddCellNum := 0; tmpAddCellNum < addCellNum; tmpAddCellNum++ {
  1191. titleRow.AddCell()
  1192. }
  1193. servicesCell.HMerge = addCellNum //向右合并列数,不包括自身列
  1194. }
  1195. continue
  1196. } else {
  1197. if item.Children != nil && len(item.Children) > 0 {
  1198. for j := 0; j < len(item.Children); j++ {
  1199. key := fmt.Sprint("service_template_", item.Children[j].ServiceTemplateId)
  1200. serviceCellMap[key] = startI
  1201. serviceSlice = append(serviceSlice, item.Children[j].Title)
  1202. startI++
  1203. addCellNum++
  1204. }
  1205. //因为自己本身有一列了,所以在最后增加列的时候,需要减去自身列
  1206. addCellNum = addCellNum - 1
  1207. if addCellNum > 0 {
  1208. for tmpAddCellNum := 0; tmpAddCellNum < addCellNum; tmpAddCellNum++ {
  1209. titleRow.AddCell()
  1210. }
  1211. servicesCell.HMerge = addCellNum //向右合并列数,不包括自身列
  1212. }
  1213. } else {
  1214. key := fmt.Sprint("service_template_", item.ServiceTemplateId)
  1215. serviceCellMap[key] = startI
  1216. serviceSlice = append(serviceSlice, item.Title)
  1217. startI++
  1218. }
  1219. }
  1220. }
  1221. }
  1222. //表头
  1223. headerRow := sheel.AddRow()
  1224. headerRow.SetHeight(24)
  1225. //合同基础信息
  1226. {
  1227. codeHeaderCell := headerRow.AddCell()
  1228. codeHeaderCell.SetValue("合同编号")
  1229. codeHeaderCell.SetStyle(headerStyle)
  1230. companyHeaderCell := headerRow.AddCell()
  1231. companyHeaderCell.SetValue("客户名称")
  1232. companyHeaderCell.SetStyle(headerStyle)
  1233. typeHeaderCell := headerRow.AddCell()
  1234. typeHeaderCell.SetValue("合同类型")
  1235. typeHeaderCell.SetStyle(headerStyle)
  1236. priceHeaderCell := headerRow.AddCell()
  1237. priceHeaderCell.SetValue("合同金额")
  1238. priceHeaderCell.SetStyle(headerStyle)
  1239. dateHeaderCell := headerRow.AddCell()
  1240. dateHeaderCell.SetValue("合同有效期")
  1241. dateHeaderCell.SetStyle(headerStyle)
  1242. sellerHeaderCell := headerRow.AddCell()
  1243. sellerHeaderCell.SetValue("销售")
  1244. sellerHeaderCell.SetStyle(headerStyle)
  1245. statusHeaderCell := headerRow.AddCell()
  1246. statusHeaderCell.SetValue("合同状态")
  1247. statusHeaderCell.SetStyle(headerStyle)
  1248. remarkHeaderCell := headerRow.AddCell()
  1249. remarkHeaderCell.SetValue("备注")
  1250. remarkHeaderCell.SetStyle(headerStyle)
  1251. }
  1252. //添加服务套餐名称
  1253. for _, service := range serviceSlice {
  1254. cell := headerRow.AddCell()
  1255. cell.SetValue(service)
  1256. cell.SetStyle(headerStyle)
  1257. }
  1258. for _, v := range list {
  1259. //如果当前合同不是该产品
  1260. if v.ProductId != productId {
  1261. continue
  1262. }
  1263. dataRow := sheel.AddRow()
  1264. dataRow.SetHeight(24)
  1265. //合同基础信息
  1266. {
  1267. codeCell := dataRow.AddCell()
  1268. codeCell.SetValue(v.ContractCode)
  1269. codeCell.SetStyle(style)
  1270. companyCell := dataRow.AddCell()
  1271. companyCell.SetValue(v.CompanyName)
  1272. companyCell.SetStyle(style)
  1273. typeCell := dataRow.AddCell()
  1274. typeCell.SetValue(v.ContractType)
  1275. typeCell.SetStyle(style)
  1276. priceCell := dataRow.AddCell()
  1277. priceCell.SetValue(v.Price)
  1278. priceCell.SetStyle(style)
  1279. dateCell := dataRow.AddCell()
  1280. dateCell.SetValue(fmt.Sprint(v.StartDate.Format(utils.FormatDate), " 至 ", v.EndDate.Format(utils.FormatDate)))
  1281. dateCell.SetStyle(style)
  1282. sellerCell := dataRow.AddCell()
  1283. sellerCell.SetValue(v.SellerName)
  1284. sellerCell.SetStyle(style)
  1285. statusCell := dataRow.AddCell()
  1286. statusCell.SetValue(v.Status)
  1287. statusCell.SetStyle(style)
  1288. //备注:该字段由三部分拼接:服务内容中的补充内容+赠送时间+优惠金额
  1289. //补充内容直接取该字段内容;
  1290. //赠送时间以年为单位,超过整年的月份作为赠送月份,如14个月即为赠送2个月;
  1291. //优惠金额等于原价-优惠后价格=优惠价格
  1292. //补充内容
  1293. var remark string
  1294. if v.Remark != "" {
  1295. remark += "补充内容:" + v.Remark
  1296. }
  1297. //赠送时间
  1298. //合同结束日期与合同开始日期的时间差(小时差)
  1299. newDecimal := decimal.NewFromFloat(v.EndDate.Sub(v.StartDate).Hours())
  1300. //分母为365天 * 24 小时
  1301. newDecimal2 := decimal.NewFromInt(24 * 365)
  1302. //计算出来相差多少年,保留一位小数(四舍五入)
  1303. numYearDecimal := newDecimal.Div(newDecimal2).Round(1).Mul(decimal.NewFromInt(10))
  1304. //如果大于1年,那么才去判断是否赠送
  1305. numYear, _ := numYearDecimal.Float64()
  1306. if numYear > 10 {
  1307. //获取多出来的整数年数据
  1308. numYearDecimal = numYearDecimal.Mod(decimal.NewFromInt(10)).Div(decimal.NewFromInt(10))
  1309. //计算赠送出来的月份
  1310. numMonthDecimal := numYearDecimal.Mul(decimal.NewFromInt(12)).Round(0)
  1311. numMonth, _ := numMonthDecimal.Float64()
  1312. if numMonth > 0 {
  1313. if remark != "" {
  1314. remark += ";"
  1315. }
  1316. remark += "赠送时间为:" + numMonthDecimal.String() + "个月"
  1317. }
  1318. }
  1319. //优惠金额
  1320. if v.OriginalPrice > v.Price {
  1321. differencePrice := v.OriginalPrice - v.Price
  1322. differencePriceDecimal := decimal.NewFromFloat(differencePrice)
  1323. if remark != "" {
  1324. remark += ";"
  1325. }
  1326. remark += "优惠金额:" + differencePriceDecimal.String() + "元。"
  1327. }
  1328. remarkCell := dataRow.AddCell()
  1329. remarkCell.SetValue(remark)
  1330. remarkCell.SetStyle(style)
  1331. }
  1332. //服务套餐
  1333. {
  1334. cellServiceMap := make(map[int]string)
  1335. for _, cellI := range serviceCellMap {
  1336. cellServiceMap[cellI] = "否"
  1337. }
  1338. if v.Service != nil && len(v.Service) > 0 {
  1339. permissionValues := []string{
  1340. "FICC周报", "商品双周报+线上电话会讨论会<br/>(由弘则的研究员主持线上讨论)", "数据点评", "深度月报:包括宏观经济月报和下游草根调研月报+电话会讨论会<br/>(由弘则的研究员主持线上讨论)",
  1341. }
  1342. for _, item := range v.Service {
  1343. //ficc小套餐
  1344. if item.ServiceTemplateId == 2 {
  1345. for _, detail := range item.DetailList {
  1346. var tableCel request.AddContractServiceDetailReq
  1347. tmpErr := json.Unmarshal([]byte(detail.Col1), &tableCel)
  1348. if tmpErr != nil {
  1349. err = tmpErr
  1350. return
  1351. }
  1352. if tableCel.Value == "商品复盘" {
  1353. var tableCel2 request.AddContractServiceDetailReq
  1354. //获取品种列数据
  1355. tmpErr := contractService.GetProductCelData(*detail, &tableCel2)
  1356. if tmpErr != nil {
  1357. err = tmpErr
  1358. return
  1359. }
  1360. //tableCel2.Tag
  1361. for _, serviceId := range tableCel2.ValueId {
  1362. key := fmt.Sprint(item.ServiceTemplateId, "_product_permission_", serviceId)
  1363. if cellI, ok := serviceCellMap[key]; ok {
  1364. cellServiceMap[cellI] = "是"
  1365. }
  1366. }
  1367. } else if strings.Contains(strings.Join(permissionValues, ","), tableCel.Value) {
  1368. //获取品种列数据
  1369. var tableCel2 request.AddContractServiceDetailReq
  1370. tmpErr := contractService.GetProductCelData(*detail, &tableCel2)
  1371. if tmpErr != nil {
  1372. err = tmpErr
  1373. return
  1374. }
  1375. for _, serviceId := range tableCel2.ValueId {
  1376. key := fmt.Sprint(item.ServiceTemplateId, "_permission_", serviceId)
  1377. if cellI, ok := serviceCellMap[key]; ok {
  1378. cellServiceMap[cellI] = "是"
  1379. }
  1380. }
  1381. }
  1382. }
  1383. } else {
  1384. key := fmt.Sprint("service_template_", item.ServiceTemplateId)
  1385. if cellI, ok := serviceCellMap[key]; ok {
  1386. cellServiceMap[cellI] = "是"
  1387. }
  1388. }
  1389. }
  1390. }
  1391. //遍历所有套餐
  1392. for tmpStartCellI := customStartCellI; tmpStartCellI < startI; tmpStartCellI++ {
  1393. servicesCell := dataRow.AddCell()
  1394. cellValue, ok := cellServiceMap[tmpStartCellI]
  1395. if ok == false {
  1396. cellValue = "否"
  1397. }
  1398. servicesCell.SetValue(cellValue)
  1399. if cellValue == "是" { //勾选了话,标红处理
  1400. servicesCell.SetStyle(redStyle)
  1401. } else {
  1402. servicesCell.SetStyle(style)
  1403. }
  1404. }
  1405. }
  1406. }
  1407. }
  1408. err = xlsxFile.Save(downLoadnFilePath)
  1409. if err != nil {
  1410. br.Msg = "保存文件失败"
  1411. br.ErrMsg = "保存文件失败"
  1412. return
  1413. }
  1414. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1415. downloadFileName := "合同列表" + randStr + ".xlsx"
  1416. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1417. br.Ret = 200
  1418. br.Success = true
  1419. br.Msg = "导出成功"
  1420. }
  1421. // CancelApply
  1422. // @Title 撤回审批申请
  1423. // @Description 撤回审批申请接口
  1424. // @Param ContractApprovalRecordId query int true "审批流id编号"
  1425. // @Param ContractId query int true "合同id编号"
  1426. // @Success Ret=200 撤回申请成功
  1427. // @router /approval/cancelApply [get]
  1428. func (this *ContractApprovalController) CancelApply() {
  1429. br := new(models.BaseResponse).Init()
  1430. defer func() {
  1431. this.Data["json"] = br
  1432. this.ServeJSON()
  1433. }()
  1434. sysUser := this.SysUser
  1435. if sysUser == nil {
  1436. br.Msg = "请登录"
  1437. br.ErrMsg = "请登录,SysUser Is Empty"
  1438. br.Ret = 408
  1439. return
  1440. }
  1441. //合同id编号
  1442. contractId, err := this.GetInt("ContractId")
  1443. if err != nil {
  1444. br.Msg = "获取审批流编号失败"
  1445. br.ErrMsg = "获取审批流编号失败,err:" + err.Error()
  1446. return
  1447. }
  1448. //审批流id编号
  1449. contractApprovalRecordId, err := this.GetInt("ContractApprovalRecordId", 0)
  1450. if err != nil {
  1451. br.Msg = "获取审批流编号失败"
  1452. br.ErrMsg = "获取审批流编号失败,err:" + err.Error()
  1453. return
  1454. }
  1455. if contractApprovalRecordId <= 0 && contractId <= 0 {
  1456. br.Msg = "请传入审批流编号获取合同编号"
  1457. br.ErrMsg = "请传入审批流编号获取合同编号"
  1458. return
  1459. }
  1460. if contractApprovalRecordId > 0 {
  1461. //获取审批流信息
  1462. contractApprovalRecord, err := contract.GetContractApprovalRecordById(contractApprovalRecordId)
  1463. if err != nil {
  1464. br.Msg = "获取审批流信息失败!"
  1465. br.ErrMsg = "获取审批流信息失败,Err:" + err.Error()
  1466. return
  1467. }
  1468. err = contractService.CancelApply(contractApprovalRecord, sysUser.AdminId)
  1469. if err != nil {
  1470. br.Msg = "撤回申请失败!"
  1471. br.ErrMsg = "撤回申请失败,Err:" + err.Error()
  1472. return
  1473. }
  1474. } else if contractId > 0 {
  1475. //获取审批流信息
  1476. contractInfo, err := contract.GetContractById(contractId)
  1477. if err != nil {
  1478. br.Msg = "获取审批流信息失败!"
  1479. br.ErrMsg = "获取审批流信息失败,Err:" + err.Error()
  1480. return
  1481. }
  1482. err = contractService.CancelApplyByContract(contractInfo, sysUser.AdminId)
  1483. if err != nil {
  1484. br.Msg = "撤回申请失败!"
  1485. br.ErrMsg = "撤回申请失败,Err:" + err.Error()
  1486. return
  1487. }
  1488. } else {
  1489. br.Msg = "请传入审批流编号获取合同编号"
  1490. br.ErrMsg = "请传入审批流编号获取合同编号"
  1491. return
  1492. }
  1493. br.Ret = 200
  1494. br.Success = true
  1495. br.Msg = "撤回申请成功"
  1496. }
  1497. // @Title 驳回审批
  1498. // @Description 驳回审批接口
  1499. // @Param request body request.RejectReq true "type json string"
  1500. // @Success Ret=200 驳回成功
  1501. // @router /approval/reject [post]
  1502. func (this *ContractApprovalController) Reject() {
  1503. br := new(models.BaseResponse).Init()
  1504. defer func() {
  1505. this.Data["json"] = br
  1506. this.ServeJSON()
  1507. }()
  1508. sysUser := this.SysUser
  1509. if sysUser == nil {
  1510. br.Msg = "请登录"
  1511. br.ErrMsg = "请登录,SysUser Is Empty"
  1512. br.Ret = 408
  1513. return
  1514. }
  1515. var req request.RejectReq
  1516. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1517. if err != nil {
  1518. br.Msg = "参数解析异常!"
  1519. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1520. return
  1521. }
  1522. //审批流id编号
  1523. contractApprovalRecordId := req.ContractApprovalRecordId
  1524. if contractApprovalRecordId <= 0 {
  1525. br.Msg = "请传入审批流编号"
  1526. br.ErrMsg = "请传入审批流编号"
  1527. return
  1528. }
  1529. //获取审批流信息
  1530. contractApprovalRecord, err := contract.GetContractApprovalRecordById(contractApprovalRecordId)
  1531. if err != nil {
  1532. br.Msg = "获取审批流信息失败!"
  1533. br.ErrMsg = "获取审批流信息失败,Err:" + err.Error()
  1534. return
  1535. }
  1536. err = contractService.Reject(contractApprovalRecord, sysUser, req.Remark)
  1537. if err != nil {
  1538. br.Msg = "驳回审批失败!"
  1539. br.ErrMsg = "驳回审批失败,Err:" + err.Error()
  1540. return
  1541. }
  1542. br.Ret = 200
  1543. br.Success = true
  1544. br.Msg = "驳回成功"
  1545. }
  1546. // @Title 处理审批单
  1547. // @Description 处理审批单
  1548. // @Param request body request.ApprovedReq true "type json string"
  1549. // @Success Ret=200 申请成功
  1550. // @router /approval/approved [post]
  1551. func (this *ContractApprovalController) Approved() {
  1552. br := new(models.BaseResponse).Init()
  1553. defer func() {
  1554. this.Data["json"] = br
  1555. this.ServeJSON()
  1556. }()
  1557. sysUser := this.SysUser
  1558. if sysUser == nil {
  1559. br.Msg = "请登录"
  1560. br.ErrMsg = "请登录,SysUser Is Empty"
  1561. br.Ret = 408
  1562. return
  1563. }
  1564. var req request.ApprovedReq
  1565. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1566. if err != nil {
  1567. br.Msg = "参数解析异常!"
  1568. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1569. return
  1570. }
  1571. //审批流id编号
  1572. contractApprovalRecordId := req.ContractApprovalRecordId
  1573. if contractApprovalRecordId <= 0 {
  1574. br.Msg = "请传入审批流编号"
  1575. br.ErrMsg = "请传入审批流编号"
  1576. return
  1577. }
  1578. //获取审批流信息
  1579. contractApprovalRecord, err := contract.GetContractApprovalRecordById(contractApprovalRecordId)
  1580. if err != nil {
  1581. br.Msg = "获取审批流信息失败!"
  1582. br.ErrMsg = "获取审批流信息失败,Err:" + err.Error()
  1583. return
  1584. }
  1585. err = contractService.Approved(contractApprovalRecord, sysUser, req.Remark)
  1586. if err != nil {
  1587. br.Msg = "审核失败!"
  1588. br.ErrMsg = "审核失败,Err:" + err.Error()
  1589. return
  1590. }
  1591. br.Ret = 200
  1592. br.Success = true
  1593. br.Msg = "审核通过"
  1594. }