Эх сурвалжийг харах

Merge branch 'crm/need_1059' of http://8.136.199.33:3000/hongze/hz_crm_api into debug

zhangchuanxing 1 долоо хоног өмнө
parent
commit
a18489dc41

+ 22 - 0
controllers/company_renewal.go

@@ -478,6 +478,28 @@ func (this *CompanyRenewalController) CompanyContractNoRenewedAscribeAdd() {
 		br.ErrMsg = "新建失败,Err:" + err.Error()
 		return
 	}
+	//新增操作记录
+	if productId == utils.COMPANY_PRODUCT_RAI_ID {
+		cp, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, productId)
+		if err != nil {
+			br.Msg = "获取客户信息失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+			return
+		}
+		if cp.IsShare == 1 {
+			err = company.UpdateCompanyProductCancelisShare(req.CompanyId, productId)
+			if err != nil {
+				br.Msg = "取消共享失败"
+				br.ErrMsg = "取消共享失败,Err:" + err.Error()
+				return
+			}
+			remark := "确认不续约,自动取消共享"
+			operation := "no_renewed"
+			services.AddCompanyOperationRecord(req.CompanyId, cp.SellerId, sysUser.AdminId, productId, sysUser.AdminId, cp.CompanyName,
+				"权益", sysUser.RealName, remark, operation, "", sysUser.RealName, "", cp.Status)
+		}
+
+	}
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "新建成功"

+ 19 - 5
models/company/company_product.go

@@ -744,7 +744,6 @@ func UpdateCompanyProductSellerUnexpiredInitinit16_1_05(sellerId int, sellerName
 	return
 }
 
-
 func GetCompanyNameByShareSellerId(shareSellerIds []int) (companyName []string, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT distinct c.company_name FROM company_product cp left join company c on cp.company_id = c.company_id WHERE cp.share_seller_id IN (` + utils.GetOrmInReplace(len(shareSellerIds)) + `)`
@@ -760,10 +759,10 @@ func GetCompanyNameByShareSellerIdStr(shareSellerIds []string) (companyName []st
 }
 
 type CompanyShareSeller struct {
-	CompanyName string 
-	ProductId int
-	ShareSellerId int 
-	ShareSeller string 
+	CompanyName   string
+	ProductId     int
+	ShareSellerId int
+	ShareSeller   string
 }
 
 func GetShareSellerByCompanyName(companyNames []string) (items []*CompanyShareSeller, err error) {
@@ -772,3 +771,18 @@ func GetShareSellerByCompanyName(companyNames []string) (items []*CompanyShareSe
 	_, err = o.Raw(sql, companyNames).QueryRows(&items)
 	return
 }
+
+// 取消共享销售
+func UpdateCompanyProductCancelisShare(companyId, productId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE company_product SET
+                            is_share = 0 , 
+                            share_seller = '',
+                            share_group_id = 0,
+                            share_seller_id = 0 , 
+                            share_seller_id_last  = 0 , 
+                            share_seller_last = ''
+                            WHERE company_id = ?  AND product_id= ? `
+	_, err = o.Raw(sql, companyId, productId).Exec()
+	return
+}