xingzai 1 vuosi sitten
vanhempi
commit
57c4185a79

+ 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("InviteCompany")
 			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 {

+ 19 - 16
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,26 +1121,23 @@ 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)
-	//}
 	//如果对应销售不存在就给王芳,汪洋推模版消息
 	if sellerItem == nil {
 		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
+
 	err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, uid, user.CompanyId, CompanyIdType)
 	if err != nil {
 		br.Msg = "申请失败"

+ 34 - 0
models/apply_record.go

@@ -7,9 +7,12 @@ import (
 
 type CygxApplyRecord 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:"创建时间"`
@@ -17,6 +20,37 @@ type CygxApplyRecord struct {
 	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
 }
 
+func AddApplyRecordold(item *ApplyTryReq, mobile, companyNamePay string, userId, companyIdPay, CompanyIdType int) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			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()
+	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, mobile, userId).Exec()
+	return
+}
+
 func AddApplyRecord(item *ApplyTryReq, mobile, companyNamePay string, userId, companyIdPay, CompanyIdType int) (err error) {
 	o, err := orm.NewOrm().Begin()
 	if err != nil {

+ 1 - 0
models/db.go

@@ -147,6 +147,7 @@ func init() {
 		new(CygxActivitySignupBreak),
 		new(CygxBannerHistory),
 		new(CygxReportHistoryRecordLog),
+		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

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

+ 5 - 0
utils/constants.go

@@ -127,6 +127,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"