Files
bl/modules/base/controller/admin/base_sys_user.go
昔念 9cc29eec35
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
feat(cool): 添加删除和更新操作的数据影响行数检查

- 在Controller的Delete方法中添加RowsAffected检查,当影响行数为0时返回"not found"错误
- 在Controller的Update方法中添加RowsAffected检查,当影响行数为0时返回"not found"错误
- 修改Service接口定义,将ServiceDelete和ServiceUpdate方法的返回值类型从interface{}改为sql
2026-03-19 17:18:32 +08:00

191 lines
4.9 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)
if !playerservice.NewTaskService(uint32(t.UserId)).CanShop() {
return cool.Fail("不满足申请条件"), 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@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"`
}
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
}