Browse Source

合并master分支

xingzai 3 years ago
parent
commit
2962b3f119
5 changed files with 51 additions and 9 deletions
  1. 17 0
      controllers/article.go
  2. 2 2
      models/tactics.go
  3. 19 0
      models/wx_user.go
  4. 1 1
      services/tactics.go
  5. 12 6
      services/user.go

+ 17 - 0
controllers/article.go

@@ -115,6 +115,23 @@ func (this *ArticleController) Detail() {
 					hasPermission = 3
 				}
 			}
+			if hasPermission == 1 {
+				key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
+				if !utils.Rc.IsExist(key) {
+					//新增浏览记录
+					record := new(models.CygxArticleViewRecord)
+					record.UserId = uid
+					record.ArticleId = articleId
+					record.CreateTime = time.Now()
+					record.Mobile = user.Mobile
+					record.Email = user.Email
+					record.CompanyId = user.CompanyId
+					record.CompanyName = user.CompanyName
+					go models.AddCygxArticleViewRecord(record)
+					utils.Rc.Put(key, 1, 5*time.Second)
+					models.ModifyReportLastViewTime(uid)
+				}
+			}
 		}
 		collectCount, err := models.GetArticleCollectCount(uid, articleId)
 		if err != nil && err.Error() != utils.ErrNoRow() {

+ 2 - 2
models/tactics.go

@@ -31,7 +31,7 @@ func GetTacticsList(endDate string) (list []*Tactics, err error) {
 				INNER JOIN article_content AS b ON a.id=b.article_id
 				INNER JOIN article_category AS c ON a.id=c.article_id
 				INNER JOIN article_categoryinfo AS d ON c.category_id=d.id
-				WHERE a.publish_status=1 AND a.publish_date>=? AND d.id IN (28,32,45,50,57,62,72,74,79,84,86,88,90) 
+				WHERE a.publish_status=1 AND a.publish_date>=? AND d.id IN (28,32,45,50,57,62,72,74,79,84,86,88,90,95,96) 
                 AND a.id NOT IN (3454,3456,3457,3459,2449,2450,2453,2454,2459,2530,2583,2663,2670,2699,2715,2732,2748,2759,2399,2356,2870,3173,2978,2826,3470) `
 	_, err = o.Raw(sql, endDate).QueryRows(&list)
 	return
@@ -45,7 +45,7 @@ func GetTacticsListAll() (list []*Tactics, err error) {
 			INNER JOIN article_content AS b ON a.id=b.article_id
 			INNER JOIN article_category AS c ON a.id=c.article_id
 			INNER JOIN article_categoryinfo AS d ON c.category_id=d.id
-			WHERE a.publish_status=1 AND d.id IN (28,32,45,50,57,62,72,74,79,84,86,88,90) 
+			WHERE a.publish_status=1 AND d.id IN (28,32,45,50,57,62,72,74,79,84,86,88,90,96) 
             AND a.id NOT IN (3454,3456,3457,3459,2449,2450,2453,2454,2459,2530,2583,2663,2670,2699,2715,2732,2748,2759,2399,2356,2870,3173,2978,2826,3470) `
 	//IN(85,71)
 	_, err = o.Raw(sql).QueryRows(&list)

+ 19 - 0
models/wx_user.go

@@ -43,6 +43,8 @@ type WxUser struct {
 	IsFreeLogin      bool      `description:"是否免登陆,true:免登陆,false:非免登陆"`
 	LoginTime        time.Time `description:"最近一次登录时间"`
 	SessionKey       string    `description:"微信小程序会话密钥"`
+	IsRegister       int       `description:"是否注册:1:已注册,0:未注册"`
+	Source           int       `description:"绑定来源,1:微信端,2:pc网页端,3:查研观向小程序,4:每日咨询"`
 }
 
 //添加用户信息
@@ -71,6 +73,8 @@ type WxUserItem struct {
 	LastUpdatedTime time.Time `description:"最近一次修改时间"`
 	SessionKey      string    `description:"微信小程序会话密钥"`
 	CompanyName     string    `description:"公司名称"`
+	IsRegister      int       `description:"是否注册:1:已注册,0:未注册"`
+	Source          int
 }
 
 func GetWxUserItemByUnionid(unionid string) (item *WxUserItem, err error) {
@@ -185,3 +189,18 @@ func GetWxUserItemByEmail(email string) (item *WxUserItem, err error) {
 	err = orm.NewOrm().Raw(sql, email).QueryRow(&item)
 	return
 }
+
+func ModifyReportLastViewTime(uid int) (err error) {
+	sql := ` UPDATE wx_user SET report_last_view_time=NOW()
+			WHERE user_id=? `
+	_, err = orm.NewOrm().Raw(sql, uid).Exec()
+	return
+}
+
+//变更联系人是否已注册状态
+func ModifyWxUserRegisterStatus(userId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE wx_user SET is_register=?,source=3,register_time=NOW() WHERE user_id = ? `
+	_, err = o.Raw(sql, 1, userId).Exec()
+	return
+}

+ 1 - 1
services/tactics.go

@@ -20,7 +20,7 @@ func SyncTacticsList() (err error) {
 	}()
 	fmt.Println("同步数据")
 	indexName := utils.IndexName
-	endDate := time.Now().AddDate(0, 0, -7).Format(utils.FormatDate)
+	endDate := time.Now().AddDate(0, 0, -30).Format(utils.FormatDate)
 	list, err := models.GetTacticsList(endDate)
 	//list, err := models.GetTacticsListAll()
 	if err != nil {

+ 12 - 6
services/user.go

@@ -191,10 +191,12 @@ func BindWxUser(openid, mobile, email string) (wxUser *models.WxUserItem, err er
 			CreatedTime:      time.Now(),
 			FirstLogin:       1,
 			Enabled:          1,
-			RegisterPlatform: 1,
+			RegisterPlatform: 4,
 			RegisterTime:     time.Now(),
 			Mobile:           mobile,
 			Email:            email,
+			IsRegister:       1,
+			Source:           3,
 		}
 		tmpUserId, addUserErr := models.AddWxUser(user)
 		if err != nil {
@@ -206,7 +208,11 @@ func BindWxUser(openid, mobile, email string) (wxUser *models.WxUserItem, err er
 		wxUser, err = models.GetWxUserItemByUserId(userId)
 	} else {
 		userId = wxUser.UserId
+		if wxUser.IsRegister == 0 {
+			models.ModifyWxUserRegisterStatus(userId)
+		}
 	}
+
 	//如果存在该手机号/邮箱,那么需要校验
 	if userRecord.UserId > 0 && userRecord.UserId != userId {
 		err = errors.New("用户已绑定,不允许重复绑定")
@@ -220,11 +226,11 @@ func BindWxUser(openid, mobile, email string) (wxUser *models.WxUserItem, err er
 	userRecord.UserId = userId
 
 	//如果当前该第三方用户信息的昵称为空串的话,那么需要去查询该用户的第一个绑定信息的数据作为来源做数据修复
-	if userRecord.NickName == ""{
+	if userRecord.NickName == "" {
 		oldUserRecord, err := models.GetUserThirdRecordByUserId(userId)
-		if err == nil && oldUserRecord != nil{
+		if err == nil && oldUserRecord != nil {
 			//如果该用户绑定的第一条数据的头像信息不为空串,那么就去做新数据的修复
-			if oldUserRecord.NickName != ""{
+			if oldUserRecord.NickName != "" {
 				_ = models.ModifyUserRecordByDetail(userRecord.OpenId, userRecord.UnionId, oldUserRecord.NickName, oldUserRecord.Headimgurl, oldUserRecord.City, oldUserRecord.Province, oldUserRecord.Country, oldUserRecord.Sex, userId)
 			}
 		}
@@ -251,7 +257,7 @@ QUERY_WX_USER:
 		//先添加第三方信息(openid等信息)
 		_, recordErr := AddUserRecord(openId, unionId, wxUserInfo.Nickname, "", wxUserInfo.Province, wxUserInfo.City, wxUserInfo.Country, wxUserInfo.Headimgurl, wxUserInfo.SessionKey, utils.WxPlatform, wxUserInfo.Sex, 0)
 		//如果插入失败,那么直接将错误信息返回
-		if recordErr != nil{
+		if recordErr != nil {
 			err = recordErr
 			return
 		}
@@ -372,4 +378,4 @@ func AddUserRecord(openId, unionId, nickName, realName, province, city, country,
 	}
 	userRecord.UserRecordId = int(recordId)
 	return
-}
+}