Explorar o código

活动可见新增客户类型判断

xingzai %!s(int64=3) %!d(string=hai) anos
pai
achega
5b99f0ac83

+ 65 - 3
controllers/activity.go

@@ -256,6 +256,18 @@ func (this *ActivityCoAntroller) ActivityList() {
 	} else {
 		conditionOr += `	OR ( art.is_limit_people = 0 	  ` + condition + `) `
 	}
+
+	//判断客户规模是否属于可见范围的活动
+	companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+		return
+	}
+	if companyProduct.Scale != "" {
+		conditionOr += ` OR (  art.scale LIKE '%` + companyProduct.Scale + `%'	 ` + condition + `) `
+	}
+
 	condition += ` AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
 	total, err := models.GetActivityCount(condition, pars)
 	if err != nil {
@@ -404,7 +416,6 @@ func (this *ActivityCoAntroller) ScheduleList() {
 		return
 	}
 	var list []*models.CygxActivityList
-	fmt.Println(totalCount)
 	//全部都是进行中的活动
 	if totalCount > currentIndex*pageSize {
 		condition += ` AND art.active_state IN(2) `
@@ -432,7 +443,6 @@ func (this *ActivityCoAntroller) ScheduleList() {
 			br.ErrMsg = "获取失败,Err:" + errList.Error()
 			return
 		}
-		fmt.Println("长度", len(listOther))
 		if len(listOther) > 0 {
 			for _, v := range listOther {
 				list = append(list, v)
@@ -651,6 +661,18 @@ func (this *ActivityCoAntroller) Detail() {
 			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
 			return
 		}
+		//获取用户的产业规模,判断是否允许可见
+		companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+			return
+		}
+		if companyProduct.Scale != "" {
+			if strings.Count(activityInfo.Scale, companyProduct.Scale) > 0 {
+				noPower = false
+			}
+		}
 		if noPower {
 			br.Msg = "您暂无查看该活动权限"
 			br.ErrMsg = "被分享客户不可见,获取信息失败"
@@ -685,7 +707,6 @@ func (this *ActivityCoAntroller) Detail() {
 
 	if user.CompanyId > 1 {
 		permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
-		fmt.Println(permissionStr)
 		if err != nil {
 			br.Msg = "获取信息失败"
 			br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
@@ -2269,6 +2290,17 @@ func (this *ActivityCoAntroller) LabelTypeList() {
 		} else {
 			conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
 		}
+		//判断客户规模是否属于可见范围的活动
+		companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+			return
+		}
+		if companyProduct.Scale != "" {
+			conditionOr += ` OR (  art.scale LIKE '%` + companyProduct.Scale + `%'	 ` + condition + `) `
+		}
+
 		condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
 
 		sortTime = ` mintimesort ASC `
@@ -2418,6 +2450,16 @@ func (this *ActivityCoAntroller) LabelMoreList() {
 	} else {
 		conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
 	}
+	//判断客户规模是否属于可见范围的活动
+	companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+		return
+	}
+	if companyProduct.Scale != "" {
+		conditionOr += ` OR (  art.scale LIKE '%` + companyProduct.Scale + `%'	 ` + condition + `) `
+	}
 	condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
 
 	//进行中的活动
@@ -2609,6 +2651,16 @@ func (this *ActivityCoAntroller) ActivityListNew() {
 	} else {
 		conditionOr += `	OR ( art.is_limit_people = 0 	  ` + condition + `) `
 	}
+	//判断客户规模是否属于可见范围的活动
+	companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+		return
+	}
+	if companyProduct.Scale != "" {
+		conditionOr += ` OR (  art.scale LIKE '%` + companyProduct.Scale + `%'	 ` + condition + `) `
+	}
 
 	condition += ` AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
 	total, err := models.GetActivityCount(condition, pars)
@@ -2843,6 +2895,16 @@ func (this *ActivityCoAntroller) LabelTypeListPc() {
 		} else {
 			conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
 		}
+		//判断客户规模是否属于可见范围的活动
+		companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+			return
+		}
+		if companyProduct.Scale != "" {
+			conditionOr += ` OR (  art.scale LIKE '%` + companyProduct.Scale + `%'	 ` + condition + `) `
+		}
 		condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
 		sortTime = ` mintimesort ASC `
 		labelList, err := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)

+ 1 - 0
models/activity.go

@@ -96,6 +96,7 @@ type ActivityDetail struct {
 	LinkParticipants        string `description:"链接参会"`
 	AppAttendance           string `description:"App参会"`
 	ConferencePassword      string `description:"会议密码"`
+	Scale                   string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
 }
 
 type CygxActivityResp struct {

+ 3 - 2
models/company.go

@@ -176,8 +176,9 @@ func GetCompanySellerName(companyId int) (sellerName string, err error) {
 	return
 }
 
-type CompanyProductStatus struct {
-	IsSuspend int `description:"1:暂停,0:启用"`
+type CompanyProduct struct {
+	IsSuspend int    `description:"1:暂停,0:启用"`
+	Scale     string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
 }
 
 //获取对应销售以及销售的手机号

+ 9 - 9
models/send_company_user.go

@@ -47,7 +47,7 @@ type CompanyJsonList struct {
 }
 
 //获取公司
-func GetSendCompanyList() (items []*CompanyJson, err error) {
+func GetSendCompanyList(condition string) (items []*CompanyJson, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT
 			c.company_name,
@@ -85,15 +85,15 @@ func GetSendCompanyList() (items []*CompanyJson, err error) {
 			AND p.STATUS IN ( '正式', '试用' ) 
 			AND a.STATUS IN ( '正式', '试用' )
 			AND( c.credit_code LIKE '91%'  OR  c.credit_code LIKE 'HZ%' )
-			AND p.product_id = 2
-		GROUP BY
+			AND p.product_id = 2 ` + condition +
+		`GROUP BY 
 			c.company_id  `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
 
 //获取FICC公司
-func GetSendCompanyFiccList() (items []*CompanyJson, err error) {
+func GetSendCompanyFiccList(condition string) (items []*CompanyJson, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT
 			c.company_name,
@@ -136,8 +136,8 @@ func GetSendCompanyFiccList() (items []*CompanyJson, err error) {
 			AND p.STATUS IN ( '正式', '试用' ) 
 			AND a.STATUS IN ( '正式', '试用' ) 
 			AND ( c.credit_code LIKE '91%' OR c.credit_code LIKE 'HZ%' ) 
-			AND p.product_id = 1
-			AND c.company_id NOT IN (
+			AND p.product_id = 1 ` + condition +
+		`AND c.company_id NOT IN (
 			SELECT
 				c.company_id 
 			FROM
@@ -165,7 +165,7 @@ func GetSendCompanyFiccList() (items []*CompanyJson, err error) {
 }
 
 //获取用户
-func GetSendUserList() (items []*UserJson, err error) {
+func GetSendUserList(condition string) (items []*UserJson, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT
 			c.credit_code,
@@ -201,8 +201,8 @@ func GetSendUserList() (items []*UserJson, err error) {
 				AND b.cygx_auth = 1 
 				AND p.STATUS IN ( '正式', '试用' ) 
 				AND a.STATUS IN ( '正式', '试用' )
-				AND us.create_time  != ''
-			GROUP BY
+				AND us.create_time  != '' ` + condition +
+		`GROUP BY
 				c.company_id 
 			)
 			AND us.create_time != '' 

+ 1 - 1
services/activity.go

@@ -595,7 +595,7 @@ func ActivityAttendanceDetail(cont context.Context) (err error) {
 	}()
 
 	fmt.Println("开始同步")
-	dateTime := time.Now().AddDate(0, 0, -30).Format(utils.FormatDate)
+	dateTime := time.Now().AddDate(0, 0, -14).Format(utils.FormatDate)
 	dateNow := time.Now().AddDate(0, 0, 0).Format(utils.FormatDate)
 	startDate := dateTime + " 00:00:00"
 	endDate := dateNow + " 23:59:59"

+ 29 - 15
services/send_company_user.go

@@ -42,7 +42,13 @@ type ShangHaiResultApidateComPany struct {
 }
 
 //c
-func SendComapnyToShanghai(url, jsonCompany, postType string) {
+func SendComapnyToShanghai(url, jsonCompany, postType string) (err error) {
+	var msg string
+	defer func() {
+		if err != nil {
+			go utils.SendEmail("同步策略平台获取数据信息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToExpert)
+		}
+	}()
 	method := "POST"
 	//fmt.Println(string(jsonCompany))
 	//utils.FileLog.Info(string(jsonCompany))
@@ -50,29 +56,31 @@ func SendComapnyToShanghai(url, jsonCompany, postType string) {
 	client := &http.Client{}
 	req, err := http.NewRequest(method, url, payload)
 	if err != nil {
-		fmt.Println(err)
-		return
+		msg = "NewRequest Err:" + err.Error()
+		return err
 	}
 	req.Header.Add("Content-Type", "application/json")
 	res, err := client.Do(req)
 	if err != nil {
-		fmt.Println(err)
-		return
+		msg = "client.Do Err:" + err.Error()
+		return err
 	}
 	defer res.Body.Close()
 	body, err := ioutil.ReadAll(res.Body)
 	if err != nil {
-		fmt.Println(err)
-		return
+		msg = "ioutil.ReadAll Err:" + err.Error()
+		return err
 	}
 	var result GetShangHaiTokenResultApiComPany
 	err = json.Unmarshal(body, &result)
 	if err != nil {
-		fmt.Println("Getres.pdfResult Err:", err.Error())
-	}
-	if result.Code != 1 {
-		go utils.SendEmail("同步策略平台信息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), url, utils.EmailSendToExpert)
+		msg = "json.Unmarshal Err:" + err.Error()
+		return err
+
 	}
+	//if result.Code != 1 {
+	//	go utils.SendEmail("同步策略平台信息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), url, utils.EmailSendToExpert)
+	//}
 	item := new(models.CygxShanghaiCompanyLog)
 	item.CreateTime = time.Now()
 	item.Url = url
@@ -95,6 +103,7 @@ func SendComapnyToShanghai(url, jsonCompany, postType string) {
 			go models.AddCygxShanghaiErrLog(item)
 		}
 	}
+	return
 	//给产品导数据用,别删
 	//companyCode = postType + companyCode
 	////fmt.Println(result.Data.FailInfo)
@@ -110,6 +119,11 @@ func DotongbuShangHai(cont context.Context) (err error) {
 			go utils.SendEmail("同步策略平台获取数据信息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToExpert)
 		}
 	}()
+	//同步24小时之前的数据到上海平台,为防止遗漏改成30小时
+	var condition string
+	updateTime := time.Now().Add(-time.Hour * 30).Format("2006-01-02 15:04:05")
+	condition = ` AND p.modify_time > ` + "'" + updateTime + "'"
+	fmt.Println(condition)
 	//获取token
 	url := "https://crm.hzinsights.com/openapi/v1/auth/getAccessToken?app_key=26945134&app_secret=b99cb2bdec70d20156000f664ec5ac30"
 	method := "GET"
@@ -139,7 +153,7 @@ func DotongbuShangHai(cont context.Context) (err error) {
 	accessToken := result.Data.AccessToken
 	fmt.Println(accessToken)
 	//同步权益客户
-	companyList, err := models.GetSendCompanyList()
+	companyList, err := models.GetSendCompanyList(condition)
 	if err != nil {
 		msg = "GetSendCompanyList Err:" + err.Error()
 		return
@@ -179,7 +193,7 @@ func DotongbuShangHai(cont context.Context) (err error) {
 		}
 	}
 	//同步FICC客户
-	companyFiccList, err := models.GetSendCompanyFiccList()
+	companyFiccList, err := models.GetSendCompanyFiccList(condition)
 	if err != nil {
 		msg = "GetSendCompanyFiccList Err:" + err.Error()
 		return err
@@ -218,12 +232,12 @@ func DotongbuShangHai(cont context.Context) (err error) {
 		}
 	}
 
-	userList, err := models.GetSendUserList()
+	userList, err := models.GetSendUserList(condition)
 	if err != nil {
 		msg = "GetSendUserList Err:" + err.Error()
 		return err
 	}
-	fmt.Println("userList", len(userList))
+	fmt.Println("用户", len(userList))
 	var userItems []*models.UserJson
 	if len(userList) > 0 {
 		url = "https://crm.hzinsights.com/openapi/v1/CustomerContact/batchSyncFiccCustomerContact?access_token=" + accessToken