瀏覽代碼

业务合同代付方

hsun 2 年之前
父節點
當前提交
75ec20d3d0
共有 4 個文件被更改,包括 66 次插入23 次删除
  1. 2 1
      controller/contract/register.go
  2. 24 5
      controller/crm/contract.go
  3. 35 16
      models/crm/contract.go
  4. 5 1
      models/fms/contract_register.go

+ 2 - 1
controller/contract/register.go

@@ -372,7 +372,7 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	updateCols := []string{
 		"ContractCode", "RelateContractCode", "CrmContractId", "ContractSource", "CompanyName", "ActualCompanyName",
 		"SellerId", "SellerName", "ContractType", "ContractAmount", "StartDate", "EndDate", "SignDate", "AgreedPayTime",
-		"ContractStatus", "RegisterStatus", "Remark", "ServiceRemark", "HasPayment", "NewCompany", "ModifyTime",
+		"ContractStatus", "RegisterStatus", "Remark", "ServiceRemark", "HasPayment", "NewCompany", "ActualPayCompanies", "ModifyTime",
 	}
 	nowTime := time.Now().Local()
 	item.ContractCode = req.ContractCode
@@ -395,6 +395,7 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	item.ServiceRemark = req.ServiceRemark
 	item.HasPayment = req.HasPayment
 	item.NewCompany = req.NewCompany
+	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 {
@@ -106,6 +124,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],
 		})
 	}
 

+ 35 - 16
models/crm/contract.go

@@ -76,21 +76,20 @@ type ContractSearchListReq struct {
 
 // ContractSearchListResp CRM系统合同-搜索列表响应体
 type ContractSearchListResp struct {
-	ContractId      int     `json:"contract_id" description:"合同ID"`
-	ContractCode    string  `json:"contract_code" description:"合同编号"`
-	ProductId       int     `json:"product_id" description:"产品ID"`
-	CompanyName     string  `json:"company_name" description:"客户名称"`
-	//PayContractCode string  `json:"pay_contract_code" description:"代付合同编号"`
-	RelateContractCode string `json:"relate_contract_code" description:"代付合同关联的实际使用方合同编号"`
-	//PayCompanyName  string  `json:"pay_company_name" description:"代付客户名称"`
-	ActualCompanyName string `json:"actual_company_name" description:"实际使用方"`
-	SellerId        int     `json:"seller_id" description:"销售ID"`
-	SellerName      string  `json:"seller_name" description:"销售名称"`
-	ContractTypeKey int     `json:"contract_type_key" description:"FMS合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议;"`
-	ContractType    string  `json:"contract_type" description:"CRM合同类型: 新签合同; 续约合同; 补充协议;"`
-	Price           float64 `json:"price" description:"合同金额"`
-	StartDate       string  `json:"start_date" description:"合同开始日期"`
-	EndDate         string  `json:"end_date" description:"合同结束日期"`
+	ContractId         int     `json:"contract_id" description:"合同ID"`
+	ContractCode       string  `json:"contract_code" description:"合同编号"`
+	ProductId          int     `json:"product_id" description:"产品ID"`
+	CompanyName        string  `json:"company_name" description:"客户名称"`
+	RelateContractCode string  `json:"relate_contract_code" description:"代付合同关联的实际使用方合同编号"`
+	ActualCompanyName  string  `json:"actual_company_name" description:"实际使用方"`
+	SellerId           int     `json:"seller_id" description:"销售ID"`
+	SellerName         string  `json:"seller_name" description:"销售名称"`
+	ContractTypeKey    int     `json:"contract_type_key" description:"FMS合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议;"`
+	ContractType       string  `json:"contract_type" description:"CRM合同类型: 新签合同; 续约合同; 补充协议;"`
+	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 代付合同
@@ -101,7 +100,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"].
@@ -114,6 +113,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

@@ -35,6 +35,7 @@ type ContractRegister struct {
 	ServiceRemark      string    `gorm:"column:service_remark" json:"service_remark" description:"套餐备注信息"`
 	HasPayment         int       `gorm:"column:has_payment" json:"has_payment" description:"是否有代付: 0-无; 1-有"`
 	NewCompany         int       `gorm:"column:new_company" json:"new_company" description:"是否为新客户: 0-否; 1-是"`
+	ActualPayCompanies string    `gorm:"column:actual_pay_companies" json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
 	IsDeleted          int       `gorm:"column:is_deleted" json:"is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
 	base.TimeBase
 }
@@ -131,6 +132,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:"登记时间"`
 }
 
@@ -177,6 +179,7 @@ type ContractRegisterAddReq struct {
 	HasPayment         int                     `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
 	NewCompany         int                     `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
 	Services           []ContractServiceAddReq `json:"services" description:"服务套餐内容"`
+	ActualPayCompanies string                  `json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
 }
 
 // ContractRegisterEditReq 编辑合同登记请求体
@@ -310,7 +313,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:"合同服务及详情"`
@@ -380,6 +383,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
 }