Commit 559cebf1 authored by hujiebin's avatar hujiebin

Update history_charge_with_agent.go

parent bb0688e3
......@@ -16,6 +16,7 @@ type ChargeWithAgent struct {
Country string
Area string
LastDealerCode string
Last30Dollar int64
}
func main() {
......@@ -47,11 +48,13 @@ group by code order by dollar DESC;
if err := mysql.ProdReadOnlyDB.Raw(sql).Scan(&data).Error; err != nil {
panic(err)
}
last30Charge := getLast30Charge()
for i, d := range data {
data[i].LastDealerCode = getLastDealerCode(d.UserId)
data[i].Area = am[d.Country]
if len(data[i].LastDealerCode) > 0 {
}
data[i].Last30Dollar = last30Charge[d.UserId]
println(i)
}
excelFileName := fmt.Sprintf("./历史累充带代理.xlsx")
......@@ -61,12 +64,12 @@ group by code order by dollar DESC;
panic(err)
}
row := sheet.AddRow()
c1, c2, c3, c4, c5 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
c1.Value, c2.Value, c3.Value, c4.Value, c5.Value = "靓号", "充值美分", "国家", "区域", "最近代理"
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 = "靓号", "充值美分", "国家", "区域", "最近代理", "最近30天充值"
for _, d := range data {
row := sheet.AddRow()
c1, c2, c3, c4, c5 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
c1.Value, c2.Value, c3.Value, c4.Value, c5.Value = d.Code, cast.ToString(d.Dollar), d.Country, d.Area, d.LastDealerCode
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 = d.Code, cast.ToString(d.Dollar), d.Country, d.Area, d.LastDealerCode, cast.ToString(d.Last30Dollar)
}
_ = xlFile.Save(excelFileName)
}
......@@ -102,3 +105,23 @@ func getLastDealerCode(userId uint64) string {
}
return res2.Code
}
func getLast30Charge() map[uint64]int64 {
sql := `
select id as user_id,code ,SUM(dollar) as dollar ,country FROM (
select u.id,u.code,SUM(price) as dollar,u.country FROM pay_order p, user u where u.id = p.user_id AND p.status = 2 AND type = 0 AND p.created_time > NOW() - INTERVAL 30 DAY group by user_id UNION ALL
select u.id,u.code,SUM(dollar) as dollar,u.country FROM dealer_transfer_detail d, user u where u.id = d.receiver_id AND d.created_time > NOW() - INTERVAL 30 DAY group by receiver_id UNION ALL
select u.id,u.code,SUM(dollar) as dollar,u.country FROM dealer_transfer_detail_pink d, user u where u.id = d.receiver_id AND d.created_time > NOW() - INTERVAL 30 DAY group by receiver_id
) t
group by code order by dollar DESC;
`
var data []ChargeWithAgent
if err := mysql.ProdReadOnlyDB.Raw(sql).Scan(&data).Error; err != nil {
panic(err)
}
var res = make(map[uint64]int64)
for _, v := range data {
res[v.UserId] = v.Dollar
}
return res
}
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