contract.go 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992
  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/services/seal"
  17. "hongze/hz_crm_api/utils"
  18. "os"
  19. "path"
  20. "path/filepath"
  21. "strconv"
  22. "strings"
  23. "time"
  24. )
  25. // 合同管理
  26. type ContractController struct {
  27. controllers.BaseAuthController
  28. }
  29. // GetServiceTemplateList
  30. // @Title 获取服务套餐列表
  31. // @Description 获取服务套餐列表
  32. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  33. // @Param ContractType query string false "合同类型:枚举值:'新签合同','续约合同','补充协议'"
  34. // @Success 200 {object} []contract.ContractServiceTemplateMapItems
  35. // @router /service/template/list [get]
  36. func (this *ContractController) GetServiceTemplateList() {
  37. br := new(models.BaseResponse).Init()
  38. defer func() {
  39. this.Data["json"] = br
  40. this.ServeJSON()
  41. }()
  42. productId, _ := this.GetInt("ProductId")
  43. contractType := this.GetString("ContractType")
  44. //没有传参时,默认是从账号中获取
  45. if productId == 0 {
  46. productId = services.GetProductId(this.SysUser.RoleTypeCode)
  47. }
  48. if productId == 0 {
  49. br.Msg = "参数异常"
  50. br.ErrMsg = "获取参数异常,获取合同类型异常,当前RoleTypeCode:" + this.SysUser.RoleTypeCode
  51. return
  52. }
  53. list, err := contract.GetContractServiceTemplateMapByProductId(productId)
  54. if err != nil {
  55. br.Msg = "获取失败"
  56. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  57. return
  58. }
  59. for i := 0; i < len(list); i++ {
  60. item := list[i]
  61. tmpList, err := contract.GetContractServiceTemplateMapByParentId(item.ServiceTemplateId)
  62. if err != nil {
  63. br.Msg = "获取失败"
  64. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  65. return
  66. }
  67. secondLen := len(tmpList)
  68. for j := 0; j < secondLen; j++ {
  69. detail, err := contract.GetContractServiceDetailByTemplateId(tmpList[j].ServiceTemplateId)
  70. if err != nil {
  71. br.Msg = "获取失败"
  72. br.ErrMsg = "获取详情模板失败,Err:" + err.Error()
  73. return
  74. }
  75. tmpList[j].Detail = detail
  76. // 权益存在第三级主客观套餐-CRM8.8
  77. thirdList, e := contract.GetContractServiceTemplateMapByParentId(tmpList[j].ServiceTemplateId)
  78. if e != nil {
  79. br.Msg = "获取失败"
  80. br.ErrMsg = "获取三级套餐失败, Err: " + e.Error()
  81. return
  82. }
  83. tmpList[j].Children = thirdList
  84. //if len(thirdList) > 0 {
  85. // if utils.InArrayByInt([]int{19, 20, 21, 22}, thirdList[0].ChartPermissionId) {
  86. // }
  87. //}
  88. }
  89. // 权益获取升级套餐-CRM13.2
  90. if productId == 2 {
  91. newTempList := make([]*contract.ContractServiceTemplateMapItems, 0)
  92. upgradeMap := make(map[int]*contract.ContractServiceTemplateMapItems)
  93. upgradeList, err := contract.GetContractServiceTemplateMapByChartPermissionId()
  94. if err != nil {
  95. br.Msg = "获取失败"
  96. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  97. return
  98. }
  99. for _, v := range upgradeList {
  100. upgradeMap[v.ChartPermissionId-100000] = v
  101. fmt.Println("v.ChartPermissionId-10000:", v.ChartPermissionId-100000)
  102. }
  103. for _, v := range tmpList {
  104. newTempList = append(newTempList, v)
  105. if len(v.Children) > 0 {
  106. if utils.InArrayByInt([]int{19, 20, 21, 22}, v.Children[0].ChartPermissionId) {
  107. newTempList = append(newTempList, upgradeMap[v.Children[0].ChartPermissionId])
  108. }
  109. }
  110. }
  111. tmpList = newTempList
  112. }
  113. detail, err := contract.GetContractServiceDetailByTemplateId(list[i].ServiceTemplateId)
  114. if err != nil {
  115. br.Msg = "获取失败"
  116. br.ErrMsg = "获取详情模板失败,Err:" + err.Error()
  117. return
  118. }
  119. if productId == 1 && contractType == "补充协议" {
  120. for _, v := range detail {
  121. //ficc 的合同模板的 补充协议需要将默认的宏观经济给移除掉
  122. if utils.InArrayByInt([]int{4, 5, 6}, v.Id) {
  123. var tableCel request.AddContractServiceDetailReq
  124. tmpErr := json.Unmarshal([]byte(v.Col2), &tableCel)
  125. if tmpErr != nil {
  126. br.Msg = "获取失败"
  127. br.ErrMsg = "配置解析失败,Err:" + tmpErr.Error()
  128. return
  129. }
  130. tableCel.ValueId = make([]int, 0)
  131. tableCel.Value = ``
  132. //contract.
  133. tmpStr, tmpErr := json.Marshal(tableCel)
  134. if tmpErr != nil {
  135. br.Msg = "获取失败"
  136. br.ErrMsg = "修改json配置后,转字符串失败,Err:" + tmpErr.Error()
  137. return
  138. }
  139. v.Col2 = string(tmpStr)
  140. }
  141. //v.Col1
  142. }
  143. }
  144. list[i].Detail = detail
  145. list[i].Children = tmpList
  146. }
  147. br.Ret = 200
  148. br.Success = true
  149. br.Msg = "获取成功"
  150. br.Data = list
  151. }
  152. // GetContractTemplateList
  153. // @Title 获取合同模板列表
  154. // @Description 获取合同模板列表
  155. // @Success 200 {object} []contract.ContractTemplate
  156. // @router /template/list [get]
  157. func (this *ContractController) GetContractTemplateList() {
  158. br := new(models.BaseResponse).Init()
  159. defer func() {
  160. this.Data["json"] = br
  161. this.ServeJSON()
  162. }()
  163. productId := services.GetProductId(this.SysUser.RoleTypeCode)
  164. list, err := contract.GetContractTemplateMapByProductId(productId)
  165. if err != nil {
  166. br.Msg = "获取失败"
  167. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  168. return
  169. }
  170. br.Ret = 200
  171. br.Success = true
  172. br.Msg = "获取成功"
  173. br.Data = list
  174. }
  175. // GetPayChannel
  176. // @Title 获取合同模板列表
  177. // @Description 获取合同模板列表
  178. // @Param Keyword query string true "关键字"
  179. // @Success 200 {object} []contract.PayChannel
  180. // @router /pay_channel/list [get]
  181. func (this *ContractController) GetPayChannel() {
  182. br := new(models.BaseResponse).Init()
  183. defer func() {
  184. this.Data["json"] = br
  185. this.ServeJSON()
  186. }()
  187. keyword := this.GetString("Keyword", "")
  188. list, err := contract.GetPayChannelList(keyword)
  189. if err != nil {
  190. br.Msg = "获取失败"
  191. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  192. return
  193. }
  194. br.Ret = 200
  195. br.Success = true
  196. br.Msg = "获取成功"
  197. br.Data = list
  198. }
  199. // AddContract
  200. // @Title 新增合同
  201. // @Description 新增合同接口
  202. // @Param request body request.AddContractReq true "type json string"
  203. // @Success 200 {object} response.AddContractResp
  204. // @router /add [post]
  205. func (this *ContractController) AddContract() {
  206. br := new(models.BaseResponse).Init()
  207. defer func() {
  208. this.Data["json"] = br
  209. this.ServeJSON()
  210. }()
  211. sysUser := this.SysUser
  212. if sysUser == nil {
  213. br.Msg = "请登录"
  214. br.ErrMsg = "请登录,SysUser Is Empty"
  215. br.Ret = 408
  216. return
  217. }
  218. productId := services.GetProductId(sysUser.RoleTypeCode)
  219. if productId == 0 {
  220. br.Msg = "账户异常"
  221. br.ErrMsg = "账户异常,当前账户类型为:" + sysUser.RoleTypeCode
  222. br.Ret = 408
  223. return
  224. }
  225. var req request.AddContractReq
  226. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  227. if err != nil {
  228. br.Msg = "参数解析异常!"
  229. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  230. return
  231. }
  232. // 限制一下合同金额, 目前只支持人民币转大写只支持到千亿, 虽然生产使用中不可能到这么大, 但还是加上吧 =_=!
  233. maxPrice := float64(1000000000000)
  234. if req.OriginalPrice >= maxPrice || req.Price >= maxPrice {
  235. br.Msg = "合同金额过大, 请核验金额"
  236. return
  237. }
  238. contractInfo, err, errMsg := contractService.AddContract(req, sysUser.AdminId, productId, sysUser.RealName)
  239. if err != nil {
  240. br.Msg = "保存合同失败!"
  241. if errMsg != "" {
  242. br.Msg = errMsg
  243. }
  244. br.ErrMsg = "保存合同失败,Err:" + err.Error()
  245. return
  246. }
  247. msg := "添加成功"
  248. //如果是直接发起审批,那么
  249. if req.IsAudit {
  250. tmpErr, errMsg := contractService.Apply(contractInfo.ContractId)
  251. if tmpErr != nil {
  252. br.Msg = "提交审批失败!"
  253. if errMsg != "" {
  254. br.Msg = errMsg
  255. }
  256. br.ErrMsg = "提交审批失败,Err:" + tmpErr.Error()
  257. return
  258. }
  259. msg = "提交审批成功"
  260. }
  261. br.Ret = 200
  262. br.Success = true
  263. br.Msg = msg
  264. br.Data = response.AddContractResp{
  265. ContractId: contractInfo.ContractId,
  266. }
  267. }
  268. // List
  269. // @Title 合同列表
  270. // @Description 合同列表接口
  271. // @Param ContractBusinessType query string false "合同业务类型,枚举值:'业务合同','代付合同'"
  272. // @Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
  273. // @Param ContractStatus query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废'"
  274. // @Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  275. // @Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  276. // @Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  277. // @Param SellerId query string false "选择的销售id"
  278. // @Param KeywordType query string false "搜索关键字类型,枚举值:'使用方','代付方'"
  279. // @Param Keyword query string false "搜索关键字"
  280. // @Param IsExport query bool false "是否导出excel,默认是false"
  281. // @Success 200 {object} response.ContractListResp
  282. // @router /list [get]
  283. func (this *ContractController) List() {
  284. br := new(models.BaseResponse).Init()
  285. defer func() {
  286. this.Data["json"] = br
  287. this.ServeJSON()
  288. }()
  289. sysUser := this.SysUser
  290. if sysUser == nil {
  291. br.Msg = "请登录"
  292. br.ErrMsg = "请登录,SysUser Is Empty"
  293. br.Ret = 408
  294. return
  295. }
  296. //合同类型、产品类型、合同状态、更新时间、所选销售
  297. //关键字:合同编号、客户名称,社会信用码
  298. contractType := this.GetString("ContractType")
  299. contractBusinessType := this.GetString("ContractBusinessType")
  300. contractStatus := this.GetString("ContractStatus")
  301. productId, _ := this.GetInt("ProductId")
  302. modifyStartTime := this.GetString("ModifyStartTime")
  303. modifyEndTime := this.GetString("ModifyEndTime")
  304. sellerIds := this.GetString("SellerId")
  305. keyword := this.GetString("Keyword")
  306. keywordType := this.GetString("KeywordType")
  307. condition := ""
  308. pars := make([]interface{}, 0)
  309. joinStr := "" //表连接
  310. productSlice := make([]int, 0) //需要下载的 产品 切片
  311. //如果不是超管或者合规,那么只能查看自己的合同
  312. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  313. condition += ` AND a.product_id = 1 AND a.status not in ("待提交","已撤回") `
  314. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  315. condition += ` AND a.product_id = 2 AND a.status not in ("待提交","已撤回") `
  316. } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FINANCE { //超管可查看所有状态的合同(除过已撤回、待提交状态合同),可下载所有状态的合同
  317. condition += ` AND a.status not in ("待提交","已撤回") `
  318. } else {
  319. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
  320. condition += ` AND a.seller_id = ? `
  321. pars = append(pars, sysUser.AdminId)
  322. }
  323. }
  324. //合同类型、、更新时间、所选销售
  325. //关键字:合同编号、客户名称,社会信用码
  326. if contractBusinessType != "" { //合同业务类型
  327. condition += ` AND a.contract_business_type = ? `
  328. pars = append(pars, contractBusinessType)
  329. }
  330. if contractType != "" {
  331. condition += ` AND a.contract_type = ? `
  332. pars = append(pars, contractType)
  333. }
  334. //合同状态
  335. if contractStatus != "" {
  336. condition += ` AND a.status = ? `
  337. pars = append(pars, contractStatus)
  338. }
  339. //产品类型
  340. if productId > 0 {
  341. condition += ` AND a.product_id = ? `
  342. pars = append(pars, productId)
  343. productSlice = append(productSlice, productId)
  344. } else {
  345. nowProductId := services.GetProductId(sysUser.RoleTypeCode)
  346. if nowProductId > 0 {
  347. productSlice = append(productSlice, nowProductId)
  348. } else {
  349. productSlice = append(productSlice, 1)
  350. productSlice = append(productSlice, 2)
  351. }
  352. }
  353. //所选销售
  354. if sellerIds != "" {
  355. condition += ` AND a.seller_id IN (` + sellerIds + `) `
  356. }
  357. //更新开始时间
  358. if modifyStartTime != "" {
  359. condition += ` AND a.modify_time >= ? `
  360. pars = append(pars, modifyStartTime)
  361. }
  362. //更新结束时间
  363. if modifyEndTime != "" {
  364. condition += ` AND a.modify_time <= ? `
  365. pars = append(pars, modifyEndTime)
  366. }
  367. //关键字
  368. //if keyword != "" {
  369. // condition += ` AND (contract_code LIKE '%` + keyword + `%' OR company_name LIKE '%` + keyword + `%' OR credit_code LIKE '%` + keyword + `%' ) `
  370. //}
  371. //搜索关键字和搜索类型同时不为空
  372. if keywordType != "" && keyword != "" {
  373. switch contractBusinessType {
  374. case "业务合同":
  375. if keywordType == "使用方" {
  376. condition += ` AND (a.contract_code LIKE '%` + keyword + `%' OR a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%' ) `
  377. } else {
  378. joinStr = " join contract_relation b on a.contract_id=b.contract_id join contract c on b.payment_on_behalf_contract_id=c.contract_id "
  379. condition += ` AND (c.contract_code LIKE '%` + keyword + `%' OR c.company_name LIKE '%` + keyword + `%' OR c.credit_code LIKE '%` + keyword + `%' ) `
  380. //关联合同的查询条件
  381. condition += ` AND c.status in ("已签回","已审批") AND c.is_delete = 0 `
  382. }
  383. case "代付合同":
  384. if keywordType == "代付方" {
  385. condition += ` AND (a.contract_code LIKE '%` + keyword + `%' OR a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%' ) `
  386. } else {
  387. joinStr = " join contract_relation b on a.contract_id=b.payment_on_behalf_contract_id join contract c on b.contract_id=c.contract_id "
  388. condition += ` AND (c.contract_code LIKE '%` + keyword + `%' OR c.company_name LIKE '%` + keyword + `%' OR c.credit_code LIKE '%` + keyword + `%' ) `
  389. //关联合同的查询条件
  390. condition += ` AND c.status in ("已签回","已审批") AND c.is_delete = 0 `
  391. }
  392. }
  393. }
  394. pageSize, _ := this.GetInt("PageSize")
  395. currentIndex, _ := this.GetInt("CurrentIndex")
  396. var startSize int
  397. if pageSize <= 0 {
  398. pageSize = utils.PageSize20
  399. }
  400. if currentIndex <= 0 {
  401. currentIndex = 1
  402. }
  403. startSize = paging.StartIndex(currentIndex, pageSize)
  404. //是否导出报表
  405. isExport, _ := this.GetBool("IsExport")
  406. if isExport {
  407. pageSize = 10000
  408. currentIndex = 1
  409. }
  410. total, err := contract.GetContractListCount(condition, joinStr, pars)
  411. if err != nil {
  412. br.Msg = "获取失败"
  413. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  414. return
  415. }
  416. list, err := contract.GetContractList(condition, joinStr, pars, startSize, pageSize)
  417. if err != nil {
  418. br.Msg = "获取合同列表失败!"
  419. br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
  420. return
  421. }
  422. //获取合同套餐服务列表
  423. serviceTemplateList, err := contract.GetAllContractServiceTemplateList()
  424. if err != nil {
  425. br.Msg = "获取合同套餐服务列表失败!"
  426. br.ErrMsg = "获取合同套餐服务列表失败,Err:" + err.Error()
  427. return
  428. }
  429. templateTitleMap := make(map[int]string)
  430. for _, serviceTemplate := range serviceTemplateList {
  431. templateTitleMap[serviceTemplate.ServiceTemplateId] = serviceTemplate.Title
  432. }
  433. //业务合同的关联合同id集合
  434. businessContractIdList := make([]string, 0)
  435. //代付合同的关联合同id集合
  436. paymentOnBehalfContractIdList := make([]string, 0)
  437. //所有合同id集合(用于查询服务内容)
  438. allServiceContractIdList := make([]string, 0)
  439. //基础合同的关联合同数据
  440. contractRelationMap := make(map[int][]*contract.RelationContractList)
  441. // 权益合同map
  442. equityContractMap := make(map[int]bool)
  443. for _, v := range list {
  444. //合同id
  445. allServiceContractIdList = append(allServiceContractIdList, fmt.Sprint(v.ContractId))
  446. switch v.ContractBusinessType {
  447. case "业务合同":
  448. businessContractIdList = append(businessContractIdList, fmt.Sprint(v.ContractId))
  449. case "代付合同":
  450. paymentOnBehalfContractIdList = append(paymentOnBehalfContractIdList, fmt.Sprint(v.ContractId))
  451. }
  452. // 权益合同
  453. if v.ProductId == 2 {
  454. equityContractMap[v.ContractId] = true
  455. }
  456. }
  457. //业务合同的关联合同
  458. if len(businessContractIdList) > 0 {
  459. contractIdStr := strings.Join(businessContractIdList, ",")
  460. businessContractList, err := contract.GetContractRelationListByRelationContractIds(contractIdStr)
  461. if err != nil {
  462. br.Msg = "获取失败"
  463. br.ErrMsg = "获取业务关联合同失败,Err:" + err.Error()
  464. return
  465. }
  466. for _, v := range businessContractList {
  467. //代付合同id
  468. allServiceContractIdList = append(allServiceContractIdList, fmt.Sprint(v.PaymentOnBehalfContractId))
  469. if _, ok := contractRelationMap[v.ContractId]; ok {
  470. contractRelationMap[v.ContractId] = append(contractRelationMap[v.ContractId], v)
  471. } else {
  472. tmpList := make([]*contract.RelationContractList, 0)
  473. contractRelationMap[v.ContractId] = append(tmpList, v)
  474. }
  475. }
  476. }
  477. //代付合同的关联合同
  478. if len(paymentOnBehalfContractIdList) > 0 {
  479. paymentOnBehalfContractIdStr := strings.Join(paymentOnBehalfContractIdList, ",")
  480. paymentOnBehalfContractList, err := contract.GetContractRelationListByPaymentOnBehalfContractIds(paymentOnBehalfContractIdStr)
  481. if err != nil {
  482. br.Msg = "获取失败"
  483. br.ErrMsg = "获取代付关联合同失败,Err:" + err.Error()
  484. return
  485. }
  486. for _, v := range paymentOnBehalfContractList {
  487. //业务合同id
  488. allServiceContractIdList = append(allServiceContractIdList, fmt.Sprint(v.ContractId))
  489. if _, ok := contractRelationMap[v.PaymentOnBehalfContractId]; ok {
  490. contractRelationMap[v.PaymentOnBehalfContractId] = append(contractRelationMap[v.PaymentOnBehalfContractId], v)
  491. } else {
  492. tmpList := make([]*contract.RelationContractList, 0)
  493. contractRelationMap[v.PaymentOnBehalfContractId] = append(tmpList, v)
  494. }
  495. }
  496. }
  497. //合同套餐服务列表
  498. serviceListMap := make(map[int][]*contract.ContractServiceAndDetail, 0)
  499. // 权益合同
  500. if len(allServiceContractIdList) > 0 {
  501. allRelationIdStr := strings.Join(allServiceContractIdList, ",")
  502. tmpServiceList, err := contract.GetContractServiceAndDetailListByIds(allRelationIdStr)
  503. if err != nil {
  504. br.Msg = "获取失败"
  505. br.ErrMsg = "获取关联合同服务详情失败,Err:" + err.Error()
  506. return
  507. }
  508. allContractServiceIdList := make([]string, 0)
  509. serviceDetailListMap := make(map[int][]*contract.ContractServiceDetail, 0)
  510. for _, service := range tmpServiceList {
  511. if service.HasDetail == "是" {
  512. allContractServiceIdList = append(allContractServiceIdList, strconv.Itoa(service.ContractServiceId))
  513. }
  514. }
  515. if len(allContractServiceIdList) > 0 {
  516. allContractServiceIdStr := strings.Join(allContractServiceIdList, ",")
  517. list, detailErr := contract.GetContractServiceDetailListByServiceIds(allContractServiceIdStr)
  518. if detailErr != nil {
  519. br.Msg = "获取失败"
  520. br.ErrMsg = "查找合同服务详情异常,Err:" + detailErr.Error()
  521. return
  522. }
  523. for _, v := range list {
  524. if _, ok := serviceDetailListMap[v.ContractServiceId]; ok {
  525. serviceDetailListMap[v.ContractServiceId] = append(serviceDetailListMap[v.ContractServiceId], v)
  526. } else {
  527. tmpList := make([]*contract.ContractServiceDetail, 0)
  528. serviceDetailListMap[v.ContractServiceId] = append(tmpList, v)
  529. }
  530. }
  531. }
  532. for _, service := range tmpServiceList {
  533. if service.HasDetail == "是" {
  534. if serviceDetailList, ok := serviceDetailListMap[service.ContractServiceId]; ok {
  535. service.DetailList = serviceDetailList
  536. }
  537. //套餐名称
  538. if title, ok := templateTitleMap[service.ServiceTemplateId]; ok {
  539. service.Title = title
  540. }
  541. }
  542. //服务列表
  543. if _, ok := serviceListMap[service.ContractId]; ok {
  544. serviceListMap[service.ContractId] = append(serviceListMap[service.ContractId], service)
  545. } else {
  546. tmpList := make([]*contract.ContractServiceAndDetail, 0)
  547. serviceListMap[service.ContractId] = append(tmpList, service)
  548. }
  549. }
  550. // CRM8.8-权益合同主客观合并
  551. for k, v := range serviceListMap {
  552. if equityContractMap[k] {
  553. mergeList := contractService.EquityMergeSubjectAndObject(v)
  554. serviceListMap[k] = mergeList
  555. }
  556. }
  557. }
  558. //关联合同
  559. for _, contractRelationList := range contractRelationMap {
  560. for _, contractRelation := range contractRelationList {
  561. //服务权限列表
  562. // 关联合同同样合并
  563. if serviceList, ok := serviceListMap[contractRelation.ContractId]; ok {
  564. relationMergeList := contractService.EquityMergeSubjectAndObject(serviceList)
  565. contractRelation.Service = relationMergeList
  566. }
  567. }
  568. }
  569. for i := 0; i < len(list); i++ {
  570. //合同操作权限
  571. var opButton contract.ContractOpButton
  572. item := list[i]
  573. list[i].StartDateStr = item.StartDate.Format(utils.FormatDate)
  574. list[i].EndDateStr = item.EndDate.Format(utils.FormatDate)
  575. list[i].CreateTimeStr = item.CreateTime.Format(utils.FormatDateTime)
  576. list[i].ModifyTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
  577. list[i].ApproveTimeStr = item.ApproveTime.Format(utils.FormatDateTime)
  578. list[i].InvalidTimeStr = item.InvalidTime.Format(utils.FormatDateTime)
  579. list[i].CheckBackFileTimeStr = item.CheckBackFileTime.Format(utils.FormatDateTime)
  580. list[i].RescindTimeStr = item.RescindTime.Format(utils.FormatDateTime)
  581. //服务列表
  582. if serviceList, ok := serviceListMap[item.ContractId]; ok {
  583. item.Service = serviceList
  584. }
  585. //serviceList, err := contract.GetContractServiceAndDetailList(item.ContractId)
  586. //if err != nil {
  587. // br.Msg = "获取失败"
  588. // br.ErrMsg = "查找合同服务异常,Err:" + err.Error()
  589. // return
  590. //}
  591. //for i := 0; len(serviceList) > i; i++ {
  592. // if serviceList[i].HasDetail == "是" {
  593. // list, detailErr := contract.GetContractServiceDetailListByServiceId(serviceList[i].ContractServiceId)
  594. // if detailErr != nil {
  595. // br.Msg = "获取失败"
  596. // br.ErrMsg = "查找合同服务详情异常,Err:" + err.Error()
  597. // return
  598. // }
  599. //
  600. // //套餐名称
  601. // serviceList[i].DetailList = list
  602. // if title, ok := templateTitleMap[serviceList[i].ServiceTemplateId]; ok {
  603. // serviceList[i].Title = title
  604. // }
  605. // }
  606. //}
  607. //list[i].Service = serviceList
  608. if item.Status == "待审批" {
  609. approvalInfo, tmpErr := contract.GetLastContractApprovalByContractId(item.ContractId, "contract")
  610. if tmpErr != nil {
  611. //err= tmpErr
  612. //return
  613. continue
  614. }
  615. //如果合同归属是当前账号,且处于第一级审批
  616. if item.SellerId == sysUser.AdminId && approvalInfo.CurrNodeId == approvalInfo.StartNodeId {
  617. opButton.Cancel = true
  618. }
  619. }
  620. //更新附件权限
  621. if item.SellerId == sysUser.AdminId && item.Status == "已审批" {
  622. opButton.UpdateFile = true
  623. }
  624. list[i].OpButton = opButton
  625. //关联合同
  626. if relationContractList, ok := contractRelationMap[item.ContractId]; ok {
  627. item.RelationContractList = relationContractList
  628. //list[i].RelationContractList = relationContractList
  629. }
  630. }
  631. page := paging.GetPaging(currentIndex, pageSize, total)
  632. //导出excel
  633. if isExport {
  634. contractListExport(this, list, productSlice, contractBusinessType, br)
  635. return
  636. }
  637. br.Ret = 200
  638. br.Success = true
  639. br.Msg = "获取成功"
  640. br.Data = response.ContractListResp{
  641. List: list,
  642. Paging: page,
  643. }
  644. }
  645. // contractListExport 合同列表数据导出
  646. func contractListExport(this *ContractController, list []*contract.ContractList, productSlice []int, contractBusinessType string, br *models.BaseResponse) {
  647. //产品类型
  648. //获取合同套餐服务列表
  649. serviceTemplateList, err := contract.GetAllContractServiceTemplateList()
  650. if err != nil {
  651. br.Msg = "获取合同套餐服务列表失败!"
  652. br.ErrMsg = "获取合同套餐服务列表失败,Err:" + err.Error()
  653. return
  654. }
  655. templateTitleMap := make(map[int]string)
  656. for _, serviceTemplate := range serviceTemplateList {
  657. templateTitleMap[serviceTemplate.ServiceTemplateId] = serviceTemplate.Title
  658. }
  659. //生成excel文件
  660. dir, err := os.Executable()
  661. exPath := filepath.Dir(dir)
  662. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  663. xlsxFile := xlsx.NewFile()
  664. if err != nil {
  665. br.Msg = "生成文件失败"
  666. br.ErrMsg = "生成文件失败"
  667. return
  668. }
  669. //设置默认字体和文字大小
  670. xlsx.SetDefaultFont(12, "宋体")
  671. //定义边框样式
  672. border := xlsx.NewBorder("thin", "thin", "thin", "thin")
  673. //定义文字排版样式
  674. alignment := xlsx.Alignment{
  675. Horizontal: "center",
  676. Vertical: "center",
  677. WrapText: true,
  678. }
  679. //普通样式
  680. style := xlsx.NewStyle()
  681. style.Alignment = alignment
  682. style.ApplyAlignment = true
  683. style.Border = *border
  684. //标红文字,便于查看哪些产品被勾选
  685. redStyle := xlsx.NewStyle()
  686. redStyle.Alignment = alignment
  687. redStyle.ApplyAlignment = true
  688. redStyle.Font.Color = "ff0000"
  689. //定义底色需要标黄的 单元格颜色
  690. redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  691. redStyle.Fill = redFill
  692. redStyle.Border = *border
  693. //标题样式
  694. titleStyle := xlsx.NewStyle()
  695. titleFont := xlsx.NewFont(14, "宋体")
  696. titleFont.Bold = true
  697. titleStyle.Font = *titleFont
  698. titleStyle.Alignment = alignment
  699. titleStyle.Border = *border
  700. //titleStyle.ApplyAlignment = true
  701. //表头
  702. headerStyle := xlsx.NewStyle()
  703. headerFont := xlsx.NewFont(12, "宋体")
  704. headerFont.Bold = true
  705. headerStyle.Font = *headerFont
  706. headerStyle.Alignment = alignment
  707. headerStyle.ApplyAlignment = true
  708. headerStyle.Border = *border
  709. defer func() {
  710. os.Remove(downLoadnFilePath)
  711. }()
  712. //遍历所拥有的的产品权限,然后插入到对应的sheet表单中
  713. for pidIndex := 0; pidIndex < len(productSlice); pidIndex++ {
  714. productId := productSlice[pidIndex]
  715. //表单名称
  716. sheetName := "合同数据"
  717. switch productId {
  718. case 1:
  719. sheetName = "ficc合同信息"
  720. case 2:
  721. sheetName = "权益合同信息"
  722. }
  723. //新增一个sheet表单
  724. sheel, err := xlsxFile.AddSheet(sheetName)
  725. if err != nil {
  726. br.Msg = "新增Sheet失败"
  727. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  728. return
  729. }
  730. //设置列宽
  731. sheel.SetColWidth(0, 0, 28)
  732. sheel.SetColWidth(1, 1, 30)
  733. sheel.SetColWidth(2, 2, 18)
  734. sheel.SetColWidth(3, 3, 18)
  735. sheel.SetColWidth(4, 4, 35)
  736. sheel.SetColWidth(5, 6, 20)
  737. sheel.SetColWidth(7, 7, 40)
  738. //合同信息列
  739. endContractInfoColIndex := 8
  740. sheel.SetColWidth(8, 8, 40)
  741. //权限列
  742. sheel.SetColWidth(endContractInfoColIndex, endContractInfoColIndex+18, 30)
  743. //标题行
  744. titleRow := sheel.AddRow()
  745. titleRow.SetHeight(30)
  746. //合同信息列
  747. titleCell := titleRow.AddCell()
  748. titleCell.HMerge = endContractInfoColIndex //向右合并列数,不包括自身列
  749. //遍历去添加需要合并的列
  750. for i := 0; i < endContractInfoColIndex; i++ {
  751. titleRow.AddCell()
  752. }
  753. //报表标题名称
  754. titleCell.SetValue("合同信息")
  755. titleCell.SetStyle(titleStyle)
  756. startI := endContractInfoColIndex + 1
  757. customStartCellI := endContractInfoColIndex + 1
  758. serviceSlice := make([]string, 0)
  759. serviceCellMap := make(map[string]int)
  760. //获取所有套餐列表
  761. {
  762. serviceList, err := getServiceTemplateList(productId)
  763. if err != nil {
  764. br.Msg = "查询套餐类型失败"
  765. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  766. return
  767. }
  768. for i := 0; i < len(serviceList); i++ {
  769. //需要向右合并添加的列数
  770. addCellNum := 0
  771. item := serviceList[i]
  772. //套餐服务列
  773. servicesCell := titleRow.AddCell()
  774. //套餐名称
  775. servicesCell.SetValue(item.Title)
  776. servicesCell.SetStyle(titleStyle)
  777. //ficc小套餐
  778. if item.ServiceTemplateId == 2 {
  779. productPermission := make(map[int]string)
  780. productPermission[1] = "每日宏观商品复盘"
  781. productPermission[2] = "能化专栏《化里化外》"
  782. productPermission[3] = "股债日评"
  783. productPermission[4] = "黑色专栏《知白守黑》"
  784. productPermission[5] = "有色专栏《有声有色》"
  785. for id, name := range productPermission {
  786. key := fmt.Sprint(item.ServiceTemplateId, "_product_permission_", id)
  787. serviceCellMap[key] = startI
  788. serviceSlice = append(serviceSlice, name)
  789. startI++
  790. addCellNum++
  791. }
  792. permissionList := make([]*company.PermissionSetItem, 0)
  793. for _, v := range utils.PermissionFiccClassifyArr {
  794. items, err := company.GetPermissionSetItems(1, v)
  795. if err != nil {
  796. br.Msg = "获取失败"
  797. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  798. return
  799. }
  800. permissionList = append(permissionList, items...)
  801. }
  802. //权限列表
  803. for j := 0; j < len(permissionList); j++ {
  804. key := fmt.Sprint(item.ServiceTemplateId, "_permission_", permissionList[j].ChartPermissionId)
  805. serviceCellMap[key] = startI
  806. serviceSlice = append(serviceSlice, permissionList[j].PermissionName)
  807. startI++
  808. addCellNum++
  809. }
  810. //因为自己本身有一列了,所以在最后增加列的时候,需要减去自身列
  811. addCellNum = addCellNum - 1
  812. if addCellNum > 0 {
  813. for tmpAddCellNum := 0; tmpAddCellNum < addCellNum; tmpAddCellNum++ {
  814. titleRow.AddCell()
  815. }
  816. servicesCell.HMerge = addCellNum //向右合并列数,不包括自身列
  817. }
  818. continue
  819. } else {
  820. if item.Children != nil && len(item.Children) > 0 {
  821. for j := 0; j < len(item.Children); j++ {
  822. key := fmt.Sprint("service_template_", item.Children[j].ServiceTemplateId)
  823. serviceCellMap[key] = startI
  824. serviceSlice = append(serviceSlice, item.Children[j].Title)
  825. startI++
  826. addCellNum++
  827. }
  828. //因为自己本身有一列了,所以在最后增加列的时候,需要减去自身列
  829. addCellNum = addCellNum - 1
  830. if addCellNum > 0 {
  831. for tmpAddCellNum := 0; tmpAddCellNum < addCellNum; tmpAddCellNum++ {
  832. titleRow.AddCell()
  833. }
  834. servicesCell.HMerge = addCellNum //向右合并列数,不包括自身列
  835. }
  836. } else {
  837. key := fmt.Sprint("service_template_", item.ServiceTemplateId)
  838. serviceCellMap[key] = startI
  839. serviceSlice = append(serviceSlice, item.Title)
  840. startI++
  841. }
  842. }
  843. }
  844. }
  845. //表头
  846. headerRow := sheel.AddRow()
  847. headerRow.SetHeight(24)
  848. //合同基础信息
  849. {
  850. codeHeaderCell := headerRow.AddCell()
  851. codeHeaderCell.SetValue("合同编号")
  852. codeHeaderCell.SetStyle(headerStyle)
  853. companyHeaderCell := headerRow.AddCell()
  854. companyHeaderStr := "客户名称"
  855. if contractBusinessType == "代付合同" {
  856. companyHeaderStr = "代付方"
  857. }
  858. companyHeaderCell.SetValue(companyHeaderStr)
  859. companyHeaderCell.SetStyle(headerStyle)
  860. typeHeaderCell := headerRow.AddCell()
  861. typeHeaderCell.SetValue("合同类型")
  862. typeHeaderCell.SetStyle(headerStyle)
  863. priceHeaderCell := headerRow.AddCell()
  864. priceHeaderCell.SetValue("合同金额")
  865. priceHeaderCell.SetStyle(headerStyle)
  866. dateHeaderCell := headerRow.AddCell()
  867. dateHeaderCell.SetValue("合同有效期")
  868. dateHeaderCell.SetStyle(headerStyle)
  869. sellerHeaderCell := headerRow.AddCell()
  870. sellerHeaderCell.SetValue("销售")
  871. sellerHeaderCell.SetStyle(headerStyle)
  872. statusHeaderCell := headerRow.AddCell()
  873. statusHeaderCell.SetValue("合同状态")
  874. statusHeaderCell.SetStyle(headerStyle)
  875. //关联合同信息
  876. payHeaderCell := headerRow.AddCell()
  877. payHeaderStr := "付款方"
  878. if contractBusinessType == "代付合同" {
  879. payHeaderStr = "客户名称"
  880. }
  881. payHeaderCell.SetValue(payHeaderStr)
  882. payHeaderCell.SetStyle(headerStyle)
  883. remarkHeaderCell := headerRow.AddCell()
  884. remarkHeaderCell.SetValue("备注")
  885. remarkHeaderCell.SetStyle(headerStyle)
  886. }
  887. //添加服务套餐名称
  888. for _, service := range serviceSlice {
  889. cell := headerRow.AddCell()
  890. cell.SetValue(service)
  891. cell.SetStyle(headerStyle)
  892. }
  893. for _, v := range list {
  894. //如果当前合同不是该产品
  895. if v.ProductId != productId {
  896. continue
  897. }
  898. dataRow := sheel.AddRow()
  899. dataRow.SetHeight(24)
  900. //合同基础信息
  901. {
  902. codeCell := dataRow.AddCell()
  903. codeCell.SetValue(v.ContractCode)
  904. codeCell.SetStyle(style)
  905. companyCell := dataRow.AddCell()
  906. companyCell.SetValue(v.CompanyName)
  907. companyCell.SetStyle(style)
  908. typeCell := dataRow.AddCell()
  909. typeCell.SetValue(v.ContractType)
  910. typeCell.SetStyle(style)
  911. priceCell := dataRow.AddCell()
  912. priceCell.SetValue(v.Price)
  913. priceCell.SetStyle(style)
  914. dateCell := dataRow.AddCell()
  915. dateCell.SetValue(fmt.Sprint(v.StartDate.Format(utils.FormatDate), " 至 ", v.EndDate.Format(utils.FormatDate)))
  916. dateCell.SetStyle(style)
  917. sellerCell := dataRow.AddCell()
  918. sellerCell.SetValue(v.SellerName)
  919. sellerCell.SetStyle(style)
  920. //合同状态
  921. statusCell := dataRow.AddCell()
  922. statusCell.SetValue(v.Status)
  923. statusCell.SetStyle(style)
  924. //关联合同客户信息
  925. relationCompanyName := ``
  926. if v.RelationContractList != nil && len(v.RelationContractList) > 0 {
  927. payCompanyNameList := make([]string, 0)
  928. for _, relationContract := range v.RelationContractList {
  929. payCompanyNameList = append(payCompanyNameList, relationContract.CompanyName)
  930. }
  931. relationCompanyName = strings.Join(payCompanyNameList, ",")
  932. } else {
  933. relationCompanyName = v.PayChannel
  934. }
  935. payCell := dataRow.AddCell()
  936. payCell.SetValue(relationCompanyName)
  937. payCell.SetStyle(style)
  938. //备注:该字段由三部分拼接:服务内容中的补充内容+赠送时间+优惠金额
  939. //补充内容直接取该字段内容;
  940. //赠送时间以年为单位,超过整年的月份作为赠送月份,如14个月即为赠送2个月;
  941. //优惠金额等于原价-优惠后价格=优惠价格
  942. //补充内容
  943. var remark string
  944. if v.Remark != "" {
  945. remark += "补充内容:" + v.Remark
  946. }
  947. //赠送时间
  948. //合同结束日期与合同开始日期的时间差(小时差)
  949. newDecimal := decimal.NewFromFloat(v.EndDate.Sub(v.StartDate).Hours())
  950. //分母为365天 * 24 小时
  951. newDecimal2 := decimal.NewFromInt(24 * 365)
  952. //计算出来相差多少年,保留一位小数(四舍五入)
  953. numYearDecimal := newDecimal.Div(newDecimal2).Round(1).Mul(decimal.NewFromInt(10))
  954. //如果大于1年,那么才去判断是否赠送
  955. numYear, _ := numYearDecimal.Float64()
  956. if numYear > 10 {
  957. //获取多出来的整数年数据
  958. numYearDecimal = numYearDecimal.Mod(decimal.NewFromInt(10)).Div(decimal.NewFromInt(10))
  959. //计算赠送出来的月份
  960. numMonthDecimal := numYearDecimal.Mul(decimal.NewFromInt(12)).Round(0)
  961. numMonth, _ := numMonthDecimal.Float64()
  962. if numMonth > 0 {
  963. if remark != "" {
  964. remark += ";"
  965. }
  966. remark += "赠送时间为:" + numMonthDecimal.String() + "个月"
  967. }
  968. }
  969. //优惠金额
  970. if v.OriginalPrice > v.Price {
  971. differencePrice := v.OriginalPrice - v.Price
  972. differencePriceDecimal := decimal.NewFromFloat(differencePrice)
  973. if remark != "" {
  974. remark += ";"
  975. }
  976. remark += "优惠金额:" + differencePriceDecimal.String() + "元。"
  977. }
  978. remarkCell := dataRow.AddCell()
  979. remarkCell.SetValue(remark)
  980. remarkCell.SetStyle(style)
  981. }
  982. //服务套餐
  983. {
  984. tmpServiceList := v.Service
  985. if contractBusinessType == "代付合同" {
  986. if v.RelationContractList != nil && len(v.RelationContractList) > 0 {
  987. tmpServiceList = v.RelationContractList[0].Service
  988. }
  989. }
  990. cellServiceMap := make(map[int]string)
  991. for _, cellI := range serviceCellMap {
  992. cellServiceMap[cellI] = "否"
  993. }
  994. if tmpServiceList != nil && len(tmpServiceList) > 0 {
  995. permissionValues := []string{
  996. "FICC周报", "商品双周报+线上电话会讨论会<br/>(由弘则的研究员主持线上讨论)", "数据点评", "深度月报:包括宏观经济月报和下游草根调研月报+电话会讨论会<br/>(由弘则的研究员主持线上讨论)",
  997. }
  998. for _, item := range tmpServiceList {
  999. //ficc小套餐
  1000. if item.ServiceTemplateId == 2 {
  1001. for _, detail := range item.DetailList {
  1002. var tableCel request.AddContractServiceDetailReq
  1003. tmpErr := json.Unmarshal([]byte(detail.Col1), &tableCel)
  1004. if tmpErr != nil {
  1005. err = tmpErr
  1006. return
  1007. }
  1008. if tableCel.Value == "商品复盘" {
  1009. var tableCel2 request.AddContractServiceDetailReq
  1010. //获取品种列数据
  1011. tmpErr := contractService.GetProductCelData(*detail, &tableCel2)
  1012. if tmpErr != nil {
  1013. err = tmpErr
  1014. return
  1015. }
  1016. //tableCel2.Tag
  1017. for _, serviceId := range tableCel2.ValueId {
  1018. key := fmt.Sprint(item.ServiceTemplateId, "_product_permission_", serviceId)
  1019. if cellI, ok := serviceCellMap[key]; ok {
  1020. cellServiceMap[cellI] = "是"
  1021. }
  1022. }
  1023. } else if strings.Contains(strings.Join(permissionValues, ","), tableCel.Value) {
  1024. //获取品种列数据
  1025. var tableCel2 request.AddContractServiceDetailReq
  1026. tmpErr := contractService.GetProductCelData(*detail, &tableCel2)
  1027. if tmpErr != nil {
  1028. err = tmpErr
  1029. return
  1030. }
  1031. for _, serviceId := range tableCel2.ValueId {
  1032. key := fmt.Sprint(item.ServiceTemplateId, "_permission_", serviceId)
  1033. if cellI, ok := serviceCellMap[key]; ok {
  1034. cellServiceMap[cellI] = "是"
  1035. }
  1036. }
  1037. }
  1038. }
  1039. } else {
  1040. key := fmt.Sprint("service_template_", item.ServiceTemplateId)
  1041. if cellI, ok := serviceCellMap[key]; ok {
  1042. cellServiceMap[cellI] = "是"
  1043. }
  1044. }
  1045. }
  1046. }
  1047. //遍历所有套餐
  1048. for tmpStartCellI := customStartCellI; tmpStartCellI < startI; tmpStartCellI++ {
  1049. servicesCell := dataRow.AddCell()
  1050. cellValue, ok := cellServiceMap[tmpStartCellI]
  1051. if ok == false {
  1052. cellValue = "否"
  1053. }
  1054. servicesCell.SetValue(cellValue)
  1055. if cellValue == "是" { //勾选了话,标红处理
  1056. servicesCell.SetStyle(redStyle)
  1057. } else {
  1058. servicesCell.SetStyle(style)
  1059. }
  1060. }
  1061. }
  1062. }
  1063. }
  1064. err = xlsxFile.Save(downLoadnFilePath)
  1065. if err != nil {
  1066. br.Msg = "保存文件失败"
  1067. br.ErrMsg = "保存文件失败"
  1068. return
  1069. }
  1070. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1071. downloadFileName := "合同列表" + randStr + ".xlsx"
  1072. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1073. br.Ret = 200
  1074. br.Success = true
  1075. br.Msg = "导出成功"
  1076. }
  1077. // OperationList
  1078. // @Title 获取合同操作记录
  1079. // @Description 合同操作记录接口
  1080. // @Param ContractId query int true "合同id编号"
  1081. // @Success 200 {object} response.ContractOperationListResp
  1082. // @router /operation/list [get]
  1083. func (this *ContractController) OperationList() {
  1084. br := new(models.BaseResponse).Init()
  1085. defer func() {
  1086. this.Data["json"] = br
  1087. this.ServeJSON()
  1088. }()
  1089. sysUser := this.SysUser
  1090. if sysUser == nil {
  1091. br.Msg = "请登录"
  1092. br.ErrMsg = "请登录,SysUser Is Empty"
  1093. br.Ret = 408
  1094. return
  1095. }
  1096. //合同类型、产品类型、合同状态、更新时间、所选销售
  1097. //关键字:合同编号、客户名称,社会信用码
  1098. contractId, err := this.GetInt("ContractId")
  1099. if err != nil {
  1100. br.Msg = "获取合同编号失败"
  1101. br.ErrMsg = "获取合同编号失败,err:" + err.Error()
  1102. return
  1103. }
  1104. if contractId <= 0 {
  1105. br.Msg = "请传入合同编号"
  1106. br.ErrMsg = "请传入合同编号"
  1107. return
  1108. }
  1109. list, err := contract.GetContractOperationRListByContractId(contractId)
  1110. if err != nil {
  1111. br.Msg = "获取合同操作记录列表失败!"
  1112. br.ErrMsg = "获取合同操作记录列表失败,Err:" + err.Error()
  1113. return
  1114. }
  1115. contractOperationRecordList := make([]response.ContractOperationRecordListResp, 0)
  1116. for i := 0; i < len(list); i++ {
  1117. contractOperationRecord := response.ContractOperationRecordListResp{
  1118. Id: list[i].Id,
  1119. ContractId: list[i].ContractId,
  1120. Operation: list[i].Operation,
  1121. OpUserId: list[i].OpUserId,
  1122. OpUserName: list[i].OpUserName,
  1123. Remark: list[i].Remark,
  1124. ApprovalRecordId: list[i].ApprovalRecordId,
  1125. CreateTime: list[i].CreateTime,
  1126. CreateTimeStr: list[i].CreateTime.Format(utils.FormatDateTime),
  1127. }
  1128. contractOperationRecordList = append(contractOperationRecordList, contractOperationRecord)
  1129. }
  1130. br.Ret = 200
  1131. br.Success = true
  1132. br.Msg = "获取成功"
  1133. br.Data = response.ContractOperationListResp{
  1134. List: contractOperationRecordList,
  1135. }
  1136. }
  1137. // EditContract
  1138. // @Title 编辑合同
  1139. // @Description 编辑合同接口
  1140. // @Param request body request.EditContractReq true "type json string"
  1141. // @Success 200 {object} response.AddContractResp
  1142. // @router /edit [post]
  1143. func (this *ContractController) EditContract() {
  1144. br := new(models.BaseResponse).Init()
  1145. defer func() {
  1146. this.Data["json"] = br
  1147. this.ServeJSON()
  1148. }()
  1149. sysUser := this.SysUser
  1150. if sysUser == nil {
  1151. br.Msg = "请登录"
  1152. br.ErrMsg = "请登录,SysUser Is Empty"
  1153. br.Ret = 408
  1154. return
  1155. }
  1156. productId := services.GetProductId(sysUser.RoleTypeCode)
  1157. if productId == 0 {
  1158. br.Msg = "账户异常"
  1159. br.ErrMsg = "账户异常,当前账户类型为:" + sysUser.RoleTypeCode
  1160. br.Ret = 408
  1161. return
  1162. }
  1163. var req request.EditContractReq
  1164. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1165. if err != nil {
  1166. br.Msg = "参数解析异常!"
  1167. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1168. return
  1169. }
  1170. if req.ContractId <= 0 {
  1171. br.Msg = "合同编号必传!"
  1172. br.ErrMsg = "合同编号必传!"
  1173. return
  1174. }
  1175. // 限制一下合同金额, 目前只支持人民币转大写只支持到千亿, 虽然生产使用中不可能到这么大, 但还是加上吧 =_=!
  1176. maxPrice := float64(1000000000000)
  1177. if req.OriginalPrice >= maxPrice || req.Price >= maxPrice {
  1178. br.Msg = "合同金额过大, 请核验金额"
  1179. return
  1180. }
  1181. contractInfo, err, errMsg := contractService.EditContract(req, sysUser)
  1182. if err != nil {
  1183. br.Msg = "修改合同失败!"
  1184. if errMsg != "" {
  1185. br.Msg = errMsg
  1186. }
  1187. br.ErrMsg = "修改合同失败,Err:" + err.Error()
  1188. return
  1189. }
  1190. msg := "修改成功"
  1191. //如果发起重新审核,那么
  1192. if req.ReAudit {
  1193. tmpErr, errMsg := contractService.Apply(contractInfo.ContractId)
  1194. if tmpErr != nil {
  1195. br.Msg = "发起重申失败!"
  1196. if errMsg != "" {
  1197. br.Msg = errMsg
  1198. }
  1199. br.ErrMsg = "发起重申失败,Err:" + tmpErr.Error()
  1200. return
  1201. }
  1202. msg = "发起重申成功"
  1203. }
  1204. br.Ret = 200
  1205. br.Success = true
  1206. br.Msg = msg
  1207. br.Data = response.AddContractResp{
  1208. ContractId: contractInfo.ContractId,
  1209. }
  1210. }
  1211. // Delete
  1212. // @Title 删除合同
  1213. // @Description 删除合同接口
  1214. // @Param ContractId query int true "合同id"
  1215. // @Success Ret=200 删除成功
  1216. // @router /delete [get]
  1217. func (this *ContractController) Delete() {
  1218. br := new(models.BaseResponse).Init()
  1219. defer func() {
  1220. this.Data["json"] = br
  1221. this.ServeJSON()
  1222. }()
  1223. sysUser := this.SysUser
  1224. if sysUser == nil {
  1225. br.Msg = "请登录"
  1226. br.ErrMsg = "请登录,SysUser Is Empty"
  1227. br.Ret = 408
  1228. return
  1229. }
  1230. contractId, _ := this.GetInt("ContractId")
  1231. //合同id
  1232. if contractId <= 0 {
  1233. br.Msg = "合同id必传!"
  1234. br.ErrMsg = "合同id必传"
  1235. return
  1236. }
  1237. err := contractService.DeleteContract(contractId, sysUser)
  1238. if err != nil {
  1239. br.Msg = "修改合同失败!"
  1240. br.ErrMsg = "修改合同失败,Err:" + err.Error()
  1241. return
  1242. }
  1243. br.Ret = 200
  1244. br.Success = true
  1245. br.Msg = "删除成功"
  1246. return
  1247. }
  1248. // Invalid
  1249. // @Title 作废合同
  1250. // @Description 作废合同接口
  1251. // @Param ContractId query int true "合同id"
  1252. // @Success Ret=200 作废成功
  1253. // @router /invalid [get]
  1254. func (this *ContractController) Invalid() {
  1255. br := new(models.BaseResponse).Init()
  1256. defer func() {
  1257. this.Data["json"] = br
  1258. this.ServeJSON()
  1259. }()
  1260. sysUser := this.SysUser
  1261. if sysUser == nil {
  1262. br.Msg = "请登录"
  1263. br.ErrMsg = "请登录,SysUser Is Empty"
  1264. br.Ret = 408
  1265. return
  1266. }
  1267. contractId, _ := this.GetInt("ContractId")
  1268. //合同id
  1269. if contractId <= 0 {
  1270. br.Msg = "合同id必传!"
  1271. br.ErrMsg = "合同id必传"
  1272. return
  1273. }
  1274. err := contractService.InvalidContract(contractId, sysUser)
  1275. if err != nil {
  1276. br.Msg = "修改合同失败!"
  1277. br.ErrMsg = "修改合同失败,Err:" + err.Error()
  1278. return
  1279. }
  1280. br.Ret = 200
  1281. br.Success = true
  1282. br.Msg = "作废成功"
  1283. return
  1284. }
  1285. // UploadCheckBackFile
  1286. // @Title 上传签回附件
  1287. // @Description 上传签回附件接口
  1288. // @Param request body request.UploadCheckBackFileReq true "type json string"
  1289. // @Success Ret=200 上传成功
  1290. // @router /upload_check_back_file [post]
  1291. func (this *ContractController) UploadCheckBackFile() {
  1292. br := new(models.BaseResponse).Init()
  1293. defer func() {
  1294. this.Data["json"] = br
  1295. this.ServeJSON()
  1296. }()
  1297. sysUser := this.SysUser
  1298. if sysUser == nil {
  1299. br.Msg = "请登录"
  1300. br.ErrMsg = "请登录,SysUser Is Empty"
  1301. br.Ret = 408
  1302. return
  1303. }
  1304. //var req request.UploadCheckBackFileReq
  1305. //err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1306. //if err != nil {
  1307. // br.Msg = "参数解析异常!"
  1308. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1309. // return
  1310. //}
  1311. ////合同编号
  1312. //if req.ContractId <= 0 {
  1313. // br.Msg = "请传入合同编号!"
  1314. // br.ErrMsg = "请传入合同编号"
  1315. // return
  1316. //}
  1317. //
  1318. //if req.FileUrl == "" {
  1319. // br.Msg = "请先上传附件!"
  1320. // br.ErrMsg = "请先上传附件"
  1321. // return
  1322. //}
  1323. contractIdStr := this.Ctx.Request.Form.Get("ContractId")
  1324. if contractIdStr == "" {
  1325. br.Msg = "合同ID必传!"
  1326. br.ErrMsg = "合同ID必传,Err"
  1327. return
  1328. }
  1329. contractId, err := strconv.Atoi(contractIdStr)
  1330. if err != nil {
  1331. br.Msg = "合同ID异常!"
  1332. br.ErrMsg = "合同ID异常,Err:" + err.Error()
  1333. return
  1334. }
  1335. fileMulti, h, err := this.GetFile("file")
  1336. if err != nil {
  1337. br.Msg = "获取资源信息失败"
  1338. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  1339. return
  1340. }
  1341. //合同编号
  1342. if contractId <= 0 {
  1343. br.Msg = "请传入合同编号!"
  1344. br.ErrMsg = "请传入合同编号"
  1345. return
  1346. }
  1347. ext := path.Ext(h.Filename)
  1348. resourceUrl, err := contractService.UploadCheckBackFile(contractId, ext, fileMulti, this.SysUser)
  1349. if err != nil {
  1350. br.Msg = "更新失败!"
  1351. br.ErrMsg = "更新失败" + err.Error()
  1352. return
  1353. }
  1354. //更新用印中的签回合同
  1355. _, _ = seal.UploadCheckBackFile(contractId, resourceUrl, this.SysUser)
  1356. br.Ret = 200
  1357. br.Success = true
  1358. br.Msg = "上传成功"
  1359. }
  1360. // UploadRescindFile
  1361. // @Title 上传解约附件
  1362. // @Description 上传解约附件接口
  1363. // @Param request body request.UploadRescindFileReq true "type json string"
  1364. // @Success Ret=200 上传成功
  1365. // @router /upload_rescind_file [post]
  1366. func (this *ContractController) UploadRescindFile() {
  1367. br := new(models.BaseResponse).Init()
  1368. defer func() {
  1369. this.Data["json"] = br
  1370. this.ServeJSON()
  1371. }()
  1372. sysUser := this.SysUser
  1373. if sysUser == nil {
  1374. br.Msg = "请登录"
  1375. br.ErrMsg = "请登录,SysUser Is Empty"
  1376. br.Ret = 408
  1377. return
  1378. }
  1379. //var req request.UploadRescindFileReq
  1380. //err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1381. //if err != nil {
  1382. // br.Msg = "参数解析异常!"
  1383. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1384. // return
  1385. //}
  1386. ////合同编号
  1387. //if req.ContractId <= 0 {
  1388. // br.Msg = "请传入合同编号!"
  1389. // br.ErrMsg = "请传入合同编号"
  1390. // return
  1391. //}
  1392. //
  1393. //if req.FileUrl == "" {
  1394. // br.Msg = "请先上传附件!"
  1395. // br.ErrMsg = "请先上传附件"
  1396. // return
  1397. //}
  1398. contractIdStr := this.Ctx.Request.Form.Get("ContractId")
  1399. if contractIdStr == "" {
  1400. br.Msg = "合同ID必传!"
  1401. br.ErrMsg = "合同ID必传,Err"
  1402. return
  1403. }
  1404. contractId, err := strconv.Atoi(contractIdStr)
  1405. if err != nil {
  1406. br.Msg = "合同ID异常!"
  1407. br.ErrMsg = "合同ID异常,Err:" + err.Error()
  1408. return
  1409. }
  1410. fileMulti, h, err := this.GetFile("file")
  1411. if err != nil {
  1412. br.Msg = "获取资源信息失败"
  1413. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  1414. return
  1415. }
  1416. //合同编号
  1417. if contractId <= 0 {
  1418. br.Msg = "请传入合同编号!"
  1419. br.ErrMsg = "请传入合同编号"
  1420. return
  1421. }
  1422. ext := path.Ext(h.Filename)
  1423. err = contractService.UploadRescindFile(contractId, ext, fileMulti, this.SysUser)
  1424. br.Ret = 200
  1425. br.Success = true
  1426. br.Msg = "上传成功"
  1427. }
  1428. // Detail
  1429. // @Title 获取合同详情
  1430. // @Description 获取合同详情接口
  1431. // @Param ContractId query int true "合同id"
  1432. // @Success 200 {object} contract.ContractDetail
  1433. // @router /detail [get]
  1434. func (this *ContractController) Detail() {
  1435. br := new(models.BaseResponse).Init()
  1436. defer func() {
  1437. this.Data["json"] = br
  1438. this.ServeJSON()
  1439. }()
  1440. sysUser := this.SysUser
  1441. if sysUser == nil {
  1442. br.Msg = "请登录"
  1443. br.ErrMsg = "请登录,SysUser Is Empty"
  1444. br.Ret = 408
  1445. return
  1446. }
  1447. //合同类型、产品类型、合同状态、更新时间、所选销售
  1448. //关键字:合同编号、客户名称,社会信用码
  1449. contractId, _ := this.GetInt("ContractId")
  1450. //合同id
  1451. if contractId <= 0 {
  1452. br.Msg = "合同id必传!"
  1453. br.ErrMsg = "合同id必传"
  1454. return
  1455. }
  1456. contractInfo, err := contractService.GetContractDetail(contractId)
  1457. if err != nil {
  1458. br.Msg = "获取合同详情失败!"
  1459. br.ErrMsg = "获取合同详情失败,ERR:" + err.Error()
  1460. return
  1461. }
  1462. // CRM8.8-权益主客观合并
  1463. if contractInfo.ProductId == 2 {
  1464. mergeList := contractService.EquityMergeSubjectAndObject(contractInfo.Service)
  1465. contractInfo.Service = mergeList
  1466. // 关联合同同样合并
  1467. for i, v := range contractInfo.RelationContractDetailList {
  1468. relationMergeList := contractService.EquityMergeSubjectAndObject(v.Service)
  1469. contractInfo.RelationContractDetailList[i].Service = relationMergeList
  1470. }
  1471. }
  1472. contractInfo.StartDateStr = contractInfo.StartDate.Format(utils.FormatDate)
  1473. contractInfo.EndDateStr = contractInfo.EndDate.Format(utils.FormatDate)
  1474. contractInfo.ModifyTimeStr = contractInfo.ModifyTime.Format(utils.FormatDateTime)
  1475. contractInfo.CreateTimeStr = contractInfo.CreateTime.Format(utils.FormatDateTime)
  1476. //合同中包含的产品权限
  1477. isNeedPermission := false //是否需要列出来套餐中的详细权限
  1478. for _, service := range contractInfo.Service {
  1479. if service.ServiceTemplateId == 2 { //小套餐才需要列出来详细的权限
  1480. isNeedPermission = true
  1481. }
  1482. }
  1483. var permissionLookListResp = make([]*contract.PermissionLookList, 0)
  1484. if isNeedPermission {
  1485. checkPermissionMap, tErr := contractService.GetServicePermissionMap(contractInfo.Service)
  1486. if tErr == nil {
  1487. permissionLookListMap := make(map[string][]*contract.PermissionLookItem)
  1488. var permissionIds []string
  1489. for _, v := range checkPermissionMap {
  1490. permissionIds = append(permissionIds, strconv.Itoa(v))
  1491. }
  1492. permissionIdStr := strings.Join(permissionIds, ",")
  1493. charPermissions, tErr1 := company.GetPermissionLookItemsSandO(permissionIdStr)
  1494. if tErr1 == nil {
  1495. for _, v := range charPermissions {
  1496. tmp := new(contract.PermissionLookItem)
  1497. tmp.ClassifyName = v.ClassifyName
  1498. tmp.PermissionName = v.PermissionName
  1499. tmp.ChartPermissionId = v.ChartPermissionId
  1500. permissionLookListMap[v.ClassifyName] = append(permissionLookListMap[v.ClassifyName], tmp)
  1501. }
  1502. classifyNameList, tErr2 := company.GetChartPermissionFirst()
  1503. if tErr2 == nil {
  1504. for _, v := range classifyNameList {
  1505. if perList, ok := permissionLookListMap[v.ClassifyName]; ok {
  1506. permissionLookListRespItem := &contract.PermissionLookList{
  1507. ClassifyName: v.ClassifyName,
  1508. Items: perList,
  1509. }
  1510. permissionLookListResp = append(permissionLookListResp, permissionLookListRespItem)
  1511. }
  1512. }
  1513. }
  1514. }
  1515. }
  1516. }
  1517. contractInfo.PermissionLookList = permissionLookListResp
  1518. br.Ret = 200
  1519. br.Success = true
  1520. br.Msg = "获取成功"
  1521. br.Data = contractInfo
  1522. }
  1523. //Export
  1524. //@Title 合同列表数据导出
  1525. //@Description 合同列表数据导出接口
  1526. //@Description 合同列表接口
  1527. //@Param ContractType query string false "合同类型,枚举值:'新签合同','续约合同','补充协议'"
  1528. //@Param ContractStatus query string false "合同状态,枚举值:'待提交','待审批','已撤回','已审批','已驳回','已作废'"
  1529. //@Param ProductId query int false "客户类型:传0或者不传为当前账号权限,1 代表是:ficc;2 代表是:权益"
  1530. //@Param ModifyStartTime query string false "服务更新时间的选择开始时间,格式:2021-05-23 00:00:00"
  1531. //@Param ModifyEndTime query string false "服务更新时间的选择结束时间,格式:2021-05-26 23:59:59"
  1532. //@Param SellerId query string false "选择的销售id"
  1533. //@Param Keyword query string false "搜索关键字"
  1534. //@Success 200 {object} response.ContractListResp
  1535. //@router /export [get]
  1536. //func (this *ContractController) Export() {
  1537. // br := new(models.BaseResponse).Init()
  1538. // defer func() {
  1539. // this.Data["json"] = br
  1540. // this.ServeJSON()
  1541. // }()
  1542. // sysUser := this.SysUser
  1543. // if sysUser == nil {
  1544. // br.Msg = "请登录"
  1545. // br.ErrMsg = "请登录,SysUser Is Empty"
  1546. // br.Ret = 408
  1547. // return
  1548. // }
  1549. //
  1550. // contractType := this.GetString("ContractType")
  1551. // contractStatus := this.GetString("ContractStatus")
  1552. // productId, _ := this.GetInt("ProductId")
  1553. // modifyStartTime := this.GetString("ModifyStartTime")
  1554. // modifyEndTime := this.GetString("ModifyEndTime")
  1555. // sellerIds := this.GetString("SellerId")
  1556. // keyword := this.GetString("Keyword")
  1557. //
  1558. // condition := ""
  1559. // pars := make([]interface{}, 0)
  1560. //
  1561. // //如果不是超管或者合规,那么只能查看自己的合同
  1562. // if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1563. // condition += ` AND product_id = 1 AND status not in ("待提交","已撤回") `
  1564. // } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1565. // condition += ` AND product_id = 2 AND status not in ("待提交","已撤回") `
  1566. // } else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超管可查看所有状态的合同(除过已撤回、待提交状态合同),可下载所有状态的合同
  1567. // condition += ` AND status not in ("待提交","已撤回") `
  1568. // } else {
  1569. // if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1570. // condition += ` AND seller_id = ? `
  1571. // pars = append(pars, sysUser.AdminId)
  1572. // }
  1573. // }
  1574. //
  1575. // //需要下载的 产品 切片
  1576. // productSlice := make([]int, 0)
  1577. //
  1578. // //合同类型、、更新时间、所选销售
  1579. // //关键字:合同编号、客户名称,社会信用码
  1580. // if contractType != "" {
  1581. // condition += ` AND contract_type = ? `
  1582. // pars = append(pars, contractType)
  1583. // }
  1584. // //合同状态
  1585. // if contractStatus != "" {
  1586. // condition += ` AND status = ? `
  1587. // pars = append(pars, contractStatus)
  1588. // }
  1589. //
  1590. // //产品类型
  1591. // if productId > 0 {
  1592. // condition += ` AND product_id = ? `
  1593. // pars = append(pars, productId)
  1594. //
  1595. // productSlice = append(productSlice, productId)
  1596. // } else {
  1597. // nowProductId := services.GetProductId(sysUser.RoleTypeCode)
  1598. // if nowProductId > 0 {
  1599. // productSlice = append(productSlice, nowProductId)
  1600. // } else {
  1601. // productSlice = append(productSlice, 1)
  1602. // productSlice = append(productSlice, 2)
  1603. // }
  1604. // }
  1605. // //所选销售
  1606. // if sellerIds != "" {
  1607. // condition += ` AND seller_id IN (` + sellerIds + `) `
  1608. // }
  1609. // //更新开始时间
  1610. // if modifyStartTime != "" {
  1611. // condition += ` AND modify_time >= ? `
  1612. // pars = append(pars, modifyStartTime)
  1613. // }
  1614. // //更新结束时间
  1615. // if modifyEndTime != "" {
  1616. // condition += ` AND modify_time <= ? `
  1617. // pars = append(pars, modifyEndTime)
  1618. // }
  1619. // //关键字
  1620. // if keyword != "" {
  1621. // condition += ` AND (contract_code LIKE '%` + keyword + `%' OR company_name LIKE '%` + keyword + `%' OR credit_code LIKE '%` + keyword + `%' ) `
  1622. // }
  1623. //
  1624. // //取 一万 条合同数据
  1625. // list, err := contract.GetContractList(condition, pars, 0, 10000)
  1626. // if err != nil {
  1627. // br.Msg = "获取合同列表失败!"
  1628. // br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
  1629. // return
  1630. // }
  1631. // //获取合同套餐服务列表
  1632. // serviceTemplateList, err := contract.GetAllContractServiceTemplateList()
  1633. // if err != nil {
  1634. // br.Msg = "获取合同套餐服务列表失败!"
  1635. // br.ErrMsg = "获取合同套餐服务列表失败,Err:" + err.Error()
  1636. // return
  1637. // }
  1638. // templateTitleMap := make(map[int]string)
  1639. // for _, serviceTemplate := range serviceTemplateList {
  1640. // templateTitleMap[serviceTemplate.ServiceTemplateId] = serviceTemplate.Title
  1641. // }
  1642. //
  1643. // for i := 0; i < len(list); i++ {
  1644. // item := list[i]
  1645. // list[i].StartDateStr = item.StartDate.Format(utils.FormatDate)
  1646. // list[i].EndDateStr = item.EndDate.Format(utils.FormatDate)
  1647. //
  1648. // list[i].CreateTimeStr = item.CreateTime.Format(utils.FormatDateTime)
  1649. // list[i].ModifyTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
  1650. //
  1651. // //服务列表
  1652. // serviceList, err := contract.GetContractServiceAndDetailList(item.ContractId)
  1653. // if err != nil {
  1654. // br.Msg = "获取失败"
  1655. // br.ErrMsg = "查找合同服务异常,Err:" + err.Error()
  1656. // return
  1657. // }
  1658. // for i := 0; len(serviceList) > i; i++ {
  1659. // if serviceList[i].HasDetail == "是" {
  1660. // list, detailErr := contract.GetContractServiceDetailListByServiceId(serviceList[i].ContractServiceId)
  1661. // if detailErr != nil {
  1662. // br.Msg = "获取失败"
  1663. // br.ErrMsg = "查找合同服务详情异常,Err:" + err.Error()
  1664. // return
  1665. // }
  1666. //
  1667. // //套餐名称
  1668. // serviceList[i].DetailList = list
  1669. // if title, ok := templateTitleMap[serviceList[i].ServiceTemplateId]; ok {
  1670. // serviceList[i].Title = title
  1671. // }
  1672. // }
  1673. // }
  1674. // list[i].Service = serviceList
  1675. // }
  1676. //
  1677. // //生成excel文件
  1678. // dir, err := os.Executable()
  1679. // exPath := filepath.Dir(dir)
  1680. // downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1681. // xlsxFile := xlsx.NewFile()
  1682. // if err != nil {
  1683. // br.Msg = "生成文件失败"
  1684. // br.ErrMsg = "生成文件失败"
  1685. // return
  1686. // }
  1687. //
  1688. // //设置默认字体和文字大小
  1689. // xlsx.SetDefaultFont(12, "宋体")
  1690. //
  1691. // //定义边框样式
  1692. // border := xlsx.NewBorder("thin", "thin", "thin", "thin")
  1693. // //定义文字排版样式
  1694. // alignment := xlsx.Alignment{
  1695. // Horizontal: "center",
  1696. // Vertical: "center",
  1697. // WrapText: true,
  1698. // }
  1699. //
  1700. // //普通样式
  1701. // style := xlsx.NewStyle()
  1702. // style.Alignment = alignment
  1703. // style.ApplyAlignment = true
  1704. // style.Border = *border
  1705. //
  1706. // //标红文字,便于查看哪些产品被勾选
  1707. // redStyle := xlsx.NewStyle()
  1708. // redStyle.Alignment = alignment
  1709. // redStyle.ApplyAlignment = true
  1710. // redStyle.Font.Color = "ff0000"
  1711. // //定义底色需要标黄的 单元格颜色
  1712. // redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
  1713. // redStyle.Fill = redFill
  1714. // redStyle.Border = *border
  1715. //
  1716. // //标题样式
  1717. // titleStyle := xlsx.NewStyle()
  1718. // titleFont := xlsx.NewFont(14, "宋体")
  1719. // titleFont.Bold = true
  1720. // titleStyle.Font = *titleFont
  1721. // titleStyle.Alignment = alignment
  1722. // titleStyle.Border = *border
  1723. //
  1724. // //titleStyle.ApplyAlignment = true
  1725. //
  1726. // //表头
  1727. // headerStyle := xlsx.NewStyle()
  1728. // headerFont := xlsx.NewFont(12, "宋体")
  1729. // headerFont.Bold = true
  1730. // headerStyle.Font = *headerFont
  1731. // headerStyle.Alignment = alignment
  1732. // headerStyle.ApplyAlignment = true
  1733. // headerStyle.Border = *border
  1734. //
  1735. // defer func() {
  1736. // os.Remove(downLoadnFilePath)
  1737. // }()
  1738. //
  1739. // //遍历所拥有的的产品权限,然后插入到对应的sheet表单中
  1740. // for pidIndex := 0; pidIndex < len(productSlice); pidIndex++ {
  1741. // productId = productSlice[pidIndex]
  1742. // //表单名称
  1743. // sheetName := "合同数据"
  1744. // switch productId {
  1745. // case 1:
  1746. // sheetName = "ficc合同信息"
  1747. // case 2:
  1748. // sheetName = "权益合同信息"
  1749. // }
  1750. // //新增一个sheet表单
  1751. // sheel, err := xlsxFile.AddSheet(sheetName)
  1752. // if err != nil {
  1753. // br.Msg = "新增Sheet失败"
  1754. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1755. // return
  1756. // }
  1757. // //设置列宽
  1758. // sheel.SetColWidth(0, 0, 28)
  1759. // sheel.SetColWidth(1, 1, 30)
  1760. // sheel.SetColWidth(2, 2, 18)
  1761. // sheel.SetColWidth(3, 3, 18)
  1762. // sheel.SetColWidth(4, 4, 35)
  1763. // sheel.SetColWidth(5, 6, 20)
  1764. // sheel.SetColWidth(7, 7, 40)
  1765. // sheel.SetColWidth(7, 35, 30)
  1766. //
  1767. // //标题行
  1768. // titleRow := sheel.AddRow()
  1769. // titleRow.SetHeight(30)
  1770. //
  1771. // //合同信息列
  1772. // titleCell := titleRow.AddCell()
  1773. // titleCell.HMerge = 7 //向右合并列数,不包括自身列
  1774. // //遍历去添加需要合并的列
  1775. // for i := 0; i < 7; i++ {
  1776. // titleRow.AddCell()
  1777. // }
  1778. //
  1779. // //报表标题名称
  1780. // titleCell.SetValue("合同信息")
  1781. // titleCell.SetStyle(titleStyle)
  1782. //
  1783. // startI := 8
  1784. // customStartCellI := 8
  1785. //
  1786. // serviceSlice := make([]string, 0)
  1787. // serviceCellMap := make(map[string]int)
  1788. //
  1789. // //获取所有套餐列表
  1790. // {
  1791. // serviceList, err := getServiceTemplateList(productId)
  1792. // if err != nil {
  1793. // br.Msg = "查询套餐类型失败"
  1794. // br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1795. // return
  1796. // }
  1797. // for i := 0; i < len(serviceList); i++ {
  1798. // //需要向右合并添加的列数
  1799. // addCellNum := 0
  1800. //
  1801. // item := serviceList[i]
  1802. // //套餐服务列
  1803. // servicesCell := titleRow.AddCell()
  1804. // //套餐名称
  1805. // servicesCell.SetValue(item.Title)
  1806. // servicesCell.SetStyle(titleStyle)
  1807. //
  1808. // //ficc小套餐
  1809. // if item.ServiceTemplateId == 2 {
  1810. // productPermission := make(map[int]string)
  1811. // productPermission[1] = "每日宏观商品复盘"
  1812. // productPermission[2] = "能化专栏《化里化外》"
  1813. // productPermission[3] = "股债日评"
  1814. // productPermission[4] = "黑色专栏《知白守黑》"
  1815. // productPermission[5] = "有色专栏《有声有色》"
  1816. // for id, name := range productPermission {
  1817. // key := fmt.Sprint(item.ServiceTemplateId, "_product_permission_", id)
  1818. // serviceCellMap[key] = startI
  1819. // serviceSlice = append(serviceSlice, name)
  1820. // startI++
  1821. // addCellNum++
  1822. // }
  1823. //
  1824. // permissionList := make([]*company.PermissionSetItem, 0)
  1825. // for _, v := range utils.PermissionFiccClassifyArr {
  1826. // items, err := company.GetPermissionSetItems(1, v)
  1827. // if err != nil {
  1828. // br.Msg = "获取失败"
  1829. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  1830. // return
  1831. // }
  1832. // permissionList = append(permissionList, items...)
  1833. // }
  1834. //
  1835. // //权限列表
  1836. // for j := 0; j < len(permissionList); j++ {
  1837. // key := fmt.Sprint(item.ServiceTemplateId, "_permission_", permissionList[j].ChartPermissionId)
  1838. // serviceCellMap[key] = startI
  1839. // serviceSlice = append(serviceSlice, permissionList[j].PermissionName)
  1840. // startI++
  1841. // addCellNum++
  1842. // }
  1843. // //因为自己本身有一列了,所以在最后增加列的时候,需要减去自身列
  1844. // addCellNum = addCellNum - 1
  1845. // if addCellNum > 0 {
  1846. // for tmpAddCellNum := 0; tmpAddCellNum < addCellNum; tmpAddCellNum++ {
  1847. // titleRow.AddCell()
  1848. // }
  1849. // servicesCell.HMerge = addCellNum //向右合并列数,不包括自身列
  1850. // }
  1851. // continue
  1852. // } else {
  1853. // if item.Children != nil && len(item.Children) > 0 {
  1854. // for j := 0; j < len(item.Children); j++ {
  1855. // key := fmt.Sprint("service_template_", item.Children[j].ServiceTemplateId)
  1856. // serviceCellMap[key] = startI
  1857. // serviceSlice = append(serviceSlice, item.Children[j].Title)
  1858. // startI++
  1859. // addCellNum++
  1860. // }
  1861. // //因为自己本身有一列了,所以在最后增加列的时候,需要减去自身列
  1862. // addCellNum = addCellNum - 1
  1863. // if addCellNum > 0 {
  1864. // for tmpAddCellNum := 0; tmpAddCellNum < addCellNum; tmpAddCellNum++ {
  1865. // titleRow.AddCell()
  1866. // }
  1867. // servicesCell.HMerge = addCellNum //向右合并列数,不包括自身列
  1868. // }
  1869. // } else {
  1870. // key := fmt.Sprint("service_template_", item.ServiceTemplateId)
  1871. // serviceCellMap[key] = startI
  1872. // serviceSlice = append(serviceSlice, item.Title)
  1873. // startI++
  1874. // }
  1875. // }
  1876. // }
  1877. // }
  1878. //
  1879. // //表头
  1880. // headerRow := sheel.AddRow()
  1881. // headerRow.SetHeight(24)
  1882. //
  1883. // //合同基础信息
  1884. // {
  1885. // codeHeaderCell := headerRow.AddCell()
  1886. // codeHeaderCell.SetValue("合同编号")
  1887. // codeHeaderCell.SetStyle(headerStyle)
  1888. //
  1889. // companyHeaderCell := headerRow.AddCell()
  1890. // companyHeaderCell.SetValue("客户名称")
  1891. // companyHeaderCell.SetStyle(headerStyle)
  1892. //
  1893. // typeHeaderCell := headerRow.AddCell()
  1894. // typeHeaderCell.SetValue("合同类型")
  1895. // typeHeaderCell.SetStyle(headerStyle)
  1896. //
  1897. // priceHeaderCell := headerRow.AddCell()
  1898. // priceHeaderCell.SetValue("合同金额")
  1899. // priceHeaderCell.SetStyle(headerStyle)
  1900. //
  1901. // dateHeaderCell := headerRow.AddCell()
  1902. // dateHeaderCell.SetValue("合同有效期")
  1903. // dateHeaderCell.SetStyle(headerStyle)
  1904. //
  1905. // sellerHeaderCell := headerRow.AddCell()
  1906. // sellerHeaderCell.SetValue("销售")
  1907. // sellerHeaderCell.SetStyle(headerStyle)
  1908. //
  1909. // statusHeaderCell := headerRow.AddCell()
  1910. // statusHeaderCell.SetValue("合同状态")
  1911. // statusHeaderCell.SetStyle(headerStyle)
  1912. //
  1913. // remarkHeaderCell := headerRow.AddCell()
  1914. // remarkHeaderCell.SetValue("备注")
  1915. // remarkHeaderCell.SetStyle(headerStyle)
  1916. // }
  1917. //
  1918. // //添加服务套餐名称
  1919. // for _, service := range serviceSlice {
  1920. // cell := headerRow.AddCell()
  1921. // cell.SetValue(service)
  1922. // cell.SetStyle(headerStyle)
  1923. // }
  1924. //
  1925. // for _, v := range list {
  1926. // //如果当前合同不是该产品
  1927. // if v.ProductId != productId {
  1928. // continue
  1929. // }
  1930. // dataRow := sheel.AddRow()
  1931. // dataRow.SetHeight(24)
  1932. //
  1933. // //合同基础信息
  1934. // {
  1935. // codeCell := dataRow.AddCell()
  1936. // codeCell.SetValue(v.ContractCode)
  1937. // codeCell.SetStyle(style)
  1938. //
  1939. // companyCell := dataRow.AddCell()
  1940. // companyCell.SetValue(v.CompanyName)
  1941. // companyCell.SetStyle(style)
  1942. //
  1943. // typeCell := dataRow.AddCell()
  1944. // typeCell.SetValue(v.ContractType)
  1945. // typeCell.SetStyle(style)
  1946. //
  1947. // priceCell := dataRow.AddCell()
  1948. // priceCell.SetValue(v.Price)
  1949. // priceCell.SetStyle(style)
  1950. //
  1951. // dateCell := dataRow.AddCell()
  1952. // dateCell.SetValue(fmt.Sprint(v.StartDate.Format(utils.FormatDate), " 至 ", v.EndDate.Format(utils.FormatDate)))
  1953. // dateCell.SetStyle(style)
  1954. //
  1955. // sellerCell := dataRow.AddCell()
  1956. // sellerCell.SetValue(v.SellerName)
  1957. // sellerCell.SetStyle(style)
  1958. //
  1959. // statusCell := dataRow.AddCell()
  1960. // statusCell.SetValue(v.Status)
  1961. // statusCell.SetStyle(style)
  1962. //
  1963. // //备注:该字段由三部分拼接:服务内容中的补充内容+赠送时间+优惠金额
  1964. // //补充内容直接取该字段内容;
  1965. // //赠送时间以年为单位,超过整年的月份作为赠送月份,如14个月即为赠送2个月;
  1966. // //优惠金额等于原价-优惠后价格=优惠价格
  1967. //
  1968. // //补充内容
  1969. // var remark string
  1970. // if v.Remark != "" {
  1971. // remark += "补充内容:" + v.Remark
  1972. // }
  1973. //
  1974. // //赠送时间
  1975. // //合同结束日期与合同开始日期的时间差(小时差)
  1976. // newDecimal := decimal.NewFromFloat(v.EndDate.Sub(v.StartDate).Hours())
  1977. // //分母为365天 * 24 小时
  1978. // newDecimal2 := decimal.NewFromInt(24 * 365)
  1979. // //计算出来相差多少年,保留一位小数(四舍五入)
  1980. // numYearDecimal := newDecimal.Div(newDecimal2).Round(1).Mul(decimal.NewFromInt(10))
  1981. // //如果大于1年,那么才去判断是否赠送
  1982. // numYear, _ := numYearDecimal.Float64()
  1983. // if numYear > 10 {
  1984. // //获取多出来的整数年数据
  1985. // numYearDecimal = numYearDecimal.Mod(decimal.NewFromInt(10)).Div(decimal.NewFromInt(10))
  1986. // //计算赠送出来的月份
  1987. // numMonthDecimal := numYearDecimal.Mul(decimal.NewFromInt(12)).Round(0)
  1988. // numMonth, _ := numMonthDecimal.Float64()
  1989. // if numMonth > 0 {
  1990. // if remark != "" {
  1991. // remark += ";"
  1992. // }
  1993. // remark += "赠送时间为:" + numMonthDecimal.String() + "个月"
  1994. // }
  1995. // }
  1996. // //优惠金额
  1997. // if v.OriginalPrice > v.Price {
  1998. // differencePrice := v.OriginalPrice - v.Price
  1999. // differencePriceDecimal := decimal.NewFromFloat(differencePrice)
  2000. //
  2001. // if remark != "" {
  2002. // remark += ";"
  2003. // }
  2004. // remark += "优惠金额:" + differencePriceDecimal.String() + "元。"
  2005. // }
  2006. // remarkCell := dataRow.AddCell()
  2007. // remarkCell.SetValue(remark)
  2008. // remarkCell.SetStyle(style)
  2009. // }
  2010. //
  2011. // //服务套餐
  2012. // {
  2013. // cellServiceMap := make(map[int]string)
  2014. // for _, cellI := range serviceCellMap {
  2015. // cellServiceMap[cellI] = "否"
  2016. // }
  2017. //
  2018. // if v.Service != nil && len(v.Service) > 0 {
  2019. // permissionValues := []string{
  2020. // "FICC周报", "商品双周报+线上电话会讨论会<br/>(由弘则的研究员主持线上讨论)", "数据点评", "深度月报:包括宏观经济月报和下游草根调研月报+电话会讨论会<br/>(由弘则的研究员主持线上讨论)",
  2021. // }
  2022. // for _, item := range v.Service {
  2023. // //ficc小套餐
  2024. // if item.ServiceTemplateId == 2 {
  2025. // for _, detail := range item.DetailList {
  2026. // var tableCel request.AddContractServiceDetailReq
  2027. // tmpErr := json.Unmarshal([]byte(detail.Col1), &tableCel)
  2028. // if tmpErr != nil {
  2029. // err = tmpErr
  2030. // return
  2031. // }
  2032. // if tableCel.Value == "商品复盘" {
  2033. // var tableCel2 request.AddContractServiceDetailReq
  2034. // //获取品种列数据
  2035. // tmpErr := contractService.GetProductCelData(*detail, &tableCel2)
  2036. // if tmpErr != nil {
  2037. // err = tmpErr
  2038. // return
  2039. // }
  2040. // //tableCel2.Tag
  2041. // for _, serviceId := range tableCel2.ValueId {
  2042. // key := fmt.Sprint(item.ServiceTemplateId, "_product_permission_", serviceId)
  2043. // if cellI, ok := serviceCellMap[key]; ok {
  2044. // cellServiceMap[cellI] = "是"
  2045. // }
  2046. // }
  2047. //
  2048. // } else if strings.Contains(strings.Join(permissionValues, ","), tableCel.Value) {
  2049. // //获取品种列数据
  2050. // var tableCel2 request.AddContractServiceDetailReq
  2051. // tmpErr := contractService.GetProductCelData(*detail, &tableCel2)
  2052. // if tmpErr != nil {
  2053. // err = tmpErr
  2054. // return
  2055. // }
  2056. // for _, serviceId := range tableCel2.ValueId {
  2057. // key := fmt.Sprint(item.ServiceTemplateId, "_permission_", serviceId)
  2058. // if cellI, ok := serviceCellMap[key]; ok {
  2059. // cellServiceMap[cellI] = "是"
  2060. // }
  2061. // }
  2062. // }
  2063. // }
  2064. // } else {
  2065. // key := fmt.Sprint("service_template_", item.ServiceTemplateId)
  2066. // if cellI, ok := serviceCellMap[key]; ok {
  2067. // cellServiceMap[cellI] = "是"
  2068. // }
  2069. // }
  2070. // }
  2071. // }
  2072. //
  2073. // //遍历所有套餐
  2074. // for tmpStartCellI := customStartCellI; tmpStartCellI < startI; tmpStartCellI++ {
  2075. // servicesCell := dataRow.AddCell()
  2076. // cellValue, ok := cellServiceMap[tmpStartCellI]
  2077. // if ok == false {
  2078. // cellValue = "否"
  2079. // }
  2080. // servicesCell.SetValue(cellValue)
  2081. // if cellValue == "是" { //勾选了话,标红处理
  2082. // servicesCell.SetStyle(redStyle)
  2083. // } else {
  2084. // servicesCell.SetStyle(style)
  2085. // }
  2086. // }
  2087. // }
  2088. //
  2089. // }
  2090. // }
  2091. // err = xlsxFile.Save(downLoadnFilePath)
  2092. // if err != nil {
  2093. // br.Msg = "保存文件失败"
  2094. // br.ErrMsg = "保存文件失败"
  2095. // return
  2096. // }
  2097. // randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  2098. // downloadFileName := "合同列表" + randStr + ".xlsx"
  2099. // this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  2100. // br.Ret = 200
  2101. // br.Success = true
  2102. // br.Msg = "导出成功"
  2103. //}
  2104. // Preview
  2105. // @Title 预览合同
  2106. // @Description 预览合同接口v
  2107. // @Param request body request.AddContractReq true "type json string"
  2108. // @Success 200 {object} response.ContractPreviewResp
  2109. // @router /preview [post]
  2110. func (this *ContractController) Preview() {
  2111. br := new(models.BaseResponse).Init()
  2112. defer func() {
  2113. this.Data["json"] = br
  2114. this.ServeJSON()
  2115. }()
  2116. sysUser := this.SysUser
  2117. if sysUser == nil {
  2118. br.Msg = "请登录"
  2119. br.ErrMsg = "请登录,SysUser Is Empty"
  2120. br.Ret = 408
  2121. return
  2122. }
  2123. productId := services.GetProductId(sysUser.RoleTypeCode)
  2124. if productId == 0 {
  2125. br.Msg = "账户异常"
  2126. br.ErrMsg = "账户异常,当前账户类型为:" + sysUser.RoleTypeCode
  2127. br.Ret = 408
  2128. return
  2129. }
  2130. var req request.AddContractReq
  2131. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2132. if err != nil {
  2133. br.Msg = "参数解析异常!"
  2134. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2135. return
  2136. }
  2137. // 限制一下合同金额, 目前只支持人民币转大写只支持到千亿, 虽然生产使用中不可能到这么大, 但还是加上吧 =_=!
  2138. maxPrice := float64(1000000000000)
  2139. if req.OriginalPrice >= maxPrice || req.Price >= maxPrice {
  2140. br.Msg = "合同金额过大, 请核验金额"
  2141. return
  2142. }
  2143. contractInfo, err := contractService.GetContractDetailByAddContractReq(req, sysUser.AdminId, productId, sysUser.RealName)
  2144. if err != nil {
  2145. br.Msg = "获取合同数据失败!"
  2146. br.ErrMsg = "获取合同数据失败,Err:" + err.Error()
  2147. return
  2148. }
  2149. // CMR8.8-合并权益主客观
  2150. if contractInfo.ProductId == 2 {
  2151. mergeList := contractService.EquityMergeSubjectAndObject(contractInfo.Service)
  2152. contractInfo.Service = mergeList
  2153. }
  2154. contractHtml, err := services.GetHtmlByContractDetail(contractInfo, "html")
  2155. if err != nil {
  2156. br.Msg = "生成预览合同失败!"
  2157. br.ErrMsg = "生成预览合同失败,Err:" + err.Error()
  2158. return
  2159. }
  2160. br.Ret = 200
  2161. br.Success = true
  2162. br.Msg = "获取成功"
  2163. br.Data = response.ContractPreviewResp{
  2164. Html: contractHtml,
  2165. }
  2166. }
  2167. // PreviewByContractId
  2168. // @Title 预览合同
  2169. // @Description 预览合同接口
  2170. // @Param ContractId query int true "合同id"
  2171. // @Success 200 {object} response.ContractPreviewResp
  2172. // @router /previewByContractId [get]
  2173. func (this *ContractController) PreviewByContractId() {
  2174. br := new(models.BaseResponse).Init()
  2175. defer func() {
  2176. this.Data["json"] = br
  2177. this.ServeJSON()
  2178. }()
  2179. sysUser := this.SysUser
  2180. if sysUser == nil {
  2181. br.Msg = "请登录"
  2182. br.ErrMsg = "请登录,SysUser Is Empty"
  2183. br.Ret = 408
  2184. return
  2185. }
  2186. contractId, _ := this.GetInt("ContractId")
  2187. //合同id
  2188. if contractId <= 0 {
  2189. br.Msg = "合同id必传!"
  2190. br.ErrMsg = "合同id必传"
  2191. return
  2192. }
  2193. contractInfo, err := contractService.GetContractDetail(contractId)
  2194. if err != nil {
  2195. br.Msg = "获取合同详情失败!"
  2196. br.ErrMsg = "获取合同详情失败,ERR:" + err.Error()
  2197. return
  2198. }
  2199. // 限制一下合同金额, 目前只支持人民币转大写只支持到千亿, 虽然生产使用中不可能到这么大, 但还是加上吧 =_=!
  2200. maxPrice := float64(1000000000000)
  2201. if contractInfo.OriginalPrice >= maxPrice || contractInfo.Price >= maxPrice {
  2202. br.Msg = "合同金额过大, 请核验金额"
  2203. return
  2204. }
  2205. // CMR8.8-合并权益主客观
  2206. if contractInfo.ProductId == 2 {
  2207. mergeList := contractService.EquityMergeSubjectAndObject(contractInfo.Service)
  2208. contractInfo.Service = mergeList
  2209. }
  2210. contractHtml, err := services.GetHtmlByContractDetail(contractInfo, "html")
  2211. if err != nil {
  2212. br.Msg = "生成预览合同失败!"
  2213. br.ErrMsg = "生成预览合同失败,Err:" + err.Error()
  2214. return
  2215. }
  2216. br.Ret = 200
  2217. br.Success = true
  2218. br.Msg = "获取成功"
  2219. br.Data = response.ContractPreviewResp{
  2220. Html: contractHtml,
  2221. }
  2222. }
  2223. // DownLoadTmpContract
  2224. // @Title 下载临时合同
  2225. // @Description 下载临时合同接口
  2226. // @Param ContractId query int true "合同id"
  2227. // @router /downLoad/tmpContract [get]
  2228. func (this *ContractController) DownLoadTmpContract() {
  2229. br := new(models.BaseResponse).Init()
  2230. defer func() {
  2231. this.Data["json"] = br
  2232. this.ServeJSON()
  2233. }()
  2234. sysUser := this.SysUser
  2235. if sysUser == nil {
  2236. br.Msg = "请登录"
  2237. br.ErrMsg = "请登录,SysUser Is Empty"
  2238. br.Ret = 408
  2239. return
  2240. }
  2241. //合同类型、产品类型、合同状态、更新时间、所选销售
  2242. //关键字:合同编号、客户名称,社会信用码
  2243. contractId, _ := this.GetInt("ContractId")
  2244. //合同id
  2245. if contractId <= 0 {
  2246. br.Msg = "合同id必传!"
  2247. br.ErrMsg = "合同id必传"
  2248. return
  2249. }
  2250. contractInfo, err := contractService.GetContractDetail(contractId)
  2251. if err != nil {
  2252. br.Msg = "获取合同详情失败!"
  2253. br.ErrMsg = "获取合同详情失败,ERR:" + err.Error()
  2254. return
  2255. }
  2256. // 限制一下合同金额, 目前只支持人民币转大写只支持到千亿, 虽然生产使用中不可能到这么大, 但还是加上吧 =_=!
  2257. maxPrice := float64(1000000000000)
  2258. if contractInfo.OriginalPrice >= maxPrice || contractInfo.Price >= maxPrice {
  2259. br.Msg = "合同金额过大, 请核验金额"
  2260. return
  2261. }
  2262. // CMR8.8-合并权益主客观
  2263. if contractInfo.ProductId == 2 {
  2264. mergeList := contractService.EquityMergeSubjectAndObject(contractInfo.Service)
  2265. contractInfo.Service = mergeList
  2266. }
  2267. //合同下载权限校验
  2268. if (sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER) && contractInfo.SellerId != sysUser.AdminId {
  2269. br.Msg = "合同异常!"
  2270. br.ErrMsg = "合同异常"
  2271. return
  2272. }
  2273. //contractHtml, tmpErr := services.GetHtmlByContractDetail(contractInfo, "pdf")
  2274. //if tmpErr != nil {
  2275. // err = tmpErr
  2276. // return
  2277. //}
  2278. //生成pdf
  2279. //pdfPath := fmt.Sprint("./static/word/系统生成合同_", contractId, ".pdf")
  2280. //tmpErr = services.Html2Pdf(contractHtml, pdfPath)
  2281. //if tmpErr != nil {
  2282. // err = tmpErr
  2283. // return
  2284. //}
  2285. //defer func() {
  2286. // os.Remove(pdfPath)
  2287. //}()
  2288. //downloadFileName := "合同草稿_" + contractInfo.ContractCode + ".pdf"
  2289. wordPath := fmt.Sprint("./static/word/系统生成合同_", contractId, ".docx")
  2290. tmpErr := services.GenerateWordV2(contractInfo, wordPath)
  2291. if tmpErr != nil {
  2292. err = tmpErr
  2293. return
  2294. }
  2295. defer func() {
  2296. os.Remove(wordPath)
  2297. }()
  2298. downloadFileName := contractInfo.CompanyName + "_" + contractInfo.ContractCode + "(草稿).docx"
  2299. this.Ctx.Output.Download(wordPath, downloadFileName)
  2300. br.Ret = 200
  2301. br.Success = true
  2302. br.Msg = "下载成功"
  2303. }
  2304. // getServiceTemplateList 获取系统服务列表
  2305. func getServiceTemplateList(productId int) (list []*contract.ContractServiceTemplateMapItems, err error) {
  2306. list, err = contract.GetContractServiceTemplateMapByProductId(productId)
  2307. if err != nil {
  2308. return
  2309. }
  2310. for i := 0; i < len(list); i++ {
  2311. item := list[i]
  2312. tmpList, tmpErr := contract.GetContractServiceTemplateMapByParentId(item.ServiceTemplateId)
  2313. if tmpErr != nil {
  2314. err = tmpErr
  2315. return
  2316. }
  2317. for j := 0; j < len(tmpList); j++ {
  2318. detail, tmpErr := contract.GetContractServiceDetailByTemplateId(tmpList[j].ServiceTemplateId)
  2319. if tmpErr != nil {
  2320. err = tmpErr
  2321. return
  2322. }
  2323. tmpList[j].Detail = detail
  2324. }
  2325. detail, tmpErr := contract.GetContractServiceDetailByTemplateId(list[i].ServiceTemplateId)
  2326. if tmpErr != nil {
  2327. err = tmpErr
  2328. return
  2329. }
  2330. list[i].Detail = detail
  2331. list[i].Children = tmpList
  2332. }
  2333. return
  2334. }
  2335. // BusinessContractCompanyList
  2336. // @Title 业务合同客户名称列表
  2337. // @Description 业务合同客户名称列表接口
  2338. // @Param Keyword query string true "搜索关键字"
  2339. // @Success 200 {object} []string
  2340. // @router /business_contract/company_name/list/ [get]
  2341. func (this *ContractController) BusinessContractCompanyList() {
  2342. br := new(models.BaseResponse).Init()
  2343. defer func() {
  2344. this.Data["json"] = br
  2345. this.ServeJSON()
  2346. }()
  2347. sysUser := this.SysUser
  2348. if sysUser == nil {
  2349. br.Msg = "请登录"
  2350. br.ErrMsg = "请登录,SysUser Is Empty"
  2351. br.Ret = 408
  2352. return
  2353. }
  2354. condition := ""
  2355. pars := make([]interface{}, 0)
  2356. condition += ` AND a.contract_business_type ="业务合同" AND a.status ="已签回" `
  2357. //如果不是超管或者合规,那么只能查看自己的合同
  2358. //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  2359. // condition += ` AND a.product_id = 1 `
  2360. //} else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  2361. // condition += ` AND product_id = 2 `
  2362. //} else {
  2363. // if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  2364. // condition += ` AND a.seller_id = ? `
  2365. // pars = append(pars, sysUser.AdminId)
  2366. // }
  2367. //}
  2368. condition += ` AND a.seller_id = ? `
  2369. pars = append(pars, sysUser.AdminId)
  2370. //关键字
  2371. keyword := this.GetString("Keyword")
  2372. if keyword == "" {
  2373. br.Msg = "请输入客户名称"
  2374. br.ErrMsg = "请输入客户名称"
  2375. return
  2376. }
  2377. condition += ` AND (contract_code LIKE '%` + keyword + `%' OR company_name LIKE '%` + keyword + `%' OR credit_code LIKE '%` + keyword + `%' ) `
  2378. list, err := contract.GetContractCompanyNameList(condition, pars)
  2379. if err != nil {
  2380. br.Msg = "获取合同列表失败!"
  2381. br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
  2382. return
  2383. }
  2384. companyNameList := make([]string, 0)
  2385. for _, v := range list {
  2386. companyNameList = append(companyNameList, v.CompanyName)
  2387. }
  2388. br.Ret = 200
  2389. br.Success = true
  2390. br.Msg = "获取成功"
  2391. br.Data = companyNameList
  2392. }
  2393. // BusinessContractListByCompanyName
  2394. // @Title 根据客户名称获取所有已签回的业务合同列表
  2395. // @Description 根据客户名称获取所有已签回的业务合同列表接口
  2396. // @Param CompanyName query string false "客户名称"
  2397. // @Success 200 {object} response.ContractListResp
  2398. // @router /business_contract/list/ [get]
  2399. func (this *ContractController) BusinessContractListByCompanyName() {
  2400. br := new(models.BaseResponse).Init()
  2401. defer func() {
  2402. this.Data["json"] = br
  2403. this.ServeJSON()
  2404. }()
  2405. sysUser := this.SysUser
  2406. if sysUser == nil {
  2407. br.Msg = "请登录"
  2408. br.ErrMsg = "请登录,SysUser Is Empty"
  2409. br.Ret = 408
  2410. return
  2411. }
  2412. condition := ""
  2413. pars := make([]interface{}, 0)
  2414. condition += ` AND a.contract_business_type ="业务合同" AND a.status ="已签回" and a.price>a.paid_price `
  2415. //如果不是超管或者合规,那么只能查看自己的合同
  2416. //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  2417. // condition += ` AND a.product_id = 1 `
  2418. //} else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  2419. // condition += ` AND product_id = 2 `
  2420. //} else {
  2421. // if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  2422. // condition += ` AND a.seller_id = ? `
  2423. // pars = append(pars, sysUser.AdminId)
  2424. // }
  2425. //}
  2426. condition += ` AND a.seller_id = ? `
  2427. pars = append(pars, sysUser.AdminId)
  2428. //关键字
  2429. companyName := this.GetString("CompanyName")
  2430. if companyName == "" {
  2431. br.Msg = "请输入客户名称"
  2432. br.ErrMsg = "请输入客户名称"
  2433. return
  2434. }
  2435. condition += ` AND company_name = ? `
  2436. pars = append(pars, companyName)
  2437. pageSize, _ := this.GetInt("PageSize")
  2438. currentIndex, _ := this.GetInt("CurrentIndex")
  2439. var startSize int
  2440. if pageSize <= 0 {
  2441. pageSize = utils.PageSize20
  2442. }
  2443. if currentIndex <= 0 {
  2444. currentIndex = 1
  2445. }
  2446. startSize = paging.StartIndex(currentIndex, pageSize)
  2447. total, err := contract.GetContractListCount(condition, "", pars)
  2448. if err != nil {
  2449. br.Msg = "获取失败"
  2450. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  2451. return
  2452. }
  2453. list, err := contract.GetContractList(condition, "", pars, startSize, pageSize)
  2454. if err != nil {
  2455. br.Msg = "获取合同列表失败!"
  2456. br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
  2457. return
  2458. }
  2459. //获取合同套餐服务列表
  2460. serviceTemplateList, err := contract.GetAllContractServiceTemplateList()
  2461. if err != nil {
  2462. br.Msg = "获取合同套餐服务列表失败!"
  2463. br.ErrMsg = "获取合同套餐服务列表失败,Err:" + err.Error()
  2464. return
  2465. }
  2466. templateTitleMap := make(map[int]string)
  2467. for _, serviceTemplate := range serviceTemplateList {
  2468. templateTitleMap[serviceTemplate.ServiceTemplateId] = serviceTemplate.Title
  2469. }
  2470. //业务合同的关联合同id集合
  2471. businessContractIdList := make([]string, 0)
  2472. //代付合同的关联合同id集合
  2473. paymentOnBehalfContractIdList := make([]string, 0)
  2474. //基础合同的关联合同数据
  2475. contractRelationMap := make(map[int][]*contract.RelationContractList)
  2476. for _, v := range list {
  2477. switch v.ContractBusinessType {
  2478. case "业务合同":
  2479. businessContractIdList = append(businessContractIdList, fmt.Sprint(v.ContractId))
  2480. case "代付合同":
  2481. paymentOnBehalfContractIdList = append(paymentOnBehalfContractIdList, fmt.Sprint(v.ContractId))
  2482. }
  2483. }
  2484. //业务合同的关联合同
  2485. if len(businessContractIdList) > 0 {
  2486. contractIdStr := strings.Join(businessContractIdList, ",")
  2487. businessContractList, err := contract.GetContractRelationListByRelationContractIds(contractIdStr)
  2488. if err != nil {
  2489. br.Msg = "获取失败"
  2490. br.ErrMsg = "获取业务关联合同失败,Err:" + err.Error()
  2491. return
  2492. }
  2493. for _, v := range businessContractList {
  2494. if _, ok := contractRelationMap[v.ContractId]; ok {
  2495. contractRelationMap[v.ContractId] = append(contractRelationMap[v.ContractId], v)
  2496. } else {
  2497. tmpList := make([]*contract.RelationContractList, 0)
  2498. contractRelationMap[v.ContractId] = append(tmpList, v)
  2499. }
  2500. }
  2501. }
  2502. //代付合同的关联合同
  2503. if len(paymentOnBehalfContractIdList) > 0 {
  2504. paymentOnBehalfContractIdStr := strings.Join(paymentOnBehalfContractIdList, ",")
  2505. paymentOnBehalfContractList, err := contract.GetContractRelationListByPaymentOnBehalfContractIds(paymentOnBehalfContractIdStr)
  2506. if err != nil {
  2507. br.Msg = "获取失败"
  2508. br.ErrMsg = "获取代付关联合同失败,Err:" + err.Error()
  2509. return
  2510. }
  2511. for _, v := range paymentOnBehalfContractList {
  2512. if _, ok := contractRelationMap[v.PaymentOnBehalfContractId]; ok {
  2513. contractRelationMap[v.PaymentOnBehalfContractId] = append(contractRelationMap[v.PaymentOnBehalfContractId], v)
  2514. } else {
  2515. tmpList := make([]*contract.RelationContractList, 0)
  2516. contractRelationMap[v.PaymentOnBehalfContractId] = append(tmpList, v)
  2517. }
  2518. }
  2519. }
  2520. for i := 0; i < len(list); i++ {
  2521. //合同操作权限
  2522. var opButton contract.ContractOpButton
  2523. item := list[i]
  2524. list[i].StartDateStr = item.StartDate.Format(utils.FormatDate)
  2525. list[i].EndDateStr = item.EndDate.Format(utils.FormatDate)
  2526. list[i].CreateTimeStr = item.CreateTime.Format(utils.FormatDateTime)
  2527. list[i].ModifyTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
  2528. list[i].ApproveTimeStr = item.ApproveTime.Format(utils.FormatDateTime)
  2529. list[i].InvalidTimeStr = item.InvalidTime.Format(utils.FormatDateTime)
  2530. list[i].CheckBackFileTimeStr = item.CheckBackFileTime.Format(utils.FormatDateTime)
  2531. list[i].RescindTimeStr = item.RescindTime.Format(utils.FormatDateTime)
  2532. //服务列表
  2533. serviceList, err := contract.GetContractServiceAndDetailList(item.ContractId)
  2534. if err != nil {
  2535. br.Msg = "获取失败"
  2536. br.ErrMsg = "查找合同服务异常,Err:" + err.Error()
  2537. return
  2538. }
  2539. for i := 0; len(serviceList) > i; i++ {
  2540. if serviceList[i].HasDetail == "是" {
  2541. list, detailErr := contract.GetContractServiceDetailListByServiceId(serviceList[i].ContractServiceId)
  2542. if detailErr != nil {
  2543. br.Msg = "获取失败"
  2544. br.ErrMsg = "查找合同服务详情异常,Err:" + err.Error()
  2545. return
  2546. }
  2547. //套餐名称
  2548. serviceList[i].DetailList = list
  2549. if title, ok := templateTitleMap[serviceList[i].ServiceTemplateId]; ok {
  2550. serviceList[i].Title = title
  2551. }
  2552. }
  2553. }
  2554. list[i].Service = serviceList
  2555. if item.Status == "待审批" {
  2556. approvalInfo, tmpErr := contract.GetLastContractApprovalByContractId(item.ContractId, "contract")
  2557. if tmpErr != nil {
  2558. //err= tmpErr
  2559. //return
  2560. continue
  2561. }
  2562. //如果合同归属是当前账号,且处于第一级审批
  2563. if item.SellerId == sysUser.AdminId && approvalInfo.CurrNodeId == approvalInfo.StartNodeId {
  2564. opButton.Cancel = true
  2565. }
  2566. }
  2567. list[i].OpButton = opButton
  2568. if relationContractList, ok := contractRelationMap[item.ContractId]; ok {
  2569. list[i].RelationContractList = relationContractList
  2570. }
  2571. }
  2572. page := paging.GetPaging(currentIndex, pageSize, total)
  2573. br.Ret = 200
  2574. br.Success = true
  2575. br.Msg = "获取成功"
  2576. br.Data = response.ContractListResp{
  2577. List: list,
  2578. Paging: page,
  2579. }
  2580. return
  2581. }
  2582. // UpdateFile
  2583. // @Title 更新合同附件(用于非标)
  2584. // @Description 更新合同附件接口
  2585. // @Param request body request.UploadFileReq true "type json string"
  2586. // @Success Ret=200 上传成功
  2587. // @router /update_file [post]
  2588. func (this *ContractController) UpdateFile() {
  2589. br := new(models.BaseResponse).Init()
  2590. defer func() {
  2591. this.Data["json"] = br
  2592. this.ServeJSON()
  2593. }()
  2594. sysUser := this.SysUser
  2595. if sysUser == nil {
  2596. br.Msg = "请登录"
  2597. br.ErrMsg = "请登录,SysUser Is Empty"
  2598. br.Ret = 408
  2599. return
  2600. }
  2601. //var req request.UploadFileReq
  2602. //err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2603. //if err != nil {
  2604. // br.Msg = "参数解析异常!"
  2605. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2606. // return
  2607. //}
  2608. contractIdStr := this.Ctx.Request.Form.Get("ContractId")
  2609. if contractIdStr == "" {
  2610. br.Msg = "合同ID必传!"
  2611. br.ErrMsg = "合同ID必传,Err"
  2612. return
  2613. }
  2614. contractId, err := strconv.Atoi(contractIdStr)
  2615. if err != nil {
  2616. br.Msg = "合同ID异常!"
  2617. br.ErrMsg = "合同ID异常,Err:" + err.Error()
  2618. return
  2619. }
  2620. fileMulti, h, err := this.GetFile("file")
  2621. if err != nil {
  2622. br.Msg = "获取资源信息失败"
  2623. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  2624. return
  2625. }
  2626. //合同编号
  2627. if contractId <= 0 {
  2628. br.Msg = "请传入合同编号!"
  2629. br.ErrMsg = "请传入合同编号"
  2630. return
  2631. }
  2632. ext := path.Ext(h.Filename)
  2633. err = contractService.UploadFile(contractId, ext, fileMulti, this.SysUser)
  2634. br.Ret = 200
  2635. br.Success = true
  2636. br.Msg = "上传成功"
  2637. }
  2638. // GetListBySeal
  2639. // @Title 获取用印所需合同列表
  2640. // @Description 获取用印所需合同列表
  2641. // @Param Keyword query string false "搜索关键字"
  2642. // @Success 200 {object} response.ContractListBySealResp
  2643. // @router /getListBySeal [get]
  2644. func (this *ContractController) GetListBySeal() {
  2645. br := new(models.BaseResponse).Init()
  2646. defer func() {
  2647. this.Data["json"] = br
  2648. this.ServeJSON()
  2649. }()
  2650. keyword := this.GetString("Keyword")
  2651. condition := ""
  2652. pars := make([]interface{}, 0)
  2653. if keyword != "" {
  2654. condition += ` AND (company_name LIKE '%` + keyword + `%') `
  2655. }
  2656. // 如果不是合规则只能查看自己的合同
  2657. if this.SysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE {
  2658. condition += ` AND seller_id = ? `
  2659. pars = append(pars, this.SysUser.AdminId)
  2660. }
  2661. list, err := contract.GetSearchListBySeal(condition, pars)
  2662. if err != nil {
  2663. br.Msg = "获取失败"
  2664. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2665. return
  2666. }
  2667. newList := make([]response.ContractListBySealResp, 0)
  2668. if len(list) > 0 {
  2669. // 代付合同查询代付用户名称
  2670. contractIdSlice := make([]string, 0)
  2671. for i := 0; i < len(list); i++ {
  2672. if list[i].ContractBusinessType == "代付合同" {
  2673. contractIdSlice = append(contractIdSlice, strconv.Itoa(list[i].ContractId))
  2674. }
  2675. }
  2676. userCompanyNameMap := make(map[int]string, 0)
  2677. if len(contractIdSlice) > 0 {
  2678. contractIdStr := strings.Join(contractIdSlice, ",")
  2679. contractList, err := contract.GetContractRelationListByPaymentOnBehalfContractIds(contractIdStr)
  2680. if err != nil {
  2681. br.Msg = "获取失败"
  2682. br.ErrMsg = "获取代付合同对应的合同数据失败,Err:" + err.Error()
  2683. return
  2684. }
  2685. for i := 0; i < len(contractList); i++ {
  2686. userCompanyNameMap[contractList[i].PaymentOnBehalfContractId] = contractList[i].CompanyName
  2687. }
  2688. }
  2689. for _, item := range list {
  2690. var tempItem response.ContractListBySealResp
  2691. tempItem.ContractId = item.ContractId
  2692. tempItem.ContractCode = item.ContractCode
  2693. tempItem.CompanyName = item.CompanyName
  2694. tempItem.FileUrl = item.FileUrl
  2695. tempItem.Price = item.Price
  2696. tempItem.CreditCode = item.CreditCode
  2697. tempItem.ContractBusinessType = item.ContractBusinessType
  2698. if item.ContractBusinessType == "代付合同" {
  2699. tempItem.ContractType = "代付合同"
  2700. tempItem.UserCompanyName = userCompanyNameMap[item.ContractId]
  2701. } else {
  2702. tempItem.ContractType = item.ContractType
  2703. }
  2704. newList = append(newList, tempItem)
  2705. }
  2706. }
  2707. br.Ret = 200
  2708. br.Success = true
  2709. br.Msg = "获取成功"
  2710. br.Data = newList
  2711. }
  2712. // DetailMerge
  2713. // @Title 获取合同详情-有套餐合并,用于审批单回显等
  2714. // @Description 获取合同详情接口
  2715. // @Param ContractId query int true "合同id"
  2716. // @Success 200 {object} contract.ContractDetail
  2717. // @router /detail/merge [get]
  2718. func (this *ContractController) DetailMerge() {
  2719. br := new(models.BaseResponse).Init()
  2720. defer func() {
  2721. this.Data["json"] = br
  2722. this.ServeJSON()
  2723. }()
  2724. sysUser := this.SysUser
  2725. if sysUser == nil {
  2726. br.Msg = "请登录"
  2727. br.ErrMsg = "请登录,SysUser Is Empty"
  2728. br.Ret = 408
  2729. return
  2730. }
  2731. //合同类型、产品类型、合同状态、更新时间、所选销售
  2732. //关键字:合同编号、客户名称,社会信用码
  2733. contractId, _ := this.GetInt("ContractId")
  2734. //合同id
  2735. if contractId <= 0 {
  2736. br.Msg = "合同id必传!"
  2737. br.ErrMsg = "合同id必传"
  2738. return
  2739. }
  2740. contractInfo, err := contractService.GetContractDetail(contractId)
  2741. if err != nil {
  2742. br.Msg = "获取合同详情失败!"
  2743. br.ErrMsg = "获取合同详情失败,ERR:" + err.Error()
  2744. return
  2745. }
  2746. // CRM8.8-权益主客观合并
  2747. if contractInfo.ProductId == 2 {
  2748. mergeList := contractService.EquityMergeSubjectAndObject(contractInfo.Service)
  2749. contractInfo.Service = mergeList
  2750. // 关联合同同样合并
  2751. for i, v := range contractInfo.RelationContractDetailList {
  2752. relationMergeList := contractService.EquityMergeSubjectAndObject(v.Service)
  2753. contractInfo.RelationContractDetailList[i].Service = relationMergeList
  2754. }
  2755. }
  2756. contractInfo.StartDateStr = contractInfo.StartDate.Format(utils.FormatDate)
  2757. contractInfo.EndDateStr = contractInfo.EndDate.Format(utils.FormatDate)
  2758. contractInfo.ModifyTimeStr = contractInfo.ModifyTime.Format(utils.FormatDateTime)
  2759. contractInfo.CreateTimeStr = contractInfo.CreateTime.Format(utils.FormatDateTime)
  2760. //合同中包含的产品权限
  2761. isNeedPermission := false //是否需要列出来套餐中的详细权限
  2762. for _, service := range contractInfo.Service {
  2763. if service.ServiceTemplateId == 2 { //小套餐才需要列出来详细的权限
  2764. isNeedPermission = true
  2765. }
  2766. }
  2767. var permissionLookListResp = make([]*contract.PermissionLookList, 0)
  2768. if isNeedPermission {
  2769. checkPermissionMap, tErr := contractService.GetServicePermissionMap(contractInfo.Service)
  2770. if tErr == nil {
  2771. permissionLookListMap := make(map[string][]*contract.PermissionLookItem)
  2772. var permissionIds []string
  2773. for _, v := range checkPermissionMap {
  2774. permissionIds = append(permissionIds, strconv.Itoa(v))
  2775. }
  2776. permissionIdStr := strings.Join(permissionIds, ",")
  2777. charPermissions, tErr1 := company.GetPermissionLookItemsSandO(permissionIdStr)
  2778. if tErr1 == nil {
  2779. for _, v := range charPermissions {
  2780. tmp := new(contract.PermissionLookItem)
  2781. tmp.ClassifyName = v.ClassifyName
  2782. tmp.PermissionName = v.PermissionName
  2783. tmp.ChartPermissionId = v.ChartPermissionId
  2784. permissionLookListMap[v.ClassifyName] = append(permissionLookListMap[v.ClassifyName], tmp)
  2785. }
  2786. classifyNameList, tErr2 := company.GetChartPermissionFirst()
  2787. if tErr2 == nil {
  2788. for _, v := range classifyNameList {
  2789. if perList, ok := permissionLookListMap[v.ClassifyName]; ok {
  2790. permissionLookListRespItem := &contract.PermissionLookList{
  2791. ClassifyName: v.ClassifyName,
  2792. Items: perList,
  2793. }
  2794. permissionLookListResp = append(permissionLookListResp, permissionLookListRespItem)
  2795. }
  2796. }
  2797. }
  2798. }
  2799. }
  2800. }
  2801. contractInfo.PermissionLookList = permissionLookListResp
  2802. br.Ret = 200
  2803. br.Success = true
  2804. br.Msg = "获取成功"
  2805. br.Data = contractInfo
  2806. }