service.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. package contract
  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/crm"
  8. "hongze/fms_api/models/fms"
  9. "strconv"
  10. )
  11. // ServiceController 合同套餐
  12. type ServiceController struct{}
  13. // ServiceList
  14. // @Title 合同套餐列表
  15. // @Description 合同套餐列表
  16. // @Param ProductId query int false "套餐类型: 1-FICC(默认); 2-权益"
  17. // @Success 200 {object} crm.ContractSearchListResp
  18. // @router /contract/service/list [get]
  19. func (sr *ServiceController) List(c *gin.Context) {
  20. var req fms.ContractServiceListReq
  21. if e := c.BindQuery(&req); e != nil {
  22. err, ok := e.(validator.ValidationErrors)
  23. if !ok {
  24. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  25. return
  26. }
  27. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  28. return
  29. }
  30. productIdStr := req.ProductId
  31. var productId int
  32. var list []*fms.ContractServiceTemplateItem
  33. var err error
  34. if productIdStr == "" {
  35. list, err = fms.GetContractServiceTemplateSecond()
  36. } else {
  37. productId, _ = strconv.Atoi(productIdStr)
  38. list, err = fms.GetContractServiceTemplateMapByProductId(productId)
  39. }
  40. if err != nil {
  41. resp.FailData("获取失败", "获取产品套餐失败, Err: "+err.Error(), c)
  42. return
  43. }
  44. allMap := make(map[int][]*fms.ContractServiceTemplateMapItems)
  45. respList := make([]*fms.ContractServiceTemplateList, 0)
  46. for i := 0; i < len(list); i++ {
  47. item := list[i]
  48. v := new(fms.ContractServiceTemplateMapItems)
  49. v.ContractServiceTemplateItem = *item
  50. secFormatList := make([]*fms.ContractServiceTemplateMapItems, 0)
  51. secList, e := fms.GetContractServiceTemplateMapByParentId(v.ServiceTemplateId)
  52. if e != nil {
  53. resp.FailData("获取失败", "Err:"+e.Error(), c)
  54. return
  55. }
  56. secondLen := len(secList)
  57. for j := 0; j < secondLen; j++ {
  58. sec := new(fms.ContractServiceTemplateMapItems)
  59. sec.ContractServiceTemplateItem = *secList[j]
  60. detail, e := fms.GetContractServiceDetailByTemplateId(secList[j].ServiceTemplateId)
  61. if e != nil {
  62. resp.FailData("获取失败", "获取详情模板失败, Err:"+e.Error(), c)
  63. return
  64. }
  65. sec.Detail = detail
  66. // 权益存在第三级主客观套餐
  67. thirdFormatList := make([]*fms.ContractServiceTemplateMapItems, 0)
  68. thirdList, e := fms.GetContractServiceTemplateMapByParentId(secList[j].ServiceTemplateId)
  69. if e != nil {
  70. resp.FailData("获取失败", "获取三级套餐失败, Err:"+e.Error(), c)
  71. return
  72. }
  73. for t := range thirdList {
  74. tf := new(fms.ContractServiceTemplateMapItems)
  75. tf.ContractServiceTemplateItem = *thirdList[t]
  76. thirdFormatList = append(thirdFormatList, tf)
  77. }
  78. sec.Children = thirdFormatList
  79. secFormatList = append(secFormatList, sec)
  80. }
  81. detail, e := fms.GetContractServiceDetailByTemplateId(item.ServiceTemplateId)
  82. if e != nil {
  83. resp.FailData("获取失败", "获取详情模板失败, Err:"+e.Error(), c)
  84. return
  85. }
  86. v.Detail = detail
  87. v.Children = secFormatList
  88. if v.Title == "FICC小套餐" {
  89. //获取ficc小套餐品种
  90. // 获取FICC权限
  91. ficcCond := `enabled = 1 AND permission_type = 0 AND product_id = ? `
  92. ficcPars := make([]interface{}, 0)
  93. ficcPars = append(ficcPars, 1)
  94. items, e := crm.GetPermissionSetItemsByCondition(ficcCond, ficcPars)
  95. if e != nil {
  96. resp.FailData("获取失败", "获取FICC权限信息失败, Err: "+e.Error(), c)
  97. return
  98. }
  99. ficcItemMap := make(map[int][]*crm.PermissionSetItem, 0)
  100. for j := range items {
  101. if items[j].ParentId > 0 {
  102. if ficcItemMap[items[j].ParentId] == nil {
  103. ficcItemMap[items[j].ParentId] = make([]*crm.PermissionSetItem, 0)
  104. }
  105. ficcItemMap[items[j].ParentId] = append(ficcItemMap[items[j].ParentId], items[j])
  106. }
  107. }
  108. for j := range items {
  109. if items[j].ParentId > 0 {
  110. continue
  111. }
  112. if items[j].PermissionName == "市场策略" {
  113. continue
  114. }
  115. checkList := make([]int, 0)
  116. if items[j].IsPublic == 1 {
  117. checkList = append(checkList, items[j].ChartPermissionId)
  118. }
  119. pItem := fms.ContractServiceTemplateItem{
  120. ServiceTemplateId: 90000 + j*100,
  121. ProductId: 1,
  122. Pid: v.ServiceTemplateId,
  123. ParentTitle: v.Title,
  124. Title: items[j].PermissionName,
  125. }
  126. childs := make([]*fms.ContractServiceTemplateMapItems, 0)
  127. ficcItems := ficcItemMap[items[j].ChartPermissionId]
  128. for _, ficcItem := range ficcItems {
  129. tempItem := fms.ContractServiceTemplateItem{
  130. ServiceTemplateId: pItem.ServiceTemplateId + ficcItem.ChartPermissionId,
  131. ProductId: 1,
  132. Pid: pItem.ServiceTemplateId,
  133. ParentTitle: pItem.Title,
  134. Title: ficcItem.PermissionName,
  135. ChartPermissionId: ficcItem.ChartPermissionId,
  136. }
  137. newpItem := fms.ContractServiceTemplateMapItems{
  138. ContractServiceTemplateItem: tempItem,
  139. }
  140. childs = append(childs, &newpItem)
  141. }
  142. tempItem := fms.ContractServiceTemplateMapItems{
  143. ContractServiceTemplateItem: pItem,
  144. Children: childs,
  145. }
  146. v.Children = append(v.Children, &tempItem)
  147. }
  148. }
  149. allMap[item.ProductId] = append(allMap[item.ProductId], v)
  150. }
  151. allTitleMap := map[int]string{
  152. 1: "FICC套餐",
  153. 2: "权益套餐",
  154. }
  155. if productId == 0 {
  156. tmp1 := &fms.ContractServiceTemplateList{
  157. Title: allTitleMap[1],
  158. Children: allMap[1],
  159. }
  160. tmp2 := &fms.ContractServiceTemplateList{
  161. Title: allTitleMap[2],
  162. Children: allMap[2],
  163. }
  164. respList = append(respList, tmp1)
  165. respList = append(respList, tmp2)
  166. } else {
  167. tmp := &fms.ContractServiceTemplateList{
  168. Title: allTitleMap[productId],
  169. Children: allMap[productId],
  170. }
  171. respList = append(respList, tmp)
  172. }
  173. resp.OkData("获取成功", respList, c)
  174. }
  175. // ServiceList
  176. // @Title 合同套餐列表
  177. // @Description 合同套餐列表
  178. // @Param ProductId query int false "套餐类型: 1-FICC(默认); 2-权益"
  179. // @Success 200 {object} crm.ContractSearchListResp
  180. // @router /contract/service/simple [get]
  181. func (sr *ServiceController) SimpleList(c *gin.Context) {
  182. list, err := fms.GetContractServiceTemplateSecond()
  183. if err != nil {
  184. resp.FailData("获取失败", "获取产品套餐失败, Err: "+err.Error(), c)
  185. return
  186. }
  187. allList := make([]*fms.ContractServiceTemplateItem, 0)
  188. allMap := make(map[int][]*fms.ContractServiceTemplateMapItems)
  189. respList := make([]*fms.ContractServiceTemplateList, 0)
  190. for i := 0; i < len(list); i++ {
  191. if list[i].Title == "行业套餐" {
  192. industryList, e := fms.GetContractServiceTemplateMapByParentId(list[i].ServiceTemplateId)
  193. if e != nil {
  194. resp.FailData("获取失败", "Err:"+e.Error(), c)
  195. return
  196. }
  197. for _, sv := range industryList {
  198. allList = append(allList, sv)
  199. }
  200. } else {
  201. allList = append(allList, list[i])
  202. }
  203. }
  204. for i := 0; i < len(allList); i++ {
  205. item := allList[i]
  206. v := new(fms.ContractServiceTemplateMapItems)
  207. v.ContractServiceTemplateItem = *item
  208. allMap[item.ProductId] = append(allMap[item.ProductId], v)
  209. }
  210. allTitleMap := map[int]string{
  211. 1: "FICC套餐",
  212. 2: "权益套餐",
  213. }
  214. tmp1 := &fms.ContractServiceTemplateList{
  215. Title: allTitleMap[1],
  216. Children: allMap[1],
  217. }
  218. tmp2 := &fms.ContractServiceTemplateList{
  219. Title: allTitleMap[2],
  220. Children: allMap[2],
  221. }
  222. respList = append(respList, tmp1)
  223. respList = append(respList, tmp2)
  224. resp.OkData("获取成功", respList, c)
  225. }