xingzai 1 год назад
Родитель
Сommit
2123136a2e

+ 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()

+ 22 - 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
@@ -561,12 +566,23 @@ func (this *UserController) ApplyTryOut() {
 		go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
 	}
 
-	err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, uid, user.CompanyId, CompanyIdType)
-	if err != nil {
-		br.Msg = "申请失败"
-		br.ErrMsg = "申请失败,Err:" + err.Error()
-		return
-	}
+	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)
 	//添加成功后,设置5分钟缓存,不允许重复添加
 	//utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
 

+ 16 - 13
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,7 @@ func AddApplyRecord(item *ApplyTryReq, mobile, companyNamePay string, userId, co
 			o.Commit()
 		}
 	}()
-
-	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()
+	_, err = o.Insert(item)
 	if err != nil {
 		return
 	}
@@ -42,7 +45,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
 }
 

+ 1 - 0
models/db.go

@@ -69,6 +69,7 @@ func init() {
 		new(CygxAboutUsVideoHistory),
 		new(CygxTacticsTimeLineHistory),
 		new(CygxBannerHistory),
+		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
+}

+ 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) {

+ 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
+}

+ 5 - 0
utils/constants.go

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