package contract import ( "github.com/gin-gonic/gin" "github.com/go-playground/validator/v10" "hongze/fms_api/controller/resp" "hongze/fms_api/global" "hongze/fms_api/models/fms" ) // ServiceController 合同套餐 type ServiceController struct{} // ServiceList // @Title 合同套餐列表 // @Description 合同套餐列表 // @Param ProductId query int false "套餐类型: 1-FICC(默认); 2-权益" // @Success 200 {object} crm.ContractSearchListResp // @router /contract/service/list [get] func (sr *ServiceController) List(c *gin.Context) { var req fms.ContractServiceListReq if e := c.BindQuery(&req); e != nil { err, ok := e.(validator.ValidationErrors) if !ok { resp.FailData("参数解析失败", "Err:"+e.Error(), c) return } resp.FailData("参数解析失败", err.Translate(global.Trans), c) return } productId := req.ProductId if productId == 0 { productId = 1 } list, e := fms.GetContractServiceTemplateMapByProductId(productId) if e != nil { resp.FailData("获取失败", "获取产品套餐失败, Err: "+e.Error(), c) return } respList := make([]*fms.ContractServiceTemplateMapItems, 0) for i := 0; i < len(list); i++ { v := new(fms.ContractServiceTemplateMapItems) v.ContractServiceTemplateItem = *list[i] secFormatList := make([]*fms.ContractServiceTemplateMapItems, 0) secList, e := fms.GetContractServiceTemplateMapByParentId(v.ServiceTemplateId) if e != nil { resp.FailData("获取失败", "Err:"+e.Error(), c) return } secondLen := len(secList) for j := 0; j < secondLen; j++ { sec := new(fms.ContractServiceTemplateMapItems) sec.ContractServiceTemplateItem = *secList[j] detail, e := fms.GetContractServiceDetailByTemplateId(secList[j].ServiceTemplateId) if e != nil { resp.FailData("获取失败", "获取详情模板失败, Err:"+e.Error(), c) return } sec.Detail = detail // 权益存在第三级主客观套餐 thirdFormatList := make([]*fms.ContractServiceTemplateMapItems, 0) thirdList, e := fms.GetContractServiceTemplateMapByParentId(secList[j].ServiceTemplateId) if e != nil { resp.FailData("获取失败", "获取三级套餐失败, Err:"+e.Error(), c) return } for t := range thirdList { tf := new(fms.ContractServiceTemplateMapItems) tf.ContractServiceTemplateItem = *thirdList[t] thirdFormatList = append(thirdFormatList, tf) } sec.Children = thirdFormatList secFormatList = append(secFormatList, sec) } detail, e := fms.GetContractServiceDetailByTemplateId(list[i].ServiceTemplateId) if e != nil { resp.FailData("获取失败", "获取详情模板失败, Err:"+e.Error(), c) return } v.Detail = detail v.Children = secFormatList respList = append(respList, v) } resp.OkData("获取成功", respList, c) }