|
|
@ -2,7 +2,6 @@ package client |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/helper" |
|
|
|
"hudongzhuanjia/controllers" |
|
|
|
"hudongzhuanjia/models" |
|
|
|
invitation_service "hudongzhuanjia/services/invitation" |
|
|
@ -18,13 +17,18 @@ type OrderEntryCtl struct { |
|
|
|
controllers.AuthorCtl |
|
|
|
} |
|
|
|
|
|
|
|
// 录入人员
|
|
|
|
// 商品 == > 用户查看所有商品
|
|
|
|
func (t *OrderEntryCtl) List() { |
|
|
|
uid := t.MustGetUID() |
|
|
|
activityId := t.MustGetInt64("activity_id") |
|
|
|
goods := make([]*models.CustomerGoods, 0) |
|
|
|
err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId). |
|
|
|
Asc("created_at").Find(&goods) |
|
|
|
|
|
|
|
entryPerson := new(models.OrderEntryPerson) |
|
|
|
exist, err := models.Get(entryPerson, uid) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在") |
|
|
|
|
|
|
|
goods, err := models.GetGoodsByActivityId(activityId, entryPerson.AreaId) |
|
|
|
t.CheckErr(err) |
|
|
|
for index := range goods { |
|
|
|
url := fmt.Sprintf("%s/PcClient/Client/OrderEntryCtl/order?"+ |
|
|
@ -86,6 +90,7 @@ func (t *OrderEntryCtl) Order() { |
|
|
|
prize.ActivityName = activity.Name |
|
|
|
prize.PrizeName = gift.GiftName |
|
|
|
prize.PrizeImg = gift.GiftPicUrl |
|
|
|
prize.ArchId = activity.ArchId |
|
|
|
prize.PrizeType = 3 |
|
|
|
prize.IsDelete = false |
|
|
|
prize.CreatedAt = time.Now() |
|
|
@ -98,8 +103,8 @@ func (t *OrderEntryCtl) Order() { |
|
|
|
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)) |
|
|
|
count, err := core.GetXormAuto().Where("activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0", |
|
|
|
activityId, activity.RehearsalId, activity.ArchId).Count(new(models.CustomerOrder)) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
|
t.CheckErr(err) |
|
|
@ -117,6 +122,7 @@ func (t *OrderEntryCtl) Order() { |
|
|
|
order := new(models.CustomerOrder) |
|
|
|
order.UserPrizeId = prize.Id |
|
|
|
order.AreaId = entryPerson.AreaId |
|
|
|
order.ArchId = activity.ArchId |
|
|
|
order.AreaName = area.Name |
|
|
|
order.BuyerId = userId |
|
|
|
order.GoodsId = goodId |
|
|
@ -126,10 +132,8 @@ func (t *OrderEntryCtl) Order() { |
|
|
|
order.OrderEntryPersonId = entryPerson.Id |
|
|
|
order.GoodsName = good.Name |
|
|
|
order.TotalAmount = good.Price |
|
|
|
order.OutTradeNo = helper.CreateUUID() |
|
|
|
order.OutTradeNo = utils.RandomStr(32) |
|
|
|
order.IsDelete = false |
|
|
|
order.UpdatedAt = time.Now() |
|
|
|
order.CreatedAt = time.Now() |
|
|
|
_, err = session.InsertOne(order) |
|
|
|
if err != nil { |
|
|
|
session.Rollback() |
|
|
@ -144,13 +148,13 @@ func (t *OrderEntryCtl) Order() { |
|
|
|
func (t *OrderEntryCtl) DeleteOrder() { |
|
|
|
orderId := t.MustGetInt64("order_id") |
|
|
|
order := new(models.CustomerOrder) |
|
|
|
exist, err := core.GetXormAuto().Where("is_delete=0 and id=?", orderId).Get(order) |
|
|
|
exist, err := models.Get(order, orderId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单不存在") |
|
|
|
_, err = new(models.CustomerOrder).SoftDeleteById(orderId) |
|
|
|
_, err = models.Del(order, order.Id) |
|
|
|
t.CheckErr(err) |
|
|
|
if order.UserPrizeId != 0 { |
|
|
|
_, err = new(models.UserPrize).SoftDeleteById(order.UserPrizeId) |
|
|
|
if order.UserPrizeId > 0 { |
|
|
|
_, err = models.Del(&models.UserPrize{}, order.UserPrizeId) |
|
|
|
t.CheckErr(err) |
|
|
|
} |
|
|
|
t.SUCCESS("删除成功") |
|
|
@ -188,9 +192,9 @@ func (t *OrderEntryCtl) EntryOrders() { |
|
|
|
Join("LEFT", new(models.CustomerGoods).Alias("g"), |
|
|
|
"o.goods_id=g.id and o.activity_id=g.activity_id and g.is_delete=0"). |
|
|
|
Join("LEFT", new(models.InvitationLetter).Alias("l"), |
|
|
|
"l.user_id = o.buyer_id and o.activity_id=l.activity_id and l.is_delete=0"). |
|
|
|
Where("o.activity_id=? and o.order_entry_person_id=? and o.rehearsal_id=? and o.is_delete=0", |
|
|
|
activityId, uid, activity.RehearsalId).Desc("o.created_at").Find(&list) |
|
|
|
"l.user_id = o.buyer_id and o.activity_id=l.activity_id and o.arch_id=l.arch_id and l.is_delete=0"). |
|
|
|
Where("o.activity_id=? and o.order_entry_person_id=? and o.rehearsal_id=? and arch_id=? and o.is_delete=0", |
|
|
|
activityId, uid, activity.RehearsalId, activity.ArchId).Desc("o.created_at").Find(&list) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
// 添加邀请函的内容
|
|
|
@ -229,8 +233,8 @@ func (t *OrderEntryCtl) UserOrders() { |
|
|
|
s := core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o"). |
|
|
|
Join("LEFT", new(models.CustomerGoods).Alias("g"), |
|
|
|
"o.goods_id=g.id and g.is_delete=0"). |
|
|
|
Where("o.buyer_id=? and o.is_delete=0 and o.activity_id=? and o.rehearsal_id=?", |
|
|
|
uid, activity.Id, activity.RehearsalId) |
|
|
|
Where("o.buyer_id=? and o.is_delete=0 and o.activity_id=? and o.rehearsal_id=? and o.arch_id=?", |
|
|
|
uid, activity.Id, activity.RehearsalId, activity.ArchId) |
|
|
|
|
|
|
|
if t.PageSize > 0 { |
|
|
|
s = s.Limit(t.PageSize, t.Page*t.PageSize) |
|
|
|