service.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/fms"
  8. )
  9. // ServiceController 合同套餐
  10. type ServiceController struct{}
  11. // ServiceList
  12. // @Title 合同套餐列表
  13. // @Description 合同套餐列表
  14. // @Param ProductId query int false "品种类型: 1-FICC(默认); 2-权益"
  15. // @Success 200 {object} crm.ContractSearchListResp
  16. // @router /contract/service/list [get]
  17. func (sr *ServiceController) List(c *gin.Context) {
  18. var req fms.ContractServiceListReq
  19. if e := c.BindQuery(&req); e != nil {
  20. err, ok := e.(validator.ValidationErrors)
  21. if !ok {
  22. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  23. return
  24. }
  25. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  26. return
  27. }
  28. productId := 0
  29. if req.ProductId == 0 {
  30. productId = 1
  31. }
  32. list, e := fms.GetContractServiceTemplateMapByProductId(productId)
  33. if e != nil {
  34. resp.FailData("获取失败", "获取产品套餐失败, Err: "+e.Error(), c)
  35. return
  36. }
  37. for i := 0; i < len(list); i++ {
  38. secList, e := fms.GetContractServiceTemplateMapByParentId(list[i].ServiceTemplateId)
  39. if e != nil {
  40. resp.FailData("获取失败", "Err:"+e.Error(), c)
  41. return
  42. }
  43. secondLen := len(secList)
  44. for j := 0; j < secondLen; j++ {
  45. detail, e := fms.GetContractServiceDetailByTemplateId(secList[j].ServiceTemplateId)
  46. if e != nil {
  47. resp.FailData("获取失败", "获取详情模板失败, Err:"+e.Error(), c)
  48. return
  49. }
  50. secList[j].Detail = detail
  51. // 权益存在第三级主客观套餐
  52. thirdList, e := fms.GetContractServiceTemplateMapByParentId(secList[j].ServiceTemplateId)
  53. if e != nil {
  54. resp.FailData("获取失败", "获取三级套餐失败, Err:"+e.Error(), c)
  55. return
  56. }
  57. secList[j].Children = thirdList
  58. }
  59. detail, e := fms.GetContractServiceDetailByTemplateId(list[i].ServiceTemplateId)
  60. if e != nil {
  61. resp.FailData("获取失败", "获取详情模板失败, Err:"+e.Error(), c)
  62. return
  63. }
  64. list[i].Detail = detail
  65. list[i].Children = secList
  66. }
  67. resp.OkData("获取成功", list, c)
  68. }