订单查询增加uid筛选

dev_aagame
zhora 1 week ago
parent a93153a32e
commit 1a65a4e9de
  1. 29
      modules/backend/handler/statistics/rechargeOrderList.go
  2. 16
      modules/backend/handler/statistics/withdrawOrderList.go
  3. 2
      modules/backend/values/statistics.go

@ -33,19 +33,18 @@ func RechargeOrderList(c *gin.Context) {
queryCount := " SELECT COUNT(*) as count FROM recharge_order AS re " queryCount := " SELECT COUNT(*) as count FROM recharge_order AS re "
queryAmount := " SELECT SUM(amount) as amount 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 { 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 { } 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 { if req.Channel != nil {
str += fmt.Sprintf(" AND channel_id = %d", *req.Channel) str += fmt.Sprintf(" AND channel_id = %d", *req.Channel)
} }
if req.Status != nil { 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 { if len(req.PayChannels) > 0 {
payChannelStr := "" payChannelStr := ""
for _, v := range req.PayChannels { for _, v := range req.PayChannels {
@ -57,7 +56,17 @@ func RechargeOrderList(c *gin.Context) {
str += fmt.Sprintf(" AND pay_channel in (%s) ", payChannelStr) 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 { if req.Birth != nil {
birthSu, birthEu := utils.GetQueryUnix(*req.Birth, *req.Birth) 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) 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 { if err != nil {
log.Error("err:%v", err) log.Error("err:%v", err)
} }
@ -122,9 +131,9 @@ func RechargeOrderList(c *gin.Context) {
Amount: v.Amount, Amount: v.Amount,
Status: int(v.Status), Status: int(v.Status),
Birth: user.Birth, Birth: user.Birth,
// OrderCount: db.Mysql().Count(&common.RechargeOrder{}, fmt.Sprintf(" uid = %d AND event = %d ", v.UID, common.CurrencyEventReCharge)), //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)), //OrderSuccessCount: db.Mysql().Count(&common.RechargeOrder{}, fmt.Sprintf(" uid = %d AND `event` = %d AND `status` = %d", v.UID, common.CurrencyEventReCharge, common.StatusROrderPay)),
// TotalAmount: totalAmount, // TotalAmount: totalAmount,
ProductId: v.ProductID, ProductId: v.ProductID,
ActivityId: getActivityId(v.ProductID), // 活动id ActivityId: getActivityId(v.ProductID), // 活动id
PayChannel: v.PayChannel, // 支付渠道 PayChannel: v.PayChannel, // 支付渠道

@ -29,12 +29,16 @@ func WithdrawOrderList(c *gin.Context) {
queryOrder := " SELECT * FROM withdraw_order AS re where" queryOrder := " SELECT * FROM withdraw_order AS re where"
queryCount := " SELECT COUNT(*) as count 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 { if req.Channel != nil {
str += fmt.Sprintf(" AND channel_id = %d ", *req.Channel) str += fmt.Sprintf(" AND channel_id = %d ", *req.Channel)
} }
if req.Status != nil { 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 " // 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 // total
s, e := utils.GetQueryUnix(req.Start, req.End) 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 { if req.Channel != nil {
sql += fmt.Sprintf(" and channel_id = %v", *req.Channel) sql += fmt.Sprintf(" and channel_id = %v", *req.Channel)
} }
resp.WithdrawTotal = db.Mysql().SumTable("withdraw_order", sql, "amount") resp.WithdrawTotal = db.Mysql().SumTable("withdraw_order", sql, "amount")
resp.WithdrawCount = db.Mysql().CountTable("withdraw_order", sql) 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 { if req.Channel != nil {
sql += fmt.Sprintf(" and channel_id = %v", *req.Channel) sql += fmt.Sprintf(" and channel_id = %v", *req.Channel)
} }
@ -130,7 +134,7 @@ func QueryWithdrawOrder(c *gin.Context) {
} }
var ret []common.WithdrawOrder 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) err := db.Mysql().QueryBySql(queryOrder, &ret)
@ -167,7 +171,7 @@ func QueryWithdrawOrder(c *gin.Context) {
if len(ret) > 0 { if len(ret) > 0 {
// total // 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.WithdrawTotal = db.Mysql().Sum(&common.WithdrawOrder{}, sql, "amount")
resp.WithdrawCount = db.Mysql().Count(&common.WithdrawOrder{}, sql) resp.WithdrawCount = db.Mysql().Count(&common.WithdrawOrder{}, sql)

@ -1161,6 +1161,7 @@ type RechargeOrderListReq struct {
Num int `json:"Num" binding:"required"` Num int `json:"Num" binding:"required"`
Birth *string `json:"Birth"` Birth *string `json:"Birth"`
Sort int `json:"Sort"` Sort int `json:"Sort"`
Uid *int `json:"Uid"`
} }
type OneRechargeOrderList struct { type OneRechargeOrderList struct {
@ -1204,6 +1205,7 @@ type WithdrawOrderListReq struct {
Page int `json:"Page" binding:"required"` Page int `json:"Page" binding:"required"`
Num int `json:"Num" binding:"required"` Num int `json:"Num" binding:"required"`
Sort int `json:"Sort"` Sort int `json:"Sort"`
Uid *int `json:"Uid"`
} }
// WithdrawOrderListResp 请求退出订单列表 // WithdrawOrderListResp 请求退出订单列表

Loading…
Cancel
Save