24 changed files with 1036 additions and 26 deletions
@ -0,0 +1,44 @@ |
|||||||
|
package game |
||||||
|
|
||||||
|
import ( |
||||||
|
"github.com/gogf/gf/v2/frame/g" |
||||||
|
commonApi "tyj_admin/api/v1/common" |
||||||
|
"tyj_admin/internal/model/entity" |
||||||
|
) |
||||||
|
|
||||||
|
type BugAddReq struct { |
||||||
|
g.Meta `path:"/custom/bugadd" tags:"增加BUG" method:"post" summary:"增加BUG"` |
||||||
|
Uid int32 `p:"uid" v:"required#uid不能为空"` |
||||||
|
Server int32 `p:"server" ` |
||||||
|
Qq string `p:"qq" ` |
||||||
|
Tel string `p:"tel" ` |
||||||
|
Bug string `p:"bug"` |
||||||
|
OccurrenceTime int64 `p:"occurrenceTime"` |
||||||
|
CreateTime int64 `p:"createTime"` |
||||||
|
State int32 `p:"state"` |
||||||
|
} |
||||||
|
|
||||||
|
type BugAddRes struct { |
||||||
|
} |
||||||
|
|
||||||
|
type BugListReq struct { |
||||||
|
g.Meta `path:"/custom/buglist" tags:"BUG列表" method:"get" summary:"BUG列表"` |
||||||
|
LowTime int64 `p:"lowTime"` |
||||||
|
UpTime int64 `p:"upTime"` |
||||||
|
State int64 `p:"state"` //0表示所有的,1表示没处理的,2表示处理完的
|
||||||
|
commonApi.PageReq |
||||||
|
} |
||||||
|
|
||||||
|
type BugListRes struct { |
||||||
|
g.Meta `mime:"application/json"` |
||||||
|
Bugs []*entity.GameBug `json:"list"` |
||||||
|
commonApi.ListRes |
||||||
|
} |
||||||
|
|
||||||
|
type OperateBugReq struct { |
||||||
|
g.Meta `path:"/custom/operatebug" tags:"处理BUG" method:"post" summary:"处理BUG"` |
||||||
|
Id int32 `p:"Id"` |
||||||
|
} |
||||||
|
|
||||||
|
type OperateBugRes struct { |
||||||
|
} |
@ -0,0 +1,13 @@ |
|||||||
|
package game |
||||||
|
|
||||||
|
import "github.com/gogf/gf/v2/frame/g" |
||||||
|
|
||||||
|
type GetGameUpdateUrlReq struct { |
||||||
|
g.Meta `path:"/updateurl/get" tags:"强更地址" method:"get" summary:"强更地址"` |
||||||
|
Channel string `p:"channel"` |
||||||
|
} |
||||||
|
|
||||||
|
type GetGameUpdateUrlRes struct { |
||||||
|
g.Meta `mime:"application/json"` |
||||||
|
Url string `json:"url"` |
||||||
|
} |
@ -0,0 +1,52 @@ |
|||||||
|
package game |
||||||
|
|
||||||
|
import "github.com/gogf/gf/v2/frame/g" |
||||||
|
|
||||||
|
type AddNoticeReq struct { |
||||||
|
g.Meta `path:"/notice/add" tags:"维护公告" method:"post" summary:"维护公告"` |
||||||
|
Status int `p:"status"` |
||||||
|
Content string `p:"content"` |
||||||
|
Channel string `p:"channel"` |
||||||
|
NoticeType int `p:"noticeType"` |
||||||
|
Id int `p:"id"` |
||||||
|
} |
||||||
|
|
||||||
|
type AddNoticeRes struct { |
||||||
|
} |
||||||
|
|
||||||
|
type GetNoticeReq struct { |
||||||
|
g.Meta `path:"/notice/get" tags:"维护公告" method:"get" summary:"维护公告"` |
||||||
|
Channel string `p:"channel"` |
||||||
|
NoticeType int `p:"noticeType"` |
||||||
|
} |
||||||
|
|
||||||
|
type GetNoticeRes struct { |
||||||
|
g.Meta `mime:"application/json"` |
||||||
|
Status int `json:"status"` |
||||||
|
Content string `json:"content"` |
||||||
|
Id int `json:"id"` |
||||||
|
} |
||||||
|
|
||||||
|
type PopReq struct { |
||||||
|
g.Meta `path:"/notice/pop" tags:"弹窗公告" method:"post" summary:"弹窗公告"` |
||||||
|
Type int `p:"popType"` |
||||||
|
Uids string `p:"uids"` |
||||||
|
ServerId int `p:"serverId"` |
||||||
|
Content string `p:"content"` |
||||||
|
} |
||||||
|
|
||||||
|
type PopRes struct { |
||||||
|
} |
||||||
|
|
||||||
|
type GetGameNoticeReq struct { |
||||||
|
g.Meta `path:"/gamenotice/get" tags:"维护公告" method:"get" summary:"维护公告"` |
||||||
|
Channel string `p:"channel"` |
||||||
|
NoticeType int `p:"noticeType"` |
||||||
|
} |
||||||
|
|
||||||
|
type GetGameNoticeRes struct { |
||||||
|
g.Meta `mime:"application/json"` |
||||||
|
Status int `json:"status"` |
||||||
|
Content string `json:"content"` |
||||||
|
Id int `json:"id"` |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
package controller |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"tyj_admin/api/v1/game" |
||||||
|
"tyj_admin/internal/serviceGame" |
||||||
|
) |
||||||
|
|
||||||
|
var GameCustom = customController{} |
||||||
|
|
||||||
|
type customController struct { |
||||||
|
BaseController |
||||||
|
} |
||||||
|
|
||||||
|
// bug 列表
|
||||||
|
func (c *customController) List(ctx context.Context, req *game.BugListReq) (res *game.BugListRes, err error) { |
||||||
|
res, err = serviceGame.GameCustom().List(ctx, req) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func (c *customController) Operate(ctx context.Context, req *game.OperateBugReq) (res *game.OperateBugRes, err error) { |
||||||
|
res, err = serviceGame.GameCustom().UpdateState(ctx, req) |
||||||
|
return |
||||||
|
} |
||||||
|
func (c *customController) Add(ctx context.Context, req *game.BugAddReq) (res *game.BugAddRes, err error) { |
||||||
|
res, err = serviceGame.GameCustom().Add(ctx, req) |
||||||
|
return |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
package controller |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"tyj_admin/api/v1/game" |
||||||
|
"tyj_admin/internal/serviceGame" |
||||||
|
) |
||||||
|
|
||||||
|
var GameManage = manageController{} |
||||||
|
|
||||||
|
type manageController struct { |
||||||
|
BaseController |
||||||
|
} |
||||||
|
|
||||||
|
func (c *manageController) ChangeGmAuthority(ctx context.Context, req *game.ChangeGmReq) (res *game.ChangeGmRes, err error) { |
||||||
|
res, err = serviceGame.GameManage().ChangeGm(ctx, req) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func (c *manageController) SearchGmAuthority(ctx context.Context, req *game.SearchGmReq) (res *game.SearchGmRes, err error) { |
||||||
|
res, err = serviceGame.GameManage().SearchGm(ctx, req) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func (c *manageController) ChangePwd(ctx context.Context, req *game.ResetPwdReq) (res *game.ResetPwdRes, err error) { |
||||||
|
res, err = serviceGame.GameManage().ChangePwd(ctx, req) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func (c *manageController) GetStatistics(ctx context.Context, req *game.StatisticsReq) (res *game.StatisticsRes, err error) { |
||||||
|
res, err = serviceGame.GameManage().GetStatistics(ctx, req) |
||||||
|
return |
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
package controller |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"fmt" |
||||||
|
"tyj_admin/api/v1/game" |
||||||
|
"tyj_admin/internal/serviceGame" |
||||||
|
"tyj_admin/library/libUtils" |
||||||
|
) |
||||||
|
|
||||||
|
var GameNotice = noticeController{} |
||||||
|
|
||||||
|
type noticeController struct { |
||||||
|
BaseController |
||||||
|
} |
||||||
|
|
||||||
|
func (c *noticeController) Add(ctx context.Context, req *game.AddNoticeReq) (res *game.AddNoticeRes, err error) { |
||||||
|
res, err = serviceGame.GameNotice().AddNotice(ctx, req) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func (c *noticeController) Get(ctx context.Context, req *game.GetNoticeReq) (res *game.GetNoticeRes, err error) { |
||||||
|
ip := libUtils.GetClientIp(ctx) |
||||||
|
fmt.Println(ip) |
||||||
|
res, err = serviceGame.GameNotice().GetNotice(ctx, req) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func (c *noticeController) PopNotice(ctx context.Context, req *game.PopReq) (res *game.PopRes, err error) { |
||||||
|
res, err = serviceGame.GameNotice().PopNotice(ctx, req) |
||||||
|
return |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
package controller |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"tyj_admin/api/v1/game" |
||||||
|
"tyj_admin/internal/model/entity" |
||||||
|
"tyj_admin/internal/service" |
||||||
|
"tyj_admin/internal/serviceGame" |
||||||
|
) |
||||||
|
|
||||||
|
var GamePub = pubController{} |
||||||
|
|
||||||
|
type pubController struct { |
||||||
|
BaseController |
||||||
|
} |
||||||
|
|
||||||
|
func (c *pubController) Get(ctx context.Context, req *game.GetGameNoticeReq) (res *game.GetGameNoticeRes, err error) { |
||||||
|
res, err = serviceGame.GameNotice().GetGameNotice(ctx, req) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func (c *pubController) GetUpdateUrl(ctx context.Context, req *game.GetGameUpdateUrlReq) (res *game.GetGameUpdateUrlRes, err error) { |
||||||
|
config := new(entity.SysConfig) |
||||||
|
res = new(game.GetGameUpdateUrlRes) |
||||||
|
config, err = service.Config().GetByKey(ctx, req.Channel+"_url") |
||||||
|
if err == nil && config != nil { |
||||||
|
res.Url = config.ConfigValue |
||||||
|
} |
||||||
|
return |
||||||
|
} |
@ -0,0 +1,86 @@ |
|||||||
|
package serviceGame |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"github.com/gogf/gf/v2/database/gdb" |
||||||
|
"github.com/gogf/gf/v2/frame/g" |
||||||
|
"github.com/gogf/gf/v2/util/gconv" |
||||||
|
"tyj_admin/api/v1/game" |
||||||
|
"tyj_admin/internal/consts" |
||||||
|
"tyj_admin/internal/dao" |
||||||
|
"tyj_admin/internal/model/do" |
||||||
|
"tyj_admin/library/liberr" |
||||||
|
) |
||||||
|
|
||||||
|
type IGameCustom interface { |
||||||
|
List(ctx context.Context, req *game.BugListReq) (res *game.BugListRes, err error) |
||||||
|
Add(ctx context.Context, req *game.BugAddReq) (res *game.BugAddRes, err error) |
||||||
|
UpdateState(ctx context.Context, req *game.OperateBugReq) (res *game.OperateBugRes, err error) |
||||||
|
} |
||||||
|
|
||||||
|
type gameCustomImpl struct { |
||||||
|
} |
||||||
|
|
||||||
|
func (c gameCustomImpl) UpdateState(ctx context.Context, req *game.OperateBugReq) (res *game.OperateBugRes, err error) { |
||||||
|
err = g.DB().Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error { |
||||||
|
err = g.Try(ctx, func(ctx context.Context) { |
||||||
|
_, err = dao.GameBug.Ctx(ctx).TX(tx).WherePri(req.Id).Update(do.GameBug{State: 1}) |
||||||
|
}) |
||||||
|
return err |
||||||
|
}) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func (c gameCustomImpl) List(ctx context.Context, req *game.BugListReq) (res *game.BugListRes, err error) { |
||||||
|
res = new(game.BugListRes) |
||||||
|
g.Try(ctx, func(ctx context.Context) { |
||||||
|
model := dao.GameBug.Ctx(ctx) |
||||||
|
if req.State != 0 { |
||||||
|
model = model.Where("state=", gconv.Int(req.State-1)) |
||||||
|
} |
||||||
|
if req.LowTime != 0 { |
||||||
|
model = model.Where("occurrenceTime>", req.LowTime/1000) |
||||||
|
} |
||||||
|
if req.UpTime != 0 { |
||||||
|
model = model.Where("occurrenceTime<", req.UpTime/1000) |
||||||
|
} |
||||||
|
res.Total, err = model.Count() |
||||||
|
liberr.ErrIsNil(ctx, err, "获取BUG数据失败") |
||||||
|
if req.PageNum == 0 { |
||||||
|
req.PageNum = 1 |
||||||
|
} |
||||||
|
res.CurrentPage = req.PageNum |
||||||
|
if req.PageSize == 0 { |
||||||
|
req.PageSize = consts.PageSize |
||||||
|
} |
||||||
|
err = model.Page(res.CurrentPage, req.PageSize).Order("id asc").Scan(&res.Bugs) |
||||||
|
liberr.ErrIsNil(ctx, err, "获取bug数据失败") |
||||||
|
}) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func (c gameCustomImpl) Add(ctx context.Context, req *game.BugAddReq) (res *game.BugAddRes, err error) { |
||||||
|
err = g.DB().Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error { |
||||||
|
err = g.Try(ctx, func(ctx context.Context) { |
||||||
|
_, err = dao.GameBug.Ctx(ctx).TX(tx).InsertAndGetId(do.GameBug{ |
||||||
|
Uid: req.Uid, |
||||||
|
Server: req.Server, |
||||||
|
Qq: req.Qq, |
||||||
|
Tel: req.Tel, |
||||||
|
Bug: req.Bug, |
||||||
|
CreateTime: req.CreateTime, |
||||||
|
OccurrenceTime: req.OccurrenceTime, |
||||||
|
State: req.State, |
||||||
|
}) |
||||||
|
|
||||||
|
}) |
||||||
|
return err |
||||||
|
}) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
var customMailService = gameCustomImpl{} |
||||||
|
|
||||||
|
func GameCustom() IGameCustom { |
||||||
|
return &customMailService |
||||||
|
} |
@ -0,0 +1,127 @@ |
|||||||
|
package internal |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"github.com/qiniu/qmgo" |
||||||
|
"go.mongodb.org/mongo-driver/bson" |
||||||
|
"time" |
||||||
|
"tyj_admin/api/v1/game" |
||||||
|
"tyj_admin/internal/model/entity" |
||||||
|
) |
||||||
|
|
||||||
|
func SearchGm(ctx context.Context, server int, account string) (gm int, err error) { |
||||||
|
filter := bson.M{} |
||||||
|
if server == 0 { |
||||||
|
acc := entity.AccountInfo{} |
||||||
|
filter["account"] = account |
||||||
|
err = MongoDatabaseList[0].Collection("account").Find(ctx, filter).One(&acc) |
||||||
|
if err == nil && acc.Gm > 0 { |
||||||
|
gm = acc.Gm |
||||||
|
return |
||||||
|
} |
||||||
|
gm = 0 |
||||||
|
return |
||||||
|
} else { |
||||||
|
acc := entity.RoleDetail{} |
||||||
|
filter["account"] = account |
||||||
|
err = MongoDatabaseList[server].Collection("colony").Find(ctx, filter).One(&acc) |
||||||
|
if err == nil && acc.Gm > 0 { |
||||||
|
gm = acc.Gm |
||||||
|
return |
||||||
|
} |
||||||
|
gm = 0 |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
func ChangeGm(ctx context.Context, account string, state int) (res *game.ChangeGmRes, err error) { |
||||||
|
filter := bson.M{} |
||||||
|
|
||||||
|
filter["account"] = account |
||||||
|
err = MongoDatabaseList[0].Collection("account").UpdateOne(ctx, filter, bson.M{"gm": state}) |
||||||
|
return |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
type GmBody struct { |
||||||
|
Uid string `json:"uid"` |
||||||
|
Gm string `json:"gm"` |
||||||
|
ModuleType string `json:"moduleType"` |
||||||
|
} |
||||||
|
|
||||||
|
type MqttGm struct { |
||||||
|
ReqId int64 `json:"reqId"` |
||||||
|
ModuleId string `json:"moduleId"` |
||||||
|
Body GmBody `json:"body"` |
||||||
|
} |
||||||
|
|
||||||
|
//func SendMqttGm(msg interface{}, c chan bool, server string) {
|
||||||
|
//
|
||||||
|
// registerFunc := func(client mqtt.Client, qtmsg mqtt.Message) {
|
||||||
|
// ss := string(msg.([]byte))
|
||||||
|
// fmt.Println(ss)
|
||||||
|
// err := ClientSend("client", 0, false, ss)
|
||||||
|
// if err != nil {
|
||||||
|
// c <- false
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// callback := func(client mqtt.Client, qtmsg mqtt.Message) {
|
||||||
|
// res := &MqttResult{}
|
||||||
|
// client.Disconnect(1)
|
||||||
|
// ss := string(qtmsg.Payload())
|
||||||
|
// ss = ss[1 : len(ss)-1]
|
||||||
|
// ss = strings.Replace(ss, "\\", "", -1)
|
||||||
|
// err := json.Unmarshal([]byte(ss), res)
|
||||||
|
// if err == nil && res.RespId == 1 && res.Error == nil {
|
||||||
|
// c <- true
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// c <- false
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// if NewMqttClient(registerFunc, callback, server) != nil {
|
||||||
|
// c <- false
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
||||||
|
func ChangePwd(ctx context.Context, account string, pwd string) (res *game.ResetPwdRes, err error) { |
||||||
|
err = MongoDatabaseList[0].Collection("account").UpdateOne(ctx, bson.M{"acccount": account}, bson.M{"$set": bson.M{"password": pwd}}) |
||||||
|
ss := make(map[string]interface{}) |
||||||
|
err = MongoDatabaseList[2].Collection("colony").Find(ctx, bson.M{"account": "lq0001"}).One(&ss) |
||||||
|
_, err = MongoDatabaseList[3].Collection("colony").InsertOne(ctx, ss) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func MigrateRole(ctx context.Context, srcServer int, srcUid int32, dstServer int, dstUid int32) (res *game.MigrateRes, err error) { |
||||||
|
ss := make(map[string]interface{}) |
||||||
|
err = MongoDatabaseList[srcServer].Collection("colony").Find(ctx, bson.M{"uid": srcUid}).One(&ss) |
||||||
|
if err != nil { |
||||||
|
return |
||||||
|
} |
||||||
|
delete(ss, "_id") |
||||||
|
delete(ss, "account") |
||||||
|
delete(ss, "uid") |
||||||
|
delete(ss, "friends") |
||||||
|
delete(ss, "friendAsks") |
||||||
|
delete(ss, "blacklist") |
||||||
|
err = MongoDatabaseList[dstServer].Collection("colony").UpdateOne(ctx, bson.M{"uid": dstUid}, bson.M{"$set": ss}) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func GetRegisterNum(ctx context.Context, lowTime int64, upTime int64) (num int64, err error) { |
||||||
|
num, err = MongoDatabaseList[0].Collection("account").Find(ctx, bson.M{"createTime": bson.M{"$lte": time.UnixMilli(upTime), "$gte": time.UnixMilli(lowTime)}}).Count() |
||||||
|
|
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func GetDeposit(ctx context.Context, lowTime int64, upTime int64) (num int64, total int64, err error) { |
||||||
|
ss := make(map[string]interface{}) |
||||||
|
matchStage := bson.D{{"$match", bson.M{"createTime": bson.M{"$gte": time.UnixMilli(lowTime), "$lte": time.UnixMilli(upTime)}}}} |
||||||
|
groupStage := bson.D{{"$group", bson.M{"totalMoney": bson.M{"$sum": "$money"}, "times": bson.M{"$sum": 1}}}} |
||||||
|
err = MongoDatabaseList[0].Collection("rechargeOrder").Aggregate(ctx, qmgo.Pipeline{matchStage, groupStage}).One(&ss) |
||||||
|
return |
||||||
|
|
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package internal |
||||||
|
|
||||||
|
type NoticeBody struct { |
||||||
|
Time int `json:"time"` |
||||||
|
Type int `json:"type"` |
||||||
|
Content string `json:"content"` |
||||||
|
ModuleType string `json:"moduleType"` |
||||||
|
Uid string `json:"uid"` |
||||||
|
} |
||||||
|
type MqttNotice struct { |
||||||
|
ReqId int64 `json:"reqId"` |
||||||
|
ModuleId string `json:"moduleId"` |
||||||
|
Body NoticeBody `json:"body"` |
||||||
|
} |
@ -0,0 +1,104 @@ |
|||||||
|
package serviceGame |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"encoding/json" |
||||||
|
"github.com/gogf/gf/v2/crypto/gmd5" |
||||||
|
"github.com/gogf/gf/v2/errors/gerror" |
||||||
|
"tyj_admin/api/v1/game" |
||||||
|
"tyj_admin/internal/serviceGame/internal" |
||||||
|
) |
||||||
|
|
||||||
|
type IGameManage interface { |
||||||
|
ChangeGm(ctx context.Context, req *game.ChangeGmReq) (res *game.ChangeGmRes, err error) |
||||||
|
ChangePwd(ctx context.Context, req *game.ResetPwdReq) (res *game.ResetPwdRes, err error) |
||||||
|
MigrateRole(ctx context.Context, req *game.MigrateReq) (res *game.MigrateRes, err error) |
||||||
|
SearchGm(ctx context.Context, req *game.SearchGmReq) (res *game.SearchGmRes, err error) |
||||||
|
GetStatistics(ctx context.Context, req *game.StatisticsReq) (res *game.StatisticsRes, err error) |
||||||
|
} |
||||||
|
|
||||||
|
type gameManageImpl struct { |
||||||
|
} |
||||||
|
|
||||||
|
var gameManageService = gameManageImpl{} |
||||||
|
|
||||||
|
func GameManage() IGameManage { |
||||||
|
return &gameManageService |
||||||
|
} |
||||||
|
|
||||||
|
func (g *gameManageImpl) ChangePwd(ctx context.Context, req *game.ResetPwdReq) (res *game.ResetPwdRes, err error) { |
||||||
|
pwd := gmd5.MustEncryptString(req.Pwd + "sdsd") |
||||||
|
res, err = internal.ChangePwd(ctx, req.Account, pwd) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func (g *gameManageImpl) MigrateRole(ctx context.Context, req *game.MigrateReq) (res *game.MigrateRes, err error) { |
||||||
|
res = new(game.MigrateRes) |
||||||
|
res, err = internal.MigrateRole(ctx, req.SrcServerId, req.SrcUid, req.DesServerId, req.DesUid) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func (g *gameManageImpl) MigrateSearch(ctx context.Context, req *game.MigrateSearchReq) (res *game.MigrateSearchRes, err error) { |
||||||
|
res = new(game.MigrateSearchRes) |
||||||
|
srcRole, srcErr := internal.GetRoleDetail(ctx, req.SrcUid, req.SrcServerId) |
||||||
|
if srcErr != nil { |
||||||
|
err = srcErr |
||||||
|
return |
||||||
|
} |
||||||
|
res.RoleList = append(res.RoleList, srcRole) |
||||||
|
desRole, desErr := internal.GetRoleDetail(ctx, req.SrcUid, req.SrcServerId) |
||||||
|
if desErr != nil { |
||||||
|
err = desErr |
||||||
|
return |
||||||
|
} |
||||||
|
res.RoleList = append(res.RoleList, desRole) |
||||||
|
return |
||||||
|
} |
||||||
|
func (g *gameManageImpl) SearchGm(ctx context.Context, req *game.SearchGmReq) (res *game.SearchGmRes, err error) { |
||||||
|
res = new(game.SearchGmRes) |
||||||
|
res.Gm, err = internal.SearchGm(ctx, req.ServerId, req.Account) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
func (g *gameManageImpl) ChangeGm(ctx context.Context, req *game.ChangeGmReq) (res *game.ChangeGmRes, err error) { |
||||||
|
res = new(game.ChangeGmRes) |
||||||
|
if req.ServerId == 0 { |
||||||
|
res, err = internal.ChangeGm(ctx, req.Account, req.ChangeValue) |
||||||
|
} else { |
||||||
|
mqttGm := internal.MqttGm{} |
||||||
|
mqttGm.Body.Uid = req.Account |
||||||
|
mqttGm.Body.Gm = "gm" |
||||||
|
mqttGm.Body.ModuleType = "changeGM" |
||||||
|
mqttGm.ModuleId = "webadmin" |
||||||
|
mqttGm.ReqId = 1 |
||||||
|
var js []byte |
||||||
|
js, err = json.Marshal(mqttGm) |
||||||
|
connectCh := make(chan bool) |
||||||
|
server := "192.168.2.100:3005" |
||||||
|
defer close(connectCh) |
||||||
|
internal.SendMqtt(js, connectCh, server) |
||||||
|
var result bool |
||||||
|
for { |
||||||
|
select { |
||||||
|
case result = <-connectCh: |
||||||
|
if result == false { |
||||||
|
err = gerror.New("失败") |
||||||
|
return |
||||||
|
} else { |
||||||
|
return |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
func (g *gameManageImpl) GetStatistics(ctx context.Context, req *game.StatisticsReq) (res *game.StatisticsRes, err error) { |
||||||
|
res = new(game.StatisticsRes) |
||||||
|
|
||||||
|
res.RegisterNum, err = internal.GetRegisterNum(ctx, req.LowTime, req.UpTime) |
||||||
|
internal.GetDeposit(ctx, req.LowTime, req.UpTime) |
||||||
|
|
||||||
|
return |
||||||
|
} |
@ -0,0 +1,169 @@ |
|||||||
|
package serviceGame |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"encoding/json" |
||||||
|
"github.com/gogf/gf/v2/errors/gerror" |
||||||
|
"github.com/gogf/gf/v2/frame/g" |
||||||
|
"tyj_admin/api/v1/game" |
||||||
|
"tyj_admin/internal/dao" |
||||||
|
"tyj_admin/internal/model/do" |
||||||
|
"tyj_admin/internal/model/entity" |
||||||
|
"tyj_admin/internal/serviceGame/internal" |
||||||
|
"tyj_admin/library/libUtils" |
||||||
|
"tyj_admin/library/liberr" |
||||||
|
) |
||||||
|
|
||||||
|
type IGameNotice interface { |
||||||
|
GetNotice(ctx context.Context, req *game.GetNoticeReq) (res *game.GetNoticeRes, err error) |
||||||
|
AddNotice(ctx context.Context, req *game.AddNoticeReq) (res *game.AddNoticeRes, err error) |
||||||
|
PopNotice(ctx context.Context, req *game.PopReq) (res *game.PopRes, err error) |
||||||
|
GetGameNotice(ctx context.Context, req *game.GetGameNoticeReq) (res *game.GetGameNoticeRes, err error) |
||||||
|
} |
||||||
|
|
||||||
|
type gameNoticeImpl struct { |
||||||
|
} |
||||||
|
|
||||||
|
var gameNoticeService = gameNoticeImpl{} |
||||||
|
|
||||||
|
func GameNotice() IGameNotice { |
||||||
|
return &gameNoticeService |
||||||
|
} |
||||||
|
func (c *gameNoticeImpl) GetNotice(ctx context.Context, req *game.GetNoticeReq) (res *game.GetNoticeRes, err error) { |
||||||
|
internal.GetWhiteList(ctx) |
||||||
|
res = new(game.GetNoticeRes) |
||||||
|
g.Try(ctx, func(ctx context.Context) { |
||||||
|
model := dao.GameNotice.Ctx(ctx) |
||||||
|
model = model.Where("notice_type = ?", req.NoticeType) |
||||||
|
model = model.Where("channel=? ", req.Channel) |
||||||
|
var noticeList []*entity.GameNotice |
||||||
|
|
||||||
|
err = model.Scan(¬iceList) |
||||||
|
if len(noticeList) >= 1 { |
||||||
|
res.Content = noticeList[0].Content |
||||||
|
res.Status = noticeList[0].Status |
||||||
|
res.Id = noticeList[0].Id |
||||||
|
} else { |
||||||
|
return |
||||||
|
} |
||||||
|
if res.Status == 2 { |
||||||
|
//ip := libUtils.GetClientIp(ctx)
|
||||||
|
//whiteIps := internal.GetWhiteList(ctx)
|
||||||
|
//res.Status = 3
|
||||||
|
//for _, v := range whiteIps {
|
||||||
|
// if v == ip {
|
||||||
|
// res.Status = 1
|
||||||
|
// break
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
} |
||||||
|
|
||||||
|
}) |
||||||
|
return |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
func (c *gameNoticeImpl) GetGameNotice(ctx context.Context, req *game.GetGameNoticeReq) (res *game.GetGameNoticeRes, err error) { |
||||||
|
res = new(game.GetGameNoticeRes) |
||||||
|
g.Try(ctx, func(ctx context.Context) { |
||||||
|
model := dao.GameNotice.Ctx(ctx) |
||||||
|
model = model.Where("notice_type = ?", req.NoticeType) |
||||||
|
model = model.Where("channel=? ", req.Channel) |
||||||
|
var noticeList []*entity.GameNotice |
||||||
|
var count int |
||||||
|
count, err = model.Count() |
||||||
|
if count == 0 { |
||||||
|
model = dao.GameNotice.Ctx(ctx) |
||||||
|
model = model.Where("notice_type = ?", req.NoticeType) |
||||||
|
model = model.Where("channel=? ", 0) |
||||||
|
} |
||||||
|
err = model.Scan(¬iceList) |
||||||
|
if len(noticeList) > 1 { |
||||||
|
for _, v := range noticeList { |
||||||
|
if v.Channel == req.Channel { |
||||||
|
res.Content = v.Content |
||||||
|
res.Status = v.Status |
||||||
|
break |
||||||
|
} |
||||||
|
} |
||||||
|
} else if len(noticeList) == 1 { |
||||||
|
res.Content = noticeList[0].Content |
||||||
|
res.Status = noticeList[0].Status |
||||||
|
res.Id = noticeList[0].Id |
||||||
|
} else if len(noticeList) == 0 { |
||||||
|
res.Content = "" |
||||||
|
res.Status = 1 |
||||||
|
res.Id = 0 |
||||||
|
} |
||||||
|
if res.Status == 2 { |
||||||
|
ip := libUtils.GetClientIp(ctx) |
||||||
|
whiteIps, e := internal.GetWhiteList(ctx) |
||||||
|
g.Log().Debugf(ctx, "ip"+ip, len(whiteIps), e) |
||||||
|
for _, v := range whiteIps { |
||||||
|
g.Log().Debugf(ctx, "whiteIps"+v) |
||||||
|
} |
||||||
|
res.Status = 3 |
||||||
|
for _, v := range whiteIps { |
||||||
|
if v == ip { |
||||||
|
res.Status = 1 |
||||||
|
break |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
}) |
||||||
|
return |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
func (c *gameNoticeImpl) AddNotice(ctx context.Context, req *game.AddNoticeReq) (res *game.AddNoticeRes, err error) { |
||||||
|
if req.Id > 0 { |
||||||
|
err = g.Try(ctx, func(ctx context.Context) { |
||||||
|
_, e := dao.GameNotice.Ctx(ctx).Where("id=", req.Id).Data(&do.GameNotice{ |
||||||
|
Status: req.Status, |
||||||
|
Content: req.Content, |
||||||
|
}).Update() |
||||||
|
liberr.ErrIsNil(ctx, e, "修改通知失败") |
||||||
|
}) |
||||||
|
|
||||||
|
} else { |
||||||
|
err = g.Try(ctx, func(ctx context.Context) { |
||||||
|
_, e := dao.GameNotice.Ctx(ctx).Where("id=", req.Id).Insert(&do.GameNotice{ |
||||||
|
Status: req.Status, |
||||||
|
Content: req.Content, |
||||||
|
NoticeType: req.NoticeType, |
||||||
|
Channel: req.Channel, |
||||||
|
}) |
||||||
|
liberr.ErrIsNil(ctx, e, "插入通知失败") |
||||||
|
}) |
||||||
|
} |
||||||
|
return |
||||||
|
} |
||||||
|
func (c *gameNoticeImpl) PopNotice(ctx context.Context, req *game.PopReq) (res *game.PopRes, err error) { |
||||||
|
mqttNotice := internal.MqttNotice{} |
||||||
|
mqttNotice.Body.Uid = req.Uids |
||||||
|
mqttNotice.Body.ModuleType = "broadcastMessage" |
||||||
|
mqttNotice.Body.Content = req.Content |
||||||
|
mqttNotice.Body.Time = 0 |
||||||
|
mqttNotice.Body.Type = req.Type |
||||||
|
mqttNotice.ModuleId = "webadmin" |
||||||
|
mqttNotice.ReqId = 1 |
||||||
|
var js []byte |
||||||
|
js, err = json.Marshal(mqttNotice) |
||||||
|
connectCh := make(chan bool) |
||||||
|
server := "192.168.2.100:3005" |
||||||
|
defer close(connectCh) |
||||||
|
internal.SendMqtt(js, connectCh, server) |
||||||
|
var result bool |
||||||
|
for { |
||||||
|
select { |
||||||
|
case result = <-connectCh: |
||||||
|
if result == false { |
||||||
|
err = gerror.New("失败") |
||||||
|
return |
||||||
|
} else { |
||||||
|
return |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue