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