rdluck 4 years ago
parent
commit
9878c209c9
7 changed files with 224 additions and 16 deletions
  1. 14 7
      controllers/search.go
  2. 34 4
      controllers/user.go
  3. 48 5
      controllers/wechat.go
  4. 2 0
      models/db.go
  5. 70 0
      models/db_base.go
  6. 20 0
      models/search_key_word.go
  7. 36 0
      models/user_record.go

+ 14 - 7
controllers/search.go

@@ -3,6 +3,7 @@ package controllers
 import (
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
+	"time"
 )
 
 type SearchController struct {
@@ -26,14 +27,13 @@ func (this *SearchController) SearchList() {
 		br.ErrMsg = "请输入搜索词"
 		return
 	}
+	user := this.User
+	if user == nil {
+		br.Msg = "请重新登录"
+		br.Ret = 408
+		return
+	}
 	/*
-		user := this.User
-		if user == nil {
-			br.Msg = "请重新登录"
-			br.Ret = 408
-			return
-		}
-
 		categoryList, err := models.GetCategoryByCompanyId(user.CompanyId)
 		if err != nil {
 			br.Msg = "检索失败!"
@@ -59,6 +59,13 @@ func (this *SearchController) SearchList() {
 	if len(result) == 0 {
 		result = make([]*models.SearchItem, 0)
 	}
+	{
+		keyWordItem:=new(models.CygxSearchKeyWord)
+		keyWordItem.UserId=user.UserId
+		keyWordItem.KeyWord=keyWord
+		keyWordItem.CreateTime=time.Now()
+		go models.AddSearchKeyWord(keyWordItem)
+	}
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 34 - 4
controllers/user.go

@@ -74,6 +74,14 @@ func (this *UserController) Login() {
 				return
 			}
 		}
+
+		//更新用户记录信息
+		updateParams := make(map[string]interface{})
+		updateParams["Mobile"] = req.Mobile
+		updateParams["BindAccount"] = req.Mobile
+		whereParam := map[string]interface{}{"user_id": user.UserId, "create_platform": 4}
+		go models.UpdateByExpr(models.UserRecord{}, whereParam, updateParams)
+
 		//BindMobile(openId, mobile string, userId, loginType int) (err error) {
 		req.Mobile = strings.Trim(req.Mobile, " ")
 		req.LoginType = 1
@@ -105,6 +113,12 @@ func (this *UserController) Login() {
 			br.Msg = "验证码错误,请重新输入"
 			return
 		}
+		updateParams := make(map[string]interface{})
+		updateParams["Email"] = req.Email
+		updateParams["BindAccount"] = req.Email
+		whereParam := map[string]interface{}{"user_id": user.UserId, "create_platform": 4}
+		go models.UpdateByExpr(models.UserRecord{}, whereParam, updateParams)
+
 		newUserId, err = models.PcBindMobile(unionId, req.Email, userId, req.LoginType)
 	} else {
 		br.Msg = "无效的登录方式"
@@ -475,13 +489,13 @@ func (this *UserController) InterviewApplyList() {
 	for i := 0; i < lenList; i++ {
 		item := list[i]
 		article := articleMap[item.ArticleId]
-		bodySub,_:=services.GetReportContentTextSub(article.Body)
+		bodySub, _ := services.GetReportContentTextSub(article.Body)
 		list[i].Title = article.Title
 		list[i].TitleEn = article.TitleEn
 		list[i].UpdateFrequency = article.UpdateFrequency
 		list[i].CreateDate = article.CreateDate
 		list[i].PublishDate = article.PublishDate
-		list[i].Body=bodySub
+		list[i].Body = bodySub
 		list[i].Abstract = article.Abstract
 		list[i].CategoryName = article.CategoryName
 		list[i].SubCategoryName = article.SubCategoryName
@@ -693,8 +707,12 @@ func (this *UserController) ApplyTryOut() {
 		} else {
 			applyMethod = "潜在客户申请"
 		}
-		if sellerItem != nil && sellerItem.AdminId > 0 && mobile != "" && sellerItem.OpenId != "" {
-			go services.SendPermissionApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, sellerItem.OpenId, applyMethod)
+		cnf, _ := models.GetConfigByCode("tpl_msg")
+		if cnf != nil {
+			openIpItem, _ := models.GetWxUserItemByMobile(cnf.ConfigValue)
+			if openIpItem != nil && openIpItem.OpenId != "" {
+				go services.SendPermissionApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, openIpItem.OpenId, applyMethod)
+			}
 		}
 	}
 	err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, user.UserId, user.CompanyId)
@@ -709,3 +727,15 @@ func (this *UserController) ApplyTryOut() {
 	br.Success = true
 	br.Data = sellerMobile
 }
+
+//func init() {
+//	fmt.Println("start")
+//	realName:="沈涛"
+//	companyName:="弘则研究"
+//	mobile:="18767183922"
+//	openId:="oN0jD1eTfIAf68Y2n24RrvIGXFw4"
+//	applyMethod:="xxx"
+//	services.SendPermissionApplyTemplateMsg(realName, companyName, mobile, openId, applyMethod)
+//	return
+//	fmt.Println("end")
+//}

+ 48 - 5
controllers/wechat.go

@@ -29,7 +29,7 @@ func (this *WechatCommonController) WechatLogin() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	code:=this.GetString("Code")
+	code := this.GetString("Code")
 	if code == "" {
 		br.Msg = "参数错误"
 		br.ErrMsg = "Code 为空"
@@ -73,6 +73,28 @@ func (this *WechatCommonController) WechatLogin() {
 			return
 		}
 		userId = int(newId)
+		//新增用户记录
+		{
+			userRecord := new(models.UserRecord)
+			userRecord.UserId = int(newId)
+			userRecord.OpenId = user.OpenId
+			userRecord.UnionId = user.UnionId
+			userRecord.CompanyId = user.CompanyId
+			userRecord.NickName = user.NickName
+			userRecord.RealName = user.RealName
+			userRecord.Mobile = user.Mobile
+			userRecord.BindAccount = user.Mobile
+			userRecord.Email = user.Email
+			userRecord.Sex = user.Sex
+			userRecord.Province = user.Province
+			userRecord.City = user.City
+			userRecord.Country = user.Country
+			userRecord.Headimgurl = user.Headimgurl
+			userRecord.CreateTime = time.Now()
+			userRecord.CreatePlatform = 4
+			userRecord.SessionKey = user.SessionKey
+			go models.AddUserRecord(userRecord)
+		}
 	} else {
 		firstLogin = wxUser.FirstLogin
 		userId = wxUser.UserId
@@ -228,7 +250,20 @@ func (this *WechatController) GetUserInfo() {
 			}
 		}
 	}
-
+	//更新用户记录信息
+	{
+		updateParams := make(map[string]interface{})
+		updateParams["NickName"]=userInfo.Nickname
+		updateParams["Province"]=userInfo.Province
+		updateParams["City"]=userInfo.City
+		updateParams["Country"]=userInfo.Country
+		updateParams["Headimgurl"]=userInfo.Avatar
+		updateParams["Sex"]=userInfo.Gender
+		updateParams["Headimgurl"]=userInfo.Avatar
+		updateParams["UnionId"]=userInfo.UnionID
+		whereParam := map[string]interface{}{"user_id": user.UserId, "create_platform": 4}
+		go models.UpdateByExpr(models.UserRecord{}, whereParam, updateParams)
+	}
 	var token string
 	tokenItem, err := models.GetTokenByUid(userId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
@@ -318,6 +353,16 @@ func (this *WechatController) GetPhoneNumber() {
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
+
+	//更新用户记录信息
+	{
+		updateParams := make(map[string]interface{})
+		updateParams["Mobile"]=wxMobile.PhoneNumber
+		updateParams["BindAccount"]=wxMobile.PhoneNumber
+		whereParam := map[string]interface{}{"user_id": user.UserId, "create_platform": 4}
+		go models.UpdateByExpr(models.UserRecord{}, whereParam, updateParams)
+	}
+
 	resp := new(models.WxGetPhoneNumberResp)
 	resp.PhoneNumber = wxMobile.PhoneNumber
 	resp.PurePhoneNumber = wxMobile.PurePhoneNumber
@@ -328,7 +373,6 @@ func (this *WechatController) GetPhoneNumber() {
 	br.Data = resp
 }
 
-
 // @Title 获取短信验证码
 // @Description 获取短信验证码接口
 // @Param   Mobile   query   string  true       "手机号码"
@@ -377,7 +421,6 @@ func (this *WechatController) GetSmsCode() {
 	br.Success = true
 }
 
-
 // @Title 获取邮件验证码
 // @Description 获取邮件验证码接口
 // @Param   Email   query   string  true       "邮箱"
@@ -443,4 +486,4 @@ func (this *WechatController) GetEmailCode() {
 //	fmt.Println(userInfo)
 //	fmt.Println(err)
 //	fmt.Println("end")
-//}
+//}

+ 2 - 0
models/db.go

@@ -40,5 +40,7 @@ func init() {
 		new(CygxInterviewApply),
 		new(CygxArticle),
 		new(CygxArticleHistoryRecord),
+		new(CygxSearchKeyWord),
+		new(UserRecord),
 	)
 }

+ 70 - 0
models/db_base.go

@@ -0,0 +1,70 @@
+// @Time : 2020/10/29 8:31 下午
+// @Author : bingee
+package models
+
+import (
+	"rdluck_tools/orm"
+)
+
+// 是否存在
+func IsExistByExpr(ptrStructOrTableName interface{}, where map[string]interface{}) bool {
+	o := orm.NewOrm()
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range where {
+		qs = qs.Filter(expr, exprV)
+	}
+	return qs.Exist()
+}
+
+// 获取条数
+func GetCountByExpr(ptrStructOrTableName interface{}, where map[string]interface{}) (count int64, err error) {
+	o := orm.NewOrm()
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range where {
+		qs = qs.Filter(expr, exprV)
+	}
+	count, err = qs.Count()
+	return
+}
+
+// 更新
+func UpdateByExpr(ptrStructOrTableName interface{}, where, updateParams map[string]interface{}) error {
+	o := orm.NewOrm()
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range where {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err := qs.Update(updateParams)
+	return err
+}
+
+// 删除
+func DeleteByExpr(ptrStructOrTableName interface{}, where map[string]interface{}) error {
+	o := orm.NewOrm()
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range where {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err := qs.Delete()
+	return err
+}
+
+// 插入
+func InsertData(o orm.Ormer, ptrStructOrTableName interface{}) error {
+	_, err := o.Insert(ptrStructOrTableName)
+	return err
+}
+
+// 获取数据
+func GetDataByExpr(ptrStructOrTableName interface{}, where map[string]interface{}, data interface{}, page ...int64) (err error) {
+	o := orm.NewOrm()
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range where {
+		qs = qs.Filter(expr, exprV)
+	}
+	if len(page) > 1 {
+		qs = qs.Limit(page[1], page[0])
+	}
+	_, err = qs.All(data)
+	return err
+}

+ 20 - 0
models/search_key_word.go

@@ -0,0 +1,20 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+type CygxSearchKeyWord struct {
+	Id         int `orm:"column(id);" description:"id"`
+	KeyWord    string
+	UserId     int
+	CreateTime time.Time
+}
+
+//新增文章
+func AddSearchKeyWord(item *CygxSearchKeyWord) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}

+ 36 - 0
models/user_record.go

@@ -0,0 +1,36 @@
+package models
+
+import (
+	"rdluck_tools/orm"
+	"time"
+)
+
+type UserRecord struct {
+	UserRecordId   int       `orm:"column(user_record_id);pk"`
+	UserId         int       `description:"用户id"`
+	OpenId         string    `description:"open_id"`
+	UnionId        string    `description:"union_id"`
+	Subscribe      int       `description:"subscribe"`
+	CompanyId      int       `description:"客户id"`
+	NickName       string    `description:"用户昵称"`
+	RealName       string    `description:"用户实际名称"`
+	Mobile         string    `description:"手机号码"`
+	BindAccount    string    `description:"绑定时的账号"`
+	Email          string    `description:"邮箱"`
+	Sex            int       `description:"普通用户性别,1为男性,2为女性"`
+	Province       string    `description:"普通用户个人资料填写的省份"`
+	City           string    `description:"普通用户个人资料填写的城市"`
+	Country        string    `description:"国家,如中国为CN"`
+	SubscribeTime  string    `description:"关注时间"`
+	Headimgurl     string    `description:"头像"`
+	CreateTime     time.Time `description:"头像"`
+	CreatePlatform int       `description:"注册平台,1:日度点评公众号,2:管理后台,3:pc端网站,4:查研观向小程序"`
+	SessionKey     string    `description:"微信小程序会话密钥"`
+}
+
+//新增联系人记录
+func AddUserRecord(item *UserRecord) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}