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.
89 lines
2.2 KiB
89 lines
2.2 KiB
|
2 months ago
|
package handler
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"server/common"
|
||
|
|
"server/db"
|
||
|
|
"server/modules/backend/app"
|
||
|
|
"server/modules/backend/values"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
type GetPayPerReq struct {
|
||
|
|
Second int // 秒
|
||
|
|
}
|
||
|
|
|
||
|
|
type GetPayPerResp struct {
|
||
|
|
Per int64
|
||
|
|
SuccessCount int64
|
||
|
|
TotalCount int64
|
||
|
|
}
|
||
|
|
|
||
|
|
// 查询支付成功率
|
||
|
|
func GetPayPer(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
req := new(GetPayPerReq)
|
||
|
|
a.S(req)
|
||
|
|
if req.Second <= 0 {
|
||
|
|
a.Code = values.CodeParam
|
||
|
|
return
|
||
|
|
}
|
||
|
|
resp := &GetPayPerResp{}
|
||
|
|
a.Data = resp
|
||
|
|
su := time.Now().Unix() - int64(req.Second)
|
||
|
|
count := getPayCount(0, su, 0)
|
||
|
|
successCount := getPaySuccessCount(0, su, 0)
|
||
|
|
if count > 0 {
|
||
|
|
resp.Per = successCount * 100 / count
|
||
|
|
}
|
||
|
|
resp.SuccessCount = successCount
|
||
|
|
resp.TotalCount = count
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取付费总单数
|
||
|
|
func getPayCount(channel int, su, eu int64) (count int64) {
|
||
|
|
channelSql := ""
|
||
|
|
if channel > 0 {
|
||
|
|
channelSql = fmt.Sprintf(` and channel_id = %d `, channel)
|
||
|
|
}
|
||
|
|
var start, end string
|
||
|
|
if su > 0 {
|
||
|
|
suStr := time.Unix(su, 0)
|
||
|
|
start = fmt.Sprintf(" and created_at >= '%s'", suStr.Format("2006-01-02 15:04:05"))
|
||
|
|
}
|
||
|
|
if eu > 0 {
|
||
|
|
euStr := time.Unix(eu, 0)
|
||
|
|
end = fmt.Sprintf(" and created_at < '%s'", euStr.Format("2006-01-02 15:04:05"))
|
||
|
|
}
|
||
|
|
sql := fmt.Sprintf(`SELECT ifNull(count(*),0) as count from recharge_order WHERE event = %d %s %s %s`,
|
||
|
|
common.CurrencyEventReCharge, start, end, channelSql)
|
||
|
|
db.Mysql().QueryCountBySql(sql, &count)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取付费成功总单数
|
||
|
|
func getPaySuccessCount(channel int, su, eu int64) (count int64) {
|
||
|
|
channelSql := ""
|
||
|
|
if channel > 0 {
|
||
|
|
channelSql = fmt.Sprintf(` and channel_id = %d `, channel)
|
||
|
|
}
|
||
|
|
var start, end string
|
||
|
|
if su > 0 {
|
||
|
|
suStr := time.Unix(su, 0)
|
||
|
|
start = fmt.Sprintf(" and created_at >= '%s'", suStr.Format("2006-01-02 15:04:05"))
|
||
|
|
}
|
||
|
|
if eu > 0 {
|
||
|
|
euStr := time.Unix(eu, 0)
|
||
|
|
end = fmt.Sprintf(" and created_at < '%s'", euStr.Format("2006-01-02 15:04:05"))
|
||
|
|
}
|
||
|
|
sql := fmt.Sprintf(`SELECT ifNull(count(*),0) as count from recharge_order WHERE event = %d and status = %d %s %s %s`,
|
||
|
|
common.CurrencyEventReCharge, common.StatusROrderPay, start, end, channelSql)
|
||
|
|
db.Mysql().QueryCountBySql(sql, &count)
|
||
|
|
return
|
||
|
|
}
|