Commit 3f189448 authored by hujiebin's avatar hujiebin

feat:脚本

parent 21335d2f
......@@ -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"
......
......@@ -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)
}
......
......@@ -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 {
......
......@@ -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"
......
......@@ -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"
......
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() {
......
......@@ -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
}
......
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