Browse Source

微路演列表权限、默认图

hsun 2 years ago
parent
commit
ee4996dc16

+ 55 - 2
controllers/micro_roadshow.go

@@ -49,6 +49,7 @@ func (this *MicroRoadShowController) List() {
 		currentIndex = 1
 	}
 
+	// 微路演列表
 	list, total, e := services.GetMicroRoadShowPageList(pageSize, currentIndex, audioId, videoId, keywords)
 	if e != nil {
 		br.Msg = "获取失败"
@@ -56,6 +57,58 @@ func (this *MicroRoadShowController) List() {
 		return
 	}
 
+	// 用户权限
+	authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
+		return
+	}
+
+	// 获取默认图配置
+	audioMap, videoMap, e := services.GetMicroRoadShowDefaultImgConfig()
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
+		return
+	}
+
+	for i := range list {
+		// 权限
+		au := new(models.UserPermissionAuthInfo)
+		au.SellerName = authInfo.SellerName
+		au.SellerMobile = authInfo.SellerMobile
+		au.HasPermission = authInfo.HasPermission
+		if authInfo.HasPermission == 1 {
+			if !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
+				au.HasPermission = 2
+			}
+		}
+		if authInfo.HasPermission == 2 {
+			if list[i].Type == 1 {
+				au.PopupMsg = services.UserPermissionPopupMsgCallActivity
+			} else {
+				au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
+			}
+		}
+		if authInfo.HasPermission == 3 {
+			if list[i].Type == 1 {
+				au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
+			} else {
+				au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
+			}
+		}
+		list[i].AuthInfo = au
+		// 默认图
+		if list[i].BackgroundImg == "" {
+			if list[i].Type == 1 {
+				list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
+			} else {
+				list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
+			}
+		}
+	}
+
 	resp := new(models.MicroRoadShowListResp)
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp.List = list
@@ -118,7 +171,7 @@ func (this *MicroRoadShowController) VideoHistoryAdd() {
 		ModifyTime:  time.Now(),
 	}
 
-	if playSeconds != ""{
+	if playSeconds != "" {
 		lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId)
 		if err != nil {
 			br.Msg = "操作失败"
@@ -143,4 +196,4 @@ func (this *MicroRoadShowController) VideoHistoryAdd() {
 	br.Success = true
 	br.Msg = "操作成功"
 	return
-}
+}

+ 17 - 0
models/config.go

@@ -8,6 +8,8 @@ import (
 var (
 	HomeHeaderTabConfigKey              = "home_header_tab"
 	MicroRoadShowListDataRatioConfigKey = "micro_roadshow_list_data_ratio"
+	HomeNewListAudioNumKey              = "home_new_list_audio_num"
+	MicroRoadshowDefaultImgKey          = "micro_roadshow_default_img"
 )
 
 type CygxConfig struct {
@@ -69,13 +71,28 @@ func GetHotSearch() (permission string, err error) {
 	return
 }
 
+// HomeHeaderTabList 首页头部导航列表
 type HomeHeaderTabList struct {
 	Home       []*HomeHeaderTab `description:"首页"`
 	SearchPage []*HomeHeaderTab `description:"搜索页"`
 }
 
+// HomeHeaderTab 首页头部导航
 type HomeHeaderTab struct {
 	Id     int    `description:"导航ID"`
 	Name   string `description:"导航名称"`
 	IsShow bool   `description:"是否展示"`
 }
+
+// MicroRoadShowDefaultImgList 微路演行业默认背景图列表
+type MicroRoadShowDefaultImgList struct {
+	Audio []*MicroRoadShowDefaultImg `description:"音频"`
+	Video []*MicroRoadShowDefaultImg `description:"视频"`
+}
+
+// MicroRoadShowDefaultImg 微路演行业默认背景图
+type MicroRoadShowDefaultImg struct {
+	ChartPermissionId   int    `description:"行业ID"`
+	ChartPermissionName string `description:"行业名称"`
+	ImgUrl              string `description:"背景图"`
+}

+ 9 - 5
models/micro_roadshow.go

@@ -23,7 +23,8 @@ type MicroRoadShowPageList struct {
 	ChartPermissionId   int    `description:"行业ID"`
 	ChartPermissionName string `description:"行业名称"`
 	PlaySeconds         string `description:"音视频时长"`
-	//AuthOk              bool   `description:"是否有权限"`
+	ActivityId          int    `description:"活动ID"`
+	AuthInfo            *UserPermissionAuthInfo
 }
 
 // GetMicroRoadShowAudioPageList 获取微路演音频列表-分页
@@ -37,7 +38,9 @@ func GetMicroRoadShowAudioPageList(startSize, pageSize int, condition string, pa
 				b.activity_time AS publish_time,
 				b.chart_permission_id,
 				b.chart_permission_name,
-				a.voice_play_seconds AS play_seconds
+				a.voice_play_seconds AS play_seconds,
+				a.img_url AS background_img,
+				a.activity_id
 			FROM
 				cygx_activity_voice AS a
 			JOIN cygx_activity AS b ON a.activity_id = b.activity_id `
@@ -68,7 +71,8 @@ func GetMicroRoadShowVideoPageList(startSize, pageSize int, condition string, pa
 				publish_date AS publish_time,
 				chart_permission_id,
 				chart_permission_name,
-				video_duration AS play_seconds
+				video_duration AS play_seconds,
+				img_url AS background_img
 			FROM
 				cygx_micro_roadshow_video
 			WHERE
@@ -90,7 +94,7 @@ func GetMicroRoadShowVideoPageList(startSize, pageSize int, condition string, pa
 }
 
 type AddVideoHistoryReq struct {
-	VideoId int  `description:"视频ID"`
+	VideoId     int    `description:"视频ID"`
 	PlaySeconds string `description:"播放时长"`
 }
 
@@ -120,4 +124,4 @@ func AddCygxMicroRoadshowVideoHistory(item *CygxMicroRoadshowVideoHistory) (err
 	o := orm.NewOrm()
 	_, err = o.Insert(item)
 	return
-}
+}

+ 10 - 1
models/user.go

@@ -211,7 +211,7 @@ type ApplyTryReq struct {
 	RealName        string `description:"姓名"`
 	CompanyName     string `description:"公司名称"`
 	ApplyMethod     int    `description:"1:已付费客户申请试用,2:非客户申请试用,3:非客户申请试用(ficc下,不需要进行数据校验)"`
-	TryType         string `description:"提交类型,Article:文章、Activity:活动"`
+	TryType         string `description:"提交类型,Article:文章、Activity:活动; MicroVideo-微路演视频"`
 	DetailId        int    `description:"详情ID"`
 }
 
@@ -463,3 +463,12 @@ func UpdateUserInteractionNum(interactionNum, userId int) (err error) {
 	_, err = o.Raw(sql, interactionNum, userId).Exec()
 	return
 }
+
+// UserPermissionAuthInfo 用户通用权限信息
+type UserPermissionAuthInfo struct {
+	HasPermission int    `description:"是否有权限:1-有权限; 2-无权限; 3-潜在客户未提交申请; 4-潜在客户已提交申请 5-仅有FICC权限"`
+	SellerMobile  string `description:"销售手机号"`
+	SellerName    string `description:"销售名称"`
+	OperationMode string `description:"操作方式:Apply-立即申请; Call-拨号"`
+	PopupMsg      string `description:"权限弹窗信息"`
+}

+ 35 - 4
services/micro_roadshow.go

@@ -1,6 +1,7 @@
 package services
 
 import (
+	"encoding/json"
 	"errors"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
@@ -97,16 +98,16 @@ func GetMicroRoadShowPageList(pageSize, currentIndex, audioId, videoId int, keyw
 	videoLen := len(videoList)
 	for i := 0; i < sliceNum; i++ {
 		// 音频
-		a := i * audioRatio		// 0 4 8 12
-		oa := a + audioRatio	// 4 8 12 16
+		a := i * audioRatio  // 0 4 8 12
+		oa := a + audioRatio // 4 8 12 16
 		if oa <= audioLen {
 			for k1 := a; k1 < oa; k1++ {
 				respList = append(respList, audioList[k1])
 			}
 		}
 		// 视频
-		b := i * videoRatio		// 0 1 2 3
-		ob := b + videoRatio	// 1 2 3 4
+		b := i * videoRatio  // 0 1 2 3
+		ob := b + videoRatio // 1 2 3 4
 		if ob <= videoLen {
 			for k2 := b; k2 < ob; k2++ {
 				respList = append(respList, videoList[k2])
@@ -162,3 +163,33 @@ func getMicroRoadShowDataRatio(pageSize int) (audioRatio, videoRatio, audioPageN
 
 	return
 }
+
+// GetMicroRoadShowDefaultImgConfig 获取微路演默认图配置
+func GetMicroRoadShowDefaultImgConfig() (audioMap, videoMap map[int]string, err error) {
+	audioMap = make(map[int]string, 0)
+	videoMap = make(map[int]string, 0)
+	key := models.MicroRoadshowDefaultImgKey
+	conf, e := models.GetConfigByCode(key)
+	if e != nil {
+		err = errors.New("获取微路演默认图配置失败, Err: " + e.Error())
+		return
+	}
+	if conf.ConfigValue == "" {
+		err = errors.New("获取微路演默认图配置有误")
+		return
+	}
+	list := new(models.MicroRoadShowDefaultImgList)
+	if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
+		err = errors.New("微路演默认图配置配置值解析失败, Err: " + e.Error())
+		return
+	}
+	audioList := list.Audio
+	for i := range audioList {
+		audioMap[audioList[i].ChartPermissionId] = audioList[i].ImgUrl
+	}
+	videoList := list.Video
+	for i := range videoList {
+		videoMap[videoList[i].ChartPermissionId] = videoList[i].ImgUrl
+	}
+	return
+}

+ 86 - 0
services/user_permission.go

@@ -0,0 +1,86 @@
+package services
+
+import (
+	"errors"
+	"hongze/hongze_cygx/models"
+	"hongze/hongze_cygx/utils"
+	"strings"
+)
+
+var (
+	UserPermissionOperationModeApply      = "Apply"
+	UserPermissionOperationModeCall       = "Call"
+	UserPermissionPopupMsgApplyActivity   = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
+	UserPermissionPopupMsgCallActivity    = "您暂无权限参加此活动,若想参加可以联系对口销售"
+	UserPermissionPopupMsgApplyMicroVideo = "您暂无权限查看此视频,若想查看可以申请开通对应的试用权限"
+	UserPermissionPopupMsgCallMicroVideo  = "您暂无权限查看此视频若想查看可以联系对口销售"
+)
+
+// GetUserRaiPermissionInfo 获取权限类型及信息
+func GetUserRaiPermissionInfo(userId, companyId int) (authInfo models.UserPermissionAuthInfo, permissionArr []string, err error) {
+	// 用户申请记录
+	applyCount, e := models.GetApplyRecordCount(userId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("获取用户申请信息失败, Err: " + e.Error())
+		return
+	}
+
+	// 潜在用户
+	if companyId <= 1 {
+		authInfo.HasPermission = 3
+		if applyCount > 0 {
+			authInfo.HasPermission = 4
+		}
+		authInfo.OperationMode = UserPermissionOperationModeApply
+		authInfo.PopupMsg = UserPermissionPopupMsgApplyActivity
+		return
+	}
+
+	// 销售信息
+	ficcSeller, e := models.GetSellerByCompanyIdCheckFicc(companyId, utils.COMPANY_PRODUCT_FICC_ID)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("获取FICC销售信息失败, Err: " + e.Error())
+		return
+	}
+	raiSeller, e := models.GetSellerByCompanyIdCheckFicc(companyId, utils.COMPANY_PRODUCT_RAI_ID)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("获取权益销售信息失败, Err: " + e.Error())
+		return
+	}
+
+	// permissions示例: 医药,消费,科技,智造,策略,专家,买方研选
+	permissions, e := models.GetCompanyPermission(companyId)
+	if e != nil {
+		err = errors.New("获取客户权限失败, Err: " + e.Error())
+		return
+	}
+	if permissions == "" {
+		// 试用已申请过
+		if applyCount > 0 {
+			authInfo.HasPermission = 4
+			return
+		}
+		// 仅有FICC权限
+		if ficcSeller != nil && raiSeller == nil {
+			authInfo.HasPermission = 5
+			return
+		}
+		// 无权益权限
+		if raiSeller != nil {
+			// 有销售信息
+			authInfo.HasPermission = 2
+			authInfo.SellerMobile = raiSeller.Mobile
+			authInfo.SellerName = raiSeller.RealName
+			authInfo.OperationMode = UserPermissionOperationModeCall
+			authInfo.PopupMsg = UserPermissionPopupMsgCallActivity
+			return
+		}
+		// 无销售信息, 无申请
+		authInfo.HasPermission = 3
+		return
+	}
+	// 有基本的权益权限
+	authInfo.HasPermission = 1
+	permissionArr = strings.Split(permissions, ",")
+	return
+}

+ 22 - 0
utils/common.go

@@ -732,3 +732,25 @@ func ReplaceSpaceAndWrap(str string) string {
 	str = strings.Replace(str, "\n", "", -1)
 	return str
 }
+
+// InArrayByInt php中的in_array(判断Int类型的切片中是否存在该int值)
+func InArrayByInt(idIntList []int, searchId int) (has bool) {
+	for _, id := range idIntList {
+		if id == searchId {
+			has = true
+			return
+		}
+	}
+	return
+}
+
+// InArrayByStr php中的in_array(判断String类型的切片中是否存在该string值)
+func InArrayByStr(idStrList []string, searchId string) (has bool) {
+	for _, id := range idStrList {
+		if id == searchId {
+			has = true
+			return
+		}
+	}
+	return
+}

+ 7 - 0
utils/constants.go

@@ -118,3 +118,10 @@ const (
 	ACTIVITY_ZXDY_ImgUrl2 = "https://hzstatic.hzinsights.com/static/temp/20220830202208/20220830/UERktOWyQQEoPeckdy01TEZP09Pu.png"
 	ACTIVITY_ZXDY_ImgUrl3 = "https://hzstatic.hzinsights.com/static/temp/20220830202208/20220830/Db2eF5jffaJlLqq1KtOgrBkddoxZ.png"
 )
+
+const (
+	COMPANY_PRODUCT_FICC_ID   = 1
+	COMPANY_PRODUCT_FICC_NAME = "ficc"
+	COMPANY_PRODUCT_RAI_ID    = 2
+	COMPANY_PRODUCT_RAI_NAME  = "权益"
+)