contract.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. package crm
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/go-playground/validator/v10"
  5. "hongze/fms_api/controller/resp"
  6. "hongze/fms_api/global"
  7. "hongze/fms_api/models/base"
  8. "hongze/fms_api/models/crm"
  9. "hongze/fms_api/models/system"
  10. "hongze/fms_api/utils"
  11. "strings"
  12. )
  13. // ContractController CRM系统合同
  14. type ContractController struct{}
  15. // SearchList
  16. // @Title 搜索合同
  17. // @Description 搜索合同
  18. // @Param Keyword query string false "关键词"
  19. // @Param ProductId query int false "合同类型: 0-全部; 1-FICC; 2-权益"
  20. // @Success 200 {object} crm.ContractSearchListResp
  21. // @router /crm/contract/search_list [get]
  22. func (rg *ContractController) SearchList(c *gin.Context) {
  23. var req crm.ContractSearchListReq
  24. if e := c.BindQuery(&req); e != nil {
  25. err, ok := e.(validator.ValidationErrors)
  26. if !ok {
  27. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  28. return
  29. }
  30. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  31. return
  32. }
  33. cond := `status IN ('已审批', '已签回')`
  34. pars := make([]interface{}, 0)
  35. if req.Keyword != "" {
  36. kw := "%" + req.Keyword + "%"
  37. cond += ` AND (company_name LIKE ? OR contract_code LIKE ?)`
  38. pars = append(pars, kw, kw)
  39. }
  40. if req.ProductId > 0 {
  41. cond += ` AND product_id = ?`
  42. pars = append(pars, req.ProductId)
  43. }
  44. page := new(base.Page)
  45. page.SetPageSize(req.PageSize)
  46. page.SetCurrent(req.Current)
  47. page.AddOrderItem(base.OrderItem{Column: "create_time", Asc: false})
  48. ob := new(crm.Contract)
  49. total, list, e := ob.PageList(page, cond, pars)
  50. if e != nil {
  51. resp.FailMsg("获取失败", "获取合同登记列表, Err: "+e.Error(), c)
  52. return
  53. }
  54. // 获取代付合同实际使用方
  55. peyContractIds := make([]int, 0)
  56. for i := range list {
  57. if list[i].ContractBusinessType == "代付合同" {
  58. peyContractIds = append(peyContractIds, list[i].ContractId)
  59. }
  60. }
  61. payCompanyMap := make(map[int]string, 0)
  62. if len(peyContractIds) > 0 {
  63. payCond := `a.status IN ('已签回', '已审批') AND b.payment_on_behalf_contract_id IN ?`
  64. payPars := make([]interface{}, 0)
  65. payPars = append(payPars, peyContractIds)
  66. payList, e := crm.GetPayCompanyByContractIds(payCond, payPars)
  67. if e != nil {
  68. resp.FailMsg("获取失败", "获取代付合同信息失败, Err: "+e.Error(), c)
  69. return
  70. }
  71. for i := range payList {
  72. payCompanyMap[payList[i].PayOnBehalfContractId] = payList[i].CompanyName
  73. }
  74. }
  75. respList := make([]*crm.ContractSearchListResp, 0)
  76. for i := range list {
  77. respList = append(respList, &crm.ContractSearchListResp{
  78. ContractId: list[i].ContractId,
  79. ContractCode: list[i].ContractCode,
  80. ProductId: list[i].ProductId,
  81. CompanyName: list[i].CompanyName,
  82. PayCompanyName: payCompanyMap[list[i].ContractId],
  83. SellerId: list[i].SellerId,
  84. SellerName: list[i].SellerName,
  85. ContractTypeKey: crm.ContractTypeFmsMap[list[i].ContractType],
  86. ContractType: list[i].ContractType,
  87. Price: list[i].Price,
  88. StartDate: utils.TimeTransferString(utils.FormatDate, list[i].StartDate),
  89. EndDate: utils.TimeTransferString(utils.FormatDate, list[i].EndDate),
  90. })
  91. }
  92. page.SetTotal(total)
  93. baseData := new(base.BaseData)
  94. baseData.SetPage(page)
  95. baseData.SetList(respList)
  96. resp.OkData("获取成功", baseData, c)
  97. }
  98. // PermissionList
  99. // @Title 合同品种列表
  100. // @Description 合同品种列表
  101. // @Param ProductId query int false "品种类型: 1-FICC(默认); 2-权益"
  102. // @Success 200 {object} crm.PermissionSetResp
  103. // @router /crm/contract/permission_list [get]
  104. func (rg *ContractController) PermissionList(c *gin.Context) {
  105. var req crm.ContractPermissionListReq
  106. if e := c.BindQuery(&req); e != nil {
  107. err, ok := e.(validator.ValidationErrors)
  108. if !ok {
  109. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  110. return
  111. }
  112. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  113. return
  114. }
  115. // 默认FICC
  116. productId := req.ProductId
  117. if productId == 0 {
  118. productId = 1
  119. }
  120. respList := new(crm.PermissionSetResp)
  121. // FICC
  122. if productId == 1 {
  123. // 获取品种分类配置
  124. sysConf := new(system.SysConfig)
  125. confCond := `config_code = ?`
  126. confPars := make([]interface{}, 0)
  127. confPars = append(confPars, system.ConfigKeyCrmPermissionFiccClassify)
  128. confItem, e := sysConf.FetchByCondition(confCond, confPars)
  129. if e != nil {
  130. resp.FailData("获取失败", "Err:"+e.Error(), c)
  131. return
  132. }
  133. if confItem.ConfigValue == "" {
  134. resp.FailData("获取失败", "FICC品种分类配置为空", c)
  135. return
  136. }
  137. classifyArr := strings.Split(confItem.ConfigValue, ",")
  138. if len(classifyArr) == 0 {
  139. resp.FailData("获取失败", "FICC品种分类配置为空", c)
  140. return
  141. }
  142. // 获取FICC权限
  143. ficcCond := `enabled = 1 AND permission_type = 0 AND product_id = ? AND classify_name IN ?`
  144. ficcPars := make([]interface{}, 0)
  145. ficcPars = append(ficcPars, productId, classifyArr)
  146. items, e := crm.GetPermissionSetItemsByCondition(ficcCond, ficcPars)
  147. if e != nil {
  148. resp.FailData("获取失败", "获取FICC权限信息失败, Err: "+e.Error(), c)
  149. return
  150. }
  151. ficcItemMap := make(map[string][]*crm.PermissionSetItem, 0)
  152. for i := range items {
  153. if ficcItemMap[items[i].ClassifyName] == nil {
  154. ficcItemMap[items[i].ClassifyName] = make([]*crm.PermissionSetItem, 0)
  155. }
  156. ficcItemMap[items[i].ClassifyName] = append(ficcItemMap[items[i].ClassifyName], items[i])
  157. }
  158. for i := range classifyArr {
  159. if classifyArr[i] == "市场策略" {
  160. continue
  161. }
  162. checkList := make([]int, 0)
  163. if classifyArr[i] == "宏观经济" {
  164. checkList = append(checkList, 1)
  165. }
  166. p := new(crm.PermissionSetList)
  167. p.ClassifyName = classifyArr[i]
  168. p.Items = ficcItemMap[classifyArr[i]]
  169. p.CheckList = make([]int, 0)
  170. respList.List = append(respList.List, p)
  171. }
  172. }
  173. // 权益
  174. if productId == 2 {
  175. raiCond := `enabled = 1 AND permission_type = 0 AND product_id = ? AND classify_name = ?`
  176. raiPars := make([]interface{}, 0)
  177. raiPars = append(raiPars, productId, crm.CompanyProductRaiName)
  178. items, e := crm.GetPermissionSetItemsByCondition(raiCond, raiPars)
  179. if e != nil {
  180. resp.FailData("获取失败", "获取权益权限信息失败, Err: "+e.Error(), c)
  181. return
  182. }
  183. p := new(crm.PermissionSetList)
  184. p.ClassifyName = crm.CompanyProductRaiName
  185. p.Items = items
  186. p.CheckList = make([]int, 0)
  187. respList.List = append(respList.List, p)
  188. }
  189. resp.OkData("获取成功", respList, c)
  190. }