Commit 3f189448 authored by hujiebin's avatar hujiebin

feat:脚本

parent 21335d2f
...@@ -2,8 +2,8 @@ package main ...@@ -2,8 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"git.hilo.cn/hilo-common/model" "git.hilo.cn/hilo-common/script/model"
"git.hilo.cn/hilo-common/mysql" "git.hilo.cn/hilo-common/script/mysql"
"github.com/spf13/cast" "github.com/spf13/cast"
"github.com/tealeg/xlsx" "github.com/tealeg/xlsx"
"time" "time"
......
...@@ -2,8 +2,8 @@ package main ...@@ -2,8 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"git.hilo.cn/hilo-common/model" model2 "git.hilo.cn/hilo-common/script/model"
"git.hilo.cn/hilo-common/mysql" "git.hilo.cn/hilo-common/script/mysql"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
"strings" "strings"
) )
...@@ -19,7 +19,7 @@ var codes = []string{"1384891", "1387474", "1379229", "1382208", "1385588", "138 ...@@ -19,7 +19,7 @@ var codes = []string{"1384891", "1387474", "1379229", "1382208", "1385588", "138
func main() { func main() {
println(len(codes)) // 1078个key的 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" sql := "SELECT * FROM `user` where id BETWEEN 4564 and 7615 limit 1078"
if err := mysql.TestDB.Raw(sql).Find(&testRobots).Error; err != nil { if err := mysql.TestDB.Raw(sql).Find(&testRobots).Error; err != nil {
panic(err) panic(err)
...@@ -39,11 +39,11 @@ func main() { ...@@ -39,11 +39,11 @@ func main() {
//break //break
} }
var userIds []uint64 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") panic("get user id fail")
} }
for _, userId := range userIds { for _, userId := range userIds {
gameRobot := &model.GameRobot{UserId: userId} gameRobot := &model2.GameRobot{UserId: userId}
if err := mysql.ProdWriteDB.Create(gameRobot).Error; err != nil { if err := mysql.ProdWriteDB.Create(gameRobot).Error; err != nil {
fmt.Printf("create robot fail:%v-%v", gameRobot, err) fmt.Printf("create robot fail:%v-%v", gameRobot, err)
} }
......
...@@ -2,8 +2,8 @@ package main ...@@ -2,8 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"git.hilo.cn/hilo-common/model" model2 "git.hilo.cn/hilo-common/script/model"
"git.hilo.cn/hilo-common/mysql" "git.hilo.cn/hilo-common/script/mysql"
"time" "time"
) )
...@@ -24,12 +24,12 @@ func main() { ...@@ -24,12 +24,12 @@ func main() {
panic(err) panic(err)
} }
for _, row := range rows { for _, row := range rows {
groupInfo := new(model.GroupInfo) groupInfo := new(model2.GroupInfo)
if err := mysql.ProdReadOnlyDB.Model(model.GroupInfo{}).Where("im_group_id = ?", row.GroupId).First(groupInfo).Error; err != nil { if err := mysql.ProdReadOnlyDB.Model(model2.GroupInfo{}).Where("im_group_id = ?", row.GroupId).First(groupInfo).Error; err != nil {
panic(err) panic(err)
} }
owner := new(model.User) owner := new(model2.User)
if err := mysql.ProdReadOnlyDB.Model(model.User{}).Where("id = ?", groupInfo.Owner).First(owner).Error; err != nil { if err := mysql.ProdReadOnlyDB.Model(model2.User{}).Where("id = ?", groupInfo.Owner).First(owner).Error; err != nil {
panic(err) panic(err)
} }
if owner.Code != owner.OriginCode && owner.Code != groupInfo.Code { if owner.Code != owner.OriginCode && owner.Code != groupInfo.Code {
......
...@@ -2,8 +2,8 @@ package main ...@@ -2,8 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"git.hilo.cn/hilo-common/model" "git.hilo.cn/hilo-common/script/model"
"git.hilo.cn/hilo-common/mysql" "git.hilo.cn/hilo-common/script/mysql"
"git.hilo.cn/hilo-common/utils/jwt" "git.hilo.cn/hilo-common/utils/jwt"
"net/http" "net/http"
"strings" "strings"
......
...@@ -2,8 +2,8 @@ package main ...@@ -2,8 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"git.hilo.cn/hilo-common/model" "git.hilo.cn/hilo-common/script/model"
"git.hilo.cn/hilo-common/mysql" "git.hilo.cn/hilo-common/script/mysql"
"git.hilo.cn/hilo-common/utils/jwt" "git.hilo.cn/hilo-common/utils/jwt"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
......
package main package main
import ( import (
"git.hilo.cn/hilo-common/model" "git.hilo.cn/hilo-common/script/model"
"git.hilo.cn/hilo-common/mysql" "git.hilo.cn/hilo-common/script/mysql"
) )
func main() { func main() {
......
...@@ -2,29 +2,39 @@ package main ...@@ -2,29 +2,39 @@ package main
import ( import (
"fmt" "fmt"
"git.hilo.cn/hilo-common/mysql" "git.hilo.cn/hilo-common/script/model"
"time" "git.hilo.cn/hilo-common/script/mysql"
) )
func main() { 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} //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") var uids []uint64
since = since.AddDate(0, 0, -7) if err := mysql.ProdReadOnlyDB.Raw("select id from user where origin_code <> `code`").Find(&uids).Error; err != nil {
var data [][2]uint64 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 { for _, uid := range uids {
m1, _ := GetUsersChargeMoneySum([]uint64{uid}, since) m1, _ := GetUsersChargeMoneySum([]uint64{uid})
m2, _ := GetUserDealerTransferMoneySum([]uint64{uid}, since) m2, _ := GetUserDealerTransferMoneySum([]uint64{uid})
data = append(data, [2]uint64{uid, uint64(m1 + m2)}) data[uid] = m1 + m2
} }
for _, r := range data { for uid, num := range data {
fmt.Println(r) fmt.Printf("%d,%s,%d\n", uid, uM[uid].Country, num)
} }
} }
// 获取用户范围内充值金额 // 获取用户范围内充值金额
// param sinceTime: 过去n时间内 // param sinceTime: 过去n时间内
// 返回美分 // 返回美分
func GetUsersChargeMoneySum(uids []uint64, sinceTime time.Time) (int64, error) { func GetUsersChargeMoneySum(uids []uint64) (int64, error) {
if len(uids) <= 0 { if len(uids) <= 0 {
return 0, nil return 0, nil
} }
...@@ -34,8 +44,8 @@ func GetUsersChargeMoneySum(uids []uint64, sinceTime time.Time) (int64, error) { ...@@ -34,8 +44,8 @@ func GetUsersChargeMoneySum(uids []uint64, sinceTime time.Time) (int64, error) {
var money R var money R
if err := mysql.ProdReadOnlyDB.Table("diamond_account_detail AS d"). if err := mysql.ProdReadOnlyDB.Table("diamond_account_detail AS d").
Joins("INNER JOIN pay_order AS p ON d.origin_id = p.id"). 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 >= ?", Where("d.user_id in (?) AND operate_type in (?) AND add_reduce = 1",
uids, []int{int(4), int(42), int(55), int(68)}, sinceTime). uids, []int{int(4), int(42), int(55), int(68)}).
Select("SUM(p.price) as money").Scan(&money).Error; err != nil { Select("SUM(p.price) as money").Scan(&money).Error; err != nil {
return 0, err return 0, err
} }
...@@ -45,7 +55,7 @@ func GetUsersChargeMoneySum(uids []uint64, sinceTime time.Time) (int64, error) { ...@@ -45,7 +55,7 @@ func GetUsersChargeMoneySum(uids []uint64, sinceTime time.Time) (int64, error) {
// 获取代理范围内总充值金额 // 获取代理范围内总充值金额
// param sinceTime: 过去n时间内 // param sinceTime: 过去n时间内
// 返回美分 // 返回美分
func GetUserDealerTransferMoneySum(uids []uint64, sinceTime time.Time) (int64, error) { func GetUserDealerTransferMoneySum(uids []uint64) (int64, error) {
if len(uids) <= 0 { if len(uids) <= 0 {
return 0, nil return 0, nil
} }
...@@ -55,8 +65,8 @@ func GetUserDealerTransferMoneySum(uids []uint64, sinceTime time.Time) (int64, e ...@@ -55,8 +65,8 @@ func GetUserDealerTransferMoneySum(uids []uint64, sinceTime time.Time) (int64, e
var money R var money R
if err := mysql.ProdReadOnlyDB.Table("diamond_account_detail AS d"). if err := mysql.ProdReadOnlyDB.Table("diamond_account_detail AS d").
Joins("INNER JOIN dealer_transfer_detail AS t ON d.origin_id = t.id"). 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 >= ?", Where("d.user_id in (?) AND operate_type = ? AND add_reduce = 1",
uids, 26, sinceTime).Select("SUM(t.dollar) as price"). uids, 26).Select("SUM(t.dollar) as price").
Scan(&money).Error; err != nil { Scan(&money).Error; err != nil {
return 0, err return 0, 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