diff --git a/controllers/pc/order_draw.go b/controllers/pc/order_draw.go index d085611..ea9008b 100644 --- a/controllers/pc/order_draw.go +++ b/controllers/pc/order_draw.go @@ -462,7 +462,17 @@ func (t *OrderDrawCtl) ListOfWinners() { t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") - result, err := lottery_service.GetOrderWinnersResult(rule.Id, activity.RehearsalId, activity.ArchId) + customer := models.Customer{} + exist, err = models.Get(&customer, activity.CustomerId) + t.CheckErr(err) + t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") + + var result []*lottery_service.OrderWinnersResult + if customer.IsSpecial == 2 { + result, err = lottery_service.GetSpecialOrderWinnersResult(rule.Id, activity.RehearsalId, activity.ArchId) + } else { + result, err = lottery_service.GetOrderWinnersResult(rule.Id, activity.RehearsalId, activity.ArchId) + } t.CheckErr(err) t.JSON(map[string]interface{}{ "total": len(result), @@ -566,7 +576,12 @@ func (t *OrderDrawCtl) OrderRank() { 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) + var total int64 = 0 + if len(res) == 1 && res[0]["num"] == "0" { + res = nil + } else { + total, err = order.TotalCustomerOrderGoodsNum(activity.Id, activity.RehearsalId, activity.ArchId) + } t.CheckErr(err) t.JSON(map[string]interface{}{ "list": res, diff --git a/models/customer_order.go b/models/customer_order.go index 61739a8..9c16e94 100644 --- a/models/customer_order.go +++ b/models/customer_order.go @@ -100,9 +100,9 @@ func (t *CustomerOrder) CountCustomerOrder(activityId, rehearsalId, archId inter 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"). + err := core.GetXormAuto().Table(t).Select("order_entry_person_id, order_entry_person_name, COALESCE(SUM(goods_num), 0) 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) + activityId, rehearsalId, archId).GroupBy("order_entry_person_id").Limit(limit).Desc("num").Find(&res) return res, err } diff --git a/ready.md b/ready.md new file mode 100644 index 0000000..5505c82 --- /dev/null +++ b/ready.md @@ -0,0 +1 @@ +go + gorm + mysql \ No newline at end of file diff --git a/services/lottery/order_special.go b/services/lottery/order_special.go index f342b2e..84dbb35 100644 --- a/services/lottery/order_special.go +++ b/services/lottery/order_special.go @@ -62,20 +62,11 @@ func GetSpecialOrderLottery(repeat string, activityId, ruleId, ladderId, rehears } -type SpecialOrderWinnersResult struct { - UserId int `json:"user_id"` - UserName string `json:"user_name"` - UserPhone string `json:"user_phone"` - Avatar string `json:"avatar"` - PrizeName string `json:"prize_name"` - EntryPersonName string `json:"entry_person_name"` -} - -func GetSpecialOrderWinnersResult(ruleId, rehearsalId, archId interface{}) (result []*SpecialOrderWinnersResult, err error) { +func GetSpecialOrderWinnersResult(ruleId, rehearsalId, archId interface{}) (result []*OrderWinnersResult, err error) { err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Alias("r"). - Select("r.order_entry_person_name as entry_person_name, r.user_id, u.nickname as username, "+ - " u.phone as user_phone, u.avatar, r.prize_name").Join("LEFT", - (&models.User{}).Alias("u"), "u.id=r.user_id and u.is_delete=0"). + Select("r.order_entry_person_name as entry_person_name, r.user_id, o.receiver as username, "+ + " u.phone as user_phone, r.prize_name").Join("LEFT", + (&models.CustomerOrder{}).Alias("o"), "o.id=r.customer_order_id and u.is_delete=0"). Where("r.is_delete=0 and r.order_draw_rule_id=? and r.rehearsal_id=? and r.arch_id=?", ruleId, rehearsalId, archId).Find(&result) return