Explorar o código

Merge branch 'cygx_need_962' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai hai 10 meses
pai
achega
7b600686c9

+ 2 - 0
controllers/yanxuan_special.go

@@ -263,6 +263,8 @@ func (this *YanxuanSpecialController) Detail() {
 		if followCount > 0 {
 			resp.IsFollowAuthor = true
 		}
+	} else {
+		item.Content = utils.InterceptHtmlLength(item.Content, 150)
 	}
 
 	//校验研选专栏权限,以及无权限的时候的对应状态码

+ 1 - 0
models/article_and_yanxuan_record.go

@@ -20,6 +20,7 @@ type CygxArticleAndYanxuanRecord struct {
 	SellerName       string    `description:"所属销售"`
 	StopTime         int       `description:"停留时间"`
 	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
+	PermissionCode   int       // 权限状态,1:有权限,0:无权限
 }
 
 // 批量添加

+ 3 - 0
models/cygx_yanxuan_special_record.go

@@ -19,6 +19,7 @@ type CygxYanxuanSpecialRecord struct {
 	RegisterPlatform           int       // 来源 1小程序,2:网页
 	YanxuanSpecialId           int       // cygx_yanxuan_special 表主键ID
 	StopTime                   int       // 停留时间
+	PermissionCode             int       // 权限状态,1:有权限,0:无权限
 }
 
 type CygxYanxuanSpecialRecordResp struct {
@@ -35,6 +36,7 @@ type CygxYanxuanSpecialRecordResp struct {
 	RegisterPlatform           int       // 来源 1小程序,2:网页
 	YanxuanSpecialId           int       // cygx_yanxuan_special 表主键ID
 	StopTime                   int       // 停留时间
+	PermissionCode             int       // 权限状态,1:有权限,0:无权限
 }
 
 func AddCygxYanxuanSpecialRecord(item *CygxYanxuanSpecialRecord) (lastId int64, err error) {
@@ -91,6 +93,7 @@ type CygxYanxuanSpecialRecordLog struct {
 	RegisterPlatform           int       // 来源 1小程序,2:网页
 	YanxuanSpecialId           int       // cygx_yanxuan_special 表主键ID
 	StopTime                   int       // 停留时间
+	PermissionCode             int       // 权限状态,1:有权限,0:无权限
 }
 
 func AddCygxYanxuanSpecialRecordLog(item *CygxYanxuanSpecialRecordLog) (lastId int64, err error) {

+ 1 - 0
services/article_history.go

@@ -271,6 +271,7 @@ func AddAllArticleAndYanxuanHistory(cont context.Context) (err error) {
 				item.CreateTime = v.CreateTime
 				item.ModifyTime = v.ModifyTime
 				item.StopTime = v.StopTime
+				item.PermissionCode = v.PermissionCode
 				item.RegisterPlatform = v.RegisterPlatform
 				items = append(items, item)
 			}

+ 4 - 0
services/cygx_yanxuan_special.go

@@ -510,6 +510,10 @@ func UpdateYanxuanSpecialAuthoMomentsImg(cont context.Context) (err error) {
 
 // GetYanxuanSpecialDetailUserPower 处理用户查看研选专栏详情的权限
 func GetYanxuanSpecialDetailUserPower(user *models.WxUserItem) (havePower bool, err error) {
+	if user.UserId == 0 {
+		havePower = true
+		return
+	}
 	//研选专栏是否需要校验权限
 	detailChart, e := models.GetConfigByCode("yanxuan_special_power_check")
 	if e != nil {

+ 14 - 1
services/cygx_yanxuan_special_company.go

@@ -75,6 +75,17 @@ func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) (err err
 			go utils.SendAlarmMsg(fmt.Sprint("记录用户阅读时长 失败 AddSpecialRecord Err:"+err.Error(), "userId:", user.UserId, "specialId:", specialId), 2)
 		}
 	}()
+	//校验研选专栏权限,以及无权限的时候的对应状态码
+	havePower, e := GetYanxuanSpecialDetailUserPower(user)
+	if e != nil {
+		err = errors.New("GetYanxuanSpecialDetailUserPower, Err: " + e.Error())
+		return
+	}
+
+	var permissionCode int
+	if havePower {
+		permissionCode = 1
+	}
 	var sellerName string
 	//获取销售信息
 	sellerName, _ = GetSellerName(user)
@@ -106,6 +117,7 @@ func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) (err err
 		item.RegisterPlatform = utils.REGISTER_PLATFORM
 		item.YanxuanSpecialId = specialId
 		item.StopTime = stopTime
+		item.PermissionCode = permissionCode
 		_, e = models.AddCygxYanxuanSpecialRecord(item) // 添加历史记录
 		if e != nil {
 			err = errors.New("AddCygxYanxuanSpecialRecord, Err: " + e.Error())
@@ -159,7 +171,8 @@ func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) (err err
 	itemLog.RegisterPlatform = utils.REGISTER_PLATFORM
 	itemLog.YanxuanSpecialId = specialId
 	itemLog.StopTime = stopTime
-	_, e := models.AddCygxYanxuanSpecialRecordLog(itemLog) // 添加历史记录
+	itemLog.PermissionCode = permissionCode
+	_, e = models.AddCygxYanxuanSpecialRecordLog(itemLog) // 添加历史记录
 	if e != nil {
 		err = errors.New("AddCygxYanxuanSpecialRecordLog, Err: " + e.Error())
 		return

+ 18 - 2
utils/common.go

@@ -966,10 +966,26 @@ func InterceptHtmlLength(body string, length int) (newbody string) {
 		return
 	}
 	bodyText := doc.Text()
-	if len(bodyText) < length {
+	//if len(bodyText) < length {
+	//	length = len(bodyText)
+	//}
+	//newbody = bodyText[0:length]
+
+	totalCharCount := utf8.RuneCountInString(bodyText)
+	if totalCharCount < length {
 		length = len(bodyText)
 	}
-	newbody = bodyText[0:length]
+	// 计算前15个汉字所需的字节位置
+	hanziCount := 0
+	byteIndex := 0
+	for byteIndex < len(bodyText) && hanziCount < length {
+		r, size := utf8.DecodeRuneInString(bodyText[byteIndex:])
+		if r != utf8.RuneError {
+			hanziCount++
+		}
+		byteIndex += size
+	}
+	newbody = bodyText[:byteIndex] + "…"
 	return
 }