Commit b2576d93 authored by hujiebin's avatar hujiebin

feat:获取用户范围内充值金额

parent dcdb599d
package main
import (
"fmt"
"github.com/hilo-common/mysql"
"time"
)
func main() {
uids := []uint64{889621, 904971, 1072931, 1083981, 1108951, 1147471, 1187511, 1365041, 1496521, 1540091, 1888121, 2037771, 2236221, 2396461, 2603721, 2613321, 2648851, 2778081, 3142631, 3219391, 3401561, 3533911, 3602511, 3791481, 3840571, 3845671, 3865481, 3873381, 3892321, 4009941}
since, _ := time.Parse("2006-01-02", "2023-02-05")
since = since.AddDate(0, 0, -7)
var data [][2]uint64
for _, uid := range uids {
m1, _ := GetUsersChargeMoneySum([]uint64{uid}, since)
m2, _ := GetUserDealerTransferMoneySum([]uint64{uid}, since)
data = append(data, [2]uint64{uid, uint64(m1 + m2)})
}
for _, r := range data {
fmt.Println(r)
}
}
// 获取用户范围内充值金额
// param sinceTime: 过去n时间内
// 返回美分
func GetUsersChargeMoneySum(uids []uint64, sinceTime time.Time) (int64, error) {
if len(uids) <= 0 {
return 0, nil
}
type R struct {
Money int64
}
var money R
if err := mysql.ProdReadOnlyDB.Table("diamond_account_detail AS d").
Joins("INNER JOIN pay_order AS p ON d.origin_id = p.id").
Where("d.user_id in (?) AND operate_type in (?) AND add_reduce = 1 AND d.created_time >= ?",
uids, []int{int(4), int(42), int(55), int(68)}, sinceTime).
Select("SUM(p.price) as money").Scan(&money).Error; err != nil {
return 0, err
}
return money.Money, nil
}
// 获取代理范围内总充值金额
// param sinceTime: 过去n时间内
// 返回美分
func GetUserDealerTransferMoneySum(uids []uint64, sinceTime time.Time) (int64, error) {
if len(uids) <= 0 {
return 0, nil
}
type R struct {
Price int64
}
var money R
if err := mysql.ProdReadOnlyDB.Table("diamond_account_detail AS d").
Joins("INNER JOIN dealer_transfer_detail AS t ON d.origin_id = t.id").
Where("d.user_id in (?) AND operate_type = ? AND add_reduce = 1 AND d.created_time >= ?",
uids, 26, sinceTime).Select("SUM(t.dollar) as price").
Scan(&money).Error; err != nil {
return 0, err
}
return money.Price, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment