This commit is contained in:
18
help/server_show冠名索引修复.sql
Normal file
18
help/server_show冠名索引修复.sql
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
-- server_show 冠名索引修复
|
||||||
|
-- 目的:
|
||||||
|
-- 1. 允许同一服务器存在多个不同玩家的冠名记录
|
||||||
|
-- 2. 保证同一玩家对同一服务器只有一条记录(续费更新该记录)
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
-- 历史上 server_id 被建成了单列唯一约束/唯一索引,会拦截同服多冠名
|
||||||
|
ALTER TABLE server_show DROP CONSTRAINT IF EXISTS idx_server_show_server_id;
|
||||||
|
DROP INDEX IF EXISTS idx_server_show_server_id;
|
||||||
|
|
||||||
|
-- 保留普通查询索引
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_server_show_server_id ON server_show (server_id);
|
||||||
|
|
||||||
|
-- 保证“一个玩家对一个服务器最多一条”
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_server_show_server_owner ON server_show (server_id, owner);
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
@@ -52,6 +52,18 @@ func (s *BaseSysUserService) GetPerson(userId uint32) (res *model.BaseSysUser) {
|
|||||||
|
|
||||||
return
|
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) {
|
func (s *BaseSysUserService) SetdepartmentId(userId, departmentId uint32) (res *model.BaseSysUser) {
|
||||||
m := cool.DBM(s.Model)
|
m := cool.DBM(s.Model)
|
||||||
m.Where("id", userId).Data("departmentId", departmentId).Update()
|
m.Where("id", userId).Data("departmentId", departmentId).Update()
|
||||||
|
|||||||
@@ -193,6 +193,9 @@ func (s *ServerService) GetDonationAvailableServerIDs() []uint32 {
|
|||||||
if server.OnlineID == 0 {
|
if server.OnlineID == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if server.IsDebug != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
ids = append(ids, server.OnlineID)
|
ids = append(ids, server.OnlineID)
|
||||||
}
|
}
|
||||||
sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] })
|
sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] })
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
package admin
|
package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"blazing/common/data"
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
|
baseservice "blazing/modules/base/service"
|
||||||
"blazing/modules/player/service"
|
"blazing/modules/player/service"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ItemBagController struct {
|
type ItemBagController struct {
|
||||||
@@ -13,10 +19,54 @@ func init() {
|
|||||||
var task_info_controller = &ItemBagController{
|
var task_info_controller = &ItemBagController{
|
||||||
&cool.Controller{
|
&cool.Controller{
|
||||||
Prefix: "/admin/game/item",
|
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
|
Service: service.NewItemService(0), //因为page已经过滤,所以这里需要改成0
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// 注册路由
|
// 注册路由
|
||||||
cool.RegisterController(task_info_controller)
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"blazing/common/data"
|
"blazing/common/data"
|
||||||
"blazing/cool"
|
"blazing/cool"
|
||||||
|
basemodel "blazing/modules/base/model"
|
||||||
"blazing/modules/player/model"
|
"blazing/modules/player/model"
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -345,17 +346,32 @@ func NewItemService(id uint32) *ItemService {
|
|||||||
Service: &cool.Service{Model: model.NewPlayerBag(), UniqueKey: map[string]string{
|
Service: &cool.Service{Model: model.NewPlayerBag(), UniqueKey: map[string]string{
|
||||||
"player_id": "角色名称不能重复",
|
"player_id": "角色名称不能重复",
|
||||||
}, PageQueryOp: &cool.QueryOp{
|
}, PageQueryOp: &cool.QueryOp{
|
||||||
KeyWordField: []string{"player_id"},
|
Select: `player_item.*, base_sys_user.username`,
|
||||||
FieldEQ: []string{"player_id"},
|
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{} {
|
Where: func(ctx context.Context) [][]interface{} {
|
||||||
var (
|
var (
|
||||||
//admin = cool.GetAdmin(ctx)
|
r = g.RequestFromCtx(ctx)
|
||||||
//userId = admin.UserId
|
|
||||||
)
|
)
|
||||||
return [][]interface{}{
|
|
||||||
|
where := [][]interface{}{
|
||||||
// {"player_id", userId, true},
|
// {"player_id", userId, true},
|
||||||
// {"free", 0, 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
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user