重构DiceLotteryConfig为DiceLotteryPoolConfig
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// | saiadmin [ saiadmin?????? ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\player;
|
||||
|
||||
use app\dice\helper\AdminScopeHelper;
|
||||
use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\player\DicePlayerLogic;
|
||||
@@ -17,12 +17,12 @@ use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 大富翁-玩家控制器
|
||||
* ???-?????
|
||||
*/
|
||||
class DicePlayerController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
* ????
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -32,14 +32,14 @@ class DicePlayerController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取彩金池配置选项(DiceLotteryConfig.id、name),供前端 lottery_config_id 下拉使用
|
||||
* ??????????DiceLotteryPoolConfig.id?name????? lottery_config_id ????
|
||||
* @param Request $request
|
||||
* @return Response 返回 [ ['id' => int, 'name' => string], ... ]
|
||||
* @return Response ?? [ ['id' => int, 'name' => string], ... ]
|
||||
*/
|
||||
#[Permission('大富翁-玩家列表', 'dice:player:index:index')]
|
||||
#[Permission('???-????', 'dice:player:index:index')]
|
||||
public function getLotteryConfigOptions(Request $request): Response
|
||||
{
|
||||
$list = DiceLotteryConfig::field('id,name')->order('id', 'asc')->select();
|
||||
$list = DiceLotteryPoolConfig::field('id,name')->order('id', 'asc')->select();
|
||||
$data = $list->map(function ($item) {
|
||||
return ['id' => (int) $item['id'], 'name' => (string) ($item['name'] ?? '')];
|
||||
})->toArray();
|
||||
@@ -47,12 +47,12 @@ class DicePlayerController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取后台管理员选项(SystemUser.id、username、realname),供 admin_id 下拉使用
|
||||
* 根据当前登录用户权限过滤(超级管理员可见全部,普通管理员按部门)
|
||||
* ??????????SystemUser.id?username?realname??? admin_id ????
|
||||
* ????????????????????????????????
|
||||
* @param Request $request
|
||||
* @return Response 返回 [ ['id' => int, 'username' => string, 'realname' => string], ... ]
|
||||
* @return Response ?? [ ['id' => int, 'username' => string, 'realname' => string], ... ]
|
||||
*/
|
||||
#[Permission('大富翁-玩家列表', 'dice:player:index:index')]
|
||||
#[Permission('???-????', 'dice:player:index:index')]
|
||||
public function getSystemUserOptions(Request $request): Response
|
||||
{
|
||||
$query = SystemUser::field('id,username,realname')->where('status', 1)->order('id', 'asc');
|
||||
@@ -76,11 +76,11 @@ class DicePlayerController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* ????
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家列表', 'dice:player:index:index')]
|
||||
#[Permission('???-????', 'dice:player:index:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
@@ -93,60 +93,60 @@ class DicePlayerController extends BaseController
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
AdminScopeHelper::applyAdminScope($query, $this->adminInfo ?? null);
|
||||
$query->with(['diceLotteryConfig']);
|
||||
$query->with(['diceLotteryPoolConfig']);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* ????
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家读取', 'dice:player:index:read')]
|
||||
#[Permission('???-????', 'dice:player:index:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if (!$model) {
|
||||
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('无权限查看该玩家');
|
||||
return $this->fail('????????');
|
||||
}
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* ????
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家添加', 'dice:player:index:save')]
|
||||
#[Permission('???-????', 'dice:player:index:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$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);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
return $this->success('????');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
return $this->fail('????');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* ????
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家修改', 'dice:player:index:update')]
|
||||
#[Permission('???-????', 'dice:player:index:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
@@ -155,55 +155,55 @@ class DicePlayerController extends BaseController
|
||||
if ($model) {
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
if ($allowedIds !== null && !in_array((int) ($model->admin_id ?? 0), $allowedIds, true)) {
|
||||
return $this->fail('无权限修改该玩家');
|
||||
return $this->fail('????????');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
return $this->success('????');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
return $this->fail('????');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅更新状态(列表内开关用)
|
||||
* ?????????????
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家修改', 'dice:player:index:update')]
|
||||
#[Permission('???-????', 'dice:player:index:update')]
|
||||
public function updateStatus(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id');
|
||||
$status = $request->input('status');
|
||||
if ($id === null || $id === '') {
|
||||
return $this->fail('缺少 id');
|
||||
return $this->fail('?? id');
|
||||
}
|
||||
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('无权限修改该玩家');
|
||||
return $this->fail('????????');
|
||||
}
|
||||
}
|
||||
$this->logic->edit($id, ['status' => (int) $status]);
|
||||
return $this->success('修改成功');
|
||||
return $this->success('????');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* ????
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('大富翁-玩家删除', 'dice:player:index:destroy')]
|
||||
#[Permission('???-????', 'dice:player:index:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
return $this->fail('?????????');
|
||||
}
|
||||
$ids = is_array($ids) ? $ids : explode(',', (string) $ids);
|
||||
$allowedIds = AdminScopeHelper::getAllowedAdminIds($this->adminInfo ?? null);
|
||||
@@ -218,14 +218,14 @@ class DicePlayerController extends BaseController
|
||||
}
|
||||
$ids = $validIds;
|
||||
if (empty($ids)) {
|
||||
return $this->fail('无权限删除所选玩家');
|
||||
return $this->fail('?????????');
|
||||
}
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
return $this->success('????');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
return $this->fail('????');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user