Browse Source

expires

master
黄梓健 5 years ago
parent
commit
d7ae7bc085
  1. 65
      controllers/client/order_entry.go
  2. 4
      models/user_order.go
  3. 4
      services/pay/order.go

65
controllers/client/order_entry.go

@ -2,6 +2,7 @@ package client
import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/helper"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
invitation_service "hudongzhuanjia/services/invitation"
@ -11,7 +12,6 @@ import (
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
"github.com/ouxuanserver/osmanthuswine/src/helper"
)
type OrderEntryCtl struct {
@ -68,24 +68,51 @@ func (t *OrderEntryCtl) Order() {
t.CheckErr(err)
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "商品不存在")
orderGift := new(models.OrderGift)
exist, err = orderGift.GetByActivityId(activityId)
t.CheckErr(err)
session := core.GetXormAuto().NewSession()
defer session.Close()
session.Begin()
gift := new(models.OrderGift)
exist, err = session.Where("is_delete=0 and activity_id=?", activityId).Get(gift)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
prize := new(models.UserPrize)
prize.UserId = userId
prize.ActivityId = activityId
prize.RehearsalId = activity.RehearsalId
prize.ActivityName = activity.Name
prize.PrizeName = orderGift.GiftName
prize.PrizeImg = orderGift.GiftPicUrl
prize.PrizeName = gift.GiftName
prize.PrizeImg = gift.GiftPicUrl
prize.PrizeType = 3
prize.IsDelete = false
prize.CreatedAt = time.Now()
prize.UpdatedAt = time.Now()
if exist && orderGift.Num == 0 { // 存在无限制
_, err = prize.Add()
t.CheckErr(err)
if exist {
if gift.Num == 0 {
_, err = session.InsertOne(prize)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
} else if gift.Num > 0 {
count, err := core.GetXormAuto().Where("activity_id=? and rehearsal_id=? and is_delete=0",
activityId, activity.RehearsalId).Count(new(models.CustomerOrder))
if err != nil {
session.Rollback()
t.CheckErr(err)
}
if gift.Num > int(count) {
_, err = session.InsertOne(prize)
if err != nil {
session.Rollback()
t.CheckErr(err)
}
}
}
}
order := new(models.CustomerOrder)
@ -103,24 +130,14 @@ func (t *OrderEntryCtl) Order() {
order.IsDelete = false
order.UpdatedAt = time.Now()
order.CreatedAt = time.Now()
_, err = core.GetXormAuto().Insert(order)
t.CheckErr(err)
// 查出这个订单多少名
// 防止并发出现错误
if exist && orderGift.Num > 0 {
count, err := core.GetXormAuto().Where("created_at >= ? and activity_id=? and rehearsal_id=? and is_delete=0",
order.CreatedAt, activityId, activity.RehearsalId).Count(new(models.CustomerOrder))
_, err = session.InsertOne(order)
if err != nil {
session.Rollback()
t.CheckErr(err)
if orderGift.Num >= int(count) {
_, err = core.GetXormAuto().InsertOne(prize)
t.CheckErr(err)
order.UserPrizeId = prize.Id
_, err := core.GetXormAuto().Where("id=?", order.Id).Cols("user_prize_id").Update(order)
t.CheckErr(err)
}
}
err = session.Commit()
t.CheckErr(err)
t.SUCCESS("success")
}

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(status ...int) ([]*UserOrder, error) {
func GetUserOrdersByStatus(expires string, status ...int) ([]*UserOrder, error) {
orders := make([]*UserOrder, 0)
err := core.GetXormAuto().Where("is_delete=0").In("status", status).Find(&orders)
err := core.GetXormAuto().Where("is_delete=0 and time_expires <= ?", expires).In("status", status).Find(&orders)
return orders, err
}

4
services/pay/order.go

@ -35,7 +35,7 @@ type orderDelayQueueParam struct {
func PutOrderDelayQueue(body, outTradeNo, openId string, amount, status int, expires int64, delay int) {
if expires == 0 {
expires = time.Now().Add(2 * time.Hour).Unix() // 2 个小时
expires = time.Now().Add(12 * time.Hour).Unix() // 2 个小时
}
if delay == 0 {
@ -55,7 +55,7 @@ func PutOrderDelayQueue(body, outTradeNo, openId string, amount, status int, exp
}
func loopUnifiedOrder() {
orders, err := models.GetUserOrdersByStatus(0, 3)
orders, err := models.GetUserOrdersByStatus(core2.FormatTime(time.Now()), 0, 3)
if err != nil {
panic(err)
}

Loading…
Cancel
Save