123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_web_mfyx/models"
- "hongze/hongze_web_mfyx/utils"
- "strconv"
- "strings"
- )
- func GetResourceDataList(condition string, pars []interface{}, startSize, pageSize int, user *models.WxUserItem) (items []*models.CygxResourceDataNewResp, err error) {
- uid := user.UserId
- list, e := models.GetResourceDataList(condition, pars, startSize, pageSize)
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- mapItems := make(map[string]*models.CygxResourceDataNewResp)
- for _, v := range list {
-
- item := new(models.CygxResourceDataNewResp)
- item.Id = v.Id
- item.SourceId = v.SourceId
- item.Source = v.Source
-
-
-
- item.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
- mapItems[fmt.Sprint(v.Source, v.SourceId)] = item
- }
- var articleIds []int
- var activityIds []int
- var activityvideoIds []string
- var activityvoiceIds []string
- var yanxuanSpecialIds []int
- var roadshowIds []string
- var askserieVideoIds []string
-
- for _, v := range list {
- if v.Source == "article" {
- articleIds = append(articleIds, v.SourceId)
- } else if v.Source == "activity" {
- activityIds = append(activityIds, v.SourceId)
- } else if v.Source == "activityvideo" {
- activityvideoIds = append(activityvideoIds, strconv.Itoa(v.SourceId))
- } else if v.Source == "activityvoice" {
- activityvoiceIds = append(activityvoiceIds, strconv.Itoa(v.SourceId))
- } else if v.Source == utils.CYGX_OBJ_YANXUANSPECIAL {
- yanxuanSpecialIds = append(yanxuanSpecialIds, v.SourceId)
- }
- }
- detail, e := models.GetConfigByCode("city_img_url")
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- detailChart, e := models.GetConfigByCode("chart_img_url")
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- addressList := strings.Split(detail.ConfigValue, "{|}")
- mapAddress := make(map[string]string)
- chartList := strings.Split(detailChart.ConfigValue, "{|}")
- mapChart := make(map[string]string)
- var cityName string
- var chartName string
- var imgUrl string
- var imgUrlChart string
- for _, v := range addressList {
- vslice := strings.Split(v, "_")
- cityName = vslice[0]
- imgUrl = vslice[len(vslice)-1]
- mapAddress[cityName] = imgUrl
- }
- for _, v := range chartList {
- vslice := strings.Split(v, "_")
- chartName = vslice[0]
- imgUrlChart = vslice[len(vslice)-1]
- mapChart[chartName] = imgUrlChart
- }
- var imgUrlResp string
-
- if len(articleIds) > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND a.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
- pars = append(pars, articleIds)
- articleList, e := models.GetHomeListPublic(condition, pars, 0, len(articleIds))
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- articleList, e = HandleArticleCategoryImg(articleList, user)
- if e != nil {
- err = errors.New("HandleArticleCategoryImg, Err: " + e.Error())
- return
- }
- for _, v := range articleList {
- v.Body = ""
- mapItems[fmt.Sprint("article", v.ArticleId)].Article = v
- }
- }
-
- if len(activityIds) > 0 {
-
-
-
- pars = make([]interface{}, 0)
- condition = ` AND art.activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
- pars = append(pars, activityIds)
- activityList, e := models.GetActivityListNew(condition, pars, uid, 0, len(activityIds), 0, 0, "")
- if e != nil {
- err = errors.New("GetResourceDataList, Err: " + e.Error())
- return
- }
- var activityListRersp []*models.ActivityListResp
-
-
-
- activityListRersp = ActivityArrButtonShow(activityList, user, make([]string, 0))
-
- mapActivitySignup, e := GetActivitySignupResp(activityIds, user)
- if e != nil {
- err = errors.New("GetActivitySignupResp, Err: " + e.Error())
- return
- }
- for _, v := range activityListRersp {
- if v == nil {
- continue
- }
- if v.ActivityType == 0 {
- if mapAddress[v.City] != "" {
- imgUrlResp = mapAddress[v.City]
- } else {
- imgUrlResp = mapAddress["其它"]
- }
- } else {
- if mapChart[v.ChartPermissionName] != "" {
- imgUrlResp = mapChart[v.ChartPermissionName]
- }
- }
- v.ImgUrl = imgUrlResp
- v.SourceType = mapActivitySignup[v.ActivityId]
- mapItems[fmt.Sprint("activity", v.ActivityId)].Activity = v
- }
- }
-
- lenyanxuanSpecialIds := len(yanxuanSpecialIds)
- if lenyanxuanSpecialIds > 0 {
- pars = make([]interface{}, 0)
- condition = ` AND a.id IN (` + utils.GetOrmInReplace(lenyanxuanSpecialIds) + `) `
- pars = append(pars, yanxuanSpecialIds)
- listyanxuanSpecial, e := models.GetYanxuanSpecialListHome(user.UserId, condition, pars, 0, 0)
- if e != nil {
- err = errors.New("GetYanxuanSpecialList, Err: " + e.Error())
- return
- }
- yanxuanSpecialPv := GetYanxuanSpecialRecordByYanxuanSpecialId(yanxuanSpecialIds)
- for _, v := range listyanxuanSpecial {
- v.PublishTime = utils.TimeRemoveHms2(v.PublishTime)
- v.Annotation, _ = GetReportContentTextSubNew(v.Content)
- v.Content = ""
- v.Pv = yanxuanSpecialPv[v.Id]
- v.LabelKeywordImgLink = utils.LABEL_ICO_4
- mapItems[fmt.Sprint(utils.CYGX_OBJ_YANXUANSPECIAL, v.Id)].YanxuanSpecial = v
- }
- }
- if len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds) > 0 {
- audioIdstr := strings.Join(activityvoiceIds, ",")
- activityVideoIdsStr := strings.Join(activityvideoIds, ",")
- roadshowIdsStr := strings.Join(roadshowIds, ",")
- askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
- listv, _, e := GetMicroRoadShowMycollectV12(len(roadshowIds)+len(activityvideoIds)+len(activityvoiceIds)+len(askserieVideoIds), 0, audioIdstr, activityVideoIdsStr, roadshowIdsStr, askserieVideoIdsStr, user)
- if e != nil {
- err = errors.New("GetMicroRoadShowMycollect, Err: " + e.Error())
- return
- }
-
- authInfo, permissionArr, e := GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
- if e != nil {
- err = errors.New("GetUserRaiPermissionInfo, Err: " + e.Error())
- return
- }
-
- audioMap, videoMap, audioShareMap, videoShareMap, e := GetMicroRoadShowDefaultImgConfig()
- if e != nil {
- err = errors.New("GetMicroRoadShowDefaultImgConfig, Err: " + e.Error())
- return
- }
-
- for i := range listv {
-
- au := new(models.UserPermissionAuthInfo)
- au.SellerName = authInfo.SellerName
- au.SellerMobile = authInfo.SellerMobile
- au.HasPermission = authInfo.HasPermission
- au.OperationMode = authInfo.OperationMode
- if au.HasPermission == 1 {
-
- if listv[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, listv[i].ChartPermissionName) {
- au.HasPermission = 2
- }
- }
-
- if au.HasPermission != 1 {
- if au.OperationMode == UserPermissionOperationModeCall {
- if listv[i].Type == 1 {
- au.PopupMsg = UserPermissionPopupMsgCallActivity
- } else {
- au.PopupMsg = UserPermissionPopupMsgCallMicroVideo
- }
- } else {
- if listv[i].Type == 1 {
- au.PopupMsg = UserPermissionPopupMsgApplyActivity
- } else {
- au.PopupMsg = UserPermissionPopupMsgApplyMicroVideo
- }
- }
- }
- listv[i].AuthInfo = au
- listv[i].PublishTime = utils.StrTimeToTime(listv[i].PublishTime).Format(utils.FormatDate)
-
- if listv[i].BackgroundImg == "" {
- if listv[i].Type == 1 {
- listv[i].BackgroundImg = audioMap[listv[i].ChartPermissionId]
- } else {
- listv[i].BackgroundImg = videoMap[listv[i].ChartPermissionId]
- }
- }
-
- if listv[i].ShareImg == "" {
- if listv[i].Type == 1 {
- listv[i].ShareImg = audioShareMap[listv[i].ChartPermissionId]
- } else {
- listv[i].ShareImg = videoShareMap[listv[i].ChartPermissionId]
- }
- }
- listv[i].LabelKeywordImgLink = utils.LABEL_ICO_10
- }
-
- for _, item := range listv {
- if item.Type == 1 {
- mapItems[fmt.Sprint("activityvoice", item.Id)].Activityvoice = item
- } else if item.Type == 2 {
- mapItems[fmt.Sprint("activityvideo", item.Id)].Activityvideo = item
- } else if item.Type == 3 {
- mapItems[fmt.Sprint("roadshow", item.Id)].Roadshow = item
- } else if item.Type == 4 {
- mapItems[fmt.Sprint(utils.CYGX_OBJ_ASKSERIEVIDEO, item.Id)].AskserieVideo = item
- }
- }
- }
- for _, vList := range list {
- for _, v := range mapItems {
-
- if v.Article == nil && v.Activity == nil && v.Activityvideo == nil && v.Activityvoice == nil && v.YanxuanSpecial == nil {
- continue
- }
- if v.SourceId == vList.SourceId && v.Source == vList.Source {
- items = append(items, v)
- }
- }
- }
- return
- }
|