Browse Source

Merge remote-tracking branch 'origin/needs/payment_company_20230215' into fms_2.5

# Conflicts:
#	controller/contract/register.go
#	controller/crm/contract.go
#	models/crm/contract.go
#	models/fms/contract_register.go
ziwen 2 years ago
parent
commit
df5ac0c413

+ 3 - 1
controller/contract/register.go

@@ -344,6 +344,7 @@ func (rg *RegisterController) Add(c *gin.Context) {
 	ob.Remark = req.Remark
 	ob.ServiceRemark = req.ServiceRemark
 	ob.HasPayment = req.HasPayment
+	ob.ActualPayCompanies = req.ActualPayCompanies
 	ob.Set()
 	updateCols := []string{
 		"ContractCode", "RelateContractCode", "RelateContractMainCode", "CrmContractId", "ContractSource",
@@ -655,7 +656,7 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	updateCols := []string{
 		"ProductIds", "ContractCode", "RelateContractCode", "CrmContractId", "ContractSource", "CompanyName",
 		"SellerId", "SellerName", "ContractType", "ContractAmount", "StartDate", "EndDate", "SignDate", "AgreedPayTime", "RaiSellerId", "RaiSellerName",
-		"ContractStatus", "RegisterStatus", "Remark", "ServiceRemark", "HasPayment", "ModifyTime",
+		"ContractStatus", "RegisterStatus", "Remark", "ServiceRemark", "ActualPayCompanies", "HasPayment", "ModifyTime",
 	}
 	nowTime := time.Now().Local()
 	item.ProductIds = req.ProductIds
@@ -680,6 +681,7 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	item.Remark = req.Remark
 	item.ServiceRemark = req.ServiceRemark
 	item.HasPayment = req.HasPayment
+	item.ActualPayCompanies = req.ActualPayCompanies
 	item.ModifyTime = nowTime
 
 	// 不需要开票到款的直接完成登记, 且不允许进行开票/到款登记

+ 24 - 5
controller/crm/contract.go

@@ -60,21 +60,24 @@ func (rg *ContractController) SearchList(c *gin.Context) {
 	}
 
 	// 获取代付合同实际使用方
-	peyContractIds := make([]int, 0)
+	businessContractIds := make([]int, 0)
+	payContractIds := make([]int, 0)
 	for i := range list {
 		if list[i].ContractBusinessType == crm.ContractTypePayment {
-			peyContractIds = append(peyContractIds, list[i].ContractId)
+			payContractIds = append(payContractIds, list[i].ContractId)
+		} else {
+			businessContractIds = append(businessContractIds, list[i].ContractId)
 		}
 	}
 	payCompanyMap := make(map[int]string, 0)      // 代付合同实际使用方
 	payContractCodeMap := make(map[int]string, 0) // 代付合同实际使用方合同编号
-	if len(peyContractIds) > 0 {
+	if len(payContractIds) > 0 {
 		payCond := `a.status IN ('已签回', '已审批') AND b.payment_on_behalf_contract_id IN ?`
 		payPars := make([]interface{}, 0)
-		payPars = append(payPars, peyContractIds)
+		payPars = append(payPars, payContractIds)
 		payList, e := crm.GetPayCompanyByContractIds(payCond, payPars)
 		if e != nil {
-			resp.FailMsg("获取失败", "获取代付合同信息失败, Err: "+e.Error(), c)
+			resp.FailMsg("获取失败", "获取代付合同实际使用方信息失败, Err: "+e.Error(), c)
 			return
 		}
 		for i := range payList {
@@ -82,6 +85,21 @@ func (rg *ContractController) SearchList(c *gin.Context) {
 			payContractCodeMap[payList[i].PaymentOnBehalfContractId] = payList[i].ContractCode
 		}
 	}
+	// 获取业务合同的所有代付方信息
+	businessPayMap := make(map[int]string, 0)
+	if len(businessContractIds) > 0 {
+		businessCond := `b.status IN ('已签回', '已审批') AND a.contract_id IN ?`
+		businessPars := make([]interface{}, 0)
+		businessPars = append(businessPars, businessContractIds)
+		businessPayCompanies, e := crm.GetContractActualPayCompaniesByContractIds(businessCond, businessPars)
+		if e != nil {
+			resp.FailMsg("获取失败", "获取业务合同代付方信息失败, Err: "+e.Error(), c)
+			return
+		}
+		for i := range businessPayCompanies {
+			businessPayMap[businessPayCompanies[i].ContractId] = businessPayCompanies[i].ActualPayCompanies
+		}
+	}
 
 	respList := make([]*crm.ContractSearchListResp, 0)
 	for i := range list {
@@ -107,6 +125,7 @@ func (rg *ContractController) SearchList(c *gin.Context) {
 			Price:                   list[i].Price,
 			StartDate:               utils.TimeTransferString(utils.FormatDate, list[i].StartDate),
 			EndDate:                 utils.TimeTransferString(utils.FormatDate, list[i].EndDate),
+			ActualPayCompanies: businessPayMap[list[i].ContractId],
 		}
 		if list[i].ContractBusinessType == crm.ContractTypePayment {
 			respItem.ContractBusinessTypeInt = 2

+ 22 - 1
models/crm/contract.go

@@ -93,6 +93,7 @@ type ContractSearchListResp struct {
 	Price           float64 `json:"price" description:"合同金额"`
 	StartDate       string  `json:"start_date" description:"合同开始日期"`
 	EndDate         string  `json:"end_date" description:"合同结束日期"`
+	ActualPayCompanies string  `json:"actual_pay_companies" description:"该合同关联的所有代付方, 英文逗号拼接"`
 }
 
 // PayCompanyRelation 代付合同
@@ -103,7 +104,7 @@ type PayCompanyRelation struct {
 	PaymentOnBehalfContractId int    `description:"实际使用方合同ID"`
 }
 
-// GetPayCompanyByContractIds 通过合同IDs获取代付客户信息
+// GetPayCompanyByContractIds 通过代付合同IDs获取关联客户信息
 func GetPayCompanyByContractIds(condition string, pars []interface{}) (results []*PayCompanyRelation, err error) {
 	results = make([]*PayCompanyRelation, 0)
 	query := global.MYSQL["report"].
@@ -116,6 +117,26 @@ func GetPayCompanyByContractIds(condition string, pars []interface{}) (results [
 	return
 }
 
+// ContractActualPayCompanies 代付合同信息
+type ContractActualPayCompanies struct {
+	ContractId         int    `json:"contract_id" description:"业务合同ID"`
+	ActualPayCompanies string `json:"actual_pay_companies" description:"关联的代付方名称, 英文逗号拼接"`
+}
+
+// GetContractActualPayCompaniesByContractIds 通过合同IDs获取代付客户信息
+func GetContractActualPayCompaniesByContractIds(condition string, pars []interface{}) (results []*ContractActualPayCompanies, err error) {
+	results = make([]*ContractActualPayCompanies, 0)
+	query := global.MYSQL["report"].
+		Table("contract_relation AS a").
+		Select("a.contract_id, GROUP_CONCAT(DISTINCT b.company_name) AS actual_pay_companies").
+		Joins("JOIN contract AS b ON a.payment_on_behalf_contract_id = b.contract_id").
+		Where("b.is_delete = 0").
+		Where(condition, pars...).
+		Group("a.contract_id")
+	err = query.Find(&results).Error
+	return
+}
+
 // ContractDetail 合同详情信息(包含服务信息等)
 type ContractDetail struct {
 	Contract

+ 5 - 1
models/fms/contract_register.go

@@ -39,6 +39,7 @@ type ContractRegister struct {
 	HasPayment             int       `gorm:"column:has_payment" json:"has_payment" description:"是否有代付: 0-无; 1-有"`
 	NewCompany             int       `gorm:"column:new_company" json:"new_company" description:"是否为新客户: 0-否; 1-是"`
 	IsDeleted              int       `gorm:"column:is_deleted" json:"is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
+	ActualPayCompanies string    `gorm:"column:actual_pay_companies" json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
 	base.TimeBase
 }
 
@@ -139,6 +140,7 @@ type ContractRegisterItem struct {
 	ServiceRemark      string  `json:"service_remark" description:"套餐备注信息"`
 	HasPayment         int     `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
 	NewCompany         int     `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
+	ActualPayCompanies string  `json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
 	CreateTime         string  `json:"create_time" description:"登记时间"`
 	SellerIds          string  `json:"seller_ids"`
 }
@@ -189,6 +191,7 @@ type ContractRegisterAddReq struct {
 	ContractRegisterId     int                           `json:"contract_register_id" description:"登记ID"`
 	Services               []ContractServiceAddReq       `json:"services" description:"服务套餐内容"`
 	ServiceAmount          []ContractServiceAmountAddReq `json:"service_amount" description:"服务套餐金额"`
+	ActualPayCompanies string                  `json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
 }
 
 // ContractRegisterEditReq 编辑合同登记请求体
@@ -348,7 +351,7 @@ type ContractRegisterDetailReq struct {
 	ContractRegisterId int `json:"contract_register_id" form:"contract_register_id" binding:"required,gte=1"`
 }
 
-// ContractRegisterDetail-合同登记详情
+// ContractRegisterDetail 合同登记详情
 type ContractRegisterDetail struct {
 	*ContractRegisterItem
 	ServiceList       []*ContractServiceAndDetail  `json:"service_list" description:"合同服务及详情"`
@@ -423,6 +426,7 @@ func formatContractRegister2Item(item *ContractRegister) (formatItem *ContractRe
 	formatItem.ServiceRemark = item.ServiceRemark
 	formatItem.HasPayment = item.HasPayment
 	formatItem.NewCompany = item.NewCompany
+	formatItem.ActualPayCompanies = item.ActualPayCompanies
 	formatItem.CreateTime = utils.TimeTransferString(utils.FormatDateTime, item.CreateTime)
 	return
 }