From 31a48aa41d3595d1aa3c36ca20a42c6dcfec8462 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Wed, 22 Apr 2020 17:12:13 +0800 Subject: [PATCH] condition --- controllers/author.go | 51 ++++++++++++++++++++++++++++++---------------- controllers/pc/activity.go | 1 + main.go | 1 + models/base.go | 3 ++- models/customer_goods.go | 4 ---- models/user_order.go | 4 ++-- services/pay/order.go | 2 +- 7 files changed, 40 insertions(+), 26 deletions(-) diff --git a/controllers/author.go b/controllers/author.go index 40e8894..d3ea642 100644 --- a/controllers/author.go +++ b/controllers/author.go @@ -1,6 +1,7 @@ package controllers import ( + jwt2 "github.com/dgrijalva/jwt-go" "hudongzhuanjia/libs/jwt" "hudongzhuanjia/utils/code" "hudongzhuanjia/utils/define" @@ -14,27 +15,41 @@ type AuthorCtl struct { func (t *AuthorCtl) Prepare() { t.BaseCtl.Prepare() - token := "" - if tokenStr, ok := t.Request.SESSION[define.TOKEN]; ok { - token = tokenStr - } else if tokenStr, ok = t.Request.REQUEST[define.TOKEN]; ok { - token = tokenStr - } else if tokenStr, ok = t.Request.HEADER[define.TOKEN]; ok { - token = tokenStr + skip := t.MustGetInt("skip") + if skip == 1 { + t.claims = &jwt.Claims{ + AccountType: "customer", + AccountId: 16, + CustomerId: 16, + CustomerPid: 0, + ActivityId: 101, + AreaId: 101, + StandardClaims: jwt2.StandardClaims{}, + } + return } else { - var param = make(map[string]interface{}, 0) - err := t.RequestToStruct(¶m) - t.CheckErr(err) - if tokenStr, ok := param[define.TOKEN]; ok { - token = tokenStr.(string) + token := "" + if tokenStr, ok := t.Request.SESSION[define.TOKEN]; ok { + token = tokenStr + } else if tokenStr, ok = t.Request.REQUEST[define.TOKEN]; ok { + token = tokenStr + } else if tokenStr, ok = t.Request.HEADER[define.TOKEN]; ok { + token = tokenStr + } else { + var param = make(map[string]interface{}, 0) + err := t.RequestToStruct(¶m) + t.CheckErr(err) + if tokenStr, ok := param[define.TOKEN]; ok { + token = tokenStr.(string) + } } + claims, err := jwt.ParseAccessToken(token) + if err != nil { + t.ERROR("token 失效", code.MSG_ERR_Authority) + } + t.claims = claims + // 最后多地区:子账号的area_id = area_id, 但是主账号的area_id 需要通过activity_id 进行获取 } - claims, err := jwt.ParseAccessToken(token) - if err != nil { - t.ERROR("token 失效", code.MSG_ERR_Authority) - } - t.claims = claims - // 最后多地区:子账号的area_id = area_id, 但是主账号的area_id 需要通过activity_id 进行获取 } func (t *AuthorCtl) MustGetUID() int64 { diff --git a/controllers/pc/activity.go b/controllers/pc/activity.go index 2bc1662..51e5725 100644 --- a/controllers/pc/activity.go +++ b/controllers/pc/activity.go @@ -13,6 +13,7 @@ import ( //活动 type ActivityCtl struct { controllers.AuthorCtl + //controllers.BaseCtl } // 废弃 diff --git a/main.go b/main.go index 63ba4a1..379c9a7 100644 --- a/main.go +++ b/main.go @@ -46,6 +46,7 @@ func main() { core.GetInstanceRouterManage().Registered(new(client.LotteryCtl)) // 奖品 core.GetInstanceRouterManage().Registered(new(client.CalorieCtl)) // 卡路里 core.GetInstanceRouterManage().Registered(new(client.LiveCtl)) // 直播 + core.GetInstanceRouterManage().Registered(new(client.GoodCtl)) // 商品 // common core.GetInstanceRouterManage().Registered(new(common.AnnexCtl)) diff --git a/models/base.go b/models/base.go index c5154b5..a769410 100644 --- a/models/base.go +++ b/models/base.go @@ -2,6 +2,7 @@ package models import ( "fmt" + "github.com/xormplus/xorm" "reflect" "strings" @@ -33,7 +34,7 @@ func Condition(condition map[string]interface{}) *xorm.Session { func Save(condition map[string]interface{}, obj interface{}, filed ...string) error { session := Condition(condition) defer session.Close() - if condition != nil && Exist(CloneSession(session), reflect.New(reflect.TypeOf(obj).Elem()).Interface()) { + if condition != nil && Exist(Condition(condition), reflect.New(reflect.TypeOf(obj).Elem()).Interface()) { //存在则更新 _, err := session.Cols(filed...).Update(obj) return err diff --git a/models/customer_goods.go b/models/customer_goods.go index e6975bf..3665f6d 100644 --- a/models/customer_goods.go +++ b/models/customer_goods.go @@ -36,10 +36,6 @@ func (t *CustomerGoods) Alias(name string) string { return AliasTableName(t, name) } -//func (t *CustomerGoods) GetById(gid int64) (bool, error) { -// return core.GetXormAuto().Where("is_delete=0 and id=?", gid).Get(t) -//} - func GetGoodsByActivityId(activityId, areaId int64) ([]*CustomerGoods, error) { goods := make([]*CustomerGoods, 0) err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and area_id=?", activityId, areaId). diff --git a/models/user_order.go b/models/user_order.go index 11355a4..3183908 100644 --- a/models/user_order.go +++ b/models/user_order.go @@ -75,8 +75,8 @@ func (t *UserOrder) UpdateRefundByOutTradeNo(outTradeNo interface{}) (int64, err Cols("success_time", "status", "refund_recv_account", "refund_account").Update(t) } -func GetUserOrdersByStatus(expires string, status ...int) ([]*UserOrder, error) { +func GetUserOrdersByStatus(expire string, status ...int) ([]*UserOrder, error) { orders := make([]*UserOrder, 0) - err := core.GetXormAuto().Where("is_delete=0 and time_expires <= ?", expires).In("status", status).Find(&orders) + err := core.GetXormAuto().Where("is_delete=0 and time_expire <= ?", expire).In("status", status).Find(&orders) return orders, err } diff --git a/services/pay/order.go b/services/pay/order.go index dbafbea..389ff87 100644 --- a/services/pay/order.go +++ b/services/pay/order.go @@ -17,7 +17,7 @@ import ( ) func init() { - go loopUnifiedOrder() + //go loopUnifiedOrder() } var orderDelayQueue = make(chan *orderDelayQueueParam, math.MaxInt8)