分类管理
()
| 931 | |
| 932 | // 分类管理 |
| 933 | func (this *ManagerController) Category() { |
| 934 | Model := new(models.Category) |
| 935 | if strings.ToLower(this.Ctx.Request.Method) == "post" { |
| 936 | //新增分类 |
| 937 | pid, _ := this.GetInt("pid") |
| 938 | if err := Model.AddCates(pid, this.GetString("cates")); err != nil { |
| 939 | this.JsonResult(1, "新增失败:"+err.Error()) |
| 940 | } |
| 941 | this.JsonResult(0, "新增成功") |
| 942 | } |
| 943 | |
| 944 | //查询所有分类 |
| 945 | cates, err := Model.GetCates(-1, -1) |
| 946 | if err != nil { |
| 947 | beego.Error(err) |
| 948 | } |
| 949 | |
| 950 | var parents []models.Category |
| 951 | for idx, item := range cates { |
| 952 | if strings.TrimSpace(item.Icon) == "" { //赋值为默认图片 |
| 953 | item.Icon = "/static/images/icon.png" |
| 954 | } else { |
| 955 | item.Icon = utils.ShowImg(item.Icon) |
| 956 | } |
| 957 | if item.Pid == 0 { |
| 958 | parents = append(parents, item) |
| 959 | } |
| 960 | cates[idx] = item |
| 961 | } |
| 962 | |
| 963 | this.Data["Parents"] = parents |
| 964 | this.Data["Cates"] = cates |
| 965 | this.Data["IsCategory"] = true |
| 966 | this.TplName = "manager/category.html" |
| 967 | } |
| 968 | |
| 969 | // 更新分类字段内容 |
| 970 | func (this *ManagerController) UpdateCate() { |
nothing calls this directly
no test coverage detected