[色子游戏]玩家抽奖记录测试数据
This commit is contained in:
@@ -143,10 +143,10 @@ export const defaultResponseAdapter = <T>(response: unknown): ApiResponse<T> =>
|
||||
total = extractTotal(res, records, tableConfig.totalFields)
|
||||
pagination = extractPagination(res)
|
||||
|
||||
// 如果没有找到,检查嵌套data
|
||||
// 如果没有找到,检查嵌套 data(如 ThinkPHP paginate: { data: { total, per_page, current_page, data: [] } })
|
||||
if (records.length === 0 && 'data' in res && typeof res.data === 'object') {
|
||||
const data = res.data as Record<string, unknown>
|
||||
records = extractRecords(data, ['list', 'records', 'items'])
|
||||
records = extractRecords(data, ['list', 'data', 'records', 'items'])
|
||||
total = extractTotal(data, records, tableConfig.totalFields)
|
||||
pagination = extractPagination(res, data)
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import request from '@/utils/http'
|
||||
|
||||
/**
|
||||
* 玩家抽奖记录(测试数据) API接口
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* 获取数据列表
|
||||
* @param params 搜索参数
|
||||
* @returns 数据列表
|
||||
*/
|
||||
list(params: Record<string, any>) {
|
||||
return request.get<Api.Common.ApiPage>({
|
||||
url: '/core/dice/play_record_test/DicePlayRecordTest/index',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param id 数据ID
|
||||
* @returns 数据详情
|
||||
*/
|
||||
read(id: number | string) {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/core/dice/play_record_test/DicePlayRecordTest/read?id=' + id
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 创建数据
|
||||
* @param params 数据参数
|
||||
* @returns 执行结果
|
||||
*/
|
||||
save(params: Record<string, any>) {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/play_record_test/DicePlayRecordTest/save',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param params 数据参数
|
||||
* @returns 执行结果
|
||||
*/
|
||||
update(params: Record<string, any>) {
|
||||
return request.put<any>({
|
||||
url: '/core/dice/play_record_test/DicePlayRecordTest/update',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param id 数据ID
|
||||
* @returns 执行结果
|
||||
*/
|
||||
delete(params: Record<string, any>) {
|
||||
return request.del<any>({
|
||||
url: '/core/dice/play_record_test/DicePlayRecordTest/destroy',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 一键删除所有测试数据
|
||||
*/
|
||||
clearAll() {
|
||||
return request.post<any>({
|
||||
url: '/core/dice/play_record_test/DicePlayRecordTest/clearAll'
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -57,5 +57,32 @@ export default {
|
||||
url: '/core/dice/reward/DiceReward/batchUpdateWeightsByDirection',
|
||||
data: { direction, items }
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 一键测试权重:创建测试记录并启动后台执行,返回 record_id 用于轮询进度
|
||||
*/
|
||||
startWeightTest(params: { lottery_config_id: number; s_count: number; n_count: number }) {
|
||||
return request.post<{ record_id: number }>({
|
||||
url: '/core/dice/reward/DiceReward/startWeightTest',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 查询一键测试进度
|
||||
*/
|
||||
getTestProgress(recordId: number) {
|
||||
return request.get<{
|
||||
total_play_count: number
|
||||
over_play_count: number
|
||||
status: number
|
||||
remark: string | null
|
||||
result_counts: Record<number, number> | null
|
||||
tier_counts: Record<string, number> | null
|
||||
}>({
|
||||
url: '/core/dice/reward/DiceReward/getTestProgress',
|
||||
params: { record_id: recordId }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,263 @@
|
||||
<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>
|
||||
<span v-if="totalWinCoin !== null" class="table-summary-inline">
|
||||
测试数据玩家总收益(游戏总亏损):<strong>{{ totalWinCoin }}</strong>
|
||||
</span>
|
||||
<ElSpace wrap class="table-toolbar-buttons">
|
||||
<ElButton
|
||||
v-permission="'dice:play_record_test:index:save'"
|
||||
@click="showDialog('add')"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:add-fill" />
|
||||
</template>
|
||||
新增
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-permission="'dice:play_record_test:index:destroy'"
|
||||
:disabled="selectedRows.length === 0"
|
||||
@click="deleteSelectedRows(api.delete, refreshData)"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:delete-bin-5-line" />
|
||||
</template>
|
||||
删除
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-permission="'dice:play_record_test:index:destroy'"
|
||||
type="danger"
|
||||
plain
|
||||
@click="handleClearAll"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:delete-bin-2-line" />
|
||||
</template>
|
||||
一键删除所有数据
|
||||
</ElButton>
|
||||
</ElSpace>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
|
||||
<!-- 表格 -->
|
||||
<ArtTable
|
||||
ref="tableRef"
|
||||
rowKey="id"
|
||||
:loading="loading"
|
||||
:data="data"
|
||||
:columns="columns"
|
||||
:pagination="pagination"
|
||||
@sort-change="handleSortChange"
|
||||
@selection-change="handleSelectionChange"
|
||||
@pagination:size-change="handleSizeChange"
|
||||
@pagination:current-change="handleCurrentChange"
|
||||
>
|
||||
<!-- 彩金池配置:显示 DiceLotteryPoolConfig.name -->
|
||||
<template #lottery_config_id="{ row }">
|
||||
<ElTag size="small">{{ lotteryConfigNameFormatter(row) }}</ElTag>
|
||||
</template>
|
||||
<!-- 抽奖类型 -->
|
||||
<template #lottery_type="{ row }">
|
||||
<ElTag size="small" :type="row.lottery_type === 0 ? 'warning' : 'success'">
|
||||
{{ row.lottery_type === 0 ? '付费' : row.lottery_type === 1 ? '赠送' : '-' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 是否中大奖 -->
|
||||
<template #is_win="{ row }">
|
||||
<ElTag size="small" :type="row.is_win === 1 ? 'success' : 'info'">
|
||||
{{ row.is_win === 0 ? '无' : row.is_win === 1 ? '中大奖' : '-' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 方向 -->
|
||||
<template #direction="{ row }">
|
||||
<ElTag size="small" :type="row.direction === 0 ? 'primary' : 'warning'">
|
||||
{{ row.direction === 0 ? '顺时针' : row.direction === 1 ? '逆时针' : '-' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 摇取点数 -->
|
||||
<template #roll_array="{ row }">
|
||||
<ElTag size="small">
|
||||
{{ formatRollArray(row.roll_array) }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 奖励档位:显示 DiceRewardConfig.tier -->
|
||||
<template #reward_config_id="{ row }">
|
||||
<ElTag size="small">{{ rewardTierFormatter(row) }}</ElTag>
|
||||
</template>
|
||||
<!-- 状态 -->
|
||||
<template #status="{ row }">
|
||||
<ElTag size="small" :type="row.status === 1 ? 'success' : 'info'">
|
||||
{{ row.status === 1 ? '成功' : '失败' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 操作列 -->
|
||||
<template #operation="{ row }">
|
||||
<div class="flex gap-2">
|
||||
<SaButton
|
||||
v-permission="'dice:play_record_test:index:update'"
|
||||
type="secondary"
|
||||
@click="showDialog('edit', row)"
|
||||
/>
|
||||
<SaButton
|
||||
v-permission="'dice:play_record_test:index:destroy'"
|
||||
type="error"
|
||||
@click="deleteRow(row, api.delete, refreshData)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</ArtTable>
|
||||
</ElCard>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<EditDialog
|
||||
v-model="dialogVisible"
|
||||
:dialog-type="dialogType"
|
||||
:data="dialogData"
|
||||
@success="refreshData"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useTable } from '@/hooks/core/useTable'
|
||||
import { useSaiAdmin } from '@/composables/useSaiAdmin'
|
||||
import api from '../../api/play_record_test/index'
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
import EditDialog from './modules/edit-dialog.vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
// 搜索表单(与 play_record 对齐:方向、赢取平台币范围、是否中大奖、中奖档位)
|
||||
const searchForm = ref<Record<string, unknown>>({
|
||||
lottery_type: undefined,
|
||||
direction: undefined,
|
||||
is_win: undefined,
|
||||
win_coin_min: undefined,
|
||||
win_coin_max: undefined,
|
||||
reward_tier: undefined
|
||||
})
|
||||
|
||||
// 当前页 win_coin 汇总(玩家总盈利 = 游戏总亏损)
|
||||
const totalWinCoin = ref<number | null>(null)
|
||||
|
||||
const listApi = async (params: Record<string, any>) => {
|
||||
const res = await api.list(params)
|
||||
totalWinCoin.value = (res as any)?.total_win_coin ?? null
|
||||
return res
|
||||
}
|
||||
|
||||
const lotteryConfigNameFormatter = (row: Record<string, any>) =>
|
||||
row?.diceLotteryPoolConfig?.name ?? row?.lottery_config_id ?? '-'
|
||||
const rewardTierFormatter = (row: Record<string, any>) =>
|
||||
row?.diceRewardConfig?.tier ?? row?.reward_config_id ?? '-'
|
||||
|
||||
/** 摇取点数格式化为 1,3,4,5,6 */
|
||||
function formatRollArray(val: unknown): string {
|
||||
if (val == null || val === '') return '-'
|
||||
if (Array.isArray(val)) return val.join(',')
|
||||
if (typeof val === 'string') {
|
||||
try {
|
||||
const arr = JSON.parse(val)
|
||||
return Array.isArray(arr) ? arr.join(',') : val
|
||||
} catch {
|
||||
return val
|
||||
}
|
||||
}
|
||||
return String(val)
|
||||
}
|
||||
|
||||
const handleClearAll = async () => {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定清空所有玩家抽奖测试数据?', '提示', {
|
||||
type: 'warning'
|
||||
})
|
||||
await api.clearAll()
|
||||
ElMessage.success('已清空所有测试数据')
|
||||
getData()
|
||||
} catch (e: any) {
|
||||
if (e !== 'cancel') {
|
||||
ElMessage.error(e?.message || '清空失败')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索处理
|
||||
const handleSearch = (params: Record<string, any>) => {
|
||||
Object.assign(searchParams, params)
|
||||
getData()
|
||||
}
|
||||
|
||||
// 表格配置
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
data,
|
||||
loading,
|
||||
getData,
|
||||
searchParams,
|
||||
pagination,
|
||||
resetSearchParams,
|
||||
handleSortChange,
|
||||
handleSizeChange,
|
||||
handleCurrentChange,
|
||||
refreshData
|
||||
} = useTable({
|
||||
core: {
|
||||
apiFn: listApi,
|
||||
columnsFactory: () => [
|
||||
{ type: 'selection' },
|
||||
{ prop: 'id', label: 'ID', width: 80 },
|
||||
{ prop: 'lottery_config_id', label: '彩金池配置', width: 120, useSlot: true },
|
||||
{ prop: 'lottery_type', label: '抽奖类型', width: 100, useSlot: true },
|
||||
{ prop: 'is_win', label: '是否中大奖', width: 100, useSlot: true },
|
||||
{ prop: 'win_coin', label: '赢取平台币', width: 110 },
|
||||
{ prop: 'super_win_coin', label: '中大奖平台币', width: 120 },
|
||||
{ prop: 'reward_win_coin', label: '摇色子中奖平台币', width: 140 },
|
||||
{ prop: 'direction', label: '方向', width: 90, useSlot: true },
|
||||
{ prop: 'start_index', label: '起始索引', width: 90 },
|
||||
{ prop: 'target_index', label: '终点索引', width: 90 },
|
||||
{ prop: 'roll_array', label: '摇取点数', width: 140, useSlot: true },
|
||||
{ prop: 'roll_number', label: '摇取点数和', width: 110, sortable: true },
|
||||
{ prop: 'reward_config_id', label: '奖励档位', width: 100, useSlot: true },
|
||||
{ prop: 'status', label: '状态', width: 80, useSlot: true },
|
||||
{ prop: 'create_time', label: '创建时间', width: 170 },
|
||||
{ prop: 'operation', label: '操作', width: 100, fixed: 'right', useSlot: true }
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
// 编辑配置
|
||||
const {
|
||||
dialogType,
|
||||
dialogVisible,
|
||||
dialogData,
|
||||
showDialog,
|
||||
deleteRow,
|
||||
deleteSelectedRows,
|
||||
handleSelectionChange,
|
||||
selectedRows
|
||||
} = useSaiAdmin()
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.table-summary-inline {
|
||||
margin-right: 12px;
|
||||
font-size: 14px;
|
||||
color: var(--el-text-color-regular);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.table-summary-inline strong {
|
||||
color: var(--el-color-danger);
|
||||
}
|
||||
.table-toolbar-buttons {
|
||||
display: inline-flex;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,270 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
:title="dialogType === 'add' ? '新增玩家抽奖记录(测试数据)' : '编辑玩家抽奖记录(测试数据)'"
|
||||
width="600px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
@close="handleClose"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
||||
<el-form-item label="彩金池配置id" prop="lottery_config_id">
|
||||
<el-input v-model="formData.lottery_config_id" placeholder="请输入彩金池配置id" />
|
||||
</el-form-item>
|
||||
<el-form-item label="抽奖类型" prop="lottery_type">
|
||||
<el-select
|
||||
v-model="formData.lottery_type"
|
||||
placeholder="请选择"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option label="付费" :value="0" />
|
||||
<el-option label="赠送" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="方向" prop="direction">
|
||||
<el-select v-model="formData.direction" placeholder="请选择" clearable style="width: 100%">
|
||||
<el-option label="顺时针" :value="0" />
|
||||
<el-option label="逆时针" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否中大奖" prop="is_win">
|
||||
<el-select v-model="formData.is_win" placeholder="请选择" clearable style="width: 100%">
|
||||
<el-option label="无" :value="0" />
|
||||
<el-option label="中大奖" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="赢取平台币" prop="win_coin">
|
||||
<el-input-number
|
||||
v-model="formData.win_coin"
|
||||
placeholder="赢取平台币"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="中奖档位" prop="reward_tier">
|
||||
<el-select
|
||||
v-model="formData.reward_tier"
|
||||
placeholder="请选择档位(选后自动带出奖励配置ID)"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
@change="onRewardTierChange"
|
||||
>
|
||||
<el-option label="T1" value="T1" />
|
||||
<el-option label="T2" value="T2" />
|
||||
<el-option label="T3" value="T3" />
|
||||
<el-option label="T4" value="T4" />
|
||||
<el-option label="T5" value="T5" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="奖励配置id" prop="reward_config_id">
|
||||
<el-input
|
||||
v-model="formData.reward_config_id"
|
||||
placeholder="可选中奖档位自动带出或手动输入"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="起始索引" prop="start_index">
|
||||
<el-input v-model="formData.start_index" placeholder="请输入起始索引" />
|
||||
</el-form-item>
|
||||
<el-form-item label="结束索引" prop="target_index">
|
||||
<el-input v-model="formData.target_index" placeholder="请输入结束索引" />
|
||||
</el-form-item>
|
||||
<el-form-item label="摇取点数和" prop="roll_number">
|
||||
<el-input v-model="formData.roll_number" placeholder="请输入摇取点数和" />
|
||||
</el-form-item>
|
||||
<el-form-item label="摇取点数:[1,2,3,4,5,6]" prop="roll_array">
|
||||
<el-input v-model="formData.roll_array" placeholder="请输入摇取点数:[1,2,3,4,5,6]" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态:0=失败,1=成功" prop="status">
|
||||
<sa-radio v-model="formData.status" dict="data_status" />
|
||||
</el-form-item>
|
||||
<el-form-item label="中大奖平台币" prop="super_win_coin">
|
||||
<el-input v-model="formData.super_win_coin" placeholder="请输入中大奖平台币" />
|
||||
</el-form-item>
|
||||
<el-form-item label="摇色子中奖平台币" prop="reward_win_coin">
|
||||
<el-input v-model="formData.reward_win_coin" placeholder="请输入摇色子中奖平台币" />
|
||||
</el-form-item>
|
||||
<el-form-item label="所属管理员" prop="admin_id">
|
||||
<el-input v-model="formData.admin_id" placeholder="请输入所属管理员" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="handleClose">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/play_record_test/index'
|
||||
import rewardConfigApi from '../../../api/reward_config/index'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
dialogType: string
|
||||
data?: Record<string, any>
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: boolean): void
|
||||
(e: 'success'): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: false,
|
||||
dialogType: 'add',
|
||||
data: undefined
|
||||
})
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
/**
|
||||
* 弹窗显示状态双向绑定
|
||||
*/
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
/**
|
||||
* 表单验证规则
|
||||
*/
|
||||
const rules = reactive<FormRules>({
|
||||
lottery_config_id: [{ required: true, message: '彩金池配置id必需填写', trigger: 'blur' }],
|
||||
lottery_type: [{ required: true, message: '抽奖类型:0=付费,1=赠送必需填写', trigger: 'blur' }],
|
||||
is_win: [{ required: true, message: '中大奖:0=无,1=中奖必需填写', trigger: 'blur' }],
|
||||
direction: [{ required: true, message: '方向:0=顺时针,1=逆时针必需填写', trigger: 'blur' }],
|
||||
reward_config_id: [{ required: true, message: '奖励配置id必需填写', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '状态:0=失败,1=成功必需填写', trigger: 'blur' }]
|
||||
})
|
||||
|
||||
/**
|
||||
* 初始数据
|
||||
*/
|
||||
const initialFormData = {
|
||||
id: null,
|
||||
lottery_config_id: null,
|
||||
lottery_type: null,
|
||||
is_win: null,
|
||||
win_coin: 0,
|
||||
direction: null,
|
||||
reward_tier: undefined as string | undefined,
|
||||
reward_config_id: null,
|
||||
start_index: null,
|
||||
target_index: null,
|
||||
roll_number: null,
|
||||
roll_array: '',
|
||||
status: 1,
|
||||
super_win_coin: '0.00',
|
||||
reward_win_coin: '0.00',
|
||||
admin_id: null
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单数据
|
||||
*/
|
||||
const formData = reactive({ ...initialFormData })
|
||||
|
||||
/**
|
||||
* 监听弹窗打开,初始化表单数据
|
||||
*/
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newVal) => {
|
||||
if (newVal) {
|
||||
initPage()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* 初始化页面数据
|
||||
*/
|
||||
const initPage = async () => {
|
||||
// 先重置为初始值
|
||||
Object.assign(formData, initialFormData)
|
||||
// 如果有数据,则填充数据
|
||||
if (props.data) {
|
||||
await nextTick()
|
||||
initForm()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化表单数据
|
||||
*/
|
||||
const initForm = () => {
|
||||
if (props.data) {
|
||||
for (const key in formData) {
|
||||
if (key === 'reward_tier') continue
|
||||
if (props.data[key] != null && props.data[key] !== undefined) {
|
||||
;(formData as Record<string, unknown>)[key] = props.data[key]
|
||||
}
|
||||
}
|
||||
if (typeof formData.win_coin === 'string') {
|
||||
formData.win_coin = parseFloat(formData.win_coin) || 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 中奖档位变更:按档位拉取奖励配置并取第一条的 id 填入 reward_config_id
|
||||
*/
|
||||
async function onRewardTierChange(tier: string) {
|
||||
if (!tier) {
|
||||
formData.reward_config_id = null
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await rewardConfigApi.list({
|
||||
saiType: 'all',
|
||||
tier: tier
|
||||
})
|
||||
const list = (res as any)?.data ?? (Array.isArray(res) ? res : [])
|
||||
const first = Array.isArray(list) ? list[0] : (list?.data?.[0] ?? list?.[0])
|
||||
if (first && first.id != null) {
|
||||
formData.reward_config_id = first.id
|
||||
} else {
|
||||
formData.reward_config_id = null
|
||||
}
|
||||
} catch {
|
||||
formData.reward_config_id = null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭弹窗并重置表单
|
||||
*/
|
||||
const handleClose = () => {
|
||||
visible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交表单
|
||||
*/
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
const payload = { ...formData }
|
||||
delete (payload as Record<string, unknown>).reward_tier
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(payload)
|
||||
ElMessage.success('新增成功')
|
||||
} else {
|
||||
await api.update(payload)
|
||||
ElMessage.success('修改成功')
|
||||
}
|
||||
emit('success')
|
||||
handleClose()
|
||||
} catch (error) {
|
||||
console.log('表单验证失败:', error)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,129 @@
|
||||
<template>
|
||||
<sa-search-bar
|
||||
ref="searchBarRef"
|
||||
v-model="formData"
|
||||
label-width="120px"
|
||||
:showExpand="false"
|
||||
@reset="handleReset"
|
||||
@search="handleSearch"
|
||||
@expand="handleExpand"
|
||||
>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="抽奖类型" prop="lottery_type">
|
||||
<el-select v-model="formData.lottery_type" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="付费" :value="0" />
|
||||
<el-option label="赠送" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="方向" prop="direction">
|
||||
<el-select v-model="formData.direction" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="顺时针" :value="0" />
|
||||
<el-option label="逆时针" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="是否中大奖" prop="is_win">
|
||||
<el-select v-model="formData.is_win" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="无" :value="0" />
|
||||
<el-option label="中大奖" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="赢取平台币" prop="win_coin_min">
|
||||
<div class="range-wrap">
|
||||
<el-input-number
|
||||
v-model="formData.win_coin_min"
|
||||
placeholder="最小"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
class="range-input"
|
||||
/>
|
||||
<span class="range-sep">至</span>
|
||||
<el-input-number
|
||||
v-model="formData.win_coin_max"
|
||||
placeholder="最大"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
class="range-input"
|
||||
/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="中奖档位" prop="reward_tier">
|
||||
<el-select v-model="formData.reward_tier" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="T1" value="T1" />
|
||||
<el-option label="T2" value="T2" />
|
||||
<el-option label="T3" value="T3" />
|
||||
<el-option label="T4" value="T4" />
|
||||
<el-option label="T5" value="T5" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</sa-search-bar>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface Props {
|
||||
modelValue: Record<string, any>
|
||||
}
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: Record<string, any>): void
|
||||
(e: 'search', params: Record<string, any>): void
|
||||
(e: 'reset'): void
|
||||
}
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
const isExpanded = ref<boolean>(false)
|
||||
|
||||
const searchBarRef = ref()
|
||||
const formData = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (val) => emit('update:modelValue', val)
|
||||
})
|
||||
|
||||
function handleReset() {
|
||||
searchBarRef.value?.ref.resetFields()
|
||||
emit('reset')
|
||||
}
|
||||
|
||||
async function handleSearch() {
|
||||
emit('search', formData.value)
|
||||
}
|
||||
|
||||
function handleExpand(expanded: boolean) {
|
||||
isExpanded.value = expanded
|
||||
}
|
||||
|
||||
const setSpan = (span: number) => ({
|
||||
span,
|
||||
xs: 24,
|
||||
sm: span >= 12 ? span : 12,
|
||||
md: span >= 8 ? span : 8,
|
||||
lg: span,
|
||||
xl: span
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.range-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.range-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.range-sep {
|
||||
color: var(--el-text-color-secondary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -21,6 +21,13 @@
|
||||
>
|
||||
权重配比
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-permission="'dice:reward:index:index'"
|
||||
@click="weightTestVisible = true"
|
||||
v-ripple
|
||||
>
|
||||
一键测试权重
|
||||
</ElButton>
|
||||
</ElSpace>
|
||||
</template>
|
||||
</ArtTableHeader>
|
||||
@@ -39,6 +46,7 @@
|
||||
</ElCard>
|
||||
|
||||
<WeightRatioDialog v-model="weightRatioVisible" @success="refreshData" />
|
||||
<WeightTestDialog v-model="weightTestVisible" @success="refreshData" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -47,9 +55,11 @@
|
||||
import api from '../../api/reward/index'
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
import WeightRatioDialog from './modules/weight-ratio-dialog.vue'
|
||||
import WeightTestDialog from './modules/weight-test-dialog.vue'
|
||||
|
||||
const currentDirection = ref<0 | 1>(0)
|
||||
const weightRatioVisible = ref(false)
|
||||
const weightTestVisible = ref(false)
|
||||
|
||||
const searchForm = ref<Record<string, unknown>>({
|
||||
direction: 0,
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
<template>
|
||||
<ElDialog
|
||||
v-model="visible"
|
||||
title="一键测试权重"
|
||||
width="520px"
|
||||
:close-on-click-modal="false"
|
||||
destroy-on-close
|
||||
@close="onClose"
|
||||
>
|
||||
<ElForm ref="formRef" :model="form" label-width="140px" :disabled="running">
|
||||
<ElFormItem label="测试数据档位类型" prop="lottery_config_id" required>
|
||||
<ElSelect
|
||||
v-model="form.lottery_config_id"
|
||||
placeholder="请选择奖池配置"
|
||||
filterable
|
||||
style="width: 100%"
|
||||
>
|
||||
<ElOption
|
||||
v-for="item in lotteryOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="顺时针方向次数" prop="s_count" required>
|
||||
<ElSelect v-model="form.s_count" placeholder="请选择" style="width: 100%">
|
||||
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="逆时针方向次数" prop="n_count" required>
|
||||
<ElSelect v-model="form.n_count" placeholder="请选择" style="width: 100%">
|
||||
<ElOption v-for="c in countOptions" :key="c" :label="String(c)" :value="c" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
|
||||
<template #footer>
|
||||
<ElButton @click="visible = false">取消</ElButton>
|
||||
<ElButton type="primary" :loading="running" @click="handleStart">开始测试</ElButton>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/reward/index'
|
||||
import lotteryPoolApi from '../../../api/lottery_pool_config/index'
|
||||
|
||||
const countOptions = [100, 500, 1000, 5000]
|
||||
|
||||
const visible = defineModel<boolean>({ default: false })
|
||||
const emit = defineEmits<{ (e: 'success'): void }>()
|
||||
|
||||
const formRef = ref()
|
||||
const form = reactive({
|
||||
lottery_config_id: undefined as number | undefined,
|
||||
s_count: 100,
|
||||
n_count: 100
|
||||
})
|
||||
const lotteryOptions = ref<Array<{ id: number; name: string }>>([])
|
||||
const running = ref(false)
|
||||
|
||||
function onClose() {
|
||||
running.value = false
|
||||
}
|
||||
|
||||
async function loadLotteryOptions() {
|
||||
try {
|
||||
const list = await lotteryPoolApi.getOptions()
|
||||
lotteryOptions.value = list.map((r: { id: number; name: string }) => ({ id: r.id, name: r.name }))
|
||||
if (list.length && !form.lottery_config_id) {
|
||||
form.lottery_config_id = list[0].id
|
||||
}
|
||||
} catch (_) {
|
||||
lotteryOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
async function handleStart() {
|
||||
if (!form.lottery_config_id) {
|
||||
ElMessage.warning('请选择测试数据档位类型')
|
||||
return
|
||||
}
|
||||
running.value = true
|
||||
try {
|
||||
await api.startWeightTest({
|
||||
lottery_config_id: form.lottery_config_id,
|
||||
s_count: form.s_count,
|
||||
n_count: form.n_count
|
||||
})
|
||||
ElMessage.success('测试任务已创建,后台将自动执行。请在【玩家抽奖记录(测试数据)】中查看生成的测试数据')
|
||||
visible.value = false
|
||||
emit('success')
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '创建测试任务失败')
|
||||
} finally {
|
||||
running.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(visible, (v) => {
|
||||
if (v) {
|
||||
loadLotteryOptions()
|
||||
} else {
|
||||
onClose()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@@ -168,7 +168,19 @@
|
||||
columnsFactory: () => [
|
||||
{ type: 'selection' },
|
||||
{ prop: 'id', label: 'ID', width: 80, align: 'center' },
|
||||
{ prop: 'test_count', label: '测试次数', width: 100, align: 'center' },
|
||||
{
|
||||
prop: 'status',
|
||||
label: '状态',
|
||||
width: 90,
|
||||
align: 'center',
|
||||
formatter: (row: Record<string, any>) =>
|
||||
row.status === 1 ? '完成' : row.status === -1 ? '失败' : '待完成'
|
||||
},
|
||||
{ prop: 's_count', label: '顺时针次数', width: 110, align: 'center' },
|
||||
{ prop: 'n_count', label: '逆时针次数', width: 110, align: 'center' },
|
||||
{ prop: 'test_count', label: '测试总次数', width: 110, align: 'center' },
|
||||
{ prop: 'over_play_count', label: '完成次数', width: 110, align: 'center' },
|
||||
{ prop: 'lottery_config_id', label: '奖池配置ID', width: 110, align: 'center' },
|
||||
{
|
||||
prop: 'admin_name',
|
||||
label: '管理员',
|
||||
@@ -190,6 +202,13 @@
|
||||
align: 'center',
|
||||
useSlot: true
|
||||
},
|
||||
{
|
||||
prop: 'remark',
|
||||
label: '备注',
|
||||
minWidth: 140,
|
||||
align: 'center',
|
||||
showOverflowTooltip: true
|
||||
},
|
||||
{ prop: 'create_time', label: '创建时间', width: 170, align: 'center' },
|
||||
{
|
||||
prop: 'operation',
|
||||
|
||||
@@ -427,4 +427,98 @@ class PlayStartLogic
|
||||
}
|
||||
return $this->generateRollArrayFromSum($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟一局抽奖(不写库、不扣玩家),用于权重测试写入 dice_play_record_test
|
||||
* @param \app\dice\model\lottery_pool_config\DiceLotteryPoolConfig $config 奖池配置
|
||||
* @param int $direction 0=顺时针 1=逆时针
|
||||
* @return array 可直接用于 DicePlayRecordTest::create 的字段 + tier(用于统计档位概率)
|
||||
*/
|
||||
public function simulateOnePlay($config, int $direction): array
|
||||
{
|
||||
$rewardInstance = DiceReward::getCachedInstance();
|
||||
$byTierDirection = $rewardInstance['by_tier_direction'] ?? [];
|
||||
$maxTierRetry = 10;
|
||||
$chosen = null;
|
||||
$tier = null;
|
||||
for ($tierAttempt = 0; $tierAttempt < $maxTierRetry; $tierAttempt++) {
|
||||
$tier = LotteryService::drawTierByWeights($config);
|
||||
$tierRewards = $byTierDirection[$tier][$direction] ?? [];
|
||||
if (empty($tierRewards)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$chosen = self::drawRewardByWeight($tierRewards);
|
||||
} catch (\RuntimeException $e) {
|
||||
if ($e->getMessage() === self::EXCEPTION_WEIGHT_ALL_ZERO) {
|
||||
continue;
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($chosen === null) {
|
||||
throw new \RuntimeException('模拟抽奖:无可用奖励配置');
|
||||
}
|
||||
|
||||
$startIndex = (int) ($chosen['start_index'] ?? 0);
|
||||
$targetIndex = (int) ($chosen['end_index'] ?? 0);
|
||||
$rollNumber = (int) ($chosen['grid_number'] ?? 0);
|
||||
$realEv = (float) ($chosen['real_ev'] ?? 0);
|
||||
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
|
||||
$rewardWinCoin = $isTierT5 ? $realEv : (100 + $realEv);
|
||||
|
||||
$superWinCoin = 0;
|
||||
$isWin = 0;
|
||||
if (in_array($rollNumber, self::SUPER_WIN_GRID_NUMBERS, true)) {
|
||||
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber);
|
||||
$alwaysSuperWin = in_array($rollNumber, self::SUPER_WIN_ALWAYS_GRID_NUMBERS, true);
|
||||
$doSuperWin = $alwaysSuperWin;
|
||||
if (!$doSuperWin) {
|
||||
$bigWinWeight = 10000;
|
||||
if ($bigWinConfig !== null && isset($bigWinConfig['weight'])) {
|
||||
$bigWinWeight = min(10000, max(0, (int) $bigWinConfig['weight']));
|
||||
}
|
||||
$roll = (random_int(0, PHP_INT_MAX - 1) / (float) PHP_INT_MAX);
|
||||
$doSuperWin = $bigWinWeight > 0 && $roll < ($bigWinWeight / 10000.0);
|
||||
}
|
||||
if ($doSuperWin) {
|
||||
$rollArray = $this->getSuperWinRollArray($rollNumber);
|
||||
$isWin = 1;
|
||||
$superWinCoin = ($bigWinConfig['real_ev'] ?? 0) > 0 ? (float) ($bigWinConfig['real_ev'] ?? 0) : self::SUPER_WIN_BONUS;
|
||||
$rewardWinCoin = 0;
|
||||
} else {
|
||||
$rollArray = $this->generateNonSuperWinRollArrayWithSum($rollNumber);
|
||||
}
|
||||
} else {
|
||||
$rollArray = $this->generateRollArrayFromSum($rollNumber);
|
||||
}
|
||||
|
||||
$winCoin = $superWinCoin + $rewardWinCoin;
|
||||
$configId = (int) $config->id;
|
||||
$rewardId = ($isWin === 1 && $superWinCoin > 0) ? 0 : $targetIndex;
|
||||
$configName = (string) ($config->name ?? '');
|
||||
|
||||
return [
|
||||
'player_id' => 0,
|
||||
'admin_id' => 0,
|
||||
'lottery_config_id' => $configId,
|
||||
'lottery_type' => self::LOTTERY_TYPE_PAID,
|
||||
'is_win' => $isWin,
|
||||
'win_coin' => $winCoin,
|
||||
'super_win_coin' => $superWinCoin,
|
||||
'reward_win_coin' => $rewardWinCoin,
|
||||
'use_coins' => 0,
|
||||
'direction' => $direction,
|
||||
'reward_config_id' => $rewardId,
|
||||
'start_index' => $startIndex,
|
||||
'target_index' => $targetIndex,
|
||||
'roll_array' => json_encode($rollArray),
|
||||
'roll_number' => array_sum($rollArray),
|
||||
'lottery_name' => $configName,
|
||||
'status' => self::RECORD_STATUS_SUCCESS,
|
||||
'tier' => $tier,
|
||||
'roll_number_for_count' => $rollNumber,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\play_record_test;
|
||||
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\play_record_test\DicePlayRecordTestLogic;
|
||||
use app\dice\validate\play_record_test\DicePlayRecordTestValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use support\think\Db;
|
||||
|
||||
/**
|
||||
* 玩家抽奖记录(测试数据)控制器
|
||||
*/
|
||||
class DicePlayRecordTestController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new DicePlayRecordTestLogic();
|
||||
$this->validate = new DicePlayRecordTestValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表,并在结果中附带当前筛选条件下所有测试数据的玩家总收益 total_win_coin(DicePlayRecordTest.win_coin 求和)
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家抽奖记录(测试数据)列表', 'dice:play_record_test:index:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['lottery_type', ''],
|
||||
['direction', ''],
|
||||
['is_win', ''],
|
||||
['win_coin_min', ''],
|
||||
['win_coin_max', ''],
|
||||
['reward_tier', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$query->with(['diceLotteryPoolConfig', 'diceRewardConfig']);
|
||||
|
||||
// 按当前筛选条件统计所有测试数据的总收益(游戏总亏损)
|
||||
$sumQuery = clone $query;
|
||||
$totalWinCoin = $sumQuery->sum('win_coin');
|
||||
|
||||
$data = $this->logic->getList($query);
|
||||
$data['total_win_coin'] = $totalWinCoin;
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家抽奖记录(测试数据)读取', 'dice:play_record_test:index:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家抽奖记录(测试数据)添加', 'dice:play_record_test:index:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家抽奖记录(测试数据)修改', 'dice:play_record_test:index:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家抽奖记录(测试数据)删除', 'dice:play_record_test:index:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键删除所有测试数据:清空 dice_play_record_test 表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家抽奖记录(测试数据)删除', 'dice:play_record_test:index:destroy')]
|
||||
public function clearAll(Request $request): Response
|
||||
{
|
||||
try {
|
||||
$table = (new \app\dice\model\play_record_test\DicePlayRecordTest())->getTable();
|
||||
Db::execute('TRUNCATE TABLE `' . $table . '`');
|
||||
return $this->success('已清空所有测试数据');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->fail('清空失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,12 @@
|
||||
namespace app\dice\controller\reward;
|
||||
|
||||
use app\dice\logic\reward\DiceRewardLogic;
|
||||
use app\dice\logic\reward_config_record\DiceRewardConfigRecordLogic;
|
||||
use app\dice\model\reward\DiceReward;
|
||||
use app\dice\model\play_record_test\DicePlayRecordTest;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use support\think\Db;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
@@ -74,6 +78,68 @@ class DiceRewardController extends BaseController
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键测试权重:创建测试记录并启动单进程后台执行,实时写入 dice_play_record_test,更新 dice_reward_config_record 进度
|
||||
* 参数:lottery_config_id 奖池配置,s_count 顺时针次数 100/500/1000/5000,n_count 逆时针次数 100/500/1000/5000
|
||||
*/
|
||||
#[Permission('奖励对照列表', 'dice:reward:index:index')]
|
||||
public function startWeightTest(Request $request): Response
|
||||
{
|
||||
$lotteryConfigId = (int) $request->post('lottery_config_id', 0);
|
||||
$sCount = (int) $request->post('s_count', 100);
|
||||
$nCount = (int) $request->post('n_count', 100);
|
||||
$adminId = isset($this->adminInfo['id']) ? (int) $this->adminInfo['id'] : null;
|
||||
try {
|
||||
$logic = new DiceRewardConfigRecordLogic();
|
||||
$recordId = $logic->createWeightTestRecord($lotteryConfigId, $sCount, $nCount, $adminId);
|
||||
// 由独立进程 WeightTestProcess 定时轮询 status=0 并执行,不占用 HTTP 资源
|
||||
return $this->success(['record_id' => $recordId]);
|
||||
} catch (\plugin\saiadmin\exception\ApiException $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询一键测试进度:total_play_count、over_play_count、status、remark
|
||||
*/
|
||||
#[Permission('奖励对照列表', 'dice:reward:index:index')]
|
||||
public function getTestProgress(Request $request): Response
|
||||
{
|
||||
$recordId = (int) $request->input('record_id', 0);
|
||||
if ($recordId <= 0) {
|
||||
return $this->fail('请传入 record_id');
|
||||
}
|
||||
$record = DiceRewardConfigRecord::find($recordId);
|
||||
if (!$record) {
|
||||
return $this->fail('记录不存在');
|
||||
}
|
||||
$arr = $record->toArray();
|
||||
$data = [
|
||||
'total_play_count' => (int) ($arr['total_play_count'] ?? 0),
|
||||
'over_play_count' => (int) ($arr['over_play_count'] ?? 0),
|
||||
'status' => (int) ($arr['status'] ?? 0),
|
||||
'remark' => $arr['remark'] ?? null,
|
||||
'result_counts' => $arr['result_counts'] ?? null,
|
||||
'tier_counts' => $arr['tier_counts'] ?? null,
|
||||
];
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键清空测试数据:清空 dice_play_record_test 表
|
||||
*/
|
||||
#[Permission('奖励对照列表', 'dice:reward:index:index')]
|
||||
public function clearPlayRecordTest(Request $request): Response
|
||||
{
|
||||
try {
|
||||
$table = (new DicePlayRecordTest())->getTable();
|
||||
Db::execute('TRUNCATE TABLE `' . $table . '`');
|
||||
return $this->success('已清空测试数据');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->fail('清空失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 权重编辑弹窗:按方向+点数批量更新权重(写入 dice_reward)
|
||||
* 参数:items: [{ grid_number, weight_clockwise, weight_counterclockwise }, ...]
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\play_record_test;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseLogic;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use plugin\saiadmin\utils\Helper;
|
||||
use app\dice\model\play_record_test\DicePlayRecordTest;
|
||||
|
||||
/**
|
||||
* 玩家抽奖记录(测试数据)逻辑层
|
||||
*/
|
||||
class DicePlayRecordTestLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new DicePlayRecordTest();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -141,4 +141,68 @@ class DiceRewardConfigRecordLogic extends BaseLogic
|
||||
DiceRewardConfig::refreshCache();
|
||||
DiceRewardConfig::clearRequestInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一键测试权重记录并返回 ID,供后台执行器写入 dice_play_record_test 并更新进度
|
||||
* @param int $lotteryConfigId 奖池配置 ID(DiceLotteryPoolConfig)
|
||||
* @param int $sCount 顺时针模拟次数 100/500/1000/5000
|
||||
* @param int $nCount 逆时针模拟次数 100/500/1000/5000
|
||||
* @param int|null $adminId 执行人
|
||||
* @return int 记录 ID
|
||||
* @throws ApiException
|
||||
*/
|
||||
public function createWeightTestRecord(int $lotteryConfigId, int $sCount, int $nCount, ?int $adminId = null): int
|
||||
{
|
||||
$allowed = [100, 500, 1000, 5000];
|
||||
if (!in_array($sCount, $allowed, true) || !in_array($nCount, $allowed, true)) {
|
||||
throw new ApiException('顺时针/逆时针次数仅支持 100、500、1000、5000');
|
||||
}
|
||||
$config = DiceLotteryPoolConfig::find($lotteryConfigId);
|
||||
if (!$config) {
|
||||
throw new ApiException('奖池配置不存在');
|
||||
}
|
||||
|
||||
$instance = DiceReward::getCachedInstance();
|
||||
$byTierDirection = $instance['by_tier_direction'] ?? [];
|
||||
$snapshot = [];
|
||||
foreach ($byTierDirection as $tier => $byDir) {
|
||||
foreach ($byDir as $dir => $rows) {
|
||||
foreach ($rows as $row) {
|
||||
$snapshot[] = [
|
||||
'id' => (int) ($row['id'] ?? 0),
|
||||
'grid_number' => (int) ($row['grid_number'] ?? 0),
|
||||
'tier' => (string) ($tier ?? ''),
|
||||
'weight' => (int) ($row['weight'] ?? 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$tierWeightsSnapshot = [
|
||||
'T1' => (int) ($config->t1_weight ?? 0),
|
||||
'T2' => (int) ($config->t2_weight ?? 0),
|
||||
'T3' => (int) ($config->t3_weight ?? 0),
|
||||
'T4' => (int) ($config->t4_weight ?? 0),
|
||||
'T5' => (int) ($config->t5_weight ?? 0),
|
||||
];
|
||||
$total = $sCount + $nCount;
|
||||
|
||||
$record = new DiceRewardConfigRecord();
|
||||
$record->test_count = $total;
|
||||
$record->weight_config_snapshot = $snapshot;
|
||||
$record->tier_weights_snapshot = $tierWeightsSnapshot;
|
||||
$record->lottery_config_id = $lotteryConfigId;
|
||||
$record->total_play_count = $total;
|
||||
$record->over_play_count = 0;
|
||||
$record->status = DiceRewardConfigRecord::STATUS_RUNNING;
|
||||
$record->remark = null;
|
||||
$record->s_count = $sCount;
|
||||
$record->n_count = $nCount;
|
||||
$record->result_counts = [];
|
||||
$record->tier_counts = null;
|
||||
$record->admin_id = $adminId;
|
||||
$record->create_time = date('Y-m-d H:i:s');
|
||||
$record->save();
|
||||
|
||||
return (int) $record->id;
|
||||
}
|
||||
}
|
||||
|
||||
156
server/app/dice/logic/reward_config_record/WeightTestRunner.php
Normal file
156
server/app/dice/logic/reward_config_record/WeightTestRunner.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\dice\logic\reward_config_record;
|
||||
|
||||
use app\api\logic\PlayStartLogic;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use app\dice\model\play_record_test\DicePlayRecordTest;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use support\Log;
|
||||
|
||||
/**
|
||||
* 一键测试权重:单进程后台执行模拟摇色子,写入 dice_play_record_test 并更新 dice_reward_config_record 进度
|
||||
*/
|
||||
class WeightTestRunner
|
||||
{
|
||||
private const BATCH_SIZE = 10;
|
||||
|
||||
/**
|
||||
* 执行指定测试记录:按 s_count(顺时针)+n_count(逆时针) 模拟,每 10 条写入一次测试表并更新进度
|
||||
* @param int $recordId dice_reward_config_record.id
|
||||
*/
|
||||
public function run(int $recordId): void
|
||||
{
|
||||
$record = DiceRewardConfigRecord::find($recordId);
|
||||
if (!$record) {
|
||||
Log::error("WeightTestRunner: 记录不存在 record_id={$recordId}");
|
||||
return;
|
||||
}
|
||||
|
||||
$sCount = (int) ($record->s_count ?? 0);
|
||||
$nCount = (int) ($record->n_count ?? 0);
|
||||
$total = $sCount + $nCount;
|
||||
if ($total <= 0) {
|
||||
$this->markFailed($recordId, 's_count + n_count 必须大于 0');
|
||||
return;
|
||||
}
|
||||
|
||||
$configId = (int) ($record->lottery_config_id ?? 0);
|
||||
$config = $configId > 0 ? DiceLotteryPoolConfig::find($configId) : DiceLotteryPoolConfig::where('type', 0)->find();
|
||||
if (!$config) {
|
||||
$this->markFailed($recordId, '奖池配置不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
$playLogic = new PlayStartLogic();
|
||||
$resultCounts = []; // grid_number => count
|
||||
$tierCounts = []; // tier => count
|
||||
$buffer = [];
|
||||
$done = 0;
|
||||
|
||||
try {
|
||||
for ($i = 0; $i < $sCount; $i++) {
|
||||
$row = $playLogic->simulateOnePlay($config, 0);
|
||||
$this->aggregate($row, $resultCounts, $tierCounts);
|
||||
$buffer[] = $this->rowForInsert($row);
|
||||
$done++;
|
||||
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
|
||||
}
|
||||
for ($i = 0; $i < $nCount; $i++) {
|
||||
$row = $playLogic->simulateOnePlay($config, 1);
|
||||
$this->aggregate($row, $resultCounts, $tierCounts);
|
||||
$buffer[] = $this->rowForInsert($row);
|
||||
$done++;
|
||||
$this->flushIfNeeded($buffer, $recordId, $done, $total, $resultCounts, $tierCounts);
|
||||
}
|
||||
if (!empty($buffer)) {
|
||||
$this->insertBuffer($buffer);
|
||||
$this->updateProgress($recordId, $done, $resultCounts, $tierCounts);
|
||||
}
|
||||
$this->markSuccess($recordId, $resultCounts, $tierCounts);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('WeightTestRunner exception: ' . $e->getMessage(), ['record_id' => $recordId, 'trace' => $e->getTraceAsString()]);
|
||||
$this->markFailed($recordId, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function aggregate(array $row, array &$resultCounts, array &$tierCounts): void
|
||||
{
|
||||
$grid = (int) ($row['roll_number_for_count'] ?? $row['roll_number'] ?? 0);
|
||||
if ($grid >= 5 && $grid <= 30) {
|
||||
$resultCounts[$grid] = ($resultCounts[$grid] ?? 0) + 1;
|
||||
}
|
||||
$tier = (string) ($row['tier'] ?? '');
|
||||
if ($tier !== '') {
|
||||
$tierCounts[$tier] = ($tierCounts[$tier] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private function rowForInsert(array $row): array
|
||||
{
|
||||
$out = [];
|
||||
$keys = [
|
||||
'player_id', 'admin_id', 'lottery_config_id', 'lottery_type', 'is_win', 'win_coin',
|
||||
'super_win_coin', 'reward_win_coin', 'use_coins', 'direction', 'reward_config_id',
|
||||
'start_index', 'target_index', 'roll_array', 'roll_number', 'lottery_name', 'status',
|
||||
];
|
||||
foreach ($keys as $k) {
|
||||
if (array_key_exists($k, $row)) {
|
||||
$out[$k] = $row[$k];
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
private function flushIfNeeded(array &$buffer, int $recordId, int $done, int $total, array $resultCounts, array $tierCounts): void
|
||||
{
|
||||
if (count($buffer) < self::BATCH_SIZE) {
|
||||
return;
|
||||
}
|
||||
$this->insertBuffer($buffer);
|
||||
$buffer = [];
|
||||
$this->updateProgress($recordId, $done, $resultCounts, $tierCounts);
|
||||
}
|
||||
|
||||
private function insertBuffer(array $rows): void
|
||||
{
|
||||
if (empty($rows)) {
|
||||
return;
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
DicePlayRecordTest::create($row);
|
||||
}
|
||||
}
|
||||
|
||||
private function updateProgress(int $recordId, int $overPlayCount, array $resultCounts, array $tierCounts): void
|
||||
{
|
||||
$record = DiceRewardConfigRecord::find($recordId);
|
||||
if ($record) {
|
||||
$record->over_play_count = $overPlayCount;
|
||||
$record->result_counts = $resultCounts;
|
||||
$record->tier_counts = $tierCounts;
|
||||
$record->save();
|
||||
}
|
||||
}
|
||||
|
||||
private function markSuccess(int $recordId, array $resultCounts, array $tierCounts): void
|
||||
{
|
||||
$record = DiceRewardConfigRecord::find($recordId);
|
||||
if ($record) {
|
||||
$record->status = DiceRewardConfigRecord::STATUS_SUCCESS;
|
||||
$record->result_counts = $resultCounts;
|
||||
$record->tier_counts = $tierCounts;
|
||||
$record->remark = null;
|
||||
$record->save();
|
||||
}
|
||||
}
|
||||
|
||||
private function markFailed(int $recordId, string $message): void
|
||||
{
|
||||
DiceRewardConfigRecord::where('id', $recordId)->update([
|
||||
'status' => DiceRewardConfigRecord::STATUS_FAIL,
|
||||
'remark' => mb_substr($message, 0, 500),
|
||||
]);
|
||||
}
|
||||
}
|
||||
122
server/app/dice/model/play_record_test/DicePlayRecordTest.php
Normal file
122
server/app/dice/model/play_record_test/DicePlayRecordTest.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\play_record_test;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
use app\dice\model\reward_config\DiceRewardConfig;
|
||||
use app\dice\model\lottery_pool_config\DiceLotteryPoolConfig;
|
||||
use think\model\relation\BelongsTo;
|
||||
|
||||
/**
|
||||
* 玩家抽奖记录(测试数据)模型
|
||||
*
|
||||
* dice_play_record_test 玩家抽奖记录(测试数据)
|
||||
*
|
||||
* @property $id ID
|
||||
* @property $lottery_config_id 彩金池配置id
|
||||
* @property $lottery_type 抽奖类型:0=付费,1=赠送
|
||||
* @property $is_win 中大奖:0=无,1=中奖
|
||||
* @property $win_coin 赢取平台币
|
||||
* @property $direction 方向:0=顺时针,1=逆时针
|
||||
* @property $reward_config_id 奖励配置id
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 修改时间
|
||||
* @property $start_index 起始索引
|
||||
* @property $target_index 结束索引
|
||||
* @property $roll_number 摇取点数和
|
||||
* @property $roll_array 摇取点数:[1,2,3,4,5,6]
|
||||
* @property $status 状态:0=失败,1=成功
|
||||
* @property $super_win_coin 中大奖平台币
|
||||
* @property $reward_win_coin 摇色子中奖平台币
|
||||
* @property $admin_id 所属管理员
|
||||
*/
|
||||
class DicePlayRecordTest extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 数据库表名称
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'dice_play_record_test';
|
||||
|
||||
/**
|
||||
* 彩金池配置
|
||||
* 关联 lottery_config_id -> DiceLotteryPoolConfig.id
|
||||
*/
|
||||
public function diceLotteryPoolConfig(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DiceLotteryPoolConfig::class, 'lottery_config_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 奖励配置(终点格 = target_index 对应 DiceRewardConfig.id,表中为 reward_config_id)
|
||||
* 关联 reward_config_id -> DiceRewardConfig.id
|
||||
*/
|
||||
public function diceRewardConfig(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DiceRewardConfig::class, 'reward_config_id', 'id');
|
||||
}
|
||||
|
||||
/** 抽奖类型 0=付费 1=赠送 */
|
||||
public function searchLotteryTypeAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('lottery_type', '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 方向 0=顺时针 1=逆时针 */
|
||||
public function searchDirectionAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('direction', '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 是否中大奖 0=无 1=中大奖 */
|
||||
public function searchIsWinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('is_win', '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 赢取平台币下限 */
|
||||
public function searchWinCoinMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('win_coin', '>=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 赢取平台币上限 */
|
||||
public function searchWinCoinMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('win_coin', '<=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 中奖档位(按 reward_config_id 对应 DiceRewardConfig.tier) */
|
||||
public function searchRewardTierAttr($query, $value)
|
||||
{
|
||||
if ($value === '' || $value === null) {
|
||||
return;
|
||||
}
|
||||
$ids = DiceRewardConfig::where('tier', '=', $value)->column('id');
|
||||
if (!empty($ids)) {
|
||||
$query->whereIn('reward_config_id', $ids);
|
||||
} else {
|
||||
$query->whereRaw('1=0');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,17 +18,31 @@ use plugin\saiadmin\basic\think\BaseModel;
|
||||
* @property array $weight_config_snapshot 测试时权重配比快照:按档位 id,grid_number,tier,weight
|
||||
* @property array $tier_weights_snapshot 测试时 T1-T5 档位权重快照(来自奖池配置)
|
||||
* @property int|null $lottery_config_id 测试时使用的奖池配置 ID
|
||||
* @property int $total_play_count 总模拟次数(s_count+n_count)
|
||||
* @property int $over_play_count 已完成次数
|
||||
* @property int $status 状态 -1失败 0进行中 1成功
|
||||
* @property string|null $remark 失败时记录原因
|
||||
* @property int $s_count 顺时针模拟次数
|
||||
* @property int $n_count 逆时针模拟次数
|
||||
* @property array $result_counts 落点统计 grid_number=>出现次数
|
||||
* @property array|null $tier_counts 档位出现次数 T1=>count
|
||||
* @property int|null $admin_id 执行测试的管理员ID
|
||||
* @property string|null $create_time 创建时间
|
||||
*/
|
||||
class DiceRewardConfigRecord extends BaseModel
|
||||
{
|
||||
/** 状态:失败 */
|
||||
public const STATUS_FAIL = -1;
|
||||
/** 状态:进行中 */
|
||||
public const STATUS_RUNNING = 0;
|
||||
/** 状态:成功 */
|
||||
public const STATUS_SUCCESS = 1;
|
||||
|
||||
protected $pk = 'id';
|
||||
|
||||
protected $table = 'dice_reward_config_record';
|
||||
|
||||
protected $json = ['weight_config_snapshot', 'tier_weights_snapshot', 'result_counts'];
|
||||
protected $json = ['weight_config_snapshot', 'tier_weights_snapshot', 'result_counts', 'tier_counts'];
|
||||
|
||||
protected $jsonAssoc = true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\validate\play_record_test;
|
||||
|
||||
use plugin\saiadmin\basic\BaseValidate;
|
||||
|
||||
/**
|
||||
* 玩家抽奖记录(测试数据)验证器
|
||||
*/
|
||||
class DicePlayRecordTestValidate extends BaseValidate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
*/
|
||||
protected $rule = [
|
||||
'lottery_config_id' => 'require',
|
||||
'lottery_type' => 'require',
|
||||
'is_win' => 'require',
|
||||
'direction' => 'require',
|
||||
'reward_config_id' => 'require',
|
||||
'status' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
*/
|
||||
protected $message = [
|
||||
'lottery_config_id' => '彩金池配置id必须填写',
|
||||
'lottery_type' => '抽奖类型:0=付费,1=赠送必须填写',
|
||||
'is_win' => '中大奖:0=无,1=中奖必须填写',
|
||||
'direction' => '方向:0=顺时针,1=逆时针必须填写',
|
||||
'reward_config_id' => '奖励配置id必须填写',
|
||||
'status' => '状态:0=失败,1=成功必须填写',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'save' => [
|
||||
'lottery_config_id',
|
||||
'lottery_type',
|
||||
'is_win',
|
||||
'direction',
|
||||
'reward_config_id',
|
||||
'status',
|
||||
],
|
||||
'update' => [
|
||||
'lottery_config_id',
|
||||
'lottery_type',
|
||||
'is_win',
|
||||
'direction',
|
||||
'reward_config_id',
|
||||
'status',
|
||||
],
|
||||
];
|
||||
|
||||
}
|
||||
44
server/app/process/WeightTestProcess.php
Normal file
44
server/app/process/WeightTestProcess.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\process;
|
||||
|
||||
use app\dice\logic\reward_config_record\WeightTestRunner;
|
||||
use app\dice\model\reward_config_record\DiceRewardConfigRecord;
|
||||
use Workerman\Timer;
|
||||
use Workerman\Worker;
|
||||
|
||||
/**
|
||||
* 一键测试权重定时任务进程:每隔一定时间检查 status=0 的测试记录并执行一条,不占用 HTTP worker 资源
|
||||
*/
|
||||
class WeightTestProcess
|
||||
{
|
||||
/** 轮询间隔(秒) */
|
||||
private const INTERVAL = 15;
|
||||
|
||||
public function onWorkerStart(Worker $worker): void
|
||||
{
|
||||
Timer::add(self::INTERVAL, function () {
|
||||
$this->runOnePending();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行一条待完成的测试记录(status=0)
|
||||
*/
|
||||
private function runOnePending(): void
|
||||
{
|
||||
$record = DiceRewardConfigRecord::where('status', DiceRewardConfigRecord::STATUS_RUNNING)
|
||||
->order('id')
|
||||
->find();
|
||||
if (!$record) {
|
||||
return;
|
||||
}
|
||||
$recordId = (int) $record->id;
|
||||
try {
|
||||
(new WeightTestRunner())->run($recordId);
|
||||
} catch (\Throwable $e) {
|
||||
// WeightTestRunner 内部会更新 status=-1 和 remark
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,11 @@ return [
|
||||
'publicPath' => public_path()
|
||||
]
|
||||
],
|
||||
// 一键测试权重:定时轮询 status=0 的测试记录并执行,不占用 HTTP 资源
|
||||
'weight_test' => [
|
||||
'handler' => app\process\WeightTestProcess::class,
|
||||
'count' => 1,
|
||||
],
|
||||
// File update detection and automatic reload
|
||||
'monitor' => [
|
||||
'handler' => app\process\Monitor::class,
|
||||
|
||||
@@ -107,6 +107,8 @@ Route::group('/core', function () {
|
||||
Route::get('/dice/reward/DiceReward/weightRatioListWithDirection', [\app\dice\controller\reward\DiceRewardController::class, 'weightRatioListWithDirection']);
|
||||
Route::post('/dice/reward/DiceReward/batchUpdateWeights', [\app\dice\controller\reward\DiceRewardController::class, 'batchUpdateWeights']);
|
||||
Route::post('/dice/reward/DiceReward/batchUpdateWeightsByDirection', [\app\dice\controller\reward\DiceRewardController::class, 'batchUpdateWeightsByDirection']);
|
||||
Route::post('/dice/reward/DiceReward/startWeightTest', [\app\dice\controller\reward\DiceRewardController::class, 'startWeightTest']);
|
||||
Route::get('/dice/reward/DiceReward/getTestProgress', [\app\dice\controller\reward\DiceRewardController::class, 'getTestProgress']);
|
||||
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']);
|
||||
@@ -118,6 +120,8 @@ Route::group('/core', function () {
|
||||
Route::post('/dice/lottery_pool_config/DiceLotteryPoolConfig/updateCurrentPool', [\app\dice\controller\lottery_pool_config\DiceLotteryPoolConfigController::class, 'updateCurrentPool']);
|
||||
fastRoute('dice/reward_config_record/DiceRewardConfigRecord', \app\dice\controller\reward_config_record\DiceRewardConfigRecordController::class);
|
||||
Route::post('/dice/reward_config_record/DiceRewardConfigRecord/importFromRecord', [\app\dice\controller\reward_config_record\DiceRewardConfigRecordController::class, 'importFromRecord']);
|
||||
fastRoute('dice/play_record_test/DicePlayRecordTest', \app\dice\controller\play_record_test\DicePlayRecordTestController::class);
|
||||
Route::post('/dice/play_record_test/DicePlayRecordTest/clearAll', [\app\dice\controller\play_record_test\DicePlayRecordTestController::class, 'clearAll']);
|
||||
|
||||
// 数据表维护
|
||||
Route::get("/database/index", [\plugin\saiadmin\app\controller\system\DataBaseController::class, 'index']);
|
||||
|
||||
Reference in New Issue
Block a user