From ce68ab2037d0525c0d8a68d76aac127220d2fcdf Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Fri, 31 Jul 2020 17:52:47 +0800 Subject: [PATCH] fix:bug --- controllers/client/order_entry.go | 97 +++++++++++++++++++++++++-------------- controllers/pc/order_draw.go | 5 ++ 2 files changed, 68 insertions(+), 34 deletions(-) diff --git a/controllers/client/order_entry.go b/controllers/client/order_entry.go index a75f7f3..299ed6f 100644 --- a/controllers/client/order_entry.go +++ b/controllers/client/order_entry.go @@ -146,6 +146,9 @@ func (t *OrderEntryCtl) Order() { order.Receiver = name order.Phone = phone order.Address = address + order.GoodsName = good.Name + order.GoodsId = good.Id + order.GoodsNum = 1 order.OutTradeNo = utils.RandomStr(32) order.OrderNo = fmt.Sprint(define.DefaultOrderNo + int(total)) order.Status = 1 @@ -442,54 +445,80 @@ func (t *OrderEntryCtl) DeleteOrder() { } type OrderListResult struct { - OrderId int `json:"order_id"` - UserId int `json:"user_id"` - EntryName string `json:"entry_name"` - GoodName string `json:"good_name"` - OrderTime string `json:"order_time"` - OrderMoney float64 `json:"order_money"` - Receiver string `json:"receiver"` - Phone string `json:"phone"` - Address string `json:"address"` - Extra []map[string]interface{} `json:"extra"` // 额外信息 - ExtraData string `json:"-"` + OrderId int `json:"order_id"` + UserId int `json:"user_id"` + EntryName string `json:"entry_name"` + GoodName string `json:"good_name"` + OrderTime string `json:"order_time"` + OrderMoney float64 `json:"order_money"` + Receiver string `json:"receiver"` + Phone string `json:"phone"` + Address string `json:"address"` + Extra interface{} `json:"extra"` // 额外信息 + ExtraData string `json:"-"` } func (t *OrderEntryCtl) EntryOrders() { uid := t.GetAccountId() - activityId := t.MustGetInt("activity_id") - entry := new(models.OrderEntryPerson) - exist, err := models.Get(entry, uid) + entry := models.OrderEntryPerson{} + exist, err := models.Get(&entry, uid) t.CheckErr(err) t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在") - activity := new(models.Activity) - exist, err = models.Get(activity, activityId) + activity := models.Activity{} + exist, err = models.Get(&activity, entry.ActivityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") - list := make([]*OrderListResult, 0) - err = core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o"). - Select("o.receiver as receiver, o.phone as phone, o.address as address,l.extra_data as extra_data, "+ - " g.name as good_name, o.buyer_id as user_id, o.total_amount as order_money, o.id as order_id, "+ - " DATE_FORMAT(o.created_at, '%Y-%m-%d %H:%i:%S') AS order_time"). - 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 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 o.arch_id=? and o.is_delete=0", - activityId, uid, activity.RehearsalId, activity.ArchId).Desc("o.created_at").Find(&list) + customer := models.Customer{} + exist, err = models.Get(&customer, activity.CustomerId) t.CheckErr(err) + t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") - // 添加邀请函的内容 - optionItems, err := invitation_service.GetOptionItem(activityId) - t.CheckErr(err) - for i := range list { - data, err := invitation_service.GetOptionValue(optionItems, list[i].ExtraData) + list := make([]*OrderListResult, 0) + if customer.IsSpecial == 0 { + // 添加邀请函的内容 + err = core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o"). + Select("o.receiver as receiver, o.phone as phone, o.address as address,l.extra_data as extra_data, "+ + " g.name as good_name, o.buyer_id as user_id, o.total_amount as order_money, o.id as order_id, "+ + " DATE_FORMAT(o.created_at, '%Y-%m-%d %H:%i:%S') AS order_time").Join("LEFT", + (&models.CustomerGoods{}).Alias("g"), "o.goods_id=g.id and o.activity_id=g.activity_id and g.is_delete=0"). + Join("LEFT", (&models.InvitationLetter{}).Alias("l"), "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 o.arch_id=? "+ + " and o.is_delete=0", activity.Id, uid, activity.RehearsalId, activity.ArchId). + Desc("o.created_at").Find(&list) t.CheckErr(err) - list[i].Extra = data - list[i].EntryName = entry.Name + optionItems, err := invitation_service.GetOptionItem(activity.Id) + t.CheckErr(err) + for i := range list { + data, err := invitation_service.GetOptionValue(optionItems, list[i].ExtraData) + t.CheckErr(err) + list[i].Extra = data + list[i].EntryName = entry.Name + } + } else { + err = core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o").Select("o.id as order_id, "+ + " o.receiver as receiver, o.phone as phone, o.address as address, o.buyer_id as user_id, o.order_entry_person_name as entry_name, "+ + " o.total_amount as order_money, DATE_FORMAT(o.created_at, '%Y-%m-%d %H:%i:%S') AS order_time"). + Where("o.activity_id=? and o.rehearsal_id=? and o.order_entry_person_id=? and o.arch_id=?", + activity.Id, activity.RehearsalId, uid, activity.ArchId).Find(&list) + t.CheckErr(err) + orderIds := make([]int, 0) + for _, v := range list { + orderIds = append(orderIds, v.OrderId) + } + subs, err := models.GetCustomerOrderSubsByOrderIds(orderIds) + t.CheckErr(err) + for i := range list { + s := make([]interface{}, 0) + for _, sub := range subs { + if sub["order_id"] == fmt.Sprint(list[i].OrderId) { + s = append(s, sub) + } + } + list[i].Extra = s + } } t.JSON(map[string]interface{}{ diff --git a/controllers/pc/order_draw.go b/controllers/pc/order_draw.go index 34f7913..08af93c 100644 --- a/controllers/pc/order_draw.go +++ b/controllers/pc/order_draw.go @@ -19,6 +19,11 @@ type OrderDrawCtl struct { controllers.AuthorCtl } +// 屏蔽 +func (t *OrderDrawCtl) Block() { + +} + // 开启订单活动 func (t *OrderDrawCtl) Switch() { activityId := t.MustGetInt("activity_id")