package aftersale import ( "zhiyuan/pkg/app" "zhiyuan/pkg/utils" "zhiyuan/services/aftersale" "zhiyuan/services/form" "github.com/gin-gonic/gin" ) func TypeList(c *gin.Context) { isTree := utils.ToInt(c.Query("tree")) if isTree == 1 { TypeListTree(c) return } page := app.HandlePageNum(c) where := make(map[string]interface{}) total, err := aftersale.CountType(where) if err != nil { app.Error(c, err.Error()) return } types, err := aftersale.GetTypeList(where, []string{"id", "type_name"}, page, nil) if err != nil { app.Error(c, err.Error()) return } data := gin.H{ "list": types, "total": total, "limit": page.PageSize, } app.Success(c, data) } func TypeListTree(c *gin.Context) { auths, err := aftersale.GetTypeList(nil, []string{"id", "type_name", "pid", "warranty_period", "repair_days", "`show`"}, app.Page{}, nil) if err != nil { app.Error(c, err.Error()) return } app.Success(c, utils.GenTree(auths, "id", "pid", "children", 0)) } func TypeAdd(c *gin.Context) { var form form.ASTypeAdd if app.Bind(c, &form) != nil { return } if id, err := aftersale.AddType(form); err != nil { app.Error(c, err.Error()) return } else { app.Success(c, gin.H{"id": id}) } } func TypeEdit(c *gin.Context) { id := utils.StrTo(c.Param("id")).MustInt() if id <= 0 { app.Error(c, "类型id有误") return } var form form.ASTypeAdd if app.Bind(c, &form) != nil { return } if _, err := aftersale.EditType(form, id); err != nil { app.ErrorMsg(c, err.Error(), nil) return } app.Success(c, nil) }