|
|
@ -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") |
|
|
|
} |
|
|
|
|
|
|
|