瀏覽代碼

Merge branch 'crm_14.4' of http://8.136.199.33:3000/hongze/hongze_task into debug

xingzai 1 年之前
父節點
當前提交
770369c2db

+ 9 - 1
models/chart_permission.go

@@ -90,4 +90,12 @@ func GetChartPermissionByIds(permissionIds []string) (list []*ChartPermission, e
 	o := orm.NewOrm()
 	_, err = o.Raw(sql).QueryRows(&list)
 	return
-}
+}
+
+// GetChartPermissionList 获取品种权限列表
+func GetChartPermissionList() (list []*ChartPermission, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM chart_permission `
+	_, err = o.Raw(sql).QueryRows(&list)
+	return
+}

+ 74 - 0
models/company_contract/company_contract.go

@@ -46,6 +46,8 @@ type CompanyContractPermission struct {
 	EndDate           string    `description:"结束日期"`
 	CreateTime        time.Time `description:"创建时间"`
 	ModifyTime        time.Time `description:"修改时间"`
+	ContractType      string    `description:"签约合同时,当前行业类型:枚举值:'行业新签','行业续约'"`
+	PermissionName    string    `description:"权限名称"`
 }
 
 // GetContractListByEndDate 通过结束日期获取当天结束的合同列表
@@ -77,3 +79,75 @@ func GetCompanyContractPermissionList(condition string, pars []interface{}) (ite
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }
+
+type CompanyContractResp struct {
+	CompanyContractId int       `orm:"column(company_contract_id);pk" description:"客户合同id"`
+	ContractType      string    `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
+	ProductId         int       `description:"产品id"`
+	ProductName       string    `description:"产品名称"`
+	CompanyId         int       `description:"客户id"`
+	CompanyProductId  int       `description:"客户产品id"`
+	ContractCode      string    `description:"合同编码"`
+	StartDate         string    `description:"合同开始时间"`
+	EndDate           string    `description:"合同结束时间"`
+	Money             float64   `description:"合同金额"`
+	PayMethod         string    `description:"支付方式"`
+	PayChannel        string    `description:"支付渠道"`
+	ImgUrl            string    `description:"合同图片,多个用#隔开"`
+	CreateTime        time.Time `description:"合同创建时间"`
+	ModifyTime        time.Time `description:"合同修改时间"`
+	Status            int       `description:"状态"`
+	Source            string    `description:"合同来源,枚举值:上传附件、系统合同,默认上传附件"`
+	PackageType       int       `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
+	RaiPackageType    int       `description:"权益套餐类型: 0-无; 1-70w大套餐; 2-45w大套餐"`
+	PermissionName    string    `description:"权限名"`
+}
+
+
+// 通过ID获取详情
+func GetCompanyContracDetail(condition string, pars []interface{}) (item *CompanyContractResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM company_contract  WHERE 1= 1 ` + condition
+	err = o.Raw(sql, pars).QueryRow(&item)
+	return
+}
+
+// UpdateCompanyContractPackageDifference 更改合同与上一份合同金额对比信息
+func UpdateCompanyContractPackageDifference(packageDifference string, companyContractId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE company_contract SET package_difference = ?  WHERE company_contract_id=? `
+	_, err = o.Raw(sql, packageDifference, companyContractId).Exec()
+	return
+}
+
+// UpdateCompanyContractPermissionMulti 批量修改
+func UpdateCompanyContractPermissionMulti(items []*CompanyContractPermission) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+
+	//批量修改公司
+	p, err := o.Raw("UPDATE company_contract_permission SET permission_name = ? ,contract_type = ? WHERE id = ?").Prepare()
+	if err != nil {
+		return
+	}
+	defer func() {
+		_ = p.Close() // 别忘记关闭 statement
+	}()
+
+	for _, v := range items {
+		_, err = p.Exec(v.PermissionName, v.ContractType, v.Id)
+		if err != nil {
+			return
+		}
+	}
+	return
+}

+ 3 - 0
services/company_contract/company_contract.go

@@ -137,6 +137,8 @@ func HandleCompanyContract(cont context.Context) (err error) {
 			cygx.YanXuanCompanyApproval(v.CompanyId)
 			cygx.ActivitySpecialCompanyApproval(v.CompanyId)
 			cygx.HandleAllocationCompanyContractByYanXuan(v.CompanyContractId) //如果合同只有研选的时候,自动处理派点
+			cygx.HandleCompanyContractPackageDifference(v.CompanyContractId) //更新与上一份合同的金额的对比 '增加套餐','减少套餐','维持套餐'
+			cygx.HandleCompanyContractPermissionContractType(v.CompanyContractId) //更新合同权限表中的权限名称,以及对应的行业权限类型(行业新签、行业续约)
 		}
 	}
 
@@ -278,3 +280,4 @@ func HandleCompanyRenewalRecord(cont context.Context) (err error) {
 
 	return
 }
+

+ 135 - 0
services/cygx/company_contract.go

@@ -2,6 +2,7 @@ package cygx
 
 import (
 	"fmt"
+	"hongze/hongze_task/models"
 	"hongze/hongze_task/models/company_contract"
 	"hongze/hongze_task/models/cygx"
 	"hongze/hongze_task/services/alarm_msg"
@@ -85,4 +86,138 @@ func HandleAllocationCompanyContractByYanXuan(companyContractId int) (err error)
 	}
 	return
 
+}
+
+
+// HandleCompanyContractPackageDifference 更新与上一份合同的金额的对比 '增加套餐','减少套餐','维持套餐'
+func HandleCompanyContractPackageDifference(companyContractId int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg(fmt.Sprint("更新与上一份合同的金额的对比 '增加套餐','减少套餐','维持套餐'失败,Err:", err.Error(), "companyContractId", companyContractId), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+
+	condition = " AND company_contract_id = ?  "
+	pars = append(pars, companyContractId)
+	detail, e := company_contract.GetCompanyContracDetail(condition, pars)
+	if e != nil {
+		err = errors.New("GetCompanyContracDetail,detail Err: " + e.Error())
+		return
+	}
+
+	//如果不是续约合同就不做对比处理
+	if detail.ContractType != "续约合同" {
+		return
+	}
+	//获取前一份合同的信息
+	pars = make([]interface{}, 0)
+	condition = " AND company_id = ? AND company_contract_id < ?   AND status = 1    AND product_id = ?  ORDER BY company_contract_id DESC   LIMIT  1  "
+	pars = append(pars, detail.CompanyId, companyContractId, detail.ProductId)
+	detailPrevious, e := company_contract.GetCompanyContracDetail(condition, pars)
+	if e != nil {
+		err = errors.New("GetCompanyContracDetail,detailPrevious Err: " + e.Error())
+		return
+	}
+	var packageDifference string
+
+	if detail.Money > detailPrevious.Money {
+		packageDifference = "增加套餐"
+	} else if detail.Money < detailPrevious.Money {
+		packageDifference = "减少套餐"
+	} else {
+		packageDifference = "维持套餐"
+	}
+
+	e = company_contract.UpdateCompanyContractPackageDifference(packageDifference, companyContractId)
+	if e != nil {
+		err = errors.New("UpdateCompanyContractPackageDifference, Err: " + e.Error())
+		return
+	}
+	return
+
+}
+
+// HandleCompanyContractPermissionContractType 更新合同权限表中的权限名称,以及对应的行业权限类型(行业新签、行业续约)
+func HandleCompanyContractPermissionContractType(companyContractId int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg(fmt.Sprint("更新合同权限表中的权限名称,以及对应的行业权限类型(行业新签、行业续约)失败,HandleCompanyContractPermissionContractType Err:", err.Error(), "companyContractId", companyContractId), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+
+	condition = " AND company_contract_id = ?  "
+	pars = append(pars, companyContractId)
+	detail, e := company_contract.GetCompanyContracDetail(condition, pars)
+	if e != nil {
+		err = errors.New("GetCompanyContracDetail,detail Err: " + e.Error())
+		return
+	}
+
+	//获取权限ID与名称的map映射
+	permissionList, e := models.GetChartPermissionList()
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetChartPermissionList Err: " + e.Error())
+		return
+	}
+
+	mapChartPermission := make(map[int]string)
+	for _, v := range permissionList {
+		mapChartPermission[v.ChartPermissionId] = v.PermissionName
+	}
+
+	companyId := detail.CompanyId
+	//如果不是续约合同就不做对比处理
+	pars = make([]interface{}, 0)
+	condition = " AND  company_contract_id  != ?   AND  company_id = ? "
+	pars = append(pars, companyContractId, companyId)
+
+	//获取历史签约信息
+	companyContractPermissionListHistory, e := company_contract.GetCompanyContractPermissionList(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("companyContractPermissionListHistory Err: " + e.Error())
+		return
+	}
+
+	var mapHistoryPerssionName []string
+	for _, v := range companyContractPermissionListHistory {
+		mapHistoryPerssionName = append(mapHistoryPerssionName, mapChartPermission[v.ChartPermissionId])
+	}
+
+	pars = make([]interface{}, 0)
+	condition = " AND  company_contract_id  = ?   "
+	pars = append(pars, companyContractId)
+	//获取当前签约的合同信息
+	companyContractPermissionLisThis, e := company_contract.GetCompanyContractPermissionList(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("companyContractPermissionLisThis Err: " + e.Error())
+		return
+	}
+
+	var items []*company_contract.CompanyContractPermission
+	for _, v := range companyContractPermissionLisThis {
+		v.PermissionName = mapChartPermission[v.ChartPermissionId]
+		if v.PermissionName == "" {
+			continue
+		}
+		//已经存在的属于行业续约、不存在的属于行业新签
+		if utils.InArrayByStr(mapHistoryPerssionName, v.PermissionName) {
+			v.ContractType = "行业续约"
+		} else {
+			v.ContractType = "行业新签"
+		}
+		items = append(items, v)
+	}
+	//批量更新合同权限表的权限行业名称,以及签约合同时,当前行业类型(行业续约、行业新签)
+	e = company_contract.UpdateCompanyContractPermissionMulti(items)
+	if e != nil {
+		err = errors.New("UpdateCompanyContractPermissionMulti Err: " + e.Error())
+		return
+	}
+	return
 }