作者 yangfu

模板排序

... ... @@ -164,6 +164,35 @@ func (this *TemplateController) TemplateEditVisible() {
msg = protocol.NewReturnResponse(rsp, err)
}
//TemplateEditSort 编辑模板排序
//@router /templateEditSort [post]
func (this *TemplateController) TemplateEditSort() {
var msg *protocol.ResponseMessage
defer func() {
this.ResposeJson(msg)
}()
var request *protocol.TemplateEditSortRequest
if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
uid := this.GetUserId()
companyId := this.GetCompanyId()
if companyId <= 0 {
log.Debug("companyId:%d err", companyId)
msg = protocol.BadRequestParam("1")
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
rsp, err := audit.TemplateEditSort(uid, companyId, request)
msg = protocol.NewReturnResponse(rsp, err)
}
//TemplateOperateCategory
//@router /templateOperateCategory [post]
func (this *TemplateController) TemplateOperateCategory() {
... ...
... ... @@ -161,3 +161,17 @@ type TemplateGetResponse struct {
Template Template `json:"template"`
Example string `json:"example"` //示例`
}
/*TemplateEditSort */
type TemplateEditSortRequest struct {
ChanceTypeId int `json:"chance_type_id"` //机会类型编号
List []SortItem `json:"list"` //需要排序的列表
}
type TemplateEditSortResponse struct {
}
//排序项
type SortItem struct {
Id int `json:"id"`
SortNum int `json:"sort_num"`
}
... ...
... ... @@ -69,6 +69,7 @@ func init() {
beego.NSRouter("/get", &controllers.TemplateController{}, "post:TemplateGet"),
beego.NSRouter("/update", &controllers.TemplateController{}, "post:TemplateUpdate"),
beego.NSRouter("/editVisible", &controllers.TemplateController{}, "post:TemplateEditVisible"),
beego.NSRouter("/editSort", &controllers.TemplateController{}, "post:TemplateEditSort"),
beego.NSRouter("/operateCategory", &controllers.TemplateController{}, "post:TemplateOperateCategory"),
),
)
... ...
... ... @@ -262,6 +262,41 @@ func TemplateEditVisible(uid, companyId int64, request *protocol.TemplateEditVis
return
}
//编辑模板排序
func TemplateEditSort(uid, companyId int64, request *protocol.TemplateEditSortRequest) (rsp *protocol.TemplateEditSortResponse, err error) {
var (
template *models.AuditTemplate
)
if _, err = models.GetChanceTypeById(request.ChanceTypeId); err != nil {
log.Error(err.Error())
return
}
orm := orm2.NewOrm()
for i := range request.List {
item := request.List[i]
if template, err = models.GetAuditTemplateById(int64(item.Id)); err != nil {
log.Error(err.Error())
continue
}
if template.CompanyId != int(companyId) {
log.Debug(fmt.Sprintf("template.companyId input:%v want:%v not equal.", companyId, template.CompanyId))
err = protocol.NewErrWithMessage("10027")
return
}
if item.SortNum == template.SortNum {
continue
}
if err = utils.UpdateTableByMapWithOrmer(orm, template, map[string]interface{}{"SortNum": item.SortNum}); err != nil {
log.Error(err.Error())
orm.Rollback()
return
}
}
orm.Commit()
rsp = &protocol.TemplateEditSortResponse{}
return
}
//操作一级分类
func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOperateCategoryRequest) (rsp *protocol.TemplateOperateCategoryResponse, err error) {
var (
... ...