diff --git a/bin/conf/backend/conf.toml b/bin/conf/backend/conf.toml index 142db1f..3d6edf0 100644 --- a/bin/conf/backend/conf.toml +++ b/bin/conf/backend/conf.toml @@ -14,5 +14,5 @@ AccessKeyId="LTAI5tLaYWuRVz7BiQ7m666Z" AccessKeySecret="6s7mMexYbVmZSLXEv3kdJwxXThMN4T" BucketName="xpggame" ObjectName="res/" - +Domain="res.tp7k.com" diff --git a/call/config.go b/call/config.go index 9c0bb26..6f6c5f4 100644 --- a/call/config.go +++ b/call/config.go @@ -61,6 +61,7 @@ var ( configServerFlag []*common.ConfigServerFlag configActivitySevenDayBox []*common.ConfigActivitySevenDayBox configActivitySuper []*common.ConfigActivitySuper + configTgRobot []*common.ConfigTgRobot ) var ( @@ -1203,13 +1204,21 @@ func LoadConfigActivityLuckCode() (err error) { return nil } -func GetConfigAcitivityLuckyCode() []*common.ConfigActivityLuckyCode { - return configActivityLuckyCode +func GetConfigAcitivityLuckyCode(t int) []*common.ConfigActivityLuckyCode { + var ret []*common.ConfigActivityLuckyCode + for _, conf := range configActivityLuckyCode { + if conf.Type == t { + ret = append(ret, conf) + } + } + return ret } -func GetConfigAcitivityLuckyCodeTotalWeight() (total int64) { +func GetConfigAcitivityLuckyCodeTotalWeight(t int) (total int64) { for _, v := range configActivityLuckyCode { - total += int64(v.Per) + if v.Type == t { + total += v.Per + } } return } @@ -1465,3 +1474,17 @@ func GetConfigActivitySuperByTypeAndIndex(t, index int) (ret []*common.ConfigAct } return } + +func LoadConfigTgRobot() (err error) { + var list []*common.ConfigTgRobot + if _, err = db.Mysql().QueryAll("", "", &common.ConfigTgRobot{}, &list); err != nil { + log.Error("err:%v", err) + return err + } + configTgRobot = list + return nil +} + +func GetConfigTgRobot() []*common.ConfigTgRobot { + return configTgRobot +} diff --git a/call/reload.go b/call/reload.go index 495e905..b5a2f9a 100644 --- a/call/reload.go +++ b/call/reload.go @@ -439,4 +439,13 @@ func CommonReload(c map[int][]func(*pb.ReloadGameConfig) error) { return nil }} } + if _, ok := c[common.ReloadConfigTgRobot]; !ok { + c[common.ReloadConfigTgRobot] = []func(*pb.ReloadGameConfig) error{func(rgc *pb.ReloadGameConfig) error { + if err := LoadConfigTgRobot(); err != nil { + log.Error("error : [%s]", err.Error()) + return err + } + return nil + }} + } } diff --git a/common/activity.go b/common/activity.go index 9ff910e..09003f1 100644 --- a/common/activity.go +++ b/common/activity.go @@ -218,6 +218,7 @@ func (c *ActivityFirstRechargeBackData) TableName() string { const ( LuckyCodeTypeZero = iota LuckyCodeTypeNormal + LuckyCodeTypeVip LuckyCodeTypeAll ) @@ -233,10 +234,11 @@ func (c *ConfigActivityLuckyCode) TableName() string { } type ActivityLuckyCodeData struct { - ID int `gorm:"primary_key;AUTO_INCREMENT;column:id"` - Type int `gorm:"column:type;default:1;type:int(11);"` - UID int `gorm:"column:uid;not null;type:int(11);uniqueIndex:uid"` - LastDraw int64 `gorm:"column:last_draw;default:0;type:bigint(20)"` + ID int `gorm:"primary_key;AUTO_INCREMENT;column:id"` + Type int `gorm:"column:type;default:1;type:int(11);"` + UID int `gorm:"column:uid;not null;type:int(11);uniqueIndex:uid"` + LastDraw int64 `gorm:"column:last_draw;default:0;type:bigint(20)"` + LastVipDraw int64 `gorm:"column:last_vip_draw;default:0;type:bigint(20)"` } func (c *ActivityLuckyCodeData) TableName() string { @@ -248,7 +250,7 @@ type ActivityLuckyCode struct { ID int `gorm:"primary_key;AUTO_INCREMENT;column:id"` Type int `gorm:"column:type;default:1;type:int(11);"` Code int `gorm:"column:code;default:0;type:int(11)"` - Date string `gorm:"column:date;default:'';type:varchar(64);uniqueIndex:date;comment:日期"` + Date string `gorm:"column:date;default:'';type:varchar(64);comment:日期"` } func (c *ActivityLuckyCode) TableName() string { diff --git a/common/config.go b/common/config.go index cdefaae..937fcf7 100644 --- a/common/config.go +++ b/common/config.go @@ -49,6 +49,7 @@ const ( ReloadConfigServerFlag // 服务器配置 ReloadConfigActivitySevenDayBox // 7日宝箱活动 ReloadConfigActivitySuper // 超级1+2 + ReloadConfigTgRobot // tg机器人配置 ) // GetConfigStructByType 获取相应配置的结构 @@ -134,6 +135,8 @@ func GetConfigStructByType(t int) (interface{}, interface{}) { return &ConfigActivitySevenDayBox{}, &[]ConfigActivitySevenDayBox{} case ReloadConfigActivitySuper: return &ConfigActivitySuper{}, &[]ConfigActivitySuper{} + case ReloadConfigTgRobot: + return &ConfigTgRobot{}, &[]ConfigTgRobot{} default: return nil, nil } @@ -548,3 +551,19 @@ type ConfigCurrencyResource struct { func (c *ConfigCurrencyResource) TableName() string { return "config_Currency_resource" } + +type ConfigTgRobot struct { + ID int `gorm:"primarykey"` + Type int `gorm:"column:type;type:int(11);default:0;comment:机器人类型" web:"type"` + ChannelName string `gorm:"column:channel_name;type:varchar(255);comment:频道名称" web:"channel_name"` // 频道id + ChannelType string `gorm:"column:channel_type;type:varchar(255);comment:频道类型" web:"channel_type"` // 频道类型 vip 普通 + Content string `gorm:"column:content;type:text;comment:内容" web:"content"` // 内容 + ContentType string `gorm:"column:content_type;type:varchar(255);comment:发送类型" web:"content_type"` // 发送类型 + Image string `gorm:"column:image;type:longtext;comment:发送类型" web:"image"` // 图片 + Time string `gorm:"column:time;type:varchar(255);comment:发送类型" web:"time"` // 时间 + Open bool `gorm:"column:open;type:int(11);default:0;comment:是否开启" web:"open"` // 是否开启 +} + +func (c *ConfigTgRobot) TableName() string { + return "config_tg_robot" +} diff --git a/config/config.go b/config/config.go index 77f5f9d..606437f 100644 --- a/config/config.go +++ b/config/config.go @@ -6,6 +6,7 @@ type OssParams struct { AccessKeySecret string BucketName string ObjectName string + Domain string } type FacebookParams struct { diff --git a/modules/backend/handler/common/common.go b/modules/backend/handler/common/common.go index d692429..b4bee26 100644 --- a/modules/backend/handler/common/common.go +++ b/modules/backend/handler/common/common.go @@ -92,6 +92,7 @@ func UploadOSS(c *gin.Context) { ossConf := config.GetConfig().Backend.Oss req := new(values.UploadOSSReq) req.ObjectName = c.PostForm("ObjectName") + req.Folder = c.PostForm("Folder") rsp := new(values.UploadOSSResp) a.Data = rsp file, err := c.FormFile("file") @@ -121,11 +122,11 @@ func UploadOSS(c *gin.Context) { return } } - err = bucket.PutObject(ossConf.ObjectName+file.Filename, f) + err = bucket.PutObject(req.Folder+ossConf.ObjectName+file.Filename, f) if err != nil { a.Code = values.CodeRetry log.Error("UploadOSS PutObject err:%v", err) return } - rsp.Url = fmt.Sprintf("https://%s.%s/%s", ossConf.BucketName, ossConf.Endpoint, ossConf.ObjectName+file.Filename) + rsp.Url = fmt.Sprintf("https://%s/%s", ossConf.Domain, req.Folder+ossConf.ObjectName+file.Filename) } diff --git a/modules/backend/migrate.go b/modules/backend/migrate.go index c31743a..ee77c5e 100644 --- a/modules/backend/migrate.go +++ b/modules/backend/migrate.go @@ -110,6 +110,7 @@ func MigrateDB() { new(common.ConfigActivitySuper), new(common.ActivitySuperData), new(common.ShareActivityCode), + new(common.ConfigTgRobot), ) if err != nil { panic("Migrate db fail") diff --git a/modules/backend/values/gm.go b/modules/backend/values/gm.go index ad235b5..ce7d473 100644 --- a/modules/backend/values/gm.go +++ b/modules/backend/values/gm.go @@ -156,6 +156,8 @@ func GetControlType(path string) int { return common.ReloadConfigActivitySevenDayBox case "super": return common.ReloadConfigActivitySuper + case "tgRobot": + return common.ReloadConfigTgRobot default: return 0 } diff --git a/modules/backend/values/protocol.go b/modules/backend/values/protocol.go index eeef714..b0d1cf8 100644 --- a/modules/backend/values/protocol.go +++ b/modules/backend/values/protocol.go @@ -271,6 +271,7 @@ type UploadOSSReq struct { AccessKeySecret string BucketName string ObjectName string + Folder string // 文件夹 } type UploadOSSResp struct { diff --git a/modules/web/handler/activity.go b/modules/web/handler/activity.go index ae1b420..02a0319 100644 --- a/modules/web/handler/activity.go +++ b/modules/web/handler/activity.go @@ -666,15 +666,26 @@ func ActivityLuckyCodeInfo(c *gin.Context) { defer func() { a.Response() }() + req := new(values.ActivityLuckyCodeInfoReq) + if !a.S(req) { + return + } + if !a.CheckActivityExpire(common.ActivityIDLuckyCode) { return } + t := req.Type + if t == 0 { + t = common.LuckyCodeTypeNormal + } else { + t = common.LuckyCodeTypeVip + } resp := &values.ActivityLuckyCodeInfoResp{ TelegramChannel: config.GetBase().Server.TelegramChannel, } a.Data = resp - con := call.GetConfigAcitivityLuckyCode() - total := call.GetConfigAcitivityLuckyCodeTotalWeight() + con := call.GetConfigAcitivityLuckyCode(t) + total := call.GetConfigAcitivityLuckyCodeTotalWeight(t) for _, v := range con { resp.List = append(resp.List, values.OneActivityLuckyCodeConfig{ ID: v.ID, @@ -699,50 +710,52 @@ func ActivityLuckyCodeDraw(c *gin.Context) { return } now := time.Now() - luckyCode := &common.ActivityLuckyCode{Date: now.Format("20060102")} + luckyCode := &common.ActivityLuckyCode{Code: req.LuckyCode, Date: now.Format("20060102")} if !a.MGet(luckyCode) { - return - } - if req.LuckyCode != luckyCode.Code { a.Code = values.CodeParam - a.Msg = "O código que você digitou está incorreto" + a.Msg = "आपके द्वारा दर्ज किया गया कोड ग़लत है" return } - t := req.Type - if t == 0 { - t = common.LuckyCodeTypeNormal - } - resp := &values.ActivityLuckyCodeDrawResp{} a.Data = resp + codeType := luckyCode.Type data := &common.ActivityLuckyCodeData{UID: a.UID} db.Mysql().Get(data) - - if util.IsSameDayTimeStamp(now.Unix(), data.LastDraw) { + if (codeType == common.LuckyCodeTypeNormal && util.IsSameDayTimeStamp(now.Unix(), data.LastDraw)) || + (codeType == common.LuckyCodeTypeVip && util.IsSameDayTimeStamp(now.Unix(), data.LastVipDraw)) { a.Code = values.CodeParam - a.Msg = "Esse código já foi usado" + a.Msg = "इस कोड का पहले ही उपयोग किया जा चुका है" return } - // 开始发奖 - con := call.GetConfigAcitivityLuckyCode() - total := call.GetConfigAcitivityLuckyCodeTotalWeight() + con := call.GetConfigAcitivityLuckyCode(codeType) + total := call.GetConfigAcitivityLuckyCodeTotalWeight(codeType) if total == 0 { log.Error("con:%+v invalid,uid:%d", con, a.UID) a.Code = values.CodeRetry return } - if data.ID == 0 { - err := db.Mysql().Create(&common.ActivityLuckyCodeData{UID: a.UID, LastDraw: now.Unix()}) + codeData := &common.ActivityLuckyCodeData{UID: a.UID, Type: codeType} + if codeType == common.LuckyCodeTypeNormal { + codeData.LastDraw = now.Unix() + } else if codeType == common.LuckyCodeTypeVip { + codeData.LastVipDraw = now.Unix() + } + err := db.Mysql().Create(codeData) if err != nil { a.Code = values.CodeRetry return } } else { - rows, err := db.Mysql().UpdateRes(&common.ActivityLuckyCodeData{UID: a.UID, LastDraw: data.LastDraw}, - map[string]interface{}{"last_draw": now.Unix()}) + updates := map[string]interface{}{} + if codeType == common.LuckyCodeTypeNormal { + updates["last_draw"] = now.Unix() + } else if codeType == common.LuckyCodeTypeVip { + updates["last_vip_draw"] = now.Unix() + } + rows, err := db.Mysql().UpdateRes(&common.ActivityLuckyCodeData{UID: a.UID, LastDraw: data.LastDraw}, updates) if rows == 0 || err != nil { a.Code = values.CodeRetry return @@ -767,7 +780,7 @@ func ActivityLuckyCodeDraw(c *gin.Context) { Type: common.CurrencyINR, Value: reward, Event: common.CurrencyEventTask, - Exs1: fmt.Sprintf("%d", t), + Exs1: fmt.Sprintf("%d", codeType), Exi1: req.LuckyCode, NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, reward), }, diff --git a/modules/web/handler/telegram.go b/modules/web/handler/telegram.go index 0db23a1..16b3ff1 100644 --- a/modules/web/handler/telegram.go +++ b/modules/web/handler/telegram.go @@ -1,7 +1,9 @@ package handler import ( + "errors" "math/rand" + "server/call" "server/common" "server/db" "server/modules/backend/values" @@ -9,11 +11,17 @@ import ( "time" "github.com/gin-gonic/gin" + "github.com/liangdas/mqant/log" "gorm.io/gorm" ) +type LuckyCodeReq struct { + Type int `form:"type" ` // code类型 +} + type LuckyCodeResp struct { - Code int + Configs []*common.ConfigTgRobot + Code int } func GetLuckyCode(c *gin.Context) { @@ -21,18 +29,28 @@ func GetLuckyCode(c *gin.Context) { defer func() { a.ResponseB() }() + req := &LuckyCodeReq{} + if !a.SB(req) { + return + } + log.Info("req:%v", req) resp := &LuckyCodeResp{} a.Data = resp + typ := req.Type + if req.Type != common.LuckyCodeTypeVip { + typ = common.LuckyCodeTypeNormal + } date := time.Now().Format("20060102") - data := &common.ActivityLuckyCode{Date: date} + data := &common.ActivityLuckyCode{Date: date, Type: typ} err := db.Mysql().Get(data) resp.Code = data.Code - if err == gorm.ErrRecordNotFound { + if errors.Is(err, gorm.ErrRecordNotFound) { code := rand.Intn(90000) + 10000 - db.Mysql().Create(&common.ActivityLuckyCode{Date: date, Code: code, Type: common.LuckyCodeTypeNormal}) + db.Mysql().Create(&common.ActivityLuckyCode{Date: date, Code: code, Type: typ}) resp.Code = code } else if err != nil { a.Code = values.CodeRetry return } + resp.Configs = call.GetConfigTgRobot() } diff --git a/modules/web/values/activity.go b/modules/web/values/activity.go index 7db43d5..99338b0 100644 --- a/modules/web/values/activity.go +++ b/modules/web/values/activity.go @@ -63,6 +63,10 @@ type ActivityLuckyCodeInfoResp struct { TelegramChannel string } +type ActivityLuckyCodeInfoReq struct { + Type int +} + // Type 类型,预留用于后续其他活动兑换码 type ActivityLuckyCodeDrawReq struct { Type int