123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- package community
- import (
- "errors"
- "hongze/hongze_yb/models/response"
- "hongze/hongze_yb/models/tables/chart_permission"
- "hongze/hongze_yb/models/tables/company_product"
- "hongze/hongze_yb/models/tables/yb_community_video"
- "hongze/hongze_yb/models/tables/yb_community_video_play_log"
- "hongze/hongze_yb/models/tables/yb_road_video"
- "hongze/hongze_yb/services/company"
- "hongze/hongze_yb/services/user"
- "hongze/hongze_yb/utils"
- "strconv"
- "strings"
- "time"
- )
- // GetVideoList 获取视频列表
- func GetVideoList(pageIndex, pageSize, videoId, varietyTagId int, keywords string) (resp []*response.CommunityVideoItem, err error) {
- condition := make(map[string]interface{})
- // 分享点进来的直接定位到具体视频
- if videoId > 0 {
- condition["community_video_id ="] = videoId
- } else {
- if varietyTagId > 0 {
- condition["variety_tag_id ="] = varietyTagId
- }
- if keywords != "" {
- condition["title like"] = "%" + keywords + "%"
- }
- }
- resp = make([]*response.CommunityVideoItem, 0)
- list, e := yb_community_video.GetPageListByCondition(condition, pageIndex, pageSize)
- if e != nil {
- err = errors.New("获取视频列表失败, Err:" + e.Error())
- return
- }
- if len(list) <= 0 {
- return
- }
- for _, v := range list {
- item := &response.CommunityVideoItem{
- CommunityVideoID: v.CommunityVideoID,
- Title: v.Title,
- VarietyTagId: v.VarietyTagId,
- VarietyTagName: v.VarietyTagName,
- CoverImgUrl: v.CoverImgURL,
- VideoUrl: v.VideoURL,
- VideoSeconds: v.VideoSeconds,
- PublishState: v.PublishState,
- PublishTime: v.PublishTime.Format(utils.FormatDateTime),
- CreateTime: v.CreateTime.Format(utils.FormatDateTime),
- ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
- ChartPermissionName: v.VarietyTagName,
- TencentId: getSubTencentUrl(v.TencentURL),
- }
- resp = append(resp, item)
- }
- return
- }
- // SaveVideoPlayLog 记录用户播放视频日志
- func SaveVideoPlayLog(userInfo user.UserInfo, videoId, sourceAgent int, videoType int8) (errMsg string, err error) {
- if videoType == 1 {
- _, e := yb_community_video.GetItemById(videoId)
- if e != nil {
- errMsg = "视频不存在或未发布"
- err = errors.New("获取视频信息失败, Err: " + e.Error())
- return
- }
- }else{
- _, e := yb_road_video.GetItemById(videoId)
- if e != nil {
- errMsg = "视频不存在或未发布"
- err = errors.New("获取视频信息失败, Err: " + e.Error())
- return
- }
- }
- companyInfo, e := company_product.GetByCompany2ProductId(userInfo.CompanyID, 1)
- if e != nil && e != utils.ErrNoRow {
- errMsg = "保存失败"
- err = errors.New("获取客户信息失败, Err: " + e.Error())
- return
- }
- companyName := "潜在客户"
- companyStatus := "潜在"
- sellerId := 0
- if companyInfo != nil && companyInfo.CompanyID > 0 {
- companyName = companyInfo.CompanyName
- companyStatus = companyInfo.Status
- sellerId = companyInfo.SellerID
- }
- item := &yb_community_video_play_log.YbCommunityVideoPlayLog{
- CommunityVideoID: videoId,
- UserID: int(userInfo.UserID),
- Mobile: userInfo.Mobile,
- RealName: userInfo.RealName,
- NickName: userInfo.NickName,
- CompanyID: int(userInfo.CompanyID),
- CompanyName: companyName,
- CompanyStatus: companyStatus,
- SourceAgent: sourceAgent,
- SellerID: sellerId,
- Type: videoType,
- CreateTime: time.Now().Local(),
- }
- if e = item.Create(); e != nil {
- errMsg = "操作失败"
- err = errors.New("新增播放视频日志失败, Err:" + e.Error())
- return
- }
- return
- }
- // getSubTencentUrl 获取腾讯视频链接子字符串
- func getSubTencentUrl(tencentUrl string) (sub string) {
- if tencentUrl != "" {
- st := strings.LastIndex(tencentUrl, "/")
- ed := strings.LastIndex(tencentUrl, ".")
- if st > 0 && ed > st {
- sub = tencentUrl[st+1 : ed]
- }
- }
- return
- }
- // GetRoadVideoList 获取线上路演视频列表
- func GetRoadVideoList(userInfo user.UserInfo, pageIndex, pageSize, videoId, chartPermissionId int, keywords string) (resp response.RoadVideoItemResp, err error) {
- list := make([]*response.RoadVideoItem, 0)
- //获取有权限的permissionID
- validPermissionList, err := company.GetValidPermissionByCompany2ProductId(userInfo.CompanyID, 1)
- if err != nil {
- return
- }
- ficcPermissionList, err := chart_permission.GetFiccListExceptTacticByProductId()
- if err != nil {
- return
- }
- permissionIds := ""
- validPermissionMap := make(map[string]struct{})
- ParentPermissionNameMap := make(map[string]string)
- ParentPermissionChildMap := make(map[string]int)
- for _, v := range validPermissionList {
- permissionIds += "'"+strconv.Itoa(v.ChartPermissionID) + "'|"
- validPermissionMap["'"+strconv.Itoa(v.ChartPermissionID)+"'"] = struct{}{}
- }
- for _, v := range ficcPermissionList {
- ParentPermissionNameMap["'"+strconv.Itoa(int(v.ChartPermissionID))+"'"] = v.ClassifyName
- ParentPermissionChildMap[v.ClassifyName] += 1
- }
- if permissionIds == "" {
- resp.List = list
- resp.Paging = response.GetPaging(pageIndex, pageSize, 0)
- return
- }
- permissionIds = strings.Trim(permissionIds,"|")
- condition := `is_deleted = 0 AND publish_state = 1 and chart_permission_ids REGEXP "(`+permissionIds+`)"`
- var par []interface{}
- // 分享点进来的直接定位到具体视频
- if videoId > 0 {
- condition += " and road_video_id = ?"
- par = append(par, videoId)
- } else {
- if chartPermissionId > 0 {
- condition += ` and FIND_IN_SET("'`+strconv.Itoa(chartPermissionId)+`'", chart_permission_ids)`
- }
- if keywords != "" {
- condition += " and title like ? "
- par = append(par,"%" + keywords + "%")
- }
- }
- videoList, total, e := yb_road_video.GetPageListByCondition(condition, par, pageIndex, pageSize)
- if e != nil {
- err = errors.New("获取视频列表失败, Err:" + e.Error())
- return
- }
- if len(videoList) <= 0 {
- resp.List = list
- resp.Paging = response.GetPaging(pageIndex, pageSize, 0)
- return
- }
- chartPermissionIdSlice := make([]int, 0)
- chartNameMap := make(map[string]string)
- for _, v := range videoList {
- tmp := strings.Split(v.ChartPermissionIds, ",")
- for _, t1 := range tmp {
- i, _ := strconv.Atoi(strings.Trim(t1, "'"))
- chartPermissionIdSlice = append(chartPermissionIdSlice, i)
- }
- }
- if len(chartPermissionIdSlice) > 0 {
- chartList, e := chart_permission.GetListByIds(chartPermissionIdSlice)
- if e != nil {
- err = errors.New("获取品种信息失败, Err:" + e.Error())
- return
- }
- for _, v := range chartList {
- chartNameMap["'"+strconv.Itoa(int(v.ChartPermissionID))+"'"] = v.PermissionName
- }
- }
- var chartPermissionNames string
- var parentPermissionName string
- for _, v := range videoList {
- chartPermissionNames = ""
- parentPermissionName = ""
- tmpSlice := strings.Split(v.ChartPermissionIds, ",")
- if len(tmpSlice) > 0 {
- // 判断是否有跨品种的chartPermissionID
- for _, cid := range tmpSlice {
- if p, ok := ParentPermissionNameMap[cid]; ok {
- if parentPermissionName == "" {
- parentPermissionName = p
- }else if parentPermissionName != p {
- parentPermissionName = ""
- break
- }
- }
- }
- //如果都是一个品种内,如果全部包含二级品种,则显示一级品种名称,否则展示全部二级品种
- if parentPermissionName != "" {
- hasNum := 0
- for _, cid := range tmpSlice {
- if _, ok := chartNameMap[cid]; ok {
- if _, ok1 := validPermissionMap[cid]; ok1 {
- hasNum += 1
- }
- }
- }
- if n, ok := ParentPermissionChildMap[parentPermissionName]; ok && n == hasNum {
- chartPermissionNames = parentPermissionName
- }
- }
- //如果包含跨品种则
- if chartPermissionNames == "" {
- for _, cid := range tmpSlice {
- if name, ok := chartNameMap[cid]; ok {
- if _, ok1 := validPermissionMap[cid]; ok1 {
- chartPermissionNames += name + ","
- }
- }
- }
- if chartPermissionNames != "" {
- chartPermissionNames = strings.Trim(chartPermissionNames, ",")
- }
- }
- }
- item := &response.RoadVideoItem{
- RoadVideoID: v.RoadVideoID,
- Title: v.Title,
- ChartPermissionIds: v.ChartPermissionIds,
- ChartPermissionName: chartPermissionNames,
- CoverImgUrl: v.CoverImgURL,
- VideoUrl: v.VideoURL,
- VideoSeconds: v.VideoSeconds,
- PublishState: v.PublishState,
- AdminId: v.AdminId,
- AdminRealName: v.AdminRealName,
- PublishTime: v.PublishTime.Format(utils.FormatDateTime),
- CreateTime: v.CreateTime.Format(utils.FormatDateTime),
- ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
- }
- list = append(list, item)
- }
- resp.List = list
- resp.Paging = response.GetPaging(pageIndex, pageSize, int(total))
- return
- }
|