重构DiceLotteryConfig为DiceLotteryPoolConfig

This commit is contained in:
2026-03-10 17:56:14 +08:00
parent 1a748745cb
commit 54aa0bd34f
22 changed files with 160 additions and 160 deletions

View File

@@ -4,12 +4,12 @@
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\dice\controller\lottery_config;
namespace app\dice\controller\lottery_pool_config;
use app\dice\model\lottery_config\DiceLotteryConfig;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use plugin\saiadmin\basic\BaseController;
use app\dice\logic\lottery_config\DiceLotteryConfigLogic;
use app\dice\validate\lottery_config\DiceLotteryConfigValidate;
use app\dice\logic\lottery_pool_config\DiceLotteryPoolConfigLogic;
use app\dice\validate\lottery_pool_config\DiceLotteryPoolConfigValidate;
use plugin\saiadmin\service\Permission;
use support\Request;
use support\Response;
@@ -17,27 +17,27 @@ use support\Response;
/**
* 色子奖池配置控制器
*/
class DiceLotteryConfigController extends BaseController
class DiceLotteryPoolConfigController extends BaseController
{
/**
* 构造函数
*/
public function __construct()
{
$this->logic = new DiceLotteryConfigLogic();
$this->validate = new DiceLotteryConfigValidate;
$this->logic = new DiceLotteryPoolConfigLogic();
$this->validate = new DiceLotteryPoolConfigValidate;
parent::__construct();
}
/**
* 获取 DiceLotteryConfig 列表数据,仅含 id、name用于 lottery_config_id 下拉(值为 id显示为 name
* 获取 DiceLotteryPoolConfig 列表数据,仅含 id、name用于 lottery_config_id 下拉(值为 id显示为 name
* @param Request $request
* @return Response 返回 [ ['id' => int, 'name' => string], ... ]
*/
#[Permission('色子奖池配置列表', 'dice:lottery_config:index:index')]
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
public function getOptions(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();
@@ -49,7 +49,7 @@ class DiceLotteryConfigController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('色子奖池配置列表', 'dice:lottery_config:index:index')]
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
public function index(Request $request): Response
{
$where = $request->more([
@@ -66,7 +66,7 @@ class DiceLotteryConfigController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('色子奖池配置读取', 'dice:lottery_config:index:read')]
#[Permission('色子奖池配置读取', 'dice:lottery_pool_config:index:read')]
public function read(Request $request): Response
{
$id = $request->input('id', '');
@@ -84,7 +84,7 @@ class DiceLotteryConfigController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('色子奖池配置添加', 'dice:lottery_config:index:save')]
#[Permission('色子奖池配置添加', 'dice:lottery_pool_config:index:save')]
public function save(Request $request): Response
{
$data = $request->post();
@@ -102,7 +102,7 @@ class DiceLotteryConfigController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('色子奖池配置修改', 'dice:lottery_config:index:update')]
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:update')]
public function update(Request $request): Response
{
$data = $request->post();
@@ -120,7 +120,7 @@ class DiceLotteryConfigController extends BaseController
* @param Request $request
* @return Response
*/
#[Permission('色子奖池配置删除', 'dice:lottery_config:index:destroy')]
#[Permission('色子奖池配置删除', 'dice:lottery_pool_config:index:destroy')]
public function destroy(Request $request): Response
{
$ids = $request->post('ids', '');
@@ -139,7 +139,7 @@ class DiceLotteryConfigController extends BaseController
* 获取当前彩金池Redis 实例化,无则按 type=0 创建)
* 返回含 profit_amount 实时值,供前端轮询展示
*/
#[Permission('色子奖池配置列表', 'dice:lottery_config:index:index')]
#[Permission('色子奖池配置列表', 'dice:lottery_pool_config:index:index')]
public function getCurrentPool(Request $request): Response
{
$data = $this->logic->getCurrentPool();
@@ -149,7 +149,7 @@ class DiceLotteryConfigController extends BaseController
/**
* 更新当前彩金池:仅可修改 safety_line、t1_weightt5_weight不可修改 profit_amount
*/
#[Permission('色子奖池配置修改', 'dice:lottery_config:index:update')]
#[Permission('色子奖池配置修改', 'dice:lottery_pool_config:index:update')]
public function updateCurrentPool(Request $request): Response
{
$data = $request->post();

View File

@@ -11,7 +11,7 @@ use plugin\saiadmin\basic\BaseController;
use app\dice\logic\play_record\DicePlayRecordLogic;
use app\dice\validate\play_record\DicePlayRecordValidate;
use app\dice\model\player\DicePlayer;
use app\dice\model\lottery_config\DiceLotteryConfig;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\reward_config\DiceRewardConfig;
use plugin\saiadmin\service\Permission;
use support\Request;
@@ -58,7 +58,7 @@ class DicePlayRecordController extends BaseController
$query->with([
'dicePlayer',
'diceRewardConfig',
'diceLotteryConfig',
'diceLotteryPoolConfig',
]);
$data = $this->logic->getList($query);
return $this->success($data);
@@ -85,7 +85,7 @@ class DicePlayRecordController extends BaseController
#[Permission('玩家抽奖记录列表', 'dice:play_record:index:index')]
public function getLotteryConfigOptions(Request $request): Response
{
$list = DiceLotteryConfig::field('id,name')->select();
$list = DiceLotteryPoolConfig::field('id,name')->select();
$data = $list->map(function ($item) {
return ['id' => $item['id'], 'name' => $item['name'] ?? ''];
})->toArray();

View File

@@ -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.idname),供前端 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.idusernamerealname),供 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('????');
}
}

View File

@@ -4,9 +4,9 @@
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\dice\logic\lottery_config;
namespace app\dice\logic\lottery_pool_config;
use app\dice\model\lottery_config\DiceLotteryConfig;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use plugin\saiadmin\basic\think\BaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
@@ -15,7 +15,7 @@ use support\think\Cache;
/**
* 色子奖池配置逻辑层
*/
class DiceLotteryConfigLogic extends BaseLogic
class DiceLotteryPoolConfigLogic extends BaseLogic
{
/** Redis 当前彩金池type=0 实例key无则按 type=0 创建 */
private const REDIS_KEY_CURRENT_POOL = 'api:game:lottery_pool:default';
@@ -27,7 +27,7 @@ class DiceLotteryConfigLogic extends BaseLogic
*/
public function __construct()
{
$this->model = new DiceLotteryConfig();
$this->model = new DiceLotteryPoolConfig();
}
/**
@@ -41,13 +41,13 @@ class DiceLotteryConfigLogic extends BaseLogic
if ($cached && is_string($cached)) {
$data = json_decode($cached, true);
if (is_array($data)) {
$config = DiceLotteryConfig::find($data['id'] ?? 0);
$config = DiceLotteryPoolConfig::find($data['id'] ?? 0);
$ev = $config && isset($config->ev) ? (float) $config->ev : (float) ($data['profit_amount'] ?? 0);
$data['profit_amount'] = $ev;
return $data;
}
}
$config = DiceLotteryConfig::where('type', 0)->find();
$config = DiceLotteryPoolConfig::where('type', 0)->find();
if (!$config) {
throw new ApiException('未找到 type=0 的奖池配置,请先创建');
}
@@ -77,7 +77,7 @@ class DiceLotteryConfigLogic extends BaseLogic
{
$pool = $this->getCurrentPool();
$id = (int) $pool['id'];
$config = DiceLotteryConfig::find($id);
$config = DiceLotteryPoolConfig::find($id);
if (!$config) {
throw new ApiException('奖池配置不存在');
}
@@ -95,9 +95,9 @@ class DiceLotteryConfigLogic extends BaseLogic
if (empty($update)) {
return;
}
DiceLotteryConfig::where('id', $id)->update($update);
DiceLotteryPoolConfig::where('id', $id)->update($update);
$pool = array_merge($pool, $update);
$refreshed = DiceLotteryConfig::find($id);
$refreshed = DiceLotteryPoolConfig::find($id);
$pool['profit_amount'] = $refreshed && isset($refreshed->ev) ? (float) $refreshed->ev : (float) ($pool['profit_amount'] ?? 0);
Cache::set(self::REDIS_KEY_CURRENT_POOL, json_encode($pool), self::EXPIRE);
}

View File

@@ -4,7 +4,7 @@
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\dice\model\lottery_config;
namespace app\dice\model\lottery_pool_config;
use plugin\saiadmin\basic\think\BaseModel;
@@ -27,7 +27,7 @@ use plugin\saiadmin\basic\think\BaseModel;
* @property $t5_weight T5池权重
* @property $ev 池子累计盈利(游戏结算时累加,仅展示不可编辑)
*/
class DiceLotteryConfig extends BaseModel
class DiceLotteryPoolConfig extends BaseModel
{
/**
* 数据表主键

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
namespace app\dice\model\play_record;
use app\dice\model\lottery_config\DiceLotteryConfig;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\player\DicePlayer;
use app\dice\model\reward_config\DiceRewardConfig;
use plugin\saiadmin\basic\think\BaseModel;
@@ -71,12 +71,12 @@ class DicePlayRecord extends BaseModel
}
/**
* 彩金配置
* 关联模型 diceLotteryConfig
* 彩金配置
* 关联模型 diceLotteryPoolConfig
*/
public function diceLotteryConfig(): BelongsTo
public function diceLotteryPoolConfig(): BelongsTo
{
return $this->belongsTo(DiceLotteryConfig::class, 'lottery_config_id', 'id');
return $this->belongsTo(DiceLotteryPoolConfig::class, 'lottery_config_id', 'id');
}
/** 按玩家用户名模糊dicePlayer.username */
@@ -93,13 +93,13 @@ class DicePlayRecord extends BaseModel
}
}
/** 按彩金池配置名称模糊diceLotteryConfig.name */
/** 按彩金池配置名称模糊diceLotteryPoolConfig.name */
public function searchLotteryConfigNameAttr($query, $value)
{
if ($value === '' || $value === null) {
return;
}
$ids = DiceLotteryConfig::where('name', 'like', '%' . $value . '%')->column('id');
$ids = DiceLotteryPoolConfig::where('name', 'like', '%' . $value . '%')->column('id');
if (!empty($ids)) {
$query->whereIn('lottery_config_id', $ids);
} else {

View File

@@ -7,7 +7,7 @@
namespace app\dice\model\player;
use plugin\saiadmin\basic\think\BaseModel;
use app\dice\model\lottery_config\DiceLotteryConfig;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
/**
* 大富翁-玩家模型
@@ -78,14 +78,14 @@ class DicePlayer extends BaseModel
if ($name === null || $name === '') {
$model->setAttr('name', $uid);
}
// 创建玩家时:未指定则自动保存 lottery_config_id 为 DiceLotteryConfig type=0 的 id没有则为 0
// 创建玩家时:未指定则自动保存 lottery_config_id 为 DiceLotteryPoolConfig type=0 的 id没有则为 0
try {
$lotteryConfigId = $model->getAttr('lottery_config_id');
} catch (\Throwable $e) {
$lotteryConfigId = null;
}
if ($lotteryConfigId === null || $lotteryConfigId === '' || (int) $lotteryConfigId === 0) {
$config = DiceLotteryConfig::where('type', 0)->find();
$config = DiceLotteryPoolConfig::where('type', 0)->find();
$model->setAttr('lottery_config_id', $config ? (int) $config->id : 0);
}
// 彩金池权重默认取 type=0 的奖池配置
@@ -93,11 +93,11 @@ class DicePlayer extends BaseModel
}
/**
* 从 DiceLotteryConfig type=0 取 t1_weightt5_weight 作为玩家未设置时的默认值
* 从 DiceLotteryPoolConfig type=0 取 t1_weightt5_weight 作为玩家未设置时的默认值
*/
protected static function setDefaultWeightsFromLotteryConfig(DicePlayer $model): void
{
$config = DiceLotteryConfig::where('type', 0)->find();
$config = DiceLotteryPoolConfig::where('type', 0)->find();
if (!$config) {
return;
}
@@ -185,8 +185,8 @@ class DicePlayer extends BaseModel
/**
* 关联彩金池配置
*/
public function diceLotteryConfig()
public function diceLotteryPoolConfig()
{
return $this->belongsTo(DiceLotteryConfig::class, 'lottery_config_id', 'id');
return $this->belongsTo(DiceLotteryPoolConfig::class, 'lottery_config_id', 'id');
}
}

View File

@@ -4,14 +4,14 @@
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\dice\validate\lottery_config;
namespace app\dice\validate\lottery_pool_config;
use plugin\saiadmin\basic\BaseValidate;
/**
* 色子奖池配置验证器
*/
class DiceLotteryConfigValidate extends BaseValidate
class DiceLotteryPoolConfigValidate extends BaseValidate
{
/**
* 定义验证规则