diff --git a/modules/backend/handler/statistics/rechargeOrderList.go b/modules/backend/handler/statistics/rechargeOrderList.go index e8bf3e6..607c992 100644 --- a/modules/backend/handler/statistics/rechargeOrderList.go +++ b/modules/backend/handler/statistics/rechargeOrderList.go @@ -33,19 +33,18 @@ func RechargeOrderList(c *gin.Context) { queryCount := " SELECT COUNT(*) as count FROM recharge_order AS re " queryAmount := " SELECT SUM(amount) as amount FROM recharge_order AS re " - var str string + var str, orderStr string if req.Status != nil && *req.Status == 2 { - str = fmt.Sprintf(" callback_time >= %d AND callback_time < %d AND event in (%d,%d) ", su, eu, common.CurrencyEventReCharge, common.CurrencyEventActivityWeekCard) + str = fmt.Sprintf(" callback_time >= %d AND callback_time < %d AND `event` in (%d,%d) ", su, eu, common.CurrencyEventReCharge, common.CurrencyEventActivityWeekCard) } else { - str = fmt.Sprintf(" create_time >= %d AND create_time < %d AND event in (%d,%d) ", su, eu, common.CurrencyEventReCharge, common.CurrencyEventActivityWeekCard) + str = fmt.Sprintf(" create_time >= %d AND create_time < %d AND `event` in (%d,%d) ", su, eu, common.CurrencyEventReCharge, common.CurrencyEventActivityWeekCard) } if req.Channel != nil { str += fmt.Sprintf(" AND channel_id = %d", *req.Channel) } if req.Status != nil { - str += fmt.Sprintf(" AND status = %d", *req.Status) + str += fmt.Sprintf(" AND `status` = %d", *req.Status) } - if len(req.PayChannels) > 0 { payChannelStr := "" for _, v := range req.PayChannels { @@ -57,7 +56,17 @@ func RechargeOrderList(c *gin.Context) { str += fmt.Sprintf(" AND pay_channel in (%s) ", payChannelStr) } - queryOrder += " LEFT JOIN ( SELECT uid, COALESCE(SUM(amount), 0) AS totalAmount FROM recharge_order WHERE " + str + " GROUP BY uid) rm ON rm.uid = re.uid " + orderStr = str + if req.Uid != nil { + str += fmt.Sprintf(" AND uid = %d ", *req.Uid) + orderStr += fmt.Sprintf(" AND re.uid = %d ", *req.Uid) + } + + if req.Uid == nil { + queryOrder += " LEFT JOIN ( SELECT uid, COALESCE(SUM(amount), 0) AS totalAmount FROM recharge_order WHERE " + str + " GROUP BY uid) rm ON rm.uid = re.uid " + } else { + queryOrder += " LEFT JOIN ( SELECT uid, COALESCE(SUM(amount), 0) AS totalAmount FROM recharge_order WHERE " + str + " ) rm ON rm.uid = re.uid " + } if req.Birth != nil { birthSu, birthEu := utils.GetQueryUnix(*req.Birth, *req.Birth) @@ -97,7 +106,7 @@ func RechargeOrderList(c *gin.Context) { limit := fmt.Sprintf(" LIMIT %d, %d ", (req.Page-1)*req.Num, req.Num) // 查询订单 - err = db.Mysql().QueryBySql(queryOrder+str+desc+limit, &ret) + err = db.Mysql().QueryBySql(queryOrder+orderStr+desc+limit, &ret) if err != nil { log.Error("err:%v", err) } @@ -122,9 +131,9 @@ func RechargeOrderList(c *gin.Context) { Amount: v.Amount, Status: int(v.Status), Birth: user.Birth, - // OrderCount: db.Mysql().Count(&common.RechargeOrder{}, fmt.Sprintf(" uid = %d AND event = %d ", v.UID, common.CurrencyEventReCharge)), - // OrderSuccessCount: db.Mysql().Count(&common.RechargeOrder{}, fmt.Sprintf(" uid = %d AND event = %d AND status = %d", v.UID, common.CurrencyEventReCharge, common.StatusROrderPay)), - // TotalAmount: totalAmount, + //OrderCount: db.Mysql().Count(&common.RechargeOrder{}, fmt.Sprintf(" uid = %d AND `event` = %d ", v.UID, common.CurrencyEventReCharge)), + //OrderSuccessCount: db.Mysql().Count(&common.RechargeOrder{}, fmt.Sprintf(" uid = %d AND `event` = %d AND `status` = %d", v.UID, common.CurrencyEventReCharge, common.StatusROrderPay)), + // TotalAmount: totalAmount, ProductId: v.ProductID, ActivityId: getActivityId(v.ProductID), // 活动id PayChannel: v.PayChannel, // 支付渠道 diff --git a/modules/backend/handler/statistics/withdrawOrderList.go b/modules/backend/handler/statistics/withdrawOrderList.go index ae6638d..b808287 100644 --- a/modules/backend/handler/statistics/withdrawOrderList.go +++ b/modules/backend/handler/statistics/withdrawOrderList.go @@ -29,12 +29,16 @@ func WithdrawOrderList(c *gin.Context) { queryOrder := " SELECT * FROM withdraw_order AS re where" queryCount := " SELECT COUNT(*) as count FROM withdraw_order AS re where" - str := fmt.Sprintf(" event = %d AND create_time >= %d AND create_time < %d ", common.CurrencyEventWithDraw, st, et) + str := fmt.Sprintf(" `event` = %d AND create_time >= %d AND create_time < %d ", common.CurrencyEventWithDraw, st, et) if req.Channel != nil { str += fmt.Sprintf(" AND channel_id = %d ", *req.Channel) } if req.Status != nil { - str += fmt.Sprintf(" AND status = %d ", *req.Status) + str += fmt.Sprintf(" AND `status` = %d ", *req.Status) + } + + if req.Uid != nil { + str += fmt.Sprintf(" AND uid = %d ", *req.Uid) } // queryOrder += " LEFT JOIN ( SELECT uid, SUM(amount) AS totalAmount FROM withdraw_order WHERE " + str + " GROUP BY uid) rm ON rm.uid = re.uid WHERE rm.uid = re.uid AND " @@ -102,14 +106,14 @@ func WithdrawOrderList(c *gin.Context) { // total s, e := utils.GetQueryUnix(req.Start, req.End) - sql := fmt.Sprintf("event = %v and status = %v and create_time >= %d and create_time < %d", common.CurrencyEventWithDraw, common.StatusROrderFinish, s, e) + sql := fmt.Sprintf("`event` = %v and `status` = %v and create_time >= %d and create_time < %d", common.CurrencyEventWithDraw, common.StatusROrderFinish, s, e) if req.Channel != nil { sql += fmt.Sprintf(" and channel_id = %v", *req.Channel) } resp.WithdrawTotal = db.Mysql().SumTable("withdraw_order", sql, "amount") resp.WithdrawCount = db.Mysql().CountTable("withdraw_order", sql) - sql = fmt.Sprintf("event = %v and create_time >= %d and create_time < %d", common.CurrencyEventWithDraw, s, e) + sql = fmt.Sprintf("`event` = %v and create_time >= %d and create_time < %d", common.CurrencyEventWithDraw, s, e) if req.Channel != nil { sql += fmt.Sprintf(" and channel_id = %v", *req.Channel) } @@ -130,7 +134,7 @@ func QueryWithdrawOrder(c *gin.Context) { } var ret []common.WithdrawOrder - queryOrder := fmt.Sprintf(" SELECT * FROM withdraw_order WHERE event = %d AND (apipayid = '%s' or orderid = '%s') ", common.CurrencyEventWithDraw, req.OrderId, req.OrderId) + queryOrder := fmt.Sprintf(" SELECT * FROM withdraw_order WHERE `event` = %d AND (apipayid = '%s' or orderid = '%s') ", common.CurrencyEventWithDraw, req.OrderId, req.OrderId) // 查询订单 err := db.Mysql().QueryBySql(queryOrder, &ret) @@ -167,7 +171,7 @@ func QueryWithdrawOrder(c *gin.Context) { if len(ret) > 0 { // total - sql := fmt.Sprintf("event = %v and status = %v and uid = %d", common.CurrencyEventWithDraw, common.StatusROrderFinish, ret[0].UID) + sql := fmt.Sprintf("`event` = %v and `status` = %v and uid = %d", common.CurrencyEventWithDraw, common.StatusROrderFinish, ret[0].UID) resp.WithdrawTotal = db.Mysql().Sum(&common.WithdrawOrder{}, sql, "amount") resp.WithdrawCount = db.Mysql().Count(&common.WithdrawOrder{}, sql) diff --git a/modules/backend/values/statistics.go b/modules/backend/values/statistics.go index c69fbfb..72606f8 100644 --- a/modules/backend/values/statistics.go +++ b/modules/backend/values/statistics.go @@ -1161,6 +1161,7 @@ type RechargeOrderListReq struct { Num int `json:"Num" binding:"required"` Birth *string `json:"Birth"` Sort int `json:"Sort"` + Uid *int `json:"Uid"` } type OneRechargeOrderList struct { @@ -1204,6 +1205,7 @@ type WithdrawOrderListReq struct { Page int `json:"Page" binding:"required"` Num int `json:"Num" binding:"required"` Sort int `json:"Sort"` + Uid *int `json:"Uid"` } // WithdrawOrderListResp 请求退出订单列表