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" "strconv" ) // 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 } productIdStr := req.ProductId var productId int var list []*fms.ContractServiceTemplateItem var err error if productIdStr == "" { list, err = fms.GetContractServiceTemplateSecond() }else{ productId, _ = strconv.Atoi(productIdStr) list, err = fms.GetContractServiceTemplateMapByProductId(productId) } if err != nil { resp.FailData("获取失败", "获取产品套餐失败, Err: "+err.Error(), c) return } allMap := make(map[int][]*fms.ContractServiceTemplateMapItems) respList := make([]*fms.ContractServiceTemplateList, 0) for i := 0; i < len(list); i++ { item := list[i] v := new(fms.ContractServiceTemplateMapItems) v.ContractServiceTemplateItem = *item 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(item.ServiceTemplateId) if e != nil { resp.FailData("获取失败", "获取详情模板失败, Err:"+e.Error(), c) return } v.Detail = detail v.Children = secFormatList allMap[item.ProductId] = append(allMap[item.ProductId], v) } allTitleMap := map[int]string{ 1:"FICC套餐", 2:"权益套餐", } if productId == 0 { tmp1 := &fms.ContractServiceTemplateList{ Title: allTitleMap[1], Children: allMap[1], } tmp2 := &fms.ContractServiceTemplateList{ Title: allTitleMap[2], Children: allMap[2], } respList = append(respList, tmp1) respList = append(respList, tmp2) }else{ tmp := &fms.ContractServiceTemplateList{ Title: allTitleMap[productId], Children: allMap[productId], } respList = append(respList, tmp) } resp.OkData("获取成功", respList, c) } // ServiceList // @Title 合同套餐列表 // @Description 合同套餐列表 // @Param ProductId query int false "套餐类型: 1-FICC(默认); 2-权益" // @Success 200 {object} crm.ContractSearchListResp // @router /contract/service/simple [get] func (sr *ServiceController) SimpleList(c *gin.Context) { list, err := fms.GetContractServiceTemplateSecond() if err != nil { resp.FailData("获取失败", "获取产品套餐失败, Err: "+err.Error(), c) return } allList := make([]*fms.ContractServiceTemplateItem, 0) allMap := make(map[int][]*fms.ContractServiceTemplateMapItems) respList := make([]*fms.ContractServiceTemplateList, 0) for i := 0; i < len(list); i++ { if list[i].Title == "行业套餐" { industryList, e := fms.GetContractServiceTemplateMapByParentId(list[i].ServiceTemplateId) if e != nil { resp.FailData("获取失败", "Err:"+e.Error(), c) return } for _, sv := range industryList { allList = append(allList, sv) } }else{ allList = append(allList, list[i]) } } for i := 0; i < len(allList); i++ { item := allList[i] v := new(fms.ContractServiceTemplateMapItems) v.ContractServiceTemplateItem = *item allMap[item.ProductId] = append(allMap[item.ProductId], v) } allTitleMap := map[int]string{ 1:"FICC套餐", 2:"权益套餐", } tmp1 := &fms.ContractServiceTemplateList{ Title: allTitleMap[1], Children: allMap[1], } tmp2 := &fms.ContractServiceTemplateList{ Title: allTitleMap[2], Children: allMap[2], } respList = append(respList, tmp1) respList = append(respList, tmp2) resp.OkData("获取成功", respList, c) }