Commit c0c38910 authored by hujiebin's avatar hujiebin

feat:小助手

parent 3e071612
...@@ -112,6 +112,9 @@ const ( ...@@ -112,6 +112,9 @@ const (
NewUserRegisterPush1 = 44 // 首次充值免费获得永久充值勋章!累积充值$50可申请特殊ID:ABBABB! NewUserRegisterPush1 = 44 // 首次充值免费获得永久充值勋章!累积充值$50可申请特殊ID:ABBABB!
NewUserRegisterPush2 = 45 // 邀请朋友来Hilo,最高获得100,000钻石奖励! NewUserRegisterPush2 = 45 // 邀请朋友来Hilo,最高获得100,000钻石奖励!
NewUserRegisterPush3 = 46 // 举办首个活动,领取10,000钻石和35%奖杯奖励! NewUserRegisterPush3 = 46 // 举办首个活动,领取10,000钻石和35%奖杯奖励!
AddUserBag = 50 // 赠送背包礼物
ActSlotDayRankAward = 52 // slot每日福利
ActSlotStageAwardNotice = 55 // slot阶梯活动
NewUserRegisterPush1_1 = 56 // 首次充值免费获得永久充值勋章!累积充值$50可申请特殊ID:ABBABB! NewUserRegisterPush1_1 = 56 // 首次充值免费获得永久充值勋章!累积充值$50可申请特殊ID:ABBABB!
CpAnniversaryNotice = 57 // cp纪念日提醒 CpAnniversaryNotice = 57 // cp纪念日提醒
) )
......
...@@ -12,4 +12,6 @@ group_power_data: ...@@ -12,4 +12,6 @@ group_power_data:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o group_power_data group_power_data.go CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o group_power_data group_power_data.go
cp_pairs_stat: cp_pairs_stat:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o cp_pairs_stat cp_pairs_stat.go CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o cp_pairs_stat cp_pairs_stat.go
charge_month:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o charge_month charge_month.go
package main
import (
"fmt"
"git.hilo.cn/hilo-common/script/mysql"
"github.com/tealeg/xlsx"
)
type ChargeMonthData struct {
Area string // 区域
Code string // 用户ID
Month string // 月份
Dollar float64 // 当月充值金额$
}
func ats27(a interface{}) string {
return fmt.Sprintf("%v", a)
}
func main() {
type ChargeMaxUid struct {
Code string
Month string
Dollar int64
}
var chargeUids []ChargeMaxUid
/*
SELECT
u. CODE,
t2.d,
t2.dollar
FROM
(
SELECT
user_id,
d,
SUM(dollar) dollar
FROM
(
SELECT
user_id,
DATE_FORMAT(created_time, "%Y-%m") d,
SUM(price) AS dollar
FROM
`pay_order`
WHERE
`status` = '2'
AND `type` = '0'
AND created_time >= "2022-05-01"
GROUP BY
user_id,
d
UNION ALL
SELECT
receiver_id AS user_id,
DATE_FORMAT(created_time, "%Y-%m") d,
SUM(dollar) AS dollar
FROM
dealer_transfer_detail
WHERE
created_time >= "2022-05-01"
GROUP BY
receiver_id,
d
) t
GROUP BY
user_id,
d
) t2,
`user` u
WHERE
u.id = t2.user_id
*/
if err := mysql.ProdReadOnlyDB.Raw("SELECT\n\tcode,\n\tt2.d month,\n\tt2.dollar\nFROM\n\t(\n\t\tSELECT\n\t\t\tuser_id,\n\t\t\td,\n\t\t\tSUM(dollar) dollar\n\t\tFROM\n\t\t\t(\n\t\t\t\tSELECT\n\t\t\t\t\tuser_id,\n\t\t\t\t\tDATE_FORMAT(created_time, \"%Y-%m\") d,\n\t\t\t\t\tSUM(price) AS dollar\n\t\t\t\tFROM\n\t\t\t\t\t`pay_order`\n\t\t\t\tWHERE\n\t\t\t\t\t`status` = '2'\n\t\t\t\tAND `type` = '0'\n\t\t\t\tAND created_time >= \"2022-05-01\"\n\t\t\t\tGROUP BY\n\t\t\t\t\tuser_id,\n\t\t\t\t\td\n\t\t\t\tUNION ALL\n\t\t\t\t\tSELECT\n\t\t\t\t\t\treceiver_id AS user_id,\n\t\t\t\t\t\tDATE_FORMAT(created_time, \"%Y-%m\") d,\n\t\t\t\t\t\tSUM(dollar) AS dollar\n\t\t\t\t\tFROM\n\t\t\t\t\t\tdealer_transfer_detail\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tcreated_time >= \"2022-05-01\"\n\t\t\t\t\tGROUP BY\n\t\t\t\t\t\treceiver_id,\n\t\t\t\t\t\td\n\t\t\t) t\n\t\tGROUP BY\n\t\t\tuser_id,\n\t\t\td\n\t) t2,\n\t`user` u\nWHERE\n\tu.id = t2.user_id").Find(&chargeUids).Error; err != nil {
panic(err)
}
var data []ChargeMonthData
maxData := make(map[string]ChargeMonthData) // code->maxMonthData
for _, uc := range chargeUids {
data = append(data, ChargeMonthData{
Dollar: float64(uc.Dollar) / 100,
Code: uc.Code,
Area: GetAreaByCode27(uc.Code),
Month: uc.Month,
})
//break
}
for _, d := range data {
if d.Dollar > maxData[d.Code].Dollar {
maxData[d.Code] = ChargeMonthData{
Area: d.Area,
Code: d.Code,
Month: d.Month,
Dollar: d.Dollar,
}
}
}
excelFileName := fmt.Sprintf("./202205当月最高充值.xlsx")
xlFile := xlsx.NewFile()
sheet, err := xlFile.AddSheet("slot")
if err != nil {
panic(err)
}
row := sheet.AddRow()
c1, c2, c3, c4 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
c1.Value, c2.Value, c3.Value, c4.Value = "区域", "用户ID", "充值月份", "单月充值金额$"
for _, d := range maxData {
row := sheet.AddRow()
c1, c2, c3, c4 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
c1.Value, c2.Value, c3.Value, c4.Value = ats27(d.Area), ats27(d.Code), ats27(d.Month), ats27(d.Dollar)
}
_ = xlFile.Save(excelFileName)
}
func GetAreaByCode27(code string) string {
sql := "SELECT area FROM res_country c,user u WHERE u.country = c.name AND u.code = ?"
var area int
if err := mysql.ProdReadOnlyDB.Raw(sql, code).Scan(&area).Error; err != nil {
panic(err)
}
if area == 1 {
return "阿语区"
}
return "非阿语区"
}
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