parent
b5a3e29bf1
commit
6fedc45331
23 changed files with 329 additions and 71 deletions
@ -0,0 +1,88 @@ |
|||||||
|
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 |
||||||
|
} |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
// 账号相关的接口
|
||||||
|
package routers |
||||||
|
|
||||||
|
import ( |
||||||
|
handler "server/modules/backend/handler/tgrobot" |
||||||
|
|
||||||
|
"github.com/gin-gonic/gin" |
||||||
|
) |
||||||
|
|
||||||
|
func tgrobot(e *gin.Engine) { |
||||||
|
e.POST("/tgrobot/getPayPer", handler.GetPayPer) |
||||||
|
} |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
package util |
||||||
|
|
||||||
|
import ( |
||||||
|
"reflect" |
||||||
|
) |
||||||
|
|
||||||
|
func GetStructFieldByJsonTag(obj interface{}, tag string) (field reflect.StructField, ok bool) { |
||||||
|
t := reflect.TypeOf(obj) |
||||||
|
v := reflect.ValueOf(obj) |
||||||
|
if v.Kind() == reflect.Ptr { |
||||||
|
t = t.Elem() |
||||||
|
} |
||||||
|
|
||||||
|
for i := 0; i < t.NumField(); i++ { |
||||||
|
field = t.Field(i) |
||||||
|
tagName := field.Tag.Get("json") |
||||||
|
if tagName == tag { |
||||||
|
ok = true |
||||||
|
return |
||||||
|
} |
||||||
|
} |
||||||
|
return |
||||||
|
} |
||||||
Loading…
Reference in new issue