Files
bl/modules/base/controller/admin/base_sys_user.go
xinian d0abb08d5b
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
fix: 修复获取全部/文件读取/ReqShop/ReqShopReqShop 请求错误
2026-04-09 15:37:48 +08:00

196 lines
5.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package admin
import (
"context"
"fmt"
"strings"
"blazing/cool"
"blazing/modules/base/model"
"blazing/modules/base/service"
config "blazing/modules/config/service"
dict "blazing/modules/dict/service"
blazing "blazing/modules/player/service"
playerservice "blazing/modules/player/service"
"github.com/deatil/go-cryptobin/cryptobin/crypto"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
type BaseSysUserController struct {
*cool.Controller
}
func init() {
var base_sys_user_controller = &BaseSysUserController{
&cool.Controller{
Prefix: "/admin/base/sys/user",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page", "Move"},
Service: service.NewBaseSysUserService(),
},
}
// 注册路由
cool.RegisterController(base_sys_user_controller)
}
type UserMoveReq struct {
g.Meta `path:"/move" method:"GET"`
Authorization string `json:"Authorization" in:"header"`
}
func (c *BaseSysUserController) Move(ctx context.Context, req *UserMoveReq) (res *cool.BaseRes, err error) {
err = service.NewBaseSysUserService().Move(ctx)
res = cool.Ok(nil)
return
}
type ReqShopReq struct {
g.Meta `path:"/reqshop" method:"POST"`
Authorization string `json:"Authorization" in:"header"`
}
func (c *BaseSysUserController) ReqShop(ctx context.Context, req *ReqShopReq) (res *cool.BaseRes, err error) {
t := cool.GetAdmin(ctx)
user := service.NewBaseSysUserService().GetPerson(uint32(t.UserId))
if user == nil || user.QQ == 0 {
return cool.Fail("请先绑定QQ"), nil
}
if err := playerservice.NewTaskService(uint32(t.UserId)).ShopRequirementError(); err != nil {
return cool.Fail(err.Error()), nil
}
cool.DBM(&model.BaseSysUserRole{}).Data("roleId", "27", "userId", t.UserId).Save()
res = cool.Ok(nil)
return
}
type SessionReq struct {
g.Meta `path:"/getSession" method:"GET"`
Authorization string `json:"Authorization" in:"header"`
}
func (c *BaseSysUserController) GetSession(ctx context.Context, req *SessionReq) (res *SessionRes, err error) {
t := cool.GetAdmin(ctx)
if t == nil || t.UserId == 0 {
return &SessionRes{}, nil
}
res = &SessionRes{}
t1 := service.NewBaseSysUserService().GetPerson(uint32(t.UserId))
res.UserID = int(t1.ID)
playerinfo := blazing.NewUserService(uint32(t1.ID)).Info.Person(uint32(t1.ID))
if playerinfo != nil {
res.IsReg = 1
if t1.DepartmentID == 35 { ///抢先服玩家3天没登录衰退
if playerinfo.UpdateTime.AddDate(0, 0, 3).Before(gtime.Now()) {
t1.DepartmentID = 1
service.NewBaseSysUserService().SetdepartmentId(uint32(t1.ID), 1)
}
}
}
res.PetID = dict.NewDictInfoService().GetShiny()
res.Server = config.NewServerService().GetPort(t1.DepartmentID)
// share.ShareManager.DeleteSession(t1)
cypten := crypto.
FromString(blazing.NewInfoService(uint32(t.UserId)).Gensession()).
SetKey("gfertf12dfertf12").
SetIv("gfertf12dfertf12").
Aes().
CBC().
PKCS7Padding().
Encrypt().
ToBase64String()
res.Session = cypten
return
}
type SessionRes struct {
IsReg int `json:"isreg"`
UserID int `json:"userid"`
Session string `json:"session"`
Server gdb.List `json:"server"`
PetID []int `json:"petid"`
}
type RegReq struct {
g.Meta `path:"/regrobot" method:"GET"`
Authorization string `json:"Authorization" in:"header"`
// 玩家昵称,@ArraySerialize注解
Nickname string `json:"nickname" ` // 固定长度16字节
// 机器人人物颜色 rgb
Color uint32 `json:"color" ` // 4字节
}
func (c *BaseSysUserController) Regrobot(ctx context.Context, req *RegReq) (res *RegRes, err error) {
t := cool.GetAdmin(ctx)
res = &RegRes{}
t1 := service.NewBaseSysUserService().GetPerson(uint32(t.UserId))
ser := playerservice.NewUserService(uint32(t1.ID))
logininfo := ser.Info.Reg(cool.Filter.Replace(strings.Trim(req.Nickname, "\x00"), '*'), req.Color)
if logininfo != nil {
res.Session = blazing.NewInfoService(uint32(t.UserId)).Gensession()
cool.CacheManager.Set(context.TODO(), fmt.Sprintf("player:%d", uint32(t1.ID)), logininfo, 0)
}
return
}
type RegRes struct {
Session string `json:"session"`
}
type UserGoldAddReq struct {
g.Meta `path:"/goldadd" method:"GET"`
Authorization string `json:"Authorization" in:"header"`
UserID int `json:"userid"`
Gold float32 `json:"gold"`
}
func (c *BaseSysUserController) GoldAdd(ctx context.Context, req *UserGoldAddReq) (res *cool.BaseRes, err error) {
service.NewBaseSysUserService().UpdateGold(uint32(req.UserID), int64(req.Gold*100))
res = cool.Ok(nil)
return
}
type DuihuanGoldAddReq struct {
g.Meta `path:"/duihuan" method:"POST"`
Authorization string `json:"Authorization" in:"header"`
Gold float32 `json:"gold"`
}
func (c *BaseSysUserController) DuihuanGold(ctx context.Context, req *DuihuanGoldAddReq) (res *cool.BaseRes, err error) {
t := cool.GetAdmin(ctx)
if service.NewBaseSysUserService().GetGold(t.UserId) < int64(req.Gold*100) {
res = cool.Fail("余额不足")
return
}
service.NewBaseSysUserService().DuihuanFreeGold(uint32(t.UserId), int64(req.Gold*100), int64(req.Gold*100))
res = cool.Ok(nil)
return
}