From f81253a67682c6cbcefada40583f62ba089640a6 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Wed, 5 Aug 2020 16:48:15 +0800 Subject: [PATCH] fix:bug --- controllers/pc/order_draw.go | 15 +++++++-------- models/customer_order.go | 11 ++++++++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/controllers/pc/order_draw.go b/controllers/pc/order_draw.go index 1e428bc..95e5189 100644 --- a/controllers/pc/order_draw.go +++ b/controllers/pc/order_draw.go @@ -244,10 +244,9 @@ func (t *OrderDrawCtl) Users() { defer s.Close() if customer.IsSpecial == 2 { s = s.Table(&models.CustomerOrder{}).Alias("o").Select("o.buyer_id as user_id, "+ - " o.phone, o.order_entry_person_name as entry_person_name, u.nickname as username, u.avatar"). - Distinct("o.buyer_id").Join("LEFT", (&models.User{}).Alias("u"), - "o.buyer_id=u.id and u.is_delete=0").Where("o.activity_id=? and o.is_delete=0 "+ - " and o.rehearsal_id=? and o.arch_id=?", activityId, activity.RehearsalId, activity.ArchId) + " o.phone, o.order_entry_person_name as entry_person_name, o.receiver as username"). + Where("o.is_delete=0 and o.activity_id=? and o.rehearsal_id=? and o.arch_id=?", + activityId, activity.RehearsalId, activity.ArchId) if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT { recordIds := make([]int, 0) @@ -516,10 +515,9 @@ func (t *OrderDrawCtl) Orders() { t.CheckErr(err) t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") - // 下订单人数 - buyerCount, err := (&models.CustomerOrder{}).CountCustomerOrder(activity.Id, activity.RehearsalId, activity.ArchId) t.CheckErr(err) if customer.IsSpecial == 2 { + count, err := (&models.CustomerOrder{}).CountCustomerOrder(activity.Id, activity.RehearsalId, activity.ArchId, 0) orders := make([]*SpecialOrdersResult, 0) err = core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o").Select("o.id as id, "+ " o.area_name as area_name, o.order_entry_person_name as entry_person_name, o.buyer_id as user_id, "+ @@ -544,10 +542,11 @@ func (t *OrderDrawCtl) Orders() { t.JSON(map[string]interface{}{ "orders": orders, "total": len(orders), - "buyer_count": buyerCount, + "buyer_count": count, }) return } else { + count, err := (&models.CustomerOrder{}).CountCustomerOrder(activity.Id, activity.RehearsalId, activity.ArchId, 1) orders := make([]*OrdersResult, 0) err = core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o"). Select("o.area_name, o.goods_name, o.buyer_id as user_id, u.nickname, l.extra_data as extra_data, o.created_at"). @@ -569,7 +568,7 @@ func (t *OrderDrawCtl) Orders() { t.JSON(map[string]interface{}{ "orders": orders, "total": len(orders), - "buyer_count": buyerCount, + "buyer_count": count, }) return } diff --git a/models/customer_order.go b/models/customer_order.go index a94d147..e8f331d 100644 --- a/models/customer_order.go +++ b/models/customer_order.go @@ -91,10 +91,15 @@ func GetExpiredAtLiveCustomerOrder() ([]*CustomerOrder, error) { return orders, nil } -func (t *CustomerOrder) CountCustomerOrder(activityId, rehearsalId, archId interface{}) (int64, error) { - buyerCount, err := core.GetXormAuto().NoAutoCondition(). +func (t *CustomerOrder) CountCustomerOrder(activityId, rehearsalId, archId interface{}, _type int) (int64, error) { + s := core.GetXormAuto().NoAutoCondition(). Where("is_delete=0 and activity_id=? and rehearsal_id=? and arch_id=?", - activityId, rehearsalId, archId).Distinct("buyer_id").Count(t) + activityId, rehearsalId, archId) + defer s.Close() + if _type == 1 { + s.Distinct("buyer_id") + } + s.Count(t) return buyerCount, err }