-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.go
74 lines (66 loc) · 1.31 KB
/
default.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
package controllers
import (
"github.com/astaxie/beego"
)
type MainController struct {
beego.Controller
}
func (this *MainController) Get() {
this.Data["Website"] = "http://" + this.Ctx.Request.Host
this.Data["Project"] = beego.AppName
this.Data["Email"] = beego.AppConfig.String("email")
this.TplNames = "index.html"
}
type CartController struct {
beego.Controller
}
func (this *CartController) Add() {
id := this.Ctx.Params["0"]
var s Shopping
var c *Cart
var msg string
v := this.GetSession("20130805")
if v == nil {
c = new(Cart)
c.Items = make(map[string]Item)
msg = c.Add(id, 1)
s = c
} else {
c = v.(*Cart)
msg = c.Add(id, 1)
s = c
}
this.SetSession("20130805", s)
this.Data["Msg"] = msg
this.Data["Cart"] = c
this.TplNames = "cart.html"
}
func (this *CartController) View() {
var s Shopping
var c *Cart
v := this.GetSession("20130805")
if v == nil {
c = new(Cart)
c.Items = make(map[string]Item)
s = c
} else {
c = v.(*Cart)
s = c
}
this.SetSession("20130805", s)
this.Data["Cart"] = c
this.TplNames = "cart.html"
}
func (this *CartController) Remove() {
id := this.Ctx.Params["0"]
var s Shopping
var c *Cart
v := this.GetSession("20130805")
if v != nil {
c = v.(*Cart)
c.Remove(id)
s = c
}
this.SetSession("20130805", s)
this.Redirect("/cart/view", 302)
}