Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev
# Conflicts: # controllers/base.go
正在显示
6 个修改的文件
包含
321 行增加
和
36 行删除
@@ -23,6 +23,7 @@ func (this *BaseController) Prepare() { | @@ -23,6 +23,7 @@ func (this *BaseController) Prepare() { | ||
23 | this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") | 23 | this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") |
24 | this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*") | 24 | this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*") |
25 | if this.Ctx.Input.Method() == "OPTIONS" { | 25 | if this.Ctx.Input.Method() == "OPTIONS" { |
26 | + this.Ctx.ResponseWriter.WriteHeader(204) | ||
26 | this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") | 27 | this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") |
27 | //this.Ctx.WriteString("") | 28 | //this.Ctx.WriteString("") |
28 | return | 29 | return |
@@ -11,7 +11,7 @@ type TemplateController struct { | @@ -11,7 +11,7 @@ type TemplateController struct { | ||
11 | BaseController | 11 | BaseController |
12 | } | 12 | } |
13 | 13 | ||
14 | -//TemplateAdd | 14 | +//TemplateAdd 模板新增 |
15 | //@router /templateAdd [post] | 15 | //@router /templateAdd [post] |
16 | func (this *TemplateController) TemplateAdd() { | 16 | func (this *TemplateController) TemplateAdd() { |
17 | var msg *protocol.ResponseMessage | 17 | var msg *protocol.ResponseMessage |
@@ -46,7 +46,7 @@ func (this *TemplateController) TemplateAdd() { | @@ -46,7 +46,7 @@ func (this *TemplateController) TemplateAdd() { | ||
46 | return | 46 | return |
47 | } | 47 | } |
48 | 48 | ||
49 | -//TemplateUpdate | 49 | +//TemplateUpdate 模板更新 |
50 | //@router /templateUpdate [post] | 50 | //@router /templateUpdate [post] |
51 | func (this *TemplateController) TemplateUpdate() { | 51 | func (this *TemplateController) TemplateUpdate() { |
52 | var msg *protocol.ResponseMessage | 52 | var msg *protocol.ResponseMessage |
@@ -76,7 +76,7 @@ func (this *TemplateController) TemplateUpdate() { | @@ -76,7 +76,7 @@ func (this *TemplateController) TemplateUpdate() { | ||
76 | return | 76 | return |
77 | } | 77 | } |
78 | 78 | ||
79 | -//TemplateList | 79 | +//TemplateList 模板列表 |
80 | //@router /templateList [post] | 80 | //@router /templateList [post] |
81 | func (this *TemplateController) TemplateList() { | 81 | func (this *TemplateController) TemplateList() { |
82 | var msg *protocol.ResponseMessage | 82 | var msg *protocol.ResponseMessage |
@@ -106,7 +106,7 @@ func (this *TemplateController) TemplateList() { | @@ -106,7 +106,7 @@ func (this *TemplateController) TemplateList() { | ||
106 | return | 106 | return |
107 | } | 107 | } |
108 | 108 | ||
109 | -//TemplateGet | 109 | +//TemplateGet 模板获取 |
110 | //@router /templateGet [post] | 110 | //@router /templateGet [post] |
111 | func (this *TemplateController) TemplateGet() { | 111 | func (this *TemplateController) TemplateGet() { |
112 | var msg *protocol.ResponseMessage | 112 | var msg *protocol.ResponseMessage |
@@ -135,7 +135,7 @@ func (this *TemplateController) TemplateGet() { | @@ -135,7 +135,7 @@ func (this *TemplateController) TemplateGet() { | ||
135 | msg = protocol.NewReturnResponse(rsp, err) | 135 | msg = protocol.NewReturnResponse(rsp, err) |
136 | } | 136 | } |
137 | 137 | ||
138 | -//TemplateEditVisible | 138 | +//TemplateEditVisible 编辑模板可见范围 |
139 | //@router /templateEditVisible [post] | 139 | //@router /templateEditVisible [post] |
140 | func (this *TemplateController) TemplateEditVisible() { | 140 | func (this *TemplateController) TemplateEditVisible() { |
141 | var msg *protocol.ResponseMessage | 141 | var msg *protocol.ResponseMessage |
@@ -193,7 +193,7 @@ func (this *TemplateController) TemplateEditSort() { | @@ -193,7 +193,7 @@ func (this *TemplateController) TemplateEditSort() { | ||
193 | msg = protocol.NewReturnResponse(rsp, err) | 193 | msg = protocol.NewReturnResponse(rsp, err) |
194 | } | 194 | } |
195 | 195 | ||
196 | -//TemplateOperateCategory | 196 | +//TemplateOperateCategory 编辑一级分类 |
197 | //@router /templateOperateCategory [post] | 197 | //@router /templateOperateCategory [post] |
198 | func (this *TemplateController) TemplateOperateCategory() { | 198 | func (this *TemplateController) TemplateOperateCategory() { |
199 | var msg *protocol.ResponseMessage | 199 | var msg *protocol.ResponseMessage |
@@ -221,3 +221,119 @@ func (this *TemplateController) TemplateOperateCategory() { | @@ -221,3 +221,119 @@ func (this *TemplateController) TemplateOperateCategory() { | ||
221 | rsp, err := audit.TemplateOperateCategory(uid, companyId, request) | 221 | rsp, err := audit.TemplateOperateCategory(uid, companyId, request) |
222 | msg = protocol.NewReturnResponse(rsp, err) | 222 | msg = protocol.NewReturnResponse(rsp, err) |
223 | } | 223 | } |
224 | + | ||
225 | +//TemplateDeleteCategory 删除一级分类 | ||
226 | +//@router /templateDeleteCategory [post] | ||
227 | +func (this *TemplateController) TemplateDeleteCategory() { | ||
228 | + var msg *protocol.ResponseMessage | ||
229 | + defer func() { | ||
230 | + this.ResposeJson(msg) | ||
231 | + }() | ||
232 | + var request *protocol.TemplateDeleteCategoryRequest | ||
233 | + | ||
234 | + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { | ||
235 | + log.Error("json 解析失败", err) | ||
236 | + msg = protocol.BadRequestParam("1") | ||
237 | + return | ||
238 | + } | ||
239 | + uid := this.GetUserId() | ||
240 | + companyId := this.GetCompanyId() | ||
241 | + if companyId <= 0 { | ||
242 | + log.Debug("companyId:%d err", companyId) | ||
243 | + msg = protocol.BadRequestParam("1") | ||
244 | + return | ||
245 | + } | ||
246 | + if b, m := this.Valid(request); !b { | ||
247 | + msg = m | ||
248 | + return | ||
249 | + } | ||
250 | + rsp, err := audit.TemplateDeleteCategory(uid, companyId, request) | ||
251 | + msg = protocol.NewReturnResponse(rsp, err) | ||
252 | +} | ||
253 | + | ||
254 | +//TemplateDelete 模板删除 | ||
255 | +//@router /templateDelete [post] | ||
256 | +func (this *TemplateController) TemplateDelete() { | ||
257 | + var msg *protocol.ResponseMessage | ||
258 | + defer func() { | ||
259 | + this.ResposeJson(msg) | ||
260 | + }() | ||
261 | + var request *protocol.TemplateDeleteRequest | ||
262 | + | ||
263 | + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { | ||
264 | + log.Error("json 解析失败", err) | ||
265 | + msg = protocol.BadRequestParam("1") | ||
266 | + return | ||
267 | + } | ||
268 | + uid := this.GetUserId() | ||
269 | + companyId := this.GetCompanyId() | ||
270 | + if companyId <= 0 { | ||
271 | + log.Debug("companyId:%d err", companyId) | ||
272 | + msg = protocol.BadRequestParam("1") | ||
273 | + return | ||
274 | + } | ||
275 | + if b, m := this.Valid(request); !b { | ||
276 | + msg = m | ||
277 | + return | ||
278 | + } | ||
279 | + rsp, err := audit.TemplateDelete(uid, companyId, request) | ||
280 | + msg = protocol.NewReturnResponse(rsp, err) | ||
281 | +} | ||
282 | + | ||
283 | +//TemplateEditEnable 模板启用 | ||
284 | +//@router /templateEditEnable [post] | ||
285 | +func (this *TemplateController) TemplateEditEnable() { | ||
286 | + var msg *protocol.ResponseMessage | ||
287 | + defer func() { | ||
288 | + this.ResposeJson(msg) | ||
289 | + }() | ||
290 | + var request *protocol.TemplateEditEnableRequest | ||
291 | + | ||
292 | + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { | ||
293 | + log.Error("json 解析失败", err) | ||
294 | + msg = protocol.BadRequestParam("1") | ||
295 | + return | ||
296 | + } | ||
297 | + uid := this.GetUserId() | ||
298 | + companyId := this.GetCompanyId() | ||
299 | + if companyId <= 0 { | ||
300 | + log.Debug("companyId:%d err", companyId) | ||
301 | + msg = protocol.BadRequestParam("1") | ||
302 | + return | ||
303 | + } | ||
304 | + if b, m := this.Valid(request); !b { | ||
305 | + msg = m | ||
306 | + return | ||
307 | + } | ||
308 | + rsp, err := audit.TemplateEditEnable(uid, companyId, request) | ||
309 | + msg = protocol.NewReturnResponse(rsp, err) | ||
310 | +} | ||
311 | + | ||
312 | +//CategoryEditSort 一级分类排序 | ||
313 | +//@router /categoryEditSort [post] | ||
314 | +func (this *TemplateController) CategoryEditSort() { | ||
315 | + var msg *protocol.ResponseMessage | ||
316 | + defer func() { | ||
317 | + this.ResposeJson(msg) | ||
318 | + }() | ||
319 | + var request *protocol.CategoryEditSortRequest | ||
320 | + | ||
321 | + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { | ||
322 | + log.Error("json 解析失败", err) | ||
323 | + msg = protocol.BadRequestParam("1") | ||
324 | + return | ||
325 | + } | ||
326 | + uid := this.GetUserId() | ||
327 | + companyId := this.GetCompanyId() | ||
328 | + if companyId <= 0 { | ||
329 | + log.Debug("companyId:%d err", companyId) | ||
330 | + msg = protocol.BadRequestParam("1") | ||
331 | + return | ||
332 | + } | ||
333 | + if b, m := this.Valid(request); !b { | ||
334 | + msg = m | ||
335 | + return | ||
336 | + } | ||
337 | + rsp, err := audit.CategoryEditSort(uid, companyId, request) | ||
338 | + msg = protocol.NewReturnResponse(rsp, err) | ||
339 | +} |
@@ -175,3 +175,32 @@ type SortItem struct { | @@ -175,3 +175,32 @@ type SortItem struct { | ||
175 | Id int `json:"id"` | 175 | Id int `json:"id"` |
176 | SortNum int `json:"sort_num"` | 176 | SortNum int `json:"sort_num"` |
177 | } | 177 | } |
178 | + | ||
179 | +/*TemplateEditEnable 模板启用*/ | ||
180 | +type TemplateEditEnableRequest struct { | ||
181 | + TemplateId int `json:"id" valid:"Required"` | ||
182 | + Enabled int8 `json:"enabled"` //启用状态 1 启用 0 禁用 | ||
183 | +} | ||
184 | +type TemplateEditEnableResponse struct { | ||
185 | +} | ||
186 | + | ||
187 | +/*TemplateDelete 删除模板*/ | ||
188 | +type TemplateDeleteRequest struct { | ||
189 | + TemplateId int `json:"id" valid:"Required"` | ||
190 | +} | ||
191 | +type TemplateDeleteResponse struct { | ||
192 | +} | ||
193 | + | ||
194 | +/*TemplateDeleteCategory 删除一级分类*/ | ||
195 | +type TemplateDeleteCategoryRequest struct { | ||
196 | + ChanceTypeId int `json:"id" valid:"Required"` | ||
197 | +} | ||
198 | +type TemplateDeleteCategoryResponse struct { | ||
199 | +} | ||
200 | + | ||
201 | +/*CategoryEditSort 一级分类排序*/ | ||
202 | +type CategoryEditSortRequest struct { | ||
203 | + List []SortItem `json:"list"` //需要排序的列表 | ||
204 | +} | ||
205 | +type CategoryEditSortResponse struct { | ||
206 | +} |
@@ -37,6 +37,10 @@ var errmessge ErrorMap = map[string]string{ | @@ -37,6 +37,10 @@ var errmessge ErrorMap = map[string]string{ | ||
37 | "10047": "只能删除没有成员的部门,需要先删除部门下的员工,再删除该部门", | 37 | "10047": "只能删除没有成员的部门,需要先删除部门下的员工,再删除该部门", |
38 | //用户中心相关 | 38 | //用户中心相关 |
39 | "10051": "无法从远端接口获取公司数据", | 39 | "10051": "无法从远端接口获取公司数据", |
40 | + //模板相关 | ||
41 | + "10061": "请先删除该分类下的二级分类", | ||
42 | + "10062": "该分类已被使用无法删除", | ||
43 | + "10063": "该分类已被使用无法禁用", | ||
40 | } | 44 | } |
41 | 45 | ||
42 | //错误码转换 ,兼容需要 | 46 | //错误码转换 ,兼容需要 |
@@ -70,9 +70,13 @@ func init() { | @@ -70,9 +70,13 @@ func init() { | ||
70 | beego.NSRouter("/list", &controllers.TemplateController{}, "post:TemplateList"), | 70 | beego.NSRouter("/list", &controllers.TemplateController{}, "post:TemplateList"), |
71 | beego.NSRouter("/get", &controllers.TemplateController{}, "post:TemplateGet"), | 71 | beego.NSRouter("/get", &controllers.TemplateController{}, "post:TemplateGet"), |
72 | beego.NSRouter("/update", &controllers.TemplateController{}, "post:TemplateUpdate"), | 72 | beego.NSRouter("/update", &controllers.TemplateController{}, "post:TemplateUpdate"), |
73 | + beego.NSRouter("/delete", &controllers.TemplateController{}, "post:TemplateDelete"), | ||
73 | beego.NSRouter("/editVisible", &controllers.TemplateController{}, "post:TemplateEditVisible"), | 74 | beego.NSRouter("/editVisible", &controllers.TemplateController{}, "post:TemplateEditVisible"), |
75 | + beego.NSRouter("/editEnable", &controllers.TemplateController{}, "post:TemplateEditEnable"), | ||
74 | beego.NSRouter("/editSort", &controllers.TemplateController{}, "post:TemplateEditSort"), | 76 | beego.NSRouter("/editSort", &controllers.TemplateController{}, "post:TemplateEditSort"), |
75 | beego.NSRouter("/operateCategory", &controllers.TemplateController{}, "post:TemplateOperateCategory"), | 77 | beego.NSRouter("/operateCategory", &controllers.TemplateController{}, "post:TemplateOperateCategory"), |
78 | + beego.NSRouter("/deleteCategory", &controllers.TemplateController{}, "post:TemplateDeleteCategory"), | ||
79 | + beego.NSRouter("/sortCategory", &controllers.TemplateController{}, "post:CategoryEditSort"), | ||
76 | ), | 80 | ), |
77 | ) | 81 | ) |
78 | 82 |
@@ -297,6 +297,111 @@ func TemplateEditSort(uid, companyId int64, request *protocol.TemplateEditSortRe | @@ -297,6 +297,111 @@ func TemplateEditSort(uid, companyId int64, request *protocol.TemplateEditSortRe | ||
297 | return | 297 | return |
298 | } | 298 | } |
299 | 299 | ||
300 | +//获取模板详情 | ||
301 | +func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rsp *protocol.TemplateGetResponse, err error) { | ||
302 | + var ( | ||
303 | + template *models.AuditTemplate | ||
304 | + auditForm []*models.AuditForm | ||
305 | + ) | ||
306 | + rsp = &protocol.TemplateGetResponse{} | ||
307 | + if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil { | ||
308 | + log.Error("template_id:%v 不存在 ,err:%v", request.Id, err.Error()) | ||
309 | + return | ||
310 | + } | ||
311 | + | ||
312 | + { | ||
313 | + rsp.Template = protocol.Template{ | ||
314 | + Id: template.Id, | ||
315 | + ChanceTypeId: template.ChanceTypeId, | ||
316 | + Name: template.Name, | ||
317 | + Doc: template.Doc, | ||
318 | + Icon: template.Icon, | ||
319 | + } | ||
320 | + rsp.Example = template.Example | ||
321 | + | ||
322 | + if auditForm, err = models.GetAuditFormByTemplateId(int(template.Id)); err != nil { | ||
323 | + if err == sql.ErrNoRows { | ||
324 | + err = nil | ||
325 | + } | ||
326 | + return | ||
327 | + } | ||
328 | + for i := range auditForm { | ||
329 | + input := auditForm[i] | ||
330 | + rsp.Template.InputList = append(rsp.Template.InputList, &protocol.InputElement{ | ||
331 | + Id: input.Id, | ||
332 | + Sort: input.SortNum, | ||
333 | + Lable: input.InputType, | ||
334 | + Required: int(input.Required), | ||
335 | + SectionType: input.Section, | ||
336 | + }) | ||
337 | + } | ||
338 | + } | ||
339 | + return | ||
340 | +} | ||
341 | + | ||
342 | +//模板删除 | ||
343 | +func TemplateDelete(uid, companyId int64, request *protocol.TemplateDeleteRequest) (rsp *protocol.TemplateDeleteResponse, err error) { | ||
344 | + var ( | ||
345 | + template *models.AuditTemplate | ||
346 | + num int | ||
347 | + sql1 string = `select count(0) from chance where chance_type_id = ? limit 1` | ||
348 | + ) | ||
349 | + if template, err = models.GetAuditTemplateById(int64(request.TemplateId)); err != nil { | ||
350 | + log.Error(err.Error()) | ||
351 | + return | ||
352 | + } | ||
353 | + if template.CompanyId != int(companyId) { | ||
354 | + err = protocol.NewErrWithMessage("10027") | ||
355 | + return | ||
356 | + } | ||
357 | + //2.判断是否有对应已经发布的机会 | ||
358 | + if err = utils.ExecuteQueryOne(&num, sql1, request.TemplateId); err == nil && num > 0 { | ||
359 | + err = protocol.NewErrWithMessage("10062") | ||
360 | + return | ||
361 | + } | ||
362 | + | ||
363 | + //删除数据 | ||
364 | + if err = models.DeleteAuditTemplate(int64(request.TemplateId)); err != nil { | ||
365 | + log.Error(err.Error()) | ||
366 | + return | ||
367 | + } | ||
368 | + rsp = &protocol.TemplateDeleteResponse{} | ||
369 | + return | ||
370 | +} | ||
371 | + | ||
372 | +//模板启用 | ||
373 | +func TemplateEditEnable(uid, companyId int64, request *protocol.TemplateEditEnableRequest) (rsp *protocol.TemplateEditEnableResponse, err error) { | ||
374 | + var ( | ||
375 | + template *models.AuditTemplate | ||
376 | + num int | ||
377 | + sql1 string = `select count(0) from chance where chance_type_id = ? limit 1` | ||
378 | + ) | ||
379 | + if template, err = models.GetAuditTemplateById(int64(request.TemplateId)); err != nil { | ||
380 | + log.Error(err.Error()) | ||
381 | + return | ||
382 | + } | ||
383 | + if template.EnableStatus == request.Enabled { | ||
384 | + return | ||
385 | + } | ||
386 | + if template.CompanyId != int(companyId) { | ||
387 | + err = protocol.NewErrWithMessage("10027") | ||
388 | + return | ||
389 | + } | ||
390 | + //2.判断是否有对应已经发布的机会 | ||
391 | + if request.Enabled == 0 { | ||
392 | + if err = utils.ExecuteQueryOne(&num, sql1, request.TemplateId); err == nil && num > 0 { | ||
393 | + err = protocol.NewErrWithMessage("10063") | ||
394 | + return | ||
395 | + } | ||
396 | + } | ||
397 | + rsp = &protocol.TemplateEditEnableResponse{} | ||
398 | + if err = utils.UpdateTableByMap(template, map[string]interface{}{"EnableStatus": request.Enabled}); err != nil { | ||
399 | + log.Error(err.Error()) | ||
400 | + return | ||
401 | + } | ||
402 | + return | ||
403 | +} | ||
404 | + | ||
300 | //操作一级分类 | 405 | //操作一级分类 |
301 | func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOperateCategoryRequest) (rsp *protocol.TemplateOperateCategoryResponse, err error) { | 406 | func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOperateCategoryRequest) (rsp *protocol.TemplateOperateCategoryResponse, err error) { |
302 | var ( | 407 | var ( |
@@ -312,7 +417,7 @@ func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOpe | @@ -312,7 +417,7 @@ func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOpe | ||
312 | err = protocol.NewErrWithMessage("10027") | 417 | err = protocol.NewErrWithMessage("10027") |
313 | log.Error("template_id:%v companyId:%v want:%v not equal.", request.Id, companyId, chanceType.CompanyId) | 418 | log.Error("template_id:%v companyId:%v want:%v not equal.", request.Id, companyId, chanceType.CompanyId) |
314 | } | 419 | } |
315 | - if err = utils.UpdateTableByMap(chanceType, map[string]interface{}{"Name": request.Name, "Icon": request.Icon, "UpdateAt": time.Now()}); err != nil { | 420 | + if err = utils.UpdateTableByMap(chanceType, map[string]interface{}{"Name": request.Name, "Icon": request.Icon, "SortNum": chanceType.SortNum, "UpdateAt": time.Now()}); err != nil { |
316 | log.Error(err.Error()) | 421 | log.Error(err.Error()) |
317 | return | 422 | return |
318 | } | 423 | } |
@@ -332,44 +437,70 @@ func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOpe | @@ -332,44 +437,70 @@ func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOpe | ||
332 | return | 437 | return |
333 | } | 438 | } |
334 | 439 | ||
335 | -//获取模板详情 | ||
336 | -func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rsp *protocol.TemplateGetResponse, err error) { | 440 | +//删除一级分类 |
441 | +func TemplateDeleteCategory(uid, companyId int64, request *protocol.TemplateDeleteCategoryRequest) (rsp *protocol.TemplateDeleteCategoryResponse, err error) { | ||
337 | var ( | 442 | var ( |
338 | - template *models.AuditTemplate | ||
339 | - auditForm []*models.AuditForm | 443 | + chanceType *models.ChanceType |
444 | + num int | ||
445 | + sql1 string = `select count(0) from from audit_template where chance_type_id =? limit 1` | ||
446 | + sql2 string = `select count(0) from chance where chance_type_id = ? limit 1` | ||
340 | ) | 447 | ) |
341 | - rsp = &protocol.TemplateGetResponse{} | ||
342 | - if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil { | ||
343 | - log.Error("template_id:%v 不存在 ,err:%v", request.Id, err.Error()) | 448 | + if chanceType, err = models.GetChanceTypeById(request.ChanceTypeId); err != nil { |
449 | + log.Error(err.Error()) | ||
450 | + return | ||
451 | + } | ||
452 | + if chanceType.CompanyId != int(companyId) { | ||
453 | + err = protocol.NewErrWithMessage("10027") | ||
344 | return | 454 | return |
345 | } | 455 | } |
346 | 456 | ||
347 | - { | ||
348 | - rsp.Template = protocol.Template{ | ||
349 | - Id: template.Id, | ||
350 | - ChanceTypeId: template.ChanceTypeId, | ||
351 | - Name: template.Name, | ||
352 | - Doc: template.Doc, | ||
353 | - Icon: template.Icon, | ||
354 | - } | ||
355 | - rsp.Example = template.Example | 457 | + //1.判断分类下面是否有模板 |
458 | + if err = utils.ExecuteQueryOne(&num, sql1, request.ChanceTypeId); err == nil && num > 0 { | ||
459 | + err = protocol.NewErrWithMessage("10061") | ||
460 | + return | ||
461 | + } | ||
462 | + //2.判断是否有对应已经发布的机会 | ||
463 | + if err = utils.ExecuteQueryOne(&num, sql2, request.ChanceTypeId); err == nil && num > 0 { | ||
464 | + err = protocol.NewErrWithMessage("10062") | ||
465 | + return | ||
466 | + } | ||
356 | 467 | ||
357 | - if auditForm, err = models.GetAuditFormByTemplateId(int(template.Id)); err != nil { | ||
358 | - if err == sql.ErrNoRows { | ||
359 | - err = nil | ||
360 | - } | 468 | + //删除数据 |
469 | + if err = models.DeleteChanceType(request.ChanceTypeId); err != nil { | ||
470 | + log.Error(err.Error()) | ||
471 | + return | ||
472 | + } | ||
473 | + rsp = &protocol.TemplateDeleteCategoryResponse{} | ||
474 | + return | ||
475 | +} | ||
476 | + | ||
477 | +//一级分类排序 | ||
478 | +func CategoryEditSort(uid, companyId int64, request *protocol.CategoryEditSortRequest) (rsp *protocol.CategoryEditSortResponse, err error) { | ||
479 | + var ( | ||
480 | + template *models.ChanceType | ||
481 | + ) | ||
482 | + orm := orm2.NewOrm() | ||
483 | + for i := range request.List { | ||
484 | + item := request.List[i] | ||
485 | + if template, err = models.GetChanceTypeById(item.Id); err != nil { | ||
486 | + log.Error(err.Error()) | ||
487 | + continue | ||
488 | + } | ||
489 | + if template.CompanyId != int(companyId) { | ||
490 | + log.Debug(fmt.Sprintf("template.companyId input:%v want:%v not equal.", companyId, template.CompanyId)) | ||
491 | + err = protocol.NewErrWithMessage("10027") | ||
361 | return | 492 | return |
362 | } | 493 | } |
363 | - for i := range auditForm { | ||
364 | - input := auditForm[i] | ||
365 | - rsp.Template.InputList = append(rsp.Template.InputList, &protocol.InputElement{ | ||
366 | - Id: input.Id, | ||
367 | - Sort: input.SortNum, | ||
368 | - Lable: input.InputType, | ||
369 | - Required: int(input.Required), | ||
370 | - SectionType: input.Section, | ||
371 | - }) | 494 | + if item.SortNum == template.SortNum { |
495 | + continue | ||
496 | + } | ||
497 | + if err = utils.UpdateTableByMapWithOrmer(orm, template, map[string]interface{}{"SortNum": item.SortNum}); err != nil { | ||
498 | + log.Error(err.Error()) | ||
499 | + orm.Rollback() | ||
500 | + return | ||
372 | } | 501 | } |
373 | } | 502 | } |
503 | + orm.Commit() | ||
504 | + rsp = &protocol.CategoryEditSortResponse{} | ||
374 | return | 505 | return |
375 | } | 506 | } |
-
请 注册 或 登录 后发表评论