|
@@ -3,8 +3,8 @@ package controllers
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"hongze/hz_crm_api/models"
|
|
|
+ "hongze/hz_crm_api/services"
|
|
|
"hongze/hz_crm_api/utils"
|
|
|
- "time"
|
|
|
)
|
|
|
|
|
|
// ClassifyController 分类
|
|
@@ -26,112 +26,21 @@ func (this *ClassifyController) ListClassify() {
|
|
|
this.Data["json"] = br
|
|
|
this.ServeJSON()
|
|
|
}()
|
|
|
-
|
|
|
keyWord := this.GetString("KeyWord")
|
|
|
companyType := this.GetString("CompanyType")
|
|
|
hideDayWeek, _ := this.GetInt("HideDayWeek")
|
|
|
|
|
|
- reqEnabled, _ := this.GetInt("Enabled", -1)
|
|
|
- enabled := -1
|
|
|
- if reqEnabled == 1 {
|
|
|
- enabled = reqEnabled
|
|
|
- }
|
|
|
-
|
|
|
- list, err := models.GetClassifyList(keyWord, companyType, hideDayWeek, enabled)
|
|
|
+ req := new(services.GetClassifyListReq)
|
|
|
+ req.Keyword = keyWord
|
|
|
+ req.CompanyType = companyType
|
|
|
+ req.HideDayWeek = hideDayWeek
|
|
|
+ resp, err := services.GetClassifyList(req)
|
|
|
if err != nil {
|
|
|
br.Msg = "获取失败"
|
|
|
br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- parentIds := make([]int, 0)
|
|
|
- for i := range list {
|
|
|
- parentIds = append(parentIds, list[i].Id)
|
|
|
- }
|
|
|
- parentIdLen := len(parentIds)
|
|
|
- if parentIdLen == 0 {
|
|
|
- resp := &models.ClassifyListResp{
|
|
|
- List: list,
|
|
|
- }
|
|
|
- br.Data = resp
|
|
|
- br.Ret = 200
|
|
|
- br.Success = true
|
|
|
- br.Msg = "获取成功"
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 获取一级分类-子目录列表
|
|
|
- menuListMap := make(map[int][]*models.ClassifyMenu, 0)
|
|
|
- var menuCond string
|
|
|
- var menuPars []interface{}
|
|
|
- menuCond += ` AND classify_id IN (` + utils.GetOrmInReplace(parentIdLen) + `)`
|
|
|
- menuPars = append(menuPars, parentIds)
|
|
|
- parentMenus, e := models.GetClassifyMenuList(menuCond, menuPars)
|
|
|
- if e != nil {
|
|
|
- br.Msg = "获取失败"
|
|
|
- br.ErrMsg = "获取一级分类子目录列表失败"
|
|
|
- return
|
|
|
- }
|
|
|
- for i := range parentMenus {
|
|
|
- if menuListMap[parentMenus[i].ClassifyId] == nil {
|
|
|
- menuListMap[parentMenus[i].ClassifyId] = make([]*models.ClassifyMenu, 0)
|
|
|
- }
|
|
|
- menuListMap[parentMenus[i].ClassifyId] = append(menuListMap[parentMenus[i].ClassifyId], parentMenus[i])
|
|
|
- }
|
|
|
-
|
|
|
- // 获取子分类
|
|
|
- children, e := models.GetClassifyChildByParentIds(parentIds, keyWord, enabled)
|
|
|
- if e != nil {
|
|
|
- br.Msg = "获取失败"
|
|
|
- br.ErrMsg = "获取子分类失败"
|
|
|
- return
|
|
|
- }
|
|
|
- childrenIds := make([]int, 0)
|
|
|
- for i := range children {
|
|
|
- childrenIds = append(childrenIds, children[i].Id)
|
|
|
- }
|
|
|
- childrenIdsLen := len(childrenIds)
|
|
|
-
|
|
|
- // 获取二级分类-子目录关联
|
|
|
- relateMap := make(map[int]int, 0)
|
|
|
- if childrenIdsLen > 0 {
|
|
|
- var relateCond string
|
|
|
- var relatePars []interface{}
|
|
|
- relateCond += ` AND classify_id IN (` + utils.GetOrmInReplace(childrenIdsLen) + `)`
|
|
|
- relatePars = append(relatePars, childrenIds)
|
|
|
- relates, e := models.GetClassifyMenuRelationList(relateCond, relatePars)
|
|
|
- if e != nil {
|
|
|
- br.Msg = "获取失败"
|
|
|
- br.ErrMsg = "获取二级分类子目录关联失败, Err: " + e.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- for i := range relates {
|
|
|
- relateMap[relates[i].ClassifyId] = relates[i].MenuId
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 二级分类
|
|
|
- childrenMap := make(map[int][]*models.ClassifyItem, 0)
|
|
|
- for i := range children {
|
|
|
-
|
|
|
- if childrenMap[children[i].ParentId] == nil {
|
|
|
- childrenMap[children[i].ParentId] = make([]*models.ClassifyItem, 0)
|
|
|
- }
|
|
|
- tmp := &models.ClassifyItem{
|
|
|
- Classify: *children[i],
|
|
|
- ClassifyMenuId: relateMap[children[i].Id],
|
|
|
- }
|
|
|
- childrenMap[children[i].ParentId] = append(childrenMap[children[i].ParentId], tmp)
|
|
|
- }
|
|
|
-
|
|
|
- // 一级分类
|
|
|
- for i := range list {
|
|
|
- list[i].ClassifyMenuList = menuListMap[list[i].Id]
|
|
|
- list[i].Child = childrenMap[list[i].Id]
|
|
|
- }
|
|
|
-
|
|
|
- resp := new(models.ClassifyListResp)
|
|
|
- resp.List = list
|
|
|
br.Data = resp
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
@@ -143,6 +52,7 @@ func (this *ClassifyController) ListClassify() {
|
|
|
// @Success 200 {object} models.Classify
|
|
|
// @router /tel_list [get]
|
|
|
func (this *ClassifyController) TelListClassify() {
|
|
|
+ // todo 获取电话会 是否需要改成从中间服务项目中获取
|
|
|
br := new(models.BaseResponse).Init()
|
|
|
defer func() {
|
|
|
this.Data["json"] = br
|
|
@@ -187,155 +97,43 @@ func (this *ClassifyController) TelListClassify() {
|
|
|
// @router /edit [post]
|
|
|
func (this *ClassifyController) Edit() {
|
|
|
br := new(models.BaseResponse).Init()
|
|
|
+ br.IsSendEmail = false
|
|
|
defer func() {
|
|
|
this.Data["json"] = br
|
|
|
this.ServeJSON()
|
|
|
}()
|
|
|
- var req models.EditClassifyReq
|
|
|
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
- if err != nil {
|
|
|
+ sysUser := this.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var req services.EditClassifyReq
|
|
|
+ if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
|
|
|
br.Msg = "参数解析异常!"
|
|
|
br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
if req.ClassifyId <= 0 {
|
|
|
- br.Msg = "参数错误"
|
|
|
+ br.Msg = "分类ID有误"
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- item, err := models.GetClassifyById(req.ClassifyId)
|
|
|
+ err, errMsg := services.EditReportClassify(&req)
|
|
|
if err != nil {
|
|
|
- if err.Error() == utils.ErrNoRow() {
|
|
|
- br.Msg = "分类不存在, 或已被删除"
|
|
|
- br.ErrMsg = "获取分类信息失败, Err: " + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- br.Msg = "获取信息失败"
|
|
|
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if item.ParentId != 0 && req.ShowType == 0 {
|
|
|
- br.Msg = "展示类型不可为空"
|
|
|
- return
|
|
|
- }
|
|
|
- if (req.ShowType == 1 || req.ShowType == 3) && req.YbRightBanner == "" && item.ParentId == 0 { //当一级报告分类为列表、品种时,增加“报告合集配图”的配置项
|
|
|
- br.Msg = "报告合集配图不可为空"
|
|
|
- return
|
|
|
- }
|
|
|
- //originRelateTel := item.RelateTel
|
|
|
- item.ModifyTime = time.Now().Local()
|
|
|
- /*item.Abstract = req.Abstract
|
|
|
- item.Descript = req.Descript
|
|
|
- item.ReportAuthor = req.ReportAuthor
|
|
|
- item.AuthorDescript = req.AuthorDescript
|
|
|
- item.ColumnImgUrl = req.ColumnImgUrl
|
|
|
- item.HeadImgUrl = req.HeadImgUrl
|
|
|
- item.AvatarImgUrl = req.AvatarImgUrl
|
|
|
- item.ReportImgUrl = req.ReportImgUrl
|
|
|
- item.HomeImgUrl = req.HomeImgUrl*/
|
|
|
- item.ClassifyLabel = req.ClassifyLabel
|
|
|
- item.ShowType = req.ShowType
|
|
|
- /* item.HasTeleconference = req.HasTeleconference
|
|
|
- item.VipTitle = req.VipTitle*/
|
|
|
- // item.Sort = req.Sort
|
|
|
- item.IsShow = req.IsShow
|
|
|
- item.YbFiccSort = req.YbFiccSort
|
|
|
- item.YbFiccIcon = req.YbFiccIcon
|
|
|
- item.YbFiccPcIcon = req.YbFiccPcIcon
|
|
|
- item.YbIconUrl = req.YbIconUrl
|
|
|
- item.YbBgUrl = req.YbBgUrl
|
|
|
- item.YbListImg = req.YbListImg
|
|
|
- item.YbShareBgImg = req.YbShareBgImg
|
|
|
- item.YbRightBanner = req.YbRightBanner
|
|
|
- //item.RelateTel = req.RelateTel
|
|
|
- item.RelateVideo = req.RelateVideo
|
|
|
- item.ModifyTime = time.Now().Local()
|
|
|
- cols := make([]string, 0)
|
|
|
- /*cols = append(cols, "Abstract", "Descript", "ReportAuthor", "AuthorDescript", "ColumnImgUrl",
|
|
|
- "HeadImgUrl", "AvatarImgUrl", "ReportImgUrl", "HomeImgUrl", "ClassifyLabel", "ShowType", "HasTeleconference", "VipTitle",
|
|
|
- "IsShow", "YbFiccSort", "YbFiccIcon", "YbFiccPcIcon", "YbIconUrl", "YbBgUrl", "YbListImg", "YbShareBgImg", "YbRightBanner",
|
|
|
- "RelateTel", "RelateVideo", "ModifyTime")*/
|
|
|
- cols = append(cols, "ClassifyLabel", "ShowType",
|
|
|
- "IsShow", "YbFiccSort", "YbFiccIcon", "YbFiccPcIcon", "YbIconUrl", "YbBgUrl", "YbListImg", "YbShareBgImg", "YbRightBanner", "RelateVideo", "ModifyTime")
|
|
|
- if e := item.UpdateClassify(cols); e != nil {
|
|
|
- br.Msg = "修改失败"
|
|
|
- br.ErrMsg = "修改失败,Err:" + e.Error()
|
|
|
+ br.Msg = errMsg
|
|
|
+ br.ErrMsg = "编辑报告分类失败, Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 获取编辑前子目录列表
|
|
|
- classifyId := item.Id
|
|
|
- var menuCond string
|
|
|
- var menuPars []interface{}
|
|
|
- menuCond += ` AND classify_id = ?`
|
|
|
- menuPars = append(menuPars, classifyId)
|
|
|
- menuList, e := models.GetClassifyMenuList(menuCond, menuPars)
|
|
|
- if e != nil {
|
|
|
- br.Msg = "保存失败"
|
|
|
- br.ErrMsg = "获取分类子目录列表失败, Err:" + e.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- oriMenuIds := make([]int, 0)
|
|
|
- for i := range menuList {
|
|
|
- oriMenuIds = append(oriMenuIds, menuList[i].MenuId)
|
|
|
- }
|
|
|
-
|
|
|
- // 一级分类-新增/编辑/删除子目录
|
|
|
- if item.ParentId == 0 && len(req.MenuList) > 0 {
|
|
|
- nowTime := time.Now().Local()
|
|
|
- insertMenus := make([]*models.ClassifyMenu, 0)
|
|
|
- editMenus := make([]*models.ClassifyMenu, 0)
|
|
|
- deleteMenuIds := make([]int, 0)
|
|
|
- menuIds := make([]int, 0)
|
|
|
- for i := range req.MenuList {
|
|
|
- m := req.MenuList[i]
|
|
|
-
|
|
|
- v := new(models.ClassifyMenu)
|
|
|
- v.MenuName = req.MenuList[i].MenuName
|
|
|
- v.ClassifyId = classifyId
|
|
|
- v.Sort = i + 1
|
|
|
- v.MenuId = m.MenuId
|
|
|
- v.ModifyTime = nowTime
|
|
|
- if v.MenuId > 0 {
|
|
|
- // 编辑
|
|
|
- editMenus = append(editMenus, v)
|
|
|
- menuIds = append(menuIds, m.MenuId)
|
|
|
- } else {
|
|
|
- // 新增
|
|
|
- v.CreateTime = nowTime
|
|
|
- insertMenus = append(insertMenus, v)
|
|
|
- }
|
|
|
- }
|
|
|
- // 编辑前存在子目录则取"编辑前子目录IDs与编辑时子目录IDs的差集"作为删除IDs
|
|
|
- if len(oriMenuIds) > 0 {
|
|
|
- deleteMenuIds = utils.MinusInt(oriMenuIds, menuIds)
|
|
|
- }
|
|
|
- if e = models.InsertAndUpdateClassifyMenu(insertMenus, editMenus, deleteMenuIds); e != nil {
|
|
|
- br.Msg = "保存失败"
|
|
|
- br.ErrMsg = "新增/编辑/删除分类子目录失败, Err:" + e.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 二级分类-新增子目录关联
|
|
|
- if item.ParentId > 0 {
|
|
|
- if e := models.DeleteAndInsertClassifyMenuRelation(classifyId, req.ClassifyMenuId); e != nil {
|
|
|
- br.Msg = "新增子目录关联失败"
|
|
|
- br.ErrMsg = "新增子目录关联失败, Err:" + e.Error()
|
|
|
- return
|
|
|
- }
|
|
|
+ // 清除小程序端的章节缓存
|
|
|
+ {
|
|
|
+ key := "hongze_yb:report_chapter_type:GetEffectTypeID"
|
|
|
+ _ = utils.Rc.Delete(key)
|
|
|
}
|
|
|
|
|
|
- // 关联电话会选项被更改时, 同步FICC活动分类
|
|
|
- //if originRelateTel != req.RelateTel {
|
|
|
- // go func() {
|
|
|
- // _ = yb.SyncClassifyAndFiccActivityType()
|
|
|
- // }()
|
|
|
- //}
|
|
|
-
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
- br.Msg = "修改成功"
|
|
|
+ br.Msg = "操作成功"
|
|
|
}
|