You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
269 lines
6.1 KiB
269 lines
6.1 KiB
|
1 year ago
|
package handler
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"server/call"
|
||
|
|
"server/common"
|
||
|
|
"server/db"
|
||
|
|
"server/modules/backend/app"
|
||
|
|
"server/modules/backend/values"
|
||
|
|
"server/natsClient"
|
||
|
|
"server/pb"
|
||
|
|
"server/util"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
"github.com/go-redis/redis/v8"
|
||
|
|
"github.com/liangdas/mqant/log"
|
||
|
|
)
|
||
|
|
|
||
|
|
func GMAddCoin(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
req := new(values.GMAddCoinReq)
|
||
|
|
if !a.S(req) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("gm add coin req:%+v", req)
|
||
|
|
uid := req.UID
|
||
|
|
err := call.MineCurrencyProReal(&common.UpdateCurrency{
|
||
|
|
CurrencyBalance: &common.CurrencyBalance{
|
||
|
|
UID: uid,
|
||
|
|
Type: req.CurrencyType,
|
||
|
|
Value: req.Amount,
|
||
|
|
Event: common.CurrencyEventGM,
|
||
|
|
Exs1: "GM",
|
||
|
|
}}).Err
|
||
|
|
if err != nil {
|
||
|
|
log.Error("GMAddCoins errs:%v", err)
|
||
|
|
a.Code = values.CodeRetry
|
||
|
|
a.Msg = "添加金币失败!"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
a.RecordEdit(values.PowerGM, fmt.Sprintf("给玩家%v增加金币:%v", req.UID, req.Amount))
|
||
|
|
}
|
||
|
|
|
||
|
|
func GMRecharge(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
req := new(values.GMRechargeReq)
|
||
|
|
if !a.S(req) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("GMRecharge:%+v", req)
|
||
|
|
if req.CurrencyType.IsValid() && req.ProductID == 0 {
|
||
|
|
a.Code = values.CodeParam
|
||
|
|
a.Msg = "请求错误"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
order := new(common.RechargeOrder)
|
||
|
|
id := util.NewOrderID(req.UID)
|
||
|
|
order.OrderID = id
|
||
|
|
order.APIPayID = id
|
||
|
|
order.UID = req.UID
|
||
|
|
order.Status = common.StatusROrderCreate
|
||
|
|
order.Event = common.CurrencyEventGMRecharge
|
||
|
|
order.CreateTime = time.Now().Unix()
|
||
|
|
if req.ProductID > 0 {
|
||
|
|
product := call.GetConfigPayProductByID(req.ProductID)
|
||
|
|
if product == nil {
|
||
|
|
a.Code = values.CodeParam
|
||
|
|
a.Msg = "请求错误"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
order.ProductID = req.ProductID
|
||
|
|
order.Amount = product.Amount
|
||
|
|
order.CurrencyType = common.CurrencyBrazil
|
||
|
|
} else {
|
||
|
|
if !req.CurrencyType.IsValid() {
|
||
|
|
log.Error("unknow CurrencyType:%v", req.CurrencyType)
|
||
|
|
a.Code = values.CodeParam
|
||
|
|
a.Msg = "货币类型不存在"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
order.Amount = req.Amount
|
||
|
|
order.CurrencyType = req.CurrencyType
|
||
|
|
}
|
||
|
|
if err := db.Mysql().C().Model(order).Create(order).Error; err != nil {
|
||
|
|
log.Error("create order err:%v", err)
|
||
|
|
a.Code = values.CodeRetry
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if err := call.RechargeCallback(order, true, "", ""); err != nil {
|
||
|
|
log.Error(err.Error())
|
||
|
|
a.Code = values.CodeRetry
|
||
|
|
return
|
||
|
|
}
|
||
|
|
a.RecordEdit(values.PowerGM, fmt.Sprintf("给玩家%v模拟充值货币:%v,数额:%v", req.UID, req.CurrencyType, req.Amount))
|
||
|
|
}
|
||
|
|
|
||
|
|
func GMBindPhone(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
req := new(values.GMBindPhoneReq)
|
||
|
|
if !a.S(req) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
uid := req.UID
|
||
|
|
|
||
|
|
one := new(common.PlayerDBInfo)
|
||
|
|
one.Id = uid
|
||
|
|
err := db.Mysql().Get(one)
|
||
|
|
if err != nil {
|
||
|
|
log.Error(err.Error())
|
||
|
|
}
|
||
|
|
if one.Id == 0 {
|
||
|
|
a.Code = values.CodeParam
|
||
|
|
a.Msg = "用户不存在"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if len(one.Mobile) > 0 {
|
||
|
|
a.Code = values.CodeParam
|
||
|
|
a.Msg = fmt.Sprintf("该用户已绑定手机:%v", one.Mobile)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if err := db.Mysql().Update(one, map[string]interface{}{"Mobile": req.Phone}); err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
a.Code = values.CodeParam
|
||
|
|
a.Msg = "绑定失败"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
a.RecordEdit(values.PowerGM, fmt.Sprintf("给玩家%v绑定手机:%v", req.UID, req.Phone))
|
||
|
|
}
|
||
|
|
|
||
|
|
func GMUnBindPhone(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
req := new(values.GMUnBindPhoneReq)
|
||
|
|
if !a.S(req) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
uid := req.UID
|
||
|
|
|
||
|
|
one := new(common.PlayerDBInfo)
|
||
|
|
one.Id = uid
|
||
|
|
err := db.Mysql().Get(one)
|
||
|
|
if err != nil {
|
||
|
|
log.Error(err.Error())
|
||
|
|
}
|
||
|
|
if one.Id == 0 {
|
||
|
|
a.Code = values.CodeParam
|
||
|
|
a.Msg = "用户不存在"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if len(one.Mobile) == 0 {
|
||
|
|
a.Code = values.CodeParam
|
||
|
|
a.Msg = "该用户未绑定手机"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if err := db.Mysql().Update(one, map[string]interface{}{"Mobile": nil}); err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
a.Code = values.CodeParam
|
||
|
|
a.Msg = "解绑失败"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
a.RecordEdit(values.PowerGM, fmt.Sprintf("给玩家%v解绑手机", req.UID))
|
||
|
|
}
|
||
|
|
|
||
|
|
func GMGetPhoneCode(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
req := new(values.GMGetPhoneCodeReq)
|
||
|
|
if !a.S(req) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
code, err := db.Redis().GetString(common.GetRedisKeyCode(req.Phone))
|
||
|
|
if err != nil && err != redis.Nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
a.Code = values.CodeRetry
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if code == "" {
|
||
|
|
a.Code = values.CodeParam
|
||
|
|
a.Msg = "该手机未发送验证码"
|
||
|
|
return
|
||
|
|
}
|
||
|
|
a.Data = values.GMGetPhoneCodeResp{Code: code}
|
||
|
|
}
|
||
|
|
|
||
|
|
func ConfigPlatformList(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
resp := values.GMConfigPlatformListResp{Config: new(common.ConfigPlatform)}
|
||
|
|
err := db.Mysql().Get(resp.Config)
|
||
|
|
if err != nil {
|
||
|
|
log.Error(err.Error())
|
||
|
|
}
|
||
|
|
a.Data = resp
|
||
|
|
}
|
||
|
|
|
||
|
|
func ConfigPlatformEdit(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
req := &values.GMConfigPlatformEditReq{Config: new(common.ConfigPlatform)}
|
||
|
|
if !a.S(req.Config) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
log.Debug("req:%+v", *req.Config)
|
||
|
|
update := util.StructToMap(req.Config, "web")
|
||
|
|
if err := db.Mysql().Update(&common.ConfigPlatform{ID: 1}, update); err != nil {
|
||
|
|
a.Code = values.CodeRetry
|
||
|
|
return
|
||
|
|
}
|
||
|
|
err := call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadPlatform})
|
||
|
|
if err != nil {
|
||
|
|
log.Error(err.Error())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func ReloadServerVersion(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
req := new(values.GMConfigReloadServerVersionReq)
|
||
|
|
if !a.S(req) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
u := &common.ServerVersion{ServerID: req.ServerID, Version: req.Version}
|
||
|
|
if _, err := db.Mysql().Upsert(fmt.Sprintf("server_id = %v", req.ServerID), u); err != nil {
|
||
|
|
log.Error("err:%v", err)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
call.Publish(natsClient.TopicReloadConfig, &pb.ReloadGameConfig{Type: common.ReloadConfigServerVersion})
|
||
|
|
}
|
||
|
|
|
||
|
|
// 后台控制玩家掉线
|
||
|
|
func OptPlayerDisconnect(c *gin.Context) {
|
||
|
|
a := app.NewApp(c)
|
||
|
|
defer func() {
|
||
|
|
a.Response()
|
||
|
|
}()
|
||
|
|
req := &values.OptPlayerDisconnectReq{}
|
||
|
|
if !a.S(req) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
for i := 0; i < len(req.UserId); i++ {
|
||
|
|
err := call.Publish(natsClient.TopicInnerOptPlayer, &pb.InnerOptPlayer{UID: uint32(req.UserId[i]), Opt: common.OptPlayerTypeDisconnect})
|
||
|
|
if err != nil {
|
||
|
|
log.Error(err.Error())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|