From 3fbf4730c51d09b0719bccde13b1fe43148c1e15 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Fri, 9 Jun 2023 15:41:25 +0800 Subject: [PATCH] Update charge_max.go --- script/charge_max.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/script/charge_max.go b/script/charge_max.go index 2c1d9a3..c84aced 100644 --- a/script/charge_max.go +++ b/script/charge_max.go @@ -25,8 +25,6 @@ func ats25(a interface{}) string { } func main() { - d := GetLastChargeTime(644741) - println(d) type ChargeMaxUid struct { UserId uint64 Dollar int64 @@ -86,7 +84,7 @@ func GetUserById25(id uint64) (model.User, error) { func GetUserMonthMaxCharge(uid uint64) float64 { var dollar int64 - if err := mysql.ProdReadOnlyDB.Raw("select max(dollar)\nFROM (\nSELECT\n\tuser_id,\n\tDATE_FORMAT(created_time,\"%Y-%m\") as d,\n\tSUM(price) as dollar\nFROM\n\t`pay_order`\nWHERE\n\t`status` = '2'\nAND `type` = '0'\nAND created_time >= \"2022-07-01\"\nAND user_id = ?\nGROUP BY user_id,d \nUNION ALL \nSELECT\n\treceiver_id user_id,\n\tDATE_FORMAT(created_time, \"%Y-%m\") AS d,\n\tSUM(dollar) AS dollar\nFROM\n\t`dealer_transfer_detail`\nWHERE\n\tcreated_time >= \"2022-07-01\"\nAND receiver_id = ?\nGROUP BY\n\treceiver_id,\n\td\n) t", uid, uid).Scan(&dollar).Error; err != nil { + if err := mysql.ProdReadOnlyDB.Raw("select MAX(dollar) FROM\n(\nselect d,SUM(dollar) as dollar FROM (\nSELECT\n\tuser_id,\n\tDATE_FORMAT(created_time,\"%Y-%m\") as d,\n\tSUM(price) as dollar\nFROM\n\t`pay_order`\nWHERE\n\t`status` = '2'\nAND `type` = '0'\nAND created_time >= \"2022-07-01\"\nAND user_id = ?\nGROUP BY user_id,d \nUNION ALL \nSELECT\n\treceiver_id user_id,\n\tDATE_FORMAT(created_time, \"%Y-%m\") AS d,\n\tSUM(dollar) AS dollar\nFROM\n\t`dealer_transfer_detail`\nWHERE\n\tcreated_time >= \"2022-07-01\"\nAND receiver_id = ?\nGROUP BY\n\treceiver_id,\n\td\n) t GROUP BY d\n) t2", uid, uid).Scan(&dollar).Error; err != nil { panic(err) } return float64(dollar) / 100 -- 2.22.0