|
@@ -0,0 +1,142 @@
|
|
|
+package controllers
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "hongze/hz_crm_api/models"
|
|
|
+ "hongze/hz_crm_api/utils"
|
|
|
+)
|
|
|
+
|
|
|
+// ReportChapterTypeController 报告章节配置
|
|
|
+type ReportChapterTypeController struct {
|
|
|
+ BaseAuthController
|
|
|
+}
|
|
|
+
|
|
|
+// List
|
|
|
+// @Title 报告章节列表
|
|
|
+// @Description 报告章节列表
|
|
|
+// @Param ReportType query string true "报告类型: day-晨报; week-周报"
|
|
|
+// @Success 200 {object} models.ReportChapterTypePageListResp
|
|
|
+// @router /chapter_type/list [get]
|
|
|
+func (this *ReportChapterTypeController) List() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ br.IsSendEmail = false
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ reportType := this.GetString("ReportType")
|
|
|
+ typeArr := []string{utils.REPORT_TYPE_DAY, utils.REPORT_TYPE_WEEK}
|
|
|
+ if !utils.InArrayByStr(typeArr, reportType) {
|
|
|
+ br.Msg = "请选择报告类型"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ cond := ` AND research_type = ?`
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, reportType)
|
|
|
+ list, e := models.GetReportChapterTypePageList(cond, pars)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取报告章节列表失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ respList := make([]*models.ReportChapterTypeListItem, 0)
|
|
|
+ for i := range list {
|
|
|
+ respList = append(respList, &models.ReportChapterTypeListItem{
|
|
|
+ ReportChapterTypeId: list[i].ReportChapterTypeId,
|
|
|
+ ReportChapterTypeName: list[i].ReportChapterTypeName,
|
|
|
+ Sort: list[i].Sort,
|
|
|
+ CreatedTime: list[i].CreatedTime.Format(utils.FormatDateTime),
|
|
|
+ ResearchType: list[i].ResearchType,
|
|
|
+ SelectedImage: list[i].SelectedImage,
|
|
|
+ UnselectedImage: list[i].UnselectedImage,
|
|
|
+ WordsImage: list[i].YbBottomIcon, // 此处的不一样
|
|
|
+ EditImgUrl: list[i].EditImgUrl,
|
|
|
+ IsShow: list[i].IsShow,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ resp := new(models.ReportChapterTypeListResp)
|
|
|
+ resp.List = respList
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
+
|
|
|
+// Edit
|
|
|
+// @Title 编辑报告章节
|
|
|
+// @Description 编辑报告章节
|
|
|
+// @Param request body models.ReportChapterTypeEditReq true "type json string"
|
|
|
+// @Success 200 string "操作成功"
|
|
|
+// @router /chapter_type/edit [post]
|
|
|
+func (this *ReportChapterTypeController) Edit() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ br.IsSendEmail = false
|
|
|
+ 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 models.ReportChapterTypeEditReq
|
|
|
+ if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.ReportChapterTypeId <= 0 {
|
|
|
+ br.Msg = "章节ID有误"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ item, e := models.GetReportChapterTypeById(req.ReportChapterTypeId)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "获取报告章节失败, Err:" + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ item.SelectedImage = req.SelectedImage
|
|
|
+ item.UnselectedImage = req.UnselectedImage
|
|
|
+ item.PcSelectedImage = req.SelectedImage
|
|
|
+ item.PcUnselectedImage = req.UnselectedImage
|
|
|
+ item.EditImgUrl = req.EditImgUrl
|
|
|
+ item.YbIconUrl = req.UnselectedImage
|
|
|
+ item.YbBottomIcon = req.WordsImage
|
|
|
+ item.IsShow = req.IsShow
|
|
|
+ item.ReportChapterTypeThumb = req.EditImgUrl
|
|
|
+ item.BannerUrl = req.UnselectedImage
|
|
|
+
|
|
|
+ updateCols := []string{"SelectedImage", "UnselectedImage",
|
|
|
+ "PcSelectedImage", "PcUnselectedImage", "EditImgUrl", "YbIconUrl", "YbBottomIcon", "IsShow",
|
|
|
+ "ReportChapterTypeThumb", "BannerUrl",
|
|
|
+ }
|
|
|
+ if e = item.Update(updateCols); e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "更新报告章节失败, Err:" + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 清除小程序端的章节缓存
|
|
|
+ {
|
|
|
+ key := "hongze_yb:report_chapter_type:GetEffectTypeID"
|
|
|
+ _ = utils.Rc.Delete(key)
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "操作成功"
|
|
|
+}
|