From 0e98389f57d6c7403ceba49155893e4196562e4f Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Mon, 3 Aug 2020 10:50:02 +0800 Subject: [PATCH] fix:bug --- controllers/client/order_entry.go | 5 ++++- controllers/pc/order_draw.go | 21 +++++++++++++++++++++ models/customer_order.go | 21 ++++++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/controllers/client/order_entry.go b/controllers/client/order_entry.go index 299ed6f..e18597d 100644 --- a/controllers/client/order_entry.go +++ b/controllers/client/order_entry.go @@ -301,9 +301,10 @@ func (t *OrderEntryCtl) ManualOrder() { } subs := make([]*models.CustomerOrderSub, 0) totalAmount := 0.00 + goodNum := 0 for _, g := range param.Goods { for _, good := range goods { - if g.GoodId == int(good.Id) { + if g.GoodId == good.Id { subs = append(subs, &models.CustomerOrderSub{ GoodsId: good.Id, GoodsNum: g.GoodNum, @@ -311,6 +312,7 @@ func (t *OrderEntryCtl) ManualOrder() { GoodPrice: good.Price, }) totalAmount += good.Price * float64(g.GoodNum) + goodNum += g.GoodNum } } } @@ -352,6 +354,7 @@ func (t *OrderEntryCtl) ManualOrder() { order.TotalAmount = totalAmount order.Receiver = param.Name order.Phone = param.Phone + order.GoodsNum = goodNum order.OutTradeNo = utils.RandomStr(32) order.OrderNo = fmt.Sprint(define.DefaultOrderNo + int(count)) order.Status = 1 diff --git a/controllers/pc/order_draw.go b/controllers/pc/order_draw.go index 6f4dbfe..edcafa1 100644 --- a/controllers/pc/order_draw.go +++ b/controllers/pc/order_draw.go @@ -434,3 +434,24 @@ func (t *OrderDrawCtl) Orders() { "buyer_count": buyerCount, }) } + +// 录入人员排行榜 +func (t *OrderDrawCtl) OrderRank() { + activityId := t.MustGetInt("activity_id") + limit := t.MustGetInt("limit") + + activity := models.Activity{} + exist, err := models.Get(&activity, activityId) + t.CheckErr(err) + t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") + + order := &models.CustomerOrder{} + res, err := order.SumCustomerOrder(activity.Id, activity.RehearsalId, activity.ArchId, limit) + t.CheckErr(err) + total, err := order.TotalCustomerOrderGoodsNum(activity.Id, activity.RehearsalId, activity.ArchId) + t.CheckErr(err) + t.JSON(map[string]interface{}{ + "list": res, + "total": total, + }) +} diff --git a/models/customer_order.go b/models/customer_order.go index b9bc51a..897b9fc 100644 --- a/models/customer_order.go +++ b/models/customer_order.go @@ -43,10 +43,11 @@ type CustomerOrder struct { CancelTime time.Time `json:"cancel_time" xorm:"comment('取消时间') DATETIME"` AutoReceiveTime time.Time `json:"auto_receive_time" xorm:"comment('自动收货时间') DATETIME"` + GoodsId int `json:"goods_id" xorm:"not null default 0 comment('customer_goods表id') BIGINT(20)"` + GoodsName string `json:"goods_name" xorm:"not null default '' comment('商品名字') VARCHAR(255)"` + GoodsNum int `json:"goods_num" xorm:"not null default 0 comment('商品数量') INT(11)"` + // 无关变量 - GoodsId int `json:"goods_id,omitempty" xorm:"not null default 0 comment('customer_goods表id') BIGINT(20)"` - GoodsName string `json:"goods_name,omitempty" xorm:"not null default '' comment('商品名字') VARCHAR(255)"` - GoodsNum int `json:"goods_num,omitempty" xorm:"not null default 0 comment('商品数量') INT(11)"` OrderTime string `json:"order_time,omitempty" xorm:"-"` Good *CustomerGoods `json:"good,omitempty" xorm:"-"` User *User `json:"user,omitempty" xorm:"-"` @@ -92,3 +93,17 @@ func (t *CustomerOrder) CountCustomerOrder(activityId, rehearsalId, archId inter activityId, rehearsalId, archId).Distinct("buyer_id").Count(t) return buyerCount, err } + +func (t *CustomerOrder) SumCustomerOrder(activityId, rehearsalId, archId interface{}, limit int) ([]map[string]string, error) { + res := make([]map[string]string, 0) + err := core.GetXormAuto().Table(t).Select("order_entry_person_id, order_entry_person_name, SUM(goods_num) as num"). + NoAutoCondition().Where("is_delete=0 and activity_id=? and rehearsal_id=? and arch_id=?", + activityId, rehearsalId, archId).Limit(limit).Desc("num").Find(&res) + return res, err +} + +func (t *CustomerOrder) TotalCustomerOrderGoodsNum(activityId, rehearsalId, archId interface{}) (int64, error) { + sum, err := core.GetXormAuto().NoAutoCondition().Where("is_delete=0 and activity_id=? and rehearsal_id=? and arch_id=?", + activityId, rehearsalId, archId).SumInt(t, "goods_num") + return sum, err +}