|
@@ -3,6 +3,7 @@ package services
|
|
|
import (
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"hongze/hongze_clpt/models"
|
|
|
"hongze/hongze_clpt/utils"
|
|
@@ -13,7 +14,7 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-//get公共请求方法
|
|
|
+// get公共请求方法
|
|
|
func PublicGetDate(url, authorization string) (body []byte, err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -39,7 +40,7 @@ func PublicGetDate(url, authorization string) (body []byte, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//同步图表列表
|
|
|
+// 同步图表列表
|
|
|
func GetChartListByApi(cont context.Context) (err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -190,7 +191,7 @@ func GetChartListByApi(cont context.Context) (err error) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-//获取图表分类
|
|
|
+// 获取图表分类
|
|
|
func GetChartPtagByApi() (items []*models.ChartPtagResp, err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -225,7 +226,7 @@ func GetChartPtagByApi() (items []*models.ChartPtagResp, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//获取用户的Token
|
|
|
+// 获取用户的Token
|
|
|
func GetUserTokenByMobile(mobile string) (token string, err error) {
|
|
|
//缓存校验
|
|
|
cacheKey := fmt.Sprint("xygx_chart:chart_token:add:", "Mobile", mobile)
|
|
@@ -270,7 +271,7 @@ func GetUserTokenByMobile(mobile string) (token string, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//获取图表收藏
|
|
|
+// 获取图表收藏
|
|
|
func GetChartCollectionByApi(mobile string, take, skip int) (items []*models.HomeChartListResp, err error, total int) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -309,7 +310,7 @@ func GetChartCollectionByApi(mobile string, take, skip int) (items []*models.Hom
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//判断策略平台是否已经添加过收藏
|
|
|
+// 判断策略平台是否已经添加过收藏
|
|
|
func GetIsCollectionChart(mobile string, chartId int) (isCollection bool, err error) {
|
|
|
//获取所有的收藏列表,进行比对看看是否收藏,调用三方接口详情没有是否收藏的字段
|
|
|
list, err, _ := GetChartCollectionByApi(mobile, 9999, 0)
|
|
@@ -324,7 +325,7 @@ func GetIsCollectionChart(mobile string, chartId int) (isCollection bool, err er
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//添加收藏
|
|
|
+// 添加收藏
|
|
|
func AddCollectionChart(mobile string, chartId int) (err error) {
|
|
|
authorization, err := GetUserTokenByMobile(mobile)
|
|
|
if err != nil {
|
|
@@ -356,7 +357,7 @@ func AddCollectionChart(mobile string, chartId int) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//移除收藏
|
|
|
+// 移除收藏
|
|
|
func DeleteCollectionChart(mobile string, chartId int) (err error) {
|
|
|
authorization, err := GetUserTokenByMobile(mobile)
|
|
|
if err != nil {
|
|
@@ -384,129 +385,32 @@ func DeleteCollectionChart(mobile string, chartId int) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func DoCompany() {
|
|
|
-
|
|
|
- //listCollect, err := models.GetCygxArticleCollectList()
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
|
|
|
- //}
|
|
|
- //for _, v := range listCollect {
|
|
|
- // user, err := models.GetWxUserItemByUserId(v.UserId)
|
|
|
- // if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // if user != nil {
|
|
|
- // fmt.Println(user.RealName)
|
|
|
- // err = models.UpdateCygxArticleCollect(user)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- //listCollect, err := models.GetCygxSearchKeyWordList()
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("GetAddCygxArticleCollectList ,Err" + err.Error())
|
|
|
- //}
|
|
|
- //for _, v := range listCollect {
|
|
|
- // user, err := models.GetWxUserItemByUserId(v.UserId)
|
|
|
- // if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // if user != nil {
|
|
|
- // fmt.Println(user.RealName)
|
|
|
- // err = models.UpdateCygxSearchKeyWord(user)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
- //var condition string
|
|
|
- ////updateTime := time.Now().Add(-time.Hour * 25).Format(utils.FormatDateTime)
|
|
|
- //condition = ` AND real_name = '' `
|
|
|
- //listArticlePv, err := models.GetArticleHistoryRecordAllByMobileList(condition)
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("GetArticleHistoryRecordAllByMobileList ,Err" + err.Error())
|
|
|
- //}
|
|
|
- //fmt.Println("长度", len(listArticlePv))
|
|
|
- //for k, v := range listArticlePv {
|
|
|
- // if v.Mobile != "" {
|
|
|
- // user, err := models.GetWxUserItemByMobile(v.Mobile)
|
|
|
- // if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // if user != nil {
|
|
|
- // fmt.Println(user.RealName, k)
|
|
|
- // err = models.UpdateCygxArticleHistoryRecordAll(user)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("UpdateCygxArticleCollect ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- //listIndustryFllow, err := models.GetCygxIndustryFllowList("")
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
|
|
|
- //}
|
|
|
- //fmt.Println("长度", len(listIndustryFllow))
|
|
|
- //for k, v := range listIndustryFllow {
|
|
|
- // if v.Mobile != "" {
|
|
|
- // user, err := models.GetWxUserItemByMobile(v.Mobile)
|
|
|
- // if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // if user != nil {
|
|
|
- // fmt.Println(user.RealName, k)
|
|
|
- // err = models.UpdateCygxIndustryFllow(user)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("UpdateCygxIndustryFllow ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
- //
|
|
|
- //lisDepartmentF, err := models.GetArticleDepartmentFollowByMobileList("")
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("GetArticleDepartmentFollowByMobileList ,Err" + err.Error())
|
|
|
- //}
|
|
|
- //fmt.Println("长度", len(lisDepartmentF))
|
|
|
- //for k, v := range lisDepartmentF {
|
|
|
- // if v.Mobile != "" {
|
|
|
- // user, err := models.GetWxUserItemByMobile(v.Mobile)
|
|
|
- // if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // if user != nil {
|
|
|
- // fmt.Println(user.RealName, k)
|
|
|
- // err = models.UpdateCygxArticleDepartmentFollow(user)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("UpdateCygxArticleDepartmentFollow ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- //listChartCollect, err := models.GetCygxChartCollectByMobileList()
|
|
|
- //if err != nil {
|
|
|
- // fmt.Println("GetCygxChartCollectByMobileList ,Err" + err.Error())
|
|
|
- //}
|
|
|
- //fmt.Println("长度", len(listChartCollect))
|
|
|
- //for k, v := range listChartCollect {
|
|
|
- // if v.Mobile != "" {
|
|
|
- // user, err := models.GetWxUserItemByMobile(v.Mobile)
|
|
|
- // if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
- // fmt.Println("GetWxUserItemByUserId ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // if user != nil {
|
|
|
- // fmt.Println(user.RealName, k)
|
|
|
- // err = models.UpdateCygxChartCollect(user)
|
|
|
- // if err != nil {
|
|
|
- // fmt.Println("UpdateCygxChartCollect ,Err" + err.Error())
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- fmt.Println("end")
|
|
|
+// 用户阅读图表,添加浏览记录
|
|
|
+func ServerAddCygxChartRecord(wxUser *models.WxUserItem, ctagId int) {
|
|
|
+ if wxUser.CompanyId < 1 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ go utils.SendAlarmMsg(fmt.Sprint("用户阅读图表,添加浏览记录失败 ctagId", ctagId, "userId", wxUser.UserId, err.Error()), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ item := new(models.CygxChartRecord)
|
|
|
+ item.ChartId = ctagId
|
|
|
+ item.UserId = wxUser.UserId
|
|
|
+ item.RealName = wxUser.RealName
|
|
|
+ item.Mobile = wxUser.Mobile
|
|
|
+ item.Email = wxUser.Email
|
|
|
+ item.CompanyId = wxUser.CompanyId
|
|
|
+ item.CompanyName = wxUser.CompanyName
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ item.RegisterPlatform = utils.REGISTER_PLATFORM
|
|
|
+ _, e := models.AddCygxChartRecord(item)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("AddCygxChartRecord" + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|