123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- 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/crm"
- "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
- if v.Title == "FICC小套餐" {
- //获取ficc小套餐品种
- // 获取FICC权限
- ficcCond := `enabled = 1 AND permission_type = 0 AND product_id = ? `
- ficcPars := make([]interface{}, 0)
- ficcPars = append(ficcPars, 1)
- items, e := crm.GetPermissionSetItemsByCondition(ficcCond, ficcPars)
- if e != nil {
- resp.FailData("获取失败", "获取FICC权限信息失败, Err: "+e.Error(), c)
- return
- }
- ficcItemMap := make(map[int][]*crm.PermissionSetItem, 0)
- for j := range items {
- if items[j].ParentId > 0 {
- if ficcItemMap[items[j].ParentId] == nil {
- ficcItemMap[items[j].ParentId] = make([]*crm.PermissionSetItem, 0)
- }
- ficcItemMap[items[j].ParentId] = append(ficcItemMap[items[j].ParentId], items[j])
- }
- }
- for j := range items {
- if items[j].ParentId > 0 {
- continue
- }
- if items[j].PermissionName == "市场策略" {
- continue
- }
- checkList := make([]int, 0)
- if items[j].IsPublic == 1 {
- checkList = append(checkList, items[j].ChartPermissionId)
- }
- pItem := fms.ContractServiceTemplateItem{
- ServiceTemplateId: 90000 + j*100,
- ProductId: 1,
- Pid: v.ServiceTemplateId,
- ParentTitle: v.Title,
- Title: items[j].PermissionName,
- }
- childs := make([]*fms.ContractServiceTemplateMapItems, 0)
- ficcItems := ficcItemMap[items[j].ChartPermissionId]
- for _, ficcItem := range ficcItems {
- tempItem := fms.ContractServiceTemplateItem{
- ServiceTemplateId: pItem.ServiceTemplateId + ficcItem.ChartPermissionId,
- ProductId: 1,
- Pid: pItem.ServiceTemplateId,
- ParentTitle: pItem.Title,
- Title: ficcItem.PermissionName,
- ChartPermissionId: ficcItem.ChartPermissionId,
- }
- newpItem := fms.ContractServiceTemplateMapItems{
- ContractServiceTemplateItem: tempItem,
- }
- childs = append(childs, &newpItem)
- }
- tempItem := fms.ContractServiceTemplateMapItems{
- ContractServiceTemplateItem: pItem,
- Children: childs,
- }
- v.Children = append(v.Children, &tempItem)
- }
- }
- 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)
- }
|