hotime/example/app/coupon.go
2022-05-17 12:31:47 +08:00

68 lines
1.6 KiB
Go

package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var CouponCtr = Ctr{
"search": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
user_id := that.Session("user_id").Data
user := that.Db.Get("user", "*", Map{"id": user_id})
if user == nil {
that.Display(1, "没有找到该用户")
return
}
//0-待使用,1-已使用,2-已过期
status := ObjToInt(that.Req.FormValue("status"))
var data = Map{
"coupon_user.user_id": user_id,
"coupon_user.state": 0,
}
if that.Req.FormValue("status") != "" {
data.Put("coupon_user.status", status)
}
specMap := Map{"AND": data}
if status == 0 {
specMap.Put("ORDER", "coupon_user.status ASC,coupon_user.effective_end_time ASC,coupon_user.create_time DESC")
}
if status == 1 {
specMap.Put("ORDER", "coupon_user.use_time DESC")
}
if status == 2 {
specMap.Put("ORDER", "coupon_user.effective_end_time DESC")
}
count := that.Db.Count("coupon_user", Map{"AND": data})
res := that.Db.Page(page, pageSize).PageSelect("coupon_user",
Map{"[>]coupon": "coupon_user.coupon_id = coupon.id"},
"coupon_user.code_no,coupon_user.effective_start_time,coupon_user.effective_end_time,coupon_user.status,"+
"coupon.coupon_amount,coupon.coupon_type,coupon.name,"+
"coupon.description",
specMap,
)
that.Display(0, Map{"total": count, "data": res})
},
}