zhangchuanxing 3 місяців тому
батько
коміт
9e8b05afee

+ 4 - 0
controllers/company.go

@@ -5320,6 +5320,10 @@ func (this *CompanyController) MoveSeller() {
 		services.AddCompanyOperationRecord(req.CompanyId, seller.AdminId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
 			cp.ProductName, sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
 	}
+
+	{
+		services.UpdateCompanyContractSellerMove(req.CompanyId, productId) //益客户移动所属销售之后,更新所关联的销售信息
+	}
 	//变更销售员与联系人关系
 	_ = models.UpdateUserSellerRelationByCompanyId(req.CompanyId, productId, seller.AdminId, seller.RealName)
 

+ 12 - 0
controllers/company_apply_v2.go

@@ -247,6 +247,10 @@ func (this *CompanyApplyController) ApplyServiceUpdate() {
 		contract.SellerNameInit = companyProduct.SellerName
 		contract.ShareSellerInit = companyProduct.ShareSeller
 		contract.ShareSellerIdInit = companyProduct.ShareSellerId
+		contract.SellerIdLast = companyProduct.SellerId
+		contract.SellerNameLast = companyProduct.SellerName
+		contract.ShareSellerLast = companyProduct.ShareSeller
+		contract.ShareSellerIdLast = companyProduct.ShareSellerId
 		newId, err := company.AddCompanyContract(contract)
 		if err != nil {
 			br.Msg = "新增合同失败"
@@ -703,6 +707,10 @@ func (this *CompanyApplyController) ApplyTurnPositive() {
 		contract.SellerNameInit = companyProduct.SellerName
 		contract.ShareSellerInit = companyProduct.ShareSeller
 		contract.ShareSellerIdInit = companyProduct.ShareSellerId
+		contract.SellerIdLast = companyProduct.SellerId
+		contract.SellerNameLast = companyProduct.SellerName
+		contract.ShareSellerLast = companyProduct.ShareSeller
+		contract.ShareSellerIdLast = companyProduct.ShareSellerId
 		newId, err := company.AddCompanyContract(contract)
 		if err != nil {
 			br.Msg = "新增合同失败"
@@ -1209,6 +1217,10 @@ func (this *CompanyApplyController) ApplyBySystemContract() {
 			SellerNameInit:    companyProduct.SellerName,
 			ShareSellerInit:   companyProduct.ShareSeller,
 			ShareSellerIdInit: companyProduct.ShareSellerId,
+			SellerIdLast:      companyProduct.SellerId,
+			SellerNameLast:    companyProduct.SellerName,
+			ShareSellerLast:   companyProduct.ShareSeller,
+			ShareSellerIdLast: companyProduct.ShareSellerId,
 		}
 		newId, err := company.AddCompanyContract(companyContract)
 		if err != nil {

+ 4 - 0
controllers/company_share.go

@@ -768,6 +768,10 @@ func (this *CompanyController) MoveShareSeller() {
 		br.ErrMsg = "修改客户信息失败,Err:" + err.Error()
 		return
 	}
+
+	{
+		services.UpdateCompanyContractSellerMove(req.CompanyId, productId) //益客户移动所属销售之后,更新所关联的销售信息
+	}
 	//新增操作记录
 	//{
 	//	remark := "移动到:" + seller.RealName

+ 0 - 1
controllers/statistic_company_merge.go

@@ -451,7 +451,6 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 			var ascribecompanyIds []int
 			var companyContractIds []int
 			for _, item := range tmpList {
-				fmt.Println(item)
 				//endDateTime, _ := time.Parse(utils.FormatDateTime, item.CreateTime)
 				//item.EndDate = endDateTime.Format(utils.FormatDate)
 				ascribecompanyIds = append(ascribecompanyIds, item.CompanyId)

+ 31 - 0
models/company/company_contract.go

@@ -31,6 +31,10 @@ type CompanyContract struct {
 	SellerNameInit    string    `description:"销售名称"`
 	ShareSellerInit   string    `description:"共享销售员"`
 	ShareSellerIdInit int       `description:"共享销售员id"`
+	SellerIdLast      int       `description:"合同到期之前最后所属销售id"`
+	SellerNameLast    string    `description:"合同到期之前最后所属销售名称"`
+	ShareSellerLast   string    `description:"合同到期之前最后所属共享销售员"`
+	ShareSellerIdLast int       `description:"合同到期之前最后所属共享销售员id"`
 }
 
 // 新增客户合同
@@ -378,3 +382,30 @@ func UpdateCompanyContractTypeinit16_1_02(seller_name_init string, seller_id_ini
 	_, err = o.Raw(sql, seller_name_init, seller_id_init, company_contract_id).Exec()
 	return
 }
+
+// 合同未生效更新对应销售的信息
+func UpdateCompanyContractSellerNotEffective(sellerId, shareSellerInit int, sellerName, shareSeller string, companyContractId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE company_contract SET seller_id_init = ? ,
+                            seller_name_init = ? ,
+                            share_seller_init = ? ,
+                            share_seller_id_init = ? , 
+                            seller_id_last = ? , 
+                            seller_name_last = ? , 
+                            share_seller_last = ? , 
+                            share_seller_id_last = ?  WHERE company_contract_id = ?  AND product_id= 2 `
+	_, err = o.Raw(sql, sellerId, sellerName, shareSellerInit, shareSeller, sellerId, sellerName, shareSellerInit, shareSeller, companyContractId).Exec()
+	return
+}
+
+// 合同未到期更新对应销售的信息
+func UpdateCompanyContractSellerUnexpired(sellerId, shareSellerInit int, sellerName, shareSeller string, companyContractId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE company_contract SET
+                            seller_id_last = ? , 
+                            seller_name_last = ? , 
+                            share_seller_last = ? , 
+                            share_seller_id_last = ?  WHERE company_contract_id = ?  AND product_id= 2 `
+	_, err = o.Raw(sql, sellerId, sellerName, shareSellerInit, shareSeller, companyContractId).Exec()
+	return
+}

+ 84 - 0
services/company_contract.go

@@ -1,5 +1,14 @@
 package services
 
+import (
+	"errors"
+	"fmt"
+	"hongze/hz_crm_api/models/company"
+	"hongze/hz_crm_api/services/alarm_msg"
+	"hongze/hz_crm_api/utils"
+	"time"
+)
+
 //func init() {
 //	InitCompanyContractMerge()
 //	//GetCompanyContractPermissionNameMapById(map[int]string{6513: "182,183", 6663: "435,542"})
@@ -396,3 +405,78 @@ package services
 //
 //	return
 //}
+
+//func init() {
+//	UpdateCompanyContractSellerMove(7034, 2)
+//}
+
+// UpdateCompanyContractSellerMove 权益客户移动所属销售之后,更新所关联的销售信息
+func UpdateCompanyContractSellerMove(companyId, productId int) (moveMap map[string]bool) {
+	if productId != utils.COMPANY_PRODUCT_RAI_ID {
+		return
+	}
+	time.Sleep(1 * time.Second) // 延迟1秒
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg("权益客户移动所属销售之后,更新所关联的销售信息失败,UpdateCompanyContractSellerMove "+fmt.Sprint("companyId:", companyId, ";err:", err), 3)
+		}
+	}()
+
+	cp, e := company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
+	if e != nil {
+		err = errors.New("GetCompanyProductByCompanyIdAndProductId Err: " + e.Error())
+		return
+	}
+
+	//更新还没有生效的合同
+	{
+		var condition string
+		var pars []interface{}
+		pars = make([]interface{}, 0)
+		condition = " AND  company_id = ?  AND  product_id = ?  AND  start_date > ? "
+		pars = append(pars, companyId, productId, time.Now())
+		list, e := company.GetCompanyContracList(condition, pars) // 获取还没有生效的合同信息
+		if e != nil {
+			err = errors.New("GetCompanyContracList, Err: " + e.Error())
+			return
+		}
+		//fmt.Println("list1", len(list))
+		if len(list) > 0 {
+			for _, v := range list {
+				e = company.UpdateCompanyContractSellerNotEffective(cp.SellerId, cp.ShareSellerId, cp.SellerName, cp.ShareSeller, v.CompanyContractId)
+				if e != nil {
+					err = errors.New("UpdateCompanyContractSellerNotEffective, Err: " + e.Error())
+					return
+				}
+			}
+		}
+	}
+
+	//更新还没有到期的合同
+	{
+		var condition string
+		var pars []interface{}
+		pars = make([]interface{}, 0)
+		condition = " AND  company_id = ?  AND  product_id = ?  AND  start_date < ?  AND  end_date > ? "
+		pars = append(pars, companyId, productId, time.Now(), time.Now())
+		list, e := company.GetCompanyContracList(condition, pars) // 获取还没有到期的合同信息
+		if e != nil {
+			err = errors.New("GetCompanyContracList, Err: " + e.Error())
+			return
+		}
+		//fmt.Println("list2", len(list))
+		if len(list) > 0 {
+			for _, v := range list {
+				e = company.UpdateCompanyContractSellerUnexpired(cp.SellerId, cp.ShareSellerId, cp.SellerName, cp.ShareSeller, v.CompanyContractId)
+				if e != nil {
+					err = errors.New("UpdateCompanyContractSellerUnexpired, Err: " + e.Error())
+					return
+				}
+			}
+		}
+	}
+
+	return
+}