Kaynağa Gözat

Merge branch 'dev/2.4_rai_new'

# Conflicts:
#	models/fms/contract_invoice.go
ziwen 2 yıl önce
ebeveyn
işleme
561b3c236f

+ 104 - 19
controller/census/invoice_payment.go

@@ -10,6 +10,7 @@ import (
 	"hongze/fms_api/global"
 	"hongze/fms_api/models/base"
 	"hongze/fms_api/models/fms"
+	fmsService "hongze/fms_api/services/fms"
 	"hongze/fms_api/utils"
 	"net/http"
 	"strconv"
@@ -326,7 +327,7 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
 
 	// 表头, 套餐动态获取
 	rowTitle := []string{"序号", "客户名称", "是否新客户", "合同有效期", "开票日", "开票金额", "到款日", "到款金额", "付款方式", "销售",
-		"组别"}
+		"销售组别", "销售类型"}
 	serviceTempCond := ``
 	serviceTempPars := make([]interface{}, 0)
 	serviceTempOB := new(fms.ContractServiceTemplate)
@@ -335,18 +336,81 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
 		resp.FailData("获取套餐模板列表失败", "Err:"+e.Error(), c)
 		return
 	}
+	serviceTempListMap := make(map[int]*fms.ContractServiceTemplate)
+	var serviceTempShow [] *fms.ContractServiceTemplate
 	for i := range serviceTempList {
-		rowTitle = append(rowTitle, serviceTempList[i].Title)
+		serviceTempListMap[serviceTempList[i].ServiceTemplateId] = serviceTempList[i]
+	}
+	for i := range serviceTempList {
+		if serviceTempList[i].ProductId == 1 {
+			rowTitle = append(rowTitle, serviceTempList[i].Title)
+			serviceTempShow = append(serviceTempShow, serviceTempList[i])
+		}else if serviceTempList[i].ProductId == 2{
+			if serviceTempList[i].Title == "行业套餐" || serviceTempList[i].Title == "权益大套餐" || (serviceTempList[i].Title == "策略" && serviceTempListMap[serviceTempList[i].Pid].Pid==0){
+			}else if serviceTempList[i].Title == "医药" || serviceTempList[i].Title == "消费" || serviceTempList[i].Title == "科技" || serviceTempList[i].Title == "智造" {
+			}else {
+				serviceTempShow = append(serviceTempShow, serviceTempList[i])
+			}
+			if serviceTempList[i].Title == "行业套餐" || serviceTempList[i].Title == "45万" ||  serviceTempList[i].Title == "70万" {
+				continue
+			}
+
+			if serviceTempList[i].Pid > 0 &&  serviceTempListMap[serviceTempList[i].Pid].Pid > 0 {
+				continue
+			}
+
+			rowTitle = append(rowTitle, serviceTempList[i].Title)
+		}
 	}
 
+	hi := 0
+	insertHi := 0
 	titleRow := sheet.AddRow()
 	for i := range rowTitle {
 		v := titleRow.AddCell()
 		v.SetString(rowTitle[i])
 		v.SetStyle(style)
+		if rowTitle[i] != "权益大套餐" && rowTitle[i] != "医药" && rowTitle[i] != "消费" && rowTitle[i] != "科技" && rowTitle[i] != "智造" {
+			v.VMerge = 1
+			hi ++
+		}else{
+			if insertHi == 0 {
+				insertHi = hi
+			}
+			v.HMerge = 1
+			titleRow.AddCell().SetString("")
+		}
+	}
+
+	// 新增一行放主观和客观
+	specialRow := sheet.AddRow()
+	for i:=0; i< hi; i++ {
+		if i == insertHi {
+			v1 := specialRow.AddCell()
+			v1.SetString("45万")
+			v1.SetStyle(style)
+			v1 = specialRow.AddCell()
+			v1.SetString("70万")
+			v1.SetStyle(style)
+			for j:=0; j<8;j++ {
+				if j%2 ==0 {
+					v1 = specialRow.AddCell()
+					v1.SetString("主观")
+					v1.SetStyle(style)
+				}else{
+					v1 = specialRow.AddCell()
+					v1.SetString("客观")
+					v1.SetStyle(style)
+				}
+			}
+		}else{
+			v := specialRow.AddCell()
+			v.SetString("")
+		}
 	}
 
 	newCompanyMap := map[int]string{0: "否", 1: "是"}
+	sellerTypeMap := map[int]string{1:"FICC销售", 2:"权益销售"}
 	for k, v := range list {
 		dataRow := sheet.AddRow()
 		// 前四个单元格根据每行开票到款条数向下合并
@@ -379,16 +443,27 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
 				fms.ContractPaymentPayTypeNameMap[v2.PayType], // 付款方式
 				v2.SellerName,                                 // 销售
 				v2.SellerGroupName,                            // 组别
+				sellerTypeMap[v2.SellerType],                  // 销售类型
 			}
 			// 套餐金额信息
-			for i := range serviceTempList {
-				sa := ""
+			serviceTempShowAmount := make(map[int]string)
+			for i := range serviceTempShow {
 				for s2 := range v2.ServiceAmountList {
-					if v2.ServiceAmountList[s2].ServiceTemplateId == serviceTempList[i].ServiceTemplateId {
-						sa = fmt.Sprint(v2.ServiceAmountList[s2].Amount)
+					item := v2.ServiceAmountList[s2]
+					if item.ServiceTemplateId == serviceTempShow[i].ServiceTemplateId {
+						serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId] = fmt.Sprint(item.Amount)
+						break
+					}else if serviceTempShow[i].Pid == item.ServiceTemplateId {
+						serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId] = fmt.Sprint(item.Amount/2)
 						break
 					}
 				}
+			}
+			for i := range serviceTempShow {
+				sa := ""
+				if am, ok :=  serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId]; ok {
+					sa = am
+				}
 				rowData = append(rowData, sa)
 			}
 			// 首行开票到款
@@ -454,16 +529,18 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 	// 客户姓名/销售
 	if req.Keyword != "" {
 		kw := "%" + req.Keyword + "%"
-		cond += ` AND b.company_name LIKE ? OR c.seller_name LIKE ?`
-		pars = append(pars, kw, kw)
+		cond += ` AND b.company_name LIKE ?`
+		pars = append(pars, kw)
 	}
-	if req.SellGroupId > 0 {
-		cond += ` AND c.seller_group_id = ?`
-		pars = append(pars, req.SellGroupId)
+	if req.SellerIds != "" {
+		sellerIds := strings.Split(req.SellerIds, ",")
+		cond += ` AND (c.seller_id in ?)`
+		pars = append(pars, sellerIds)
 	}
 	// 套餐筛选
-	if req.ServiceType != 0 {
-		tempRegisterIds, e := fms.GetContractRegisterIdsByTempId(req.ServiceType)
+	if req.ServiceTypes != "" {
+		serviceTypes := strings.Split(req.ServiceTypes, ",")
+		tempRegisterIds, e := fms.GetContractRegisterIdsByTempId(serviceTypes)
 		if e != nil {
 			resp.FailMsg("获取失败", "获取合同登记IDs失败, Err: "+e.Error(), c)
 			return
@@ -619,7 +696,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 			}
 
 			// 合同套餐
-			contractServiceCond := `contract_register_id IN ?`
+			/*contractServiceCond := `contract_register_id IN ?`
 			contractServicePars := make([]interface{}, 0)
 			contractServicePars = append(contractServicePars, queryRegisterIds)
 			contractServiceOB := new(fms.ContractService)
@@ -637,7 +714,12 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 				contractServiceMap[contractServiceList[i].ContractRegisterId] = append(contractServiceMap[contractServiceList[i].ContractRegisterId], contractServiceList[i])
 				servicesNameMap[contractServiceList[i].ContractRegisterId] = append(servicesNameMap[contractServiceList[i].ContractRegisterId], contractServiceList[i].Title)
 			}
-
+*/
+			servicesNameMap, serviceFormatMap, e := fmsService.GetContractServiceNameFormat(queryRegisterIds)
+			if e != nil {
+				listErr = fmt.Errorf("获取合同套餐列表失败, Err: %s", e.Error())
+				return
+			}
 			// 到款套餐分配
 			serviceAmountMap := make(map[int][]*fms.ContractPaymentServiceAmount, 0)
 			if len(paymentIds) > 0 {
@@ -670,6 +752,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 				v.SellerName = summaryList[i].SellerName
 				v.SellerGroupId = summaryList[i].SellerGroupId
 				v.SellerGroupName = summaryList[i].SellerGroupName
+				v.SellerType = summaryList[i].ServiceProductId
 				v.PaymentId = summaryList[i].PaymentId
 				v.PaymentDate = utils.TimeTransferString(utils.FormatDate, summaryList[i].PaymentDate)
 				v.PaymentAmount = summaryList[i].PaymentAmount
@@ -684,12 +767,13 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 					}
 				}
 				// 合同对应的所有套餐
-				svList := contractServiceMap[summaryList[i].RegisterId]
+				svList := serviceFormatMap[summaryList[i].RegisterId]
 				if svList != nil {
 					for ii := range svList {
 						vv := new(fms.ContractPaymentServiceAmountItem)
 						vv.ServiceTemplateId = svList[ii].ServiceTemplateId
-						vv.ServiceTemplateName = svList[ii].Title
+						vv.ServiceTemplateName = svList[ii].FormatTitle
+						vv.ServiceTemplatePid = svList[ii].ServiceTemplatePid
 						k2 := fmt.Sprintf("%d-%d", summaryList[i].PaymentId, svList[ii].ServiceTemplateId)
 						a := amountMap[k2]
 						if a != nil {
@@ -714,8 +798,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 				v.NewCompany = registerList[i].NewCompany
 				v.StartDate = utils.TimeTransferString(utils.FormatDate, registerList[i].StartDate)
 				v.EndDate = utils.TimeTransferString(utils.FormatDate, registerList[i].EndDate)
-				svList := servicesNameMap[registerList[i].ContractRegisterId]
-				v.ServicesName = strings.Join(svList, ",")
+				v.ServicesName = servicesNameMap[registerList[i].ContractRegisterId]
 				v.InvoicePaymentList = summaryMap[registerList[i].SummaryId]
 				respList = append(respList, v)
 			}
@@ -848,3 +931,5 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 	baseData.SetList(results)
 	resp.OkData("获取成功", baseData, c)
 }
+
+

+ 27 - 5
controller/census/seller.go

@@ -42,9 +42,20 @@ func (ct *SellerController) GroupInvoiceList(c *gin.Context) {
 		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
 		return
 	}
-
+	var departmentId int
+	if req.SellerType == 1 {
+		departmentId = crm.SellerDepartmentId
+	}else if req.SellerType == 2 {
+		departmentId = crm.RaiSellerDepartmentId
+	}else if req.SellerType == 0 {
+		resp.Fail("请选择销售类型", c)
+		return
+	}else {
+		resp.Fail("请选择正确的销售类型", c)
+		return
+	}
 	outCond := ` department_id = %d AND parent_id = 0 `
-	outCond = fmt.Sprintf(outCond, crm.SellerDepartmentId)
+	outCond = fmt.Sprintf(outCond, departmentId)
 	cond := ` invoice_type = %d AND is_deleted = 0 AND seller_group_id != 0 `
 	cond = fmt.Sprintf(cond, fms.ContractInvoiceTypeMake)
 	pars := make([]interface{}, 0)
@@ -199,12 +210,23 @@ func (ct *SellerController) InvoiceList(c *gin.Context) {
 		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
 		return
 	}
-
+	var departmentId int
+	if req.SellerType == 1 {
+		departmentId = crm.SellerDepartmentId
+	}else if req.SellerType == 2 {
+		departmentId = crm.RaiSellerDepartmentId
+	}else if req.SellerType == 0 {
+		resp.Fail("请选择销售类型", c)
+		return
+	}else {
+		resp.Fail("请选择正确的销售类型", c)
+		return
+	}
 	pars := make([]interface{}, 0)
 	outCond := ` a.department_id = %d AND a.enabled = 1 `
-	outCond = fmt.Sprintf(outCond, crm.SellerDepartmentId)
+	outCond = fmt.Sprintf(outCond, departmentId)
 	totalCond := ` department_id = %d AND enabled = 1 `
-	totalCond = fmt.Sprintf(totalCond, crm.SellerDepartmentId)
+	totalCond = fmt.Sprintf(totalCond, departmentId)
 	totalPars := make([]interface{}, 0)
 	if req.GroupId > 0 {
 		// 筛选组别时, 查询当前组别的下级组(因为admin表存的group_id, 有三级的存的是子ID, 只有二级的存的才是父ID =_=!)

+ 1 - 0
controller/contract/payment.go

@@ -84,6 +84,7 @@ func (ct *PaymentController) DistributePaymentServiceAmount(c *gin.Context) {
 		v := &fms.ContractPaymentServiceAmount{
 			ContractRegisterId: req.ContractRegisterId,
 			ContractPaymentId:  req.ContractPaymentId,
+			ServiceTemplatePid: req.List[i].ServiceTemplatePid,
 			ServiceTemplateId:  req.List[i].ServiceTemplateId,
 			Amount:             req.List[i].Amount,
 		}

Dosya farkı çok büyük olduğundan ihmal edildi
+ 498 - 94
controller/contract/register.go


+ 93 - 10
controller/contract/service.go

@@ -6,6 +6,7 @@ import (
 	"hongze/fms_api/controller/resp"
 	"hongze/fms_api/global"
 	"hongze/fms_api/models/fms"
+	"strconv"
 )
 
 // ServiceController 合同套餐
@@ -29,20 +30,27 @@ func (sr *ServiceController) List(c *gin.Context) {
 		return
 	}
 
-	productId := req.ProductId
-	if productId == 0 {
-		productId = 1
+	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)
 	}
 
-	list, e := fms.GetContractServiceTemplateMapByProductId(productId)
-	if e != nil {
-		resp.FailData("获取失败", "获取产品套餐失败, Err: "+e.Error(), c)
+	if err != nil {
+		resp.FailData("获取失败", "获取产品套餐失败, Err: "+err.Error(), c)
 		return
 	}
-	respList := make([]*fms.ContractServiceTemplateMapItems, 0)
+	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 = *list[i]
+		v.ContractServiceTemplateItem = *item
 
 		secFormatList := make([]*fms.ContractServiceTemplateMapItems, 0)
 		secList, e := fms.GetContractServiceTemplateMapByParentId(v.ServiceTemplateId)
@@ -77,14 +85,89 @@ func (sr *ServiceController) List(c *gin.Context) {
 			secFormatList = append(secFormatList, sec)
 		}
 
-		detail, e := fms.GetContractServiceDetailByTemplateId(list[i].ServiceTemplateId)
+		detail, e := fms.GetContractServiceDetailByTemplateId(item.ServiceTemplateId)
 		if e != nil {
 			resp.FailData("获取失败", "获取详情模板失败, Err:"+e.Error(), c)
 			return
 		}
 		v.Detail = detail
 		v.Children = secFormatList
-		respList = append(respList, v)
+		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)
 }

+ 25 - 49
controller/crm/company_seller.go

@@ -15,61 +15,15 @@ type CompanySellerController struct{}
 // List
 // @Title 销售列表
 // @Description 销售列表
-// @Param   SellerType  query  int  false  "销售类型: 0-所有; 1-FICC; 2-权益"
-// @Success 200 {object} crm.CompanySellerList
+// @Success 200 {object} crm.SellerAdminWithGroupList
 // @router /crm/company_seller/list [get]
 func (rg *CompanySellerController) List(c *gin.Context) {
-	var req crm.CompanySellerListReq
-	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
-	}
-
-	//roleCodeArr := make([]string, 0)
-	//if req.SellerType == crm.CompanyProductRai {
-	//	roleCodeArr = []string{
-	//		crm.ROLE_TYPE_CODE_RAI_ADMIN,
-	//		crm.ROLE_TYPE_CODE_RAI_DEPARTMENT,
-	//		crm.ROLE_TYPE_CODE_RAI_GROUP,
-	//		crm.ROLE_TYPE_CODE_RAI_SELLER,
-	//	}
-	//} else {
-	//	roleCodeArr = []string{
-	//		crm.ROLE_TYPE_CODE_FICC_ADMIN,
-	//		crm.ROLE_TYPE_CODE_FICC_DEPARTMENT,
-	//		crm.ROLE_TYPE_CODE_FICC_GROUP,
-	//		crm.ROLE_TYPE_CODE_FICC_TEAM,
-	//		crm.ROLE_TYPE_CODE_FICC_SELLER,
-	//	}
-	//}
-	//cond := `b.role_type_code IN ?`
-	//pars := make([]interface{}, 0)
-	//pars = append(pars, roleCodeArr)
-	//list, e := crm.GetCompanySellerByRoleCodes(cond, pars)
-	//if e != nil {
-	//	resp.FailData("获取失败", "获取销售列表失败, Err:"+e.Error(), c)
-	//	return
-	//}
-
 	// 此处调整为只取销售部门的人员, 而不是原先的根据角色取
-	sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
+	list, e := crmService.GetSellerDepartmentList()
 	if e != nil {
 		resp.FailData("获取失败", "获取销售列表失败, Err:"+e.Error(), c)
 		return
 	}
-	list := make([]*crm.CompanySellerList, 0)
-	for i := range sellerList {
-		list = append(list, &crm.CompanySellerList{
-			AdminId: sellerList[i].SellerId,
-			AdminName: sellerList[i].SellerName,
-			RealName: sellerList[i].SellerName,
-		})
-	}
 	resp.OkData("获取成功", list, c)
 }
 
@@ -79,10 +33,32 @@ func (rg *CompanySellerController) List(c *gin.Context) {
 // @Success 200 {object} crm.SysGroup
 // @router /crm/company_seller/group_list [get]
 func (rg *CompanySellerController) GroupList(c *gin.Context) {
+	var req crm.SysGroupListReq
+	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
+	}
+	var departmentId int
+	if req.SellerType == 1 {
+		departmentId = crm.SellerDepartmentId
+	}else if req.SellerType == 2 {
+		departmentId = crm.RaiSellerDepartmentId
+	}else if req.SellerType == 0 {
+		resp.Fail("请选择销售类型", c)
+		return
+	}else {
+		resp.Fail("请选择正确的销售类型", c)
+		return
+	}
 	groupOB := new(crm.SysGroup)
 	cond := `department_id = ? AND parent_id = 0`
 	pars := make([]interface{}, 0)
-	pars = append(pars, crm.SellerDepartmentId)
+	pars = append(pars, departmentId)
 	list, e := groupOB.List(cond, pars)
 	if e != nil {
 		resp.FailData("获取失败", "获取销售组别列表失败, Err:"+e.Error(), c)

+ 1 - 0
controller/crm/contract.go

@@ -235,6 +235,7 @@ func (rg *ContractController) ServiceDetail(c *gin.Context) {
 
 	contractDetail, e := crmService.GetContractDetail(req.ContractId)
 	if e != nil {
+		global.LOG.Error(e.Error())
 		resp.FailMsg("获取失败", "获取合同套餐及品种信息失败, Err: "+e.Error(), c)
 		return
 	}

+ 25 - 6
models/crm/company_seller.go

@@ -29,10 +29,29 @@ func GetCompanySellerByRoleCodes(condition string, pars []interface{}) (results
 
 // SellerAdminWithGroupTeam 系统销售(包含大小分组)
 type SellerAdminWithGroupTeam struct {
-	SellerId   int    `json:"seller_id" description:"销售ID"`
-	SellerName string `json:"seller_name" description:"销售名称"`
-	GroupId    int    `json:"group_id" description:"分组ID"`
-	GroupName  string `json:"group_name" description:"分组名称"`
-	TeamId     int    `json:"team_id" description:"小组ID"`
-	TeamName   string `json:"team_name" description:"小组名称"`
+	SellerId     int    `json:"seller_id" description:"销售ID"`
+	SellerName   string `json:"seller_name" description:"销售名称"`
+	GroupId      int    `json:"group_id" description:"分组ID"`
+	GroupName    string `json:"group_name" description:"分组名称"`
+	TeamId       int    `json:"team_id" description:"小组ID"`
+	TeamName     string `json:"team_name" description:"小组名称"`
+	DepartmentId int    `json:"department_id" description:"部分ID"`
 }
+
+// SellerAdminWithGroupList 系统销售(包含大分组)
+type SellerAdminWithGroupList struct {
+	AllList  []SellerAdminWithGroupTree `json:"all_list"`
+	FiccList []SellerAdminList          `json:"ficc_list"`
+	RaiList  []SellerAdminList          `json:"rai_list"`
+}
+
+type SellerAdminWithGroupTree struct {
+	SellerId   int                        `json:"seller_id"`
+	SellerName string                     `json:"seller_name"`
+	Child      []SellerAdminWithGroupTree `json:"child"`
+}
+
+type SellerAdminList struct {
+	SellerId   int    `json:"seller_id"`
+	SellerName string `json:"seller_name"`
+}

+ 3 - 1
models/crm/constants.go

@@ -46,8 +46,10 @@ const (
 	ContractTypeBusiness = "业务合同"
 	ContractTypePayment  = "代付合同"
 
-	// 销售部门ID
+	// FICC销售部门ID
 	SellerDepartmentId = 2
+	// 权益销售部门ID
+	RaiSellerDepartmentId = 5
 )
 
 // ContractTypeFmsMap CRM系统合同类型/FMS系统合同类型

+ 1 - 1
models/crm/contract.go

@@ -125,7 +125,7 @@ type ContractDetail struct {
 	RescindTimeStr             string `description:"解约时间(字符串形式)"`
 	ModifyTimeStr              string `description:"最近一次更新时间(字符串形式)"`
 	CreateTimeStr              string `description:"合同添加时间(字符串形式)"`
-	Service                    []*ContractServiceAndDetail
+	Service                    []*ContractServiceAndDetailRespItem
 	RelationContractDetailList []*ContractDetail     `description:"关联合同详情"`
 	PermissionLookList         []*PermissionLookList `description:"合同里面的权限列表"`
 }

+ 26 - 3
models/crm/contract_service.go

@@ -8,6 +8,7 @@ type ContractServiceAndDetail struct {
 	ContractId         int    `description:"合同id"`
 	ProductId          int    `description:"产品id,1:ficc;2:权益"`
 	ServiceTemplateId  int    `description:"合同服务模板id"`
+	Pid                int    `json:"pid" description:"父级ID"`
 	Title              string `description:"套餐标题"`
 	Value              string `description:"套餐的值"`
 	HasDetail          string `description:"是否有详情,枚举值:是、否;默认:否"`
@@ -22,6 +23,7 @@ type ContractServiceAndDetailQueryItem struct {
 	ContractId        int    `description:"合同id"`
 	ProductId         int    `description:"产品id,1:ficc;2:权益"`
 	ServiceTemplateId int    `description:"合同服务模板id"`
+	Pid               int    `json:"pid" description:"父级ID"`
 	Title             string `description:"套餐标题"`
 	Value             string `description:"套餐的值"`
 	HasDetail         string `description:"是否有详情,枚举值:是、否;默认:否"`
@@ -29,9 +31,9 @@ type ContractServiceAndDetailQueryItem struct {
 	ChartPermissionId int    `description:"权限id"`
 }
 
-func GetContractServiceAndDetailList(contractId int) (list []*ContractServiceAndDetail, err error) {
+func GetContractServiceAndDetailList(contractId int) (list []*ContractServiceAndDetailRespItem, err error) {
 	results := make([]*ContractServiceAndDetailQueryItem, 0)
-	list = make([]*ContractServiceAndDetail, 0)
+	list = make([]*ContractServiceAndDetailRespItem, 0)
 	query := global.MYSQL["report"].
 		Table("contract_service").
 		Where("contract_id = ?", contractId)
@@ -40,11 +42,12 @@ func GetContractServiceAndDetailList(contractId int) (list []*ContractServiceAnd
 		return
 	}
 	for i := range results {
-		list = append(list, &ContractServiceAndDetail{
+		list = append(list, &ContractServiceAndDetailRespItem{
 			ContractServiceId: results[i].ContractServiceId,
 			ContractId:        results[i].ContractId,
 			ProductId:         results[i].ProductId,
 			ServiceTemplateId: results[i].ServiceTemplateId,
+			Pid:               results[i].Pid,
 			Title:             results[i].Title,
 			Value:             results[i].Value,
 			HasDetail:         results[i].HasDetail,
@@ -54,3 +57,23 @@ func GetContractServiceAndDetailList(contractId int) (list []*ContractServiceAnd
 	}
 	return
 }
+
+// ContractServiceAndDetailRespItem
+type ContractServiceAndDetailRespItem struct {
+	ContractServiceId     int    `description:"套餐ID"`
+	ContractId            int    `description:"合同id"`
+	ProductId             int    `description:"产品id,1:ficc;2:权益"`
+	ServiceTemplateId     int    `description:"合同服务模板id"`
+	Pid                   int    `json:"pid" description:"父级ID"`
+	Title                 string `description:"套餐标题"`
+	Value                 string `description:"套餐的值"`
+	HasDetail             string `description:"是否有详情,枚举值:是、否;默认:否"`
+	TableValue            string `description:"表格数据,用于word生成时的json数据"`
+	ChartPermissionId     int    `description:"权限id"`
+	ChartPermissionIds    []int  `description:"小套餐-权限IDs"`
+	FMSServiceTemplateId  int    `description:"fms里的模版id"`
+	FMSServiceTemplatePId int    `description:"fms里的父级模版id"`
+	FMSTitle              string `description:"fms里的模版名称"`
+	FMSPTitle             string `description:"fms里的父级模版名称"`
+	DetailList            []*ContractServiceDetail
+}

+ 4 - 0
models/crm/sys_group.go

@@ -18,6 +18,10 @@ func (m *SysGroup) TableName() string {
 	return "sys_group"
 }
 
+type SysGroupListReq struct {
+	SellerType int    `json:"seller_type" form:"seller_type" description:"销售类型:1ficc销售,2权益销售"`
+}
+
 func (m *SysGroup) List(condition string, pars []interface{}) (list []*SysGroup, err error) {
 	list = make([]*SysGroup, 0)
 	err = global.MYSQL["report"].Model(m).

+ 44 - 34
models/fms/contract_invoice.go

@@ -29,6 +29,7 @@ type ContractInvoice struct {
 	AdminName          string    `gorm:"column:admin_name" json:"admin_name" description:"操作人姓名"`
 	Remark             string    `gorm:"column:remark" json:"remark" description:"备注信息"`
 	IsDeleted          int       `gorm:"column:is_deleted" json:"is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
+	ServiceProductId   int       `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
 	IsPrePay           int       `gorm:"column:is_pre_pay" json:"is_pre_pay" description:"是否预付款: 0-不是; 1-是"`
 	base.TimeBase
 }
@@ -53,6 +54,7 @@ type ContractInvoiceItem struct {
 	SellerName         string  `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
 	PayType            int     `gorm:"column:pay_type" json:"pay_type" description:"付款方式:0-无;1-年付;2-半年付;3-季付;4-次付;5-异常"`
 	Remark             string  `gorm:"column:remark" json:"remark" description:"备注信息"`
+	ServiceProductId   int     `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
 	IsPrePay           int     `gorm:"column:is_pre_pay" json:"is_pre_pay" description:"是否预付款: 0-不是; 1-是"`
 	CreateTime         string  `gorm:"column:create_time" json:"create_time" description:"创建时间"`
 }
@@ -153,12 +155,13 @@ type ContractInvoiceSaveReq struct {
 
 // ContractInvoiceSaveItem 合同开票数据
 type ContractInvoiceSaveItem struct {
-	InvoiceId    int     `json:"invoice_id" description:"开票ID"`
-	OriginAmount float64 `json:"origin_amount" description:"开票(到款)金额"`
-	Amount       float64 `json:"amount" description:"换算后的金额"`
-	InvoiceDate  string  `json:"invoice_date" description:"开票日期/到款月"`
-	Remark       string  `json:"remark" description:"备注"`
-	SellerId     int     `json:"seller_id" description:"销售ID"`
+	ServiceProductId int     `json:"service_product_id" binding:"oneof=1 2" description:"套餐类型:1ficc套餐,2权益套餐"`
+	InvoiceId        int     `json:"invoice_id" description:"开票ID"`
+	OriginAmount     float64 `json:"origin_amount" description:"开票(到款)金额"`
+	Amount           float64 `json:"amount" description:"换算后的金额"`
+	InvoiceDate      string  `json:"invoice_date" description:"开票日期/到款月"`
+	Remark           string  `json:"remark" description:"备注"`
+	SellerId         int     `json:"seller_id" description:"销售ID"`
 }
 
 // GetContractInvoiceItemList 获取开票到款列表
@@ -195,6 +198,7 @@ func formatContractInvoice2ItemList(list []*ContractInvoice) (itemList []*Contra
 			Remark:             list[i].Remark,
 			IsPrePay:           list[i].IsPrePay,
 			CreateTime:         utils.TimeTransferString(utils.FormatDateTime, list[i].CreateTime),
+			ServiceProductId:   list[i].ServiceProductId,
 		})
 	}
 	return
@@ -202,13 +206,15 @@ func formatContractInvoice2ItemList(list []*ContractInvoice) (itemList []*Contra
 
 // ContractInvoiceListReq 合同开票/到款登记列表请求体
 type ContractInvoiceListReq struct {
-	InvoiceType  int     `json:"invoice_type" form:"invoice_type" binding:"oneof=1 2" description:"类型: 1-开票登记; 2-到款登记"`
-	ContractCode string  `json:"contract_code" form:"contract_code" binding:"omitempty" description:"合同编号"`
-	StartDate    string  `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"开始日期"`
-	EndDate      string  `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"结束日期"`
-	MinAmount    float64 `json:"min_amount" form:"min_amount" description:"开票金额区间-最小值"`
-	MaxAmount    float64 `json:"max_amount" form:"max_amount" description:"开票金额区间-最大值"`
-	IsExport     int     `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
+	InvoiceType      int     `json:"invoice_type" form:"invoice_type" binding:"oneof=1 2" description:"类型: 1-开票登记; 2-到款登记"`
+	SellerIds        string  `json:"seller_ids" form:"seller_ids" description:"销售ID, 多个id用逗号拼接"`
+	ContractCode     string  `json:"contract_code" form:"contract_code" binding:"omitempty" description:"合同编号"`
+	StartDate        string  `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"开始日期"`
+	EndDate          string  `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"结束日期"`
+	MinAmount        float64 `json:"min_amount" form:"min_amount" description:"开票金额区间-最小值"`
+	MaxAmount        float64 `json:"max_amount" form:"max_amount" description:"开票金额区间-最大值"`
+	IsExport         int     `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
+	ServiceProductId int     `json:"service_product_id" form:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
 	base.PageReq
 }
 
@@ -248,6 +254,7 @@ func formatContractInvoice2Item(item *ContractInvoice) (formatItem *ContractInvo
 	formatItem.PayType = item.PayType
 	formatItem.Remark = item.Remark
 	formatItem.IsPrePay = item.IsPrePay
+	formatItem.ServiceProductId = item.ServiceProductId
 	formatItem.CreateTime = utils.TimeTransferString(utils.FormatDateTime, item.CreateTime)
 	return
 }
@@ -261,16 +268,16 @@ func DeleteContractInvoicesByRegisterId(registerId int) (err error) {
 
 // InvoicePaymentCensusListReq 商品到款统计列表请求体
 type InvoicePaymentCensusListReq struct {
-	Keyword     string `json:"keyword" form:"keyword" binding:"omitempty" description:"关键词"`
-	SellGroupId int    `json:"sell_group_id" form:"sell_group_id" description:"销售组别ID"`
-	ServiceType int    `json:"service_type" form:"service_type" description:"套餐类型"`
-	StartDate   string `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"开始日期"`
-	EndDate     string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"结束日期"`
-	HasInvoice  string `json:"has_invoice" form:"has_invoice" description:"是否已开票: 0-否; 1-是; 空-全部"`
-	HasPayment  string `json:"has_payment" form:"has_payment" description:"是否已到款: 0-否; 1-是; 空-全部"`
-	IsExport    int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
-	SortParam   string `json:"sort_param" form:"sort_param" description:"排序字段参数,用来排序的字段, 枚举值:'invoice_time':开票日 、 'payment_date':到款日"`
-	SortType    string `json:"sort_type" form:"sort_type" description:"如何排序,是正序还是倒序,枚举值:asc 正序,desc 倒叙"`
+	Keyword      string `json:"keyword" form:"keyword" binding:"omitempty" description:"关键词"`
+	SellerIds    string `json:"seller_ids" form:"seller_ids" description:"销售ID,多个ID之间用逗号拼接"`
+	ServiceTypes string `json:"service_types" form:"service_types" description:"套餐类型, 多个套餐之间用逗号拼接"`
+	StartDate    string `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"开始日期"`
+	EndDate      string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"结束日期"`
+	HasInvoice   string `json:"has_invoice" form:"has_invoice" description:"是否已开票: 0-否; 1-是; 空-全部"`
+	HasPayment   string `json:"has_payment" form:"has_payment" description:"是否已到款: 0-否; 1-是; 空-全部"`
+	IsExport     int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
+	SortParam    string `json:"sort_param" form:"sort_param" description:"排序字段参数,用来排序的字段, 枚举值:'invoice_time':开票日 、 'payment_date':到款日"`
+	SortType     string `json:"sort_type" form:"sort_type" description:"如何排序,是正序还是倒序,枚举值:asc 正序,desc 倒叙"`
 	TimeType    int    `json:"time_type" form:"time_type" description:"时间类型: 1-开票时间; 2-到款时间;3-开票时间&到款时间"`
 	base.PageReq
 }
@@ -336,6 +343,7 @@ type InvoicePaymentCensusInfo struct {
 	PaymentAmount     float64                             `json:"payment_amount" description:"到款金额"`
 	PayType           int                                 `json:"pay_type" description:"付款方式:0-无;1-年付;2-半年付;3-季付;4-次付;5-异常"`
 	ServiceAmountList []*ContractPaymentServiceAmountItem `json:"service_amount_list" description:"到款套餐金额分配信息"`
+	SellerType        int                                 `json:"seller_type" description:"销售类型:1ficc销售,2权益销售"`
 }
 
 // ContractInvoiceAmountTotal 开票到款金额合计信息
@@ -363,11 +371,12 @@ type UpdatePaymentPayTypeReq struct {
 
 // CensusSellerGroupInvoiceListReq 销售组开票统计列表请求体
 type CensusSellerGroupInvoiceListReq struct {
-	StartDate string `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"开始日期"`
-	EndDate   string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"结束日期"`
-	SortField int    `json:"sort_field" form:"sort_field" description:"排序字段: 1-开票金额; 2-组别占比"`
-	SortType  int    `json:"sort_type" form:"sort_type" description:"排序方式: 1-正序; 2-倒序"`
-	IsExport  int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
+	StartDate  string `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"开始日期"`
+	EndDate    string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"结束日期"`
+	SortField  int    `json:"sort_field" form:"sort_field" description:"排序字段: 1-开票金额; 2-组别占比"`
+	SortType   int    `json:"sort_type" form:"sort_type" description:"排序方式: 1-正序; 2-倒序"`
+	IsExport   int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
+	SellerType int    `json:"seller_type" form:"seller_type" description:"销售类型:1ficc销售,2权益销售"`
 	base.PageReq
 }
 
@@ -407,12 +416,13 @@ func GetCensusSellerGroupInvoicePageList(page base.IPage, condition, outCond str
 
 // CensusSellerInvoiceListReq 销售开票统计列表请求体
 type CensusSellerInvoiceListReq struct {
-	GroupId   int    `json:"group_id" form:"group_id" description:"销售组别ID"`
-	StartDate string `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"开始日期"`
-	EndDate   string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"结束日期"`
-	SortField int    `json:"sort_field" form:"sort_field" description:"排序字段: 1-开票金额; 2-小组占比; 3-全员占比"`
-	SortType  int    `json:"sort_type" form:"sort_type" description:"排序方式: 1-正序; 2-倒序"`
-	IsExport  int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
+	GroupId    int    `json:"group_id" form:"group_id" description:"销售组别ID"`
+	StartDate  string `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"开始日期"`
+	EndDate    string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"结束日期"`
+	SortField  int    `json:"sort_field" form:"sort_field" description:"排序字段: 1-开票金额; 2-小组占比; 3-全员占比"`
+	SortType   int    `json:"sort_type" form:"sort_type" description:"排序方式: 1-正序; 2-倒序"`
+	IsExport   int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
+	SellerType int    `json:"seller_type" form:"seller_type" description:"销售类型:1ficc销售,2权益销售"`
 	base.PageReq
 }
 

+ 18 - 0
models/fms/contract_payment_service_amount.go

@@ -11,8 +11,10 @@ type ContractPaymentServiceAmount struct {
 	ContractRegisterId             int     `gorm:"column:contract_register_id" json:"contract_register_id" description:"合同登记ID"`
 	ContractPaymentId              int     `gorm:"column:contract_payment_id" json:"contract_payment_id" description:"到款登记ID"`
 	ServiceTemplateId              int     `gorm:"column:service_template_id" json:"service_template_id" description:"套餐ID"`
+	ServiceTemplatePid             int     `gorm:"column:service_template_pid" json:"service_template_pid" description:"套餐父级ID"`
 	Amount                         float64 `gorm:"column:amount" json:"amount" description:"分配金额"`
 	IsDeleted                      int     `gorm:"column:is_deleted" json:"is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
+	InitType                       int     `gorm:"column:init_type" json:"init_type" description:"初始分配类型:0人为分配,1自动分配"`
 	base.TimeBase
 }
 
@@ -49,6 +51,7 @@ type ContractPaymentServiceAmountItem struct {
 	ContractPaymentServiceAmountId int     `json:"contract_payment_service_amount_id"`
 	ContractPaymentId              int     `json:"contract_payment_id" description:"到款登记ID"`
 	ServiceTemplateId              int     `json:"service_template_id" description:"套餐ID"`
+	ServiceTemplatePid             int     `json:"service_template_pid" description:"套餐父级ID"`
 	ServiceTemplateName            string  `json:"service_template_name"`
 	Amount                         float64 `json:"amount" description:"分配金额"`
 }
@@ -60,10 +63,17 @@ type DistributePaymentServiceAmountReq struct {
 	List               []*DistributePaymentServiceAmountItem `json:"list"`
 }
 
+// GetPaymentServiceAmountReq 到款登记-查询分配套餐金额请求体
+type GetPaymentServiceAmountReq struct {
+	ContractRegisterId int `json:"contract_register_id" binding:"required,gte=1" description:"合同登记ID"`
+	ContractPaymentId  int `json:"contract_payment_id" binding:"required,gte=1" description:"到款登记ID"`
+}
+
 // DistributePaymentServiceAmountItem 到款登记-分配套餐金额列表信息
 type DistributePaymentServiceAmountItem struct {
 	ContractPaymentServiceAmountId int     `json:"contract_payment_service_amount_id"`
 	ServiceTemplateId              int     `json:"service_template_id" description:"套餐ID"`
+	ServiceTemplatePid             int     `json:"service_template_pid" description:"套餐父级ID"`
 	Amount                         float64 `json:"amount" description:"分配金额"`
 }
 
@@ -88,3 +98,11 @@ func CreatePaymentServiceAmount(registerId, payId int, addList []*ContractPaymen
 	}
 	return
 }
+
+func DeletePaymentServiceAmountByRegisterId(registerId int) (err error) {
+	// 删除原自动分配信息
+	err = global.DEFAULT_MYSQL.
+		Where("contract_register_id = ? and init_type=1", registerId).
+		Delete(ContractPaymentServiceAmount{}).Error
+	return
+}

+ 105 - 38
models/fms/contract_register.go

@@ -16,9 +16,11 @@ type ContractRegister struct {
 	ContractSource     int       `gorm:"column:contract_source" json:"contract_source" description:"合同来源: 0-非系统合同导入; 1-CRM合同导入"`
 	CompanyName        string    `gorm:"column:company_name" json:"company_name" description:"客户名称"`
 	ActualCompanyName  string    `gorm:"column:actual_company_name" json:"actual_company_name" description:"实际使用方"`
-	ProductId          int       `gorm:"column:product_id" json:"product_id" description:"产品ID: 1-FICC; 2-权益"`
+	ProductIds         string    `gorm:"column:product_ids" json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
 	SellerId           int       `gorm:"column:seller_id" json:"seller_id" description:"CRM系统-销售ID"`
 	SellerName         string    `gorm:"column:seller_name" json:"seller_name" description:"CRM系统-销售名称"`
+	RaiSellerId        int       `gorm:"column:rai_seller_id" json:"rai_seller_id"  description:"CRM系统-权益销售ID"`
+	RaiSellerName      string    `gorm:"column:rai_seller_name" json:"rai_seller_name" description:"CRM系统-权益销售名称"`
 	ContractType       int       `gorm:"column:contract_type" json:"contract_type" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
 	ContractAmount     float64   `gorm:"column:contract_amount" json:"contract_amount" description:"合同金额"`
 	InvoicedAmount     float64   `gorm:"column:invoiced_amount" json:"invoiced_amount" description:"开票金额"`
@@ -98,7 +100,7 @@ type ContractRegisterListReq struct {
 	Keyword        string `json:"keyword" form:"keyword" binding:"omitempty" description:"关键词"`
 	StartDate      string `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"合同开始日期"`
 	EndDate        string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"合同结束日期"`
-	ServiceType    int    `json:"service_type" form:"service_type" description:"套餐类型"`
+	ServiceTypes   string `json:"service_types" form:"service_types" description:"套餐类型"`
 	ContractType   int    `json:"contract_type" form:"contract_type" description:"合同类型"`
 	RegisterStatus int    `json:"register_status" form:"register_status" description:"登记状态"`
 	base.PageReq
@@ -113,8 +115,11 @@ type ContractRegisterItem struct {
 	ContractSource     int     `json:"contract_source" description:"合同来源: 0-非系统合同导入; 1-CRM合同导入"`
 	CompanyName        string  `json:"company_name" description:"客户名称"`
 	ActualCompanyName  string  `json:"actual_company_name" description:"实际使用方"`
+	ProductIds         string  `json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
 	SellerId           int     `json:"seller_id" description:"CRM系统-销售ID"`
 	SellerName         string  `json:"seller_name" description:"CRM系统-销售名称"`
+	RaiSellerId        int     `json:"rai_seller_id"  description:"CRM系统-权益销售ID"`
+	RaiSellerName      string  `json:"rai_seller_name" description:"CRM系统-权益销售名称"`
 	ContractType       int     `json:"contract_type" description:"合同类型: 1-新签; 2-续约"`
 	ContractAmount     float64 `json:"contract_amount" description:"合同金额"`
 	InvoicedAmount     float64 `json:"invoiced_amount" description:"开票金额"`
@@ -132,6 +137,7 @@ type ContractRegisterItem struct {
 	HasPayment         int     `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
 	NewCompany         int     `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
 	CreateTime         string  `json:"create_time" description:"登记时间"`
+	SellerIds          string  `json:"seller_ids"`
 }
 
 // ContractRegisterList 合同登记列表
@@ -155,30 +161,30 @@ type ContractRegisterUpdateStatusReq struct {
 
 // ContractRegisterAddReq 新增合同登记请求体
 type ContractRegisterAddReq struct {
-	ContractCode       string                  `json:"contract_code" binding:"required" description:"合同编号"`
-	RelateContractCode string                  `json:"relate_contract_code" description:"关联合同编号"`
-	CrmContractId      int                     `json:"crm_contract_id" description:"CRM系统-合同ID"`
-	ContractSource     int                     `json:"contract_source" binding:"oneof=0 1" description:"合同来源: 0-非系统合同导入; 1-CRM合同导入"`
-	CompanyName        string                  `json:"company_name" binding:"required" description:"客户名称"`
-	ActualCompanyName  string                  `json:"actual_company_name" description:"实际使用方"`
-	SellerId           int                     `json:"seller_id" binding:"required" description:"CRM系统-销售ID"`
-	SellerName         string                  `json:"seller_name" binding:"required" description:"CRM系统-销售名称"`
-	ContractType       int                     `json:"contract_type" binding:"oneof=1 2 3 4" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
-	ContractAmount     float64                 `json:"contract_amount" binding:"required" description:"合同金额"`
-	CurrencyUnit       string                  `json:"currency_unit" binding:"required" description:"货币单位"`
-	StartDate          string                  `json:"start_date" binding:"required" description:"合同开始日期"`
-	EndDate            string                  `json:"end_date" binding:"required" description:"合同结束日期"`
-	SignDate           string                  `json:"sign_date" description:"合同签订日期"`
-	AgreedPayTime      string                  `json:"agreed_pay_time" description:"约定付款时间(如:生效日起10日内)"`
-	ContractStatus     int                     `json:"contract_status" binding:"oneof=1 2 3 4 5" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回; 4-已终止; 5-邮件备案"`
-	Remark             string                  `json:"remark" description:"备注信息"`
-	ProductId          int                     `json:"product_id" binding:"oneof=1 2" description:"产品ID"`
-	ServiceRemark      string                  `json:"service_remark" description:"套餐备注"`
-	HasPayment         int                     `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
-	NewCompany         int                     `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
-	Supplement         int                     `json:"supplement" description:"是否为补录合同: 0-否; 1-是"`
-	PrePayId           int                     `json:"pre_pay_id" description:"预到款信息ID"`
-	Services           []ContractServiceAddReq `json:"services" description:"服务套餐内容"`
+	ContractCode       string                        `json:"contract_code" binding:"required" description:"合同编号"`
+	RelateContractCode string                        `json:"relate_contract_code" description:"关联合同编号"`
+	CrmContractId      int                           `json:"crm_contract_id" description:"CRM系统-合同ID"`
+	ContractSource     int                           `json:"contract_source" binding:"oneof=0 1" description:"合同来源: 0-非系统合同导入; 1-CRM合同导入"`
+	CompanyName        string                        `json:"company_name" binding:"required" description:"客户名称"`
+	ActualCompanyName  string                        `json:"actual_company_name" description:"实际使用方"`
+	SellerIds          string                        `json:"seller_ids" binding:"required" description:"CRM系统-销售ID"`
+	ContractType       int                           `json:"contract_type" binding:"oneof=1 2 3 4" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
+	ContractAmount     float64                       `json:"contract_amount" binding:"required" description:"合同金额"`
+	CurrencyUnit       string                        `json:"currency_unit" binding:"required" description:"货币单位"`
+	StartDate          string                        `json:"start_date" binding:"required" description:"合同开始日期"`
+	EndDate            string                        `json:"end_date" binding:"required" description:"合同结束日期"`
+	SignDate           string                        `json:"sign_date" description:"合同签订日期"`
+	AgreedPayTime      string                        `json:"agreed_pay_time" description:"约定付款时间(如:生效日起10日内)"`
+	ContractStatus     int                           `json:"contract_status" binding:"oneof=1 2 3 4 5" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回; 4-已终止; 5-邮件备案"`
+	Remark             string                        `json:"remark" description:"备注信息"`
+	ProductIds         string                        `json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
+	ServiceRemark      string                        `json:"service_remark" description:"套餐备注"`
+	HasPayment         int                           `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
+	NewCompany         int                           `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
+	Supplement         int                           `json:"supplement" description:"是否为补录合同: 0-否; 1-是"`
+	PrePayId           int                           `json:"pre_pay_id" description:"预到款信息ID"`
+	Services           []ContractServiceAddReq       `json:"services" description:"服务套餐内容"`
+	ServiceAmount      []ContractServiceAmountAddReq `json:"service_amount" description:"服务套餐金额"`
 }
 
 // ContractRegisterEditReq 编辑合同登记请求体
@@ -188,7 +194,7 @@ type ContractRegisterEditReq struct {
 }
 
 // CreateContractRegisterAndServices 新增合同登记及套餐
-func CreateContractRegisterAndServices(item *ContractRegister, serviceDetail []*ContractServiceAndDetail) (err error) {
+func CreateContractRegisterAndServices(item *ContractRegister, serviceDetail []*ContractServiceAndDetail, serviceAmount []*ContractServiceAmount) (err error) {
 	tx := global.DEFAULT_MYSQL.Begin()
 	defer func() {
 		if err != nil {
@@ -207,7 +213,7 @@ func CreateContractRegisterAndServices(item *ContractRegister, serviceDetail []*
 		t := serviceDetail[i]
 		contractService := &ContractService{
 			ContractRegisterId: item.ContractRegisterId,
-			ProductId:          item.ProductId,
+			ProductId:          t.ProductId,
 			ServiceTemplateId:  t.ServiceTemplateId,
 			Title:              t.Title,
 			Value:              t.Value,
@@ -230,12 +236,24 @@ func CreateContractRegisterAndServices(item *ContractRegister, serviceDetail []*
 		//	t.Detail[j] = contractServiceDetail
 		//}
 	}
+
+	for i := 0; i < len(serviceAmount); i++ {
+		// 合同服务
+		t := serviceAmount[i]
+		tmp := &ContractServiceAmount{
+			ContractRegisterId: item.ContractRegisterId,
+			ProductId:          t.ProductId,
+			ServiceAmount:      t.ServiceAmount,
+			CurrencyUnit:       t.CurrencyUnit,
+		}
+		tx.Create(tmp)
+	}
 	return
 }
 
 // UpdateContractRegister 更新合同登记
 func UpdateContractRegister(item *ContractRegister, updateCols []string, serviceDetail []*ContractServiceAndDetail,
-	invoiceList []*ContractInvoice, invoiceUpdateCols []string, invoiceHandleType int) (err error) {
+	invoiceList []*ContractInvoice, invoiceUpdateCols []string, invoiceHandleType int, serviceAmount []*ContractServiceAmount) (err error) {
 	tx := global.DEFAULT_MYSQL.Begin()
 	defer func() {
 		if err != nil {
@@ -256,6 +274,9 @@ func UpdateContractRegister(item *ContractRegister, updateCols []string, service
 	tx.Exec(sql, item.ContractRegisterId)
 	sql = `DELETE FROM contract_service_detail WHERE contract_register_id = ?`
 	tx.Exec(sql, item.ContractRegisterId)
+	sql = `DELETE FROM contract_service_amount WHERE contract_register_id = ?`
+	tx.Exec(sql, item.ContractRegisterId)
+
 
 	// 新增合同服务
 	//nowTime := time.Now().Local()
@@ -264,7 +285,7 @@ func UpdateContractRegister(item *ContractRegister, updateCols []string, service
 		t := serviceDetail[i]
 		contractService := &ContractService{
 			ContractRegisterId: item.ContractRegisterId,
-			ProductId:          item.ProductId,
+			ProductId:          t.ProductId,
 			ServiceTemplateId:  t.ServiceTemplateId,
 			Title:              t.Title,
 			Value:              t.Value,
@@ -288,6 +309,18 @@ func UpdateContractRegister(item *ContractRegister, updateCols []string, service
 		//}
 	}
 
+	for i := 0; i < len(serviceAmount); i++ {
+		// 合同服务
+		t := serviceAmount[i]
+		tmp := &ContractServiceAmount{
+			ContractRegisterId: item.ContractRegisterId,
+			ProductId:          t.ProductId,
+			ServiceAmount:      t.ServiceAmount,
+			CurrencyUnit:       t.CurrencyUnit,
+		}
+		tx.Create(tmp)
+	}
+
 	// 开票到款操作类型: 0-无; 1-更新; 2-删除;
 	if invoiceHandleType == 2 {
 		sql = `UPDATE contract_invoice SET is_deleted = 1 WHERE contract_register_id = ?`
@@ -315,10 +348,11 @@ type ContractRegisterDetailReq struct {
 // ContractRegisterDetail-合同登记详情
 type ContractRegisterDetail struct {
 	*ContractRegisterItem
-	ServiceList []*ContractServiceAndDetail `json:"service_list" description:"合同服务及详情"`
-	InvoiceList []*ContractInvoiceItem      `json:"invoice_list" description:"开票信息"`
-	PaymentList []*ContractInvoiceItem      `json:"payment_list" description:"到款信息"`
-	Logs        []*ContractRegisterLogItem  `json:"logs" description:"登记日志"`
+	ServiceList       []*ContractServiceAndDetail `json:"service_list" description:"合同服务及详情"`
+	InvoiceList       []*ContractInvoiceItem      `json:"invoice_list" description:"开票信息"`
+	PaymentList       []*ContractInvoiceItem      `json:"payment_list" description:"到款信息"`
+	Logs              []*ContractRegisterLogItem  `json:"logs" description:"登记日志"`
+	ServiceAmountList []*ContractServiceAmountItem    `json:"service_amount_list" description:"合同套餐金额"`
 }
 
 // GetContractRegisterItemById 获取合同登记信息
@@ -364,8 +398,11 @@ func formatContractRegister2Item(item *ContractRegister) (formatItem *ContractRe
 	formatItem.ContractSource = item.ContractSource
 	formatItem.CompanyName = item.CompanyName
 	formatItem.ActualCompanyName = item.ActualCompanyName
+	formatItem.ProductIds = item.ProductIds
 	formatItem.SellerId = item.SellerId
 	formatItem.SellerName = item.SellerName
+	formatItem.RaiSellerId = item.RaiSellerId
+	formatItem.RaiSellerName = item.RaiSellerName
 	formatItem.ContractType = item.ContractType
 	formatItem.ContractAmount = item.ContractAmount
 	formatItem.InvoicedAmount = item.InvoicedAmount
@@ -387,7 +424,7 @@ func formatContractRegister2Item(item *ContractRegister) (formatItem *ContractRe
 }
 
 // CreateImportContractRegister 新增导入的合同登记及套餐、开票到款信息
-func CreateImportContractRegister(item *ContractRegister, serviceList []*ContractService, invoiceList []*ContractInvoice) (newId int, err error) {
+func CreateImportContractRegister(item *ContractRegister, serviceList []*ContractService, invoiceList []*ContractInvoice, serviceAmountList []*ContractServiceAmount) (newId int, err error) {
 	tx := global.DEFAULT_MYSQL.Begin()
 	defer func() {
 		if err != nil {
@@ -406,10 +443,29 @@ func CreateImportContractRegister(item *ContractRegister, serviceList []*Contrac
 
 	// 新增套餐
 	if len(serviceList) > 0 {
+		// 过滤重复的数组
+		serviceMap := make(map[int]struct{})
+		addServiceList := make([]*ContractService, 0)
 		for i := range serviceList {
-			serviceList[i].ContractRegisterId = newId
+			if _, ok := serviceMap[serviceList[i].ServiceTemplateId]; !ok {
+				serviceList[i].ContractRegisterId = newId
+				addServiceList = append(addServiceList, serviceList[i])
+				serviceMap[serviceList[i].ServiceTemplateId] = struct{}{}
+			}
+
+		}
+		if e := tx.CreateInBatches(addServiceList, len(addServiceList)).Error; e != nil {
+			err = e
+			return
+		}
+	}
+
+	// 新增合同套餐金额相关信息
+	if len(serviceAmountList) > 0 {
+		for i := range serviceAmountList {
+			serviceAmountList[i].ContractRegisterId = newId
 		}
-		if e := tx.CreateInBatches(serviceList, len(serviceList)).Error; e != nil {
+		if e := tx.CreateInBatches(serviceAmountList, len(serviceAmountList)).Error; e != nil {
 			err = e
 			return
 		}
@@ -456,7 +512,7 @@ func CreateContractRegisterAndServicesAndPayMent(item *ContractRegister, service
 		t := serviceDetail[i]
 		contractService := &ContractService{
 			ContractRegisterId: item.ContractRegisterId,
-			ProductId:          item.ProductId,
+			ProductId:          t.ProductId,
 			ServiceTemplateId:  t.ServiceTemplateId,
 			Title:              t.Title,
 			Value:              t.Value,
@@ -482,3 +538,14 @@ func CreateContractRegisterAndServicesAndPayMent(item *ContractRegister, service
 
 	return
 }
+
+type  CheckContractNameReq struct {
+	CompanyName string `json:"company_name" form:"company_name" description:"客户名称"`
+	StartDate   string `json:"start_date" form:"start_date" description:"合同开始日期"`
+	EndDate     string `json:"end_date" form:"end_date" description:"合同结束日期"`
+}
+
+
+type  CheckContractNameResp struct {
+	Exist int 	`json:"exist" description:"是否存在相似的合同:0不存在,1存在"`
+}

+ 39 - 13
models/fms/contract_service.go

@@ -7,19 +7,25 @@ import (
 
 // ContractService 合同服务套餐
 type ContractService struct {
-	ContractServiceId  int    `gorm:"primaryKey;column:contract_service_id" json:"contract_service_id"`
-	ContractRegisterId int    `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
-	ProductId          int    `gorm:"column:product_id" json:"product_id" description:"产品ID"`
-	ServiceTemplateId  int    `gorm:"column:service_template_id" json:"service_template_id" description:"合同服务模板ID"`
-	Title              string `gorm:"column:title" json:"title" description:"套餐名称"`
-	Value              string `gorm:"column:value" json:"value" description:"套餐的值"`
-	TableValue         string `gorm:"column:table_value" json:"table_value" description:"表格数据,用于word生成时的json数据"`
-	HasDetail          string `gorm:"column:has_detail" json:"has_detail" description:"是否有详情: 无; 有"`
-	ChartPermissionId  int    `gorm:"column:chart_permission_id" json:"chart_permission_id" description:"权限ID"`
-	ChartPermissionIds string `gorm:"column:chart_permission_ids" json:"chart_permission_ids" description:"权限IDs-小套餐"`
+	ContractServiceId  int     `gorm:"primaryKey;column:contract_service_id" json:"contract_service_id"`
+	ContractRegisterId int     `gorm:"column:contract_register_id" json:"contract_register_id" description:"登记ID"`
+	ProductId          int     `gorm:"column:product_id" json:"product_id" description:"产品ID"`
+	ServiceTemplateId  int     `gorm:"column:service_template_id" json:"service_template_id" description:"合同服务模板ID"`
+	Title              string  `gorm:"column:title" json:"title" description:"套餐名称"`
+	Value              string  `gorm:"column:value" json:"value" description:"套餐的值"`
+	TableValue         string  `gorm:"column:table_value" json:"table_value" description:"表格数据,用于word生成时的json数据"`
+	HasDetail          string  `gorm:"column:has_detail" json:"has_detail" description:"是否有详情: 无; 有"`
+	ChartPermissionId  int     `gorm:"column:chart_permission_id" json:"chart_permission_id" description:"权限ID"`
+	ChartPermissionIds string  `gorm:"column:chart_permission_ids" json:"chart_permission_ids" description:"权限IDs-小套餐"`
 	base.TimeBase
 }
 
+type ContractServiceWithParentTitle struct {
+	ContractService
+	Pid         int
+	ParentTitle string
+}
+
 func (c *ContractService) TableName() string {
 	return "contract_service"
 }
@@ -32,6 +38,17 @@ func (c *ContractService) List(condition string, pars []interface{}) (list []*Co
 	return
 }
 
+func (c *ContractService) ListWithWithParentTitle(condition string, pars []interface{}) (list []*ContractServiceWithParentTitle, err error) {
+	list = make([]*ContractServiceWithParentTitle, 0)
+	err = global.DEFAULT_MYSQL.Table("contract_service as cv").
+		Select("cv.*, t1.pid, t2.title as parent_title").
+		Joins(" left join contract_service_template as t1 on cv.service_template_id = t1.service_template_id").
+		Joins(" left join contract_service_template as t2 on t1.pid = t2.service_template_id").
+		Where(condition, pars...).
+		Find(&list).Error
+	return
+}
+
 // ContractServiceAddReq 新增合同套餐请求体
 type ContractServiceAddReq struct {
 	ServiceTemplateId  int    `json:"service_template_id" description:"服务套餐id"`
@@ -104,10 +121,10 @@ func formatContractServiceAndDetailList(list []*ContractServiceItem) (itemList [
 }
 
 // GetContractRegisterIdsByTempId 套餐模板ID获取关联的合同登记ID
-func GetContractRegisterIdsByTempId(tempId int) (registerIds []int, err error) {
+func GetContractRegisterIdsByTempId(tempIds []string) (registerIds []int, err error) {
 	err = global.DEFAULT_MYSQL.Model(ContractService{}).
 		Select("DISTINCT contract_register_id").
-		Where("service_template_id = ?", tempId).
+		Where("service_template_id in (?)", tempIds).
 		Find(&registerIds).Error
 	return
 }
@@ -123,8 +140,17 @@ func GetContractRegisterServicesNameByRegisterIds(registerIds []int) (list []*Co
 	list = make([]*ContractRegisterServicesName, 0)
 	err = global.DEFAULT_MYSQL.Model(ContractService{}).
 		Select("contract_register_id, GROUP_CONCAT(title) AS services_name").
-		Where("contract_register_id IN ?", registerIds).
+		Where("contract_register_id IN ? ", registerIds).
 		Group("contract_register_id").
 		Find(&list).Error
 	return
 }
+
+// GetContractRegisterServicesByRegisterIds 合同登记IDs获取套餐拼接字符串
+func GetContractRegisterServicesByRegisterIds(registerIds []int) (list []*ContractService, err error) {
+	err = global.DEFAULT_MYSQL.Model(ContractService{}).
+		Select("*").
+		Where("contract_register_id IN ?", registerIds).
+		Find(&list).Error
+	return
+}

+ 60 - 0
models/fms/contract_service_amount.go

@@ -0,0 +1,60 @@
+package fms
+
+import (
+	"hongze/fms_api/global"
+	"hongze/fms_api/models/base"
+)
+
+// 合同套餐金额表
+type ContractServiceAmount struct {
+	Id                 int     `gorm:"primaryKey;column:id" json:"id"`
+	ContractRegisterId int     `gorm:"column:contract_register_id" json:"contract_register_id"` //登记ID
+	ProductId          int     `gorm:"column:product_id" json:"product_id"`                     //产品ID
+	ServiceAmount      float64 `gorm:"column:service_amount" json:"service_amount"`             //套餐总金额
+	CurrencyUnit       string  `gorm:"column:currency_unit" json:"currency_unit"`               //货币国际代码
+	base.TimeBase
+}
+
+// ContractServiceAmountAddReq 新增合同套餐金额请求体
+type ContractServiceAmountAddReq struct {
+	ProductId     int     `json:"product_id"`     //产品ID
+	ServiceAmount float64 `json:"service_amount"` //套餐总金额
+}
+
+func (c *ContractServiceAmount) TableName() string {
+	return "contract_service_amount"
+}
+
+func (c *ContractServiceAmount) Create() (err error) {
+	err = global.DEFAULT_MYSQL.Create(c).Error
+	return
+}
+
+func (c *ContractServiceAmount) AddInBatches(list []*ContractServiceAmount) (err error) {
+	err = global.DEFAULT_MYSQL.CreateInBatches(list, len(list)).Error
+	return
+}
+
+type ContractServiceAmountItem struct {
+	ContractRegisterId int     `gorm:"column:contract_register_id" json:"contract_register_id"` //登记ID
+	ProductId          int     `gorm:"column:product_id" json:"product_id"`                     //产品ID
+	ServiceAmount      float64 `gorm:"column:service_amount" json:"service_amount"`             //套餐总金额
+	CurrencyUnit       string  `gorm:"column:currency_unit" json:"currency_unit"`               //货币国际代码
+}
+// GetContractServiceAmountByContractRegisterIds 根据登记id获取套餐金额列表数据
+func GetContractServiceAmountByContractRegisterIds(contractRegisterIds []int) (list []*ContractServiceAmount, err error) {
+	err = global.DEFAULT_MYSQL.Model(ContractServiceAmount{}).
+		Where("contract_register_id in (?)", contractRegisterIds).
+		Find(&list).Error
+	return
+}
+
+
+// GetContractServiceAmountByRegisterId 根据id获取合同套餐金额数据
+func GetContractServiceAmountByRegisterId(contractRegisterId int) (list []*ContractServiceAmount, err error) {
+	err = global.DEFAULT_MYSQL.Model(ContractServiceAmount{}).
+		Where("contract_register_id = ?", contractRegisterId).
+		Find(&list).Error
+	return
+}
+

+ 70 - 2
models/fms/contract_service_template.go

@@ -8,7 +8,7 @@ import (
 // ContractServiceTemplate 合同服务模板表
 type ContractServiceTemplate struct {
 	ServiceTemplateId int       `gorm:"primaryKey;column:service_template_id" json:"service_template_id"`
-	ProductId         string    `gorm:"column:product_id" json:"product_id" description:"产品id"`
+	ProductId         int       `gorm:"column:product_id" json:"product_id" description:"产品id"`
 	Pid               int       `gorm:"column:pid" json:"pid" description:"父级id"`
 	Title             string    `gorm:"column:title" json:"title" description:"套餐名称"`
 	Value             string    `gorm:"column:value" json:"value" description:"对应的数据"`
@@ -39,6 +39,7 @@ type ContractServiceTemplateItem struct {
 	ServiceTemplateId int    `json:"service_template_id" description:"套餐模板ID"`
 	ProductId         int    `json:"product_id" description:"产品ID"`
 	Pid               int    `json:"pid" description:"父级ID"`
+	ParentTitle       string `json:"parent_title" description:"父级套餐名称"`
 	Title             string `json:"title" description:"套餐名称"`
 	Value             string `json:"value" description:"对应的数据"`
 	SelectType        string `json:"select_type" description:"选择器类型:radio-单选; checkbox-多选"`
@@ -46,6 +47,11 @@ type ContractServiceTemplateItem struct {
 	ChartPermissionId int    `json:"chart_permission_id" description:"权限ID"`
 }
 
+type ContractServiceTemplateList struct {
+	Title string `json:"title"`
+	Children []*ContractServiceTemplateMapItems `json:"children"`
+}
+
 type ContractServiceTemplateMapItems struct {
 	ContractServiceTemplateItem
 	Children []*ContractServiceTemplateMapItems `json:"children"`
@@ -67,7 +73,7 @@ type ContractServiceTemplateMapItems2 struct {
 
 // ContractServiceListReq CRM系统合同套餐-列表请求体
 type ContractServiceListReq struct {
-	ProductId int `json:"product_id" form:"product_id" description:"产品: 1-FICC; 2-权益"`
+	ProductId string `json:"product_id" form:"product_id" description:"产品:空值-全部; 1-FICC; 2-权益"`
 }
 
 func GetContractServiceTemplateMapByProductId(productId int) (items []*ContractServiceTemplateItem, err error) {
@@ -79,6 +85,15 @@ func GetContractServiceTemplateMapByProductId(productId int) (items []*ContractS
 	return
 }
 
+func GetContractServiceTemplateAllByProductId(productId int) (items []*ContractServiceTemplateItem, err error) {
+	items = make([]*ContractServiceTemplateItem, 0)
+	err = global.DEFAULT_MYSQL.Table("contract_service_template").
+		Where("product_id = ? AND is_delete = 0", productId).
+		Order("service_template_id ASC").
+		Find(&items).Error
+	return
+}
+
 func GetContractServiceTemplateMapByParentId(parentId int) (items []*ContractServiceTemplateItem, err error) {
 	items = make([]*ContractServiceTemplateItem, 0)
 	err = global.DEFAULT_MYSQL.Table("contract_service_template").
@@ -94,3 +109,56 @@ func GetContractServiceTemplateById(templateId int) (item *ContractServiceTempla
 		First(&item).Error
 	return
 }
+
+func GetContractServiceTemplateSecond() (items []*ContractServiceTemplateItem, err error) {
+	items = make([]*ContractServiceTemplateItem, 0)
+	err = global.DEFAULT_MYSQL.Table("contract_service_template").
+		Where("pid = 0 AND is_delete = 0").
+		Order("service_template_id ASC").
+		Find(&items).Error
+	return
+}
+
+type ContractServiceTemplateFullName struct {
+	ContractServiceTemplateItem
+	ParentTitle string
+}
+
+
+type ContractServiceTemplateFormat struct {
+	FormatTitle        string
+	ServiceTemplateId  int
+	ServiceTemplatePid int
+}
+
+type ContractServiceTemplateFormatList []ContractServiceTemplateFormat
+
+func (c ContractServiceTemplateFormatList) Len() int {
+	return len(c)
+}
+
+func (c ContractServiceTemplateFormatList) Less(i, j int) bool {
+	return c[i].ServiceTemplateId < c[j].ServiceTemplateId
+}
+
+func (c ContractServiceTemplateFormatList) Swap(i, j int) {
+	c[i], c[j] = c[j], c[i]
+}
+
+func GetContractServiceTemplateFullName() (items []*ContractServiceTemplateFullName, err error) {
+	err = global.DEFAULT_MYSQL.Table("contract_service_template as t1").
+		Select("t1.*, t2.title as parent_title").
+		Joins(" left join contract_service_template as t2 on t1.pid = t2.service_template_id").
+		Where("t1.is_delete = 0").
+		Order("t1.service_template_id ASC").
+		Find(&items).Error
+	return
+}
+
+// GetContractServiceTemplateByTitle 用名称获取合同套餐模板
+func GetContractServiceTemplateByTitle(titles string) (items []*ContractServiceTemplate, err error) {
+	err = global.DEFAULT_MYSQL.Model(ContractServiceTemplate{}).
+		Where("title IN (?)", titles).
+		Scan(&items).Error
+	return
+}

+ 24 - 22
models/fms/invoice_payment_summary.go

@@ -10,10 +10,11 @@ import (
 
 // InvoicePaymentSummary 开票到款汇总表
 type InvoicePaymentSummary struct {
-	Id         int `gorm:"primaryKey;column:id" json:"id" description:"汇总ID"`
-	RegisterId int `gorm:"column:register_id" json:"register_id" description:"登记ID"`
-	InvoiceId  int `gorm:"column:invoice_id" json:"invoice_id" description:"开票ID"`
-	PaymentId  int `gorm:"column:payment_id" json:"payment_id" description:"到款ID"`
+	Id               int `gorm:"primaryKey;column:id" json:"id" description:"汇总ID"`
+	RegisterId       int `gorm:"column:register_id" json:"register_id" description:"登记ID"`
+	InvoiceId        int `gorm:"column:invoice_id" json:"invoice_id" description:"开票ID"`
+	PaymentId        int `gorm:"column:payment_id" json:"payment_id" description:"到款ID"`
+	ServiceProductId int `gorm:"column:service_product_id" json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
 	base.TimeBase
 }
 
@@ -71,28 +72,29 @@ func GetInvoicePaymentCensusPageList(page base.IPage, condition string, pars []i
 }
 
 type InvoicePaymentSummaryItem struct {
-	SummaryId       int       `json:"summary_id" description:"汇总ID"`
-	RegisterId      int       `json:"register_id" description:"登记ID"`
-	CompanyName     string    `json:"company_name" description:"客户名称"`
-	NewCompany      int       `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
-	StartDate       time.Time `json:"start_date" description:"合同开始日期"`
-	EndDate         time.Time `json:"end_date" description:"合同结束日期"`
-	InvoiceId       int       `json:"invoice_id" description:"开票ID"`
-	InvoiceDate     time.Time `json:"invoice_time" description:"开票日期"`
-	InvoiceAmount   float64   `json:"invoice_amount" description:"开票金额"`
-	SellerId        int       `json:"seller_id" description:"销售ID"`
-	SellerName      string    `json:"seller_name" description:"销售名称"`
-	SellerGroupId   int       `json:"seller_group_id" description:"销售组别ID"`
-	SellerGroupName string    `json:"seller_group_name" description:"销售组别名称"`
-	PaymentId       int       `json:"payment_id" description:"到款ID"`
-	PaymentDate     time.Time `json:"payment_date" description:"到款日期"`
-	PaymentAmount   float64   `json:"payment_amount" description:"到款金额"`
-	PayType         int       `json:"pay_type" description:"付款方式:0-无;1-年付;2-半年付;3-季付;4-次付;5-异常"`
+	SummaryId        int       `json:"summary_id" description:"汇总ID"`
+	RegisterId       int       `json:"register_id" description:"登记ID"`
+	CompanyName      string    `json:"company_name" description:"客户名称"`
+	NewCompany       int       `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
+	StartDate        time.Time `json:"start_date" description:"合同开始日期"`
+	EndDate          time.Time `json:"end_date" description:"合同结束日期"`
+	InvoiceId        int       `json:"invoice_id" description:"开票ID"`
+	InvoiceDate      time.Time `json:"invoice_time" description:"开票日期"`
+	InvoiceAmount    float64   `json:"invoice_amount" description:"开票金额"`
+	SellerId         int       `json:"seller_id" description:"销售ID"`
+	SellerName       string    `json:"seller_name" description:"销售名称"`
+	SellerGroupId    int       `json:"seller_group_id" description:"销售组别ID"`
+	SellerGroupName  string    `json:"seller_group_name" description:"销售组别名称"`
+	PaymentId        int       `json:"payment_id" description:"到款ID"`
+	PaymentDate      time.Time `json:"payment_date" description:"到款日期"`
+	PaymentAmount    float64   `json:"payment_amount" description:"到款金额"`
+	PayType          int       `json:"pay_type" description:"付款方式:0-无;1-年付;2-半年付;3-季付;4-次付;5-异常"`
+	ServiceProductId int       `json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
 }
 
 // GetInvoicePaymentCensusSummaryData 获取商品到款统计列表-汇总数据
 func GetInvoicePaymentCensusSummaryData(condition string, pars []interface{}) (results []*InvoicePaymentSummaryItem, err error) {
-	fields := []string{"a.id AS summary_id", "a.register_id", "a.invoice_id", "a.payment_id", "b.company_name", "b.start_date", "b.end_date",
+	fields := []string{"a.id AS summary_id", "a.register_id", "a.invoice_id", "a.payment_id", "a.service_product_id", "b.company_name", "b.start_date", "b.end_date",
 		"c.origin_amount AS invoice_amount", "c.invoice_time AS invoice_date", "c.seller_id", "c.seller_name", "c.seller_group_id",
 		"c.seller_group_name", "d.origin_amount AS payment_amount", "d.invoice_time AS payment_date", "d.pay_type",
 	}

+ 2 - 0
routers/contract.go

@@ -22,11 +22,13 @@ func InitContract(rg *gin.RouterGroup) {
 	crGroup.GET("invoice_list", cr.InvoiceList)
 	crGroup.POST("import", cr.Import)
 	crGroup.GET("currency_list", cr.CurrencyList)
+	crGroup.GET("check_contract_code", cr.CheckContractName)
 
 	// 合同套餐
 	sr := new(contract.ServiceController)
 	srGroup := rg.Group("service/").Use(middleware.Token())
 	srGroup.GET("list", sr.List)
+	srGroup.GET("simple", sr.SimpleList)
 
 	// 到款登记
 	pay := new(contract.PaymentController)

+ 120 - 6
services/crm/company_seller.go

@@ -7,11 +7,12 @@ import (
 
 // GetSellerDepartmentAndGroupMap 获取销售部门列表-包含大组和小组
 func GetSellerDepartmentListWithGroupAndTeam() (sellerList []*crm.SellerAdminWithGroupTeam, err error) {
+	departmentIds := []int{crm.SellerDepartmentId,crm.RaiSellerDepartmentId}
 	sellerList = make([]*crm.SellerAdminWithGroupTeam, 0)
 	// 获取组别列表
-	groupCond := "department_id = ?"
+	groupCond := "department_id in (?)"
 	groupPars := make([]interface{}, 0)
-	groupPars = append(groupPars, crm.SellerDepartmentId)
+	groupPars = append(groupPars, departmentIds)
 	groupOB := new(crm.SysGroup)
 	groupList, e := groupOB.List(groupCond, groupPars)
 	if e != nil {
@@ -24,9 +25,9 @@ func GetSellerDepartmentListWithGroupAndTeam() (sellerList []*crm.SellerAdminWit
 	}
 
 	// 获取销售部门所有销售信息
-	adminCond := "department_id = ? AND enabled = 1"
+	adminCond := "department_id in (?) AND enabled = 1"
 	adminPars := make([]interface{}, 0)
-	adminPars = append(adminPars, crm.SellerDepartmentId)
+	adminPars = append(adminPars, departmentIds)
 	adminOB := new(crm.Admin)
 	adminList, e := adminOB.List(adminCond, adminPars)
 	if e != nil {
@@ -37,6 +38,7 @@ func GetSellerDepartmentListWithGroupAndTeam() (sellerList []*crm.SellerAdminWit
 	// 销售列表
 	for i := range adminList {
 		v := new(crm.SellerAdminWithGroupTeam)
+		v.DepartmentId = adminList[i].DepartmentId
 		v.SellerId = adminList[i].AdminId
 		v.SellerName = adminList[i].RealName
 		g := groupMap[adminList[i].GroupId]
@@ -64,9 +66,9 @@ func GetSellerDepartmentListWithGroupAndTeam() (sellerList []*crm.SellerAdminWit
 // GetSellerTeamGroupMap 获取销售组别对应的大组信息
 func GetSellerTeamGroupMap() (teamGroupMap map[int]*crm.SysGroup, err error) {
 	teamGroupMap = make(map[int]*crm.SysGroup)
-	groupCond := `department_id = ?`
+	groupCond := `department_id IN (?,?)`
 	groupPars := make([]interface{}, 0)
-	groupPars = append(groupPars, crm.SellerDepartmentId)
+	groupPars = append(groupPars, crm.SellerDepartmentId, crm.RaiSellerDepartmentId)
 	groupOB := new(crm.SysGroup)
 	groupList, e := groupOB.List(groupCond, groupPars)
 	if e != nil {
@@ -87,3 +89,115 @@ func GetSellerTeamGroupMap() (teamGroupMap map[int]*crm.SysGroup, err error) {
 	}
 	return
 }
+
+
+// GetSellerDepartmentList 获取销售部门列表-包含大组和小组
+func GetSellerDepartmentList() (resp crm.SellerAdminWithGroupList, err error) {
+	// 获取组别列表
+	departmentIds := []int{crm.SellerDepartmentId,crm.RaiSellerDepartmentId}
+	groupCond := "department_id in (?)"
+	groupPars := make([]interface{}, 0)
+	groupPars = append(groupPars, departmentIds)
+	groupOB := new(crm.SysGroup)
+	groupList, e := groupOB.List(groupCond, groupPars)
+	if e != nil {
+		err = errors.New("获取组别列表失败, Err: " + e.Error())
+		return
+	}
+	groupMap := make(map[int]*crm.SysGroup)
+	teamMap := make(map[int]*crm.SysGroup)
+	for i := range groupList {
+		if groupList[i].ParentId > 0 {
+			teamMap[groupList[i].GroupId] = groupList[i]
+		}else{
+			groupMap[groupList[i].GroupId] = groupList[i]
+		}
+	}
+
+	// 获取销售部门所有销售信息
+	adminCond := "department_id in (?) AND enabled = 1"
+	adminPars := make([]interface{}, 0)
+	adminPars = append(adminPars, departmentIds)
+	adminOB := new(crm.Admin)
+	adminList, e := adminOB.List(adminCond, adminPars)
+	if e != nil {
+		err = errors.New("获取销售列表失败, Err: " + e.Error())
+		return
+	}
+
+	// 销售列表
+	groupSeller := make(map[int][]crm.SellerAdminWithGroupTree)
+	ficcList := make([]crm.SellerAdminList, 0)
+	raiList := make([]crm.SellerAdminList, 0)
+	for i := range adminList {
+		v := crm.SellerAdminList{
+			SellerId:    adminList[i].AdminId,
+			SellerName:  adminList[i].RealName,
+		}
+		if adminList[i].DepartmentId == crm.SellerDepartmentId {
+			ficcList = append(ficcList, v)
+		}else if adminList[i].DepartmentId == crm.RaiSellerDepartmentId {
+			raiList = append(raiList, v)
+		}
+		if t, ok := teamMap[adminList[i].GroupId]; ok { // 如果销售是在三级分组下面,则找到对应的二级分组
+			if g, ok1 := groupMap[t.ParentId]; ok1 {
+				tmp := crm.SellerAdminWithGroupTree{
+					SellerId:    adminList[i].AdminId,
+					SellerName:  adminList[i].RealName,
+					Child: nil,
+				}
+				groupSeller[g.GroupId] = append(groupSeller[g.GroupId], tmp)
+			}else{
+				err = errors.New("找不到对应的销售分组")
+				return
+			}
+		}else{
+			if g, ok1 := groupMap[adminList[i].GroupId]; ok1 {
+				tmp := crm.SellerAdminWithGroupTree{
+					SellerId:    adminList[i].AdminId,
+					SellerName:  adminList[i].RealName,
+					Child: nil,
+				}
+				groupSeller[g.GroupId] = append(groupSeller[g.GroupId], tmp)
+			}else{
+				err = errors.New("找不到对应的销售分组")
+				return
+			}
+		}
+	}
+	//分组
+	departmentMap := make(map[int][]crm.SellerAdminWithGroupTree)
+	for k, v := range groupMap {
+		child, _ := groupSeller[k]
+		tmp := crm.SellerAdminWithGroupTree{
+			SellerId:   k,
+			SellerName: v.GroupName,
+			Child:      child,
+		}
+		departmentMap[v.DepartmentId] = append(departmentMap[v.DepartmentId], tmp)
+	}
+	//分部门
+	allTitleMap := map[int]string{
+		crm.SellerDepartmentId:"FICC销售",
+		crm.RaiSellerDepartmentId:"权益销售",
+	}
+	ficcTree, _ := departmentMap[crm.SellerDepartmentId]
+	raiTree, _ := departmentMap[crm.RaiSellerDepartmentId]
+	tmp1 := crm.SellerAdminWithGroupTree{
+		SellerId:   crm.SellerDepartmentId,
+		SellerName: allTitleMap[crm.SellerDepartmentId],
+		Child:      ficcTree,
+	}
+	tmp2 := crm.SellerAdminWithGroupTree{
+		SellerId:   crm.RaiSellerDepartmentId,
+		SellerName: allTitleMap[crm.RaiSellerDepartmentId],
+		Child:      raiTree,
+	}
+	allList := make([]crm.SellerAdminWithGroupTree, 0)
+	allList = append(allList, tmp1)
+	allList = append(allList, tmp2)
+	resp.AllList = allList
+	resp.FiccList = ficcList
+	resp.RaiList = raiList
+	return
+}

+ 44 - 2
services/crm/contract.go

@@ -5,6 +5,7 @@ import (
 	"errors"
 	"fmt"
 	"hongze/fms_api/models/crm"
+	"hongze/fms_api/models/fms"
 	"hongze/fms_api/models/system"
 	"hongze/fms_api/utils"
 	"reflect"
@@ -81,12 +82,37 @@ func getContractDetail(contractId int) (contractDetail *crm.ContractDetail, err
 }
 
 // getContractServiceAndDetailList 根据合同Id获取服务详情列表
-func getContractServiceAndDetailList(contractId int) (serviceList []*crm.ContractServiceAndDetail, err error) {
+func getContractServiceAndDetailList(contractId int) (serviceList []*crm.ContractServiceAndDetailRespItem, err error) {
 	serviceList, err = crm.GetContractServiceAndDetailList(contractId)
 	if err != nil {
 		err = errors.New(fmt.Sprint("查找合同服务异常", err))
 		return
 	}
+
+	serviceTempCond := ``
+	serviceTempPars := make([]interface{}, 0)
+	serviceTempOB := new(fms.ContractServiceTemplate)
+	serviceTempList, e := serviceTempOB.List(serviceTempCond, serviceTempPars)
+	if e != nil {
+		return
+	}
+
+	templateMap := make(map[string]*fms.ContractServiceTemplate,0)
+	templateIdMap := make(map[int]string,0)
+	for _, v := range serviceTempList {
+		templateIdMap[v.ServiceTemplateId] = v.Title
+	}
+	for _, v := range serviceTempList {
+		if v.Title == "主观" || v.Title == "客观" {
+			pTitle := templateIdMap[v.Pid]
+			templateMap[pTitle+"("+v.Title+")"] = v
+		}else {
+			templateMap[v.Title] = v
+		}
+	}
+
+	fmsTemplateIdMap := make(map[int]string,0)
+
 	newLen := len(serviceList)
 	for i := 0; newLen > i; i++ {
 		if serviceList[i].HasDetail == "是" {
@@ -100,12 +126,28 @@ func getContractServiceAndDetailList(contractId int) (serviceList []*crm.Contrac
 			}
 			serviceList[i].DetailList = list
 		}
+		fmsTemplateIdMap[serviceList[i].ServiceTemplateId] = serviceList[i].Title
+	}
+	for _, v := range serviceList {
+		if v.Title ==  "主观" || v.Title == "客观" {
+			v.FMSServiceTemplateId = templateMap[v.Title].ServiceTemplateId
+			v.FMSTitle = templateIdMap[v.FMSServiceTemplateId]
+			v.FMSServiceTemplatePId =templateMap[v.Title].Pid
+			v.FMSPTitle = templateIdMap[v.Pid]
+		}else{
+			if templateMap[v.Title] != nil {
+				v.FMSServiceTemplateId = templateMap[v.Title].ServiceTemplateId
+				v.FMSServiceTemplatePId =templateMap[v.Title].Pid
+			}
+			v.FMSTitle = templateIdMap[v.FMSServiceTemplateId]
+			v.FMSPTitle = templateIdMap[v.Pid]
+		}
 	}
 	return
 }
 
 // GetServicePermissionMap 获取合同服务中的权限id  map
-func GetServicePermissionMap(serviceList []*crm.ContractServiceAndDetail) (checkPermissionIdMap map[int]int, err error) {
+func GetServicePermissionMap(serviceList []*crm.ContractServiceAndDetailRespItem) (checkPermissionIdMap map[int]int, err error) {
 	checkPermissionIdMap = make(map[int]int)
 
 	// 获取品种分类配置

+ 125 - 98
services/fms/contract_register.go

@@ -4,6 +4,7 @@ import (
 	"errors"
 	"fmt"
 	"github.com/shopspring/decimal"
+	"hongze/fms_api/models/base"
 	"hongze/fms_api/models/crm"
 	"hongze/fms_api/models/fms"
 	"hongze/fms_api/services/alarm_msg"
@@ -12,6 +13,7 @@ import (
 	"hongze/fms_api/utils"
 	"os"
 	"regexp"
+	"sort"
 	"strings"
 	"time"
 )
@@ -77,7 +79,7 @@ func CheckContractRegisterAmount(registerId int) {
 }
 
 // HandleContractServiceAndDetail 根据请求数据获取套餐服务详情信息
-func HandleContractServiceAndDetail(productId int, serviceList []fms.ContractServiceAddReq, base642Image bool) (serviceDetailList []*fms.ContractServiceAndDetail, err error) {
+func HandleContractServiceAndDetail(serviceList []fms.ContractServiceAddReq, base642Image bool, serviceAmountMap map[int]float64) (serviceDetailList []*fms.ContractServiceAndDetail, err error) {
 	serviceDetailList = make([]*fms.ContractServiceAndDetail, 0)
 	if len(serviceList) < 0 {
 		err = errors.New("请至少选择一种套餐")
@@ -85,103 +87,7 @@ func HandleContractServiceAndDetail(productId int, serviceList []fms.ContractSer
 	}
 	for i := 0; i < len(serviceList); i++ {
 		item := serviceList[i]
-		//detail := item.Detail
-		//
-		//detailList := make([]*fms.ContractServiceDetail, 0)
-		//if len(detail) > 0 {
-		//	for j := 0; j < len(detail); j++ {
-		//		detailItem := detail[j]
-		//		cellMap := make(map[string]string)
-		//		for k := 0; k < len(detailItem); k++ {
-		//			key := fmt.Sprint("cell_", k+1)
-		//			v, e := json.Marshal(detailItem[k])
-		//			if e != nil {
-		//				err = errors.New(fmt.Sprint("json转换失败:", e))
-		//				return
-		//			}
-		//			cellMap[key] = string(v)
-		//		}
-		//		contractServiceDetail := &fms.ContractServiceDetail{
-		//			Col1: func(cellMap map[string]string) string {
-		//				v, ok := cellMap["cell_1"]
-		//				if ok {
-		//					return v
-		//				} else {
-		//					return ""
-		//				}
-		//			}(cellMap),
-		//			Col2: func(cellMap map[string]string) string {
-		//				v, ok := cellMap["cell_2"]
-		//				if ok {
-		//					return v
-		//				} else {
-		//					return ""
-		//				}
-		//			}(cellMap),
-		//			Col3: func(cellMap map[string]string) string {
-		//				v, ok := cellMap["cell_3"]
-		//				if ok {
-		//					return v
-		//				} else {
-		//					return ""
-		//				}
-		//			}(cellMap),
-		//			Col4: func(cellMap map[string]string) string {
-		//				v, ok := cellMap["cell_4"]
-		//				if ok {
-		//					return v
-		//				} else {
-		//					return ""
-		//				}
-		//			}(cellMap),
-		//			Col5: func(cellMap map[string]string) string {
-		//				v, ok := cellMap["cell_5"]
-		//				if ok {
-		//					return v
-		//				} else {
-		//					return ""
-		//				}
-		//			}(cellMap),
-		//			Col6: func(cellMap map[string]string) string {
-		//				v, ok := cellMap["cell_6"]
-		//				if ok {
-		//					return v
-		//				} else {
-		//					return ""
-		//				}
-		//			}(cellMap),
-		//			Col7: func(cellMap map[string]string) string {
-		//				v, ok := cellMap["cell_7"]
-		//				if ok {
-		//					return v
-		//				} else {
-		//					return ""
-		//				}
-		//			}(cellMap),
-		//			ServiceTemplateId: item.ServiceTemplateId,
-		//			CreateTime:        time.Now(),
-		//		}
-		//		detailList = append(detailList, contractServiceDetail)
-		//	}
-		//}
 		hasDetail := "否"
-		//if len(detailList) > 0 {
-		//	hasDetail = "是"
-		//}
-		//// 报价单图片地址
-		//newValue := item.Value
-		//if base642Image {
-		//	b, _ := regexp.MatchString(`^data:\s*image\/(\w+);base64,`, newValue)
-		//	if b {
-		//		imageUrl, e := UploadImageBase64(newValue)
-		//		if e != nil {
-		//			err = errors.New(fmt.Sprint("base64图片上传失败:", e))
-		//			return
-		//		}
-		//		newValue = imageUrl
-		//	}
-		//}
-
 		// 合同模板
 		serviceTemp, e := fms.GetContractServiceTemplateById(item.ServiceTemplateId)
 		if e != nil {
@@ -192,7 +98,7 @@ func HandleContractServiceAndDetail(productId int, serviceList []fms.ContractSer
 			ServiceTemplateId:  item.ServiceTemplateId,
 			Title:              item.Title,
 			Value:              item.Value,
-			ProductId:          productId,
+			ProductId:          serviceTemp.ProductId,
 			HasDetail:          hasDetail,
 			TableValue:         serviceTemp.TableValue,
 			ChartPermissionId:  serviceTemp.ChartPermissionId,
@@ -204,6 +110,30 @@ func HandleContractServiceAndDetail(productId int, serviceList []fms.ContractSer
 	return
 }
 
+// HandleContractServiceAmount 根据请求数据获取套餐金额详情信息
+func HandleContractServiceAmount(serviceAmountList []fms.ContractServiceAmountAddReq, serviceAmountMap map[int]float64, currencyUnit string) (list []*fms.ContractServiceAmount, err error) {
+	if len(serviceAmountList) < 0 {
+		err = errors.New("请至少输入一种套餐金额信息")
+		return
+	}
+	for i := 0; i < len(serviceAmountList); i++ {
+		item := serviceAmountList[i]
+		serviceAmountMap[item.ProductId] = item.ServiceAmount
+		if item.ProductId !=crm.CompanyProductRai && item.ProductId != crm.CompanyProductFicc {
+			err = errors.New("请选择正确和套餐类型")
+			return
+		}
+		serviceDetail := &fms.ContractServiceAmount{
+			ProductId:     item.ProductId,
+			ServiceAmount: item.ServiceAmount,
+			CurrencyUnit:  currencyUnit,
+			TimeBase:      base.TimeBase{},
+		}
+		list = append(list, serviceDetail)
+	}
+	return
+}
+
 // GetContractServiceAndDetail 根据合同登记ID获取服务详情
 func GetContractServiceAndDetail(contractRegisterId int) (serviceList []*fms.ContractServiceAndDetail, err error) {
 	list, e := fms.GetContractServiceAndDetailList(contractRegisterId)
@@ -376,3 +306,100 @@ func FixContractSummaryData() {
 	fmt.Println("end 修复")
 	return
 }
+
+
+func GetContractServiceNameFormat(registerIds []int) (serviceNameMap map[int]string, serviceFormatMap map[int][]fms.ContractServiceTemplateFormat, err error) {
+	serviceNameMap = make(map[int]string)
+	serviceMap := make(map[int][]string, 0)
+	serviceFormatMap = make(map[int][]fms.ContractServiceTemplateFormat, 0)
+	serviceIndustryStr := "医药,消费,科技,智造"
+	serviceIdMap := make(map[int]*fms.ContractServiceTemplateFullName, 0)
+	serviceIndustryMap := make(map[int]map[string][]*fms.ContractServiceTemplateFullName, 0)
+	allServiceList, e := fms.GetContractServiceTemplateFullName()
+	if e != nil {
+		err = fmt.Errorf("获取所有套餐失败, Err: "+e.Error())
+		return
+	}
+	for _, v := range allServiceList {
+		serviceIdMap[v.ServiceTemplateId] = v
+	}
+	// 获取服务套餐
+	servicesList, e := fms.GetContractRegisterServicesByRegisterIds(registerIds)
+	if e != nil {
+		err = fmt.Errorf("获取套餐字符串失败, Err: "+e.Error())
+		return
+	}
+	for i := range servicesList {
+		item := servicesList[i]
+		if item.Title == "行业套餐" || item.Title == "权益大套餐" {
+			continue
+		}
+		if fullItem, ok := serviceIdMap[item.ServiceTemplateId]; ok {
+			if fullItem.ParentTitle == "行业套餐" {
+				continue
+			}
+			if fullItem.ParentTitle != "" {
+				if strings.Contains(serviceIndustryStr, fullItem.ParentTitle) {
+					if _, ok1 := serviceIndustryMap[item.ContractRegisterId]; !ok1 {
+						serviceIndustryMap[item.ContractRegisterId] = make(map[string][]*fms.ContractServiceTemplateFullName)
+					}
+					serviceIndustryMap[item.ContractRegisterId][fullItem.ParentTitle] = append(serviceIndustryMap[item.ContractRegisterId][fullItem.ParentTitle], fullItem)
+				} else {
+					formatTitle := ""
+					if fullItem.ParentTitle == "策略" {
+						formatTitle = fullItem.Title
+					}else{
+						formatTitle = fullItem.ParentTitle+"("+fullItem.Title+")"
+					}
+					serviceMap[item.ContractRegisterId] = append(serviceMap[item.ContractRegisterId], formatTitle)
+					tmp := fms.ContractServiceTemplateFormat{
+						FormatTitle:        formatTitle,
+						ServiceTemplateId:  fullItem.ServiceTemplateId,
+						ServiceTemplatePid: fullItem.Pid,
+					}
+					serviceFormatMap[item.ContractRegisterId] = append(serviceFormatMap[item.ContractRegisterId], tmp)
+				}
+			}else{
+				serviceMap[item.ContractRegisterId] = append(serviceMap[item.ContractRegisterId], fullItem.Title)
+				tmp := fms.ContractServiceTemplateFormat{
+					FormatTitle:        fullItem.Title,
+					ServiceTemplateId:  fullItem.ServiceTemplateId,
+					ServiceTemplatePid: fullItem.Pid,
+				}
+				serviceFormatMap[item.ContractRegisterId] = append(serviceFormatMap[item.ContractRegisterId], tmp)
+			}
+		}
+	}
+	for k, v := range serviceIndustryMap {
+		for sk, sv := range v {
+			formatTitle := ""
+			templateId := 0
+			pid := 0
+			if len(sv) >= 2 {
+				formatTitle = sk
+				templateId = sv[0].Pid
+			}else{
+				formatTitle = sk+"("+sv[0].Title+")"
+				templateId = sv[0].ServiceTemplateId
+				pid = sv[0].Pid
+			}
+			serviceMap[k] = append(serviceMap[k], formatTitle)
+			tmp := fms.ContractServiceTemplateFormat{
+				FormatTitle:       formatTitle,
+				ServiceTemplateId: templateId,
+				ServiceTemplatePid: pid,
+			}
+			serviceFormatMap[k] = append(serviceFormatMap[k], tmp)
+		}
+	}
+
+	// 给套餐内容排序
+	for k, v := range serviceFormatMap {
+		sort.Sort(fms.ContractServiceTemplateFormatList(v))
+		for _, sv := range v {
+			serviceNameMap[k] += sv.FormatTitle+","
+		}
+		serviceNameMap[k] = strings.Trim(serviceNameMap[k], ",")
+	}
+	return
+}

+ 215 - 16
services/fms/invoice_payment.go

@@ -3,9 +3,11 @@ package fms
 import (
 	"fmt"
 	"github.com/shopspring/decimal"
+	"hongze/fms_api/models/crm"
 	"hongze/fms_api/models/fms"
 	"hongze/fms_api/services/alarm_msg"
 	"hongze/fms_api/utils"
+	"strconv"
 	"time"
 )
 
@@ -176,52 +178,100 @@ func SummaryInvoicePaymentByContractRegisterId(registerId int) {
 		err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
 		return
 	}
-	invoiceIds := make([]int, 0)
-	paymentIds := make([]int, 0)
+	ficcInvoiceIds := make([]int, 0)
+	ficcPaymentIds := make([]int, 0)
+	raiInvoiceIds := make([]int, 0)
+	raiPaymentIds := make([]int, 0)
 	for i := range list {
 		if list[i].InvoiceType == fms.ContractInvoiceTypeMake {
-			invoiceIds = append(invoiceIds, list[i].ContractInvoiceId)
+			if list[i].ServiceProductId == crm.CompanyProductFicc {
+				ficcInvoiceIds = append(ficcInvoiceIds, list[i].ContractInvoiceId)
+			}else if list[i].ServiceProductId == crm.CompanyProductRai {
+				raiInvoiceIds = append(raiInvoiceIds, list[i].ContractInvoiceId)
+			}
 			continue
 		}
 		if list[i].InvoiceType == fms.ContractInvoiceTypePay {
-			paymentIds = append(paymentIds, list[i].ContractInvoiceId)
+			if list[i].ServiceProductId == crm.CompanyProductFicc {
+				ficcPaymentIds = append(ficcPaymentIds, list[i].ContractInvoiceId)
+			}else if list[i].ServiceProductId == crm.CompanyProductRai {
+				raiPaymentIds = append(raiPaymentIds, list[i].ContractInvoiceId)
+			}
 		}
 	}
-	invoiceLen := len(invoiceIds)
-	paymentLen := len(paymentIds)
+	ficcInvoiceLen := len(ficcInvoiceIds)
+	raiInvoiceLen := len(raiInvoiceIds)
+	ficcPaymentLen := len(ficcPaymentIds)
+	raiPaymentLen := len(raiPaymentIds)
 
 	// 汇总数据
 	nowTime := time.Now().Local()
 	summaryList := make([]*fms.InvoicePaymentSummary, 0)
-	if invoiceLen >= paymentLen {
-		for i := range invoiceIds {
+	// ficc
+	if ficcInvoiceLen >= ficcPaymentLen {
+		for i := range ficcInvoiceIds {
 			v := new(fms.InvoicePaymentSummary)
 			v.RegisterId = registerId
-			v.InvoiceId = invoiceIds[i]
+			v.InvoiceId = ficcInvoiceIds[i]
+			v.ServiceProductId = crm.CompanyProductFicc
 			v.CreateTime = nowTime
 			v.ModifyTime = nowTime
 			// 取对应key的到款ID
-			if i+1 <= paymentLen {
-				v.PaymentId = paymentIds[i]
+			if i+1 <= ficcPaymentLen {
+				v.PaymentId = ficcPaymentIds[i]
 			}
 			summaryList = append(summaryList, v)
 		}
 	}
-	if paymentLen > invoiceLen {
-		for i := range paymentIds {
+	if ficcPaymentLen > ficcInvoiceLen {
+		for i := range ficcPaymentIds {
 			v := new(fms.InvoicePaymentSummary)
 			v.RegisterId = registerId
-			v.PaymentId = paymentIds[i]
+			v.PaymentId = ficcPaymentIds[i]
+			v.ServiceProductId = crm.CompanyProductFicc
 			v.CreateTime = nowTime
 			v.ModifyTime = nowTime
 			// 取对应key的开票ID
-			if i+1 <= invoiceLen {
-				v.InvoiceId = invoiceIds[i]
+			if i+1 <= ficcInvoiceLen {
+				v.InvoiceId = ficcInvoiceIds[i]
+			}
+			summaryList = append(summaryList, v)
+		}
+	}
+
+	// rai
+	if raiInvoiceLen >= raiPaymentLen {
+		for i := range raiInvoiceIds {
+			v := new(fms.InvoicePaymentSummary)
+			v.RegisterId = registerId
+			v.InvoiceId = raiInvoiceIds[i]
+			v.ServiceProductId = crm.CompanyProductRai
+			v.CreateTime = nowTime
+			v.ModifyTime = nowTime
+			// 取对应key的到款ID
+			if i+1 <= raiPaymentLen {
+				v.PaymentId = raiPaymentIds[i]
+			}
+			summaryList = append(summaryList, v)
+		}
+	}
+	if raiPaymentLen > raiInvoiceLen {
+		for i := range raiPaymentIds {
+			v := new(fms.InvoicePaymentSummary)
+			v.RegisterId = registerId
+			v.PaymentId = raiPaymentIds[i]
+			v.ServiceProductId = crm.CompanyProductRai
+			v.CreateTime = nowTime
+			v.ModifyTime = nowTime
+			// 取对应key的开票ID
+			if i+1 <= raiInvoiceLen {
+				v.InvoiceId = raiInvoiceIds[i]
 			}
 			summaryList = append(summaryList, v)
 		}
 	}
 
+
 	// 删除并新增汇总数据
 	summaryOB := new(fms.InvoicePaymentSummary)
 	if e = summaryOB.DeleteAndCreate(registerId, summaryList); e != nil {
@@ -229,3 +279,152 @@ func SummaryInvoicePaymentByContractRegisterId(registerId int) {
 	}
 	return
 }
+
+// CalculatePaymentServiceAmount
+func CalculatePaymentServiceAmount(registerId int) (err error)  {
+	// todo 判断是否符合均分金额的条件,如果符合,需要生成金额分配记录表
+	// 查询所有的到款记录,如果没有到款记录则无需分配到款金额
+	cond := `contract_register_id = ? and invoice_type=2 and service_product_id=2`
+	pars := make([]interface{}, 0)
+	pars = append(pars, registerId)
+	paymentList, err := fms.GetContractInvoiceItemList(cond, pars)
+	if err != nil {
+		err = fmt.Errorf("获取开票到款列表失败, Err: %s", err.Error())
+		return
+	}
+	if len(paymentList) == 0 {
+		return
+	}
+	var contractPaymentIds []int
+	for _, v:= range paymentList{
+		contractPaymentIds = append(contractPaymentIds, v.ContractInvoiceId)
+	}
+	// 获取服务套餐
+	servicesList, err := fms.GetContractServiceAndDetailList(registerId)
+	if err != nil {
+		err = fmt.Errorf("获取服务套餐失败, Err: "+err.Error())
+		return
+	}
+	industrySlice := []string{
+		"行业套餐",
+		"医药",
+		"消费",
+		"科技",
+		"智造",
+		"策略",
+		"主观",
+		"客观",
+	}
+	unNeedAsign := false
+	industryFlag := false
+	servicesListMap := make(map[int]*fms.ContractServiceAndDetail)
+	// 判断当前套餐是否符合分配规则
+	for _, v :=range servicesList {
+		if v.ProductId == crm.CompanyProductRai {
+			industryFlag = true
+		}
+		servicesListMap[v.ServiceTemplateId] = v
+		if v.ProductId==crm.CompanyProductRai && !utils.InArray(v.Title, industrySlice){
+			unNeedAsign = true
+		}
+	}
+	if unNeedAsign || !industryFlag{
+		//不符合自动分配规则,则直接删除之前的自动分配记录
+		err =fms.DeletePaymentServiceAmountByRegisterId(registerId)
+		if err !=nil {
+			return
+		}
+		return
+	} else {
+		//遍历所有的到款记录,筛选出需要删除并新增的到款记录ID
+		_, serviceFormatMap, e := GetContractServiceNameFormat([]int{registerId})
+		if e != nil {
+			err = fmt.Errorf("获取合同套餐失败, Err: %s", e.Error())
+			return
+		}
+		servicesFormatList, ok := serviceFormatMap[registerId]
+		if !ok {
+			err = fmt.Errorf("查不到合同套餐")
+			return
+		}
+
+		servicesFormatStr := ""
+		length :=0
+		for _, v :=range servicesFormatList {
+			if  servicesListMap[v.ServiceTemplateId].ProductId==crm.CompanyProductRai{
+				length ++
+				servicesFormatStr += fmt.Sprintf("%d_", v.ServiceTemplateId)
+			}
+		}
+		if length ==0 {
+			return
+		}
+		payAverageAmountMap := make(map[int]float64)
+		for _, v := range paymentList{
+			payAverageAmountMap[v.ContractInvoiceId] = v.Amount/float64(length)
+			payAverageAmountMap[v.ContractInvoiceId], _ = strconv.ParseFloat(fmt.Sprintf("%.2f", payAverageAmountMap[v.ContractInvoiceId]), 64)
+		}
+
+		//查询原来的金额分配记录
+		serviceAmountCond := `contract_payment_id = ? and contract_payment_id in ?`
+		serviceAmountPars := make([]interface{}, 0)
+		serviceAmountPars = append(serviceAmountPars, registerId, contractPaymentIds)
+		serviceAmountOB := new(fms.ContractPaymentServiceAmount)
+		serviceAmountList, e := serviceAmountOB.List(serviceAmountCond, serviceAmountPars)
+		if e != nil {
+			err = fmt.Errorf("获取到款套餐分配列表失败, Err: %s", e.Error())
+			return
+		}
+
+		oldPaymentServiceMap := make(map[int]string)
+		oldPaymentAmountMap := make(map[int]float64)
+		for _, v := range serviceAmountList{
+			oldPaymentServiceMap[v.ContractPaymentId] += fmt.Sprintf("%d_", v.ServiceTemplateId)
+			oldPaymentAmountMap[v.ContractPaymentId] = v.Amount
+		}
+
+		var newPaymentIds []int
+		for _, v := range paymentList{
+			if _, ok1 := oldPaymentServiceMap[v.ContractInvoiceId]; !ok1{
+				newPaymentIds = append(newPaymentIds, v.ContractInvoiceId)
+				continue
+			}
+			if oldPaymentServiceMap[v.ContractInvoiceId] != servicesFormatStr {
+				newPaymentIds = append(newPaymentIds, v.ContractInvoiceId)
+				continue
+			}
+			if oldPaymentAmountMap[v.ContractInvoiceId] != payAverageAmountMap[v.ContractInvoiceId] {
+				newPaymentIds = append(newPaymentIds, v.ContractInvoiceId)
+				continue
+			}
+		}
+
+		// 删除旧的金额分配记录并生成新的自动分配记录
+		if len(newPaymentIds) == 0{
+			return
+		}
+		for _, v := range newPaymentIds {
+			addList := make([]*fms.ContractPaymentServiceAmount, 0)
+			for _, f := range servicesFormatList {
+				if  servicesListMap[f.ServiceTemplateId].ProductId==crm.CompanyProductRai {
+					t := &fms.ContractPaymentServiceAmount{
+						ContractRegisterId: registerId,
+						ContractPaymentId:  v,
+						ServiceTemplatePid: f.ServiceTemplatePid,
+						ServiceTemplateId:  f.ServiceTemplateId,
+						Amount:             payAverageAmountMap[v],
+						InitType:           1,
+					}
+					t.Set()
+					addList = append(addList, t)
+				}
+			}
+			if e := fms.CreatePaymentServiceAmount(registerId, v, addList); e != nil {
+				err = fmt.Errorf( "新增到款套餐金额失败, Err: "+e.Error())
+				return
+			}
+		}
+	}
+	return
+}
+

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor