Browse Source

condition

master
黄梓健 5 years ago
parent
commit
31a48aa41d
  1. 51
      controllers/author.go
  2. 1
      controllers/pc/activity.go
  3. 1
      main.go
  4. 3
      models/base.go
  5. 4
      models/customer_goods.go
  6. 4
      models/user_order.go
  7. 2
      services/pay/order.go

51
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(&param)
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(&param)
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 {

1
controllers/pc/activity.go

@ -13,6 +13,7 @@ import (
//活动
type ActivityCtl struct {
controllers.AuthorCtl
//controllers.BaseCtl
}
// 废弃

1
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))

3
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

4
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).

4
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
}

2
services/pay/order.go

@ -17,7 +17,7 @@ import (
)
func init() {
go loopUnifiedOrder()
//go loopUnifiedOrder()
}
var orderDelayQueue = make(chan *orderDelayQueueParam, math.MaxInt8)

Loading…
Cancel
Save