Commit 5cda68e6 authored by hujiebin's avatar hujiebin

Update fruit_machine_charge.go

parent c2fdaaf3
......@@ -32,12 +32,16 @@ func main() {
endTime := time.Date(2023, time.March, 1, 0, 0, 0, 0, time.Local)
var data []FruitDayChargeData
for startTime.Before(endTime) {
var userIds []uint64
date := startTime.Format("2006-01-02")
um1, err := GetDateChargeUserAndMoney(date)
if err := mysql.ProdReadOnlyDB.Table("fruit_machine_stake").Where("`date` = ?", date).Group("user_id").Select("user_id").Scan(&userIds).Error; err != nil {
panic(err)
}
um1, err := GetDateChargeUserAndMoney(date, userIds)
if err != nil {
panic(err)
}
um2, err := GetUserDealerTransferUserAndMoney(date)
um2, err := GetUserDealerTransferUserAndMoney(date, userIds)
if err != nil {
panic(err)
}
......@@ -51,9 +55,9 @@ func main() {
userChargeNum[um.UserId] = struct{}{}
userChargeMoney += um.Money
}
var userIds []uint64
var chargeUserIds []uint64
for userId := range userChargeNum {
userIds = append(userIds, userId)
chargeUserIds = append(chargeUserIds, userId)
}
userNum, err := GetFruitUserNum(date)
if err != nil {
......@@ -63,7 +67,7 @@ func main() {
if err != nil {
panic(err)
}
fruitChargeRecycle, err := GetFruitChargeRecycle(date, userIds)
fruitChargeRecycle, err := GetFruitChargeRecycle(date, chargeUserIds)
if err != nil {
panic(err)
}
......@@ -84,7 +88,7 @@ func main() {
sheet, _ := xlFile.AddSheet("charge")
row := sheet.AddRow()
c1, c2, c3, c4, c5, c6 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
c1.Value, c2.Value, c3.Value, c4.Value, c5.Value, c6.Value = "日期", "参与人数", "总回收 M", "当日充值用户数", "当日充值金额", "充值用户回收 M"
c1.Value, c2.Value, c3.Value, c4.Value, c5.Value, c6.Value = "日期", "参与人数", "总回收 M", "当日充值用户数", "当日充值金额(美分)", "充值用户回收 M"
for _, d := range data {
row := sheet.AddRow()
c1, c2, c3, c4, c5, c6 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
......@@ -95,12 +99,13 @@ func main() {
// 获取充值用户以及金额
// return 充值userIds,充值金额
func GetDateChargeUserAndMoney(date string) ([]UserAndMoney, error) {
func GetDateChargeUserAndMoney(date string, userIds []uint64) ([]UserAndMoney, error) {
var money []UserAndMoney
if err := mysql.ProdReadOnlyDB.Table("diamond_account_detail AS d").
Joins("INNER JOIN pay_order AS p ON d.origin_id = p.id").
Where("DATE(d.created_time) >= ? AND DATE(d.created_time) <= ? AND operate_type in (?) AND add_reduce = 1",
date, date, []int{int(4), int(42), int(55), int(68)}).
Where("d.user_id in ?", userIds).
Group("d.user_id").
Select("d.user_id,SUM(p.price) as money").Scan(&money).Error; err != nil {
return nil, err
......@@ -110,12 +115,14 @@ func GetDateChargeUserAndMoney(date string) ([]UserAndMoney, error) {
// 获取代理充值用户以及金额
// return 充值userIds,充值金额
func GetUserDealerTransferUserAndMoney(date string) ([]UserAndMoney, error) {
func GetUserDealerTransferUserAndMoney(date string, userIds []uint64) ([]UserAndMoney, error) {
var money []UserAndMoney
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("DATE(d.created_time) >= ? AND DATE(d.created_time) <= ? AND operate_type = ? AND add_reduce = 1",
date, date, 26).Select("d.user_id,SUM(t.dollar) as money").
date, date, 26).
Where("d.user_id in ?", userIds).
Select("d.user_id,SUM(t.dollar) as money").
Group("d.user_id").
Scan(&money).Error; err != nil {
return nil, err
......
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