1
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed

This commit is contained in:
昔念
2026-04-21 01:12:26 +08:00
parent 4b42a64da0
commit dcbd9950d3
5 changed files with 105 additions and 6 deletions

View File

@@ -52,6 +52,18 @@ func (s *BaseSysUserService) GetPerson(userId uint32) (res *model.BaseSysUser) {
return
}
func (s *BaseSysUserService) GetByUsername(username string) (res *model.BaseSysUser) {
if strings.TrimSpace(username) == "" {
return nil
}
m := cool.DBM(s.Model)
m.Where("username", strings.ToLower(strings.TrimSpace(username))).FieldsEx("password").Scan(&res)
return
}
func (s *BaseSysUserService) SetdepartmentId(userId, departmentId uint32) (res *model.BaseSysUser) {
m := cool.DBM(s.Model)
m.Where("id", userId).Data("departmentId", departmentId).Update()

View File

@@ -193,6 +193,9 @@ func (s *ServerService) GetDonationAvailableServerIDs() []uint32 {
if server.OnlineID == 0 {
continue
}
if server.IsDebug != 0 {
continue
}
ids = append(ids, server.OnlineID)
}
sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] })

View File

@@ -1,8 +1,14 @@
package admin
import (
"context"
"blazing/common/data"
"blazing/cool"
baseservice "blazing/modules/base/service"
"blazing/modules/player/service"
"github.com/gogf/gf/v2/frame/g"
)
type ItemBagController struct {
@@ -13,10 +19,54 @@ func init() {
var task_info_controller = &ItemBagController{
&cool.Controller{
Prefix: "/admin/game/item",
Api: []string{"Delete", "Update", "Info", "List", "Page"},
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page", "Grant"},
Service: service.NewItemService(0), //因为page已经过滤所以这里需要改成0
},
}
// 注册路由
cool.RegisterController(task_info_controller)
}
type ItemGrantReq struct {
g.Meta `path:"/grant" method:"POST"`
Authorization string `json:"Authorization" in:"header"`
PlayerID uint32 `json:"player_id"`
Username string `json:"username"`
ItemID int64 `json:"item_id" v:"required#请选择物品"`
ItemCnt int64 `json:"item_cnt" v:"required|min:1#请输入数量|数量必须大于0"`
}
func (c *ItemBagController) Grant(ctx context.Context, req *ItemGrantReq) (res *cool.BaseRes, err error) {
playerID := req.PlayerID
if playerID == 0 && req.Username != "" {
user := baseservice.NewBaseSysUserService().GetByUsername(req.Username)
if user == nil {
return cool.Fail("用户不存在"), nil
}
playerID = uint32(user.ID)
}
if playerID == 0 {
return cool.Fail("请先选择玩家"), nil
}
items, err := service.NewItemService(playerID).AddItems([]data.ItemInfo{
{
ItemId: req.ItemID,
ItemCnt: req.ItemCnt,
},
})
if err != nil {
return cool.Fail(err.Error()), nil
}
if len(items) == 0 {
return cool.Fail("发放失败,可能已达到物品上限"), nil
}
return cool.Ok(g.Map{
"player_id": playerID,
"item_id": req.ItemID,
"item_cnt": req.ItemCnt,
"items": items,
}), nil
}

View File

@@ -3,6 +3,7 @@ package service
import (
"blazing/common/data"
"blazing/cool"
basemodel "blazing/modules/base/model"
"blazing/modules/player/model"
"context"
"strings"
@@ -345,17 +346,32 @@ func NewItemService(id uint32) *ItemService {
Service: &cool.Service{Model: model.NewPlayerBag(), UniqueKey: map[string]string{
"player_id": "角色名称不能重复",
}, PageQueryOp: &cool.QueryOp{
KeyWordField: []string{"player_id"},
FieldEQ: []string{"player_id"},
Select: `player_item.*, base_sys_user.username`,
Join: []*cool.JoinOp{
{
Model: basemodel.NewBaseSysUser(),
Alias: "base_sys_user",
Type: cool.LeftJoin,
Condition: `player_item.player_id = base_sys_user.id`,
},
},
KeyWordField: []string{"player_item.player_id", "base_sys_user.username"},
FieldEQ: []string{"player_id", "item_id"},
Where: func(ctx context.Context) [][]interface{} {
var (
//admin = cool.GetAdmin(ctx)
//userId = admin.UserId
r = g.RequestFromCtx(ctx)
)
return [][]interface{}{
where := [][]interface{}{
// {"player_id", userId, true},
// {"free", 0, true},
}
if username := strings.TrimSpace(r.Get("username").String()); username != "" {
where = append(where, []interface{}{`LOWER(base_sys_user.username) LIKE ?`, "%" + strings.ToLower(username) + "%"})
}
return where
},
}},
},