相关记录表admin_id关联当前管理员id
This commit is contained in:
@@ -83,5 +83,29 @@ export default {
|
|||||||
})
|
})
|
||||||
const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{ id: number; name: string }>
|
const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{ id: number; name: string }>
|
||||||
return rows.map((r) => ({ id: Number(r.id), name: String(r.name ?? r.id ?? '') }))
|
return rows.map((r) => ({ id: Number(r.id), name: String(r.name ?? r.id ?? '') }))
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取后台管理员选项(SystemUser),供 admin_id 下拉使用
|
||||||
|
* @returns [ { id, username, realname, label } ]
|
||||||
|
*/
|
||||||
|
async getSystemUserOptions(): Promise<
|
||||||
|
Array<{ id: number; username: string; realname: string; label: string }>
|
||||||
|
> {
|
||||||
|
const res = await request.get<any>({
|
||||||
|
url: '/dice/player/DicePlayer/getSystemUserOptions'
|
||||||
|
})
|
||||||
|
const rows = (Array.isArray(res) ? res : (res?.data ?? [])) as Array<{
|
||||||
|
id: number
|
||||||
|
username: string
|
||||||
|
realname: string
|
||||||
|
label: string
|
||||||
|
}>
|
||||||
|
return rows.map((r) => ({
|
||||||
|
id: Number(r.id),
|
||||||
|
username: String(r.username ?? ''),
|
||||||
|
realname: String(r.realname ?? ''),
|
||||||
|
label: String(r.label ?? r.username ?? r.id ?? '')
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,23 @@
|
|||||||
<el-form-item label="状态" prop="status">
|
<el-form-item label="状态" prop="status">
|
||||||
<sa-switch v-model="formData.status" />
|
<sa-switch v-model="formData.status" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="所属管理员" prop="admin_id">
|
||||||
|
<el-select
|
||||||
|
v-model="formData.admin_id"
|
||||||
|
placeholder="选择后台管理员(可选)"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
style="width: 100%"
|
||||||
|
:loading="systemUserOptionsLoading"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in systemUserOptions"
|
||||||
|
:key="item.id"
|
||||||
|
:label="item.label || item.username || `#${item.id}`"
|
||||||
|
:value="item.id"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="平台币" prop="coin">
|
<el-form-item label="平台币" prop="coin">
|
||||||
<el-input-number
|
<el-input-number
|
||||||
v-model="formData.coin"
|
v-model="formData.coin"
|
||||||
@@ -221,6 +238,8 @@
|
|||||||
phone: '',
|
phone: '',
|
||||||
password: '',
|
password: '',
|
||||||
status: 1 as number,
|
status: 1 as number,
|
||||||
|
/** 所属后台管理员 ID(SystemUser.id) */
|
||||||
|
admin_id: null as number | null,
|
||||||
coin: 0 as number,
|
coin: 0 as number,
|
||||||
/** 彩金池配置 ID:空 = 自定义权重,否则 = DiceLotteryConfig.id */
|
/** 彩金池配置 ID:空 = 自定义权重,否则 = DiceLotteryConfig.id */
|
||||||
lottery_config_id: null as number | null,
|
lottery_config_id: null as number | null,
|
||||||
@@ -237,6 +256,12 @@
|
|||||||
const lotteryConfigOptions = ref<Array<{ id: number; name: string }>>([])
|
const lotteryConfigOptions = ref<Array<{ id: number; name: string }>>([])
|
||||||
/** 彩金池选项加载中 */
|
/** 彩金池选项加载中 */
|
||||||
const lotteryConfigLoading = ref(false)
|
const lotteryConfigLoading = ref(false)
|
||||||
|
/** 后台管理员下拉选项(SystemUser) */
|
||||||
|
const systemUserOptions = ref<
|
||||||
|
Array<{ id: number; username: string; realname: string; label: string }>
|
||||||
|
>([])
|
||||||
|
/** 管理员选项加载中 */
|
||||||
|
const systemUserOptionsLoading = ref(false)
|
||||||
/** 当前选中的 DiceLotteryConfig 完整数据(用于展示) */
|
/** 当前选中的 DiceLotteryConfig 完整数据(用于展示) */
|
||||||
const currentLotteryConfig = ref<Record<string, any> | null>(null)
|
const currentLotteryConfig = ref<Record<string, any> | null>(null)
|
||||||
|
|
||||||
@@ -306,10 +331,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 加载后台管理员选项 */
|
||||||
|
async function loadSystemUserOptions() {
|
||||||
|
systemUserOptionsLoading.value = true
|
||||||
|
try {
|
||||||
|
systemUserOptions.value = await api.getSystemUserOptions()
|
||||||
|
} catch {
|
||||||
|
systemUserOptions.value = []
|
||||||
|
} finally {
|
||||||
|
systemUserOptionsLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const initPage = async () => {
|
const initPage = async () => {
|
||||||
currentLotteryConfig.value = null
|
currentLotteryConfig.value = null
|
||||||
Object.assign(formData, initialFormData)
|
Object.assign(formData, initialFormData)
|
||||||
await loadLotteryConfigOptions()
|
await Promise.all([loadLotteryConfigOptions(), loadSystemUserOptions()])
|
||||||
if (props.data) {
|
if (props.data) {
|
||||||
await nextTick()
|
await nextTick()
|
||||||
initForm()
|
initForm()
|
||||||
@@ -355,7 +392,7 @@
|
|||||||
if (numKeys.includes(key)) {
|
if (numKeys.includes(key)) {
|
||||||
if (key === 'id') {
|
if (key === 'id') {
|
||||||
;(formData as any)[key] = val != null ? Number(val) || null : null
|
;(formData as any)[key] = val != null ? Number(val) || null : null
|
||||||
} else if (key === 'lottery_config_id') {
|
} else if (key === 'lottery_config_id' || key === 'admin_id') {
|
||||||
const num = Number(val)
|
const num = Number(val)
|
||||||
;(formData as any)[key] = val != null && !Number.isNaN(num) && num !== 0 ? num : null
|
;(formData as any)[key] = val != null && !Number.isNaN(num) && num !== 0 ? num : null
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -137,9 +137,16 @@ class GameController extends BaseController
|
|||||||
]);
|
]);
|
||||||
$timeoutRecord = null;
|
$timeoutRecord = null;
|
||||||
$timeout_message = '';
|
$timeout_message = '';
|
||||||
|
$adminId = null;
|
||||||
|
try {
|
||||||
|
$timeoutPlayer = DicePlayer::find($userId);
|
||||||
|
$adminId = ($timeoutPlayer && ($timeoutPlayer->admin_id ?? null)) ? (int) $timeoutPlayer->admin_id : null;
|
||||||
|
} catch (\Throwable $_) {
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$timeoutRecord = DicePlayRecord::create([
|
$timeoutRecord = DicePlayRecord::create([
|
||||||
'player_id' => $userId,
|
'player_id' => $userId,
|
||||||
|
'admin_id' => $adminId,
|
||||||
'lottery_config_id' => 0,
|
'lottery_config_id' => 0,
|
||||||
'lottery_type' => 0,
|
'lottery_type' => 0,
|
||||||
'is_win' => 0,
|
'is_win' => 0,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace app\api\controller\v1;
|
|||||||
use app\api\logic\UserLogic;
|
use app\api\logic\UserLogic;
|
||||||
use app\api\util\ReturnCode;
|
use app\api\util\ReturnCode;
|
||||||
use app\dice\model\player\DicePlayer;
|
use app\dice\model\player\DicePlayer;
|
||||||
|
use plugin\saiadmin\app\model\system\SystemUser;
|
||||||
use app\dice\model\play_record\DicePlayRecord;
|
use app\dice\model\play_record\DicePlayRecord;
|
||||||
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
|
use app\dice\model\player_wallet_record\DicePlayerWalletRecord;
|
||||||
use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
|
use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
|
||||||
@@ -40,9 +41,18 @@ class GameController extends BaseController
|
|||||||
$time = (string) time();
|
$time = (string) time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$adminId = null;
|
||||||
|
$agentId = trim((string) ($request->agent_id ?? ''));
|
||||||
|
if ($agentId !== '') {
|
||||||
|
$systemUser = SystemUser::where('agent_id', $agentId)->find();
|
||||||
|
if ($systemUser) {
|
||||||
|
$adminId = (int) $systemUser->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$logic = new UserLogic();
|
$logic = new UserLogic();
|
||||||
$result = $logic->loginByUsername($username, $password, 'chs', 0.0, $time);
|
$result = $logic->loginByUsername($username, $password, 'chs', 0.0, $time, $adminId);
|
||||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||||
return $this->fail($e->getMessage(), ReturnCode::PARAMS_ERROR);
|
return $this->fail($e->getMessage(), ReturnCode::PARAMS_ERROR);
|
||||||
}
|
}
|
||||||
@@ -264,8 +274,10 @@ class GameController extends BaseController
|
|||||||
$player->coin = $walletAfter;
|
$player->coin = $walletAfter;
|
||||||
$player->save();
|
$player->save();
|
||||||
|
|
||||||
|
$adminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
|
||||||
$record = DicePlayerWalletRecord::create([
|
$record = DicePlayerWalletRecord::create([
|
||||||
'player_id' => (int) $player->id,
|
'player_id' => (int) $player->id,
|
||||||
|
'admin_id' => $adminId,
|
||||||
'coin' => $coinVal,
|
'coin' => $coinVal,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'wallet_before' => $walletBefore,
|
'wallet_before' => $walletBefore,
|
||||||
|
|||||||
@@ -69,10 +69,12 @@ class GameLogic
|
|||||||
|
|
||||||
UserCache::setUser($playerId, $updatedUserArr);
|
UserCache::setUser($playerId, $updatedUserArr);
|
||||||
|
|
||||||
|
$adminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
|
||||||
try {
|
try {
|
||||||
Db::transaction(function () use (
|
Db::transaction(function () use (
|
||||||
$player,
|
$player,
|
||||||
$playerId,
|
$playerId,
|
||||||
|
$adminId,
|
||||||
$cost,
|
$cost,
|
||||||
$coinBefore,
|
$coinBefore,
|
||||||
$coinAfter,
|
$coinAfter,
|
||||||
@@ -91,6 +93,7 @@ class GameLogic
|
|||||||
|
|
||||||
DicePlayerWalletRecord::create([
|
DicePlayerWalletRecord::create([
|
||||||
'player_id' => $playerId,
|
'player_id' => $playerId,
|
||||||
|
'admin_id' => $adminId,
|
||||||
'coin' => -$cost,
|
'coin' => -$cost,
|
||||||
'type' => self::WALLET_TYPE_BUY_DRAW,
|
'type' => self::WALLET_TYPE_BUY_DRAW,
|
||||||
'wallet_before' => $coinBefore,
|
'wallet_before' => $coinBefore,
|
||||||
@@ -103,6 +106,7 @@ class GameLogic
|
|||||||
|
|
||||||
DicePlayerTicketRecord::create([
|
DicePlayerTicketRecord::create([
|
||||||
'player_id' => $playerId,
|
'player_id' => $playerId,
|
||||||
|
'admin_id' => $adminId,
|
||||||
'use_coins' => $cost,
|
'use_coins' => $cost,
|
||||||
'total_ticket_count' => $addTotal,
|
'total_ticket_count' => $addTotal,
|
||||||
'paid_ticket_count' => $addPaid,
|
'paid_ticket_count' => $addPaid,
|
||||||
|
|||||||
@@ -160,9 +160,11 @@ class PlayStartLogic
|
|||||||
$rewardId = $chosenId;
|
$rewardId = $chosenId;
|
||||||
$configName = (string) ($config->name ?? '');
|
$configName = (string) ($config->name ?? '');
|
||||||
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
|
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
|
||||||
|
$adminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
|
||||||
try {
|
try {
|
||||||
Db::transaction(function () use (
|
Db::transaction(function () use (
|
||||||
$playerId,
|
$playerId,
|
||||||
|
$adminId,
|
||||||
$configId,
|
$configId,
|
||||||
$rewardId,
|
$rewardId,
|
||||||
$configName,
|
$configName,
|
||||||
@@ -181,6 +183,7 @@ class PlayStartLogic
|
|||||||
) {
|
) {
|
||||||
$record = DicePlayRecord::create([
|
$record = DicePlayRecord::create([
|
||||||
'player_id' => $playerId,
|
'player_id' => $playerId,
|
||||||
|
'admin_id' => $adminId,
|
||||||
'lottery_config_id' => $configId,
|
'lottery_config_id' => $configId,
|
||||||
'lottery_type' => $ticketType,
|
'lottery_type' => $ticketType,
|
||||||
'is_win' => $isWin,
|
'is_win' => $isWin,
|
||||||
@@ -219,6 +222,7 @@ class PlayStartLogic
|
|||||||
|
|
||||||
DicePlayerTicketRecord::create([
|
DicePlayerTicketRecord::create([
|
||||||
'player_id' => $playerId,
|
'player_id' => $playerId,
|
||||||
|
'admin_id' => $adminId,
|
||||||
'free_ticket_count' => 1,
|
'free_ticket_count' => 1,
|
||||||
'remark' => '中奖结果为T5',
|
'remark' => '中奖结果为T5',
|
||||||
]);
|
]);
|
||||||
@@ -236,6 +240,7 @@ class PlayStartLogic
|
|||||||
|
|
||||||
DicePlayerWalletRecord::create([
|
DicePlayerWalletRecord::create([
|
||||||
'player_id' => $playerId,
|
'player_id' => $playerId,
|
||||||
|
'admin_id' => $adminId,
|
||||||
'coin' => $winCoin,
|
'coin' => $winCoin,
|
||||||
'type' => self::WALLET_TYPE_DRAW,
|
'type' => self::WALLET_TYPE_DRAW,
|
||||||
'wallet_before' => $coinBefore,
|
'wallet_before' => $coinBefore,
|
||||||
@@ -248,6 +253,7 @@ class PlayStartLogic
|
|||||||
try {
|
try {
|
||||||
$record = DicePlayRecord::create([
|
$record = DicePlayRecord::create([
|
||||||
'player_id' => $playerId,
|
'player_id' => $playerId,
|
||||||
|
'admin_id' => $adminId ?? null,
|
||||||
'lottery_config_id' => $configId ?? 0,
|
'lottery_config_id' => $configId ?? 0,
|
||||||
'lottery_type' => $ticketType,
|
'lottery_type' => $ticketType,
|
||||||
'is_win' => 0,
|
'is_win' => 0,
|
||||||
|
|||||||
@@ -45,8 +45,10 @@ class UserLogic
|
|||||||
* 登录(JSON:username, password, lang, coin, time)
|
* 登录(JSON:username, password, lang, coin, time)
|
||||||
* 存在则校验密码并更新 coin(累加);不存在则创建用户并写入 coin。
|
* 存在则校验密码并更新 coin(累加);不存在则创建用户并写入 coin。
|
||||||
* 将会话写入 Redis,返回 token 与前端连接地址。
|
* 将会话写入 Redis,返回 token 与前端连接地址。
|
||||||
|
*
|
||||||
|
* @param int|null $adminId 创建新用户时关联的后台管理员ID(sa_system_user.id),可选
|
||||||
*/
|
*/
|
||||||
public function loginByUsername(string $username, string $password, string $lang, float $coin, string $time): array
|
public function loginByUsername(string $username, string $password, string $lang, float $coin, string $time, ?int $adminId = null): array
|
||||||
{
|
{
|
||||||
$username = trim($username);
|
$username = trim($username);
|
||||||
if ($username === '') {
|
if ($username === '') {
|
||||||
@@ -72,6 +74,9 @@ class UserLogic
|
|||||||
$player->password = $this->hashPassword($password);
|
$player->password = $this->hashPassword($password);
|
||||||
$player->status = self::STATUS_NORMAL;
|
$player->status = self::STATUS_NORMAL;
|
||||||
$player->coin = $coin;
|
$player->coin = $coin;
|
||||||
|
if ($adminId !== null && $adminId > 0) {
|
||||||
|
$player->admin_id = $adminId;
|
||||||
|
}
|
||||||
$player->save();
|
$player->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace app\dice\controller\play_record;
|
namespace app\dice\controller\play_record;
|
||||||
|
|
||||||
|
use app\dice\helper\AdminScopeHelper;
|
||||||
use plugin\saiadmin\basic\BaseController;
|
use plugin\saiadmin\basic\BaseController;
|
||||||
use app\dice\logic\play_record\DicePlayRecordLogic;
|
use app\dice\logic\play_record\DicePlayRecordLogic;
|
||||||
use app\dice\validate\play_record\DicePlayRecordValidate;
|
use app\dice\validate\play_record\DicePlayRecordValidate;
|
||||||
@@ -53,6 +54,7 @@ class DicePlayRecordController extends BaseController
|
|||||||
['direction', ''],
|
['direction', ''],
|
||||||
]);
|
]);
|
||||||
$query = $this->logic->search($where);
|
$query = $this->logic->search($where);
|
||||||
|
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||||
$query->with([
|
$query->with([
|
||||||
'dicePlayer',
|
'dicePlayer',
|
||||||
'diceRewardConfig',
|
'diceRewardConfig',
|
||||||
@@ -68,7 +70,9 @@ class DicePlayRecordController extends BaseController
|
|||||||
#[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')]
|
#[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')]
|
||||||
public function getPlayerOptions(Request $request): Response
|
public function getPlayerOptions(Request $request): Response
|
||||||
{
|
{
|
||||||
$list = DicePlayer::field('id,username')->select();
|
$query = DicePlayer::field('id,username');
|
||||||
|
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||||
|
$list = $query->select();
|
||||||
$data = $list->map(function ($item) {
|
$data = $list->map(function ($item) {
|
||||||
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
||||||
})->toArray();
|
})->toArray();
|
||||||
@@ -115,12 +119,15 @@ class DicePlayRecordController extends BaseController
|
|||||||
{
|
{
|
||||||
$id = $request->input('id', '');
|
$id = $request->input('id', '');
|
||||||
$model = $this->logic->read($id);
|
$model = $this->logic->read($id);
|
||||||
if ($model) {
|
if (!$model) {
|
||||||
$data = is_array($model) ? $model : $model->toArray();
|
|
||||||
return $this->success($data);
|
|
||||||
} else {
|
|
||||||
return $this->fail('未查找到信息');
|
return $this->fail('未查找到信息');
|
||||||
}
|
}
|
||||||
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
|
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||||
|
return $this->fail('无权限查看该记录');
|
||||||
|
}
|
||||||
|
$data = is_array($model) ? $model : $model->toArray();
|
||||||
|
return $this->success($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,7 +6,9 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace app\dice\controller\player;
|
namespace app\dice\controller\player;
|
||||||
|
|
||||||
|
use app\dice\helper\AdminScopeHelper;
|
||||||
use app\dice\model\lottery_config\DiceLotteryConfig;
|
use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||||
|
use plugin\saiadmin\app\model\system\SystemUser;
|
||||||
use plugin\saiadmin\basic\BaseController;
|
use plugin\saiadmin\basic\BaseController;
|
||||||
use app\dice\logic\player\DicePlayerLogic;
|
use app\dice\logic\player\DicePlayerLogic;
|
||||||
use app\dice\validate\player\DicePlayerValidate;
|
use app\dice\validate\player\DicePlayerValidate;
|
||||||
@@ -44,6 +46,35 @@ class DicePlayerController extends BaseController
|
|||||||
return $this->success($data);
|
return $this->success($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取后台管理员选项(SystemUser.id、username、realname),供 admin_id 下拉使用
|
||||||
|
* 根据当前登录用户权限过滤(超级管理员可见全部,普通管理员按部门)
|
||||||
|
* @param Request $request
|
||||||
|
* @return Response 返回 [ ['id' => int, 'username' => string, 'realname' => string], ... ]
|
||||||
|
*/
|
||||||
|
#[Permission('大富翁-玩家列表', 'dice:player:index:index')]
|
||||||
|
public function getSystemUserOptions(Request $request): Response
|
||||||
|
{
|
||||||
|
$query = SystemUser::field('id,username,realname')->where('status', 1)->order('id', 'asc');
|
||||||
|
if (isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 1) {
|
||||||
|
$deptList = $this->adminInfo['deptList'] ?? [];
|
||||||
|
if (!empty($deptList)) {
|
||||||
|
$query->auth($deptList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$list = $query->select();
|
||||||
|
$data = $list->map(function ($item) {
|
||||||
|
$label = trim((string) ($item['realname'] ?? '')) ?: (string) ($item['username'] ?? '');
|
||||||
|
return [
|
||||||
|
'id' => (int) $item['id'],
|
||||||
|
'username' => (string) ($item['username'] ?? ''),
|
||||||
|
'realname' => (string) ($item['realname'] ?? ''),
|
||||||
|
'label' => $label ?: (string) $item['id'],
|
||||||
|
];
|
||||||
|
})->toArray();
|
||||||
|
return $this->success($data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据列表
|
* 数据列表
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
@@ -61,6 +92,7 @@ class DicePlayerController extends BaseController
|
|||||||
['lottery_config_id', ''],
|
['lottery_config_id', ''],
|
||||||
]);
|
]);
|
||||||
$query = $this->logic->search($where);
|
$query = $this->logic->search($where);
|
||||||
|
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||||
$query->with(['diceLotteryConfig']);
|
$query->with(['diceLotteryConfig']);
|
||||||
$data = $this->logic->getList($query);
|
$data = $this->logic->getList($query);
|
||||||
return $this->success($data);
|
return $this->success($data);
|
||||||
@@ -76,12 +108,15 @@ class DicePlayerController extends BaseController
|
|||||||
{
|
{
|
||||||
$id = $request->input('id', '');
|
$id = $request->input('id', '');
|
||||||
$model = $this->logic->read($id);
|
$model = $this->logic->read($id);
|
||||||
if ($model) {
|
if (!$model) {
|
||||||
$data = is_array($model) ? $model : $model->toArray();
|
|
||||||
return $this->success($data);
|
|
||||||
} else {
|
|
||||||
return $this->fail('未查找到信息');
|
return $this->fail('未查找到信息');
|
||||||
}
|
}
|
||||||
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
|
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||||
|
return $this->fail('无权限查看该玩家');
|
||||||
|
}
|
||||||
|
$data = is_array($model) ? $model : $model->toArray();
|
||||||
|
return $this->success($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,6 +129,10 @@ class DicePlayerController extends BaseController
|
|||||||
{
|
{
|
||||||
$data = $request->post();
|
$data = $request->post();
|
||||||
$this->validate('save', $data);
|
$this->validate('save', $data);
|
||||||
|
// 新增时若未选择管理员,默认使用当前登录用户
|
||||||
|
if (empty($data['admin_id']) && isset($this->adminInfo['id']) && (int) $this->adminInfo['id'] > 0) {
|
||||||
|
$data['admin_id'] = (int) $this->adminInfo['id'];
|
||||||
|
}
|
||||||
$result = $this->logic->add($data);
|
$result = $this->logic->add($data);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success('添加成功');
|
return $this->success('添加成功');
|
||||||
@@ -112,6 +151,13 @@ class DicePlayerController extends BaseController
|
|||||||
{
|
{
|
||||||
$data = $request->post();
|
$data = $request->post();
|
||||||
$this->validate('update', $data);
|
$this->validate('update', $data);
|
||||||
|
$model = $this->logic->read($data['id'] ?? 0);
|
||||||
|
if ($model) {
|
||||||
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
|
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||||
|
return $this->fail('无权限修改该玩家');
|
||||||
|
}
|
||||||
|
}
|
||||||
$result = $this->logic->edit($data['id'], $data);
|
$result = $this->logic->edit($data['id'], $data);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success('修改成功');
|
return $this->success('修改成功');
|
||||||
@@ -136,6 +182,13 @@ class DicePlayerController extends BaseController
|
|||||||
if ($status === null || $status === '') {
|
if ($status === null || $status === '') {
|
||||||
return $this->fail('缺少 status');
|
return $this->fail('缺少 status');
|
||||||
}
|
}
|
||||||
|
$model = $this->logic->read($id);
|
||||||
|
if ($model) {
|
||||||
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
|
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||||
|
return $this->fail('无权限修改该玩家');
|
||||||
|
}
|
||||||
|
}
|
||||||
$this->logic->edit($id, ['status' => (int) $status]);
|
$this->logic->edit($id, ['status' => (int) $status]);
|
||||||
return $this->success('修改成功');
|
return $this->success('修改成功');
|
||||||
}
|
}
|
||||||
@@ -152,6 +205,22 @@ class DicePlayerController extends BaseController
|
|||||||
if (empty($ids)) {
|
if (empty($ids)) {
|
||||||
return $this->fail('请选择要删除的数据');
|
return $this->fail('请选择要删除的数据');
|
||||||
}
|
}
|
||||||
|
$ids = is_array($ids) ? $ids : explode(',', (string) $ids);
|
||||||
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
|
if ($allowedIds !== null) {
|
||||||
|
$models = $this->logic->model->whereIn('id', $ids)->column('admin_id', 'id');
|
||||||
|
$validIds = [];
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$adminId = (int) ($models[$id] ?? 0);
|
||||||
|
if (in_array($adminId, $allowedIds, true)) {
|
||||||
|
$validIds[] = $id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$ids = $validIds;
|
||||||
|
if (empty($ids)) {
|
||||||
|
return $this->fail('无权限删除所选玩家');
|
||||||
|
}
|
||||||
|
}
|
||||||
$result = $this->logic->destroy($ids);
|
$result = $this->logic->destroy($ids);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return $this->success('删除成功');
|
return $this->success('删除成功');
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace app\dice\controller\player_ticket_record;
|
namespace app\dice\controller\player_ticket_record;
|
||||||
|
|
||||||
|
use app\dice\helper\AdminScopeHelper;
|
||||||
use plugin\saiadmin\basic\BaseController;
|
use plugin\saiadmin\basic\BaseController;
|
||||||
use app\dice\logic\player_ticket_record\DicePlayerTicketRecordLogic;
|
use app\dice\logic\player_ticket_record\DicePlayerTicketRecordLogic;
|
||||||
use app\dice\validate\player_ticket_record\DicePlayerTicketRecordValidate;
|
use app\dice\validate\player_ticket_record\DicePlayerTicketRecordValidate;
|
||||||
@@ -51,6 +52,7 @@ class DicePlayerTicketRecordController extends BaseController
|
|||||||
['create_time_max', ''],
|
['create_time_max', ''],
|
||||||
]);
|
]);
|
||||||
$query = $this->logic->search($where);
|
$query = $this->logic->search($where);
|
||||||
|
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||||
$query->with([
|
$query->with([
|
||||||
'dicePlayer',
|
'dicePlayer',
|
||||||
]);
|
]);
|
||||||
@@ -66,7 +68,9 @@ class DicePlayerTicketRecordController extends BaseController
|
|||||||
#[Permission('抽奖券获取记录列表', 'dice:player_ticket_record:index:index')]
|
#[Permission('抽奖券获取记录列表', 'dice:player_ticket_record:index:index')]
|
||||||
public function getPlayerOptions(Request $request): Response
|
public function getPlayerOptions(Request $request): Response
|
||||||
{
|
{
|
||||||
$list = DicePlayer::field('id,username')->select();
|
$query = DicePlayer::field('id,username');
|
||||||
|
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||||
|
$list = $query->select();
|
||||||
$data = $list->map(function ($item) {
|
$data = $list->map(function ($item) {
|
||||||
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
||||||
})->toArray();
|
})->toArray();
|
||||||
@@ -83,12 +87,15 @@ class DicePlayerTicketRecordController extends BaseController
|
|||||||
{
|
{
|
||||||
$id = $request->input('id', '');
|
$id = $request->input('id', '');
|
||||||
$model = $this->logic->read($id);
|
$model = $this->logic->read($id);
|
||||||
if ($model) {
|
if (!$model) {
|
||||||
$data = is_array($model) ? $model : $model->toArray();
|
|
||||||
return $this->success($data);
|
|
||||||
} else {
|
|
||||||
return $this->fail('未查找到信息');
|
return $this->fail('未查找到信息');
|
||||||
}
|
}
|
||||||
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
|
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||||
|
return $this->fail('无权限查看该记录');
|
||||||
|
}
|
||||||
|
$data = is_array($model) ? $model : $model->toArray();
|
||||||
|
return $this->success($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace app\dice\controller\player_wallet_record;
|
namespace app\dice\controller\player_wallet_record;
|
||||||
|
|
||||||
|
use app\dice\helper\AdminScopeHelper;
|
||||||
use plugin\saiadmin\basic\BaseController;
|
use plugin\saiadmin\basic\BaseController;
|
||||||
use app\dice\logic\player_wallet_record\DicePlayerWalletRecordLogic;
|
use app\dice\logic\player_wallet_record\DicePlayerWalletRecordLogic;
|
||||||
use app\dice\validate\player_wallet_record\DicePlayerWalletRecordValidate;
|
use app\dice\validate\player_wallet_record\DicePlayerWalletRecordValidate;
|
||||||
@@ -47,6 +48,7 @@ class DicePlayerWalletRecordController extends BaseController
|
|||||||
['create_time_max', ''],
|
['create_time_max', ''],
|
||||||
]);
|
]);
|
||||||
$query = $this->logic->search($where);
|
$query = $this->logic->search($where);
|
||||||
|
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||||
$query->with([
|
$query->with([
|
||||||
'dicePlayer',
|
'dicePlayer',
|
||||||
'operator',
|
'operator',
|
||||||
@@ -63,7 +65,9 @@ class DicePlayerWalletRecordController extends BaseController
|
|||||||
#[Permission('玩家钱包流水列表', 'dice:player_wallet_record:index:index')]
|
#[Permission('玩家钱包流水列表', 'dice:player_wallet_record:index:index')]
|
||||||
public function getPlayerOptions(Request $request): Response
|
public function getPlayerOptions(Request $request): Response
|
||||||
{
|
{
|
||||||
$list = DicePlayer::field('id,username')->select();
|
$query = DicePlayer::field('id,username');
|
||||||
|
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||||
|
$list = $query->select();
|
||||||
$data = $list->map(function ($item) {
|
$data = $list->map(function ($item) {
|
||||||
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
return ['id' => $item['id'], 'username' => $item['username'] ?? ''];
|
||||||
})->toArray();
|
})->toArray();
|
||||||
@@ -83,10 +87,14 @@ class DicePlayerWalletRecordController extends BaseController
|
|||||||
if ($playerId === null || $playerId === '') {
|
if ($playerId === null || $playerId === '') {
|
||||||
return $this->fail('缺少 player_id');
|
return $this->fail('缺少 player_id');
|
||||||
}
|
}
|
||||||
$player = DicePlayer::field('coin')->where('id', $playerId)->find();
|
$player = DicePlayer::field('coin,admin_id')->where('id', $playerId)->find();
|
||||||
if (!$player) {
|
if (!$player) {
|
||||||
return $this->fail('玩家不存在');
|
return $this->fail('玩家不存在');
|
||||||
}
|
}
|
||||||
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
|
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
|
||||||
|
return $this->fail('无权限操作该玩家');
|
||||||
|
}
|
||||||
return $this->success(['wallet_before' => (float) $player['coin']]);
|
return $this->success(['wallet_before' => (float) $player['coin']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,12 +108,15 @@ class DicePlayerWalletRecordController extends BaseController
|
|||||||
{
|
{
|
||||||
$id = $request->input('id', '');
|
$id = $request->input('id', '');
|
||||||
$model = $this->logic->read($id);
|
$model = $this->logic->read($id);
|
||||||
if ($model) {
|
if (!$model) {
|
||||||
$data = is_array($model) ? $model : $model->toArray();
|
|
||||||
return $this->success($data);
|
|
||||||
} else {
|
|
||||||
return $this->fail('未查找到信息');
|
return $this->fail('未查找到信息');
|
||||||
}
|
}
|
||||||
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
|
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||||
|
return $this->fail('无权限查看该记录');
|
||||||
|
}
|
||||||
|
$data = is_array($model) ? $model : $model->toArray();
|
||||||
|
return $this->success($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -155,6 +166,14 @@ class DicePlayerWalletRecordController extends BaseController
|
|||||||
return $this->fail('请先登录');
|
return $this->fail('请先登录');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$player = DicePlayer::field('admin_id')->where('id', $playerId)->find();
|
||||||
|
if ($player) {
|
||||||
|
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||||
|
if ($allowedIds !== null && !in_array((int) ($player->admin_id ?? 0), $allowedIds, true)) {
|
||||||
|
return $this->fail('无权限操作该玩家');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->logic->adminOperate($data, $adminId);
|
$this->logic->adminOperate($data, $adminId);
|
||||||
return $this->success('操作成功');
|
return $this->success('操作成功');
|
||||||
|
|||||||
60
server/app/dice/helper/AdminScopeHelper.php
Normal file
60
server/app/dice/helper/AdminScopeHelper.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace app\dice\helper;
|
||||||
|
|
||||||
|
use plugin\saiadmin\app\model\system\SystemUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员数据范围辅助类
|
||||||
|
* 用于获取当前管理员及其部门下属管理员可访问的数据范围
|
||||||
|
*/
|
||||||
|
class AdminScopeHelper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取当前管理员可访问的 admin_id 列表
|
||||||
|
* 超级管理员(id=1) 返回 null 表示不限制
|
||||||
|
* 普通管理员返回其本人及部门下属管理员的 id 列表
|
||||||
|
*
|
||||||
|
* @param array|null $adminInfo 当前登录管理员信息(含 id、deptList)
|
||||||
|
* @return int[]|null null=不限制(超级管理员),否则为可访问的 admin_id 数组
|
||||||
|
*/
|
||||||
|
public static function getAllowedAdminIds(?array $adminInfo): ?array
|
||||||
|
{
|
||||||
|
if (empty($adminInfo) || !isset($adminInfo['id'])) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$adminId = (int) $adminInfo['id'];
|
||||||
|
if ($adminId <= 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$deptList = $adminInfo['deptList'] ?? [];
|
||||||
|
if (empty($deptList) || !isset($deptList['id'])) {
|
||||||
|
return [$adminId];
|
||||||
|
}
|
||||||
|
$query = SystemUser::field('id');
|
||||||
|
$query->auth($deptList);
|
||||||
|
$ids = $query->column('id');
|
||||||
|
return array_map('intval', $ids ?: []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对查询应用 admin_id 范围过滤
|
||||||
|
*
|
||||||
|
* @param object $query ThinkORM 查询对象
|
||||||
|
* @param array|null $adminInfo 当前登录管理员信息
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function applyAdminScope($query, ?array $adminInfo): void
|
||||||
|
{
|
||||||
|
$allowedIds = self::getAllowedAdminIds($adminInfo);
|
||||||
|
if ($allowedIds === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (empty($allowedIds)) {
|
||||||
|
$query->whereRaw('1=0');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$query->whereIn('admin_id', $allowedIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -73,8 +73,10 @@ class DicePlayerWalletRecordLogic extends BaseLogic
|
|||||||
|
|
||||||
DicePlayer::where('id', $playerId)->update(['coin' => $walletAfter]);
|
DicePlayer::where('id', $playerId)->update(['coin' => $walletAfter]);
|
||||||
|
|
||||||
|
$playerAdminId = ($player->admin_id ?? null) ? (int) $player->admin_id : null;
|
||||||
$record = [
|
$record = [
|
||||||
'player_id' => $playerId,
|
'player_id' => $playerId,
|
||||||
|
'admin_id' => $playerAdminId,
|
||||||
'coin' => $type === 3 ? $coin : -$coin,
|
'coin' => $type === 3 ? $coin : -$coin,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'wallet_before' => $walletBefore,
|
'wallet_before' => $walletBefore,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use think\model\relation\BelongsTo;
|
|||||||
*
|
*
|
||||||
* @property $id ID
|
* @property $id ID
|
||||||
* @property $player_id 玩家id
|
* @property $player_id 玩家id
|
||||||
|
* @property $admin_id 关联玩家所属管理员ID(DicePlayer.admin_id)
|
||||||
* @property $lottery_config_id 彩金池配置
|
* @property $lottery_config_id 彩金池配置
|
||||||
* @property $lottery_type 抽奖类型
|
* @property $lottery_type 抽奖类型
|
||||||
* @property $is_win 是否中大奖:豹子号[1,1,1,1,1]~[6,6,6,6,6]为1,否则0
|
* @property $is_win 是否中大奖:豹子号[1,1,1,1,1]~[6,6,6,6,6]为1,否则0
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ use app\dice\model\lottery_config\DiceLotteryConfig;
|
|||||||
* @property $password 密码
|
* @property $password 密码
|
||||||
* @property $status 状态
|
* @property $status 状态
|
||||||
* @property $coin 平台币
|
* @property $coin 平台币
|
||||||
|
* @property $admin_id 创建该玩家的后台管理员ID,关联 sa_system_user.id
|
||||||
* @property $lottery_config_id 彩金池配置ID(0或null时使用自定义权重*_weight)
|
* @property $lottery_config_id 彩金池配置ID(0或null时使用自定义权重*_weight)
|
||||||
* @property $t1_weight T1池权重
|
* @property $t1_weight T1池权重
|
||||||
* @property $t2_weight T2池权重
|
* @property $t2_weight T2池权重
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use think\model\relation\BelongsTo;
|
|||||||
*
|
*
|
||||||
* @property $id ID
|
* @property $id ID
|
||||||
* @property $player_id 玩家id
|
* @property $player_id 玩家id
|
||||||
|
* @property $admin_id 关联玩家所属管理员ID(DicePlayer.admin_id)
|
||||||
* @property $use_coins 消耗硬币
|
* @property $use_coins 消耗硬币
|
||||||
* @property $total_ticket_count 总抽奖次数
|
* @property $total_ticket_count 总抽奖次数
|
||||||
* @property $paid_ticket_count 购买抽奖次数
|
* @property $paid_ticket_count 购买抽奖次数
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use think\model\relation\BelongsTo;
|
|||||||
*
|
*
|
||||||
* @property $id ID
|
* @property $id ID
|
||||||
* @property $player_id 用户id
|
* @property $player_id 用户id
|
||||||
|
* @property $admin_id 关联玩家所属管理员ID(DicePlayer.admin_id)
|
||||||
* @property $coin 平台币变化
|
* @property $coin 平台币变化
|
||||||
* @property $type 类型:0=充值 1=提现 2=购买抽奖次数
|
* @property $type 类型:0=充值 1=提现 2=购买抽奖次数
|
||||||
* @property $wallet_before 钱包操作前
|
* @property $wallet_before 钱包操作前
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ Route::group('/core', function () {
|
|||||||
fastRoute('dice/player/DicePlayer', \app\dice\controller\player\DicePlayerController::class);
|
fastRoute('dice/player/DicePlayer', \app\dice\controller\player\DicePlayerController::class);
|
||||||
Route::put('/dice/player/DicePlayer/updateStatus', [\app\dice\controller\player\DicePlayerController::class, 'updateStatus']);
|
Route::put('/dice/player/DicePlayer/updateStatus', [\app\dice\controller\player\DicePlayerController::class, 'updateStatus']);
|
||||||
Route::get('/dice/player/DicePlayer/getLotteryConfigOptions', [\app\dice\controller\player\DicePlayerController::class, 'getLotteryConfigOptions']);
|
Route::get('/dice/player/DicePlayer/getLotteryConfigOptions', [\app\dice\controller\player\DicePlayerController::class, 'getLotteryConfigOptions']);
|
||||||
|
Route::get('/dice/player/DicePlayer/getSystemUserOptions', [\app\dice\controller\player\DicePlayerController::class, 'getSystemUserOptions']);
|
||||||
fastRoute('dice/play_record/DicePlayRecord', \app\dice\controller\play_record\DicePlayRecordController::class);
|
fastRoute('dice/play_record/DicePlayRecord', \app\dice\controller\play_record\DicePlayRecordController::class);
|
||||||
Route::get('/dice/play_record/DicePlayRecord/getPlayerOptions', [\app\dice\controller\play_record\DicePlayRecordController::class, 'getPlayerOptions']);
|
Route::get('/dice/play_record/DicePlayRecord/getPlayerOptions', [\app\dice\controller\play_record\DicePlayRecordController::class, 'getPlayerOptions']);
|
||||||
Route::get('/dice/play_record/DicePlayRecord/getLotteryConfigOptions', [\app\dice\controller\play_record\DicePlayRecordController::class, 'getLotteryConfigOptions']);
|
Route::get('/dice/play_record/DicePlayRecord/getLotteryConfigOptions', [\app\dice\controller\play_record\DicePlayRecordController::class, 'getLotteryConfigOptions']);
|
||||||
|
|||||||
Reference in New Issue
Block a user