xingzai 1 yıl önce
ebeveyn
işleme
cf22528f0d

+ 11 - 0
controllers/user.go

@@ -391,6 +391,17 @@ func (this *UserController) ApplyTryOut() {
 		}
 		title = ProductInteriorDetail.Title
 		source = "productinterior"
+	} else if tryType == "YanxuanSpecial" {
+		// 研选专栏
+		YanxuanSpecialBySpeciaDetail, e := models.GetYanxuanSpecialBySpecialId(detailId)
+		if e != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "产品内测信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
+			return
+		}
+		title = YanxuanSpecialBySpeciaDetail.Title
+		source = "yanxuanspecial"
+		isResearch = true
 	}
 
 	//缓存校验

+ 18 - 1
controllers/yanxuan_special.go

@@ -231,7 +231,20 @@ func (this *YanxuanSpecialController) Detail() {
 	}
 	if item.UserId != sysUser.UserId && item.Status != 3 && !strings.Contains(cnf.ConfigValue, sysUser.Mobile) {
 		resp.CygxYanxuanSpecialItem = *new(models.CygxYanxuanSpecialItem) // 如果内容不可见,就把内容置空
-		resp.HasPermission = 2
+		//resp.HasPermission = 2
+	}
+
+	//如果是用户本人写的专栏,那么就不做校验
+	if item.UserId == sysUser.UserId || sysUser.UserId == 0 {
+		resp.HasPermission = 1
+	} else {
+		hasPermission, err := services.GetUserRaiPermissionYanXuanInfo(sysUser)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败, Err:" + err.Error()
+			return
+		}
+		resp.HasPermission = hasPermission
 	}
 
 	//判断是否属于审核人员
@@ -242,6 +255,10 @@ func (this *YanxuanSpecialController) Detail() {
 		}
 	}
 
+	if resp.HasPermission != 1 || sysUser.UserId == 0 {
+		resp.Content = utils.InterceptHtmlLength(resp.Content, 240)
+	}
+
 	br.Data = resp
 	br.Ret = 200
 	br.Success = true

+ 0 - 18
models/chart_permission.go

@@ -2,7 +2,6 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
-	"time"
 )
 
 type ChartPermissionResp struct {
@@ -25,23 +24,6 @@ type ChartPermissionItemResp struct {
 	MatchTypeName     string `description:"匹配类型名称"`
 }
 
-type CompanyReportPermission struct {
-	CompanyReportPermissionId int `orm:"column(company_report_permission_id);pk"`
-	CompanyId                 int `description:"客户id"`
-	ReportPermissionId        int `description:"报告权限id"`
-	CreatedTime               time.Time
-	LastUpdatedTime           time.Time
-	ChartPermissionId         int    `description:"权限id"`
-	StartDate                 string `description:"权限开始日期"`
-	EndDate                   string `description:"权限结束日期"`
-	ProductId                 int    `description:"产品id"`
-	ProductName               string `description:"产品名称"`
-	ModifyTime                string `description:"修改时间"`
-	CompanyContractId         string `description:"合同id"`
-	Status                    string `description:"状态  '正式','试用','关闭','永续','潜在' "`
-	IsUpgrade                 int    `description:"是否升级,1是,0否"`
-}
-
 type ChartPermissionListResp struct {
 	List      []*ChartPermissionResp
 	CheckList []int `description:"权限"`

+ 45 - 0
models/company_report_permission.go

@@ -0,0 +1,45 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CompanyReportPermission struct {
+	CompanyReportPermissionId int `orm:"column(company_report_permission_id);pk"`
+	CompanyId                 int `description:"客户id"`
+	ReportPermissionId        int `description:"报告权限id"`
+	CreatedTime               time.Time
+	LastUpdatedTime           time.Time
+	ChartPermissionId         int    `description:"权限id"`
+	StartDate                 string `description:"权限开始日期"`
+	EndDate                   string `description:"权限结束日期"`
+	ProductId                 int    `description:"产品id"`
+	ProductName               string `description:"产品名称"`
+	ModifyTime                string `description:"修改时间"`
+	CompanyContractId         string `description:"合同id"`
+	Status                    string `description:"状态  '正式','试用','关闭','永续','潜在' "`
+	IsUpgrade                 int    `description:"是否升级,1是,0否"`
+}
+
+// 通过查询条件获取详情
+func GetCompanyReportPermissionDetailByCondition(condition string, pars []interface{}) (item *CompanyReportPermission, err error) {
+	if condition == "" {
+		return
+	}
+	o := orm.NewOrmUsingDB("weekly_report")
+	sql := `SELECT * FROM company_report_permission  WHERE 1 = 1  ` + condition
+	err = o.Raw(sql, pars).QueryRow(&item)
+	return
+}
+
+// 列表
+func GetCompanyReportPermissionList(condition string, pars []interface{}) (items []*CompanyReportPermission, err error) {
+	o := orm.NewOrmUsingDB("weekly_report")
+	sql := `SELECT * FROM company_report_permission  WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 24 - 0
services/user_permission.go

@@ -162,3 +162,27 @@ func GetUserRaiPermissionInfo(userId, companyId int) (authInfo models.UserPermis
 	permissionArr = strings.Split(permissions, ",")
 	return
 }
+
+// 查询研选的权限状态
+func GetUserRaiPermissionYanXuanInfo(user *models.WxUserItem) (hasPermission int, err error) {
+	var condition string
+	var pars []interface{}
+	condition = " AND company_id = ?  AND status  IN ('正式','试用')  AND chart_permission_id = ?   ORDER BY company_report_permission_id DESC LIMIT 1  "
+	pars = append(pars, user.CompanyId, utils.CHART_PERMISSION_ID_YANXUAN)
+	companyReportPermissionDetail, e := models.GetCompanyReportPermissionDetailByCondition(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCompanyReportPermissionDetailByCondition, Err: " + e.Error())
+		return
+	}
+	//如果用户没有研选权限,那么就获取他对应的状态码
+	if companyReportPermissionDetail == nil {
+		hasPermission, _, _, _, e = GetUserHasPermissionArticle(user)
+		if e != nil {
+			err = errors.New("GetUserHasPermissionArticle, Err: " + e.Error())
+			return
+		}
+	} else {
+		hasPermission = 1
+	}
+	return
+}

+ 18 - 1
utils/common.go

@@ -8,6 +8,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"github.com/PuerkitoBio/goquery"
+	"html"
 	"image"
 	"image/png"
 	"math"
@@ -787,7 +788,7 @@ func ArticleHasImgUrl(body string) (hasImg bool, err error) {
 	return
 }
 
-func ArticleRemoveImgUrl(body string) (result string){
+func ArticleRemoveImgUrl(body string) (result string) {
 	// 使用正则表达式去除img标签
 	re := regexp.MustCompile(`<img[^>]*>`)
 	result = re.ReplaceAllString(body, "")
@@ -819,3 +820,19 @@ func ExtractText(body string) (result string, err error) {
 
 	return
 }
+
+// 富文本字符串截取指定长度
+func InterceptHtmlLength(body string, length int) (newbody string) {
+	content := html.UnescapeString(body)
+	doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
+	if err != nil {
+		fmt.Println("create doc err:", err.Error())
+		return
+	}
+	bodyText := doc.Text()
+	if len(bodyText) < length {
+		length = len(bodyText)
+	}
+	newbody = bodyText[0:length]
+	return
+}