|
@@ -15,7 +15,7 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-// 合同处理
|
|
|
+// HandleCompanyContract 合同处理
|
|
|
func HandleCompanyContract(cont context.Context) (err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -83,6 +83,12 @@ func HandleCompanyContract(cont context.Context) (err error) {
|
|
|
errorList = append(errorList, fmt.Sprint("合同id:", v.CompanyContractId, ";TryOutToFormal Err: ", e.Error()))
|
|
|
}
|
|
|
case 5, 6:
|
|
|
+ // 续约异常客户记录
|
|
|
+ tmpErr := contactHandleCompanyRenewalRecord(v, today)
|
|
|
+ if tmpErr != nil {
|
|
|
+ errorList = append(errorList, tmpErr.Error())
|
|
|
+ }
|
|
|
+
|
|
|
e := company.ApplyServiceUpdate(v.CompanyId, v.ProductId, utils.AdminId, v.CompanyContractId, v.StartDate, v.EndDate, utils.RealName, v.ProductName, v.PackageType, v.RaiPackageType)
|
|
|
if e != nil {
|
|
|
errorList = append(errorList, fmt.Sprint("合同id:", v.CompanyContractId, ";ApplyServiceUpdate Err: ", e.Error()))
|
|
@@ -131,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) //更新合同权限表中的权限名称,以及对应的行业权限类型(行业新签、行业续约)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -140,3 +148,136 @@ func HandleCompanyContract(cont context.Context) (err error) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// contactHandleCompanyRenewalRecord
|
|
|
+// @Description: 合同处理完成后的续约异常记录
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2023-12-07 14:24:44
|
|
|
+// @param contractInfo *company_contract.CompanyContract
|
|
|
+// @param day string
|
|
|
+// @return err error
|
|
|
+func contactHandleCompanyRenewalRecord(contractInfo *company_contract.CompanyContract, day string) (err error) {
|
|
|
+ // 判断合同类型是否是续约合同,如果不是的话,就不往下走了
|
|
|
+ if contractInfo.ContractType != `续约合同` {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取早于当前合同结束日期的上一份合同
|
|
|
+ lastContract, tmpErr := company_contract.GetLastContractListByEndDate(contractInfo.CompanyId, contractInfo.ProductId, contractInfo.EndDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = errors.New(fmt.Sprint("合同id:", contractInfo.CompanyContractId, ";通过最近一份合同的日期获取早于该合同的最晚一份合同失败,ERR:", tmpErr))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 校验 上一份合同的结束日期 与 今天 相隔的天数
|
|
|
+ betweenDay, tmpErr := utils.GetDaysBetween2Date(utils.FormatDate, day, lastContract.EndDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = errors.New(fmt.Sprint("合同id:", contractInfo.CompanyContractId, ";计算两个日期相差的天数失败,ERR:", tmpErr))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ source := 2 // 正常续约
|
|
|
+ // 如果间隔时间超过60天,那么标记为超时续约
|
|
|
+ if betweenDay > 60 {
|
|
|
+ source = 3 // 超时续约
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果间隔时间超过60天,那么标记为超时续约
|
|
|
+ companyProductItem, tmpErr := models.GetCompanyProductItemByCompanyId(contractInfo.CompanyId, contractInfo.ProductId)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = errors.New(fmt.Sprint("合同id:", contractInfo.CompanyContractId, ";GetCompanyProductItemByCompanyId失败,ERR:", tmpErr))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var shareSellerId int
|
|
|
+ var shareSellerName string
|
|
|
+ if companyProductItem.IsShare == 1 {
|
|
|
+ shareSellerId = companyProductItem.ShareSellerId
|
|
|
+ shareSellerName = companyProductItem.ShareSeller
|
|
|
+ }
|
|
|
+ item := &models.CompanyRenewalRecord{
|
|
|
+ Id: 0,
|
|
|
+ CompanyId: contractInfo.CompanyId,
|
|
|
+ ProductId: contractInfo.ProductId,
|
|
|
+ Source: source,
|
|
|
+ SellerId: companyProductItem.SellerId,
|
|
|
+ SellerName: companyProductItem.SellerName,
|
|
|
+ ShareSellerId: shareSellerId,
|
|
|
+ ShareSellerName: shareSellerName,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ ModifyTime: time.Now(),
|
|
|
+ }
|
|
|
+ tmpErr = item.Add()
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = errors.New(fmt.Sprint("合同id:", contractInfo.CompanyContractId, ";添加续约异常记录失败,ERR:", tmpErr))
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// HandleCompanyRenewalRecord
|
|
|
+// @Description: 处理续约客户的问题
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2023-12-07 10:56:24
|
|
|
+// @param cont context.Context
|
|
|
+// @return err error
|
|
|
+func HandleCompanyRenewalRecord(cont context.Context) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ //fmt.Println("合同处理 ErrMsg:"+err.Error())
|
|
|
+ //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "合同处理 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
|
|
|
+ go alarm_msg.SendAlarmMsg("合同处理 ErrMsg:"+err.Error(), 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ // 需求是60个自然后未续约的客户,所以要减去61天
|
|
|
+ endDate := time.Now().AddDate(0, 0, -61).Format(utils.FormatDate)
|
|
|
+ total, list, err := company_contract.GetContractListByEndDate(endDate)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("HandleCompanyRenewalRecord GetStartContractListByEndDate Err:%s" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Sprintln("总共d%条数据待处理", total)
|
|
|
+ if total <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ companyIdList := make([]int, 0)
|
|
|
+ for _, companyInfo := range list {
|
|
|
+ companyIdList = append(companyIdList, companyInfo.CompanyId)
|
|
|
+ }
|
|
|
+
|
|
|
+ companyList, err := models.GetCompanyProductItemListByCompanyIdList(companyIdList, 1)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("HandleCompanyRenewalRecord GetCompanyProductListByCompanyIdList Err:%s" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ addList := make([]*models.CompanyRenewalRecord, 0)
|
|
|
+ for _, v := range companyList {
|
|
|
+ if v.Status != "正式" {
|
|
|
+ var shareSellerId int
|
|
|
+ var shareSellerName string
|
|
|
+ if v.IsShare == 1 {
|
|
|
+ shareSellerId = v.ShareSellerId
|
|
|
+ shareSellerName = v.ShareSeller
|
|
|
+ }
|
|
|
+ addList = append(addList, &models.CompanyRenewalRecord{
|
|
|
+ Id: 0,
|
|
|
+ CompanyId: v.CompanyId,
|
|
|
+ ProductId: v.ProductId,
|
|
|
+ Source: 1,
|
|
|
+ SellerId: v.SellerId,
|
|
|
+ SellerName: v.SellerName,
|
|
|
+ ShareSellerId: shareSellerId,
|
|
|
+ ShareSellerName: shareSellerName,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ ModifyTime: time.Now(),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(addList) > 0 {
|
|
|
+ err = models.MultiAddCompanyRenewalRecord(addList)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|