Quellcode durchsuchen

查研观向10.5.3,络町

xingzai vor 1 Jahr
Ursprung
Commit
ba089241f7

+ 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")
 			}
@@ -81,6 +82,7 @@ func (this *BaseAuthController) Prepare() {
 				this.StopRun()
 				return
 			}
+			wxUser.InviteCompany = inviteCompany
 			this.User = wxUser
 			go services.AddCygxPageHistoryRecord(this.User, this.Ctx)
 		} else {

+ 35 - 19
controllers/user.go

@@ -192,6 +192,12 @@ func (this *UserController) Login() {
 	{
 		services.UpdateCygxSubscribe(userId, unionId)
 	}
+
+	//记录通过三方合作机构过来的公司
+	{
+		services.AddInviteCompany(user)
+	}
+
 	resp := new(models.LoginResp)
 	resp.UserId = userId
 	resp.Authorization = token
@@ -1115,25 +1121,24 @@ func (this *UserController) ApplyTryOut() {
 			applyMethod = applyMethod + "," + title
 		}
 	}
-	//var configCode string
-	////如果是研选的就推送给汪洋,否则就推送给王芳
-	//if isResearch {
-	//	configCode = "tpl_msg_wang_yang"
-	//} else {
-	//	configCode = "tpl_msg"
-	//}
-	//cnf, _ := models.GetConfigByCode(configCode)
-	//openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
-	//if openIpItem != nil && openIpItem.OpenId != "" {
-	//	if req.ApplyMethod != 2 {
-	//		req.RealName = user.RealName
-	//		req.CompanyName = user.CompanyName
-	//	}
-	//	go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
-	//}
-	//如果对应销售不存在就给王芳,汪洋推模版消息
 
-	err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, uid, user.CompanyId, CompanyIdType)
+	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()
@@ -1805,7 +1810,7 @@ func (this *UserController) ApplyDetail() {
 		br.Ret = 408
 		return
 	}
-	resp := new(models.CygxApplyRecordResp)
+	resp := new(models.CygxApplyRecordDetialResp)
 	applyRecordId, _ := this.GetInt("ApplyRecordId")
 	detail, err := models.GetCygxApplyRecordById(applyRecordId)
 	if err != nil {
@@ -1813,6 +1818,17 @@ func (this *UserController) ApplyDetail() {
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
 		return
 	}
+	switch detail.RegisterPlatform {
+	case 1:
+		detail.ApplicationSource = "小程序"
+	case 2:
+		detail.ApplicationSource = "网页版"
+	}
+
+	switch detail.InviteCompanySource {
+	case 2:
+		detail.ApplicationSource += "(络町)"
+	}
 	resp.Detail = detail
 	br.Msg = "申请成功!"
 	br.Ret = 200

+ 62 - 13
models/apply_record.go

@@ -6,18 +6,39 @@ import (
 )
 
 type CygxApplyRecord struct {
-	ApplyRecordId    int       `orm:"column(apply_record_id);pk" description:"申请试用id"`
-	BusinessCardUrl  string    `description:"名片地址"`
-	RealName         string    `description:"姓名"`
-	CompanyName      string    `description:"公司名称"`
-	CompanyNamePay   string    `description:"公司名称"`
-	Mobile           string    `description:"手机号"`
-	CreateTime       time.Time `description:"创建时间"`
-	ApplyMethod      int       `description:"1:已付费客户申请试用,2:非客户申请试用"`
-	RegisterPlatform 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) {
+type CygxApplyRecordResp struct {
+	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:络町"`
+	ApplicationSource   string    `description:"申请来源"`
+}
+
+func AddApplyRecordold(item *ApplyTryReq, mobile, companyNamePay string, userId, companyIdPay, CompanyIdType int) (err error) {
 	o, err := orm.NewOrm().Begin()
 	if err != nil {
 		return
@@ -48,6 +69,34 @@ func AddApplyRecord(item *ApplyTryReq, mobile, companyNamePay string, userId, co
 	return
 }
 
+func AddApplyRecord(item *CygxApplyRecord) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+	}()
+	_, err = o.Insert(item)
+	if err != nil {
+		return
+	}
+	msql := `UPDATE  wx_user
+		SET
+		  note = ?,
+		  is_note = 1,
+		  apply_method = ?,
+          real_name=?,
+		  mobile=?
+		WHERE user_id = ? `
+	_, err = o.Raw(msql, item.CompanyName, item.ApplyMethod, item.RealName, item.Mobile, item.UserId).Exec()
+	return
+}
+
 func GetApplyRecordCount(userId int) (count int, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT COUNT(1) AS count FROM cygx_apply_record WHERE user_id=? AND status=0 `
@@ -64,13 +113,13 @@ func GetCygxApplyRecordByMobile(mobile string) (item *CygxApplyRecord, err error
 }
 
 // 通过ID获取详情
-func GetCygxApplyRecordById(applyRecordId int) (item *CygxApplyRecord, err error) {
+func GetCygxApplyRecordById(applyRecordId int) (item *CygxApplyRecordResp, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM cygx_apply_record  WHERE apply_record_id=?  `
 	err = o.Raw(sql, applyRecordId).QueryRow(&item)
 	return
 }
 
-type CygxApplyRecordResp struct {
-	Detail *CygxApplyRecord
+type CygxApplyRecordDetialResp struct {
+	Detail *CygxApplyRecordResp
 }

+ 1 - 0
models/db.go

@@ -151,6 +151,7 @@ func init() {
 		new(CygxUserLabelActivity),
 		new(CygxUserLabelArticle),
 		new(CygxUserLabelActivitySpecial),
+		new(CygxInviteCompany),
 	)
 	// 记录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 - 4
models/page_history_record.go

@@ -21,6 +21,7 @@ type CygxPageHistoryRecord struct {
 	Router                 string    `description:"路由"`
 	PageRouter             string    `description:"前端页面路径"`
 	Parameter              string    `description:"参数"`
+	RegisterPlatform       int       `description:"来源 1小程序,2:网页"`
 }
 
 type CygxPageHistoryRecordRep struct {
@@ -40,7 +41,7 @@ type CygxPageHistoryRecordHtgjRep struct {
 	Sign                   string `description:"签名"`
 }
 
-//添加
+// 添加
 func AddCygxPageHistoryRecord(item *CygxPageHistoryRecord) (lastId int64, err error) {
 	o := orm.NewOrm()
 	lastId, err = o.Insert(item)
@@ -53,14 +54,14 @@ type PageRouter struct {
 
 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)+`'`
+	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) + `'`
 	err = o.Raw(sql, userId).QueryRow(&count)
 	return
 }
 
 func GetTimeLineRecordItem(userId, industrialManagementId int) (item *CygxPageHistoryRecord, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM cygx_page_history_record WHERE user_id=? AND router = '/api/report/industry/ArticleList?PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=`+strconv.Itoa(industrialManagementId)+ `' ORDER BY create_time DESC LIMIT 1,1 `
+	sql := `SELECT * FROM cygx_page_history_record WHERE user_id=? AND router = '/api/report/industry/ArticleList?PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=` + strconv.Itoa(industrialManagementId) + `' ORDER BY create_time DESC LIMIT 1,1 `
 	err = o.Raw(sql, userId).QueryRow(&item)
 	return
 }
@@ -70,4 +71,4 @@ func GetTimeLineRecordAllCount(userId int, date string) (items []*CygxPageHistor
 	sql := `SELECT * FROM cygx_page_history_record WHERE user_id=? AND router LIKE '%/api/report/industry/ArticleList?PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=%' AND create_time > ? `
 	_, err = o.Raw(sql, userId, date).QueryRows(&items)
 	return
-}
+}

+ 1 - 0
models/wx_user.go

@@ -85,6 +85,7 @@ type WxUserItem struct {
 	IsMsgOutboundMobile int       `description:"是否弹窗过绑定外呼手机号区号"`
 	IsMaker             int       `description:"是否是决策人"`
 	Position            string    `description:"职务"`
+	InviteCompany       string    `description:"邀请机构 ,LUODING:络町"`
 	Source              int
 }
 

+ 38 - 0
services/invite_company.go

@@ -0,0 +1,38 @@
+package services
+
+import (
+	"errors"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/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
+}

+ 4 - 0
services/page_history_record.go

@@ -20,6 +20,10 @@ func AddCygxPageHistoryRecord(user *models.WxUserItem, Ctx *context.Context) {
 	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:]

+ 0 - 2
services/wechat_send_msg.go

@@ -110,9 +110,7 @@ func SendPermissionApplyTemplateMsg(realName, companyName, mobile, applyMethod s
 		if err != nil {
 			go utils.SendAlarmMsg(fmt.Sprint("权限申请模板消息推送消息失败,手机号", mobile, "公司:", companyName, "手机号:", mobile, ";Err:"+err.Error()), 2)
 		}
-
 	}()
-
 	var first string
 	var keyword1 string
 	var keyword2 string

+ 5 - 0
utils/constants.go

@@ -129,6 +129,11 @@ const (
 	SHANG_HAI_CRM_API_TOKEN = "SHANG_HAI_CRM_API_TOKEN"
 )
 
+// 邀请机构标识
+const (
+	LUODING_CODE = "LUODING" //络町
+)
+
 const (
 	//专项调研背景图片
 	//ACTIVITY_ZXDY_ImgUrl1 = "https://hzstatic.hzinsights.com/static/temp/20220427202204/20220427/b2Bj3fGakP16iJRFKisQohCWnCNl.png"