-
Notifications
You must be signed in to change notification settings - Fork 0
/
category_c.go
133 lines (116 loc) · 3.29 KB
/
category_c.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* Copyright 2014 @ z3q.net.
* name :
* author : jarryliu
* date : 2014-02-05 21:53
* description :
* history :
*/
package partner
import (
"encoding/json"
"fmt"
"github.com/jsix/gof"
"github.com/jsix/gof/web"
"github.com/jsix/gof/web/ui/tree"
"go2o/src/app/cache"
"go2o/src/core/domain/interface/sale"
"go2o/src/core/infrastructure/format"
"go2o/src/core/service/dps"
"go2o/src/core/variable"
"go2o/src/x/echox"
"html/template"
"net/http"
"regexp"
"strconv"
)
type categoryC struct {
}
//分类树形功能
func (this *categoryC) All_category(ctx *echox.Context) error {
d := ctx.NewData()
d.Map["no_pic_url"] = format.GetGoodsImageUrl("")
return ctx.RenderOK("category.index.html", d)
}
//分类Json数据
func (this *categoryC) CategoryJson(ctx *echox.Context) error {
partnerId := getPartnerId(ctx)
var node *tree.TreeNode = dps.SaleService.GetCategoryTreeNode(partnerId)
return ctx.JSON(http.StatusOK, node)
}
//分类树形功能
func (this *categoryC) CategorySelect(ctx *echox.Context) error {
d := ctx.NewData()
return ctx.RenderOK("category.select.html", d)
}
//分类Json数据
func (this *categoryC) CreateCategory(ctx *echox.Context) error {
partnerId := getPartnerId(ctx)
cateOpts := cache.GetDropOptionsOfCategory(partnerId)
e := &sale.ValueCategory{
Icon: ctx.App.Config().GetString(variable.NoPicPath),
}
eJson, _ := json.Marshal(e)
d := ctx.NewData()
d.Map = map[string]interface{}{
"Entity": template.JS(eJson),
"CateOpts": template.HTML(cateOpts),
"Icon": format.GetGoodsImageUrl(e.Icon),
}
return ctx.RenderOK("category.create.html", d)
}
func (this *categoryC) EditCategory(ctx *echox.Context) error {
partnerId := getPartnerId(ctx)
r := ctx.HttpRequest()
r.ParseForm()
id, _ := strconv.Atoi(r.Form.Get("id"))
e, _ := dps.SaleService.GetCategory(partnerId, id)
eJson, _ := json.Marshal(e)
re := regexp.MustCompile(fmt.Sprintf("<option class=\"opt\\d+\" value=\"%d\">[^>]+>", id))
originOpts := cache.GetDropOptionsOfCategory(partnerId)
cateOpts := re.ReplaceAll(originOpts, nil)
d := ctx.NewData()
d.Map = map[string]interface{}{
"Entity": template.JS(eJson),
"CateOpts": template.HTML(cateOpts),
"Icon": format.GetGoodsImageUrl(e.Icon),
}
return ctx.RenderOK("category.edit.html", d)
}
//修改门店信息
func (this *categoryC) SaveCategory(ctx *echox.Context) error {
partnerId := getPartnerId(ctx)
r := ctx.HttpRequest()
if r.Method == "POST" {
var result gof.Message
r.ParseForm()
e := sale.ValueCategory{}
web.ParseFormToEntity(r.Form, &e)
id, err := dps.SaleService.SaveCategory(partnerId, &e)
if err != nil {
result = gof.Message{Result: false, Message: err.Error()}
} else {
result = gof.Message{Result: true, Message: "", Data: id}
}
return ctx.JSON(http.StatusOK, result)
}
return nil
}
func (this *categoryC) DelCategory(ctx *echox.Context) error {
partnerId := getPartnerId(ctx)
r := ctx.HttpRequest()
if r.Method == "POST" {
var result gof.Message
r.ParseForm()
categoryId, _ := strconv.Atoi(r.FormValue("id"))
//删除分类
err := dps.SaleService.DeleteCategory(partnerId, categoryId)
if err != nil {
result = gof.Message{Result: false, Message: err.Error()}
} else {
result = gof.Message{Result: true, Message: ""}
}
return ctx.JSON(http.StatusOK, result)
}
return nil
}