DicePlayRecord添加字段super_win_coin和reward_win_coin记录不同的中奖金额类型
This commit is contained in:
@@ -5,7 +5,7 @@ import request from '@/utils/http'
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* 获取数据列表
|
||||
* 获取数据列表(DiceLotteryConfig)
|
||||
* @param params 搜索参数
|
||||
* @returns 数据列表
|
||||
*/
|
||||
@@ -16,6 +16,21 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取彩金池配置下拉选项(来自 DiceLotteryConfig,用于 lottery_config_id 选择)
|
||||
* @returns { id, name }[]
|
||||
*/
|
||||
async getOptions(): Promise<Array<{ id: number; name: string }>> {
|
||||
const res = await request.get<any>({
|
||||
url: '/dice/lottery_config/DiceLotteryConfig/index',
|
||||
params: { limit: 500, page: 1 }
|
||||
})
|
||||
const rows = (res?.data?.data ?? res?.data?.rows ?? []) as Array<{ id: number; name: string }>
|
||||
return Array.isArray(rows)
|
||||
? rows.map((r) => ({ id: Number(r.id), name: String(r.name ?? r.id) }))
|
||||
: []
|
||||
},
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param id 数据ID
|
||||
|
||||
@@ -56,10 +56,10 @@
|
||||
{{ row.lottery_type === 0 ? '付费' : row.lottery_type === 1 ? '赠送' : '-' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 中奖 tag -->
|
||||
<!-- 是否中大奖 tag -->
|
||||
<template #is_win="{ row }">
|
||||
<ElTag size="small" :type="row.is_win === 1 ? 'success' : 'info'">
|
||||
{{ row.is_win === 0 ? '无' : row.is_win === 1 ? '中奖' : '-' }}
|
||||
{{ row.is_win === 0 ? '无' : row.is_win === 1 ? '中大奖' : '-' }}
|
||||
</ElTag>
|
||||
</template>
|
||||
<!-- 方向 tag -->
|
||||
@@ -182,8 +182,10 @@
|
||||
useSlot: true
|
||||
},
|
||||
{ prop: 'lottery_type', label: '抽奖类型', width: 100, useSlot: true },
|
||||
{ prop: 'is_win', label: '中奖', width: 80, useSlot: true },
|
||||
{ prop: 'win_coin', label: '赢取平台币' },
|
||||
{ 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 },
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
<el-option label="赠送" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="中奖" prop="is_win">
|
||||
<el-form-item label="是否中大奖" prop="is_win">
|
||||
<el-select
|
||||
v-model="formData.is_win"
|
||||
placeholder="请选择"
|
||||
@@ -63,18 +63,38 @@
|
||||
:disabled="dialogType === 'edit'"
|
||||
>
|
||||
<el-option label="无" :value="0" />
|
||||
<el-option label="中奖" :value="1" />
|
||||
<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="请输入赢取平台币"
|
||||
placeholder="= 中大奖 + 摇色子中奖"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="中大奖平台币" prop="super_win_coin">
|
||||
<el-input-number
|
||||
v-model="formData.super_win_coin"
|
||||
placeholder="豹子时发放"
|
||||
:precision="2"
|
||||
:min="0"
|
||||
style="width: 100%"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="摇色子中奖平台币" prop="reward_win_coin">
|
||||
<el-input-number
|
||||
v-model="formData.reward_win_coin"
|
||||
placeholder="摇色子中奖"
|
||||
:precision="2"
|
||||
:min="0"
|
||||
style="width: 100%"
|
||||
:disabled="dialogType === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="方向" prop="direction">
|
||||
<el-select
|
||||
v-model="formData.direction"
|
||||
@@ -186,7 +206,7 @@
|
||||
player_id: [{ required: true, message: '请选择玩家', trigger: 'change' }],
|
||||
lottery_config_id: [{ required: true, message: '请选择彩金池配置', trigger: 'change' }],
|
||||
lottery_type: [{ required: true, message: '请选择抽奖类型', trigger: 'change' }],
|
||||
is_win: [{ required: true, message: '请选择中奖', trigger: 'change' }],
|
||||
is_win: [{ required: true, message: '请选择是否中大奖', trigger: 'change' }],
|
||||
win_coin: [{ required: true, message: '赢取平台币必填', trigger: 'blur' }],
|
||||
rollArrayItems: [
|
||||
{
|
||||
@@ -219,6 +239,8 @@
|
||||
lottery_type: null as number | null,
|
||||
is_win: null as number | null,
|
||||
win_coin: null as number | null,
|
||||
super_win_coin: null as number | null,
|
||||
reward_win_coin: null as number | null,
|
||||
direction: null as number | null,
|
||||
start_index: null as number | null,
|
||||
target_index: null as number | null,
|
||||
@@ -278,6 +300,8 @@
|
||||
'lottery_type',
|
||||
'is_win',
|
||||
'win_coin',
|
||||
'super_win_coin',
|
||||
'reward_win_coin',
|
||||
'direction',
|
||||
'start_index',
|
||||
'target_index',
|
||||
|
||||
@@ -27,10 +27,10 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="中奖" prop="is_win">
|
||||
<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-option label="中大奖" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
phone: undefined,
|
||||
status: undefined,
|
||||
coin: undefined,
|
||||
is_up: undefined
|
||||
lottery_config_id: undefined
|
||||
})
|
||||
|
||||
// 搜索处理
|
||||
@@ -127,17 +127,9 @@
|
||||
return cellValue != null && cellValue !== '' ? `${cellValue}%` : '-'
|
||||
}
|
||||
|
||||
// 倍率列展示:0=正常 1=强制杀猪 2=T1高倍率
|
||||
const isUpFormatter = (row: any) => {
|
||||
const cellValue = row.is_up
|
||||
return cellValue === 0
|
||||
? '正常'
|
||||
: cellValue === 1
|
||||
? '强制杀猪'
|
||||
: cellValue === 2
|
||||
? 'T1高倍率'
|
||||
: '-'
|
||||
}
|
||||
// 彩金池配置列:lottery_config_id 关联 DiceLotteryConfig,显示 name
|
||||
const lotteryConfigNameFormatter = (row: any) =>
|
||||
row?.diceLotteryConfig?.name ?? (row?.lottery_config_id ? `#${row.lottery_config_id}` : '自定义')
|
||||
|
||||
// 表格配置
|
||||
const {
|
||||
@@ -176,11 +168,11 @@
|
||||
useSlot: true
|
||||
},
|
||||
{
|
||||
prop: 'is_up',
|
||||
label: '倍率',
|
||||
width: 80,
|
||||
prop: 'lottery_config_id',
|
||||
label: '彩金池配置',
|
||||
width: 120,
|
||||
align: 'center',
|
||||
formatter: isUpFormatter
|
||||
formatter: (row: any) => lotteryConfigNameFormatter(row)
|
||||
},
|
||||
{
|
||||
prop: 't1_weight',
|
||||
|
||||
@@ -15,7 +15,13 @@
|
||||
<el-input v-model="formData.name" placeholder="请输入昵称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号" prop="phone">
|
||||
<el-input v-model="formData.phone" placeholder="请输入手机号" clearable maxlength="20" show-word-limit />
|
||||
<el-input
|
||||
v-model="formData.phone"
|
||||
placeholder="请输入手机号"
|
||||
clearable
|
||||
maxlength="20"
|
||||
show-word-limit
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password" :rules="passwordRules">
|
||||
<el-input
|
||||
@@ -38,29 +44,39 @@
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="倍率" prop="is_up">
|
||||
<el-select v-model="formData.is_up" placeholder="请选择倍率" clearable style="width: 100%">
|
||||
<el-option label="正常" :value="0" />
|
||||
<el-option label="强制杀猪" :value="1" />
|
||||
<el-option label="T1高倍率" :value="2" />
|
||||
<el-form-item label="彩金池配置" prop="lottery_config_id">
|
||||
<el-select
|
||||
v-model="formData.lottery_config_id"
|
||||
placeholder="不选则使用下方自定义权重"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
@change="onLotteryConfigChange"
|
||||
>
|
||||
<el-option label="自定义权重" :value="0" />
|
||||
<el-option
|
||||
v-for="item in lotteryConfigOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="T1池权重(%)" prop="t1_weight">
|
||||
<el-form-item v-if="!formData.lottery_config_id" label="T1池权重(%)" prop="t1_weight">
|
||||
<el-slider v-model="formData.t1_weight" :min="0" :max="100" :step="0.01" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item label="T2池权重(%)" prop="t2_weight">
|
||||
<el-form-item v-if="!formData.lottery_config_id" label="T2池权重(%)" prop="t2_weight">
|
||||
<el-slider v-model="formData.t2_weight" :min="0" :max="100" :step="0.01" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item label="T3池权重(%)" prop="t3_weight">
|
||||
<el-form-item v-if="!formData.lottery_config_id" label="T3池权重(%)" prop="t3_weight">
|
||||
<el-slider v-model="formData.t3_weight" :min="0" :max="100" :step="0.01" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item label="T4池权重(%)" prop="t4_weight">
|
||||
<el-form-item v-if="!formData.lottery_config_id" label="T4池权重(%)" prop="t4_weight">
|
||||
<el-slider v-model="formData.t4_weight" :min="0" :max="100" :step="0.01" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item label="T5池权重(%)" prop="t5_weight">
|
||||
<el-form-item v-if="!formData.lottery_config_id" label="T5池权重(%)" prop="t5_weight">
|
||||
<el-slider v-model="formData.t5_weight" :min="0" :max="100" :step="0.01" show-input />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-form-item v-if="!formData.lottery_config_id">
|
||||
<div class="text-gray-500 text-sm">
|
||||
五个池权重总和:<span :class="Math.abs(weightsSum - 100) > 0.01 ? 'text-red-500' : ''">{{
|
||||
weightsSum
|
||||
@@ -78,9 +94,12 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/player/index'
|
||||
import lotteryConfigApi from '../../../api/lottery_config/index'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
const WEIGHT_FIELDS = ['t1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'] as const
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
dialogType: string
|
||||
@@ -107,9 +126,8 @@
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
const WEIGHT_KEYS = ['t1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'] as const
|
||||
const weightsSum = computed(() => {
|
||||
return WEIGHT_KEYS.reduce((sum, key) => sum + Number(formData[key] ?? 0), 0)
|
||||
return WEIGHT_FIELDS.reduce((sum, key) => sum + Number(formData[key] ?? 0), 0)
|
||||
})
|
||||
|
||||
/** 新增时密码必填,编辑时选填 */
|
||||
@@ -133,7 +151,7 @@
|
||||
password: '',
|
||||
status: 1 as number,
|
||||
coin: 0 as number,
|
||||
is_up: null as number | null,
|
||||
lottery_config_id: null as number | null,
|
||||
t1_weight: 0 as number,
|
||||
t2_weight: 0 as number,
|
||||
t3_weight: 0 as number,
|
||||
@@ -143,6 +161,9 @@
|
||||
|
||||
const formData = reactive({ ...initialFormData })
|
||||
|
||||
/** 彩金池配置下拉选项 */
|
||||
const lotteryConfigOptions = ref<Array<{ id: number; name: string }>>([])
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(newVal) => {
|
||||
@@ -150,19 +171,45 @@
|
||||
}
|
||||
)
|
||||
|
||||
/** 选择彩金池配置时,拉取该配置的权重填入表单(仅展示/备份;lottery_config_id 非空时后端以配置为准) */
|
||||
async function onLotteryConfigChange(lotteryConfigId: number | null) {
|
||||
if (!lotteryConfigId) return
|
||||
try {
|
||||
const res = await lotteryConfigApi.read(lotteryConfigId)
|
||||
const row = (res as any)?.data
|
||||
if (row) {
|
||||
WEIGHT_FIELDS.forEach((key) => {
|
||||
;(formData as any)[key] = Number(row[key] ?? 0)
|
||||
})
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('拉取彩金池配置权重失败', err)
|
||||
}
|
||||
}
|
||||
|
||||
const initPage = async () => {
|
||||
Object.assign(formData, initialFormData)
|
||||
await loadLotteryConfigOptions()
|
||||
if (props.data) {
|
||||
await nextTick()
|
||||
initForm()
|
||||
}
|
||||
}
|
||||
|
||||
/** 从 DiceLotteryConfig 拉取彩金池配置下拉选项 */
|
||||
async function loadLotteryConfigOptions() {
|
||||
try {
|
||||
lotteryConfigOptions.value = await lotteryConfigApi.getOptions()
|
||||
} catch {
|
||||
lotteryConfigOptions.value = []
|
||||
}
|
||||
}
|
||||
|
||||
const numKeys = [
|
||||
'id',
|
||||
'status',
|
||||
'coin',
|
||||
'is_up',
|
||||
'lottery_config_id',
|
||||
't1_weight',
|
||||
't2_weight',
|
||||
't3_weight',
|
||||
@@ -197,7 +244,8 @@
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
if (Math.abs(weightsSum.value - 100) > 0.01) {
|
||||
const useCustomWeights = !formData.lottery_config_id
|
||||
if (useCustomWeights && Math.abs(weightsSum.value - 100) > 0.01) {
|
||||
ElMessage.warning('五个池权重总和必须为100%')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -44,11 +44,19 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item label="倍率" prop="is_up">
|
||||
<el-select v-model="formData.is_up" placeholder="全部" clearable style="width: 100%">
|
||||
<el-option label="正常" :value="0" />
|
||||
<el-option label="强制杀猪" :value="1" />
|
||||
<el-option label="T1高倍率" :value="2" />
|
||||
<el-form-item label="彩金池配置" prop="lottery_config_id">
|
||||
<el-select
|
||||
v-model="formData.lottery_config_id"
|
||||
placeholder="全部"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in lotteryConfigOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@@ -56,6 +64,8 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import lotteryConfigApi from '../../../api/lottery_config/index'
|
||||
|
||||
interface Props {
|
||||
modelValue: Record<string, any>
|
||||
}
|
||||
@@ -67,6 +77,16 @@
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
const isExpanded = ref<boolean>(false)
|
||||
const lotteryConfigOptions = ref<Array<{ id: number; name: string }>>([])
|
||||
|
||||
/** 从 DiceLotteryConfig 拉取彩金池配置下拉选项,用于 lottery_config_id 筛选 */
|
||||
onMounted(async () => {
|
||||
try {
|
||||
lotteryConfigOptions.value = await lotteryConfigApi.getOptions()
|
||||
} catch {
|
||||
lotteryConfigOptions.value = []
|
||||
}
|
||||
})
|
||||
|
||||
const searchBarRef = ref()
|
||||
const formData = computed({
|
||||
|
||||
@@ -137,7 +137,10 @@ class GameController extends OpenController
|
||||
'player_id' => $userId,
|
||||
'lottery_config_id' => 0,
|
||||
'lottery_type' => 0,
|
||||
'is_win' => 0,
|
||||
'win_coin' => 0,
|
||||
'super_win_coin' => 0,
|
||||
'reward_win_coin' => 0,
|
||||
'use_coins' => 0,
|
||||
'direction' => $direction,
|
||||
'reward_config_id' => 0,
|
||||
|
||||
@@ -34,6 +34,8 @@ class PlayStartLogic
|
||||
|
||||
/** 开启对局最低余额 = |DiceRewardConfig 最小 real_ev + 100| */
|
||||
private const MIN_COIN_EXTRA = 100;
|
||||
/** 豹子号中大奖额外平台币(可从 dice_config 等配置读取) */
|
||||
private const SUPER_WIN_BONUS = 500;
|
||||
|
||||
/**
|
||||
* 执行一局游戏
|
||||
@@ -120,13 +122,24 @@ class PlayStartLogic
|
||||
$targetIndex
|
||||
));
|
||||
$realEv = (float) ($chosen['real_ev'] ?? 0);
|
||||
$winCoin = 100 + $realEv; // 赢取平台币 = 100 + DiceRewardConfig.real_ev
|
||||
$rewardWinCoin = 100 + $realEv; // 摇色子中奖平台币 = 100 + DiceRewardConfig.real_ev
|
||||
$isSuperWin = DicePlayRecord::isSuperWin($rollArray);
|
||||
// 豹子中大奖时从缓存查 tier=BIGWIN 且 grid_number=roll_number 的奖励配置,取 real_ev 计算中大奖平台币
|
||||
$superWinCoin = 0;
|
||||
if ($isSuperWin) {
|
||||
$bigWinConfig = DiceRewardConfig::getCachedByTierAndGridNumber('BIGWIN', $rollNumber);
|
||||
$superWinCoin = $bigWinConfig !== null
|
||||
? 100 + (float) ($bigWinConfig['real_ev'] ?? 0)
|
||||
: self::SUPER_WIN_BONUS;
|
||||
}
|
||||
$winCoin = $superWinCoin + $rewardWinCoin; // 赢取平台币 = 中大奖 + 摇色子中奖
|
||||
|
||||
$record = null;
|
||||
$configId = (int) $config->id;
|
||||
$rewardId = $chosenId;
|
||||
$configName = (string) ($config->name ?? '');
|
||||
$isTierT5 = (string) ($chosen['tier'] ?? '') === 'T5';
|
||||
$isWin = $isSuperWin ? 1 : 0;
|
||||
try {
|
||||
Db::transaction(function () use (
|
||||
$playerId,
|
||||
@@ -135,6 +148,9 @@ class PlayStartLogic
|
||||
$configName,
|
||||
$ticketType,
|
||||
$winCoin,
|
||||
$superWinCoin,
|
||||
$rewardWinCoin,
|
||||
$isWin,
|
||||
$realEv,
|
||||
$direction,
|
||||
$startIndex,
|
||||
@@ -147,7 +163,10 @@ class PlayStartLogic
|
||||
'player_id' => $playerId,
|
||||
'lottery_config_id' => $configId,
|
||||
'lottery_type' => $ticketType,
|
||||
'is_win' => $isWin,
|
||||
'win_coin' => $winCoin,
|
||||
'super_win_coin' => $superWinCoin,
|
||||
'reward_win_coin' => $rewardWinCoin,
|
||||
'use_coins' => 0,
|
||||
'direction' => $direction,
|
||||
'reward_config_id' => $rewardId,
|
||||
@@ -210,7 +229,10 @@ class PlayStartLogic
|
||||
'player_id' => $playerId,
|
||||
'lottery_config_id' => $configId ?? 0,
|
||||
'lottery_type' => $ticketType,
|
||||
'is_win' => 0,
|
||||
'win_coin' => 0,
|
||||
'super_win_coin' => 0,
|
||||
'reward_win_coin' => 0,
|
||||
'use_coins' => 0,
|
||||
'direction' => $direction,
|
||||
'reward_config_id' => 0,
|
||||
|
||||
@@ -82,7 +82,7 @@ class UserLogic
|
||||
$token = $tokenResult['access_token'];
|
||||
UserCache::setSessionByUsername($username, $token);
|
||||
|
||||
$userArr = $player->hidden(['password', 'is_up', 't1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'])->toArray();
|
||||
$userArr = $player->hidden(['password', 'lottery_config_id', 't1_weight', 't2_weight', 't3_weight', 't4_weight', 't5_weight'])->toArray();
|
||||
UserCache::setUser((int) $player->id, $userArr);
|
||||
UserCache::setPlayerByUsername($username, $userArr);
|
||||
|
||||
|
||||
@@ -42,9 +42,10 @@ class DicePlayerController extends BaseController
|
||||
['phone', ''],
|
||||
['status', ''],
|
||||
['coin', ''],
|
||||
['is_up', ''],
|
||||
['lottery_config_id', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$query->with(['diceLotteryConfig']);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
@@ -48,4 +48,13 @@ class DiceLotteryConfig extends BaseModel
|
||||
$query->where('name', 'like', '%'.$value.'%');
|
||||
}
|
||||
|
||||
/**
|
||||
* 奖池类型 搜索(type=0/1/2 等)
|
||||
*/
|
||||
public function searchTypeAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('type', '=', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,10 @@ use think\model\relation\BelongsTo;
|
||||
* @property $player_id 玩家id
|
||||
* @property $lottery_config_id 彩金池配置
|
||||
* @property $lottery_type 抽奖类型
|
||||
* @property $is_win 中奖
|
||||
* @property $win_coin 赢取平台币
|
||||
* @property $is_win 是否中大奖:豹子号[1,1,1,1,1]~[5,5,5,5,5]为1,否则0
|
||||
* @property $win_coin 赢取平台币(= super_win_coin + reward_win_coin)
|
||||
* @property $super_win_coin 中大奖平台币(豹子时发放)
|
||||
* @property $reward_win_coin 摇色子中奖平台币
|
||||
* @property $direction 方向:0=顺时针,1=逆时针
|
||||
* @property $reward_config_id 奖励配置id
|
||||
* @property $lottery_id 奖池
|
||||
@@ -111,7 +113,25 @@ class DicePlayRecord extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 中奖 */
|
||||
/**
|
||||
* 是否豹子号(中大奖):5 个点数相同且为 1~5 之一
|
||||
* @param int[] $rollArray 摇取点数数组,如 [1,1,1,1,1]
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSuperWin(array $rollArray): bool
|
||||
{
|
||||
if (count($rollArray) !== 5) {
|
||||
return false;
|
||||
}
|
||||
$unique = array_unique($rollArray);
|
||||
if (count($unique) !== 1) {
|
||||
return false;
|
||||
}
|
||||
$value = reset($unique);
|
||||
return in_array($value, [1, 2, 3, 4, 5], true);
|
||||
}
|
||||
|
||||
/** 是否中大奖 */
|
||||
public function searchIsWinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
@@ -135,6 +155,38 @@ class DicePlayRecord extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/** 中大奖平台币下限 */
|
||||
public function searchSuperWinCoinMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('super_win_coin', '>=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 中大奖平台币上限 */
|
||||
public function searchSuperWinCoinMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('super_win_coin', '<=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 摇色子中奖平台币下限 */
|
||||
public function searchRewardWinCoinMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('reward_win_coin', '>=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 摇色子中奖平台币上限 */
|
||||
public function searchRewardWinCoinMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('reward_win_coin', '<=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/** 按奖励配置前端显示文本模糊(diceRewardConfig.ui_text) */
|
||||
public function searchRewardUiTextAttr($query, $value)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ use app\dice\model\lottery_config\DiceLotteryConfig;
|
||||
* @property $password 密码
|
||||
* @property $status 状态
|
||||
* @property $coin 平台币
|
||||
* @property $is_up 倍率
|
||||
* @property $lottery_config_id 彩金池配置ID(0或null时使用自定义权重*_weight)
|
||||
* @property $t1_weight T1池权重
|
||||
* @property $t2_weight T2池权重
|
||||
* @property $t3_weight T3池权重
|
||||
@@ -162,13 +162,20 @@ class DicePlayer extends BaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* 倍率 搜索
|
||||
* 彩金池配置ID 搜索
|
||||
*/
|
||||
public function searchIs_upAttr($query, $value)
|
||||
public function searchLottery_config_idAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('is_up', '=', $value);
|
||||
$query->where('lottery_config_id', '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联彩金池配置
|
||||
*/
|
||||
public function diceLotteryConfig()
|
||||
{
|
||||
return $this->belongsTo(DiceLotteryConfig::class, 'lottery_config_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class DiceRewardConfig extends BaseModel
|
||||
|
||||
/**
|
||||
* 获取彩金池实例(含 list / 索引),无则从库加载并写入缓存;同请求内复用
|
||||
* @return array{list: array, by_tier: array, by_s_end_index: array, by_n_end_index: array, min_real_ev: float}
|
||||
* @return array{list: array, by_tier: array, by_tier_grid: array, by_s_end_index: array, by_n_end_index: array, min_real_ev: float}
|
||||
*/
|
||||
public static function getCachedInstance(): array
|
||||
{
|
||||
@@ -86,6 +86,7 @@ class DiceRewardConfig extends BaseModel
|
||||
{
|
||||
$list = (new self())->order('id', 'asc')->select()->toArray();
|
||||
$byTier = [];
|
||||
$byTierGrid = [];
|
||||
$bySEndIndex = [];
|
||||
$byNEndIndex = [];
|
||||
foreach ($list as $row) {
|
||||
@@ -95,6 +96,13 @@ class DiceRewardConfig extends BaseModel
|
||||
$byTier[$tier] = [];
|
||||
}
|
||||
$byTier[$tier][] = $row;
|
||||
$gridNum = isset($row['grid_number']) ? (int) $row['grid_number'] : 0;
|
||||
if (!isset($byTierGrid[$tier])) {
|
||||
$byTierGrid[$tier] = [];
|
||||
}
|
||||
if (!isset($byTierGrid[$tier][$gridNum])) {
|
||||
$byTierGrid[$tier][$gridNum] = $row;
|
||||
}
|
||||
}
|
||||
$sEnd = isset($row['s_end_index']) ? (int) $row['s_end_index'] : 0;
|
||||
if ($sEnd !== 0) {
|
||||
@@ -115,6 +123,7 @@ class DiceRewardConfig extends BaseModel
|
||||
self::$instance = [
|
||||
'list' => $list,
|
||||
'by_tier' => $byTier,
|
||||
'by_tier_grid' => $byTierGrid,
|
||||
'by_s_end_index' => $bySEndIndex,
|
||||
'by_n_end_index' => $byNEndIndex,
|
||||
'min_real_ev' => $minRealEv,
|
||||
@@ -128,12 +137,28 @@ class DiceRewardConfig extends BaseModel
|
||||
return [
|
||||
'list' => [],
|
||||
'by_tier' => [],
|
||||
'by_tier_grid' => [],
|
||||
'by_s_end_index' => [],
|
||||
'by_n_end_index' => [],
|
||||
'min_real_ev' => 0.0,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 从缓存按档位 + 色子点数取一条奖励配置(用于超级大奖 tier=BIGWIN + grid_number=roll_number)
|
||||
* @param string $tier 档位,如 BIGWIN
|
||||
* @param int $gridNumber 色子点数(如摇出总和)
|
||||
* @return array|null 配置行或 null
|
||||
*/
|
||||
public static function getCachedByTierAndGridNumber(string $tier, int $gridNumber): ?array
|
||||
{
|
||||
$inst = self::getCachedInstance();
|
||||
$byTierGrid = $inst['by_tier_grid'] ?? [];
|
||||
$tierData = $byTierGrid[$tier] ?? [];
|
||||
$row = $tierData[$gridNumber] ?? null;
|
||||
return is_array($row) ? $row : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从缓存取最小 real_ev
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user