contract.go 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036
  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[int][]*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.ParentId] = append(permissionLookListMap[v.ParentId], tmp)
  1501. }
  1502. classifyNameList, tErr2 := company.GetChartPermissionFirst()
  1503. if tErr2 == nil {
  1504. for _, v := range classifyNameList {
  1505. if perList, ok := permissionLookListMap[v.ChartPermissionId]; 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. keyword = strings.TrimSpace(keyword)
  2373. if keyword == "" {
  2374. br.Msg = "请输入客户名称"
  2375. br.ErrMsg = "请输入客户名称"
  2376. return
  2377. }
  2378. kw := fmt.Sprint("%", keyword, "%")
  2379. condition += ` AND (contract_code LIKE ? OR company_name LIKE ? OR credit_code LIKE ? ) `
  2380. pars = append(pars, kw, kw, kw)
  2381. list, err := contract.GetContractCompanyNameList(condition, pars)
  2382. if err != nil {
  2383. br.Msg = "获取合同列表失败!"
  2384. br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
  2385. return
  2386. }
  2387. companyNameList := make([]string, 0)
  2388. for _, v := range list {
  2389. companyNameList = append(companyNameList, v.CompanyName)
  2390. }
  2391. // 13.6正式共享客户的处理
  2392. {
  2393. // 通过关键词获取分配给当前销售的正式共享客户
  2394. cond := ` AND share_seller_id = ? AND is_share = 1 AND company_name LIKE ?`
  2395. pars := make([]interface{}, 0)
  2396. pars = append(pars, sysUser.AdminId, kw)
  2397. shares, e := company.GetCompanyProductList(cond, pars)
  2398. if e != nil {
  2399. br.Msg = "获取失败"
  2400. br.ErrMsg = "获取共享客户信息失败, Err: " + e.Error()
  2401. return
  2402. }
  2403. for _, v := range shares {
  2404. if !utils.InArrayByStr(companyNameList, v.CompanyName) {
  2405. companyNameList = append(companyNameList, v.CompanyName)
  2406. }
  2407. }
  2408. }
  2409. br.Ret = 200
  2410. br.Success = true
  2411. br.Msg = "获取成功"
  2412. br.Data = companyNameList
  2413. }
  2414. // BusinessContractListByCompanyName
  2415. // @Title 根据客户名称获取所有已签回的业务合同列表
  2416. // @Description 根据客户名称获取所有已签回的业务合同列表接口
  2417. // @Param CompanyName query string false "客户名称"
  2418. // @Success 200 {object} response.ContractListResp
  2419. // @router /business_contract/list/ [get]
  2420. func (this *ContractController) BusinessContractListByCompanyName() {
  2421. br := new(models.BaseResponse).Init()
  2422. defer func() {
  2423. this.Data["json"] = br
  2424. this.ServeJSON()
  2425. }()
  2426. sysUser := this.SysUser
  2427. if sysUser == nil {
  2428. br.Msg = "请登录"
  2429. br.ErrMsg = "请登录,SysUser Is Empty"
  2430. br.Ret = 408
  2431. return
  2432. }
  2433. condition := ""
  2434. pars := make([]interface{}, 0)
  2435. condition += ` AND a.contract_business_type ="业务合同" AND a.status ="已签回" and a.price>a.paid_price `
  2436. //如果不是超管或者合规,那么只能查看自己的合同
  2437. //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  2438. // condition += ` AND a.product_id = 1 `
  2439. //} else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  2440. // condition += ` AND product_id = 2 `
  2441. //} else {
  2442. // if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  2443. // condition += ` AND a.seller_id = ? `
  2444. // pars = append(pars, sysUser.AdminId)
  2445. // }
  2446. //}
  2447. //condition += ` AND a.seller_id = ? `
  2448. //pars = append(pars, sysUser.AdminId)
  2449. // 13.6正式共享客户-可以选择分配给自己的共享客户下的非自己创建的合同
  2450. joinStr := ` LEFT JOIN company_product AS b ON a.company_name = b.company_name `
  2451. condition += ` AND (a.seller_id = ? OR (b.is_share = 1 AND b.share_seller_id = ?))`
  2452. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  2453. //关键字
  2454. companyName := this.GetString("CompanyName")
  2455. if companyName == "" {
  2456. br.Msg = "请输入客户名称"
  2457. br.ErrMsg = "请输入客户名称"
  2458. return
  2459. }
  2460. condition += ` AND a.company_name = ? `
  2461. pars = append(pars, companyName)
  2462. pageSize, _ := this.GetInt("PageSize")
  2463. currentIndex, _ := this.GetInt("CurrentIndex")
  2464. var startSize int
  2465. if pageSize <= 0 {
  2466. pageSize = utils.PageSize20
  2467. }
  2468. if currentIndex <= 0 {
  2469. currentIndex = 1
  2470. }
  2471. startSize = paging.StartIndex(currentIndex, pageSize)
  2472. total, err := contract.GetContractListCount(condition, joinStr, pars)
  2473. if err != nil {
  2474. br.Msg = "获取失败"
  2475. br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
  2476. return
  2477. }
  2478. list, err := contract.GetContractList(condition, joinStr, pars, startSize, pageSize)
  2479. if err != nil {
  2480. br.Msg = "获取合同列表失败!"
  2481. br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
  2482. return
  2483. }
  2484. //获取合同套餐服务列表
  2485. serviceTemplateList, err := contract.GetAllContractServiceTemplateList()
  2486. if err != nil {
  2487. br.Msg = "获取合同套餐服务列表失败!"
  2488. br.ErrMsg = "获取合同套餐服务列表失败,Err:" + err.Error()
  2489. return
  2490. }
  2491. templateTitleMap := make(map[int]string)
  2492. for _, serviceTemplate := range serviceTemplateList {
  2493. templateTitleMap[serviceTemplate.ServiceTemplateId] = serviceTemplate.Title
  2494. }
  2495. //业务合同的关联合同id集合
  2496. businessContractIdList := make([]string, 0)
  2497. //代付合同的关联合同id集合
  2498. paymentOnBehalfContractIdList := make([]string, 0)
  2499. //基础合同的关联合同数据
  2500. contractRelationMap := make(map[int][]*contract.RelationContractList)
  2501. for _, v := range list {
  2502. switch v.ContractBusinessType {
  2503. case "业务合同":
  2504. businessContractIdList = append(businessContractIdList, fmt.Sprint(v.ContractId))
  2505. case "代付合同":
  2506. paymentOnBehalfContractIdList = append(paymentOnBehalfContractIdList, fmt.Sprint(v.ContractId))
  2507. }
  2508. }
  2509. //业务合同的关联合同
  2510. if len(businessContractIdList) > 0 {
  2511. contractIdStr := strings.Join(businessContractIdList, ",")
  2512. businessContractList, err := contract.GetContractRelationListByRelationContractIds(contractIdStr)
  2513. if err != nil {
  2514. br.Msg = "获取失败"
  2515. br.ErrMsg = "获取业务关联合同失败,Err:" + err.Error()
  2516. return
  2517. }
  2518. for _, v := range businessContractList {
  2519. if _, ok := contractRelationMap[v.ContractId]; ok {
  2520. contractRelationMap[v.ContractId] = append(contractRelationMap[v.ContractId], v)
  2521. } else {
  2522. tmpList := make([]*contract.RelationContractList, 0)
  2523. contractRelationMap[v.ContractId] = append(tmpList, v)
  2524. }
  2525. }
  2526. }
  2527. //代付合同的关联合同
  2528. if len(paymentOnBehalfContractIdList) > 0 {
  2529. paymentOnBehalfContractIdStr := strings.Join(paymentOnBehalfContractIdList, ",")
  2530. paymentOnBehalfContractList, err := contract.GetContractRelationListByPaymentOnBehalfContractIds(paymentOnBehalfContractIdStr)
  2531. if err != nil {
  2532. br.Msg = "获取失败"
  2533. br.ErrMsg = "获取代付关联合同失败,Err:" + err.Error()
  2534. return
  2535. }
  2536. for _, v := range paymentOnBehalfContractList {
  2537. if _, ok := contractRelationMap[v.PaymentOnBehalfContractId]; ok {
  2538. contractRelationMap[v.PaymentOnBehalfContractId] = append(contractRelationMap[v.PaymentOnBehalfContractId], v)
  2539. } else {
  2540. tmpList := make([]*contract.RelationContractList, 0)
  2541. contractRelationMap[v.PaymentOnBehalfContractId] = append(tmpList, v)
  2542. }
  2543. }
  2544. }
  2545. for i := 0; i < len(list); i++ {
  2546. //合同操作权限
  2547. var opButton contract.ContractOpButton
  2548. item := list[i]
  2549. list[i].StartDateStr = item.StartDate.Format(utils.FormatDate)
  2550. list[i].EndDateStr = item.EndDate.Format(utils.FormatDate)
  2551. list[i].CreateTimeStr = item.CreateTime.Format(utils.FormatDateTime)
  2552. list[i].ModifyTimeStr = item.ModifyTime.Format(utils.FormatDateTime)
  2553. list[i].ApproveTimeStr = item.ApproveTime.Format(utils.FormatDateTime)
  2554. list[i].InvalidTimeStr = item.InvalidTime.Format(utils.FormatDateTime)
  2555. list[i].CheckBackFileTimeStr = item.CheckBackFileTime.Format(utils.FormatDateTime)
  2556. list[i].RescindTimeStr = item.RescindTime.Format(utils.FormatDateTime)
  2557. //服务列表
  2558. serviceList, err := contract.GetContractServiceAndDetailList(item.ContractId)
  2559. if err != nil {
  2560. br.Msg = "获取失败"
  2561. br.ErrMsg = "查找合同服务异常,Err:" + err.Error()
  2562. return
  2563. }
  2564. for i := 0; len(serviceList) > i; i++ {
  2565. if serviceList[i].HasDetail == "是" {
  2566. list, detailErr := contract.GetContractServiceDetailListByServiceId(serviceList[i].ContractServiceId)
  2567. if detailErr != nil {
  2568. br.Msg = "获取失败"
  2569. br.ErrMsg = "查找合同服务详情异常,Err:" + err.Error()
  2570. return
  2571. }
  2572. //套餐名称
  2573. serviceList[i].DetailList = list
  2574. if title, ok := templateTitleMap[serviceList[i].ServiceTemplateId]; ok {
  2575. serviceList[i].Title = title
  2576. }
  2577. }
  2578. }
  2579. list[i].Service = serviceList
  2580. if item.Status == "待审批" {
  2581. approvalInfo, tmpErr := contract.GetLastContractApprovalByContractId(item.ContractId, "contract")
  2582. if tmpErr != nil {
  2583. //err= tmpErr
  2584. //return
  2585. continue
  2586. }
  2587. //如果合同归属是当前账号,且处于第一级审批
  2588. if item.SellerId == sysUser.AdminId && approvalInfo.CurrNodeId == approvalInfo.StartNodeId {
  2589. opButton.Cancel = true
  2590. }
  2591. }
  2592. list[i].OpButton = opButton
  2593. if relationContractList, ok := contractRelationMap[item.ContractId]; ok {
  2594. list[i].RelationContractList = relationContractList
  2595. }
  2596. }
  2597. page := paging.GetPaging(currentIndex, pageSize, total)
  2598. br.Ret = 200
  2599. br.Success = true
  2600. br.Msg = "获取成功"
  2601. br.Data = response.ContractListResp{
  2602. List: list,
  2603. Paging: page,
  2604. }
  2605. return
  2606. }
  2607. // UpdateFile
  2608. // @Title 更新合同附件(用于非标)
  2609. // @Description 更新合同附件接口
  2610. // @Param request body request.UploadFileReq true "type json string"
  2611. // @Success Ret=200 上传成功
  2612. // @router /update_file [post]
  2613. func (this *ContractController) UpdateFile() {
  2614. br := new(models.BaseResponse).Init()
  2615. defer func() {
  2616. this.Data["json"] = br
  2617. this.ServeJSON()
  2618. }()
  2619. sysUser := this.SysUser
  2620. if sysUser == nil {
  2621. br.Msg = "请登录"
  2622. br.ErrMsg = "请登录,SysUser Is Empty"
  2623. br.Ret = 408
  2624. return
  2625. }
  2626. //var req request.UploadFileReq
  2627. //err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2628. //if err != nil {
  2629. // br.Msg = "参数解析异常!"
  2630. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2631. // return
  2632. //}
  2633. contractIdStr := this.Ctx.Request.Form.Get("ContractId")
  2634. if contractIdStr == "" {
  2635. br.Msg = "合同ID必传!"
  2636. br.ErrMsg = "合同ID必传,Err"
  2637. return
  2638. }
  2639. contractId, err := strconv.Atoi(contractIdStr)
  2640. if err != nil {
  2641. br.Msg = "合同ID异常!"
  2642. br.ErrMsg = "合同ID异常,Err:" + err.Error()
  2643. return
  2644. }
  2645. fileMulti, h, err := this.GetFile("file")
  2646. if err != nil {
  2647. br.Msg = "获取资源信息失败"
  2648. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  2649. return
  2650. }
  2651. //合同编号
  2652. if contractId <= 0 {
  2653. br.Msg = "请传入合同编号!"
  2654. br.ErrMsg = "请传入合同编号"
  2655. return
  2656. }
  2657. ext := path.Ext(h.Filename)
  2658. err = contractService.UploadFile(contractId, ext, fileMulti, this.SysUser)
  2659. br.Ret = 200
  2660. br.Success = true
  2661. br.Msg = "上传成功"
  2662. }
  2663. // GetListBySeal
  2664. // @Title 获取用印所需合同列表
  2665. // @Description 获取用印所需合同列表
  2666. // @Param Keyword query string false "搜索关键字"
  2667. // @Success 200 {object} response.ContractListBySealResp
  2668. // @router /getListBySeal [get]
  2669. func (this *ContractController) GetListBySeal() {
  2670. br := new(models.BaseResponse).Init()
  2671. defer func() {
  2672. this.Data["json"] = br
  2673. this.ServeJSON()
  2674. }()
  2675. sysUser := this.SysUser
  2676. if sysUser == nil {
  2677. br.Msg = "请登录"
  2678. br.ErrMsg = "请登录,SysUser Is Empty"
  2679. br.Ret = 408
  2680. return
  2681. }
  2682. keyword := this.GetString("Keyword")
  2683. condition := ` AND a.status = "已审批"`
  2684. pars := make([]interface{}, 0)
  2685. if keyword != "" {
  2686. kw := fmt.Sprint("%", keyword, "%")
  2687. condition += ` AND (a.company_name LIKE ?) `
  2688. pars = append(pars, kw)
  2689. }
  2690. // 13.6正式共享客户
  2691. joinStr := ` LEFT JOIN company_product AS b ON a.company_name = b.company_name `
  2692. // 非合规角色可查看自己的合同或是自己的共享客户下的非自己创建的合同
  2693. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE {
  2694. condition += ` AND (a.seller_id = ? OR (b.is_share = 1 AND b.share_seller_id = ?))`
  2695. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  2696. }
  2697. list, e := contract.GetContractList(condition, joinStr, pars, 0, 100)
  2698. if e != nil {
  2699. br.Msg = "获取失败"
  2700. br.ErrMsg = "获取合同列表失败, Err:" + e.Error()
  2701. return
  2702. }
  2703. //list, err := contract.GetSearchListBySeal(condition, pars)
  2704. //if err != nil {
  2705. // br.Msg = "获取失败"
  2706. // br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2707. // return
  2708. //}
  2709. newList := make([]response.ContractListBySealResp, 0)
  2710. if len(list) > 0 {
  2711. // 代付合同查询代付用户名称
  2712. contractIdSlice := make([]string, 0)
  2713. for i := 0; i < len(list); i++ {
  2714. if list[i].ContractBusinessType == "代付合同" {
  2715. contractIdSlice = append(contractIdSlice, strconv.Itoa(list[i].ContractId))
  2716. }
  2717. }
  2718. userCompanyNameMap := make(map[int]string, 0)
  2719. if len(contractIdSlice) > 0 {
  2720. contractIdStr := strings.Join(contractIdSlice, ",")
  2721. contractList, err := contract.GetContractRelationListByPaymentOnBehalfContractIds(contractIdStr)
  2722. if err != nil {
  2723. br.Msg = "获取失败"
  2724. br.ErrMsg = "获取代付合同对应的合同数据失败,Err:" + err.Error()
  2725. return
  2726. }
  2727. for i := 0; i < len(contractList); i++ {
  2728. userCompanyNameMap[contractList[i].PaymentOnBehalfContractId] = contractList[i].CompanyName
  2729. }
  2730. }
  2731. for _, item := range list {
  2732. var tempItem response.ContractListBySealResp
  2733. tempItem.ContractId = item.ContractId
  2734. tempItem.ContractCode = item.ContractCode
  2735. tempItem.CompanyName = item.CompanyName
  2736. tempItem.FileUrl = item.FileUrl
  2737. tempItem.Price = item.Price
  2738. tempItem.CreditCode = item.CreditCode
  2739. tempItem.ContractBusinessType = item.ContractBusinessType
  2740. if item.ContractBusinessType == "代付合同" {
  2741. tempItem.ContractType = "代付合同"
  2742. tempItem.UserCompanyName = userCompanyNameMap[item.ContractId]
  2743. } else {
  2744. tempItem.ContractType = item.ContractType
  2745. }
  2746. newList = append(newList, tempItem)
  2747. }
  2748. }
  2749. br.Ret = 200
  2750. br.Success = true
  2751. br.Msg = "获取成功"
  2752. br.Data = newList
  2753. }
  2754. // DetailMerge
  2755. // @Title 获取合同详情-有套餐合并,用于审批单回显等
  2756. // @Description 获取合同详情接口
  2757. // @Param ContractId query int true "合同id"
  2758. // @Success 200 {object} contract.ContractDetail
  2759. // @router /detail/merge [get]
  2760. func (this *ContractController) DetailMerge() {
  2761. br := new(models.BaseResponse).Init()
  2762. defer func() {
  2763. this.Data["json"] = br
  2764. this.ServeJSON()
  2765. }()
  2766. sysUser := this.SysUser
  2767. if sysUser == nil {
  2768. br.Msg = "请登录"
  2769. br.ErrMsg = "请登录,SysUser Is Empty"
  2770. br.Ret = 408
  2771. return
  2772. }
  2773. //合同类型、产品类型、合同状态、更新时间、所选销售
  2774. //关键字:合同编号、客户名称,社会信用码
  2775. contractId, _ := this.GetInt("ContractId")
  2776. //合同id
  2777. if contractId <= 0 {
  2778. br.Msg = "合同id必传!"
  2779. br.ErrMsg = "合同id必传"
  2780. return
  2781. }
  2782. contractInfo, err := contractService.GetContractDetail(contractId)
  2783. if err != nil {
  2784. br.Msg = "获取合同详情失败!"
  2785. br.ErrMsg = "获取合同详情失败,ERR:" + err.Error()
  2786. return
  2787. }
  2788. // CRM8.8-权益主客观合并
  2789. if contractInfo.ProductId == 2 {
  2790. mergeList := contractService.EquityMergeSubjectAndObject(contractInfo.Service)
  2791. contractInfo.Service = mergeList
  2792. // 关联合同同样合并
  2793. for i, v := range contractInfo.RelationContractDetailList {
  2794. relationMergeList := contractService.EquityMergeSubjectAndObject(v.Service)
  2795. contractInfo.RelationContractDetailList[i].Service = relationMergeList
  2796. }
  2797. }
  2798. contractInfo.StartDateStr = contractInfo.StartDate.Format(utils.FormatDate)
  2799. contractInfo.EndDateStr = contractInfo.EndDate.Format(utils.FormatDate)
  2800. contractInfo.ModifyTimeStr = contractInfo.ModifyTime.Format(utils.FormatDateTime)
  2801. contractInfo.CreateTimeStr = contractInfo.CreateTime.Format(utils.FormatDateTime)
  2802. //合同中包含的产品权限
  2803. isNeedPermission := false //是否需要列出来套餐中的详细权限
  2804. for _, service := range contractInfo.Service {
  2805. if service.ServiceTemplateId == 2 { //小套餐才需要列出来详细的权限
  2806. isNeedPermission = true
  2807. }
  2808. }
  2809. var permissionLookListResp = make([]*contract.PermissionLookList, 0)
  2810. if isNeedPermission {
  2811. checkPermissionMap, tErr := contractService.GetServicePermissionMap(contractInfo.Service)
  2812. if tErr == nil {
  2813. permissionLookListMap := make(map[int][]*contract.PermissionLookItem)
  2814. var permissionIds []string
  2815. for _, v := range checkPermissionMap {
  2816. permissionIds = append(permissionIds, strconv.Itoa(v))
  2817. }
  2818. permissionIdStr := strings.Join(permissionIds, ",")
  2819. charPermissions, tErr1 := company.GetPermissionLookItemsSandO(permissionIdStr)
  2820. if tErr1 == nil {
  2821. for _, v := range charPermissions {
  2822. tmp := new(contract.PermissionLookItem)
  2823. tmp.ClassifyName = v.ClassifyName
  2824. tmp.PermissionName = v.PermissionName
  2825. tmp.ChartPermissionId = v.ChartPermissionId
  2826. permissionLookListMap[v.ParentId] = append(permissionLookListMap[v.ParentId], tmp)
  2827. }
  2828. classifyNameList, tErr2 := company.GetChartPermissionFirst()
  2829. if tErr2 == nil {
  2830. for _, v := range classifyNameList {
  2831. if perList, ok := permissionLookListMap[v.ChartPermissionId]; ok {
  2832. permissionLookListRespItem := &contract.PermissionLookList{
  2833. ClassifyName: v.ClassifyName,
  2834. Items: perList,
  2835. }
  2836. permissionLookListResp = append(permissionLookListResp, permissionLookListRespItem)
  2837. }
  2838. }
  2839. }
  2840. }
  2841. }
  2842. }
  2843. contractInfo.PermissionLookList = permissionLookListResp
  2844. br.Ret = 200
  2845. br.Success = true
  2846. br.Msg = "获取成功"
  2847. br.Data = contractInfo
  2848. }