Commit c8ff53370753836f5b77351f5c7f8ed1040fde54

Authored by 王家文
1 parent 4c5f3412
Exists in master and in 1 other branch dev-wjw

refactor♻️:redis对象和mysql对象持久化和读取

README.md
1 1  
2 2 ## 项目目录结构
3 3  
4   -| 项目目录 | 目录说明 |
5   -|-------------|----------|
6   -| conf | beego配置 |
7   -| controllers | 控制器 |
8   -| dto | 数据库存储对象 |
9   -| models | 与客户端传输对象 |
10   -| routers | 路由 |
11   -| sdk | SDK |
12   -| service | 游戏服务器逻辑 |
13   -| sign | 签名 |
14   -| util | 公共库 |
15   -| util-lx | 公共库(李旭) |
  4 +| 项目目录 | 目录说明 |
  5 +|----------------|----------|
  6 +| conf | beego配置 |
  7 +| configs | 游戏配置处理 |
  8 +| controllers | 控制器 |
  9 +| middleware | 中间件 |
  10 +| models | 与客户端传输对象 |
  11 +| routers | 路由 |
  12 +| service-common | 服务器公共模块 |
  13 +| service | 游戏服务器逻辑 |
  14 +| util | 公共库 |
  15 +| util-lx | 公共库(李旭) |
16 16  
17 17 ## 游戏和游戏功能列表
18 18  
19   -| 功能模块名 | 所属功能 | 负责人 |
20   -|---------------|------|-----|
  19 +| 功能模块名 | 所属功能 | 负责人 |
  20 +|------------|------|-----|
21 21 | cardholder | 卡包卡牌 | 王家文 |
... ...
common/svconst/consts.go
... ... @@ -1 +0,0 @@
1   -package svconst
common/svconst/vars.go
... ... @@ -1,13 +0,0 @@
1   -package svconst
2   -
3   -import "gorm.io/gorm"
4   -
5   -var (
6   - AppName = ""
7   -
8   - DbApi *gorm.DB
9   - DbCommon *gorm.DB
10   - DbConfig *gorm.DB
11   -
12   - GameListCardHolder = []string{"10149"}
13   -)
common/svdto/dto.go
... ... @@ -1,68 +0,0 @@
1   -package svdto
2   -
3   -import (
4   - "apigame/util/utdto"
5   - "apigame/util/util-lx/lxalilog"
6   -)
7   -
8   -func InitTable(tb IDtoData, gameId string) {
9   - rule := tb.GetRule(gameId)
10   - utdto.InitTable(rule.DbMysql, tb, rule.TableName)
11   -}
12   -
13   -func Insert(data IDtoData, gameId string) (err error) {
14   - rule := data.GetRule(gameId)
15   - result := utdto.Insert(rule.DbMysql, data, rule.TableName)
16   - err = result.Error
17   - if err != nil {
18   - lxalilog.Errors(err, gameId)
19   - return
20   - }
21   - return
22   -}
23   -
24   -func Update(data IDtoData, gameId string) (err error) {
25   - rule := data.GetRule(gameId)
26   - result := utdto.Update(rule.DbMysql, data, rule.TableName)
27   - err = result.Error
28   - if err != nil {
29   - lxalilog.Errors(err, gameId)
30   - return
31   - }
32   - return
33   -}
34   -
35   -func Save(data IDtoData, gameId string) (err error) {
36   - rule := data.GetRule(gameId)
37   - result := utdto.Save(rule.DbMysql, data, rule.TableName)
38   - err = result.Error
39   - if err != nil {
40   - lxalilog.Errors(err, gameId)
41   - return
42   - }
43   - return
44   -}
45   -
46   -func First(data IDtoData, gameId string) (has bool, err error) {
47   - rule := data.GetRule(gameId)
48   - result := utdto.First(rule.DbMysql, data, rule.TableName)
49   - has = result.RowsAffected != 0
50   - err = result.Error
51   - if err != nil {
52   - lxalilog.Errors(err, gameId)
53   - return
54   - }
55   - return
56   -}
57   -
58   -func Find(data any, dataTemp IDtoData, gameId string) (has bool, err error) {
59   - rule := dataTemp.GetRule(gameId)
60   - result := utdto.Find(rule.DbMysql, data, rule.TableName)
61   - has = result.RowsAffected != 0
62   - err = result.Error
63   - if err != nil {
64   - lxalilog.Errors(err, rule.TableName)
65   - return
66   - }
67   - return
68   -}
common/svdto/init.go
... ... @@ -1,2 +0,0 @@
1   -package svdto
2   -
common/svdto/interface.go
... ... @@ -1,23 +0,0 @@
1   -package svdto
2   -
3   -import "gorm.io/gorm"
4   -
5   -const (
6   - REDIS_CACHEP_REFIX = "apigame" // 缓存前缀
7   -)
8   -
9   -// DtoRule dto参数
10   -type DtoRule struct {
11   - DbMysql *gorm.DB
12   - TableName string
13   - CacheKey string
14   - CacheTime int
15   -}
16   -
17   -// IDtoData dto数据
18   -type IDtoData interface {
19   - // TableName 表名模板
20   - TableName() string
21   - // GetRule 表名模板
22   - GetRule(gameId string) *DtoRule
23   -}
common/svdto/record.go
... ... @@ -1,10 +0,0 @@
1   -package svdto
2   -
3   -import (
4   - "apigame/util/utdto"
5   -)
6   -
7   -func SaveRecord(gameId string, data IDtoData) {
8   - rule := data.GetRule(gameId)
9   - utdto.Insert(rule.DbMysql, data, rule.TableName)
10   -}
common/svlog/ali-log.go
... ... @@ -1,40 +0,0 @@
1   -package svlog
2   -
3   -import (
4   - "apigame/util/util-lx/lxalilog"
5   - "fmt"
6   - "github.com/astaxie/beego"
7   - lalilog "github.com/lixu-any/go-tools/ali/log"
8   -)
9   -
10   -func InitAliLog(appName string) {
11   -
12   - //初始化阿里云日志
13   - logm, _ := beego.AppConfig.GetSection("alilog")
14   - lxalilog.InitAliLog(lxalilog.MapAlilogConfig{
15   - Endpoint: logm["endpoint"],
16   - AccessKeyId: logm["accesskeyid"],
17   - AccessKeySecret: logm["accesskeysecret"],
18   - Project: logm["project"],
19   - AppNaame: appName,
20   - On: logm["on"],
21   - Debug: logm["debug"],
22   - TableError: "api_code_merge",
23   - TableDebug: logm["tabledebug"],
24   - Env: beego.AppConfig.String("env"),
25   - })
26   -
27   - lalilog.InitAliLog(lalilog.MapAlilogConfig{
28   - Endpoint: logm["endpoint"],
29   - AccessKeyId: logm["accesskeyid"],
30   - AccessKeySecret: logm["accesskeysecret"],
31   - Project: logm["project"],
32   - On: logm["on"],
33   - Debug: logm["debug"],
34   - TableError: logm["tableerror"],
35   - TableDebug: logm["tabledebug"],
36   - Env: beego.AppConfig.String("env"),
37   - })
38   -
39   - fmt.Println(appName + " alilog init success")
40   -}
common/svlog/log.go
... ... @@ -1,22 +0,0 @@
1   -package svlog
2   -
3   -import (
4   - "apigame/common/svconst"
5   - "apigame/util/util-lx/lxbeego"
6   - "fmt"
7   - "github.com/astaxie/beego"
8   -)
9   -
10   -func Init() {
11   -
12   - // 初始化日志文件
13   - conf, _ := beego.AppConfig.GetSection("log")
14   - conf["filename"] = conf["path"] + "api.log"
15   -
16   - if err := lxbeego.Inits(conf); err != nil {
17   - fmt.Println("svlog.Inits Error::" + err.Error())
18   - }
19   -
20   - fmt.Println(svconst.AppName + " svlog init success")
21   -
22   -}
common/svmysql/index.go
... ... @@ -1,119 +0,0 @@
1   -package svmysql
2   -
3   -import (
4   - "apigame/common/svconst"
5   - "apigame/service/constd"
6   - "apigame/util/utdto"
7   - "apigame/util/util-lx/lxalilog"
8   - "fmt"
9   - "github.com/astaxie/beego"
10   - "gorm.io/gorm"
11   - "strings"
12   -)
13   -
14   -func Init() bool {
15   -
16   - // ConnectMySQL
17   - if db, err := utdto.ConnectMySQL(beego.AppConfig.String("mysql::" + constd.MYSQL_DBAPI)); err == nil {
18   - svconst.DbApi = db
19   - } else {
20   - fmt.Println("svmysql.Init DbApi Error::" + err.Error())
21   - return false
22   - }
23   - if db, err := utdto.ConnectMySQL(beego.AppConfig.String("mysql::mergecommon")); err == nil {
24   - svconst.DbCommon = db
25   - } else {
26   - fmt.Println("svmysql.Init DbCommon Error::" + err.Error())
27   - return false
28   - }
29   - if db, err := utdto.ConnectMySQL(beego.AppConfig.String("mysql::" + constd.MYSQL_MERGECONFIG)); err == nil {
30   - svconst.DbConfig = db
31   - } else {
32   - fmt.Println("svmysql.Init DbConfig Error::" + err.Error())
33   - return false
34   - }
35   - return true
36   -
37   -}
38   -
39   -func InitTable(obj IMysqlData, gameId string) {
40   - info := obj.MysqlInfo(gameId)
41   - utdto.InitTable(info.DbMysql, obj, info.TableName)
42   -}
43   -
44   -func Insert(obj IMysqlData, gameId string) (err error) {
45   - info := obj.MysqlInfo(gameId)
46   - db := info.DbMysql
47   - stmt := db.Session(&gorm.Session{DryRun: true}).Create(obj).Statement
48   - stmtSQL := stmt.SQL.String()
49   - sql := strings.Replace(stmtSQL, stmt.Table, info.TableName, -1)
50   - result := db.Exec(sql, stmt.Vars...)
51   - err = result.Error
52   - if err != nil {
53   - lxalilog.Errors(err, gameId)
54   - return
55   - }
56   - return
57   -}
58   -
59   -func Updates(obj IMysqlData, gameId string) (err error) {
60   - info := obj.MysqlInfo(gameId)
61   - db := info.DbMysql
62   - stmt := db.Session(&gorm.Session{DryRun: true}).Updates(obj).Statement
63   - stmtSQL := stmt.SQL.String()
64   - sql := strings.Replace(stmtSQL, stmt.Table, info.TableName, -1)
65   - result := db.Exec(sql, stmt.Vars...)
66   - err = result.Error
67   - if err != nil {
68   - lxalilog.Errors(err, gameId)
69   - return
70   - }
71   - return
72   -}
73   -
74   -func Save(obj IMysqlData, gameId string) (err error) {
75   - info := obj.MysqlInfo(gameId)
76   - db := info.DbMysql
77   - stmt := db.Session(&gorm.Session{DryRun: true}).Save(obj).Statement
78   - stmtSQL := stmt.SQL.String()
79   - sql := strings.Replace(stmtSQL, stmt.Table, info.TableName, -1)
80   - result := db.Exec(sql, stmt.Vars...)
81   - err = result.Error
82   - if err != nil {
83   - lxalilog.Errors(err, gameId)
84   - return
85   - }
86   - return
87   -}
88   -
89   -func First(obj IMysqlData, gameId string) (has bool, err error) {
90   - info := obj.MysqlInfo(gameId)
91   - db := info.DbMysql
92   - stmt := db.Session(&gorm.Session{DryRun: true}).First(obj).Statement
93   - stmtSQL := stmt.SQL.String()
94   - sql := strings.Replace(stmtSQL, stmt.Table, info.TableName, -1)
95   - result := db.Raw(sql, stmt.Vars...).Scan(obj)
96   - has = result.RowsAffected != 0
97   - err = result.Error
98   - if err != nil {
99   - lxalilog.Errors(err, gameId)
100   - return
101   - }
102   - return
103   -}
104   -
105   -func Find(obj IMysqlData, gameId string) (has bool, err error) {
106   - info := obj.MysqlInfo(gameId)
107   - db := info.DbMysql
108   - stmt := db.Session(&gorm.Session{DryRun: true}).Find(obj).Statement
109   - stmtSQL := stmt.SQL.String()
110   - sql := strings.Replace(stmtSQL, stmt.Table, info.TableName, -1)
111   - result := db.Raw(sql, stmt.Vars...).Scan(obj)
112   - has = result.RowsAffected != 0
113   - err = result.Error
114   - if err != nil {
115   - lxalilog.Errors(err, gameId)
116   - return
117   - }
118   - return
119   -}
common/svmysql/interface.go
... ... @@ -1,15 +0,0 @@
1   -package svmysql
2   -
3   -import "gorm.io/gorm"
4   -
5   -// MysqlInfo mysql存储信息
6   -type MysqlInfo struct {
7   - DbMysql *gorm.DB
8   - TableName string
9   -}
10   -
11   -// IMysqlData mysql存储对象
12   -type IMysqlData interface {
13   - // MysqlInfo mysql存储信息
14   - MysqlInfo(gameId string) *MysqlInfo
15   -}
common/svredis/index.go
... ... @@ -1,58 +0,0 @@
1   -package svredis
2   -
3   -import (
4   - "apigame/common/svconst"
5   - "apigame/util/utstring"
6   - "apigame/util/zjson"
7   - "apigame/util/zredis"
8   - "fmt"
9   - "github.com/astaxie/beego"
10   - "github.com/mitchellh/mapstructure"
11   -)
12   -
13   -type RedisConfig struct {
14   - Host string `json:"host"`
15   - Port string `json:"port"`
16   - Pwd string `json:"pwd"`
17   - Db string `json:"Db"`
18   - Prefix string `json:"prefix"`
19   -}
20   -
21   -func Init() bool {
22   - //初始化Redis
23   - confText, _ := beego.AppConfig.GetSection("redis")
24   - var conf RedisConfig
25   - err := mapstructure.Decode(confText, &conf)
26   - if err != nil {
27   - fmt.Println("svredis.Init mapstructure.Decode Error::" + err.Error())
28   - }
29   - zredis.Init(conf.Host+":"+conf.Port, conf.Pwd, utstring.StringToInt(conf.Db))
30   - if !zredis.Check() {
31   - return false
32   - }
33   -
34   - fmt.Println(svconst.AppName + " redis init success")
35   - return true
36   -}
37   -
38   -func SaveData(gameId string, obj IRedisData) {
39   - info := obj.RedisInfo(gameId)
40   - _ = zredis.SetEx(zredis.GetConn(), info.CacheKey, zjson.Str(obj), info.CacheTime)
41   -}
42   -
43   -func LoadData[T IRedisData](gameId string, obj T) (has bool) {
44   - has = true
45   - info := obj.RedisInfo(gameId)
46   - text, err := zredis.Get(zredis.GetConn(), info.CacheKey)
47   - if err != nil {
48   - has = false
49   - return
50   - }
51   - err = zjson.Obj(text, &obj)
52   - if err != nil {
53   - fmt.Println(err)
54   - has = false
55   - return
56   - }
57   - return
58   -}
common/svredis/interface.go
... ... @@ -1,13 +0,0 @@
1   -package svredis
2   -
3   -// RedisInfo redis存储信息
4   -type RedisInfo struct {
5   - CacheKey string
6   - CacheTime int
7   -}
8   -
9   -// IRedisData redis存储对象
10   -type IRedisData interface {
11   - // RedisInfo redis存储信息
12   - RedisInfo(gameId string) *RedisInfo
13   -}
common/thinkingdata/index.go
... ... @@ -1,119 +0,0 @@
1   -package thinkingdata
2   -
3   -import (
4   - "crypto/tls"
5   - "encoding/json"
6   - "errors"
7   - "fmt"
8   - "gitee.com/lxgow/lxconv"
9   - "github.com/astaxie/beego"
10   - "github.com/astaxie/beego/httplib"
11   - lconv "github.com/lixu-any/go-tools/conv"
12   - "time"
13   -)
14   -
15   -// index
16   -// 创建时间:2023/10/23 10:06
17   -// 创建人:lixu
18   -
19   -// index 数数科技
20   -// 创建时间:2023/7/18 16:03
21   -// 创建人:lixu
22   -
23   -// GetNowDateTime 当前日期时间
24   -func GetNowDateTime() string {
25   - tim := time.Unix(time.Now().Unix(), 0).Format("2006-01-02 15:04:05")
26   - return fmt.Sprintf("%s", tim)
27   -}
28   -
29   -type MThinkDataConfig struct {
30   - Url string `json:"url"`
31   - Debug int `json:"debug"`
32   -}
33   -
34   -type MRespData struct {
35   - Msg string `json:"Msg"`
36   - Code int `json:"code"`
37   -}
38   -
39   -var THINKINGDATACONFIG MThinkDataConfig
40   -
41   -// InitThinkData 初始化数数
42   -func InitThinkData() (err error) {
43   - thinkingdata, _ := beego.AppConfig.GetSection("thinkingdata")
44   - THINKINGDATACONFIG.Url = thinkingdata["url"]
45   - THINKINGDATACONFIG.Debug = lxconv.ParseInt(thinkingdata["debug"])
46   - return
47   -}
48   -
49   -// AddOneData 数据上报
50   -func AddOneData(appid, account_id, distinct_id string, event string, data map[string]interface{}, typ string) (resp MRespData, err error) {
51   -
52   - _data := map[string]interface{}{
53   - "#type": typ,
54   - //"#event_name": event,
55   - "#time": GetNowDateTime(),
56   - "#account_id": account_id,
57   - "#distinct_id": distinct_id,
58   - "properties": data,
59   - }
60   -
61   - if typ == "track" && event != "" {
62   - _data["#event_name"] = event
63   - }
64   -
65   - postdata := map[string]interface{}{
66   - "appid": appid,
67   - "debug": THINKINGDATACONFIG.Debug,
68   - "data": _data,
69   - }
70   -
71   - req := httplib.Post(THINKINGDATACONFIG.Url + "/sync_json")
72   -
73   - req.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
74   -
75   - _, err = req.JSONBody(&postdata)
76   - if err != nil {
77   - err = errors.New("thinkingdata-AddOneData req.JSONBody() error::" + err.Error() + "::" + lconv.JsonEncode(postdata))
78   - return
79   - }
80   -
81   - var (
82   - bytes []byte
83   - )
84   -
85   - bytes, err = req.Bytes()
86   - if err != nil {
87   - err = errors.New("thinkingdata-AddOneData req.Bytes() error::" + err.Error() + "::" + lconv.JsonEncode(postdata) + "::" + string(bytes))
88   - return
89   - }
90   -
91   - _ = json.Unmarshal(bytes, &resp)
92   -
93   - if resp.Code != 0 {
94   - err = errors.New("thinkingdata-AddOneData resp.Code error:: " + lconv.JsonEncode(postdata) + "::" + string(bytes))
95   - return
96   - }
97   -
98   - return
99   -}
100   -
101   -// TrackOne 向事件表传入一个事件
102   -func TrackOne(appid, account_id string, event string, data map[string]interface{}) (resp MRespData, err error) {
103   - return AddOneData(appid, account_id, "", event, data, "track")
104   -}
105   -
106   -// UserSet 对用户表进行操作,覆盖一个或多个用户属性,如果该属性已有值存在,覆盖先前值
107   -func UserSet(appid, account_id string, data map[string]interface{}) (resp MRespData, err error) {
108   - return AddOneData(appid, account_id, "", "", data, "user_set")
109   -}
110   -
111   -// UserSetOnce 对用户表进行操作,初始化一个或多个用户属性,如果该属性已有值存在,则忽略本次操作
112   -func UserSetOnce(appid, account_id string, data map[string]interface{}) (resp MRespData, err error) {
113   - return AddOneData(appid, account_id, "", "", data, "user_setOnce")
114   -}
115   -
116   -// UserAdd 对用户表进行操作,为一个或多个数值型用户属性做累加计算
117   -func UserAdd(appid, account_id string, data map[string]interface{}) (resp MRespData, err error) {
118   - return AddOneData(appid, account_id, "", "", data, "user_add")
119   -}
configs/feat-api.go
1 1 package configs
2 2  
3 3 import (
4   - "apigame/common/svconst"
5   - "apigame/common/svdto"
6   - "apigame/common/svmysql"
7   - "apigame/common/svredis"
  4 + "apigame/service-common/svconst"
  5 + "apigame/service-common/svmysql"
  6 + "apigame/service-common/svredis"
8 7 "fmt"
9 8 )
10 9  
... ... @@ -20,7 +19,7 @@ type ApiGameConfig struct {
20 19 func (c *ApiGameConfig) RedisInfo(gameId string) *svredis.RedisInfo {
21 20 tableName := "s_game_config"
22 21 return &svredis.RedisInfo{
23   - CacheKey: fmt.Sprintf("%s:%s:%s", svdto.REDIS_CACHEP_REFIX, tableName, gameId),
  22 + CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, gameId),
24 23 CacheTime: 300,
25 24 }
26 25 }
... ...
configs/feat-cardholder.go
1 1 package configs
2 2  
3 3 import (
4   - "apigame/common/svconst"
5   - "apigame/common/svdto"
6   - "apigame/common/svmysql"
7   - "apigame/common/svredis"
8   - "apigame/service/constd"
  4 + "apigame/service-common/svconst"
  5 + "apigame/service-common/svmysql"
  6 + "apigame/service-common/svredis"
9 7 "fmt"
10 8 )
11 9  
... ... @@ -33,9 +31,9 @@ type CardActivityConfig struct {
33 31 }
34 32  
35 33 func (c *CardActivityConfig) RedisInfo(gameId string) *svredis.RedisInfo {
36   - tableName := constd.MYSQL_TABLE_S_CARDHOLDER_CONFIG
  34 + tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_CONFIG
37 35 return &svredis.RedisInfo{
38   - CacheKey: fmt.Sprintf("%s:%s:%s", svdto.REDIS_CACHEP_REFIX, tableName, gameId),
  36 + CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, gameId),
39 37 CacheTime: 300,
40 38 }
41 39 }
... ... @@ -61,7 +59,7 @@ type CardActivityConfigRaw struct {
61 59 }
62 60  
63 61 func (c *CardActivityConfigRaw) MysqlInfo(gameId string) *svmysql.MysqlInfo {
64   - tableName := constd.MYSQL_TABLE_S_CARDHOLDER_CONFIG
  62 + tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_CONFIG
65 63 return &svmysql.MysqlInfo{
66 64 DbMysql: svconst.DbConfig.Where("status = ?", 1),
67 65 TableName: tableName + gameId,
... ...
configs/index.go
... ... @@ -1,14 +0,0 @@
1   -package configs
2   -
3   -import (
4   - "apigame/common/svdto"
5   -)
6   -
7   -// func GetConfigRedis[T svconfig.IDtoData](gameId string) (result *T, has bool) {
8   -// t = new(T)
9   -// var rule = t.GetRule(gameId)
10   -// return
11   -// }
12   -func GetConfigMysql[T svdto.IDtoData](gameId string, t T) (result *T, has bool) {
13   - return
14   -}
configs/registry.go
1 1 package configs
2 2  
3 3 import (
4   - "apigame/common/svmysql"
5   - "apigame/common/svredis"
  4 + "apigame/service-common/svmysql"
  5 + "apigame/service-common/svredis"
6 6 "fmt"
7 7 )
8 8  
... ...
controllers/base.go
... ... @@ -2,7 +2,7 @@ package controllers
2 2  
3 3 import (
4 4 "apigame/middleware/sign"
5   - "apigame/service/constd"
  5 + "apigame/service/code-msg"
6 6 "encoding/json"
7 7 "github.com/astaxie/beego"
8 8 )
... ... @@ -27,7 +27,7 @@ func (c *BaseController) RetRspData(rspData any) {
27 27 // RetRspCodeData 返回封装
28 28 func (c *BaseController) RetRspCodeData(code string, rspData any) {
29 29 resp := make(map[string]any)
30   - resp = constd.CodeMsg(resp, code)
  30 + resp = code_msg.CodeMsg(resp, code)
31 31 resp["data"] = rspData
32 32 c.RetData(resp)
33 33 }
... ... @@ -35,7 +35,7 @@ func (c *BaseController) RetRspCodeData(code string, rspData any) {
35 35 // RetCode 返回错误封装
36 36 func (c *BaseController) RetCode(code string) {
37 37 resp := make(map[string]any)
38   - resp = constd.CodeMsg(resp, code)
  38 + resp = code_msg.CodeMsg(resp, code)
39 39 c.RetData(resp)
40 40 }
41 41  
... ... @@ -48,7 +48,7 @@ func (c *BaseController) GetPostData(postData any) bool {
48 48 if checkLocal() {
49 49 err := json.Unmarshal(req, &postData)
50 50 if err != nil {
51   - c.RetCode(constd.RECODE_PARAMERROR)
  51 + c.RetCode(code_msg.RECODE_PARAMERROR)
52 52 return false
53 53 }
54 54 return true
... ... @@ -58,7 +58,7 @@ func (c *BaseController) GetPostData(postData any) bool {
58 58 code, err := sign.Check(req, &postData, true, true)
59 59 if err != nil {
60 60 resp := make(map[string]interface{})
61   - resp = constd.CodeMsg(resp, code)
  61 + resp = code_msg.CodeMsg(resp, code)
62 62 c.RetData(resp)
63 63 return false
64 64 }
... ...
main.go
1 1 package main
2 2  
3 3 import (
4   - "apigame/common/svconst"
5   - "apigame/common/svlog"
6   - "apigame/common/svmysql"
7   - "apigame/common/svredis"
8 4 "apigame/configs"
9 5 _ "apigame/routers"
  6 + "apigame/service-common/svconst"
  7 + "apigame/service-common/svlog"
  8 + "apigame/service-common/svmysql"
  9 + "apigame/service-common/svredis"
10 10 "apigame/service/cardholder"
11 11 "github.com/astaxie/beego"
12 12 "github.com/astaxie/beego/logs"
... ...
middleware/sign/index.go
... ... @@ -3,7 +3,7 @@ package sign
3 3 import (
4 4 "apigame/configs"
5 5 "apigame/middleware/sdk"
6   - "apigame/service/constd"
  6 + "apigame/service/code-msg"
7 7 "apigame/util/util-lx/lxalilog"
8 8 "apigame/util/util-lx/lxarray"
9 9 "apigame/util/util-lx/lxconv"
... ... @@ -77,7 +77,7 @@ func InitCheck(postdata interface{}, cgg MCheckConfig) (code string, gameconfig
77 77  
78 78 time_stamp = getTimeStamp(tempData["time_stamp"])
79 79 if time_stamp < (nowtime-JG) || time_stamp > (nowtime+JG) {
80   - code = constd.RECODE_REQUESTTIME_ERROR
  80 + code = code_msg.RECODE_REQUESTTIME_ERROR
81 81 err = errors.New(code)
82 82 lxalilog.Errors("RECODE_REQUESTTIME_ERROR error:", string(cgg.Bodys))
83 83 return
... ... @@ -100,7 +100,7 @@ func InitCheck(postdata interface{}, cgg MCheckConfig) (code string, gameconfig
100 100 }
101 101  
102 102 if cgg.CheckUrlGameID && urlGameId == "" {
103   - code = constd.RECODE_PARAMERROR
  103 + code = code_msg.RECODE_PARAMERROR
104 104 err = errors.New(code)
105 105 lxalilog.Errors("urlGameid error:")
106 106 return
... ... @@ -109,21 +109,21 @@ func InitCheck(postdata interface{}, cgg MCheckConfig) (code string, gameconfig
109 109 postGameId, ty = lxlimit.CheckLimit(c)
110 110  
111 111 if cgg.CheckUrlGameID && postGameId != urlGameId {
112   - code = constd.RECODE_PARAMERROR
  112 + code = code_msg.RECODE_PARAMERROR
113 113 err = errors.New(code)
114 114 lxalilog.Errors("urlGameid !=postGameId:", urlGameId, postdata)
115 115 return
116 116 }
117 117  
118 118 if ty != "" {
119   - code = constd.RECODE_REQUESTXIANLIU_ERROR
  119 + code = code_msg.RECODE_REQUESTXIANLIU_ERROR
120 120 err = errors.New(ty)
121 121 return
122 122 }
123 123  
124 124 err = json.Unmarshal(cgg.Bodys, &postdata)
125 125 if err != nil {
126   - code = constd.RECODE_PARAMERROR
  126 + code = code_msg.RECODE_PARAMERROR
127 127 lxalilog.Errors("json.Unmarshal error:", err, string(cgg.Bodys))
128 128 return
129 129 }
... ... @@ -134,13 +134,13 @@ func InitCheck(postdata interface{}, cgg MCheckConfig) (code string, gameconfig
134 134  
135 135 b, err = valid.Valid(postdata)
136 136 if err != nil {
137   - code = constd.RECODE_PARAMERROR
  137 + code = code_msg.RECODE_PARAMERROR
138 138 lxalilog.Errors("valid.Valid error:", err, string(cgg.Bodys), valid.Errors)
139 139 return
140 140 }
141 141  
142 142 if !b {
143   - code = constd.RECODE_PARAMERROR
  143 + code = code_msg.RECODE_PARAMERROR
144 144 err = errors.New(code)
145 145 lxalilog.Errors("valid.Valid error:", err, string(cgg.Bodys), valid.Errors)
146 146 return
... ... @@ -161,7 +161,7 @@ func Check(req []byte, postdata interface{}, checkSign bool, checkToken bool) (c
161 161  
162 162 err = json.Unmarshal(req, &postdata)
163 163 if err != nil {
164   - code = constd.RECODE_PARAMERROR
  164 + code = code_msg.RECODE_PARAMERROR
165 165 lxalilog.Errors("json.Unmarshal error:", err, string(req))
166 166 return
167 167 }
... ... @@ -172,13 +172,13 @@ func Check(req []byte, postdata interface{}, checkSign bool, checkToken bool) (c
172 172  
173 173 b, err = valid.Valid(postdata)
174 174 if err != nil {
175   - code = constd.RECODE_PARAMERROR
  175 + code = code_msg.RECODE_PARAMERROR
176 176 lxalilog.Errors("valid.Valid error:", err, string(req), valid.Errors)
177 177 return
178 178 }
179 179  
180 180 if !b {
181   - code = constd.RECODE_PARAMERROR
  181 + code = code_msg.RECODE_PARAMERROR
182 182 err = errors.New(code)
183 183 lxalilog.Errors("valid.Valid error:", err, string(req), valid.Errors)
184 184 return
... ... @@ -209,13 +209,13 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *conf
209 209  
210 210 err = json.Unmarshal(jsonBody, &newdata)
211 211 if err != nil {
212   - code = constd.RECODE_SIGNERROR
  212 + code = code_msg.RECODE_SIGNERROR
213 213 lxalilog.Errors("json.Unmarshal error:", err)
214 214 return
215 215 }
216 216  
217 217 if newdata["gameid"] == "" || newdata["channel"] == "" || newdata["sign"] == "" || newdata["sign_type"] == "" || newdata["time_stamp"] == "" || newdata["ver"] == "" {
218   - code = constd.RECODE_SIGNERROR
  218 + code = code_msg.RECODE_SIGNERROR
219 219 err = errors.New("签名错误,参数错误" + logstr)
220 220 lxalilog.Errors(err)
221 221 return
... ... @@ -236,7 +236,7 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *conf
236 236 appkey := gameconfig.AppKey
237 237  
238 238 if appkey == "" {
239   - code = constd.RECODE_SIGNERROR
  239 + code = code_msg.RECODE_SIGNERROR
240 240 err = errors.New("签名错误,参数错误" + gameid + "no appkey")
241 241 lxalilog.Errors(err)
242 242 return
... ... @@ -262,7 +262,7 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *conf
262 262 }
263 263  
264 264 if len(fiterkey) > 0 {
265   - code = constd.RECODE_WEIXINAZIFU_ERROR
  265 + code = code_msg.RECODE_WEIXINAZIFU_ERROR
266 266 err = errors.New("fiterkey error" + logstr)
267 267 lxalilog.Errors(err, lxconv.JsonEncode(fiterkey), "data:", lxconv.JsonEncode(newdata))
268 268 return
... ... @@ -282,7 +282,7 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *conf
282 282 md5key := strings.ToLower(lxconv.EncryMD5(valstr))
283 283  
284 284 if md5key != sign {
285   - code = constd.RECODE_SIGNERROR
  285 + code = code_msg.RECODE_SIGNERROR
286 286 err = errors.New(code)
287 287 lxalilog.Errors("sign error,md5key::", md5key, ",sign:", sign, logstr, "data:", lxconv.JsonEncode(newdata))
288 288 return
... ... @@ -291,7 +291,7 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *conf
291 291 if checkToken {
292 292  
293 293 if newdata["uid"] == nil || newdata["token"] == nil {
294   - code = constd.RECODE_PARAMERROR
  294 + code = code_msg.RECODE_PARAMERROR
295 295 err = errors.New(code)
296 296 lxalilog.Errors("no uid or token", "data:", lxconv.JsonEncode(newdata))
297 297 return
... ... @@ -299,7 +299,7 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *conf
299 299  
300 300 err = sdk.CheckSdkToken(gameid, lxconv.ToInt64(newdata["uid"]), lxconv.InterfaceToStr(newdata["token"]))
301 301 if err != nil {
302   - code = constd.RECODE_LOGINCHECK_ERROR
  302 + code = code_msg.RECODE_LOGINCHECK_ERROR
303 303 return
304 304 }
305 305  
... ...
service-common/svconst/consts.go 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +package svconst
  2 +
  3 +const (
  4 + REDIS_CACHEP_REFIX = "apigame" // 缓存前缀
  5 +)
... ...
service-common/svconst/mysql.go 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +package svconst
  2 +
  3 +// mysql
  4 +// 创建时间:2023/4/3 15:28
  5 +// 创建人:lixu
  6 +
  7 +const (
  8 + MYSQL_DEFAULT = "default"
  9 + MYSQL_DBAPI = "api"
  10 + MYSQL_MERGECOMMON = "merge_common"
  11 + MYSQL_MERGECONFIG = "merge_config"
  12 + MYSQL_DEFAULT_QUERY_MAXCOUNT = 100
  13 +
  14 + MYSQL_TABLE_S_CARDHOLDER_CONFIG = "s_card_activity_" // 开卡包活动配置
  15 + MYSQL_TABLE_S_CARDHOLDER_DATA = "s_cardholder_data_" // 开卡包活动数据
  16 + MYSQL_TABLE_S_CARDHOLDER_RECORD_GETNEW = "s_cardholder_record_getnew_" // 开卡包活动日志获得卡包
  17 + MYSQL_TABLE_S_CARDHOLDER_RECORD_OPEN = "s_cardholder_record_open_" // 开卡包活动日志开卡包
  18 + MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM = "s_cardholder_record_rewardalbum_" // 开卡包活动日志领取卡组奖励
  19 + MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND = "s_cardholder_record_rewardround_" // 开卡包活动日志领取轮次奖励
  20 +
  21 +)
... ...
service-common/svconst/vars.go 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +package svconst
  2 +
  3 +import "gorm.io/gorm"
  4 +
  5 +var (
  6 + AppName = ""
  7 +
  8 + DbApi *gorm.DB
  9 + DbCommon *gorm.DB
  10 + DbConfig *gorm.DB
  11 +
  12 + GameListCardHolder = []string{"10149"}
  13 +)
... ...
service-common/svlog/ali-log.go 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +package svlog
  2 +
  3 +import (
  4 + "apigame/util/util-lx/lxalilog"
  5 + "fmt"
  6 + "github.com/astaxie/beego"
  7 + lalilog "github.com/lixu-any/go-tools/ali/log"
  8 +)
  9 +
  10 +func InitAliLog(appName string) {
  11 +
  12 + //初始化阿里云日志
  13 + logm, _ := beego.AppConfig.GetSection("alilog")
  14 + lxalilog.InitAliLog(lxalilog.MapAlilogConfig{
  15 + Endpoint: logm["endpoint"],
  16 + AccessKeyId: logm["accesskeyid"],
  17 + AccessKeySecret: logm["accesskeysecret"],
  18 + Project: logm["project"],
  19 + AppNaame: appName,
  20 + On: logm["on"],
  21 + Debug: logm["debug"],
  22 + TableError: "api_code_merge",
  23 + TableDebug: logm["tabledebug"],
  24 + Env: beego.AppConfig.String("env"),
  25 + })
  26 +
  27 + lalilog.InitAliLog(lalilog.MapAlilogConfig{
  28 + Endpoint: logm["endpoint"],
  29 + AccessKeyId: logm["accesskeyid"],
  30 + AccessKeySecret: logm["accesskeysecret"],
  31 + Project: logm["project"],
  32 + On: logm["on"],
  33 + Debug: logm["debug"],
  34 + TableError: logm["tableerror"],
  35 + TableDebug: logm["tabledebug"],
  36 + Env: beego.AppConfig.String("env"),
  37 + })
  38 +
  39 + fmt.Println(appName + " alilog init success")
  40 +}
... ...
service-common/svlog/log.go 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +package svlog
  2 +
  3 +import (
  4 + "apigame/service-common/svconst"
  5 + "apigame/util/util-lx/lxbeego"
  6 + "fmt"
  7 + "github.com/astaxie/beego"
  8 +)
  9 +
  10 +func Init() {
  11 +
  12 + // 初始化日志文件
  13 + conf, _ := beego.AppConfig.GetSection("log")
  14 + conf["filename"] = conf["path"] + "api.log"
  15 +
  16 + if err := lxbeego.Inits(conf); err != nil {
  17 + fmt.Println("svlog.Inits Error::" + err.Error())
  18 + }
  19 +
  20 + fmt.Println(svconst.AppName + " svlog init success")
  21 +
  22 +}
... ...
service-common/svmysql/dto.go 0 → 100644
... ... @@ -0,0 +1,84 @@
  1 +package svmysql
  2 +
  3 +import (
  4 + "apigame/util/util-lx/lxalilog"
  5 + "gorm.io/gorm"
  6 + "strings"
  7 +)
  8 +
  9 +func Insert(obj IMysqlData, gameId string) (err error) {
  10 + info := obj.MysqlInfo(gameId)
  11 + db := info.DbMysql
  12 + stmt := db.Session(&gorm.Session{DryRun: true}).Create(obj).Statement
  13 + stmtSQL := stmt.SQL.String()
  14 + sql := strings.Replace(stmtSQL, stmt.Table, info.TableName, -1)
  15 + result := db.Exec(sql, stmt.Vars...)
  16 + err = result.Error
  17 + if err != nil {
  18 + lxalilog.Errors(err, gameId)
  19 + return
  20 + }
  21 + return
  22 +}
  23 +
  24 +func Updates(obj IMysqlData, gameId string) (err error) {
  25 + info := obj.MysqlInfo(gameId)
  26 + db := info.DbMysql
  27 + stmt := db.Session(&gorm.Session{DryRun: true}).Updates(obj).Statement
  28 + stmtSQL := stmt.SQL.String()
  29 + sql := strings.Replace(stmtSQL, stmt.Table, info.TableName, -1)
  30 + result := db.Exec(sql, stmt.Vars...)
  31 + err = result.Error
  32 + if err != nil {
  33 + lxalilog.Errors(err, gameId)
  34 + return
  35 + }
  36 + return
  37 +}
  38 +
  39 +func Save(obj IMysqlData, gameId string) (err error) {
  40 + info := obj.MysqlInfo(gameId)
  41 + db := info.DbMysql
  42 + stmt := db.Session(&gorm.Session{DryRun: true}).Save(obj).Statement
  43 + stmtSQL := stmt.SQL.String()
  44 + sql := strings.Replace(stmtSQL, stmt.Table, info.TableName, -1)
  45 + result := db.Exec(sql, stmt.Vars...)
  46 + err = result.Error
  47 + if err != nil {
  48 + lxalilog.Errors(err, gameId)
  49 + return
  50 + }
  51 + return
  52 +}
  53 +
  54 +func First(obj IMysqlData, gameId string) (has bool, err error) {
  55 + info := obj.MysqlInfo(gameId)
  56 + db := info.DbMysql
  57 + stmt := db.Session(&gorm.Session{DryRun: true}).First(obj).Statement
  58 + stmtSQL := stmt.SQL.String()
  59 + sql := strings.Replace(stmtSQL, stmt.Table, info.TableName, -1)
  60 + result := db.Raw(sql, stmt.Vars...).Scan(obj)
  61 + has = result.RowsAffected != 0
  62 + err = result.Error
  63 + if err != nil {
  64 + lxalilog.Errors(err, gameId)
  65 + return
  66 + }
  67 + return
  68 +}
  69 +
  70 +func Find(obj IMysqlData, gameId string) (has bool, err error) {
  71 + info := obj.MysqlInfo(gameId)
  72 + db := info.DbMysql
  73 + stmt := db.Session(&gorm.Session{DryRun: true}).Find(obj).Statement
  74 + stmtSQL := stmt.SQL.String()
  75 + sql := strings.Replace(stmtSQL, stmt.Table, info.TableName, -1)
  76 + result := db.Raw(sql, stmt.Vars...).Scan(obj)
  77 + has = result.RowsAffected != 0
  78 + err = result.Error
  79 + if err != nil {
  80 + lxalilog.Errors(err, gameId)
  81 + return
  82 + }
  83 + return
  84 +}
... ...
service-common/svmysql/index.go 0 → 100644
... ... @@ -0,0 +1,38 @@
  1 +package svmysql
  2 +
  3 +import (
  4 + "apigame/service-common/svconst"
  5 + "fmt"
  6 + "github.com/astaxie/beego"
  7 + "gorm.io/driver/mysql"
  8 + "gorm.io/gorm"
  9 +)
  10 +
  11 +func Init() bool {
  12 +
  13 + // ConnectMySQL
  14 + if db, err := ConnectMySQL(beego.AppConfig.String("mysql::" + svconst.MYSQL_DBAPI)); err == nil {
  15 + svconst.DbApi = db
  16 + } else {
  17 + fmt.Println("svmysql.Init DbApi Error::" + err.Error())
  18 + return false
  19 + }
  20 + if db, err := ConnectMySQL(beego.AppConfig.String("mysql::mergecommon")); err == nil {
  21 + svconst.DbCommon = db
  22 + } else {
  23 + fmt.Println("svmysql.Init DbCommon Error::" + err.Error())
  24 + return false
  25 + }
  26 + if db, err := ConnectMySQL(beego.AppConfig.String("mysql::" + svconst.MYSQL_MERGECONFIG)); err == nil {
  27 + svconst.DbConfig = db
  28 + } else {
  29 + fmt.Println("svmysql.Init DbConfig Error::" + err.Error())
  30 + return false
  31 + }
  32 + return true
  33 +
  34 +}
  35 +
  36 +func ConnectMySQL(dsn string) (db *gorm.DB, err error) {
  37 + return gorm.Open(mysql.Open(dsn), &gorm.Config{})
  38 +}
... ...
service-common/svmysql/interface.go 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +package svmysql
  2 +
  3 +import "gorm.io/gorm"
  4 +
  5 +// MysqlInfo mysql存储信息
  6 +type MysqlInfo struct {
  7 + DbMysql *gorm.DB
  8 + TableName string
  9 +}
  10 +
  11 +// IMysqlData mysql存储对象
  12 +type IMysqlData interface {
  13 + // MysqlInfo mysql存储信息
  14 + MysqlInfo(gameId string) *MysqlInfo
  15 +}
... ...
service-common/svmysql/table.go 0 → 100644
... ... @@ -0,0 +1,135 @@
  1 +package svmysql
  2 +
  3 +import (
  4 + "fmt"
  5 + "gorm.io/driver/mysql"
  6 + "gorm.io/gorm"
  7 + "gorm.io/gorm/clause"
  8 + "gorm.io/gorm/migrator"
  9 + "strings"
  10 +)
  11 +
  12 +func InitTable(obj IMysqlData, gameId string) {
  13 + info := obj.MysqlInfo(gameId)
  14 + db := info.DbMysql
  15 + tableName := info.TableName
  16 + m := db.Migrator().(mysql.Migrator).Migrator
  17 + queryTx, execTx := m.GetQueryAndExecTx()
  18 + if HasTable(queryTx.Migrator().(mysql.Migrator).Migrator, obj, tableName) {
  19 + fmt.Println(tableName + " exist, skip!")
  20 + } else {
  21 + err := CreateTable(execTx, obj, tableName)
  22 + if err != nil {
  23 + fmt.Println("err", err)
  24 + }
  25 + }
  26 +}
  27 +
  28 +func HasTable(m migrator.Migrator, obj any, tableName string) bool {
  29 + var count int64
  30 +
  31 + m.RunWithValue(obj, func(stmt *gorm.Statement) error {
  32 + currentDatabase := m.DB.Migrator().CurrentDatabase()
  33 + return m.DB.Raw("SELECT count(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ? AND table_type = ?", currentDatabase, tableName, "BASE TABLE").Row().Scan(&count)
  34 + })
  35 +
  36 + return count > 0
  37 +}
  38 +
  39 +func CreateTable(execTx *gorm.DB, value any, tableName string) error {
  40 + m := execTx.Migrator().(mysql.Migrator).Migrator
  41 + tx := m.DB.Session(&gorm.Session{})
  42 +
  43 + if err := m.RunWithValue(value, func(stmt *gorm.Statement) (err error) {
  44 + var (
  45 + createTableSQL = "CREATE TABLE ? ("
  46 + values = []interface{}{clause.Table{Name: tableName}}
  47 + hasPrimaryKeyInDataType bool
  48 + )
  49 +
  50 + for _, dbName := range stmt.Schema.DBNames {
  51 + field := stmt.Schema.FieldsByDBName[dbName]
  52 + if !field.IgnoreMigration {
  53 + createTableSQL += "? ?"
  54 + hasPrimaryKeyInDataType = hasPrimaryKeyInDataType || strings.Contains(strings.ToUpper(m.DataTypeOf(field)), "PRIMARY KEY")
  55 + values = append(values, clause.Column{Name: dbName}, m.DB.Migrator().FullDataTypeOf(field))
  56 + createTableSQL += ","
  57 + }
  58 + }
  59 +
  60 + if !hasPrimaryKeyInDataType && len(stmt.Schema.PrimaryFields) > 0 {
  61 + createTableSQL += "PRIMARY KEY ?,"
  62 + primaryKeys := make([]interface{}, 0, len(stmt.Schema.PrimaryFields))
  63 + for _, field := range stmt.Schema.PrimaryFields {
  64 + primaryKeys = append(primaryKeys, clause.Column{Name: field.DBName})
  65 + }
  66 +
  67 + values = append(values, primaryKeys)
  68 + }
  69 +
  70 + for _, idx := range stmt.Schema.ParseIndexes() {
  71 + if m.CreateIndexAfterCreateTable {
  72 + defer func(value interface{}, name string) {
  73 + if err == nil {
  74 + err = tx.Migrator().CreateIndex(value, name)
  75 + }
  76 + }(value, idx.Name)
  77 + } else {
  78 + if idx.Class != "" {
  79 + createTableSQL += idx.Class + " "
  80 + }
  81 + createTableSQL += "INDEX ? ?"
  82 +
  83 + if idx.Comment != "" {
  84 + createTableSQL += fmt.Sprintf(" COMMENT '%s'", idx.Comment)
  85 + }
  86 +
  87 + if idx.Option != "" {
  88 + createTableSQL += " " + idx.Option
  89 + }
  90 +
  91 + createTableSQL += ","
  92 + values = append(values, clause.Column{Name: idx.Name}, tx.Migrator().(migrator.BuildIndexOptionsInterface).BuildIndexOptions(idx.Fields, stmt))
  93 + }
  94 + }
  95 +
  96 + if !m.DB.DisableForeignKeyConstraintWhenMigrating && !m.DB.IgnoreRelationshipsWhenMigrating {
  97 + for _, rel := range stmt.Schema.Relationships.Relations {
  98 + if rel.Field.IgnoreMigration {
  99 + continue
  100 + }
  101 + if constraint := rel.ParseConstraint(); constraint != nil {
  102 + if constraint.Schema == stmt.Schema {
  103 + sql, vars := constraint.Build()
  104 + createTableSQL += sql + ","
  105 + values = append(values, vars...)
  106 + }
  107 + }
  108 + }
  109 + }
  110 +
  111 + for _, uni := range stmt.Schema.ParseUniqueConstraints() {
  112 + createTableSQL += "CONSTRAINT ? UNIQUE (?),"
  113 + values = append(values, clause.Column{Name: uni.Name}, clause.Expr{SQL: stmt.Quote(uni.Field.DBName)})
  114 + }
  115 +
  116 + for _, chk := range stmt.Schema.ParseCheckConstraints() {
  117 + createTableSQL += "CONSTRAINT ? CHECK (?),"
  118 + values = append(values, clause.Column{Name: chk.Name}, clause.Expr{SQL: chk.Constraint})
  119 + }
  120 +
  121 + createTableSQL = strings.TrimSuffix(createTableSQL, ",")
  122 +
  123 + createTableSQL += ")"
  124 +
  125 + if tableOption, ok := m.DB.Get("gorm:table_options"); ok {
  126 + createTableSQL += fmt.Sprint(tableOption)
  127 + }
  128 +
  129 + err = tx.Exec(createTableSQL, values...).Error
  130 + return err
  131 + }); err != nil {
  132 + return err
  133 + }
  134 + return nil
  135 +}
... ...
service-common/svredis/index.go 0 → 100644
... ... @@ -0,0 +1,58 @@
  1 +package svredis
  2 +
  3 +import (
  4 + "apigame/service-common/svconst"
  5 + "apigame/util/utstring"
  6 + "apigame/util/zjson"
  7 + "apigame/util/zredis"
  8 + "fmt"
  9 + "github.com/astaxie/beego"
  10 + "github.com/mitchellh/mapstructure"
  11 +)
  12 +
  13 +type RedisConfig struct {
  14 + Host string `json:"host"`
  15 + Port string `json:"port"`
  16 + Pwd string `json:"pwd"`
  17 + Db string `json:"Db"`
  18 + Prefix string `json:"prefix"`
  19 +}
  20 +
  21 +func Init() bool {
  22 + //初始化Redis
  23 + confText, _ := beego.AppConfig.GetSection("redis")
  24 + var conf RedisConfig
  25 + err := mapstructure.Decode(confText, &conf)
  26 + if err != nil {
  27 + fmt.Println("svredis.Init mapstructure.Decode Error::" + err.Error())
  28 + }
  29 + zredis.Init(conf.Host+":"+conf.Port, conf.Pwd, utstring.StringToInt(conf.Db))
  30 + if !zredis.Check() {
  31 + return false
  32 + }
  33 +
  34 + fmt.Println(svconst.AppName + " redis init success")
  35 + return true
  36 +}
  37 +
  38 +func SaveData(gameId string, obj IRedisData) {
  39 + info := obj.RedisInfo(gameId)
  40 + _ = zredis.SetEx(zredis.GetConn(), info.CacheKey, zjson.Str(obj), info.CacheTime)
  41 +}
  42 +
  43 +func LoadData[T IRedisData](gameId string, obj T) (has bool) {
  44 + has = true
  45 + info := obj.RedisInfo(gameId)
  46 + text, err := zredis.Get(zredis.GetConn(), info.CacheKey)
  47 + if err != nil {
  48 + has = false
  49 + return
  50 + }
  51 + err = zjson.Obj(text, &obj)
  52 + if err != nil {
  53 + fmt.Println(err)
  54 + has = false
  55 + return
  56 + }
  57 + return
  58 +}
... ...
service-common/svredis/interface.go 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +package svredis
  2 +
  3 +// RedisInfo redis存储信息
  4 +type RedisInfo struct {
  5 + CacheKey string
  6 + CacheTime int
  7 +}
  8 +
  9 +// IRedisData redis存储对象
  10 +type IRedisData interface {
  11 + // RedisInfo redis存储信息
  12 + RedisInfo(gameId string) *RedisInfo
  13 +}
... ...
service-common/thinkingdata/index.go 0 → 100644
... ... @@ -0,0 +1,119 @@
  1 +package thinkingdata
  2 +
  3 +import (
  4 + "crypto/tls"
  5 + "encoding/json"
  6 + "errors"
  7 + "fmt"
  8 + "gitee.com/lxgow/lxconv"
  9 + "github.com/astaxie/beego"
  10 + "github.com/astaxie/beego/httplib"
  11 + lconv "github.com/lixu-any/go-tools/conv"
  12 + "time"
  13 +)
  14 +
  15 +// index
  16 +// 创建时间:2023/10/23 10:06
  17 +// 创建人:lixu
  18 +
  19 +// index 数数科技
  20 +// 创建时间:2023/7/18 16:03
  21 +// 创建人:lixu
  22 +
  23 +// GetNowDateTime 当前日期时间
  24 +func GetNowDateTime() string {
  25 + tim := time.Unix(time.Now().Unix(), 0).Format("2006-01-02 15:04:05")
  26 + return fmt.Sprintf("%s", tim)
  27 +}
  28 +
  29 +type MThinkDataConfig struct {
  30 + Url string `json:"url"`
  31 + Debug int `json:"debug"`
  32 +}
  33 +
  34 +type MRespData struct {
  35 + Msg string `json:"Msg"`
  36 + Code int `json:"code"`
  37 +}
  38 +
  39 +var THINKINGDATACONFIG MThinkDataConfig
  40 +
  41 +// InitThinkData 初始化数数
  42 +func InitThinkData() (err error) {
  43 + thinkingdata, _ := beego.AppConfig.GetSection("thinkingdata")
  44 + THINKINGDATACONFIG.Url = thinkingdata["url"]
  45 + THINKINGDATACONFIG.Debug = lxconv.ParseInt(thinkingdata["debug"])
  46 + return
  47 +}
  48 +
  49 +// AddOneData 数据上报
  50 +func AddOneData(appid, account_id, distinct_id string, event string, data map[string]interface{}, typ string) (resp MRespData, err error) {
  51 +
  52 + _data := map[string]interface{}{
  53 + "#type": typ,
  54 + //"#event_name": event,
  55 + "#time": GetNowDateTime(),
  56 + "#account_id": account_id,
  57 + "#distinct_id": distinct_id,
  58 + "properties": data,
  59 + }
  60 +
  61 + if typ == "track" && event != "" {
  62 + _data["#event_name"] = event
  63 + }
  64 +
  65 + postdata := map[string]interface{}{
  66 + "appid": appid,
  67 + "debug": THINKINGDATACONFIG.Debug,
  68 + "data": _data,
  69 + }
  70 +
  71 + req := httplib.Post(THINKINGDATACONFIG.Url + "/sync_json")
  72 +
  73 + req.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
  74 +
  75 + _, err = req.JSONBody(&postdata)
  76 + if err != nil {
  77 + err = errors.New("thinkingdata-AddOneData req.JSONBody() error::" + err.Error() + "::" + lconv.JsonEncode(postdata))
  78 + return
  79 + }
  80 +
  81 + var (
  82 + bytes []byte
  83 + )
  84 +
  85 + bytes, err = req.Bytes()
  86 + if err != nil {
  87 + err = errors.New("thinkingdata-AddOneData req.Bytes() error::" + err.Error() + "::" + lconv.JsonEncode(postdata) + "::" + string(bytes))
  88 + return
  89 + }
  90 +
  91 + _ = json.Unmarshal(bytes, &resp)
  92 +
  93 + if resp.Code != 0 {
  94 + err = errors.New("thinkingdata-AddOneData resp.Code error:: " + lconv.JsonEncode(postdata) + "::" + string(bytes))
  95 + return
  96 + }
  97 +
  98 + return
  99 +}
  100 +
  101 +// TrackOne 向事件表传入一个事件
  102 +func TrackOne(appid, account_id string, event string, data map[string]interface{}) (resp MRespData, err error) {
  103 + return AddOneData(appid, account_id, "", event, data, "track")
  104 +}
  105 +
  106 +// UserSet 对用户表进行操作,覆盖一个或多个用户属性,如果该属性已有值存在,覆盖先前值
  107 +func UserSet(appid, account_id string, data map[string]interface{}) (resp MRespData, err error) {
  108 + return AddOneData(appid, account_id, "", "", data, "user_set")
  109 +}
  110 +
  111 +// UserSetOnce 对用户表进行操作,初始化一个或多个用户属性,如果该属性已有值存在,则忽略本次操作
  112 +func UserSetOnce(appid, account_id string, data map[string]interface{}) (resp MRespData, err error) {
  113 + return AddOneData(appid, account_id, "", "", data, "user_setOnce")
  114 +}
  115 +
  116 +// UserAdd 对用户表进行操作,为一个或多个数值型用户属性做累加计算
  117 +func UserAdd(appid, account_id string, data map[string]interface{}) (resp MRespData, err error) {
  118 + return AddOneData(appid, account_id, "", "", data, "user_add")
  119 +}
... ...
service/cardholder/dto-game.go
1 1 package cardholder
2 2  
3 3 import (
4   - "apigame/common/svconst"
5   - "apigame/common/svmysql"
6   - "apigame/service/constd"
  4 + "apigame/service-common/svconst"
  5 + "apigame/service-common/svmysql"
7 6 "apigame/util/util-lx/lxalilog"
8 7 "apigame/util/util-lx/lxtime"
9 8 "encoding/json"
... ... @@ -20,7 +19,7 @@ type DataCardHolder struct {
20 19 }
21 20  
22 21 func (d *DataCardHolder) MysqlInfo(gameId string) *svmysql.MysqlInfo {
23   - tableName := constd.MYSQL_TABLE_S_CARDHOLDER_DATA
  22 + tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_DATA
24 23 return &svmysql.MysqlInfo{
25 24 DbMysql: svconst.DbCommon,
26 25 TableName: tableName + gameId,
... ...
service/cardholder/dto-record.go
1 1 package cardholder
2 2  
3 3 import (
4   - "apigame/common/svconst"
5   - "apigame/common/svmysql"
6   - "apigame/service/constd"
  4 + "apigame/service-common/svconst"
  5 + "apigame/service-common/svmysql"
7 6 "apigame/util/util-lx/lxtime"
8 7 )
9 8  
... ... @@ -41,7 +40,7 @@ type RecordCardHolderOpen struct {
41 40 }
42 41  
43 42 func (d *RecordCardHolderOpen) MysqlInfo(gameId string) *svmysql.MysqlInfo {
44   - tableName := constd.MYSQL_TABLE_S_CARDHOLDER_RECORD_OPEN
  43 + tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_RECORD_OPEN
45 44 return &svmysql.MysqlInfo{
46 45 DbMysql: svconst.DbCommon,
47 46 TableName: tableName + gameId,
... ... @@ -66,7 +65,7 @@ type RecordCardHolderRewardAlbum struct {
66 65 }
67 66  
68 67 func (d *RecordCardHolderRewardAlbum) MysqlInfo(gameId string) *svmysql.MysqlInfo {
69   - tableName := constd.MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM
  68 + tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM
70 69 return &svmysql.MysqlInfo{
71 70 DbMysql: svconst.DbCommon,
72 71 TableName: tableName + gameId,
... ... @@ -89,7 +88,7 @@ type RecordCardHolderRewardRound struct {
89 88 }
90 89  
91 90 func (d *RecordCardHolderRewardRound) MysqlInfo(gameId string) *svmysql.MysqlInfo {
92   - tableName := constd.MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND
  91 + tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND
93 92 return &svmysql.MysqlInfo{
94 93 DbMysql: svconst.DbCommon,
95 94 TableName: tableName + gameId,
... ...
service/cardholder/handle.go
... ... @@ -3,7 +3,7 @@ package cardholder
3 3 import (
4 4 "apigame/configs"
5 5 "apigame/models"
6   - "apigame/service/constd"
  6 + "apigame/service/code-msg"
7 7 "apigame/util/util-lx/lxalilog"
8 8 "apigame/util/util-lx/lxtime"
9 9 "apigame/util/utslice"
... ... @@ -13,7 +13,7 @@ import (
13 13 // HandleGetConfig 活动配置
14 14 func HandleGetConfig(req *models.ReqCardHolderGetConfig) (code string, rsp models.RspCardHolderGetConfig) {
15 15 rsp = models.RspCardHolderGetConfig{}
16   - code = constd.RECODE_OK
  16 + code = code_msg.RECODE_OK
17 17  
18 18 // 尝试更新配置
19 19 config, _ := configs.GetCardActivityConfig(req.GameID)
... ... @@ -31,19 +31,19 @@ func HandleGetConfig(req *models.ReqCardHolderGetConfig) (code string, rsp model
31 31 // HandleInfo 卡包信息
32 32 func HandleInfo(req *models.ReqCardHolderInfo) (code string, rsp models.RspCardHolderInfo) {
33 33 rsp = models.RspCardHolderInfo{}
34   - code = constd.RECODE_OK
  34 + code = code_msg.RECODE_OK
35 35  
36 36 // 尝试更新配置
37 37 config, hasConfig := configs.GetCardActivityConfig(req.GameID)
38 38 if !hasConfig {
39   - code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
  39 + code = code_msg.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
40 40 return
41 41 }
42 42  
43 43 // 判断预告时间
44 44 sec := lxtime.NowUninx()
45 45 if sec < config.StartTime {
46   - code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
  46 + code = code_msg.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
47 47 return
48 48 }
49 49  
... ... @@ -61,25 +61,25 @@ func HandleOpen(req *models.ReqCardHolderOpen) (code string, rsp models.RspCardH
61 61 NewCards: make([][]int, 0),
62 62 AwardAlbum: make(map[int]string),
63 63 }
64   - code = constd.RECODE_OK
  64 + code = code_msg.RECODE_OK
65 65  
66 66 // 尝试更新配置
67 67 config, hasConfig := configs.GetCardActivityConfig(req.GameID)
68 68 if !hasConfig {
69   - code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
  69 + code = code_msg.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
70 70 return
71 71 }
72 72  
73 73 // 检查活动状态
74 74 code = CheckStatus(config)
75   - if code != constd.RECODE_OK {
  75 + if code != code_msg.RECODE_OK {
76 76 return
77 77 }
78 78 // 检查卡包ID
79 79 for _, idCardholder := range req.Ids {
80 80 _, okCardholder := config.CardholderConfig[strconv.Itoa(idCardholder)]
81 81 if !okCardholder {
82   - code = constd.RECODE_MERGE_CARDHOLDER_CARDHOLDERID_ERROR
  82 + code = code_msg.RECODE_MERGE_CARDHOLDER_CARDHOLDERID_ERROR
83 83 return
84 84 }
85 85 }
... ... @@ -88,7 +88,7 @@ func HandleOpen(req *models.ReqCardHolderOpen) (code string, rsp models.RspCardH
88 88 gameData := LoadData(req.GameID, req.UID, config)
89 89 // 检查游戏数据 轮次等
90 90 code = CheckGameData(gameData, config)
91   - if code != constd.RECODE_OK {
  91 + if code != code_msg.RECODE_OK {
92 92 return
93 93 }
94 94  
... ... @@ -136,24 +136,24 @@ func HandleShopExchange(req *models.ReqStarShopExchange) (code string, rsp model
136 136 NewCards: make([]int, 0),
137 137 AwardAlbum: make(map[int]string),
138 138 }
139   - code = constd.RECODE_OK
  139 + code = code_msg.RECODE_OK
140 140  
141 141 // 尝试更新配置
142 142 config, hasConfig := configs.GetCardActivityConfig(req.GameID)
143 143 if !hasConfig {
144   - code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
  144 + code = code_msg.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
145 145 return
146 146 }
147 147  
148 148 // 检查活动状态
149 149 code = CheckStatus(config)
150   - if code != constd.RECODE_OK {
  150 + if code != code_msg.RECODE_OK {
151 151 return
152 152 }
153 153 // 检查星星商店ID
154 154 confStarShop, okStarShopConfig := config.StarShopConfig[req.Id]
155 155 if !okStarShopConfig {
156   - code = constd.RECODE_MERGE_CARDHOLDER_STARSHOPID_ERROR
  156 + code = code_msg.RECODE_MERGE_CARDHOLDER_STARSHOPID_ERROR
157 157 return
158 158 }
159 159  
... ... @@ -161,39 +161,39 @@ func HandleShopExchange(req *models.ReqStarShopExchange) (code string, rsp model
161 161 gameData := LoadData(req.GameID, req.UID, config)
162 162 // 检查游戏数据 轮次等
163 163 code = CheckGameData(gameData, config)
164   - if code != constd.RECODE_OK {
  164 + if code != code_msg.RECODE_OK {
165 165 return
166 166 }
167 167  
168 168 // 判断星星数是否足够
169 169 if gameData.Details.StarCount < confStarShop.NeedStarNumber {
170   - code = constd.RECODE_MERGE_CARDHOLDER_STAR_NOTENOUGH_ERROR
  170 + code = code_msg.RECODE_MERGE_CARDHOLDER_STAR_NOTENOUGH_ERROR
171 171 return
172 172 }
173 173  
174 174 // 判断配置
175 175 if len(confStarShop.CardBagIds) < 3 {
176 176 lxalilog.Errors("StarShopConfig.CardBagIds error", confStarShop.Id)
177   - code = constd.RECODE_MERGE_CONFIG_ERROR
  177 + code = code_msg.RECODE_MERGE_CONFIG_ERROR
178 178 return
179 179 }
180 180 cardholderId := confStarShop.CardBagIds[1]
181 181 cardholderCount := confStarShop.CardBagIds[2]
182 182 if cardholderCount < 1 {
183 183 lxalilog.Errors("StarShopConfig.CardBagIds error", confStarShop.Id)
184   - code = constd.RECODE_MERGE_CONFIG_ERROR
  184 + code = code_msg.RECODE_MERGE_CONFIG_ERROR
185 185 return
186 186 }
187 187 confCardholder, okCardholder := config.CardholderConfig[strconv.Itoa(cardholderId)]
188 188 if !okCardholder {
189   - code = constd.RECODE_MERGE_CONFIG_ERROR
  189 + code = code_msg.RECODE_MERGE_CONFIG_ERROR
190 190 return
191 191 }
192 192  
193 193 // 按照规则扣除星星
194 194 enough, cardList := GetStarCardList(gameData, config, confStarShop.NeedStarNumber)
195 195 if !enough {
196   - code = constd.RECODE_MERGE_CARDHOLDER_STAR_NOTENOUGH_ERROR
  196 + code = code_msg.RECODE_MERGE_CARDHOLDER_STAR_NOTENOUGH_ERROR
197 197 return
198 198 }
199 199 for i, i2 := range cardList {
... ... @@ -242,18 +242,18 @@ func HandleAutoExchangeInfo(req *models.ReqAutoExchangeInfo) (code string, rsp m
242 242 AwardAlbum: make(map[int]string),
243 243 AutoExchangeHolder: make([]int, 0),
244 244 }
245   - code = constd.RECODE_OK
  245 + code = code_msg.RECODE_OK
246 246  
247 247 // 尝试更新配置
248 248 config, hasConfig := configs.GetCardActivityConfig(req.GameID)
249 249 if !hasConfig {
250   - code = constd.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
  250 + code = code_msg.RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR
251 251 return
252 252 }
253 253  
254 254 // 检查活动状态
255 255 code = CheckStatus(config)
256   - if code != constd.RECODE_OK {
  256 + if code != code_msg.RECODE_OK {
257 257 return
258 258 }
259 259  
... ... @@ -261,12 +261,12 @@ func HandleAutoExchangeInfo(req *models.ReqAutoExchangeInfo) (code string, rsp m
261 261 gameData := LoadData(req.GameID, req.UID, config)
262 262 // 检查游戏数据 轮次等
263 263 code = CheckGameData(gameData, config)
264   - if code != constd.RECODE_OK {
  264 + if code != code_msg.RECODE_OK {
265 265 return
266 266 }
267 267  
268 268 if gameData.Details.LastStarCount <= 0 {
269   - code = constd.RECODE_MERGE_CARDHOLDER_NOAUTOEXCHANGEINFO_ERROR
  269 + code = code_msg.RECODE_MERGE_CARDHOLDER_NOAUTOEXCHANGEINFO_ERROR
270 270 return
271 271 }
272 272  
... ...
service/cardholder/init.go
1 1 package cardholder
2 2  
3 3 import (
4   - "apigame/common/svconst"
5   - "apigame/common/svmysql"
  4 + "apigame/service-common/svconst"
  5 + "apigame/service-common/svmysql"
6 6 )
7 7  
8 8 func Init() {
... ...
service/cardholder/logic.go
1 1 package cardholder
2 2  
3 3 import (
4   - "apigame/common/svmysql"
5 4 "apigame/configs"
6 5 "apigame/models"
7   - "apigame/service/constd"
  6 + "apigame/service-common/svmysql"
  7 + "apigame/service/code-msg"
8 8 "apigame/util/util-lx/lxalilog"
9 9 "apigame/util/util-lx/lxtime"
10 10 "apigame/util/utjson"
... ... @@ -65,23 +65,23 @@ func LoadData(gameId string, uid int64, config *configs.CardActivityConfig) (d *
65 65 func CheckStatus(conf *configs.CardActivityConfig) string {
66 66 sec := lxtime.NowUninx()
67 67 if conf.Id == 0 {
68   - return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR
  68 + return code_msg.RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR
69 69 }
70 70 if sec < conf.StartTime {
71   - return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR
  71 + return code_msg.RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR
72 72 }
73 73 if sec > conf.EndTime {
74   - return constd.RECODE_MERGE_CARDHOLDER_NOTOPEN2_ERROR
  74 + return code_msg.RECODE_MERGE_CARDHOLDER_NOTOPEN2_ERROR
75 75 }
76   - return constd.RECODE_OK
  76 + return code_msg.RECODE_OK
77 77 }
78 78  
79 79 // CheckGameData 检查游戏数据 轮次等
80 80 func CheckGameData(d *DataCardHolder, conf *configs.CardActivityConfig) string {
81 81 if d.Details.Round > conf.Round {
82   - return constd.RECODE_MERGE_CARDHOLDER_ROUNDFINISH_ERROR
  82 + return code_msg.RECODE_MERGE_CARDHOLDER_ROUNDFINISH_ERROR
83 83 }
84   - return constd.RECODE_OK
  84 + return code_msg.RECODE_OK
85 85 }
86 86  
87 87 // GetUserSequenceIdAndCohort 获取 用户序列组ID(sequenceId) 用户分组(cohort)
... ...
service/code-msg/code-msg.go 0 → 100644
... ... @@ -0,0 +1,121 @@
  1 +package code_msg
  2 +
  3 +import (
  4 + "apigame/util/util-lx/lxalilog"
  5 + "apigame/util/util-lx/lxtime"
  6 +)
  7 +
  8 +const (
  9 + RECODE_OK = "0"
  10 + RECODE_FALIED = "1000"
  11 + RECODE_UNKNOWERR = "1001"
  12 + RECODE_PARAMERROR = "1002"
  13 + RECODE_SIGNERROR = "1003"
  14 + RECODE_DATA_BUCUNZIA_ERROR = "1004"
  15 + RECODE_PARAMDECODE_ERROR = "1005"
  16 + RECODE_DATANOEXIST_ERROR = "1006"
  17 + RECODE_CREATEUID_ERROR = "1007"
  18 + RECODE_LOGINCHECK_ERROR = "1008"
  19 + RECODE_WEIXINAZIFU_ERROR = "1009"
  20 + RECODE_SDKMEMBER_ERROR = "1010"
  21 + RECODE_CAOZUOPINFAN_ERROR = "1011"
  22 + RECODE_REQUESTXIANLIU_ERROR = "1110"
  23 + RECODE_REQUESTTIME_ERROR = "1111"
  24 +
  25 + RECODE_MERGE_CONFIG_ERROR = "2000"
  26 + RECODE_MERGE_CFLQ_ERROR = "2001"
  27 + RECODE_MERGE_AZSXLQ_ERROR = "2002"
  28 + RECODE_MERGE_QXGMSP_ERROR = "2003"
  29 + RECODE_MERGE_MEMBERSHIP_QXCZZK_ERROR = "2010"
  30 + RECODE_MERGE_MEMBERSHIP_QXCZYK_ERROR = "2011"
  31 + RECODE_MERGE_MEMBERSHIP_QXCZ_ERROR = "2012"
  32 + RECODE_MERGE_MEMBERSHIP_BNCFLQ_ERROR = "2013"
  33 +
  34 + RECODE_MERGE_NOVICE_QXCZ_ERROR = "2021"
  35 + RECODE_MERGE_NOVICE_BNCFLQ_ERROR = "2032"
  36 + RECODE_MERGE_NOVICE_MYDDLQTJ_ERROR = "2033"
  37 + RECODE_MERGE_HUODONGWEIKAISHI_ERROR = "2040"
  38 + RECODE_MERGE_HUODONGYIJIESHU_ERROR = "2041"
  39 + RECODE_MERGE_CCZDXX_ERROR = "2042"
  40 + RECODE_MERGE_TONGXINGZHENGBUCUNZAI_ERROR = "2051"
  41 + RECODE_MERGE_QINGXIANGMTXZ_ERROR = "2052"
  42 +
  43 + RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR = "2100"
  44 + RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR = "2101"
  45 + RECODE_MERGE_CARDHOLDER_NOTOPEN2_ERROR = "2102"
  46 + RECODE_MERGE_CARDHOLDER_ROUNDFINISH_ERROR = "2103"
  47 + RECODE_MERGE_CARDHOLDER_CARDHOLDERID_ERROR = "2104"
  48 + RECODE_MERGE_CARDHOLDER_STARSHOPID_ERROR = "2105"
  49 + RECODE_MERGE_CARDHOLDER_STAR_NOTENOUGH_ERROR = "2106"
  50 + RECODE_MERGE_CARDHOLDER_NOAUTOEXCHANGEINFO_ERROR = "2107"
  51 +)
  52 +
  53 +var recodeText = map[string]string{
  54 + RECODE_OK: "成功",
  55 + RECODE_FALIED: "操作失败",
  56 + RECODE_UNKNOWERR: "未知错误",
  57 + RECODE_PARAMERROR: "参数错误",
  58 + RECODE_SIGNERROR: "签名错误",
  59 + RECODE_DATA_BUCUNZIA_ERROR: "数据不存在",
  60 + RECODE_PARAMDECODE_ERROR: "解析参数失败,请检查参数合法性",
  61 + RECODE_DATANOEXIST_ERROR: "数据不存在",
  62 + RECODE_CREATEUID_ERROR: "创建用户UID失败",
  63 + RECODE_LOGINCHECK_ERROR: "登录验证失败,请重新登录",
  64 + RECODE_WEIXINAZIFU_ERROR: "参数存在危险字符",
  65 + RECODE_SDKMEMBER_ERROR: "获取SDK用户信息失败",
  66 + RECODE_CAOZUOPINFAN_ERROR: "操作频繁",
  67 + RECODE_REQUESTXIANLIU_ERROR: "操作被限流",
  68 + RECODE_REQUESTTIME_ERROR: "time errors",
  69 +
  70 + RECODE_MERGE_CONFIG_ERROR: "获取配置文件错误",
  71 + RECODE_MERGE_CFLQ_ERROR: "不能重复领取",
  72 + RECODE_MERGE_AZSXLQ_ERROR: "请按照顺序领取",
  73 + RECODE_MERGE_QXGMSP_ERROR: "请先购买对应商品",
  74 +
  75 + RECODE_MERGE_MEMBERSHIP_QXCZZK_ERROR: "请先购买周卡",
  76 + RECODE_MERGE_MEMBERSHIP_QXCZYK_ERROR: "请先购买月卡",
  77 + RECODE_MERGE_MEMBERSHIP_QXCZ_ERROR: "请先购买对应商品",
  78 + RECODE_MERGE_MEMBERSHIP_BNCFLQ_ERROR: "不能重复领取",
  79 +
  80 + RECODE_MERGE_NOVICE_QXCZ_ERROR: "请先购买对应商品",
  81 + RECODE_MERGE_NOVICE_BNCFLQ_ERROR: "不能重复领取",
  82 + RECODE_MERGE_NOVICE_MYDDLQTJ_ERROR: "没有达到领取条件",
  83 +
  84 + RECODE_MERGE_HUODONGWEIKAISHI_ERROR: "活动未开始",
  85 + RECODE_MERGE_HUODONGYIJIESHU_ERROR: "活动已结束",
  86 + RECODE_MERGE_CCZDXX_ERROR: "超出最大限制",
  87 +
  88 + RECODE_MERGE_TONGXINGZHENGBUCUNZAI_ERROR: "通行证不存在",
  89 + RECODE_MERGE_QINGXIANGMTXZ_ERROR: "请先购买通行证",
  90 +
  91 + RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR: "活动未开放",
  92 + RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR: "活动未开始",
  93 + RECODE_MERGE_CARDHOLDER_NOTOPEN2_ERROR: "活动已结束",
  94 + RECODE_MERGE_CARDHOLDER_ROUNDFINISH_ERROR: "活动轮次已全部完成",
  95 + RECODE_MERGE_CARDHOLDER_CARDHOLDERID_ERROR: "卡包ID错误",
  96 + RECODE_MERGE_CARDHOLDER_STARSHOPID_ERROR: "商店ID错误",
  97 + RECODE_MERGE_CARDHOLDER_STAR_NOTENOUGH_ERROR: "星星商店星星不足",
  98 + RECODE_MERGE_CARDHOLDER_NOAUTOEXCHANGEINFO_ERROR: "没有星星商店自动兑换信息",
  99 +}
  100 +
  101 +func RecodeText(code string) string {
  102 + str, ok := recodeText[code]
  103 + if ok {
  104 + return str
  105 + }
  106 + return RecodeText(RECODE_UNKNOWERR)
  107 +}
  108 +
  109 +func CodeMsg(data map[string]interface{}, code interface{}) map[string]interface{} {
  110 + data["code"] = code
  111 + data["msg"] = RecodeText(code.(string))
  112 + lxtime.NowUninx()
  113 + data["servertime"] = lxtime.NowUninx()
  114 + return data
  115 +}
  116 +
  117 +func CodeMsgLog(data map[string]interface{}, code interface{}, log ...interface{}) map[string]interface{} {
  118 + // 写入日志
  119 + lxalilog.ErrorCode(code, log)
  120 + return CodeMsg(data, code)
  121 +}
... ...
service/constd/code-msg.go
... ... @@ -1,121 +0,0 @@
1   -package constd
2   -
3   -import (
4   - "apigame/util/util-lx/lxalilog"
5   - "apigame/util/util-lx/lxtime"
6   -)
7   -
8   -const (
9   - RECODE_OK = "0"
10   - RECODE_FALIED = "1000"
11   - RECODE_UNKNOWERR = "1001"
12   - RECODE_PARAMERROR = "1002"
13   - RECODE_SIGNERROR = "1003"
14   - RECODE_DATA_BUCUNZIA_ERROR = "1004"
15   - RECODE_PARAMDECODE_ERROR = "1005"
16   - RECODE_DATANOEXIST_ERROR = "1006"
17   - RECODE_CREATEUID_ERROR = "1007"
18   - RECODE_LOGINCHECK_ERROR = "1008"
19   - RECODE_WEIXINAZIFU_ERROR = "1009"
20   - RECODE_SDKMEMBER_ERROR = "1010"
21   - RECODE_CAOZUOPINFAN_ERROR = "1011"
22   - RECODE_REQUESTXIANLIU_ERROR = "1110"
23   - RECODE_REQUESTTIME_ERROR = "1111"
24   -
25   - RECODE_MERGE_CONFIG_ERROR = "2000"
26   - RECODE_MERGE_CFLQ_ERROR = "2001"
27   - RECODE_MERGE_AZSXLQ_ERROR = "2002"
28   - RECODE_MERGE_QXGMSP_ERROR = "2003"
29   - RECODE_MERGE_MEMBERSHIP_QXCZZK_ERROR = "2010"
30   - RECODE_MERGE_MEMBERSHIP_QXCZYK_ERROR = "2011"
31   - RECODE_MERGE_MEMBERSHIP_QXCZ_ERROR = "2012"
32   - RECODE_MERGE_MEMBERSHIP_BNCFLQ_ERROR = "2013"
33   -
34   - RECODE_MERGE_NOVICE_QXCZ_ERROR = "2021"
35   - RECODE_MERGE_NOVICE_BNCFLQ_ERROR = "2032"
36   - RECODE_MERGE_NOVICE_MYDDLQTJ_ERROR = "2033"
37   - RECODE_MERGE_HUODONGWEIKAISHI_ERROR = "2040"
38   - RECODE_MERGE_HUODONGYIJIESHU_ERROR = "2041"
39   - RECODE_MERGE_CCZDXX_ERROR = "2042"
40   - RECODE_MERGE_TONGXINGZHENGBUCUNZAI_ERROR = "2051"
41   - RECODE_MERGE_QINGXIANGMTXZ_ERROR = "2052"
42   -
43   - RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR = "2100"
44   - RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR = "2101"
45   - RECODE_MERGE_CARDHOLDER_NOTOPEN2_ERROR = "2102"
46   - RECODE_MERGE_CARDHOLDER_ROUNDFINISH_ERROR = "2103"
47   - RECODE_MERGE_CARDHOLDER_CARDHOLDERID_ERROR = "2104"
48   - RECODE_MERGE_CARDHOLDER_STARSHOPID_ERROR = "2105"
49   - RECODE_MERGE_CARDHOLDER_STAR_NOTENOUGH_ERROR = "2106"
50   - RECODE_MERGE_CARDHOLDER_NOAUTOEXCHANGEINFO_ERROR = "2107"
51   -)
52   -
53   -var recodeText = map[string]string{
54   - RECODE_OK: "成功",
55   - RECODE_FALIED: "操作失败",
56   - RECODE_UNKNOWERR: "未知错误",
57   - RECODE_PARAMERROR: "参数错误",
58   - RECODE_SIGNERROR: "签名错误",
59   - RECODE_DATA_BUCUNZIA_ERROR: "数据不存在",
60   - RECODE_PARAMDECODE_ERROR: "解析参数失败,请检查参数合法性",
61   - RECODE_DATANOEXIST_ERROR: "数据不存在",
62   - RECODE_CREATEUID_ERROR: "创建用户UID失败",
63   - RECODE_LOGINCHECK_ERROR: "登录验证失败,请重新登录",
64   - RECODE_WEIXINAZIFU_ERROR: "参数存在危险字符",
65   - RECODE_SDKMEMBER_ERROR: "获取SDK用户信息失败",
66   - RECODE_CAOZUOPINFAN_ERROR: "操作频繁",
67   - RECODE_REQUESTXIANLIU_ERROR: "操作被限流",
68   - RECODE_REQUESTTIME_ERROR: "time errors",
69   -
70   - RECODE_MERGE_CONFIG_ERROR: "获取配置文件错误",
71   - RECODE_MERGE_CFLQ_ERROR: "不能重复领取",
72   - RECODE_MERGE_AZSXLQ_ERROR: "请按照顺序领取",
73   - RECODE_MERGE_QXGMSP_ERROR: "请先购买对应商品",
74   -
75   - RECODE_MERGE_MEMBERSHIP_QXCZZK_ERROR: "请先购买周卡",
76   - RECODE_MERGE_MEMBERSHIP_QXCZYK_ERROR: "请先购买月卡",
77   - RECODE_MERGE_MEMBERSHIP_QXCZ_ERROR: "请先购买对应商品",
78   - RECODE_MERGE_MEMBERSHIP_BNCFLQ_ERROR: "不能重复领取",
79   -
80   - RECODE_MERGE_NOVICE_QXCZ_ERROR: "请先购买对应商品",
81   - RECODE_MERGE_NOVICE_BNCFLQ_ERROR: "不能重复领取",
82   - RECODE_MERGE_NOVICE_MYDDLQTJ_ERROR: "没有达到领取条件",
83   -
84   - RECODE_MERGE_HUODONGWEIKAISHI_ERROR: "活动未开始",
85   - RECODE_MERGE_HUODONGYIJIESHU_ERROR: "活动已结束",
86   - RECODE_MERGE_CCZDXX_ERROR: "超出最大限制",
87   -
88   - RECODE_MERGE_TONGXINGZHENGBUCUNZAI_ERROR: "通行证不存在",
89   - RECODE_MERGE_QINGXIANGMTXZ_ERROR: "请先购买通行证",
90   -
91   - RECODE_MERGE_CARDHOLDER_NOTOPEN_ERROR: "活动未开放",
92   - RECODE_MERGE_CARDHOLDER_NOTOPEN1_ERROR: "活动未开始",
93   - RECODE_MERGE_CARDHOLDER_NOTOPEN2_ERROR: "活动已结束",
94   - RECODE_MERGE_CARDHOLDER_ROUNDFINISH_ERROR: "活动轮次已全部完成",
95   - RECODE_MERGE_CARDHOLDER_CARDHOLDERID_ERROR: "卡包ID错误",
96   - RECODE_MERGE_CARDHOLDER_STARSHOPID_ERROR: "商店ID错误",
97   - RECODE_MERGE_CARDHOLDER_STAR_NOTENOUGH_ERROR: "星星商店星星不足",
98   - RECODE_MERGE_CARDHOLDER_NOAUTOEXCHANGEINFO_ERROR: "没有星星商店自动兑换信息",
99   -}
100   -
101   -func RecodeText(code string) string {
102   - str, ok := recodeText[code]
103   - if ok {
104   - return str
105   - }
106   - return RecodeText(RECODE_UNKNOWERR)
107   -}
108   -
109   -func CodeMsg(data map[string]interface{}, code interface{}) map[string]interface{} {
110   - data["code"] = code
111   - data["msg"] = RecodeText(code.(string))
112   - lxtime.NowUninx()
113   - data["servertime"] = lxtime.NowUninx()
114   - return data
115   -}
116   -
117   -func CodeMsgLog(data map[string]interface{}, code interface{}, log ...interface{}) map[string]interface{} {
118   - // 写入日志
119   - lxalilog.ErrorCode(code, log)
120   - return CodeMsg(data, code)
121   -}
service/constd/mysql.go
... ... @@ -1,21 +0,0 @@
1   -package constd
2   -
3   -// mysql
4   -// 创建时间:2023/4/3 15:28
5   -// 创建人:lixu
6   -
7   -const (
8   - MYSQL_DEFAULT = "default"
9   - MYSQL_DBAPI = "api"
10   - MYSQL_MERGECOMMON = "merge_common"
11   - MYSQL_MERGECONFIG = "merge_config"
12   - MYSQL_DEFAULT_QUERY_MAXCOUNT = 100
13   -
14   - MYSQL_TABLE_S_CARDHOLDER_CONFIG = "s_card_activity_" // 开卡包活动配置
15   - MYSQL_TABLE_S_CARDHOLDER_DATA = "s_cardholder_data_" // 开卡包活动数据
16   - MYSQL_TABLE_S_CARDHOLDER_RECORD_GETNEW = "s_cardholder_record_getnew_" // 开卡包活动日志获得卡包
17   - MYSQL_TABLE_S_CARDHOLDER_RECORD_OPEN = "s_cardholder_record_open_" // 开卡包活动日志开卡包
18   - MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDALBUM = "s_cardholder_record_rewardalbum_" // 开卡包活动日志领取卡组奖励
19   - MYSQL_TABLE_S_CARDHOLDER_RECORD_REWARDROUND = "s_cardholder_record_rewardround_" // 开卡包活动日志领取轮次奖励
20   -
21   -)
util/utdto/base.go
... ... @@ -1,44 +0,0 @@
1   -package utdto
2   -
3   -import (
4   - "gorm.io/gorm"
5   - "strings"
6   -)
7   -
8   -// Insert 插入
9   -func Insert(db *gorm.DB, value any, tableName string) *gorm.DB {
10   - stmt := db.Session(&gorm.Session{DryRun: true}).Create(value).Statement
11   - stmtSQL := stmt.SQL.String()
12   - sql := strings.Replace(stmtSQL, MYSQL_TABLE_TEMPLATE, tableName, -1)
13   - return db.Exec(sql, stmt.Vars...)
14   -}
15   -
16   -// Update 更新
17   -func Update(db *gorm.DB, value any, tableName string) *gorm.DB {
18   - stmt := db.Session(&gorm.Session{DryRun: true}).Updates(value).Statement
19   - stmtSQL := stmt.SQL.String()
20   - sql := strings.Replace(stmtSQL, MYSQL_TABLE_TEMPLATE, tableName, -1)
21   - return db.Exec(sql, stmt.Vars...)
22   -}
23   -
24   -// Save 保存
25   -func Save(db *gorm.DB, value any, tableName string) *gorm.DB {
26   - stmt := db.Session(&gorm.Session{DryRun: true}).Save(value).Statement
27   - stmtSQL := stmt.SQL.String()
28   - sql := strings.Replace(stmtSQL, MYSQL_TABLE_TEMPLATE, tableName, -1)
29   - return db.Exec(sql, stmt.Vars...)
30   -}
31   -
32   -func First(db *gorm.DB, value any, tableName string) *gorm.DB {
33   - stmt := db.Session(&gorm.Session{DryRun: true}).First(value).Statement
34   - stmtSQL := stmt.SQL.String()
35   - sql := strings.Replace(stmtSQL, MYSQL_TABLE_TEMPLATE, tableName, -1)
36   - return db.Raw(sql, stmt.Vars...).Scan(value)
37   -}
38   -
39   -func Find(db *gorm.DB, value any, tableName string) *gorm.DB {
40   - stmt := db.Session(&gorm.Session{DryRun: true}).Find(value).Statement
41   - stmtSQL := stmt.SQL.String()
42   - sql := strings.Replace(stmtSQL, MYSQL_TABLE_TEMPLATE, tableName, -1)
43   - return db.Raw(sql, stmt.Vars...).Scan(value)
44   -}
util/utdto/mysql.go
... ... @@ -1,12 +0,0 @@
1   -package utdto
2   -
3   -import (
4   - "gorm.io/driver/mysql"
5   - "gorm.io/gorm"
6   -)
7   -
8   -const MYSQL_TABLE_TEMPLATE = "all_table_template" // 表名模板
9   -
10   -func ConnectMySQL(dsn string) (db *gorm.DB, err error) {
11   - return gorm.Open(mysql.Open(dsn), &gorm.Config{})
12   -}
util/utdto/table.go
... ... @@ -1,132 +0,0 @@
1   -package utdto
2   -
3   -import (
4   - "fmt"
5   - "gorm.io/driver/mysql"
6   - "gorm.io/gorm"
7   - "gorm.io/gorm/clause"
8   - "gorm.io/gorm/migrator"
9   - "strings"
10   -)
11   -
12   -func InitTable(db *gorm.DB, value any, tableName string) {
13   - m := db.Migrator().(mysql.Migrator).Migrator
14   - queryTx, execTx := m.GetQueryAndExecTx()
15   - if HasTable(queryTx.Migrator().(mysql.Migrator).Migrator, value, tableName) {
16   - fmt.Println(tableName + " exist, skip!")
17   - } else {
18   - err := CreateTable(execTx, value, tableName)
19   - if err != nil {
20   - fmt.Println("err", err)
21   - }
22   - }
23   -}
24   -
25   -func HasTable(m migrator.Migrator, value interface{}, tableName string) bool {
26   - var count int64
27   -
28   - m.RunWithValue(value, func(stmt *gorm.Statement) error {
29   - currentDatabase := m.DB.Migrator().CurrentDatabase()
30   - return m.DB.Raw("SELECT count(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ? AND table_type = ?", currentDatabase, tableName, "BASE TABLE").Row().Scan(&count)
31   - })
32   -
33   - return count > 0
34   -}
35   -
36   -func CreateTable(execTx *gorm.DB, value any, tableName string) error {
37   - m := execTx.Migrator().(mysql.Migrator).Migrator
38   - tx := m.DB.Session(&gorm.Session{})
39   -
40   - if err := m.RunWithValue(value, func(stmt *gorm.Statement) (err error) {
41   - var (
42   - createTableSQL = "CREATE TABLE ? ("
43   - values = []interface{}{clause.Table{Name: tableName}}
44   - hasPrimaryKeyInDataType bool
45   - )
46   -
47   - for _, dbName := range stmt.Schema.DBNames {
48   - field := stmt.Schema.FieldsByDBName[dbName]
49   - if !field.IgnoreMigration {
50   - createTableSQL += "? ?"
51   - hasPrimaryKeyInDataType = hasPrimaryKeyInDataType || strings.Contains(strings.ToUpper(m.DataTypeOf(field)), "PRIMARY KEY")
52   - values = append(values, clause.Column{Name: dbName}, m.DB.Migrator().FullDataTypeOf(field))
53   - createTableSQL += ","
54   - }
55   - }
56   -
57   - if !hasPrimaryKeyInDataType && len(stmt.Schema.PrimaryFields) > 0 {
58   - createTableSQL += "PRIMARY KEY ?,"
59   - primaryKeys := make([]interface{}, 0, len(stmt.Schema.PrimaryFields))
60   - for _, field := range stmt.Schema.PrimaryFields {
61   - primaryKeys = append(primaryKeys, clause.Column{Name: field.DBName})
62   - }
63   -
64   - values = append(values, primaryKeys)
65   - }
66   -
67   - for _, idx := range stmt.Schema.ParseIndexes() {
68   - if m.CreateIndexAfterCreateTable {
69   - defer func(value interface{}, name string) {
70   - if err == nil {
71   - err = tx.Migrator().CreateIndex(value, name)
72   - }
73   - }(value, idx.Name)
74   - } else {
75   - if idx.Class != "" {
76   - createTableSQL += idx.Class + " "
77   - }
78   - createTableSQL += "INDEX ? ?"
79   -
80   - if idx.Comment != "" {
81   - createTableSQL += fmt.Sprintf(" COMMENT '%s'", idx.Comment)
82   - }
83   -
84   - if idx.Option != "" {
85   - createTableSQL += " " + idx.Option
86   - }
87   -
88   - createTableSQL += ","
89   - values = append(values, clause.Column{Name: idx.Name}, tx.Migrator().(migrator.BuildIndexOptionsInterface).BuildIndexOptions(idx.Fields, stmt))
90   - }
91   - }
92   -
93   - if !m.DB.DisableForeignKeyConstraintWhenMigrating && !m.DB.IgnoreRelationshipsWhenMigrating {
94   - for _, rel := range stmt.Schema.Relationships.Relations {
95   - if rel.Field.IgnoreMigration {
96   - continue
97   - }
98   - if constraint := rel.ParseConstraint(); constraint != nil {
99   - if constraint.Schema == stmt.Schema {
100   - sql, vars := constraint.Build()
101   - createTableSQL += sql + ","
102   - values = append(values, vars...)
103   - }
104   - }
105   - }
106   - }
107   -
108   - for _, uni := range stmt.Schema.ParseUniqueConstraints() {
109   - createTableSQL += "CONSTRAINT ? UNIQUE (?),"
110   - values = append(values, clause.Column{Name: uni.Name}, clause.Expr{SQL: stmt.Quote(uni.Field.DBName)})
111   - }
112   -
113   - for _, chk := range stmt.Schema.ParseCheckConstraints() {
114   - createTableSQL += "CONSTRAINT ? CHECK (?),"
115   - values = append(values, clause.Column{Name: chk.Name}, clause.Expr{SQL: chk.Constraint})
116   - }
117   -
118   - createTableSQL = strings.TrimSuffix(createTableSQL, ",")
119   -
120   - createTableSQL += ")"
121   -
122   - if tableOption, ok := m.DB.Get("gorm:table_options"); ok {
123   - createTableSQL += fmt.Sprint(tableOption)
124   - }
125   -
126   - err = tx.Exec(createTableSQL, values...).Error
127   - return err
128   - }); err != nil {
129   - return err
130   - }
131   - return nil
132   -}