Browse Source

Merge branch 'master' of http://8.136.199.33:3000/cxzhang/hongze_clpt into cygx_10.7

xingzai 1 year ago
parent
commit
34740d0429

+ 2 - 0
controllers/base_auth.go

@@ -39,6 +39,7 @@ func (this *BaseAuthController) Prepare() {
 	if method != "HEAD" {
 		if method == "POST" || method == "GET" {
 			authorization := this.Ctx.Input.Header("Authorization")
+			inviteCompany := this.Ctx.Input.Header("From")
 			if authorization == "" {
 				authorization = this.GetString("Authorization")
 			}
@@ -83,6 +84,7 @@ func (this *BaseAuthController) Prepare() {
 				}
 				this.User = wxUser
 			}
+			this.User.InviteCompany = inviteCompany
 		} else {
 			this.JSON(models.BaseResponse{Ret: 408, Msg: "请求异常,请联系客服!", ErrMsg: "POST之外的请求,暂不支持"}, false, false)
 			this.StopRun()

+ 3 - 0
controllers/base_auth_mobile.go

@@ -38,6 +38,7 @@ func (this *BaseAuthMobileController) Prepare() {
 	if method != "HEAD" {
 		if method == "POST" || method == "GET" {
 			authorization := this.Ctx.Input.Header("Authorization")
+			inviteCompany := this.Ctx.Input.Header("From")
 			if authorization == "" {
 				authorization = this.GetString("Authorization")
 			}
@@ -81,6 +82,8 @@ func (this *BaseAuthMobileController) Prepare() {
 				}
 				this.User = wxUser
 			}
+			this.User.InviteCompany = inviteCompany
+			go services.AddCygxPageHistoryRecord(this.User, this.Ctx)
 		} else {
 			this.JSON(models.BaseResponse{Ret: 408, Msg: "请求异常,请联系客服!", ErrMsg: "POST之外的请求,暂不支持"}, false, false)
 			this.StopRun()

+ 35 - 6
controllers/user.go

@@ -123,6 +123,11 @@ func (this *UserCommonController) Login() {
 			return
 		}
 	}
+
+	//记录通过三方合作机构过来的公司
+	{
+		services.AddInviteCompany(user)
+	}
 	resp := new(models.LoginResp)
 	resp.UserId = user.UserId
 	resp.Headimgurl = user.Headimgurl
@@ -525,7 +530,7 @@ func (this *UserController) ApplyTryOut() {
 					req.RealName = user.RealName
 					req.CompanyName = user.CompanyName
 				}
-				go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
+				//go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
 			}
 		}
 	} else {
@@ -556,17 +561,41 @@ func (this *UserController) ApplyTryOut() {
 	//	utils.FileLog.Info("推送消息 %s %s,%s,%s,%s", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
 	//	go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
 	//}
-	//如果对应销售不存在就给王芳,汪洋推模版消息
-	if sellerItem == nil {
-		go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
-	}
 
-	err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, uid, user.CompanyId, CompanyIdType)
+	//go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
+
+	item := new(models.CygxApplyRecord)
+	item.UserId = user.UserId
+	item.BusinessCardUrl = req.BusinessCardUrl
+	item.RealName = req.RealName
+	item.CompanyName = req.CompanyName
+	item.Mobile = user.Mobile
+	item.CreateTime = time.Now()
+	item.ApplyMethod = req.ApplyMethod
+	item.CompanyIdPay = user.CompanyId
+	item.CompanyNamePay = user.CompanyName
+	item.CompanyIdType = CompanyIdType
+	if user.InviteCompany == utils.LUODING_CODE && user.CompanyId == 1 {
+		//如果是潜在客户就标记来源
+		item.InviteCompanySource = 2
+	}
+	item.RegisterPlatform = utils.REGISTER_PLATFORM
+	err = models.AddApplyRecord(item)
+
 	if err != nil {
 		br.Msg = "申请失败"
 		br.ErrMsg = "申请失败,Err:" + err.Error()
 		return
 	}
+	if sellerItem == nil {
+		go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
+	} else {
+		openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
+		if openIpItem != nil && openIpItem.OpenId != "" {
+			go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
+		}
+	}
+
 	//添加成功后,设置5分钟缓存,不允许重复添加
 	//utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
 

+ 24 - 12
models/apply_record.go

@@ -6,16 +6,22 @@ import (
 )
 
 type CygxApplyRecord struct {
-	ApplyRecordId   int       `orm:"column(apply_record_id);pk" description:"申请试用id"`
-	BusinessCardUrl string    `description:"名片地址"`
-	RealName        string    `description:"姓名"`
-	CompanyName     string    `description:"公司名称"`
-	Mobile          string    `description:"手机号"`
-	CreateTime      time.Time `description:"创建时间"`
-	ApplyMethod     int       `description:"1:已付费客户申请试用,2:非客户申请试用"`
+	ApplyRecordId       int       `orm:"column(apply_record_id);pk" description:"申请试用id"`
+	UserId              int       `description:"用户ID"`
+	BusinessCardUrl     string    `description:"名片地址"`
+	RealName            string    `description:"姓名"`
+	CompanyName         string    `description:"公司名称"`
+	CompanyIdPay        int       `description:"已付费客户公司id"`
+	CompanyIdType       int       `description:"用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限)  、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失) "`
+	CompanyNamePay      string    `description:"公司名称"`
+	Mobile              string    `description:"手机号"`
+	CreateTime          time.Time `description:"创建时间"`
+	ApplyMethod         int       `description:"1:已付费客户申请试用,2:非客户申请试用"`
+	RegisterPlatform    int       `description:"来源 1小程序,2:网页"`
+	InviteCompanySource int       `description:"来源 1小程序,2:网页"`
 }
 
-func AddApplyRecord(item *ApplyTryReq, mobile, companyNamePay string, userId, companyIdPay, CompanyIdType int) (err error) {
+func AddApplyRecord(item *CygxApplyRecord) (err error) {
 	o, err := orm.NewOrm().Begin()
 	if err != nil {
 		return
@@ -27,10 +33,8 @@ func AddApplyRecord(item *ApplyTryReq, mobile, companyNamePay string, userId, co
 			o.Commit()
 		}
 	}()
+	_, err = o.Insert(item)
 
-	sql := `INSERT INTO cygx_apply_record (user_id,business_card_url, real_name,company_name, mobile,create_time, apply_method,company_id_pay,company_name_pay,company_id_type)
-          VALUES(?,?,?,?,?,?,?,?,?,?) `
-	_, err = o.Raw(sql, userId, item.BusinessCardUrl, item.RealName, item.CompanyName, mobile, time.Now(), item.ApplyMethod, companyIdPay, companyNamePay, CompanyIdType).Exec()
 	if err != nil {
 		return
 	}
@@ -42,7 +46,7 @@ func AddApplyRecord(item *ApplyTryReq, mobile, companyNamePay string, userId, co
           real_name=?,
 		  mobile=?
 		WHERE user_id = ? `
-	_, err = o.Raw(msql, item.CompanyName, item.ApplyMethod, item.RealName, mobile, userId).Exec()
+	_, err = o.Raw(msql, item.CompanyName, item.ApplyMethod, item.RealName, item.Mobile, item.UserId).Exec()
 	return
 }
 
@@ -52,3 +56,11 @@ func GetApplyRecordCount(userId int) (count int, err error) {
 	err = o.Raw(sql, userId).QueryRow(&count)
 	return
 }
+
+// 通过手机号获取详情
+func GetCygxApplyRecordByMobile(mobile string) (item *CygxApplyRecord, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_apply_record   WHERE mobile=? AND status=0   ORDER BY apply_record_id DESC   LIMIT 1 `
+	err = o.Raw(sql, mobile).QueryRow(&item)
+	return
+}

+ 2 - 0
models/db.go

@@ -72,6 +72,8 @@ func init() {
 		new(CygxBannerHistory),
 		new(CygxReportHistoryRecordLog),
 		new(CygxUserLabel),
+		new(CygxInviteCompany),
+		new(CygxApplyRecord),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 23 - 0
models/invite_company.go

@@ -0,0 +1,23 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxInviteCompany struct {
+	Id         int       `gorm:"column:id;primary_key;AUTO_INCREMENT" json:"id"`
+	UserId     int       `gorm:"column:user_id" json:"user_id"`                            // 用户ID
+	Mobile     string    `gorm:"column:mobile" json:"mobile"`                              // 手机号
+	Email      string    `gorm:"column:email" json:"email"`                                // 邮箱
+	Source     int       `gorm:"column:source;default:1;NOT NULL" json:"source"`           // 来源,1络町
+	SourceCode string    `gorm:"column:source_code;default:1;NOT NULL" json:"source_code"` // 来源编码
+	CreateTime time.Time `gorm:"column:create_time" json:"create_time"`                    // 创建时间
+}
+
+// 添加
+func AddCygxInviteCompany(item *CygxInviteCompany) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}

+ 5 - 0
models/page_history_record.go

@@ -21,6 +21,7 @@ type CygxPageHistoryRecord struct {
 	Parameter              string    `description:"参数"`
 	Router                 string    `description:"路由"`
 	PageRouter             string    `description:"前端页面路径"`
+	RegisterPlatform       int       `description:"来源 1小程序,2:网页"`
 }
 
 type CygxPageHistoryRecordRep struct {
@@ -47,6 +48,10 @@ func AddCygxPageHistoryRecord(item *CygxPageHistoryRecord) (lastId int64, err er
 	return
 }
 
+type PageRouter struct {
+	PageRouter string
+}
+
 func GetTimeLineRecordCount(userId, industrialManagementId int) (count int, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT COUNT(1) AS count FROM cygx_page_history_record WHERE user_id=? AND router = '/api/report/industry/ArticleList?PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=` + strconv.Itoa(industrialManagementId) + `'`

+ 1 - 0
models/wx_user.go

@@ -78,6 +78,7 @@ type WxUserItem struct {
 	Source              int
 	IsMaker             int    `description:"是否是决策人"`
 	Position            string `description:"职务"`
+	InviteCompany       string `description:"邀请机构 ,LUODING:络町"`
 }
 
 func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {

+ 1 - 1
routers/router.go

@@ -17,7 +17,7 @@ func init() {
 	web.InsertFilter("*", web.BeforeRouter, cors.Allow(&cors.Options{
 		AllowAllOrigins:  true,
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
-		AllowHeaders:     []string{"Origin", "Account", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
+		AllowHeaders:     []string{"Origin", "Account", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "From"},
 		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type", "Sign"},
 		AllowCredentials: true,
 	}))

+ 38 - 0
services/invite_company.go

@@ -0,0 +1,38 @@
+package services
+
+import (
+	"errors"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"strconv"
+	"time"
+)
+
+// 记录通过三方合作机构过来的公司
+func AddInviteCompany(user *models.WxUserItem) (err error) {
+	defer func() {
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			go utils.SendAlarmMsg("记录通过三方合作机构过来的公司失败"+err.Error()+"uid:"+strconv.Itoa(user.UserId), 2)
+		}
+	}()
+	item := new(models.CygxInviteCompany)
+	if user.InviteCompany != utils.LUODING_CODE {
+		return
+	} else {
+		item.Source = 2
+	}
+	// 非潜在客户不记录
+	if user.CompanyId != 1 {
+		return
+	}
+	item.UserId = user.UserId
+	item.Mobile = user.Mobile
+	item.Email = user.Email
+	item.SourceCode = user.InviteCompany
+	item.CreateTime = time.Now()
+	e := models.AddCygxInviteCompany(item)
+	if e != nil {
+		err = errors.New("AddCygxInviteCompany, Err: " + e.Error())
+	}
+	return
+}

+ 72 - 0
services/page_history_record.go

@@ -0,0 +1,72 @@
+package services
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/beego/beego/v2/server/web/context"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"strings"
+	"time"
+)
+
+func AddCygxPageHistoryRecord(user *models.WxUserItem, Ctx *context.Context) {
+	item := new(models.CygxPageHistoryRecord)
+	item.UserId = user.UserId
+	item.CreateTime = time.Now()
+	item.Mobile = user.Mobile
+	item.Email = user.Email
+	item.CompanyId = user.CompanyId
+	item.CompanyName = user.CompanyName
+	item.Router = Ctx.Request.RequestURI
+	item.PageRouter = Ctx.Input.Query("PageRouter")
+	if user.InviteCompany != "" {
+		item.Router += "&From=" + user.InviteCompany
+	}
+	item.RegisterPlatform = utils.REGISTER_PLATFORM
+	index := strings.Index(item.Router, "?")
+	if index != -1 {
+		item.Parameter = item.Router[index+1:]
+	}
+	if Ctx.Input.Method() == "POST" && string(Ctx.Input.RequestBody) != "" {
+		item.Parameter = string(Ctx.Input.RequestBody)
+		var pr models.PageRouter
+		err := json.Unmarshal(Ctx.Input.RequestBody, &pr)
+		if err != nil {
+			fmt.Println(err)
+			utils.FileLog.Info(err.Error())
+		}
+		item.PageRouter = pr.PageRouter
+	}
+	if strings.Contains(item.Router, "/api/article/detail") {
+		//cacheKey := fmt.Sprint("uid:", user.UserId, "_Parameter:", item.Parameter)
+		//isExist := utils.Rc.IsExist(cacheKey)
+		//if !isExist {
+		//	setNX := utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
+		//	if !setNX {
+		//		go utils.SendAlarmMsg("记录用户阅读文章,设置Redis Key 过期时间失败:key"+cacheKey, 3)
+		//	}
+		//	return
+		//}
+
+		sliceParameter := strings.Split(item.Parameter, "&PageRouter=")
+		cacheKey := fmt.Sprint("uid:", user.UserId, "_Parameter:", sliceParameter[0])
+		isExist := utils.Rc.IsExist(cacheKey)
+		if isExist {
+			return
+		}
+		setNX := utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
+		if !setNX {
+			if !setNX {
+				go utils.SendAlarmMsg("记录用户阅读文章,设置Redis Key 过期时间失败:key"+cacheKey, 3)
+			}
+		}
+	}
+
+	_, err := models.AddCygxPageHistoryRecord(item)
+	if err != nil {
+		fmt.Println(err)
+		utils.FileLog.Info(err.Error())
+		return
+	}
+}

+ 10 - 0
services/wechat_send_msg.go

@@ -9,6 +9,7 @@ import (
 	"hongze/hongze_clpt/utils"
 	"io/ioutil"
 	"net/http"
+	"strconv"
 	"strings"
 	"time"
 )
@@ -170,6 +171,15 @@ func SendPermissionApplyTemplateMsg(realName, companyName, mobile, applyMethod s
 	var keyword4 string
 	var remark string
 	var redirectUrl string
+	detail, e := models.GetCygxApplyRecordByMobile(mobile)
+	if e != nil {
+		err = errors.New("GetActivitySignupNomeetingCountList" + e.Error())
+		return
+	}
+	//如果是潜在客户就推送可查看详情的模版消息
+	if detail.ApplyMethod == 2 {
+		redirectUrl = utils.WX_MSG_PATH_APPLY_DETAIL + strconv.Itoa(detail.ApplyRecordId)
+	}
 	keyword1 = "权限申请:" + realName + "【" + companyName + "】"
 	keyword2 = mobile
 	keyword3 = time.Now().Format(utils.FormatDateTime)

+ 6 - 0
utils/constants.go

@@ -146,6 +146,11 @@ const (
 	CYGX_USER_KEY_LABEL = "CYGX_USER_KEY_LABEL" //查研观向用户标签
 )
 
+// 邀请机构标识
+const (
+	LUODING_CODE = "LUODING" //络町
+)
+
 const (
 	//专项调研背景图片
 	//ACTIVITY_ZXDY_ImgUrl1 = "https://hzstatic.hzinsights.com/static/temp/20220427202204/20220427/b2Bj3fGakP16iJRFKisQohCWnCNl.png"
@@ -170,6 +175,7 @@ const (
 	WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL  = "activityPages/specialDetail/specialDetail?id="   //专项调研活动模板消息地址
 	WX_MSG_PATH_ACTIVITY_INDUSTRYR_EPORT = "reportPages/IndustryReport/IndustryReport?id="   //产业文章列表模板消息地址
 	WX_MSG_PATH_ACTIVITY_DETAIL          = "activityPages/activityDetail/activityDetail?id=" //活动模板消息地址
+	WX_MSG_PATH_APPLY_DETAIL             = "pages-message/applyFor/applyFor?id="             //潜在用户试用权限申请
 )
 
 // 微信模板消息推送公共接口的秘钥