瀏覽代碼

合规登记新增/编辑、导入导出

xiexiaoyuan 2 年之前
父節點
當前提交
e6c5a3b861

+ 3 - 2
controller/census/invoice_payment.go

@@ -460,8 +460,9 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 		pars = append(pars, req.SellGroupId)
 	}
 	// 套餐筛选
-	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

+ 462 - 70
controller/contract/register.go

@@ -75,8 +75,9 @@ func (rg *RegisterController) List(c *gin.Context) {
 		pars = append(pars, req.RegisterStatus)
 	}
 	// 套餐筛选
-	if req.ServiceType != 0 {
-		registerIds, e := fms.GetContractRegisterIdsByTempId(req.ServiceType)
+	if req.ServiceTypes != "" {
+		serviceTypes := strings.Split(req.ServiceTypes, ",")
+		registerIds, e := fms.GetContractRegisterIdsByTempId(serviceTypes)
 		if e != nil {
 			resp.FailMsg("获取失败", "获取合同登记IDs失败, Err: "+e.Error(), c)
 			return
@@ -242,9 +243,11 @@ func (rg *RegisterController) Add(c *gin.Context) {
 	ob.ContractSource = req.ContractSource
 	ob.CompanyName = req.CompanyName
 	ob.ActualCompanyName = req.ActualCompanyName
-	ob.ProductId = req.ProductId
+	ob.ProductIds = req.ProductIds
 	ob.SellerId = req.SellerId
 	ob.SellerName = req.SellerName
+	ob.RaiSellerId = req.RaiSellerId
+	ob.RaiSellerName = req.RaiSellerName
 	ob.ContractType = req.ContractType
 	ob.ContractAmount = req.ContractAmount
 	ob.CurrencyUnit = req.CurrencyUnit
@@ -265,15 +268,22 @@ func (rg *RegisterController) Add(c *gin.Context) {
 		ob.RegisterStatus = fms.ContractRegisterStatusComplete
 	}
 
+	// 新增套餐金额详情内容
+	serviceAmountMap := make(map[int]float64)
+	serviceAmountList, e := fmsService.HandleContractServiceAmount(req.ServiceAmount, serviceAmountMap, req.CurrencyUnit)
+	if e != nil {
+		resp.FailMsg("操作失败", "新增合同套餐金额信息失败, Err: "+e.Error(), c)
+		return
+	}
 	// 套餐信息
-	serviceList, e := fmsService.HandleContractServiceAndDetail(req.ProductId, req.Services, true)
+	serviceList, e := fmsService.HandleContractServiceAndDetail(req.Services, true, serviceAmountMap)
 	if e != nil {
 		resp.FailMsg("操作失败", "获取合同套餐详情失败, Err: "+e.Error(), c)
 		return
 	}
 
 	// 新增合同及套餐
-	if e = fms.CreateContractRegisterAndServices(ob, serviceList); e != nil {
+	if e = fms.CreateContractRegisterAndServices(ob, serviceList, serviceAmountList); e != nil {
 		resp.FailMsg("操作失败", "新增合同及套餐失败, Err: "+e.Error(), c)
 		return
 	}
@@ -370,11 +380,12 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	originHasPayment := item.HasPayment
 
 	updateCols := []string{
-		"ContractCode", "RelateContractCode", "CrmContractId", "ContractSource", "CompanyName", "ActualCompanyName",
+		"ProductIds","ContractCode", "RelateContractCode", "CrmContractId", "ContractSource", "CompanyName", "ActualCompanyName",
 		"SellerId", "SellerName", "ContractType", "ContractAmount", "StartDate", "EndDate", "SignDate", "AgreedPayTime",
 		"ContractStatus", "RegisterStatus", "Remark", "ServiceRemark", "HasPayment", "NewCompany", "ModifyTime",
 	}
 	nowTime := time.Now().Local()
+	item.ProductIds = req.ProductIds
 	item.ContractCode = req.ContractCode
 	item.RelateContractCode = req.RelateContractCode
 	item.CrmContractId = req.CrmContractId
@@ -383,6 +394,8 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	item.ActualCompanyName = req.ActualCompanyName
 	item.SellerId = req.SellerId
 	item.SellerName = req.SellerName
+	item.RaiSellerId = req.RaiSellerId
+	item.RaiSellerName = req.RaiSellerName
 	item.ContractType = req.ContractType
 	item.ContractAmount = req.ContractAmount
 	item.StartDate = startDate
@@ -455,16 +468,23 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 			logRemark = fmt.Sprintf("金额单位由%s修改为%s\n%s", item.CurrencyUnit, req.CurrencyUnit, logRemark)
 		}
 	}
+	// 新增套餐金额详情内容
+	serviceAmountMap := make(map[int]float64)
+	serviceAmountList, e := fmsService.HandleContractServiceAmount(req.ServiceAmount, serviceAmountMap, req.CurrencyUnit)
+	if e != nil {
+		resp.FailMsg("操作失败", "新增合同套餐金额信息失败, Err: "+e.Error(), c)
+		return
+	}
 
 	// 套餐信息
-	serviceList, e := fmsService.HandleContractServiceAndDetail(req.ProductId, req.Services, true)
+	serviceList, e := fmsService.HandleContractServiceAndDetail(req.Services, true, serviceAmountMap)
 	if e != nil {
 		resp.FailMsg("操作失败", "获取合同套餐详情失败, Err: "+e.Error(), c)
 		return
 	}
 
 	// 更新合同登记、套餐、开票到款
-	if e = fms.UpdateContractRegister(item, updateCols, serviceList, invoiceList, invoiceUpdateCols, invoiceHandleType); e != nil {
+	if e = fms.UpdateContractRegister(item, updateCols, serviceList, invoiceList, invoiceUpdateCols, invoiceHandleType, serviceAmountList); e != nil {
 		resp.FailMsg("操作失败", "更新合同及套餐失败, Err: "+e.Error(), c)
 		return
 	}
@@ -949,8 +969,9 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		cond += ` AND register_status = ?`
 		pars = append(pars, req.RegisterStatus)
 	}
-	if req.ServiceType != 0 {
-		registerIds, e := fms.GetContractRegisterIdsByTempId(req.ServiceType)
+	if req.ServiceTypes != "" {
+		serviceTypes := strings.Split(req.ServiceTypes, ",")
+		registerIds, e := fms.GetContractRegisterIdsByTempId(serviceTypes)
 		if e != nil {
 			resp.FailMsg("获取失败", "获取合同登记IDs失败, Err: "+e.Error(), c)
 			return
@@ -995,7 +1016,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		permissionNameIdMap[permissionList[i].PermissionName] = permissionList[i].ChartPermissionId
 	}
 
-	// 获取套餐服务
+	// 获取所有FICC套餐服务
 	serviceList, e := fms.GetContractServiceTemplateMapByProductId(crm.CompanyProductFicc)
 	if e != nil {
 		resp.FailData("获取套餐服务失败", "Err:"+e.Error(), c)
@@ -1010,6 +1031,47 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	}
 	otherServiceLen := len(otherService)
 
+
+	// 获取所有权益套餐服务
+	raiServiceList, e := fms.GetContractServiceTemplateMapByProductId(crm.CompanyProductRai)
+	if e != nil {
+		resp.FailData("获取权益套餐服务失败", "Err:"+e.Error(), c)
+		return
+	}
+	// 除大小套餐外的其他套餐(下面的导出需要以此动态处理)
+	raiOtherService := make([]*fms.ContractServiceTemplateItem, 0)
+	for i := range raiServiceList {
+		//获取二级套餐
+		secondServiceList, e := fms.GetContractServiceTemplateMapByParentId(raiServiceList[i].ServiceTemplateId)
+		if e != nil {
+			resp.FailData("获取二级权益套餐服务失败", "Err:"+e.Error(), c)
+			return
+		}
+		if len(secondServiceList) > 0 {
+			for _, sv := range secondServiceList {
+				//获取三级套餐
+				thirdServiceList, e := fms.GetContractServiceTemplateMapByParentId(sv.ServiceTemplateId)
+				if e != nil {
+					resp.FailData("获取三级权益套餐服务失败", "Err:"+e.Error(), c)
+					return
+				}
+				if len(thirdServiceList) > 0 {
+					for _, tv := range thirdServiceList {
+						raiOtherService = append(raiOtherService, tv)
+					}
+				}else{
+					raiOtherService = append(raiOtherService, sv)
+				}
+			}
+		}else{
+			raiOtherService = append(raiOtherService, raiServiceList[i])
+		}
+	}
+	otherServiceLen += len(raiOtherService)
+
+	//套餐金额map
+	serviceAmountMap := make(map[int]map[int]*fms.ContractServiceAmount)
+
 	// 套餐/开票/到款列表
 	serviceMap := make(map[int][]*fms.ContractService)
 	serviceChartPermissionsMap := make(map[int][]int)
@@ -1044,6 +1106,18 @@ func (rg *RegisterController) Export(c *gin.Context) {
 			}
 		}
 
+		// 获取合同的套餐金额信息
+		serviceAmountList, e := fms.GetContractServiceAmountByContractRegisterIds(registerIds)
+		if e != nil {
+			resp.FailData("获取合同的套餐金额信息失败", "Err:"+e.Error(), c)
+			return
+		}
+		for _, v := range serviceAmountList {
+			if _, ok := serviceAmountMap[v.ContractRegisterId]; !ok {
+				serviceAmountMap[v.ContractRegisterId] = make(map[int]*fms.ContractServiceAmount)
+			}
+			serviceAmountMap[v.ContractRegisterId][v.ProductId] = v
+		}
 		// 获取开票/到款详情, 并取最大的开票/到款数(用于动态扩展第二列表头)
 		ci := new(fms.ContractInvoice)
 		invoiceList, e := ci.List(csCond, csPars, "")
@@ -1100,76 +1174,149 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	}
 
 	// 1行表头
+	hInt := 0
 	titleRow := sheet.AddRow()
 	titleRow.SetHeight(40)
-	// 1行1列-右合并两格
+	// 1行1列-右合并两格, 下合并1行
 	cell1 := titleRow.AddCell()
-	cell1.HMerge = 3
+	cell1.HMerge = 4
+	cell1.VMerge = 1
 	cell1.SetString("FICC客户签约表")
 	cell1.SetStyle(style)
 	// 右增两列空白格用于第一列合并, 否则后续单元格合并会有问题
 	titleRow.AddCell().SetString("")
 	titleRow.AddCell().SetString("")
 	titleRow.AddCell().SetString("")
+	titleRow.AddCell().SetString("")
+	hInt += 5
 
 	// 1行2列
 	cell2 := titleRow.AddCell()
+	cell2.VMerge = 1
 	cell2.SetString("FICC大套餐")
 	cell2.SetStyle(style)
-
+	hInt ++
 	// 1行3列-右合并小套餐数
 	if permissionLen >= 1 {
 		cell3 := titleRow.AddCell()
+		hInt ++
 		cell3.HMerge = permissionLen - 1
+		cell3.VMerge = 1
 		cell3.SetString("FICC小套餐")
 		cell3.SetStyle(style)
 		// 同上右增单元格小套餐数-1的空白单元格用于合并
 		for i := 0; i < permissionLen-1; i++ {
 			titleRow.AddCell().SetString("")
+			hInt ++
 		}
 	}
 	for i := range otherService {
 		cellOther := titleRow.AddCell()
+		cellOther.VMerge = 1
+		hInt ++
 		cellOther.SetString(otherService[i].Title)
 		cellOther.SetStyle(style)
 	}
 
-	// 第二行表头
+	//权益大套餐
+	cell4 := titleRow.AddCell()
+	cell4.HMerge = 1
+	cell4.VMerge = 1
+	cell4.SetString("权益大套餐")
+	cell4.SetStyle(style)
+	titleRow.AddCell().SetString("")
+	hInt +=2
+
+	//权益分行业套餐
+	cell5 := titleRow.AddCell()
+	cell5.HMerge = 8
+	cell5.SetString("权益分行业套餐")
+	cell5.SetStyle(style)
+	titleRow.AddCell().SetString("")
+	titleRow.AddCell().SetString("")
+	titleRow.AddCell().SetString("")
+	titleRow.AddCell().SetString("")
+	titleRow.AddCell().SetString("")
+	titleRow.AddCell().SetString("")
+	titleRow.AddCell().SetString("")
+	titleRow.AddCell().SetString("")
+
+	//第二行,前面几个单元格用于第一行的合并
 	titleRow2 := sheet.AddRow()
-	titleRow2.SetHeight(60)
-	row2Title := make([]string, 0)
-	row2Title = append(row2Title, "客户名称", "新客户\n0-是\n1-否", "合同类型\n续约-0\n新增-1\n代付-2\n补充协议-3", "销售", "FICC大套餐")
+	titleRow2.SetHeight(30)
+	for i:= 0; i<hInt;i++ {
+		titleRow2.AddCell().SetString("")
+	}
+	//权益分行业套餐
+	row2Cell1 := titleRow2.AddCell()
+	row2Cell1.HMerge = 1
+	row2Cell1.SetString("医药")
+	row2Cell1.SetStyle(style)
+	titleRow2.AddCell().SetString("")
+
+	row2Cell2 := titleRow2.AddCell()
+	row2Cell2.HMerge = 1
+	row2Cell2.SetString("消费")
+	row2Cell2.SetStyle(style)
+	titleRow2.AddCell().SetString("")
+
+	row2Cell3 := titleRow2.AddCell()
+	row2Cell3.HMerge = 1
+	row2Cell3.SetString("科技")
+	row2Cell3.SetStyle(style)
+	titleRow2.AddCell().SetString("")
+
+	row2Cell4 := titleRow2.AddCell()
+	row2Cell4.HMerge = 1
+	row2Cell4.SetString("智造")
+	row2Cell4.SetStyle(style)
+	titleRow2.AddCell().SetString("")
+
+	row2Cell5 := titleRow2.AddCell()
+	row2Cell5.SetString("策略")
+	row2Cell5.SetStyle(style)
+
+	// 第三行表头
+	titleRow3 := sheet.AddRow()
+	titleRow3.SetHeight(60)
+	row3Title := make([]string, 0)
+	row3Title = append(row3Title, "客户名称", "新客户\n0-是\n1-否", "合同类型\n续约-0\n新增-1\n代付-2\n补充协议-3", "FICC销售", "权益销售", "FICC大套餐")
 	for i := range permissionList {
-		row2Title = append(row2Title, permissionList[i].PermissionName)
+		row3Title = append(row3Title, permissionList[i].PermissionName)
 	}
 
 	// 其他套餐
 	for i := range otherService {
-		row2Title = append(row2Title, otherService[i].Title)
+		row3Title = append(row3Title, otherService[i].Title)
 	}
-	row2Title = append(row2Title, "套餐备注", "开始时间", "到期时间", "2022年合同金额", "金额单位", "约定付款时间", "签订日", "合同状态",
+	// 权益三级套餐
+	for i := range raiOtherService {
+		row3Title = append(row3Title, raiOtherService[i].Title)
+	}
+
+	row3Title = append(row3Title, "套餐备注", "开始时间", "到期时间", "2022年合同金额", "金额单位", "FICC套餐总金额", "权益套餐总金额", "约定付款时间", "签订日", "合同状态",
 		"合同编号", "合规备注")
 
 	// 设置表头
-	for i := range row2Title {
-		v := titleRow2.AddCell()
-		v.SetString(row2Title[i])
+	for i := range row3Title {
+		v := titleRow3.AddCell()
+		v.SetString(row3Title[i])
 		v.SetStyle(style)
 	}
 
 	// 第二行表头-开票/收款(动态添加)
-	invoiceTitle := []string{"开票日", "开票金额", "销售", "备注"}
+	invoiceTitle := []string{"开票日", "开票金额", "套餐类型", "销售", "备注"}
 	for i := 0; i < maxInvoice; i++ {
 		n := i + 1
 		for ii := range invoiceTitle {
-			c := titleRow2.AddCell()
+			c := titleRow3.AddCell()
 			t := fmt.Sprintf("%s%d", invoiceTitle[ii], n)
 			c.SetString(t)
 			c.SetStyle(style)
-			row2Title = append(row2Title, t)
+			row3Title = append(row3Title, t)
 		}
 	}
-	paymentTitle := []string{"到款日", "到款金额", "备注"}
+	paymentTitle := []string{"到款日", "到款金额", "套餐类型", "备注"}
 	for i := 0; i < maxPayment; i++ {
 		n := i + 1
 		for ii := range paymentTitle {
@@ -1177,13 +1324,13 @@ func (rg *RegisterController) Export(c *gin.Context) {
 			t := fmt.Sprintf("%s%d", paymentTitle[ii], n)
 			c.SetString(t)
 			c.SetStyle(style)
-			row2Title = append(row2Title, t)
+			row3Title = append(row3Title, t)
 		}
 	}
 	// 此处取第二行标题NameKeyMap, 后面的动态匹配
 	row2NameKeyMap := make(map[string]int)
-	for i := range row2Title {
-		row2NameKeyMap[row2Title[i]] = i
+	for i := range row3Title {
+		row2NameKeyMap[row3Title[i]] = i
 	}
 
 	newCompanyMap := map[int]string{0: "1", 1: "0"}
@@ -1202,15 +1349,17 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		dataRow.AddCell().SetString(newCompanyMap[v.NewCompany])
 		dataRow.AddCell().SetString(fmt.Sprint(contractTMap[v.ContractType]))
 		dataRow.AddCell().SetString(v.SellerName)
+		dataRow.AddCell().SetString(v.RaiSellerName)
 
 		// 大套餐
 		k += 1
-		col4Name := row2Title[k]
+		col4Name := row3Title[k]
 		svList := serviceMap[v.ContractRegisterId]
 		col4 := ""
 		if svList != nil && len(svList) > 0 {
 			for isv := range svList {
 				if svList[isv].Title == col4Name {
+					// todo 判断权益套餐权限时会有问题,需要同时判断父级name
 					col4 = "是"
 					break
 				}
@@ -1222,7 +1371,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		serviceChartPermissionIds := serviceChartPermissionsMap[v.ContractRegisterId]
 		for i := 0; i < permissionLen; i++ {
 			k += 1
-			colName := row2Title[k]
+			colName := row3Title[k]
 			chartPermissionId := permissionNameIdMap[colName]
 			if utils.InArray(chartPermissionId, serviceChartPermissionIds) {
 				dataRow.AddCell().SetString("是")
@@ -1234,7 +1383,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		// 除大小套餐外的其他套餐(处理方式其实跟上面的大套餐一样, 只是中间隔了小套餐按照顺序要这么处理=_=!)
 		for i := 0; i < otherServiceLen; i++ {
 			k += 1
-			otherColName := row2Title[k]
+			otherColName := row3Title[k]
 			otherCol := ""
 			if svList != nil && len(svList) > 0 {
 				for isv := range svList {
@@ -1248,11 +1397,15 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		}
 
 		// 其他信息
+		ficcAmount, _ := serviceAmountMap[v.ContractRegisterId][crm.CompanyProductFicc]
+		raiAmount, _ := serviceAmountMap[v.ContractRegisterId][crm.CompanyProductRai]
 		dataRow.AddCell().SetString(v.ServiceRemark)                                     // 套餐备注
 		dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", v.StartDate)) // 开始时间
 		dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", v.EndDate))   // 到期时间
 		dataRow.AddCell().SetString(fmt.Sprint("¥", v.ContractAmount))                   // 2022年合同金额
 		dataRow.AddCell().SetString(v.CurrencyUnit)                                      // 货币单位
+		dataRow.AddCell().SetString(fmt.Sprint("¥", ficcAmount.ServiceAmount))                    // FICC套餐总金额
+		dataRow.AddCell().SetString(fmt.Sprint("¥", raiAmount.ServiceAmount))                     // 权益套餐总金额
 		dataRow.AddCell().SetString(v.AgreedPayTime)                                     // 约定付款时间
 		dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", v.SignDate))  // 签订日
 		dataRow.AddCell().SetString(fms.ContractStatusKeyNameMap[v.ContractStatus])      // 合同状态
@@ -1267,6 +1420,8 @@ func (rg *RegisterController) Export(c *gin.Context) {
 				if ivList != nil && ivList[ia] != nil {
 					dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", ivList[ia].InvoiceDate)) // 开票日
 					dataRow.AddCell().SetString(fmt.Sprint(ivList[ia].OriginAmount))                            // 开票金额
+					// todo 开票中的套餐类型
+					dataRow.AddCell().SetString("")
 					dataRow.AddCell().SetString(ivList[ia].SellerName)                                          // 销售名称
 					dataRow.AddCell().SetString(ivList[ia].Remark)                                              // 开票备注
 					continue
@@ -1277,6 +1432,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 			dataRow.AddCell().SetString("")
 			dataRow.AddCell().SetString("")
 			dataRow.AddCell().SetString("")
+			dataRow.AddCell().SetString("")
 		}
 		pyList := paymentMap[v.ContractRegisterId]
 		pyListLen := len(pyList)
@@ -1285,6 +1441,8 @@ func (rg *RegisterController) Export(c *gin.Context) {
 				if pyList != nil && pyList[ib] != nil {
 					dataRow.AddCell().SetString(utils.TimeTransferString("2006/01/02", pyList[ib].InvoiceDate)) // 收款日
 					dataRow.AddCell().SetString(fmt.Sprint(pyList[ib].OriginAmount))                            // 收款金额
+					//todo 到款的套餐类型
+					dataRow.AddCell().SetString("")                                                          // 套餐类型
 					dataRow.AddCell().SetString(pyList[ib].Remark)                                              // 收款备注
 					continue
 				}
@@ -1293,6 +1451,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 			dataRow.AddCell().SetString("")
 			dataRow.AddCell().SetString("")
 			dataRow.AddCell().SetString("")
+			dataRow.AddCell().SetString("")
 		}
 	}
 
@@ -1613,10 +1772,38 @@ func (rg *RegisterController) Import(c *gin.Context) {
 		return
 	}
 	serviceTempNameMap := make(map[string]*fms.ContractServiceTemplate)
+	serviceTempFullNameMap := make(map[string]*fms.ContractServiceTemplate)
+	serviceTempIdMap := make(map[int]*fms.ContractServiceTemplate)
 	for i := range serviceTempList {
+		serviceTempIdMap[serviceTempList[i].ServiceTemplateId] = serviceTempList[i]
 		serviceTempNameMap[serviceTempList[i].Title] = serviceTempList[i]
 	}
 
+	for i := range serviceTempList {
+		fullName := serviceTempList[i].Title
+		if serviceTempList[i].Pid > 0  {
+			parentItem := serviceTempIdMap[serviceTempList[i].Pid]
+			fullName += "_"+parentItem.Title
+			if parentItem.Pid > 0 {
+				fullName += "_"+serviceTempIdMap[parentItem.Pid].Title
+			}
+		}
+		serviceTempFullNameMap[fullName] = serviceTempList[i]
+	}
+
+	//权益行业套餐名称
+	raiIndustryMap := map[int]string{
+		36:"医药",
+		37:"医药",
+		38:"消费",
+		39:"消费",
+		40:"科技",
+		41:"科技",
+		42:"智造",
+		43:"智造",
+		44:"策略",
+	}
+
 	// 获取货币列表及汇率(汇率为导入日的汇率)
 	rateList, e := fmsService.GetTodayCurrencyRateList()
 	if e != nil {
@@ -1658,8 +1845,8 @@ func (rg *RegisterController) Import(c *gin.Context) {
 		// 遍历行读取
 		maxRow := sheet.MaxRow
 		for i := 0; i < maxRow; i++ {
-			// 第行开始读取表头
-			if i == 1 {
+			// 第行开始读取表头
+			if i == 2 {
 				row := sheet.Row(i)
 				cells := row.Cells
 				for k, cell := range cells {
@@ -1671,35 +1858,41 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							resp.Fail("【客户名称】列名称有误, 请参考模板导入", c)
 							return
 						}
-					}
-					if k == 1 {
+						continue
+					} else if k == 1 {
 						if !strings.Contains(text, "新客户") {
 							resp.Fail("【新客户】列名称有误, 请参考模板导入", c)
 							return
 						}
-					}
-					if k == 2 {
+						continue
+					} else if k == 2 {
 						if !strings.Contains(text, "合同类型") {
 							resp.Fail("【合同类型】列名称有误, 请参考模板导入", c)
 							return
 						}
-					}
-					if k == 3 {
-						if text != "销售" {
-							resp.Fail("【销售】列名称有误, 请参考模板导入", c)
+						continue
+					} else if k == 3 {
+						if text != "FICC销售" {
+							resp.Fail("【FICC销售】列名称有误, 请参考模板导入", c)
 							return
 						}
-					}
-					if k == 4 {
+						continue
+					} else if k == 4 {
+						if text != "权益销售" {
+							resp.Fail("【权益销售】列名称有误, 请参考模板导入", c)
+							return
+						}
+						continue
+					} else if k == 5 {
 						if text != "FICC大套餐" {
 							resp.Fail("【FICC大套餐】列名称有误, 请参考模板导入", c)
 							return
 						}
+						continue
 					}
 				}
-			}
-			// 数据行
-			if i >= 2 {
+			}else if i >= 3 {
+				// 数据行
 				row := sheet.Row(i)
 				cells := row.Cells
 
@@ -1707,6 +1900,8 @@ func (rg *RegisterController) Import(c *gin.Context) {
 				rowRegister := new(fms.ContractRegister)
 				// 套餐
 				rowServices := make([]*fms.ContractService, 0)
+				// 套餐金额
+				rowServiceAmount := make([]*fms.ContractServiceAmount, 0)
 				// 开票/到款
 				rowInvoices := make([]*fms.ContractInvoice, 0)
 				for ir := 0; ir < invoiceMax; ir++ {
@@ -1719,6 +1914,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 				// 小套餐权限
 				rowChartPermissionIdArr := make([]string, 0)
 
+				productIds := make(map[int]struct{})
 				isSkip := false
 				for k, cell := range cells {
 					v := utils.TrimStr(cell.String())
@@ -1753,23 +1949,39 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						continue
 					}
-					// 销售
+					// FICC销售
 					if k == 3 {
-						if v == "" {
-							resp.Fail(fmt.Sprintf("第%d行销售名称不可为空, 请按模板导入", i+1), c)
+						if v != "" {
+							/*resp.Fail(fmt.Sprintf("第%d行销售名称不可为空, 请按模板导入", i+1), c)
+							return*/
+							sellerItem := sellerMap[v]
+							if sellerItem == nil {
+								resp.Fail(fmt.Sprintf("第%d行销售名称与系统销售不匹配, 请核对名称后导入", i+1), c)
+								return
+							}
+							rowRegister.SellerId = sellerItem.SellerId
+							rowRegister.SellerName = sellerItem.SellerName
+						}
+						continue
+					}
+
+					// 权益销售
+					if k == 4 {
+						if v == "" && rowRegister.SellerName == "" {
+							resp.Fail(fmt.Sprintf("第FICC销售名称和权益销售名称不可都为空, 请按模板导入", i+1), c)
 							return
 						}
 						sellerItem := sellerMap[v]
 						if sellerItem == nil {
-							resp.Fail(fmt.Sprintf("第%d行销售名称与系统销售不匹配, 请核对名称后导入", i+1), c)
+							resp.Fail(fmt.Sprintf("第%d行权益销售名称与系统销售不匹配, 请核对名称后导入", i+1), c)
 							return
 						}
-						rowRegister.SellerId = sellerItem.SellerId
-						rowRegister.SellerName = sellerItem.SellerName
+						rowRegister.RaiSellerId = sellerItem.SellerId
+						rowRegister.RaiSellerName = sellerItem.SellerName
 						continue
 					}
 					// FICC大套餐
-					if k == 4 {
+					if k == 5 {
 						if v == "是" {
 							tempItem := serviceTempNameMap[titleMap[k]]
 							if tempItem == nil {
@@ -1786,19 +1998,21 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							}
 							cs.Set()
 							rowServices = append(rowServices, cs)
+							productIds[crm.CompanyProductFicc] = struct{}{}
 						}
 						continue
 					}
 					// FICC小套餐
-					if k >= 5 && k <= 25 {
+					if k >= 6 && k <= 26 {
 						// 小套餐权限
 						if v == "是" {
 							rowChartPermissionIdArr = append(rowChartPermissionIdArr, strconv.Itoa(chartPermissionNameIdMap[titleMap[k]]))
+							productIds[crm.CompanyProductFicc] = struct{}{}
 						}
 						continue
 					}
 					// 其他类型套餐
-					if k >= 26 && k <= 32 {
+					if k >= 27 && k <= 33 {
 						if v == "是" {
 							tempItem := serviceTempNameMap[titleMap[k]]
 							if tempItem == nil {
@@ -1815,16 +2029,135 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							}
 							cs.Set()
 							rowServices = append(rowServices, cs)
+							productIds[crm.CompanyProductFicc] = struct{}{}
+						}
+						continue
+					}
+					// todo 权益行业套餐
+					if k >=34 && k<=44 {
+						if v == "是" {
+							// 权益大套餐
+							if k <= 35 {
+								//新增
+								parentName := "权益大套餐"
+								tempItem := serviceTempNameMap[titleMap[k]]
+								if tempItem == nil {
+									resp.Fail(fmt.Sprintf("第%d行套餐名称不匹配, 请按模板导入", i+1), c)
+									return
+								}
+								cs := &fms.ContractService{
+									ProductId:         crm.CompanyProductFicc,
+									ServiceTemplateId: tempItem.ServiceTemplateId,
+									Title:             tempItem.Title,
+									Value:             tempItem.Value,
+									TableValue:        tempItem.TableValue,
+									ChartPermissionId: tempItem.ChartPermissionId,
+								}
+								rowServices = append(rowServices, cs)
+
+								tempItem = serviceTempNameMap[parentName]
+								if tempItem == nil {
+									resp.Fail(fmt.Sprintf("第%d行套餐名称不匹配, 请按模板导入", i+1), c)
+									return
+								}
+								cs = &fms.ContractService{
+									ProductId:         crm.CompanyProductRai,
+									ServiceTemplateId: tempItem.ServiceTemplateId,
+									Title:             tempItem.Title,
+									Value:             tempItem.Value,
+									TableValue:        tempItem.TableValue,
+									ChartPermissionId: tempItem.ChartPermissionId,
+								}
+								rowServices = append(rowServices, cs)
+							} else {
+								rootName := "行业套餐"
+								// 新增三条套餐信息
+								parentName, _ := raiIndustryMap[k]
+								childName := titleMap[k]
+								fullName := childName+"_"+parentName+"_"+rootName
+								if fullName != "" {
+									//增加三级权限
+									tempItem := serviceTempFullNameMap[fullName]
+									if tempItem == nil {
+										resp.Fail(fmt.Sprintf("第%d行套餐名称不匹配, 请按模板导入", i+1), c)
+										return
+									}
+									cs := &fms.ContractService{
+										ProductId:         crm.CompanyProductRai,
+										ServiceTemplateId: tempItem.ServiceTemplateId,
+										Title:             tempItem.Title,
+										Value:             tempItem.Value,
+										TableValue:        tempItem.TableValue,
+										ChartPermissionId: tempItem.ChartPermissionId,
+									}
+									rowServices = append(rowServices, cs)
+
+									//增加二级权限
+									tempItem = serviceTempFullNameMap[parentName+"_"+rootName]
+									if tempItem == nil {
+										resp.Fail(fmt.Sprintf("第%d行套餐名称不匹配, 请按模板导入", i+1), c)
+										return
+									}
+									cs = &fms.ContractService{
+										ProductId:         crm.CompanyProductRai,
+										ServiceTemplateId: tempItem.ServiceTemplateId,
+										Title:             tempItem.Title,
+										Value:             tempItem.Value,
+										TableValue:        tempItem.TableValue,
+										ChartPermissionId: tempItem.ChartPermissionId,
+									}
+									rowServices = append(rowServices, cs)
+
+									//增加一级权限
+									tempItem = serviceTempFullNameMap[rootName]
+									if tempItem == nil {
+										resp.Fail(fmt.Sprintf("第%d行套餐名称不匹配, 请按模板导入", i+1), c)
+										return
+									}
+									cs = &fms.ContractService{
+										ProductId:         crm.CompanyProductRai,
+										ServiceTemplateId: tempItem.ServiceTemplateId,
+										Title:             tempItem.Title,
+										Value:             tempItem.Value,
+										TableValue:        tempItem.TableValue,
+										ChartPermissionId: tempItem.ChartPermissionId,
+									}
+									rowServices = append(rowServices, cs)
+								}
+							}
+							productIds[crm.CompanyProductRai] = struct{}{}
+						}
+						continue
+					}
+					// 权益研选等套餐
+					if k >= 45 && k<=49 {
+						if v == "是" {
+							tempItem := serviceTempNameMap[titleMap[k]]
+							if tempItem == nil {
+								resp.Fail(fmt.Sprintf("第%d行套餐名称不匹配, 请按模板导入", i+1), c)
+								return
+							}
+							cs := &fms.ContractService{
+								ProductId:         crm.CompanyProductRai,
+								ServiceTemplateId: tempItem.ServiceTemplateId,
+								Title:             tempItem.Title,
+								Value:             tempItem.Value,
+								TableValue:        tempItem.TableValue,
+								ChartPermissionId: tempItem.ChartPermissionId,
+							}
+							cs.Set()
+							rowServices = append(rowServices, cs)
+							productIds[crm.CompanyProductRai] = struct{}{}
 						}
 						continue
 					}
 					// 套餐备注
-					if k == 33 {
+					if k == 50 {
 						rowRegister.ServiceRemark = v
 						continue
 					}
 					// 开始时间/到期时间
-					if k == 34 {
+					if k == 51 {
 						// 转换失败可能是因为格式为Excel日期格式, 读取出来会是一串数字, 将其转换成日期字符串再处理
 						va := cell.Value
 						if va == "" {
@@ -1848,7 +2181,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						rowRegister.StartDate = startDate
 						continue
 					}
-					if k == 35 {
+					if k == 52 {
 						va := cell.Value
 						if va == "" {
 							resp.Fail(fmt.Sprintf("第%d行到期时间不可为空, 请按模板导入", i+1), c)
@@ -1871,7 +2204,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合同金额
-					if k == 36 {
+					if k == 53 {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
@@ -1882,7 +2215,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 金额单位
-					if k == 37 {
+					if k == 54 {
 						rate := rateMap[v]
 						if rate <= 0 {
 							resp.Fail(fmt.Sprintf("第%d行金额单位有误, 请按模板导入", i+1), c)
@@ -1892,13 +2225,51 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						rowRegister.RMBRate = rate
 						continue
 					}
+					// todo FICC套餐总金额
+					if k == 55 {
+						amountStr := v
+						amount, e := strconv.ParseFloat(amountStr, 64)
+						if e != nil {
+							resp.Fail(fmt.Sprintf("第%d行FICC套餐总金额有误, 请按模板导入", i+1), c)
+							return
+						}
+						if amount > 0 {
+							tmp := &fms.ContractServiceAmount{
+								ProductId:          crm.CompanyProductFicc,
+								ServiceAmount:      amount,
+								CurrencyUnit:       rowRegister.CurrencyUnit,
+								TimeBase:           base.TimeBase{},
+							}
+							rowServiceAmount = append(rowServiceAmount, tmp)
+						}
+						continue
+					}
+					// todo 权益套餐总金额
+					if k == 56 {
+						amountStr := v
+						amount, e := strconv.ParseFloat(amountStr, 64)
+						if e != nil {
+							resp.Fail(fmt.Sprintf("第%d行权益套餐总金额有误, 请按模板导入", i+1), c)
+							return
+						}
+						if amount > 0 {
+							tmp := &fms.ContractServiceAmount{
+								ProductId:          crm.CompanyProductRai,
+								ServiceAmount:      amount,
+								CurrencyUnit:       rowRegister.CurrencyUnit,
+								TimeBase:           base.TimeBase{},
+							}
+							rowServiceAmount = append(rowServiceAmount, tmp)
+						}
+						continue
+					}
 					// 约定付款日期
-					if k == 38 {
+					if k == 57 {
 						rowRegister.AgreedPayTime = v
 						continue
 					}
 					// 签订日
-					if k == 39 {
+					if k == 58 {
 						va := cell.Value
 						if va == "" {
 							continue
@@ -1920,7 +2291,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合同状态
-					if k == 40 {
+					if k == 59 {
 						rowRegister.ContractStatus = fms.ContractStatusNameKeyMap[v]
 						if rowRegister.ContractStatus == 0 {
 							resp.Fail(fmt.Sprintf("第%d行合同状态不匹配, 请按模板导入", i+1), c)
@@ -1929,7 +2300,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合同编号
-					if k == 41 {
+					if k == 60 {
 						rowContractCode := v
 						if rowContractCode == "" {
 							resp.Fail(fmt.Sprintf("第%d行合同编号不可为空, 请按模板导入", i+1), c)
@@ -1944,12 +2315,12 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合规备注
-					if k == 42 {
+					if k == 61 {
 						rowRegister.Remark = v
 						continue
 					}
 					// 开票列表
-					k2 := 42
+					k2 := 62
 					for ir := 0; ir < invoiceMax; ir++ {
 						n := ir + 1
 						// 开票日
@@ -1996,6 +2367,13 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							}
 							continue
 						}
+						// todo 开票套餐类型
+						k2 += 1
+						if k == k2 {
+							if v != "" {
+							}
+							continue
+						}
 						// 开票销售
 						k2 += 1
 						if k == k2 {
@@ -2075,6 +2453,16 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							}
 							continue
 						}
+
+						// todo 到款套餐类型
+						k2 += 1
+						if k == k2 {
+							if v != "" {
+
+							}
+							continue
+						}
+
 						// 备注
 						k2 += 1
 						if k == k2 {
@@ -2140,7 +2528,11 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					}
 				}
 				// 新增登记、套餐、开票到款信息
-				newId, e := fms.CreateImportContractRegister(rowRegister, rowServices, rowInvoiceList)
+				for proId, _ := range productIds  {
+					rowRegister.ProductIds += strconv.Itoa(proId)+","
+				}
+				rowRegister.ProductIds = strings.Trim(rowRegister.ProductIds, ",")
+				newId, e := fms.CreateImportContractRegister(rowRegister, rowServices, rowInvoiceList, rowServiceAmount)
 				if e != nil {
 					resp.FailData(fmt.Sprintf("第%d行导入失败", i+1), "新增导入登记失败, Err: "+e.Error(), c)
 					return

+ 0 - 1
controller/contract/service.go

@@ -47,7 +47,6 @@ func (sr *ServiceController) List(c *gin.Context) {
 	}
 	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)

+ 2 - 50
controller/crm/company_seller.go

@@ -2,9 +2,7 @@ package crm
 
 import (
 	"github.com/gin-gonic/gin"
-	"github.com/go-playground/validator/v10"
 	"hongze/fms_api/controller/resp"
-	"hongze/fms_api/global"
 	"hongze/fms_api/models/crm"
 	crmService "hongze/fms_api/services/crm"
 )
@@ -15,61 +13,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)
 }
 

+ 18 - 0
models/crm/company_seller.go

@@ -36,3 +36,21 @@ type SellerAdminWithGroupTeam struct {
 	TeamId     int    `json:"team_id" description:"小组ID"`
 	TeamName   string `json:"team_name" description:"小组名称"`
 }
+
+// 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系统合同类型

+ 9 - 9
models/fms/contract_invoice.go

@@ -256,15 +256,15 @@ 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:"结束日期"`
-	TimeType    int    `json:"time_type" form:"time_type" description:"时间类型: 1-开票时间; 2-到款时间"`
-	HasInvoice  int    `json:"has_invoice" form:"has_invoice" description:"是否已开票: 0-否; 1-是"`
-	HasPayment  int    `json:"has_payment" form:"has_payment" description:"是否已到款: 0-否; 1-是"`
-	IsExport    int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
+	Keyword      string `json:"keyword" form:"keyword" binding:"omitempty" description:"关键词"`
+	SellGroupId  int    `json:"sell_group_id" form:"sell_group_id" description:"销售组别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:"结束日期"`
+	TimeType     int    `json:"time_type" form:"time_type" description:"时间类型: 1-开票时间; 2-到款时间"`
+	HasInvoice   int    `json:"has_invoice" form:"has_invoice" description:"是否已开票: 0-否; 1-是"`
+	HasPayment   int    `json:"has_payment" form:"has_payment" description:"是否已到款: 0-否; 1-是"`
+	IsExport     int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
 	base.PageReq
 }
 

+ 83 - 31
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" binding:"required" description:"CRM系统-权益销售ID"`
+	RaiSellerName      string    `gorm:"column:rai_seller_name" json:"rai_seller_name" binding:"required" 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
@@ -155,28 +157,31 @@ 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" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回; 4-已终止"`
-	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-是"`
-	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:"实际使用方"`
+	SellerId           int                           `json:"seller_id" binding:"required" description:"CRM系统-销售ID"`
+	SellerName         string                        `json:"seller_name" binding:"required" description:"CRM系统-销售名称"`
+	RaiSellerId        int                           `json:"rai_seller_id" binding:"required" description:"CRM系统-权益销售ID"`
+	RaiSellerName      string                        `json:"rai_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" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回; 4-已终止"`
+	Remark             string                        `json:"remark" description:"备注信息"`
+	ServiceRemark      string                        `json:"service_remark" description:"套餐备注"`
+	ProductIds         string                        `json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
+	HasPayment         int                           `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
+	NewCompany         int                           `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
+	Services           []ContractServiceAddReq       `json:"services" description:"服务套餐内容"`
+	ServiceAmount      []ContractServiceAmountAddReq `json:"service_amount" description:"服务套餐金额"`
 }
 
 // ContractRegisterEditReq 编辑合同登记请求体
@@ -186,7 +191,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 {
@@ -205,7 +210,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,
@@ -213,6 +218,7 @@ func CreateContractRegisterAndServices(item *ContractRegister, serviceDetail []*
 			HasDetail:          t.HasDetail,
 			ChartPermissionId:  t.ChartPermissionId,
 			ChartPermissionIds: t.ChartPermissionIds,
+			ServiceAmount:      t.ServiceAmount,
 		}
 		contractService.Set()
 		tx.Create(contractService)
@@ -228,12 +234,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 {
@@ -254,6 +272,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()
@@ -262,7 +283,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,
@@ -286,6 +307,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 = ?`
@@ -385,7 +418,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 {
@@ -404,10 +437,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
 		}

+ 15 - 12
models/fms/contract_service.go

@@ -7,16 +7,18 @@ 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:"是否有详情: 无; 有"`
+	ServiceAmount      float64 `gorm:"column:service_amount" json:"service_amount" description:"套餐总金额"`
+	CurrencyUnit       string  `gorm:"column:currency_unit" json:"currency_unit" 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
 }
 
@@ -67,6 +69,7 @@ type ContractServiceAndDetail struct {
 	TableValue         string `json:"table_value" description:"表格数据,用于word生成时的json数据"`
 	ChartPermissionId  int    `json:"chart_permission_id" description:"权限id"`
 	ChartPermissionIds string `json:"chart_permission_ids" description:"品种权限-小套餐"`
+	ServiceAmount      float64 `gorm:"column:service_amount" json:"service_amount" description:"套餐总金额"`
 	//Detail             []*ContractServiceDetail `json:"detail"`
 }
 
@@ -104,10 +107,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
 }

+ 46 - 0
models/fms/contract_service_amount.go

@@ -0,0 +1,46 @@
+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
+}
+
+// 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
+}
+
+

+ 1 - 1
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:"对应的数据"`

+ 117 - 4
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 {
@@ -87,3 +88,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
+}

+ 24 - 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"
@@ -77,111 +78,16 @@ 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("请至少选择一种套餐")
 		return
 	}
+	// todo 如果权益套餐中只有行业套餐,需要均分套餐金额,否则无需均分
 	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,26 @@ 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
+		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)