From 3f1894485c82bd58c86d8c685f3cb18157c5f5e2 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Wed, 8 Feb 2023 15:19:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/group_power_india.go | 4 +-- {model => script/model}/group.go | 0 {model => script/model}/robot.go | 0 {model => script/model}/user.go | 0 {mysql => script/mysql}/mysql.go | 0 script/prod_game_robot.go | 10 ++++---- script/sync_group_code.go | 12 ++++----- script/test_20_in_mic.go | 4 +-- script/test_fruit_machine.go | 4 +-- script/test_game_robot.go | 4 +-- script/user_charge.go | 44 ++++++++++++++++++++------------ 11 files changed, 46 insertions(+), 36 deletions(-) rename {model => script/model}/group.go (100%) rename {model => script/model}/robot.go (100%) rename {model => script/model}/user.go (100%) rename {mysql => script/mysql}/mysql.go (100%) diff --git a/script/group_power_india.go b/script/group_power_india.go index 47d12f9..e2d882c 100644 --- a/script/group_power_india.go +++ b/script/group_power_india.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "git.hilo.cn/hilo-common/model" - "git.hilo.cn/hilo-common/mysql" + "git.hilo.cn/hilo-common/script/model" + "git.hilo.cn/hilo-common/script/mysql" "github.com/spf13/cast" "github.com/tealeg/xlsx" "time" diff --git a/model/group.go b/script/model/group.go similarity index 100% rename from model/group.go rename to script/model/group.go diff --git a/model/robot.go b/script/model/robot.go similarity index 100% rename from model/robot.go rename to script/model/robot.go diff --git a/model/user.go b/script/model/user.go similarity index 100% rename from model/user.go rename to script/model/user.go diff --git a/mysql/mysql.go b/script/mysql/mysql.go similarity index 100% rename from mysql/mysql.go rename to script/mysql/mysql.go diff --git a/script/prod_game_robot.go b/script/prod_game_robot.go index 9d5dd55..fd38e57 100644 --- a/script/prod_game_robot.go +++ b/script/prod_game_robot.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "git.hilo.cn/hilo-common/model" - "git.hilo.cn/hilo-common/mysql" + model2 "git.hilo.cn/hilo-common/script/model" + "git.hilo.cn/hilo-common/script/mysql" uuid "github.com/satori/go.uuid" "strings" ) @@ -19,7 +19,7 @@ var codes = []string{"1384891", "1387474", "1379229", "1382208", "1385588", "138 func main() { println(len(codes)) // 1078个key的 - var testRobots []model.UserNoId + var testRobots []model2.UserNoId sql := "SELECT * FROM `user` where id BETWEEN 4564 and 7615 limit 1078" if err := mysql.TestDB.Raw(sql).Find(&testRobots).Error; err != nil { panic(err) @@ -39,11 +39,11 @@ func main() { //break } var userIds []uint64 - if err := mysql.ProdReadOnlyDB.Model(model.User{}).Select("id").Where("code in ?", codes).Find(&userIds).Error; err != nil { + if err := mysql.ProdReadOnlyDB.Model(model2.User{}).Select("id").Where("code in ?", codes).Find(&userIds).Error; err != nil { panic("get user id fail") } for _, userId := range userIds { - gameRobot := &model.GameRobot{UserId: userId} + gameRobot := &model2.GameRobot{UserId: userId} if err := mysql.ProdWriteDB.Create(gameRobot).Error; err != nil { fmt.Printf("create robot fail:%v-%v", gameRobot, err) } diff --git a/script/sync_group_code.go b/script/sync_group_code.go index d2ee1bb..a63392c 100644 --- a/script/sync_group_code.go +++ b/script/sync_group_code.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "git.hilo.cn/hilo-common/model" - "git.hilo.cn/hilo-common/mysql" + model2 "git.hilo.cn/hilo-common/script/model" + "git.hilo.cn/hilo-common/script/mysql" "time" ) @@ -24,12 +24,12 @@ func main() { panic(err) } for _, row := range rows { - groupInfo := new(model.GroupInfo) - if err := mysql.ProdReadOnlyDB.Model(model.GroupInfo{}).Where("im_group_id = ?", row.GroupId).First(groupInfo).Error; err != nil { + groupInfo := new(model2.GroupInfo) + if err := mysql.ProdReadOnlyDB.Model(model2.GroupInfo{}).Where("im_group_id = ?", row.GroupId).First(groupInfo).Error; err != nil { panic(err) } - owner := new(model.User) - if err := mysql.ProdReadOnlyDB.Model(model.User{}).Where("id = ?", groupInfo.Owner).First(owner).Error; err != nil { + owner := new(model2.User) + if err := mysql.ProdReadOnlyDB.Model(model2.User{}).Where("id = ?", groupInfo.Owner).First(owner).Error; err != nil { panic(err) } if owner.Code != owner.OriginCode && owner.Code != groupInfo.Code { diff --git a/script/test_20_in_mic.go b/script/test_20_in_mic.go index cb3b4c0..2a53ad1 100644 --- a/script/test_20_in_mic.go +++ b/script/test_20_in_mic.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "git.hilo.cn/hilo-common/model" - "git.hilo.cn/hilo-common/mysql" + "git.hilo.cn/hilo-common/script/model" + "git.hilo.cn/hilo-common/script/mysql" "git.hilo.cn/hilo-common/utils/jwt" "net/http" "strings" diff --git a/script/test_fruit_machine.go b/script/test_fruit_machine.go index ffe0e15..0c34bce 100644 --- a/script/test_fruit_machine.go +++ b/script/test_fruit_machine.go @@ -2,8 +2,8 @@ package main import ( "fmt" - "git.hilo.cn/hilo-common/model" - "git.hilo.cn/hilo-common/mysql" + "git.hilo.cn/hilo-common/script/model" + "git.hilo.cn/hilo-common/script/mysql" "git.hilo.cn/hilo-common/utils/jwt" "io/ioutil" "math/rand" diff --git a/script/test_game_robot.go b/script/test_game_robot.go index e385c4b..7e238f8 100644 --- a/script/test_game_robot.go +++ b/script/test_game_robot.go @@ -1,8 +1,8 @@ package main import ( - "git.hilo.cn/hilo-common/model" - "git.hilo.cn/hilo-common/mysql" + "git.hilo.cn/hilo-common/script/model" + "git.hilo.cn/hilo-common/script/mysql" ) func main() { diff --git a/script/user_charge.go b/script/user_charge.go index 3eb8d77..a56eb35 100644 --- a/script/user_charge.go +++ b/script/user_charge.go @@ -2,29 +2,39 @@ package main import ( "fmt" - "git.hilo.cn/hilo-common/mysql" - "time" + "git.hilo.cn/hilo-common/script/model" + "git.hilo.cn/hilo-common/script/mysql" ) 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 + //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} + var uids []uint64 + if err := mysql.ProdReadOnlyDB.Raw("select id from user where origin_code <> `code`").Find(&uids).Error; err != nil { + panic(err) + } + var users []model.User + if err := mysql.ProdReadOnlyDB.Model(model.User{}).Where("id in ?", uids).Find(&users).Error; err != nil { + panic(err) + } + uM := make(map[uint64]model.User) + for k, u := range users { + uM[u.Id] = users[k] + } + var data = make(map[uint64]int64) for _, uid := range uids { - m1, _ := GetUsersChargeMoneySum([]uint64{uid}, since) - m2, _ := GetUserDealerTransferMoneySum([]uint64{uid}, since) - data = append(data, [2]uint64{uid, uint64(m1 + m2)}) + m1, _ := GetUsersChargeMoneySum([]uint64{uid}) + m2, _ := GetUserDealerTransferMoneySum([]uint64{uid}) + data[uid] = m1 + m2 } - for _, r := range data { - fmt.Println(r) + for uid, num := range data { + fmt.Printf("%d,%s,%d\n", uid, uM[uid].Country, num) } } // 获取用户范围内充值金额 // param sinceTime: 过去n时间内 // 返回美分 -func GetUsersChargeMoneySum(uids []uint64, sinceTime time.Time) (int64, error) { +func GetUsersChargeMoneySum(uids []uint64) (int64, error) { if len(uids) <= 0 { return 0, nil } @@ -34,8 +44,8 @@ func GetUsersChargeMoneySum(uids []uint64, sinceTime time.Time) (int64, error) { 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). + Where("d.user_id in (?) AND operate_type in (?) AND add_reduce = 1", + uids, []int{int(4), int(42), int(55), int(68)}). Select("SUM(p.price) as money").Scan(&money).Error; err != nil { return 0, err } @@ -45,7 +55,7 @@ func GetUsersChargeMoneySum(uids []uint64, sinceTime time.Time) (int64, error) { // 获取代理范围内总充值金额 // param sinceTime: 过去n时间内 // 返回美分 -func GetUserDealerTransferMoneySum(uids []uint64, sinceTime time.Time) (int64, error) { +func GetUserDealerTransferMoneySum(uids []uint64) (int64, error) { if len(uids) <= 0 { return 0, nil } @@ -55,8 +65,8 @@ func GetUserDealerTransferMoneySum(uids []uint64, sinceTime time.Time) (int64, e 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"). + Where("d.user_id in (?) AND operate_type = ? AND add_reduce = 1", + uids, 26).Select("SUM(t.dollar) as price"). Scan(&money).Error; err != nil { return 0, err } -- 2.22.0