You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
4.2 KiB
110 lines
4.2 KiB
|
1 year ago
|
package statistics
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"server/common"
|
||
|
|
"server/db"
|
||
|
|
"server/modules/backend/app"
|
||
|
|
utils "server/modules/backend/util"
|
||
|
|
"server/modules/backend/values"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
)
|
||
|
|
|
||
|
|
func RechargeTrendMap(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
req := new(values.RechargeTrendMapReq)
|
||
|
|
if !a.S(req) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
var resp values.RechargeTrendMapResp
|
||
|
|
|
||
|
|
var oneDay int64 = 24 * 60 * 60
|
||
|
|
var half int64 = 1 * 60 * 60
|
||
|
|
su, eu := utils.GetQueryUnix(req.Start, req.End)
|
||
|
|
|
||
|
|
for i := su; i < eu; i += oneDay {
|
||
|
|
dayS := i
|
||
|
|
dayE := i + oneDay
|
||
|
|
for j := i; j < i+oneDay; j += half {
|
||
|
|
s := j
|
||
|
|
e := j + half
|
||
|
|
resp.List = append(resp.List, getRechargeTrendMapInfo(&s, &e, &dayS, &dayE, req.Channel))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
a.Data = resp
|
||
|
|
}
|
||
|
|
|
||
|
|
func getRechargeTrendMapInfo(s, e, dayS, dayE *int64, channel *int) values.RechargeTrendMapInfo {
|
||
|
|
var rechargeTrendInfo values.RechargeTrendMapInfo
|
||
|
|
|
||
|
|
// sts := time.Unix(*dayS, 0).Format("2006-01-02 15:04:05")
|
||
|
|
// ete := time.Unix(*dayE, 0).Format("2006-01-02 15:04:05")
|
||
|
|
sts := *dayS
|
||
|
|
ete := *dayE
|
||
|
|
st := *s
|
||
|
|
et := *e
|
||
|
|
|
||
|
|
// st := time.Unix(*s, 0).Format("2006-01-02 15:04:05")
|
||
|
|
// et := time.Unix(*e, 0).Format("2006-01-02 15:04:05")
|
||
|
|
|
||
|
|
// 日期
|
||
|
|
rechargeTrendInfo.Date = *s
|
||
|
|
|
||
|
|
// 新用户充值订单数
|
||
|
|
newSql1 := ` SELECT COUNT(a.id) as NewRechargeOrderCount FROM users a ` +
|
||
|
|
` LEFT JOIN recharge_order b on a.id = b.uid ` +
|
||
|
|
` where a.role <> 100 ` +
|
||
|
|
` and "%s" <= FROM_UNIXTIME(a.birth) and "%s" > FROM_UNIXTIME(a.birth) ` +
|
||
|
|
` and create_time >= %d and create_time < %d` +
|
||
|
|
` and (event = %v or event = %v) `
|
||
|
|
|
||
|
|
// 充值总金额
|
||
|
|
amountTotal := `SELECT SUM(amount) as RechargeAmount FROM recharge_order WHERE (event = %v or event = %v) and status = %v and create_time >= %d and create_time < %d `
|
||
|
|
|
||
|
|
if channel != nil {
|
||
|
|
// 新用户充值订单数
|
||
|
|
err := db.Mysql().QueryBySql(fmt.Sprintf(newSql1+" and channel_id = %d ", sts, ete, st, et, common.CurrencyEventReCharge, common.CurrencyEventGMRecharge, *channel), &rechargeTrendInfo.NewRechargeOrderCount)
|
||
|
|
if err != nil {
|
||
|
|
log.Error(err.Error())
|
||
|
|
}
|
||
|
|
|
||
|
|
// 成功充值订单数
|
||
|
|
sqlStr := fmt.Sprintf(" (event = %v or event = %v) and status = %v and create_time >= %d and create_time < %d and channel_id = %d ", common.CurrencyEventReCharge, common.CurrencyEventGMRecharge, common.StatusROrderPay, *s, *e, channel)
|
||
|
|
rechargeTrendInfo.RechargeOrderSuccessCount = db.Mysql().Count(&common.RechargeOrder{}, sqlStr)
|
||
|
|
|
||
|
|
// 充值总订单数
|
||
|
|
rechargeTrendInfo.RechargeOrderCount = db.Mysql().Count(&common.RechargeOrder{}, fmt.Sprintf(" ( event = %v or event = %v ) and create_time >= %d and create_time < %d and channel_id = %d ", common.CurrencyEventReCharge, common.CurrencyEventGMRecharge, st, et, channel))
|
||
|
|
|
||
|
|
// 充值总金额
|
||
|
|
_ = db.Mysql().QueryBySql(fmt.Sprintf(amountTotal+" and channel_id = %v ", common.CurrencyEventReCharge, common.CurrencyEventGMRecharge, common.StatusROrderPay, st, et, *channel), &rechargeTrendInfo.RechargeAmount)
|
||
|
|
} else {
|
||
|
|
// 新用户充值订单数
|
||
|
|
err := db.Mysql().QueryBySql(fmt.Sprintf(newSql1, sts, ete, st, et, common.CurrencyEventReCharge, common.CurrencyEventGMRecharge), &rechargeTrendInfo.NewRechargeOrderCount)
|
||
|
|
if err != nil {
|
||
|
|
log.Error(err.Error())
|
||
|
|
}
|
||
|
|
|
||
|
|
// 成功充值订单数
|
||
|
|
sqlStr := fmt.Sprintf(" (event = %v or event = %v) and status = %v and create_time >= %d and create_time < %d", common.CurrencyEventReCharge, common.CurrencyEventGMRecharge, common.StatusROrderPay, st, et)
|
||
|
|
rechargeTrendInfo.RechargeOrderSuccessCount = db.Mysql().Count(&common.RechargeOrder{}, sqlStr)
|
||
|
|
|
||
|
|
// 充值总订单数
|
||
|
|
rechargeTrendInfo.RechargeOrderCount = db.Mysql().Count(&common.RechargeOrder{}, fmt.Sprintf(" ( event = %v or event = %v ) and create_time >= %d and create_time < %d ", common.CurrencyEventReCharge, common.CurrencyEventGMRecharge, st, et))
|
||
|
|
|
||
|
|
// 充值总金额
|
||
|
|
_ = db.Mysql().QueryBySql(fmt.Sprintf(amountTotal, common.CurrencyEventReCharge, common.CurrencyEventGMRecharge, common.StatusROrderPay, st, et), &rechargeTrendInfo.RechargeAmount)
|
||
|
|
}
|
||
|
|
|
||
|
|
// 充值成功率
|
||
|
|
rechargeTrendInfo.RechargeSuccessPer = utils.GetPer(rechargeTrendInfo.RechargeOrderSuccessCount, rechargeTrendInfo.RechargeOrderCount)
|
||
|
|
|
||
|
|
return rechargeTrendInfo
|
||
|
|
}
|