|
@@ -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
|
|
|
}
|