diff --git a/script/charge_max.go b/script/charge_max.go index 2c1d9a3534dc704850c883b48e68bff0be19d26e..c84aced24a8ddf1f42183ce3732b3792bcb27939 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