xingzai 1 年間 前
コミット
238f57f6c6

+ 132 - 3
controllers/yanxuan_special.go

@@ -6,6 +6,7 @@ import (
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
+	"strconv"
 	"strings"
 	"time"
 )
@@ -205,9 +206,6 @@ func (this *YanxuanSpecialController) Detail() {
 		resp.CygxYanxuanSpecialItem = *new(models.CygxYanxuanSpecialItem) // 如果内容不可见,就把内容置空
 		resp.HasPermission = 2
 	}
-
-	go services.AddSpecialRecord(this.User, specialId)
-
 	br.Data = resp
 	br.Ret = 200
 	br.Success = true
@@ -653,6 +651,8 @@ func (this *YanxuanSpecialController) Record() {
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
+	specialId := req.SpecialId
+	stopTime := req.StopTime
 	if req.SpecialId <= 0 {
 		br.Msg = "文章不存在"
 		br.ErrMsg = "文章不存在,文章ID错误"
@@ -684,6 +684,8 @@ func (this *YanxuanSpecialController) Record() {
 		br.ErrMsg = "记录失败,Err:" + err.Error()
 		return
 	}
+
+	go services.AddSpecialRecord(this.User, specialId, stopTime)
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "记录成功"
@@ -1134,3 +1136,130 @@ func (this *YanxuanSpecialController) Check() {
 	br.Success = true
 	br.Msg = "校验成功"
 }
+
+// @Title 上传文章阅读时间
+// @Description 上传文章阅读时间接口
+// @Param  request	body models.AddStopTimeRep true "type json string"
+// @Success 200 {object} models.ArticleDetailResp
+// @router /addStopTime [post]
+func (this *YanxuanSpecialController) AddStopTime() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	var req models.AddStopTimeRep
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	uid := user.UserId
+	articleId := req.ArticleId
+	stopTime := req.StopTime
+	outType := req.OutType
+	source := req.Source
+	if articleId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误"
+		return
+	}
+	if stopTime == 0 {
+		stopTime = 1
+	}
+	if outType != 2 {
+		outType = 1
+	}
+	if source != "PC" {
+		source = "MOBILE"
+	}
+
+	detail := new(models.ArticleDetail)
+	hasPermission := 0
+	hasFree := 0
+
+	//判断是否已经申请过
+	applyCount, err := models.GetApplyRecordCount(uid)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+		return
+	}
+	//`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
+	if user.CompanyId > 1 {
+		companyPermission, err := models.GetCompanyPermission(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		detail, err = models.GetArticleDetailById(articleId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		if companyPermission == "" {
+			if applyCount > 0 {
+				hasPermission = 5
+			} else {
+				hasPermission = 2
+			}
+			hasFree = 2
+			goto Loop
+		} else {
+			hasFree = 1
+			var articlePermissionPermissionName string
+			if detail.CategoryId > 0 {
+				articlePermission, err := models.GetArticlePermission(detail.CategoryId)
+				if err != nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+					return
+				}
+				if articlePermission == nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+					return
+				}
+				articlePermissionPermissionName = articlePermission.PermissionName
+			} else {
+				articlePermissionPermissionName = detail.CategoryName
+			}
+			var hasPersion bool
+			slice := strings.Split(articlePermissionPermissionName, ",")
+			for _, v := range slice {
+				if strings.Contains(companyPermission, v) {
+					hasPersion = true
+				}
+			}
+			if hasPersion {
+				go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
+			} else { //无该行业权限
+				hasPermission = 3
+			}
+		}
+	} else { //潜在客户
+		if applyCount > 0 {
+			hasPermission = 5
+		} else {
+			hasPermission = 4
+		}
+	}
+Loop:
+	resp := new(models.ArticleDetailAddStopTimeRep)
+	resp.HasPermission = hasPermission
+	resp.HasFree = hasFree
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = resp
+}

+ 4 - 0
models/cygx_yanxuan_special.go

@@ -53,6 +53,8 @@ type CygxYanxuanSpecialItem struct {
 	IndustryTags  string
 	ContentHasImg int //正文是否包含图片 1包含 0不包含
 	Docs          []Doc
+	Pv            string `description:"Pv"`
+	Uv            string `description:"Uv"`
 }
 
 type CygxYanxuanSpecialResp struct {
@@ -97,6 +99,8 @@ type CygxYanxuanSpecialCenterResp struct {
 	Docs            []Doc
 	Annotation      string `description:"核心观点"`
 	Source          string `description:"来源"`
+	Pv              string `description:"Pv"`
+	Uv              string `description:"Uv"`
 	PublishDate     string // 提审过审或驳回时间      string `description:"核心观点"`
 }
 

+ 3 - 2
models/cygx_yanxuan_special_record.go

@@ -28,5 +28,6 @@ func AddCygxYanxuanSpecialRecord(item *CygxYanxuanSpecialRecord) (lastId int64,
 }
 
 type AddCygxYanxuanSpecialRecordReq struct {
-	SpecialId           int `description:"专栏文章id"`
-}
+	SpecialId int `description:"专栏文章id"`
+	StopTime  int `description:"停留时间"`
+}

+ 46 - 22
services/cygx_yanxuan_special_company.go

@@ -44,11 +44,10 @@ func GetStocksFromVmp(cont context.Context) (err error) {
 
 	items := make([]*models.CygxYanxuanSpecialCompany, 0)
 
-
 	for i, _ := range resp.Data {
 		items = append(items, &resp.Data[i])
 		if len(items) > 5000 {
-			err  = models.AddCygxYanxuanSpecialCompanyMulti(items)
+			err = models.AddCygxYanxuanSpecialCompanyMulti(items)
 			if err != nil {
 				fmt.Println("AddCygxYanxuanSpecialCompanyMulti Err:%s", err.Error())
 				return
@@ -57,7 +56,7 @@ func GetStocksFromVmp(cont context.Context) (err error) {
 		}
 	}
 
-	err  = models.AddCygxYanxuanSpecialCompanyMulti(items)
+	err = models.AddCygxYanxuanSpecialCompanyMulti(items)
 	if err != nil {
 		fmt.Println("AddCygxYanxuanSpecialCompanyMulti Err:%s", err.Error())
 		return
@@ -65,27 +64,52 @@ func GetStocksFromVmp(cont context.Context) (err error) {
 	return
 }
 
-func AddSpecialRecord(user *models.WxUserItem, specialId int) {
+func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) {
 	var sellerName string
-	sellerName, err := models.GetCompanySellerName(user.CompanyId)
+	//获取销售信息
+	sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
 	if err != nil {
 		return
 	}
-	item := models.CygxYanxuanSpecialRecord{
-		UserId:           user.UserId,
-		Mobile:           user.Mobile,
-		Email:            user.Email,
-		CompanyId:        user.CompanyId,
-		CompanyName:      user.CompanyName,
-		RealName:         user.RealName,
-		SellerName:       sellerName,
-		CreateTime:       time.Now(),
-		ModifyTime:       time.Now(),
-		RegisterPlatform: utils.REGISTER_PLATFORM,
-		YanxuanSpecialId: specialId,
-	}
-	_, err = models.AddCygxYanxuanSpecialRecord(&item)
-	if err != nil {
-		return
+	sellerName = sellerItem.RealName
+
+	if stopTime >= 3 {
+		item := new(models.CygxYanxuanSpecialRecord)
+		item.UserId = user.UserId
+		item.Mobile = user.Mobile
+		item.Email = user.Email
+		item.CompanyId = user.CompanyId
+		item.CompanyName = user.CompanyName
+		item.RealName = user.RealName
+		item.SellerName = sellerName
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		item.RegisterPlatform = utils.REGISTER_PLATFORM
+		item.YanxuanSpecialId = specialId
+
+		_, err = models.AddCygxYanxuanSpecialRecord(item)
+		if err != nil {
+			return
+		}
+
+		//如果不是弘则研究的人员阅读的,就修改Pv、Uv数量
+		if user.CompanyId != utils.HZ_COMPANY_ID {
+
+		}
 	}
-}
+
+	//item := models.CygxYanxuanSpecialRecord{
+	//	UserId:           user.UserId,
+	//	Mobile:           user.Mobile,
+	//	Email:            user.Email,
+	//	CompanyId:        user.CompanyId,
+	//	CompanyName:      user.CompanyName,
+	//	RealName:         user.RealName,
+	//	SellerName:       sellerName,
+	//	CreateTime:       time.Now(),
+	//	ModifyTime:       time.Now(),
+	//	RegisterPlatform: utils.REGISTER_PLATFORM,
+	//	YanxuanSpecialId: specialId,
+	//}
+
+}