-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_c.go
executable file
·155 lines (133 loc) · 3.58 KB
/
main_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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* Copyright 2014 @ z3q.net.
* name :
* author : jarryliu
* date : 2014-02-05 21:53
* description :
* history :
*/
package partner
import (
"fmt"
"github.com/jsix/gof"
"go2o/src/app/front"
"go2o/src/core/domain/interface/partner"
"go2o/src/core/service/dps"
"go2o/src/core/variable"
"go2o/src/x/echox"
"gopkg.in/labstack/echo.v1"
"net/http"
"strings"
)
type mainC struct {
*front.WebCgi
}
//入口
func (this *mainC) Index(ctx *echo.Context) (err error) {
_, err = ctx.Response().Write([]byte("<script>location.replace('/main/dashboard')</script>"))
//todo:??
// if this.baseC.Requesting(ctx) {
// ctx.Response.Write([]byte("<script>location.replace('/main/dashboard')</script>"))
// }
// this.baseC.RequestEnd(ctx)
return err
}
//登陆
func (this *mainC) Login(ctx *echox.Context) error {
if ctx.Request().Method == "POST" {
return this.Login_post(ctx)
}
d := ctx.NewData()
return ctx.RenderOK("login.html", d)
}
func (this *mainC) Login_post(ctx *echox.Context) error {
r, w := ctx.HttpRequest(), ctx.HttpResponse()
r.ParseForm()
usr, pwd := r.Form.Get("uid"), r.Form.Get("pwd")
pwd = strings.TrimSpace(pwd)
pt, result, message := this.ValidLogin(usr, pwd)
if result {
ctx.Session.Set("partner_id", pt.Id)
if err := ctx.Session.Save(); err != nil {
result = false
message = err.Error()
}
}
if result {
w.Write([]byte("{result:true}"))
} else {
w.Write([]byte("{result:false,message:'" + message + "'}"))
}
return nil
}
//验证登陆
func (pb *mainC) ValidLogin(usr string, pwd string) (*partner.ValuePartner, bool, string) {
var message string
var result bool
var pt *partner.ValuePartner
var err error
id := dps.PartnerService.Verify(usr, pwd)
if id == -1 {
result = false
message = "用户或密码不正确!"
} else {
pt, err = dps.PartnerService.GetPartner(id)
if err != nil {
message = err.Error()
result = false
} else {
result = true
}
}
return pt, result, message
}
func (this *mainC) Logout(ctx *echox.Context) error {
ctx.Session.Destroy()
ctx.HttpResponse().Write([]byte("<script>location.replace('/login')</script>"))
return nil
}
//商户首页
func (this *mainC) Dashboard(ctx *echox.Context) error {
pt, _ := dps.PartnerService.GetPartner(getPartnerId(ctx))
d := ctx.NewData()
d.Map = gof.TemplateDataMap{
"partner": pt,
"loginIp": ctx.Request().Header.Get("USER_ADDRESS"),
"AliasGrow": variable.AliasGrowAccount,
}
return ctx.Render(200, "dashboard.html", d)
}
//商户汇总页
func (this *mainC) Summary(ctx *echox.Context) error {
r := ctx.HttpRequest()
pt, _ := dps.PartnerService.GetPartner(getPartnerId(ctx))
d := ctx.NewData()
d.Map["partner"] = pt
d.Map["loginIp"] = r.Header.Get("USER_ADDRESS")
return ctx.Render(http.StatusOK, "summary.html", d)
}
// 导出数据
func (this *mainC) exportData(ctx *echox.Context) error {
ctx.HttpResponse().Header().Set("Content-Type", "application/json")
ctx.HttpResponse().Write(GetExportData(ctx.HttpRequest(), getPartnerId(ctx)))
return nil
}
func (this *mainC) Upload_post(ctx *echox.Context) error {
req := ctx.HttpRequest()
partnerId := getPartnerId(ctx)
req.ParseMultipartForm(20 * 1024 * 1024 * 1024) //20M
for f := range req.MultipartForm.File {
ctx.HttpResponse().Write(this.WebCgi.Upload(f, ctx, fmt.Sprintf("%d/item_pic/", partnerId)))
}
return nil
}
func (this *mainC) GeoLocation(ctx *echox.Context) error {
this.WebCgi.GeoLocation(ctx)
return nil
}
//地区Json
//func (this *mainC) ChinaJson(ctx *echox.Context)error{
// var node *tree.TreeNode = dao.Common().GetChinaTree()
// json, _ := json.Marshal(node)
// w.Write(json)
//}