123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- package cygx
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hz_crm_api/controllers"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/cygx"
- cygxService "hongze/hz_crm_api/services/cygx"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- "time"
- )
- // 系列问答视频
- type AskserieVideoController struct {
- controllers.BaseAuthController
- }
- // @Title 新增
- // @Description 新增系列问答接口
- // @Param request body cygx.AddProductInteriorReq true "type json string"
- // @Success 200 {object} "保存成功"
- // @router /askserie_video/preserveAndEdit [post]
- func (this *AskserieVideoController) PreserveAndPublish() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req cygx.AddAskserieVideoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- askserieVideoId := req.AskserieVideoId
- videoName := req.VideoName
- videoUrl := req.VideoUrl
- videoDuration := req.VideoDuration
- chartPermissionId := req.ChartPermissionId
- chartPermissionName := req.ChartPermissionName
- industrialManagementIds := req.IndustrialManagementIds
- backgroundImg := req.BackgroundImg
- shareImg := req.ShareImg
- // 产业ID校验
- if industrialManagementIds != "" {
- industrialManagementIdList := strings.Split(industrialManagementIds, ",")
- for _, v := range industrialManagementIdList {
- _, err := strconv.Atoi(v)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "产业ID不规范,Err:" + err.Error() + industrialManagementIds
- return
- }
- }
- }
- item := new(cygx.CygxAskserieVideo)
- item.AskserieVideoId = askserieVideoId
- item.VideoName = videoName
- item.VideoUrl = videoUrl
- item.VideoDuration = videoDuration
- item.ChartPermissionId = chartPermissionId
- item.ChartPermissionName = chartPermissionName
- item.PublishStatus = 1
- item.BackgroundImg = backgroundImg
- item.ShareImg = shareImg
- item.AdminId = sysUser.AdminId
- item.ModifyDate = time.Now()
- item.PublishDate = time.Now()
- item.CreateTime = time.Now()
- if askserieVideoId == 0 {
- //新增
- err = cygx.AddCygxAskserieVideo(item, industrialManagementIds)
- } else {
- //更新
- _, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
- if err != nil {
- br.Msg = "详情不存在"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- err = cygx.UpdateCygxAskserieVideo(item, industrialManagementIds)
- }
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "保存失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.IsAddLog = true
- br.Msg = "操作成功"
- }
- // @Title 列表
- // @Description 列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
- // @Param EndDate query string false "结束时间,列如2021-03-06 "
- // @Param PublishStatus query int true "发布状态: -1-默认全部; 0-未发布; 1-已关注"
- // @Param ChartPermissionId query string false "行业Id"
- // @Success Ret=200 {object} cygx.GetCygxTacticsTimeLineResp
- // @router /askserie_video/list [get]
- func (this *AskserieVideoController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- resp := new(cygx.GetCygxAskserieVideoRespListResp)
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- publishStatus, _ := this.GetInt("PublishStatus", -1)
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- chartPermissionId, _ := this.GetInt("ChartPermissionId")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //发布状态查询
- if publishStatus == 0 || publishStatus == 1 {
- condition += ` AND art.publish_status = ? `
- pars = append(pars, publishStatus)
- }
- //起始日期查询
- if startDate != "" && endDate != "" {
- condition += ` AND art.publish_time BETWEEN ? AND ? `
- pars = append(pars, startDate, endDate)
- }
- //行业查询
- if chartPermissionId > 0 {
- condition += ` AND art.chart_permission_id = ?`
- pars = append(pars, chartPermissionId)
- }
- total, err := cygx.GetCygxAskserieVideoCount(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- condition += " ORDER BY art.modify_date DESC "
- list, err := cygx.GetCygxAskserieVideoList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- var askserieVideoIds []int
- for _, v := range list {
- askserieVideoIds = append(askserieVideoIds, v.AskserieVideoId)
- }
- mapLabel := cygxService.GetCygxAskserieVideoLabelMap(askserieVideoIds) // 标签
- for _, v := range list {
- v.IndustryName = mapLabel[v.AskserieVideoId]
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 详情
- // @Description 获取详情接口
- // @Param AskserieVideoId query int true "ID"
- // @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
- // @router /askserie_video/detail [get]
- func (this *AskserieVideoController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- AdminUser := this.SysUser
- if AdminUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- resp := new(cygx.GetCygxAskserieVideoDetailResp)
- askserieVideoId, _ := this.GetInt("AskserieVideoId")
- if askserieVideoId < 1 {
- br.Msg = "请输入详情ID"
- return
- }
- detail, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
- if err != nil {
- br.Msg = "详情不存在"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- //产业标签
- industrialListMap := cygxService.GetCygxAskserieVideoLabelListMap([]int{askserieVideoId})
- detail.ListIndustrial = industrialListMap[askserieVideoId]
- resp.Detail = detail
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 播放记录详情
- // @Description 播放记录详情接口
- // @Param AskserieVideoId query int true "ID"
- // @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
- // @router /askserie_video/history_list [get]
- func (this *AskserieVideoController) HistoryList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- AdminUser := this.SysUser
- if AdminUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- resp := new(cygx.CygxCygxAskserieVideoHistoryRecordListResp)
- askserieVideoId, _ := this.GetInt("AskserieVideoId")
- if askserieVideoId < 1 {
- br.Msg = "请输入详情ID"
- return
- }
- _, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
- if err != nil {
- br.Msg = "详情不存在"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- var condition string
- var pars []interface{}
- condition = ` AND askserie_video_id = ? ORDER BY id DESC `
- pars = append(pars, askserieVideoId)
- list, err := cygx.GetCygxAskserieVideoHistoryRecordList(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 留言记录详情
- // @Description 留言记录详情接口
- // @Param AskserieVideoId query int true "ID"
- // @Success Ret=200 {object} cygx.GetCygxProductInteriorDetailResp
- // @router /askserie_video/collection_list [get]
- func (this *AskserieVideoController) CollectionList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- AdminUser := this.SysUser
- if AdminUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- resp := new(cygx.CygxAskserieVideoCollectionListResp)
- askserieVideoId, _ := this.GetInt("AskserieVideoId")
- if askserieVideoId < 1 {
- br.Msg = "请输入详情ID"
- return
- }
- _, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
- if err != nil {
- br.Msg = "详情不存在"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- var condition string
- var pars []interface{}
- condition = ` AND askserie_video_id = ? ORDER BY id DESC `
- pars = append(pars, askserieVideoId)
- list, err := cygx.GetCygxAskserieVideoCollectionList(condition, pars)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 发布/取消发布
- // @Description 发布/取消发布接口
- // @Param request body cygx.ProductInteriorIdReq true "type json string"
- // @Success 200 Ret=200 发布成功
- // @router /askserie_video/publishAndcancel [post]
- func (this *AskserieVideoController) PublishReport() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req cygx.AskserieVideoIdIdReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- askserieVideoId := req.AskserieVideoId
- if askserieVideoId == 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,id不可为空"
- return
- }
- detail, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
- if err != nil {
- br.Msg = "详情不存在"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- var status int
- if detail.PublishStatus == 0 {
- status = 1
- } else {
- status = 0
- //go cygxService.UpdateResourceData(productInteriorId, "productinterior", "delete", time.Now().Format(utils.FormatDateTime))
- //go cygxService.UpdateProductInteriorResourceData(productInteriorId) //写入首页最新 cygx_resource_data 表
- }
- err = cygx.EditCygxAskserieVideoStatus(status, askserieVideoId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|