Files
bl/modules/base/controller/admin/base_sys_user.go
xinian b00d81bf63
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
1
2026-02-23 00:57:07 +08:00

140 lines
3.4 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/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 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))
if playerinfo.Info.IsReg() {
res.IsReg = 1
if t1.DepartmentID == 35 { ///抢先服玩家3天没登录衰退
r := playerinfo.Info.Person(uint32(t1.ID))
if r.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@UInt注解
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"`
}