正在显示
4 个修改的文件
包含
79 行增加
和
0 行删除
| @@ -164,6 +164,35 @@ func (this *TemplateController) TemplateEditVisible() { | @@ -164,6 +164,35 @@ func (this *TemplateController) TemplateEditVisible() { | ||
| 164 | msg = protocol.NewReturnResponse(rsp, err) | 164 | msg = protocol.NewReturnResponse(rsp, err) |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | +//TemplateEditSort 编辑模板排序 | ||
| 168 | +//@router /templateEditSort [post] | ||
| 169 | +func (this *TemplateController) TemplateEditSort() { | ||
| 170 | + var msg *protocol.ResponseMessage | ||
| 171 | + defer func() { | ||
| 172 | + this.ResposeJson(msg) | ||
| 173 | + }() | ||
| 174 | + var request *protocol.TemplateEditSortRequest | ||
| 175 | + | ||
| 176 | + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { | ||
| 177 | + log.Error("json 解析失败", err) | ||
| 178 | + msg = protocol.BadRequestParam("1") | ||
| 179 | + return | ||
| 180 | + } | ||
| 181 | + uid := this.GetUserId() | ||
| 182 | + companyId := this.GetCompanyId() | ||
| 183 | + if companyId <= 0 { | ||
| 184 | + log.Debug("companyId:%d err", companyId) | ||
| 185 | + msg = protocol.BadRequestParam("1") | ||
| 186 | + return | ||
| 187 | + } | ||
| 188 | + if b, m := this.Valid(request); !b { | ||
| 189 | + msg = m | ||
| 190 | + return | ||
| 191 | + } | ||
| 192 | + rsp, err := audit.TemplateEditSort(uid, companyId, request) | ||
| 193 | + msg = protocol.NewReturnResponse(rsp, err) | ||
| 194 | +} | ||
| 195 | + | ||
| 167 | //TemplateOperateCategory | 196 | //TemplateOperateCategory |
| 168 | //@router /templateOperateCategory [post] | 197 | //@router /templateOperateCategory [post] |
| 169 | func (this *TemplateController) TemplateOperateCategory() { | 198 | func (this *TemplateController) TemplateOperateCategory() { |
| @@ -161,3 +161,17 @@ type TemplateGetResponse struct { | @@ -161,3 +161,17 @@ type TemplateGetResponse struct { | ||
| 161 | Template Template `json:"template"` | 161 | Template Template `json:"template"` |
| 162 | Example string `json:"example"` //示例` | 162 | Example string `json:"example"` //示例` |
| 163 | } | 163 | } |
| 164 | + | ||
| 165 | +/*TemplateEditSort */ | ||
| 166 | +type TemplateEditSortRequest struct { | ||
| 167 | + ChanceTypeId int `json:"chance_type_id"` //机会类型编号 | ||
| 168 | + List []SortItem `json:"list"` //需要排序的列表 | ||
| 169 | +} | ||
| 170 | +type TemplateEditSortResponse struct { | ||
| 171 | +} | ||
| 172 | + | ||
| 173 | +//排序项 | ||
| 174 | +type SortItem struct { | ||
| 175 | + Id int `json:"id"` | ||
| 176 | + SortNum int `json:"sort_num"` | ||
| 177 | +} |
| @@ -69,6 +69,7 @@ func init() { | @@ -69,6 +69,7 @@ func init() { | ||
| 69 | beego.NSRouter("/get", &controllers.TemplateController{}, "post:TemplateGet"), | 69 | beego.NSRouter("/get", &controllers.TemplateController{}, "post:TemplateGet"), |
| 70 | beego.NSRouter("/update", &controllers.TemplateController{}, "post:TemplateUpdate"), | 70 | beego.NSRouter("/update", &controllers.TemplateController{}, "post:TemplateUpdate"), |
| 71 | beego.NSRouter("/editVisible", &controllers.TemplateController{}, "post:TemplateEditVisible"), | 71 | beego.NSRouter("/editVisible", &controllers.TemplateController{}, "post:TemplateEditVisible"), |
| 72 | + beego.NSRouter("/editSort", &controllers.TemplateController{}, "post:TemplateEditSort"), | ||
| 72 | beego.NSRouter("/operateCategory", &controllers.TemplateController{}, "post:TemplateOperateCategory"), | 73 | beego.NSRouter("/operateCategory", &controllers.TemplateController{}, "post:TemplateOperateCategory"), |
| 73 | ), | 74 | ), |
| 74 | ) | 75 | ) |
| @@ -262,6 +262,41 @@ func TemplateEditVisible(uid, companyId int64, request *protocol.TemplateEditVis | @@ -262,6 +262,41 @@ func TemplateEditVisible(uid, companyId int64, request *protocol.TemplateEditVis | ||
| 262 | return | 262 | return |
| 263 | } | 263 | } |
| 264 | 264 | ||
| 265 | +//编辑模板排序 | ||
| 266 | +func TemplateEditSort(uid, companyId int64, request *protocol.TemplateEditSortRequest) (rsp *protocol.TemplateEditSortResponse, err error) { | ||
| 267 | + var ( | ||
| 268 | + template *models.AuditTemplate | ||
| 269 | + ) | ||
| 270 | + if _, err = models.GetChanceTypeById(request.ChanceTypeId); err != nil { | ||
| 271 | + log.Error(err.Error()) | ||
| 272 | + return | ||
| 273 | + } | ||
| 274 | + orm := orm2.NewOrm() | ||
| 275 | + for i := range request.List { | ||
| 276 | + item := request.List[i] | ||
| 277 | + if template, err = models.GetAuditTemplateById(int64(item.Id)); err != nil { | ||
| 278 | + log.Error(err.Error()) | ||
| 279 | + continue | ||
| 280 | + } | ||
| 281 | + if template.CompanyId != int(companyId) { | ||
| 282 | + log.Debug(fmt.Sprintf("template.companyId input:%v want:%v not equal.", companyId, template.CompanyId)) | ||
| 283 | + err = protocol.NewErrWithMessage("10027") | ||
| 284 | + return | ||
| 285 | + } | ||
| 286 | + if item.SortNum == template.SortNum { | ||
| 287 | + continue | ||
| 288 | + } | ||
| 289 | + if err = utils.UpdateTableByMapWithOrmer(orm, template, map[string]interface{}{"SortNum": item.SortNum}); err != nil { | ||
| 290 | + log.Error(err.Error()) | ||
| 291 | + orm.Rollback() | ||
| 292 | + return | ||
| 293 | + } | ||
| 294 | + } | ||
| 295 | + orm.Commit() | ||
| 296 | + rsp = &protocol.TemplateEditSortResponse{} | ||
| 297 | + return | ||
| 298 | +} | ||
| 299 | + | ||
| 265 | //操作一级分类 | 300 | //操作一级分类 |
| 266 | func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOperateCategoryRequest) (rsp *protocol.TemplateOperateCategoryResponse, err error) { | 301 | func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOperateCategoryRequest) (rsp *protocol.TemplateOperateCategoryResponse, err error) { |
| 267 | var ( | 302 | var ( |
-
请 注册 或 登录 后发表评论