|
@@ -3,6 +3,7 @@ package services
|
|
|
import (
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"hongze/hongze_cygx/models"
|
|
|
"hongze/hongze_cygx/utils"
|
|
@@ -64,16 +65,31 @@ func GetStocksFromVmp(cont context.Context) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) {
|
|
|
+
|
|
|
+func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) (err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ go utils.SendAlarmMsg(fmt.Sprint("记录用户阅读时长 失败 AddSpecialRecord Err:"+err.Error(), "userId:", user.UserId, "specialId:", specialId), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
var sellerName string
|
|
|
|
|
|
- sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
|
|
|
- if err != nil {
|
|
|
+ sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
|
|
|
return
|
|
|
}
|
|
|
sellerName = sellerItem.RealName
|
|
|
|
|
|
if stopTime >= 3 {
|
|
|
+
|
|
|
+
|
|
|
+ totalRecord, e := models.GetCygxYanxuanSpecialRecordCountByUser(user.UserId, specialId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("GetCygxYanxuanSpecialRecordCountByUser, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
item := new(models.CygxYanxuanSpecialRecord)
|
|
|
item.UserId = user.UserId
|
|
|
item.Mobile = user.Mobile
|
|
@@ -82,34 +98,67 @@ func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) {
|
|
|
item.CompanyName = user.CompanyName
|
|
|
item.RealName = user.RealName
|
|
|
item.SellerName = sellerName
|
|
|
- item.CreateTime = time.Now()
|
|
|
+ item.CreateTime = time.Now().Add(-time.Duration(stopTime) * time.Second)
|
|
|
item.ModifyTime = time.Now()
|
|
|
item.RegisterPlatform = utils.REGISTER_PLATFORM
|
|
|
item.YanxuanSpecialId = specialId
|
|
|
-
|
|
|
- _, err = models.AddCygxYanxuanSpecialRecord(item)
|
|
|
- if err != nil {
|
|
|
+ item.StopTime = stopTime
|
|
|
+ _, e = models.AddCygxYanxuanSpecialRecord(item)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("AddCygxYanxuanSpecialRecord, Err: " + e.Error())
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
|
|
|
if user.CompanyId != utils.HZ_COMPANY_ID {
|
|
|
|
|
|
+
|
|
|
+ e = models.UpdateYanxuanSpecialPv(specialId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateYanxuanSpecialPv, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ e = models.UpdateCygxYanxuanSpecialAuthorPv(user.UserId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateCygxYanxuanSpecialAuthorPv, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if totalRecord == 0 {
|
|
|
+ e = models.UpdateYanxuanSpecialUv(specialId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateYanxuanSpecialUv, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ e = models.UpdateCygxYanxuanSpecialAuthorUv(user.UserId)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("UpdateCygxYanxuanSpecialAuthorUv, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ itemLog := new(models.CygxYanxuanSpecialRecordLog)
|
|
|
+ itemLog.UserId = user.UserId
|
|
|
+ itemLog.Mobile = user.Mobile
|
|
|
+ itemLog.Email = user.Email
|
|
|
+ itemLog.CompanyId = user.CompanyId
|
|
|
+ itemLog.CompanyName = user.CompanyName
|
|
|
+ itemLog.RealName = user.RealName
|
|
|
+ itemLog.SellerName = sellerName
|
|
|
+ itemLog.CreateTime = time.Now().Add(-time.Duration(stopTime) * time.Second)
|
|
|
+ itemLog.ModifyTime = time.Now()
|
|
|
+ itemLog.RegisterPlatform = utils.REGISTER_PLATFORM
|
|
|
+ itemLog.YanxuanSpecialId = specialId
|
|
|
+ _, e = models.AddCygxYanxuanSpecialRecordLog(itemLog)
|
|
|
+ if e != nil {
|
|
|
+ err = errors.New("AddCygxYanxuanSpecialRecordLog, Err: " + e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|