ziwen 2 years ago
parent
commit
380c82908d
1 changed files with 81 additions and 78 deletions
  1. 81 78
      controller/contract/register.go

+ 81 - 78
controller/contract/register.go

@@ -234,9 +234,9 @@ func (rg *RegisterController) Add(c *gin.Context) {
 
 	// 查询销售信息
 	var (
-		sellerId int
-		raiSellerId int
-		sellerName string
+		sellerId      int
+		raiSellerId   int
+		sellerName    string
 		raiSellerName string
 	)
 
@@ -259,7 +259,7 @@ func (rg *RegisterController) Add(c *gin.Context) {
 			if v.DepartmentId == crm.SellerDepartmentId {
 				sellerId = v.AdminId
 				sellerName = v.AdminName
-			}else if v.DepartmentId == crm.RaiSellerDepartmentId {
+			} else if v.DepartmentId == crm.RaiSellerDepartmentId {
 				raiSellerId = v.AdminId
 				raiSellerName = v.AdminName
 			}
@@ -320,8 +320,8 @@ func (rg *RegisterController) Add(c *gin.Context) {
 	for _, v := range serviceAmountList {
 		productIds[v.ProductId] = struct{}{}
 	}
-	for proId, _ := range productIds  {
-		productIdsStr += strconv.Itoa(proId)+","
+	for proId, _ := range productIds {
+		productIdsStr += strconv.Itoa(proId) + ","
 	}
 	productIdsStr = strings.Trim(productIdsStr, ",")
 	ob.ProductIds = productIdsStr
@@ -520,9 +520,9 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 
 	// 查询销售信息
 	var (
-		sellerId int
-		raiSellerId int
-		sellerName string
+		sellerId      int
+		raiSellerId   int
+		sellerName    string
 		raiSellerName string
 	)
 
@@ -545,7 +545,7 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 			if v.DepartmentId == crm.SellerDepartmentId {
 				sellerId = v.AdminId
 				sellerName = v.AdminName
-			}else if v.DepartmentId == crm.RaiSellerDepartmentId {
+			} else if v.DepartmentId == crm.RaiSellerDepartmentId {
 				raiSellerId = v.AdminId
 				raiSellerName = v.AdminName
 			}
@@ -568,7 +568,7 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	originHasPayment := item.HasPayment
 
 	updateCols := []string{
-		"ProductIds","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",
 	}
@@ -670,8 +670,8 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	for _, v := range serviceAmountList {
 		productIds[v.ProductId] = struct{}{}
 	}
-	for proId, _ := range productIds  {
-		productIdsStr += strconv.Itoa(proId)+","
+	for proId, _ := range productIds {
+		productIdsStr += strconv.Itoa(proId) + ","
 	}
 	productIdsStr = strings.Trim(productIdsStr, ",")
 	item.ProductIds = productIdsStr
@@ -824,7 +824,7 @@ func (rg *RegisterController) Detail(c *gin.Context) {
 
 	item.SellerIds = strconv.Itoa(item.SellerId)
 	if item.RaiSellerId != 0 {
-		item.SellerIds += ","+strconv.Itoa(item.RaiSellerId)
+		item.SellerIds += "," + strconv.Itoa(item.RaiSellerId)
 	}
 	item.SellerIds = strings.Trim(item.SellerIds, ",")
 	result.ContractRegisterItem = item
@@ -1020,7 +1020,7 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
 				resp.Fail("请选择日期", c)
 				return
 			}
-			if req.AmountList[i].ServiceProductId != 1 &&  req.AmountList[i].ServiceProductId !=2 {
+			if req.AmountList[i].ServiceProductId != 1 && req.AmountList[i].ServiceProductId != 2 {
 				resp.Fail("请选择套餐类型", c)
 				return
 			}
@@ -1280,7 +1280,6 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	}
 	otherServiceLen := len(otherService)
 
-
 	// 获取所有权益套餐服务
 	raiServiceList, e := fms.GetContractServiceTemplateAllByProductId(crm.CompanyProductRai)
 	if e != nil {
@@ -1299,7 +1298,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		if v.Pid > 0 && raiServiceIdMap[v.Pid].Pid > 0 {
 			raiServiceNotShowMap[v.Pid] = struct{}{}
 			raiServiceNotShowMap[raiServiceIdMap[v.Pid].Pid] = struct{}{}
-		}else if v.Pid > 0 {
+		} else if v.Pid > 0 {
 			raiServiceNotShowMap[v.Pid] = struct{}{}
 		}
 	}
@@ -1403,8 +1402,8 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	}
 
 	serviceProductIdMap := map[int]string{
-		1:"FICC套餐",
-		2:"权益套餐",
+		1: "FICC套餐",
+		2: "权益套餐",
 	}
 	// 生成Excel文件
 	xlsxFile := xlsx.NewFile()
@@ -1446,11 +1445,11 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	cell2.VMerge = 1
 	cell2.SetString("FICC大套餐")
 	cell2.SetStyle(style)
-	hInt ++
+	hInt++
 	// 1行3列-右合并小套餐数
 	if permissionLen >= 1 {
 		cell3 := titleRow.AddCell()
-		hInt ++
+		hInt++
 		cell3.HMerge = permissionLen - 1
 		cell3.VMerge = 1
 		cell3.SetString("FICC小套餐")
@@ -1458,13 +1457,13 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		// 同上右增单元格小套餐数-1的空白单元格用于合并
 		for i := 0; i < permissionLen-1; i++ {
 			titleRow.AddCell().SetString("")
-			hInt ++
+			hInt++
 		}
 	}
 	for i := range otherService {
 		cellOther := titleRow.AddCell()
 		cellOther.VMerge = 1
-		hInt ++
+		hInt++
 		cellOther.SetString(otherService[i].Title)
 		cellOther.SetStyle(style)
 	}
@@ -1476,7 +1475,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	cell4.SetString("权益大套餐")
 	cell4.SetStyle(style)
 	titleRow.AddCell().SetString("")
-	hInt +=2
+	hInt += 2
 
 	//权益分行业套餐
 	cell5 := titleRow.AddCell()
@@ -1495,7 +1494,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	//第二行,前面几个单元格用于第一行的合并
 	titleRow2 := sheet.AddRow()
 	titleRow2.SetHeight(30)
-	for i:= 0; i<hInt;i++ {
+	for i := 0; i < hInt; i++ {
 		titleRow2.AddCell().SetString("")
 	}
 	//权益分行业套餐
@@ -1542,7 +1541,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		row3Title = append(row3Title, otherService[i].Title)
 	}
 	// 定义二级套餐名称
-	for i:= range row3Title {
+	for i := range row3Title {
 		row3TitleParent = append(row3TitleParent, row3Title[i])
 	}
 	// 权益三级套餐
@@ -1550,7 +1549,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		row3Title = append(row3Title, raiOtherService[i].Title)
 		if raiOtherService[i].ParentTitle != "" {
 			row3TitleParent = append(row3TitleParent, raiOtherService[i].ParentTitle)
-		}else{
+		} else {
 			row3TitleParent = append(row3TitleParent, raiOtherService[i].Title)
 		}
 	}
@@ -1654,7 +1653,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 								otherCol = "是"
 								break
 							}
-						}else{
+						} else {
 							otherCol = "是"
 							break
 						}
@@ -1672,13 +1671,17 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		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])      // 合同状态
-		dataRow.AddCell().SetString(v.ContractCode)                                      // 合同编号
-		dataRow.AddCell().SetString(v.Remark)                                            // 合规备注
+		if ficcAmount != nil {
+			dataRow.AddCell().SetString(fmt.Sprint("¥", ficcAmount.ServiceAmount)) // FICC套餐总金额
+		}
+		if raiAmount != nil {
+			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])     // 合同状态
+		dataRow.AddCell().SetString(v.ContractCode)                                     // 合同编号
+		dataRow.AddCell().SetString(v.Remark)                                           // 合规备注
 
 		// 开票/到款信息
 		ivList := invoiceMap[v.ContractRegisterId]
@@ -1688,7 +1691,7 @@ 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))                            // 开票金额
-					dataRow.AddCell().SetString(serviceProductIdMap[ivList[ia].ServiceProductId])             // 套餐类型
+					dataRow.AddCell().SetString(serviceProductIdMap[ivList[ia].ServiceProductId])               // 套餐类型
 					dataRow.AddCell().SetString(ivList[ia].SellerName)                                          // 销售名称
 					dataRow.AddCell().SetString(ivList[ia].Remark)                                              // 开票备注
 					continue
@@ -1708,7 +1711,7 @@ 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))                            // 收款金额
-					dataRow.AddCell().SetString(serviceProductIdMap[pyList[ib].ServiceProductId])            // 套餐类型
+					dataRow.AddCell().SetString(serviceProductIdMap[pyList[ib].ServiceProductId])               // 套餐类型
 					dataRow.AddCell().SetString(pyList[ib].Remark)                                              // 收款备注
 					continue
 				}
@@ -1955,20 +1958,20 @@ func ExportInvoiceList(c *gin.Context, req fms.ContractInvoiceListReq, results *
 	}
 	ServiceTemplateStrMap := map[int]string{
 		crm.CompanyProductFicc: "FICC套餐",
-		crm.CompanyProductRai: "权益套餐",
+		crm.CompanyProductRai:  "权益套餐",
 	}
 	// 单元格赋值
 	for _, v := range list {
 		dataRow := sheet.AddRow()
 		dataRow.SetHeight(20)
-		dataRow.AddCell().SetString(v.ContractCode)             // 合同编号
+		dataRow.AddCell().SetString(v.ContractCode)                            // 合同编号
 		dataRow.AddCell().SetString(ServiceTemplateStrMap[v.ServiceProductId]) // 套餐类型
-		dataRow.AddCell().SetString(fmt.Sprint(v.OriginAmount)) // 开票金额
-		dataRow.AddCell().SetString(v.UnitName)                 // 金额单位
-		dataRow.AddCell().SetString(fmt.Sprint(v.Amount))       // 换算金额(元)
-		dataRow.AddCell().SetString(v.InvoiceDate)              // 开票日
-		dataRow.AddCell().SetString(v.SellerName)               // 销售
-		dataRow.AddCell().SetString(v.Remark)                   // 备注
+		dataRow.AddCell().SetString(fmt.Sprint(v.OriginAmount))                // 开票金额
+		dataRow.AddCell().SetString(v.UnitName)                                // 金额单位
+		dataRow.AddCell().SetString(fmt.Sprint(v.Amount))                      // 换算金额(元)
+		dataRow.AddCell().SetString(v.InvoiceDate)                             // 开票日
+		dataRow.AddCell().SetString(v.SellerName)                              // 销售
+		dataRow.AddCell().SetString(v.Remark)                                  // 备注
 	}
 
 	// 输出文件
@@ -2080,11 +2083,11 @@ func (rg *RegisterController) Import(c *gin.Context) {
 
 	for i := range serviceTempList {
 		fullName := serviceTempList[i].Title
-		if serviceTempList[i].Pid > 0  {
+		if serviceTempList[i].Pid > 0 {
 			parentItem := serviceTempIdMap[serviceTempList[i].Pid]
-			fullName += "_"+parentItem.Title
+			fullName += "_" + parentItem.Title
 			if parentItem.Pid > 0 {
-				fullName += "_"+serviceTempIdMap[parentItem.Pid].Title
+				fullName += "_" + serviceTempIdMap[parentItem.Pid].Title
 			}
 		}
 		serviceTempFullNameMap[fullName] = serviceTempList[i]
@@ -2092,15 +2095,15 @@ func (rg *RegisterController) Import(c *gin.Context) {
 
 	//权益行业套餐名称
 	raiIndustryMap := map[int]string{
-		36:"医药",
-		37:"医药",
-		38:"消费",
-		39:"消费",
-		40:"科技",
-		41:"科技",
-		42:"智造",
-		43:"智造",
-		44:"策略",
+		36: "医药",
+		37: "医药",
+		38: "消费",
+		39: "消费",
+		40: "科技",
+		41: "科技",
+		42: "智造",
+		43: "智造",
+		44: "策略",
 	}
 
 	// 获取货币列表及汇率(汇率为导入日的汇率)
@@ -2190,7 +2193,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 				}
-			}else if i >= 3 {
+			} else if i >= 3 {
 				// 数据行
 				row := sheet.Row(i)
 				cells := row.Cells
@@ -2332,7 +2335,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						continue
 					}
-					if k >=34 && k<=44 {
+					if k >= 34 && k <= 44 {
 						if v == "是" {
 							// 权益大套餐
 							if k <= 35 {
@@ -2372,7 +2375,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 								// 新增三条套餐信息
 								parentName, _ := raiIndustryMap[k]
 								childName := titleMap[k]
-								fullName := childName+"_"+parentName+"_"+rootName
+								fullName := childName + "_" + parentName + "_" + rootName
 								if fullName != "" {
 									//增加三级权限
 									tempItem := serviceTempFullNameMap[fullName]
@@ -2428,7 +2431,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 权益研选等套餐
-					if k >= 45 && k<=49 {
+					if k >= 45 && k <= 49 {
 						if v == "是" {
 							tempItem := serviceTempNameMap[titleMap[k]]
 							if tempItem == nil {
@@ -2533,10 +2536,10 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						if amount > 0 {
 							tmp := &fms.ContractServiceAmount{
-								ProductId:          crm.CompanyProductFicc,
-								ServiceAmount:      amount,
-								CurrencyUnit:       rowRegister.CurrencyUnit,
-								TimeBase:           base.TimeBase{},
+								ProductId:     crm.CompanyProductFicc,
+								ServiceAmount: amount,
+								CurrencyUnit:  rowRegister.CurrencyUnit,
+								TimeBase:      base.TimeBase{},
 							}
 							rowServiceAmount = append(rowServiceAmount, tmp)
 						}
@@ -2552,10 +2555,10 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						if amount > 0 {
 							tmp := &fms.ContractServiceAmount{
-								ProductId:          crm.CompanyProductRai,
-								ServiceAmount:      amount,
-								CurrencyUnit:       rowRegister.CurrencyUnit,
-								TimeBase:           base.TimeBase{},
+								ProductId:     crm.CompanyProductRai,
+								ServiceAmount: amount,
+								CurrencyUnit:  rowRegister.CurrencyUnit,
+								TimeBase:      base.TimeBase{},
 							}
 							rowServiceAmount = append(rowServiceAmount, tmp)
 						}
@@ -2671,9 +2674,9 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							if v != "" {
 								if v == "FICC套餐" {
 									rowInvoices[ir].ServiceProductId = crm.CompanyProductFicc
-								}else if v == "权益套餐"{
+								} else if v == "权益套餐" {
 									rowInvoices[ir].ServiceProductId = crm.CompanyProductRai
-								}else{
+								} else {
 									resp.Fail(fmt.Sprintf("第%d行开票套餐类型%d:%s有误, 请按模板导入", i+1, n, v), c)
 									return
 								}
@@ -2766,9 +2769,9 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							if v != "" {
 								if v == "FICC套餐" {
 									rowPayments[ir].ServiceProductId = crm.CompanyProductFicc
-								}else if v == "权益套餐"{
+								} else if v == "权益套餐" {
 									rowPayments[ir].ServiceProductId = crm.CompanyProductRai
-								}else{
+								} else {
 									resp.Fail(fmt.Sprintf("第%d行到款套餐类型%d:%s有误, 请按模板导入", i+1, n, v), c)
 									return
 								}
@@ -2841,8 +2844,8 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					}
 				}
 				// 新增登记、套餐、开票到款信息
-				for proId, _ := range productIds  {
-					rowRegister.ProductIds += strconv.Itoa(proId)+","
+				for proId, _ := range productIds {
+					rowRegister.ProductIds += strconv.Itoa(proId) + ","
 				}
 				rowRegister.ProductIds = strings.Trim(rowRegister.ProductIds, ",")
 				newId, e := fms.CreateImportContractRegister(rowRegister, rowServices, rowInvoiceList, rowServiceAmount)
@@ -2890,7 +2893,7 @@ func (rg *RegisterController) CheckContractName(c *gin.Context) {
 		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
 		return
 	}
-	existCond :=""
+	existCond := ""
 	existPars := make([]interface{}, 0)
 	if req.CompanyName != "" {
 		// 是否存在相同的合同名称的登记
@@ -2912,7 +2915,7 @@ func (rg *RegisterController) CheckContractName(c *gin.Context) {
 		}
 		if existCond != "" {
 			existCond += ` or (start_date =? and end_date=?)`
-		}else{
+		} else {
 			existCond = ` start_date = ? and end_date=?`
 		}
 
@@ -2940,4 +2943,4 @@ func (rg *RegisterController) CheckContractName(c *gin.Context) {
 	data.Exist = 1
 	resp.OkData("查询成功", data, c)
 	return
-}
+}