重构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

@@ -5,24 +5,24 @@ import request from '@/utils/http'
*/
export default {
/**
* DiceLotteryConfig
* DiceLotteryPoolConfig
* @param params
* @returns
*/
list(params: Record<string, any>) {
return request.get<Api.Common.ApiPage>({
url: '/dice/lottery_config/DiceLotteryConfig/index',
url: '/dice/lottery_pool_config/DiceLotteryPoolConfig/index',
params
})
},
/**
* DiceLotteryConfig idname lottery_config_id
* @returns DiceLotteryConfig['id','name']
* DiceLotteryPoolConfig idname lottery_config_id
* @returns DiceLotteryPoolConfig['id','name']
*/
async getOptions(): Promise<Array<{ id: number; name: string }>> {
const res = await request.get<any>({
url: '/dice/lottery_config/DiceLotteryConfig/getOptions'
url: '/dice/lottery_pool_config/DiceLotteryPoolConfig/getOptions'
})
const rows = (res?.data ?? []) as Array<{ id: number; name: string }>
return Array.isArray(rows)
@@ -37,7 +37,7 @@ export default {
*/
read(id: number | string) {
return request.get<Api.Common.ApiData>({
url: '/dice/lottery_config/DiceLotteryConfig/read?id=' + id
url: '/dice/lottery_pool_config/DiceLotteryPoolConfig/read?id=' + id
})
},
@@ -48,7 +48,7 @@ export default {
*/
save(params: Record<string, any>) {
return request.post<any>({
url: '/dice/lottery_config/DiceLotteryConfig/save',
url: '/dice/lottery_pool_config/DiceLotteryPoolConfig/save',
data: params
})
},
@@ -60,7 +60,7 @@ export default {
*/
update(params: Record<string, any>) {
return request.put<any>({
url: '/dice/lottery_config/DiceLotteryConfig/update',
url: '/dice/lottery_pool_config/DiceLotteryPoolConfig/update',
data: params
})
},
@@ -72,7 +72,7 @@ export default {
*/
delete(params: Record<string, any>) {
return request.del<any>({
url: '/dice/lottery_config/DiceLotteryConfig/destroy',
url: '/dice/lottery_pool_config/DiceLotteryPoolConfig/destroy',
data: params
})
},
@@ -92,7 +92,7 @@ export default {
t5_weight: number
profit_amount: number
}>({
url: '/dice/lottery_config/DiceLotteryConfig/getCurrentPool'
url: '/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool'
})
},
@@ -108,7 +108,7 @@ export default {
t5_weight?: number
}) {
return request.post<any>({
url: '/dice/lottery_config/DiceLotteryConfig/updateCurrentPool',
url: '/dice/lottery_pool_config/DiceLotteryPoolConfig/updateCurrentPool',
data: params
})
}

View File

@@ -74,7 +74,7 @@ export default {
},
/**
* 获取彩金池配置选项DiceLotteryConfig.id、name供 lottery_config_id 下拉使用
* 获取彩金池配置选项DiceLotteryPoolConfig.id、name供 lottery_config_id 下拉使用
* @returns [ { id, name } ]
*/
async getLotteryConfigOptions(): Promise<Array<{ id: number; name: string }>> {

View File

@@ -8,7 +8,7 @@
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
<template #left>
<ElButton
v-permission="'dice:lottery_config:index:index'"
v-permission="'dice:lottery_pool_config:index:index'"
type="primary"
@click="showCurrentPoolDialog"
>
@@ -34,12 +34,12 @@
<template #operation="{ row }">
<div class="flex gap-2">
<SaButton
v-permission="'dice:lottery_config:index:update'"
v-permission="'dice:lottery_pool_config:index:update'"
type="secondary"
@click="showDialog('edit', row)"
/>
<!-- <SaButton-->
<!-- v-permission="'dice:lottery_config:index:destroy'"-->
<!-- v-permission="'dice:lottery_pool_config:index:destroy'"-->
<!-- type="error"-->
<!-- @click="deleteRow(row, api.delete, refreshData)"-->
<!-- />-->
@@ -63,7 +63,7 @@
<script setup lang="ts">
import { useTable } from '@/hooks/core/useTable'
import { useSaiAdmin } from '@/composables/useSaiAdmin'
import api from '../../api/lottery_config/index'
import api from '../../api/lottery_pool_config/index'
import TableSearch from './modules/table-search.vue'
import EditDialog from './modules/edit-dialog.vue'
import CurrentPoolDialog from './modules/current-pool-dialog.vue'

View File

@@ -64,7 +64,7 @@
</template>
<script setup lang="ts">
import api from '../../../api/lottery_config/index'
import api from '../../../api/lottery_pool_config/index'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'

View File

@@ -78,7 +78,7 @@
</template>
<script setup lang="ts">
import api from '../../../api/lottery_config/index'
import api from '../../../api/lottery_pool_config/index'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'

View File

@@ -133,7 +133,7 @@
const usernameFormatter = (row: Record<string, any>) =>
row?.dicePlayer?.username ?? row?.player_id ?? '-'
const lotteryConfigNameFormatter = (row: Record<string, any>) =>
row?.diceLotteryConfig?.name ?? row?.lottery_config_id ?? '-'
row?.diceLotteryPoolConfig?.name ?? row?.lottery_config_id ?? '-'
const rewardTierFormatter = (row: Record<string, any>) =>
row?.diceRewardConfig?.tier ?? row?.reward_config_id ?? '-'

View File

@@ -1,10 +1,10 @@
<template>
<div class="art-full-height">
<!-- 搜索面板 -->
<!-- ???? -->
<TableSearch v-model="searchForm" @search="handleSearch" @reset="resetSearchParams" />
<ElCard class="art-table-card" shadow="never">
<!-- 表格头部 -->
<!-- ???? -->
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
<template #left>
<ElSpace wrap>
@@ -12,7 +12,7 @@
<template #icon>
<ArtSvgIcon icon="ri:add-fill" />
</template>
新增
??
</ElButton>
<ElButton
v-permission="'dice:player:index:destroy'"
@@ -23,13 +23,13 @@
<template #icon>
<ArtSvgIcon icon="ri:delete-bin-5-line" />
</template>
删除
??
</ElButton>
</ElSpace>
</template>
</ArtTableHeader>
<!-- 表格 -->
<!-- ?? -->
<ArtTable
ref="tableRef"
rowKey="id"
@@ -42,7 +42,7 @@
@pagination:size-change="handleSizeChange"
@pagination:current-change="handleCurrentChange"
>
<!-- 状态开关直接修改 -->
<!-- ????????? -->
<template #status="{ row }">
<ElSwitch
v-permission="'dice:player:index:update'"
@@ -51,7 +51,7 @@
@change="(v: string | number | boolean) => handleStatusChange(row, v ? 1 : 0)"
/>
</template>
<!-- 平台币tag 可点击打开钱包操作弹窗 -->
<!-- ????tag ??????????? -->
<template #coin="{ row }">
<ElTag
type="info"
@@ -62,7 +62,7 @@
{{ row.coin ?? 0 }}
</ElTag>
</template>
<!-- 操作列 -->
<!-- ??? -->
<template #operation="{ row }">
<div class="flex gap-2">
<SaButton
@@ -80,7 +80,7 @@
</ArtTable>
</ElCard>
<!-- 编辑弹窗 -->
<!-- ???? -->
<EditDialog
v-model="dialogVisible"
:dialog-type="dialogType"
@@ -88,7 +88,7 @@
@success="refreshData"
/>
<!-- 钱包操作弹窗加点/扣点 -->
<!-- ?????????/??? -->
<WalletOperateDialog
v-model="walletDialogVisible"
:player="walletOperatePlayer"
@@ -105,7 +105,7 @@
import EditDialog from './modules/edit-dialog.vue'
import WalletOperateDialog from './modules/WalletOperateDialog.vue'
// 搜索表单
// ????
const searchForm = ref({
username: undefined,
name: undefined,
@@ -115,23 +115,23 @@
lottery_config_id: undefined
})
// 搜索处理
// ????
const handleSearch = (params: Record<string, any>) => {
Object.assign(searchParams, params)
getData()
}
// 权重列带 % formatterColumnOption.formatter 仅接收 row
// ???? % ? formatter?ColumnOption.formatter ??? row?
const weightFormatter = (prop: string) => (row: any) => {
const cellValue = row[prop]
return cellValue != null && cellValue !== '' ? `${cellValue}%` : '-'
}
// 彩金池配置列:lottery_config_id 关联 DiceLotteryConfig,显示 name
// ???????lottery_config_id ?? DiceLotteryPoolConfig??? name
const lotteryConfigNameFormatter = (row: any) =>
row?.diceLotteryConfig?.name ?? (row?.lottery_config_id ? `#${row.lottery_config_id}` : '自定义')
row?.diceLotteryPoolConfig?.name ?? (row?.lottery_config_id ? `#${row.lottery_config_id}` : '???')
// 表格配置
// ????
const {
columns,
columnChecks,
@@ -150,73 +150,73 @@
apiFn: api.list,
columnsFactory: () => [
{ type: 'selection' },
{ prop: 'username', label: '用户名', align: 'center' },
{ prop: 'phone', label: '手机号', align: 'center' },
{ prop: 'name', label: '昵称', align: 'center' },
{ prop: 'username', label: '???', align: 'center' },
{ prop: 'phone', label: '???', align: 'center' },
{ prop: 'name', label: '??', align: 'center' },
{
prop: 'status',
label: '状态',
label: '??',
width: 88,
align: 'center',
useSlot: true
},
{
prop: 'coin',
label: '平台币',
label: '???',
width: 100,
align: 'center',
useSlot: true
},
{
prop: 'lottery_config_id',
label: '彩金池配置',
label: '?????',
width: 120,
align: 'center',
formatter: (row: any) => lotteryConfigNameFormatter(row)
},
{
prop: 't1_weight',
label: 'T1池权重',
label: 'T1???',
width: 80,
align: 'center',
formatter: weightFormatter('t1_weight')
},
{
prop: 't2_weight',
label: 'T2池权重',
label: 'T2???',
width: 100,
align: 'center',
formatter: weightFormatter('t2_weight')
},
{
prop: 't3_weight',
label: 'T3池权重',
label: 'T3???',
width: 100,
align: 'center',
formatter: weightFormatter('t3_weight')
},
{
prop: 't4_weight',
label: 'T4池权重',
label: 'T4???',
width: 100,
align: 'center',
formatter: weightFormatter('t4_weight')
},
{
prop: 't5_weight',
label: 'T5池权重',
label: 'T5???',
width: 100,
align: 'center',
formatter: weightFormatter('t5_weight')
},
{ prop: 'total_ticket_count', label: '总抽奖次数', align: 'center' },
{ prop: 'paid_ticket_count', label: '购买抽奖次数', align: 'center' },
{ prop: 'free_ticket_count', label: '赠送抽奖次数', align: 'center' },
{ prop: 'create_time', label: '创建时间', align: 'center' },
{ prop: 'update_time', label: '更新时间', align: 'center' },
{ prop: 'total_ticket_count', label: '?????', align: 'center' },
{ prop: 'paid_ticket_count', label: '??????', align: 'center' },
{ prop: 'free_ticket_count', label: '??????', align: 'center' },
{ prop: 'create_time', label: '????', align: 'center' },
{ prop: 'update_time', label: '????', align: 'center' },
{
prop: 'operation',
label: '操作',
label: '??',
width: 100,
align: 'center',
fixed: 'right',
@@ -226,7 +226,7 @@
}
})
// 状态开关切换(列表内直接修改)
// ???????????????
const handleStatusChange = async (row: Record<string, any>, status: number) => {
row._statusLoading = true
try {
@@ -239,7 +239,7 @@
}
}
// 编辑配置
// ????
const {
dialogType,
dialogVisible,
@@ -251,7 +251,7 @@
selectedRows
} = useSaiAdmin()
// 钱包操作弹窗(从平台币 tag 点击打开)
// ??????????? tag ?????
const walletDialogVisible = ref(false)
type WalletPlayer = { id: number; username?: string; coin?: number }
const walletOperatePlayer = ref<WalletPlayer | null>(null)

View File

@@ -170,7 +170,7 @@
<script setup lang="ts">
import api from '../../../api/player/index'
import lotteryConfigApi from '../../../api/lottery_config/index'
import lotteryConfigApi from '../../../api/lottery_pool_config/index'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'

View File

@@ -79,7 +79,7 @@
const isExpanded = ref<boolean>(false)
const lotteryConfigOptions = ref<Array<{ id: number; name: string }>>([])
/** 从玩家控制器获取 DiceLotteryConfig id/name 列表,用于 lottery_config_id 筛选 */
/** 从玩家控制器获取 DiceLotteryPoolConfig id/name 列表,用于 lottery_config_id 筛选 */
onMounted(async () => {
try {
lotteryConfigOptions.value = await api.getLotteryConfigOptions()

View File

@@ -5,7 +5,7 @@ namespace app\api\logic;
use app\api\cache\UserCache;
use app\api\service\LotteryService;
use app\dice\model\lottery_config\DiceLotteryConfig;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\play_record\DicePlayRecord;
use app\dice\model\player\DicePlayer;
use app\dice\model\player_ticket_record\DicePlayerTicketRecord;
@@ -70,8 +70,8 @@ class PlayStartLogic
$lotteryService = LotteryService::getOrCreate($playerId);
$ticketType = LotteryService::drawTicketType($paid, $free);
$config = $ticketType === self::LOTTERY_TYPE_PAID
? ($lotteryService->getConfigType0Id() ? DiceLotteryConfig::find($lotteryService->getConfigType0Id()) : null)
: ($lotteryService->getConfigType1Id() ? DiceLotteryConfig::find($lotteryService->getConfigType1Id()) : null);
? ($lotteryService->getConfigType0Id() ? DiceLotteryPoolConfig::find($lotteryService->getConfigType0Id()) : null)
: ($lotteryService->getConfigType1Id() ? DiceLotteryPoolConfig::find($lotteryService->getConfigType1Id()) : null);
if (!$config) {
throw new ApiException('奖池配置不存在');
}
@@ -232,7 +232,7 @@ class PlayStartLogic
// 累加彩金池盈利额度(累加值为 -real_ev。若 dice_lottery_config 表有 ev 字段则执行
try {
DiceLotteryConfig::where('id', $configId)->update([
DiceLotteryPoolConfig::where('id', $configId)->update([
'ev' => Db::raw('IFNULL(ev,0) - ' . (float) $realEv),
]);
} catch (\Throwable $_) {

View File

@@ -3,7 +3,7 @@ declare(strict_types=1);
namespace app\api\service;
use app\dice\model\lottery_config\DiceLotteryConfig;
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
use app\dice\model\player\DicePlayer;
use support\think\Cache;
@@ -37,7 +37,7 @@ class LotteryService
return self::REDIS_KEY_START_INDEX . $playerId;
}
/** 从 Redis 加载或根据玩家与 DiceLotteryConfig 创建并保存 */
/** 从 Redis 加载或根据玩家与 DiceLotteryPoolConfig 创建并保存 */
public static function getOrCreate(int $playerId): self
{
$key = self::getRedisKey($playerId);
@@ -56,8 +56,8 @@ class LotteryService
if (!$player) {
throw new \RuntimeException('玩家不存在');
}
$config0 = DiceLotteryConfig::where('type', 0)->find();
$config1 = DiceLotteryConfig::where('type', 1)->find();
$config0 = DiceLotteryPoolConfig::where('type', 0)->find();
$config1 = DiceLotteryPoolConfig::where('type', 1)->find();
$s = new self($playerId);
$s->configType0Id = $config0 ? (int) $config0->id : null;
$s->configType1Id = $config1 ? (int) $config1->id : null;
@@ -84,7 +84,7 @@ class LotteryService
}
/** 根据奖池配置的 t1_weight..t5_weight 权重随机抽取档位 T1-T5 */
public static function drawTierByWeights(DiceLotteryConfig $config): string
public static function drawTierByWeights(DiceLotteryPoolConfig $config): string
{
$tiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
$weights = [

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
{
/**
* 定义验证规则

View File

@@ -18,7 +18,7 @@ abstract class AbstractLogic implements LogicInterface
* 模型注入
* @var object
*/
protected $model;
public $model;
/**
* 管理员信息

View File

@@ -105,10 +105,10 @@ Route::group('/core', function () {
fastRoute('dice/reward_config/DiceRewardConfig', \app\dice\controller\reward_config\DiceRewardConfigController::class);
Route::get('/dice/reward_config/DiceRewardConfig/weightRatioList', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'weightRatioList']);
Route::post('/dice/reward_config/DiceRewardConfig/batchUpdateWeights', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'batchUpdateWeights']);
fastRoute('dice/lottery_config/DiceLotteryConfig', \app\dice\controller\lottery_config\DiceLotteryConfigController::class);
Route::get('/dice/lottery_config/DiceLotteryConfig/getOptions', [\app\dice\controller\lottery_config\DiceLotteryConfigController::class, 'getOptions']);
Route::get('/dice/lottery_config/DiceLotteryConfig/getCurrentPool', [\app\dice\controller\lottery_config\DiceLotteryConfigController::class, 'getCurrentPool']);
Route::post('/dice/lottery_config/DiceLotteryConfig/updateCurrentPool', [\app\dice\controller\lottery_config\DiceLotteryConfigController::class, 'updateCurrentPool']);
fastRoute('dice/lottery_pool_config/DiceLotteryPoolConfig', \app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class);
Route::get('/dice/lottery_pool_config/DiceLotteryPoolConfig/getOptions', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'getOptions']);
Route::get('/dice/lottery_pool_config/DiceLotteryPoolConfig/getCurrentPool', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'getCurrentPool']);
Route::post('/dice/lottery_pool_config/DiceLotteryPoolConfig/updateCurrentPool', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'updateCurrentPool']);
// 数据表维护
Route::get("/database/index", [\plugin\saiadmin\app\controller\system\DataBaseController::class, 'index']);