Răsfoiți Sursa

Merge branch 'crm/crm_17.1_rai' of http://8.136.199.33:3000/hongze/hz_crm_api into debug

zhangchuanxing 1 zi în urmă
părinte
comite
17e9b41dfb

+ 12 - 0
controllers/company_apply_v2.go

@@ -486,6 +486,17 @@ func (this *CompanyApplyController) ApplyTurnPositive() {
 		return
 	}
 
+	var wxUserName string
+	if wxUserId > 0 {
+		wxUser, err := models.GetWxUserItemByUserId(wxUserId)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败, GetWxUserItemByUserId  Err:" + err.Error()
+			return
+		}
+		wxUserName = wxUser.RealName
+	}
+
 	//添加缓存,避免多次点击提交
 	{
 		deleteCache := true
@@ -846,6 +857,7 @@ func (this *CompanyApplyController) ApplyTurnPositive() {
 		contract.ShareSellerLast = companyProduct.ShareSeller
 		contract.ShareSellerIdLast = companyProduct.ShareSellerId
 		contract.WxUserId = wxUserId
+		contract.WxUserName = wxUserName
 		newId, err := company.AddCompanyContract(contract)
 		if err != nil {
 			br.Msg = "新增合同失败"

+ 3 - 0
controllers/cygx/contract_allocation.go

@@ -321,6 +321,9 @@ func (this *ContractAllocationController) CompanyContractList() {
 					quarter, _ := utils.GetQuarterStrStartDatesInRange(v.StartDate, v.EndDate)
 					v.Quarter = strings.Replace(quarter, ",", "+", -1)
 				}
+				if v.WxUserId > 0 {
+					v.CompanyName = v.WxUserName + "(" + v.CompanyName + ")"
+				}
 			}
 		}
 	}

+ 6 - 0
controllers/statistic_company_merge.go

@@ -510,6 +510,9 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 	var companyIds []int
 	for i := 0; i < listLen; i++ {
 		item := list[i]
+		if item.WxUserId > 0 {
+			item.CompanyName = item.WxUserName + "(" + item.CompanyName + ")"
+		}
 		companyContractIds = append(companyContractIds, item.CompanyContractId)
 		//新增试用不需要计算剩余日期
 		if dataType != "新增试用" {
@@ -1211,6 +1214,9 @@ func (this *StatisticCompanyMergerController) CompanyContractPermissionList() {
 		item := list[i]
 		companyContractIds = append(companyContractIds, item.CompanyContractId)
 		companyIds = append(companyIds, item.CompanyId)
+		if item.WxUserId > 0 {
+			item.CompanyName = item.WxUserName + "(" + item.CompanyName + ")"
+		}
 		//新增试用不需要计算剩余日期
 		if dataType != "新增试用" {
 			//剩余可用天数

+ 7 - 1
controllers/statistic_report.go

@@ -3799,7 +3799,7 @@ func (this *StatisticReportController) IncrementalCompanyList() {
 	if adminId != "" {
 		if dataType == "未续约客户" {
 			condition += ` AND (c.share_seller_id in  (` + adminId + `) OR c.seller_id in  (` + adminId + `)) `
-		}else{
+		} else {
 			condition += ` AND c.seller_id in  (` + adminId + `) `
 		}
 		//pars = append(pars, adminId)
@@ -4249,6 +4249,9 @@ func (this *StatisticReportController) IncrementalCompanyList() {
 	}
 	for i := 0; i < listLen; i++ {
 		item := list[i]
+		if item.WxUserId > 0 {
+			item.CompanyName = item.WxUserName + "(" + item.CompanyName + ")"
+		}
 
 		//新增试用不需要计算剩余日期
 		if dataType != "新增试用" {
@@ -7470,6 +7473,9 @@ func getTodayStackCompanyListV2Rai(sysUser *system.Admin, currentIndex, pageSize
 			//给list赋值
 			for _, item := range list {
 				if item.ProductName == "权益" {
+					if item.WxUserId > 0 {
+						item.CompanyName = item.WxUserName + "(" + item.CompanyName + ")"
+					}
 					oldMoney, _ := oldMoneyMap[item.CompanyId]
 					lastContract, _ := oldCompanyMap[item.CompanyId]
 					if oldMoney > lastContract.Money {

+ 49 - 0
models/company/company_approval.go

@@ -334,7 +334,50 @@ func TryOutToFormalByWxUser(companyId, productId, sellerId, companyApprovalId, c
 			return
 		}
 	} else {
+		itemuserProductDetail := new(UserProduct)
+		sql = ` SELECT * FROM user_product AS a WHERE user_id = ?  AND  product_id =  ? `
+		err = o.Raw(sql, userId, productId).QueryRow(&itemuserProductDetail)
+		if err != nil {
+			return
+		}
+
+		updateStartDateTime, tmpErr := time.Parse(utils.FormatDate, itemuserProductDetail.StartDate)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+
+		updateEndDateTime, tmpErr := time.Parse(utils.FormatDate, itemuserProductDetail.EndDate)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+
+		//校验原始数据中的开始日期是否小于合同内的开始日期,如果小于,那么变更为原先的合同开始日期
+		tmpStartDate, tmpErr := time.Parse(utils.FormatDate, startDate)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		if tmpStartDate.Before(updateStartDateTime) {
+			updateStartDateTime = tmpStartDate
+		}
 
+		//校验原始数据中的结束日期是否大于合同内的结束日期,如果大于,那么变更为原先的合同结束日期
+		tmpEndDate, tmpErr := time.Parse(utils.FormatDate, endDate)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		if tmpEndDate.After(updateEndDateTime) {
+			updateEndDateTime = tmpEndDate
+		}
+
+		sql = `UPDATE user_product SET status='正式', start_date=?, end_date=?,modify_time=NOW() WHERE WHERE user_id = ?  AND  product_id =  ? `
+		_, err = to.Raw(sql, updateStartDateTime, updateEndDateTime, userId, productId).Exec()
+		if err != nil {
+			return
+		}
 	}
 
 	sql = `UPDATE company_approval SET approve_status='已审批',approve_time=NOW(),modify_time=NOW() WHERE company_approval_id=? AND company_id=? AND product_id=? `
@@ -342,6 +385,7 @@ func TryOutToFormalByWxUser(companyId, productId, sellerId, companyApprovalId, c
 	if err != nil {
 		return
 	}
+
 	items := make([]*UserReportPermission, 0)
 	sql = `SELECT * FROM user_report_permission WHERE company_id=? AND product_id=? `
 	_, err = to.Raw(sql, companyId, productId).QueryRows(&items)
@@ -382,6 +426,11 @@ func TryOutToFormalByWxUser(companyId, productId, sellerId, companyApprovalId, c
 			Status:             "正式",
 			ModifyTime:         time.Now(),
 		}
+		sql = ` DELETE FROM user_report_permission WHERE chart_permission_id=? AND product_id=?  AND user_id = ? `
+		_, err = to.Raw(sql, pv.ChartPermissionId, productId, userId).Exec()
+		if err != nil {
+			return
+		}
 		_, tmpErr := to.Insert(tmpUserReportPermission)
 		if tmpErr != nil {
 			err = tmpErr

+ 1 - 0
models/company/company_contract.go

@@ -39,6 +39,7 @@ type CompanyContract struct {
 	ShareSellerLast   string    `description:"合同到期之前最后所属共享销售员"`
 	ShareSellerIdLast int       `description:"合同到期之前最后所属共享销售员id"`
 	WxUserId          int       `description:"用户ID,开通个人权限使用"`
+	WxUserName        string    `description:"用户姓名,针对某份合同仅对单个用户使用的时候的场景"`
 }
 
 // 新增客户合同

+ 7 - 0
models/company/user_product.go

@@ -55,3 +55,10 @@ func GetUserProductByUserIds(userIds []int) (items []*UserProduct, err error) {
 	_, err = o.Raw(sql, userIds).QueryRows(&items)
 	return
 }
+
+func GetUserProductDetailByProductIdUserId(userId, productId int) (item *UserProduct, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM user_product AS a WHERE user_id = ?  AND  product_id =  ? `
+	err = o.Raw(sql, userId, productId).QueryRow(&item)
+	return
+}

+ 2 - 0
models/cygx/company_contract.go

@@ -27,6 +27,8 @@ type CompanyContractResp struct {
 	MoneyPoint        float64 `description:"派点金额"`
 	PermissionName    string  `description:"权限名"`
 	Quarter           string  `description:"季度(X类试用客户使用)"`
+	WxUserId          int     `description:"用户id,针对某份合同仅对单个用户使用的时候的场景"`
+	WxUserName        string  `description:"用户姓名,针对某份合同仅对单个用户使用的时候的场景"`
 }
 
 // 增量客户统计报表返回类

+ 3 - 1
models/statistic_report.go

@@ -417,6 +417,8 @@ type IncrementalList struct {
 	SysRealName     string `description:"操作者名称"`
 	SysUserId       string `description:"操作者Id"`
 	Operation       string `description:"操作"`
+	WxUserId        int    `description:"用户ID,开通个人权限使用"`
+	WxUserName      string `description:"用户姓名,针对某份合同仅对单个用户使用的时候的场景"`
 }
 
 // GetIncrementalNewCompanyCount 获取增量客户报表列表统计数据(根据合同来展示)
@@ -1001,7 +1003,7 @@ func GetIncrementalCompanyListByOperationRecordMerge(condition string, pars []in
 	o := orm.NewOrm()
 
 	//查询真正的数据
-	sql := `SELECT a.company_contract_id,a.contract_type ,a.company_product_id ,a.contract_code ,a.pay_method ,a.pay_channel ,a.package_difference ,a.company_id, a.start_date, a.end_date, a.money, b.company_name, a.seller_id_last as seller_id, a.seller_name_last as  seller_name, a.share_seller_last as  share_seller, a.product_id, a.product_name, a.create_time, b.region_type, c.renewal_reason, c.renewal_todo, c.status  FROM company_contract a
+	sql := `SELECT a.company_contract_id,a.contract_type ,a.company_product_id ,a.contract_code ,a.pay_method ,a.pay_channel ,a.package_difference ,a.company_id, a.start_date, a.end_date, a.money, b.company_name, a.seller_id_last as seller_id, a.seller_name_last as  seller_name, a.share_seller_last as  share_seller, a.product_id, a.product_name, a.create_time, b.region_type, c.renewal_reason, c.renewal_todo, c.status , a.wx_user_id , a.wx_user_name  FROM company_contract a
 		RIGHT JOIN company b ON a.company_id = b.company_id
 		JOIN company_product c ON b.company_id = c.company_id 
 		AND a.product_id = c.product_id  where 1=1  `

+ 1 - 1
services/company_apply/company_approval.go

@@ -418,7 +418,7 @@ func Approved(approvalRecord *contract.ContractApprovalRecord, opUser *system.Ad
 				//}
 
 				//权益销售客户申请转正后,消息群发给所有销售
-				services.AddCompanyApprovalMessageRai(recordInfo.CompanyId, recordInfo.CompanyContractId, recordInfo.ApplyRealName, companyInfo.CompanyName)
+				services.AddCompanyApprovalMessageRai(recordInfo.CompanyId, recordInfo.CompanyContractId, recordInfo.ApplyRealName, companyInfo.CompanyName, recordInfo.WxUserName)
 
 				//客户研选行业转正时(王芳审批通过),模板消息提醒汪洋
 				services.AddCompanyApprovalMessageWangYang(recordInfo.CompanyId, recordInfo.CompanyContractId, recordInfo.ApplyRealName, companyInfo.CompanyName)

+ 7 - 2
services/company_approval_message.go

@@ -175,7 +175,7 @@ func AddCompanyMessage(createUserId, receiveUserId, companyId, companyApprovalId
 }
 
 // AddCompanyApprovalMessageRai 权益销售客户申请转正后,消息群发给所有销售
-func AddCompanyApprovalMessageRai(companyId, companyContractId int, applyRealName, companyName string) (err error) {
+func AddCompanyApprovalMessageRai(companyId, companyContractId int, applyRealName, companyName, wxUserName string) (err error) {
 	defer func() {
 		if err != nil {
 			fmt.Println("err:", err)
@@ -195,7 +195,12 @@ func AddCompanyApprovalMessageRai(companyId, companyContractId int, applyRealNam
 	}
 
 	var first, keyword1, keyword2, keyword3, keyword4 string
-	keyword1 = applyRealName + "已签约" + companyName
+
+	if wxUserName == "" {
+		keyword1 = applyRealName + "已签约" + companyName
+	} else {
+		keyword1 = wxUserName + "(" + companyName + ")"
+	}
 	keyword2 = time.Now().Format(utils.FormatDate)
 	keyword3 = contractDetail.StartDate
 	adminList, err := system.GetSysuserRaiList()