[色子游戏]底注配置
This commit is contained in:
37
saiadmin-artd/src/locales/langs/en/dice/ante_config.json
Normal file
37
saiadmin-artd/src/locales/langs/en/dice/ante_config.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"search": {
|
||||
"name": "Name",
|
||||
"title": "Title",
|
||||
"isDefault": "Default",
|
||||
"placeholderName": "Please enter name",
|
||||
"placeholderTitle": "Please enter title",
|
||||
"placeholderIsDefault": "Please select default status"
|
||||
},
|
||||
"table": {
|
||||
"id": "ID",
|
||||
"name": "Name",
|
||||
"title": "Title",
|
||||
"mult": "Ante Multiplier",
|
||||
"isDefault": "Default Ante",
|
||||
"defaultYes": "Yes",
|
||||
"defaultNo": "No",
|
||||
"createTime": "Create Time",
|
||||
"updateTime": "Update Time"
|
||||
},
|
||||
"form": {
|
||||
"titleAdd": "Add Ante Config",
|
||||
"titleEdit": "Edit Ante Config",
|
||||
"labelName": "Name",
|
||||
"labelTitle": "Title",
|
||||
"labelMult": "Ante Multiplier",
|
||||
"labelIsDefault": "Default Ante",
|
||||
"placeholderName": "Please enter name",
|
||||
"placeholderTitle": "Please enter title",
|
||||
"ruleNameRequired": "Please enter name",
|
||||
"ruleTitleRequired": "Please enter title",
|
||||
"ruleMultRequired": "Please enter ante multiplier",
|
||||
"ruleDefaultRequired": "Please select default status",
|
||||
"addSuccess": "Added successfully",
|
||||
"editSuccess": "Updated successfully"
|
||||
}
|
||||
}
|
||||
37
saiadmin-artd/src/locales/langs/zh/dice/ante_config.json
Normal file
37
saiadmin-artd/src/locales/langs/zh/dice/ante_config.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"search": {
|
||||
"name": "名称",
|
||||
"title": "标题",
|
||||
"isDefault": "是否默认",
|
||||
"placeholderName": "请输入名称",
|
||||
"placeholderTitle": "请输入标题",
|
||||
"placeholderIsDefault": "请选择是否默认"
|
||||
},
|
||||
"table": {
|
||||
"id": "ID",
|
||||
"name": "名称",
|
||||
"title": "标题",
|
||||
"mult": "底注倍率",
|
||||
"isDefault": "默认底注",
|
||||
"defaultYes": "是",
|
||||
"defaultNo": "否",
|
||||
"createTime": "创建时间",
|
||||
"updateTime": "更新时间"
|
||||
},
|
||||
"form": {
|
||||
"titleAdd": "新增底注配置",
|
||||
"titleEdit": "编辑底注配置",
|
||||
"labelName": "名称",
|
||||
"labelTitle": "标题",
|
||||
"labelMult": "底注倍率",
|
||||
"labelIsDefault": "默认底注",
|
||||
"placeholderName": "请输入名称",
|
||||
"placeholderTitle": "请输入标题",
|
||||
"ruleNameRequired": "请输入名称",
|
||||
"ruleTitleRequired": "请输入标题",
|
||||
"ruleMultRequired": "请输入底注倍率",
|
||||
"ruleDefaultRequired": "请选择是否默认底注",
|
||||
"addSuccess": "新增成功",
|
||||
"editSuccess": "修改成功"
|
||||
}
|
||||
}
|
||||
139
saiadmin-artd/src/views/plugin/dice/ante_config/index/index.vue
Normal file
139
saiadmin-artd/src/views/plugin/dice/ante_config/index/index.vue
Normal file
@@ -0,0 +1,139 @@
|
||||
<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>
|
||||
<ElButton v-permission="'dice:ante_config:index:save'" @click="showDialog('add')" v-ripple>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:add-fill" />
|
||||
</template>
|
||||
{{ $t('table.actions.add') }}
|
||||
</ElButton>
|
||||
<ElButton
|
||||
v-permission="'dice:ante_config:index:destroy'"
|
||||
:disabled="selectedRows.length === 0"
|
||||
@click="deleteSelectedRows(api.delete, refreshData)"
|
||||
v-ripple
|
||||
>
|
||||
<template #icon>
|
||||
<ArtSvgIcon icon="ri:delete-bin-5-line" />
|
||||
</template>
|
||||
{{ $t('table.actions.delete') }}
|
||||
</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"
|
||||
>
|
||||
<template #is_default="{ row }">
|
||||
<ElTag :type="row.is_default === 1 ? 'success' : 'info'" size="small">
|
||||
{{ row.is_default === 1 ? $t('page.table.defaultYes') : $t('page.table.defaultNo') }}
|
||||
</ElTag>
|
||||
</template>
|
||||
|
||||
<template #operation="{ row }">
|
||||
<div class="flex gap-2">
|
||||
<SaButton
|
||||
v-permission="'dice:ante_config:index:update'"
|
||||
type="secondary"
|
||||
@click="showDialog('edit', row)"
|
||||
/>
|
||||
<SaButton
|
||||
v-permission="'dice:ante_config: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/ante_config/index'
|
||||
import TableSearch from './modules/table-search.vue'
|
||||
import EditDialog from './modules/edit-dialog.vue'
|
||||
|
||||
const searchForm = ref({
|
||||
name: undefined,
|
||||
title: undefined,
|
||||
is_default: undefined
|
||||
})
|
||||
|
||||
const handleSearch = (params: Record<string, unknown>) => {
|
||||
Object.assign(searchParams, params)
|
||||
getData()
|
||||
}
|
||||
|
||||
const {
|
||||
columns,
|
||||
columnChecks,
|
||||
data,
|
||||
loading,
|
||||
getData,
|
||||
searchParams,
|
||||
pagination,
|
||||
resetSearchParams,
|
||||
handleSortChange,
|
||||
handleSizeChange,
|
||||
handleCurrentChange,
|
||||
refreshData
|
||||
} = useTable({
|
||||
core: {
|
||||
apiFn: api.list,
|
||||
columnsFactory: () => [
|
||||
{ type: 'selection' },
|
||||
{ prop: 'id', label: 'page.table.id', width: 80, align: 'center' },
|
||||
{ prop: 'name', label: 'page.table.name', align: 'center' },
|
||||
{ prop: 'title', label: 'page.table.title', align: 'center' },
|
||||
{ prop: 'mult', label: 'page.table.mult', align: 'center' },
|
||||
{ prop: 'is_default', label: 'page.table.isDefault', width: 110, align: 'center', useSlot: true },
|
||||
{ prop: 'create_time', label: 'page.table.createTime', width: 170, align: 'center' },
|
||||
{ prop: 'update_time', label: 'page.table.updateTime', width: 170, align: 'center' },
|
||||
{
|
||||
prop: 'operation',
|
||||
label: 'table.actions.operation',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
useSlot: true
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
const {
|
||||
dialogType,
|
||||
dialogVisible,
|
||||
dialogData,
|
||||
showDialog,
|
||||
deleteRow,
|
||||
deleteSelectedRows,
|
||||
handleSelectionChange,
|
||||
selectedRows
|
||||
} = useSaiAdmin()
|
||||
</script>
|
||||
@@ -0,0 +1,126 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
:title="dialogType === 'add' ? $t('page.form.titleAdd') : $t('page.form.titleEdit')"
|
||||
width="560px"
|
||||
align-center
|
||||
:close-on-click-modal="false"
|
||||
@close="handleClose"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
|
||||
<el-form-item :label="$t('page.form.labelName')" prop="name">
|
||||
<el-input v-model="formData.name" :placeholder="$t('page.form.placeholderName')" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('page.form.labelTitle')" prop="title">
|
||||
<el-input v-model="formData.title" :placeholder="$t('page.form.placeholderTitle')" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('page.form.labelMult')" prop="mult">
|
||||
<el-input-number v-model="formData.mult" :min="1" :step="1" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('page.form.labelIsDefault')" prop="is_default">
|
||||
<el-radio-group v-model="formData.is_default">
|
||||
<el-radio :value="1">{{ $t('page.table.defaultYes') }}</el-radio>
|
||||
<el-radio :value="0">{{ $t('page.table.defaultNo') }}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="handleClose">{{ $t('common.cancel') }}</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">{{ $t('table.form.submit') }}</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '../../../api/ante_config/index'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
interface Props {
|
||||
modelValue: boolean
|
||||
dialogType: string
|
||||
data?: Record<string, unknown>
|
||||
}
|
||||
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 = computed<FormRules>(() => ({
|
||||
name: [{ required: true, message: t('page.form.ruleNameRequired'), trigger: 'blur' }],
|
||||
title: [{ required: true, message: t('page.form.ruleTitleRequired'), trigger: 'blur' }],
|
||||
mult: [{ required: true, message: t('page.form.ruleMultRequired'), trigger: 'blur' }],
|
||||
is_default: [{ required: true, message: t('page.form.ruleDefaultRequired'), trigger: 'change' }]
|
||||
}))
|
||||
|
||||
interface AnteFormData {
|
||||
id: number | null
|
||||
name: string
|
||||
title: string
|
||||
mult: number
|
||||
is_default: number
|
||||
}
|
||||
|
||||
const initialFormData: AnteFormData = {
|
||||
id: null,
|
||||
name: '',
|
||||
title: '',
|
||||
mult: 1,
|
||||
is_default: 0
|
||||
}
|
||||
|
||||
const formData = reactive({ ...initialFormData })
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
async (newVal) => {
|
||||
if (!newVal) return
|
||||
Object.assign(formData, initialFormData)
|
||||
if (!props.data) return
|
||||
await nextTick()
|
||||
if (typeof props.data.id === 'number') formData.id = props.data.id
|
||||
if (typeof props.data.name === 'string') formData.name = props.data.name
|
||||
if (typeof props.data.title === 'string') formData.title = props.data.title
|
||||
formData.mult = Number(props.data.mult ?? 1) || 1
|
||||
formData.is_default = Number(props.data.is_default ?? 0) === 1 ? 1 : 0
|
||||
}
|
||||
)
|
||||
|
||||
function handleClose() {
|
||||
visible.value = false
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
if (props.dialogType === 'add') {
|
||||
await api.save(formData)
|
||||
ElMessage.success(t('page.form.addSuccess'))
|
||||
} else {
|
||||
await api.update(formData)
|
||||
ElMessage.success(t('page.form.editSuccess'))
|
||||
}
|
||||
emit('success')
|
||||
handleClose()
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,68 @@
|
||||
<template>
|
||||
<sa-search-bar
|
||||
ref="searchBarRef"
|
||||
v-model="formData"
|
||||
label-width="100px"
|
||||
:showExpand="false"
|
||||
@reset="handleReset"
|
||||
@search="handleSearch"
|
||||
>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item :label="$t('page.search.name')" prop="name">
|
||||
<el-input v-model="formData.name" :placeholder="$t('page.search.placeholderName')" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item :label="$t('page.search.title')" prop="title">
|
||||
<el-input v-model="formData.title" :placeholder="$t('page.search.placeholderTitle')" clearable />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col v-bind="setSpan(6)">
|
||||
<el-form-item :label="$t('page.search.isDefault')" prop="is_default">
|
||||
<el-select v-model="formData.is_default" :placeholder="$t('page.search.placeholderIsDefault')" clearable>
|
||||
<el-option :label="$t('page.table.defaultYes')" :value="1" />
|
||||
<el-option :label="$t('page.table.defaultNo')" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</sa-search-bar>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface Props {
|
||||
modelValue: Record<string, unknown>
|
||||
}
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: Record<string, unknown>): void
|
||||
(e: 'search', params: Record<string, unknown>): void
|
||||
(e: 'reset'): void
|
||||
}
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const searchBarRef = ref()
|
||||
const formData = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (val) => emit('update:modelValue', val)
|
||||
})
|
||||
|
||||
function handleReset() {
|
||||
searchBarRef.value?.ref.resetFields()
|
||||
emit('reset')
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
emit('search', formData.value)
|
||||
}
|
||||
|
||||
const setSpan = (span: number) => {
|
||||
return {
|
||||
span,
|
||||
xs: 24,
|
||||
sm: span >= 12 ? span : 12,
|
||||
md: span >= 8 ? span : 8,
|
||||
lg: span,
|
||||
xl: span
|
||||
}
|
||||
}
|
||||
</script>
|
||||
40
saiadmin-artd/src/views/plugin/dice/api/ante_config/index.ts
Normal file
40
saiadmin-artd/src/views/plugin/dice/api/ante_config/index.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import request from '@/utils/http'
|
||||
|
||||
/**
|
||||
* 底注配置 API
|
||||
*/
|
||||
export default {
|
||||
list(params: Record<string, unknown>) {
|
||||
return request.get<Api.Common.ApiPage>({
|
||||
url: '/core/dice/ante_config/DiceAnteConfig/index',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
read(id: number | string) {
|
||||
return request.get<Api.Common.ApiData>({
|
||||
url: '/core/dice/ante_config/DiceAnteConfig/read?id=' + id
|
||||
})
|
||||
},
|
||||
|
||||
save(params: Record<string, unknown>) {
|
||||
return request.post({
|
||||
url: '/core/dice/ante_config/DiceAnteConfig/save',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
update(params: Record<string, unknown>) {
|
||||
return request.put({
|
||||
url: '/core/dice/ante_config/DiceAnteConfig/update',
|
||||
data: params
|
||||
})
|
||||
},
|
||||
|
||||
delete(params: Record<string, unknown>) {
|
||||
return request.del({
|
||||
url: '/core/dice/ante_config/DiceAnteConfig/destroy',
|
||||
data: params
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\controller\ante_config;
|
||||
|
||||
use app\dice\logic\ante_config\DiceAnteConfigLogic;
|
||||
use app\dice\validate\ante_config\DiceAnteConfigValidate;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 底注配置控制器
|
||||
*/
|
||||
class DiceAnteConfigController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new DiceAnteConfigLogic();
|
||||
$this->validate = new DiceAnteConfigValidate();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
#[Permission('底注配置列表', 'dice:ante_config:index:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['name', ''],
|
||||
['title', ''],
|
||||
['is_default', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
#[Permission('底注配置读取', 'dice:ante_config:index:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
#[Permission('底注配置添加', 'dice:ante_config:index:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
return $result ? $this->success('add success') : $this->fail('add failed');
|
||||
}
|
||||
|
||||
#[Permission('底注配置修改', 'dice:ante_config:index:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
return $result ? $this->success('update success') : $this->fail('update failed');
|
||||
}
|
||||
|
||||
#[Permission('底注配置删除', 'dice:ante_config:index:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('please select data to delete');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
return $result ? $this->success('delete success') : $this->fail('delete failed');
|
||||
}
|
||||
}
|
||||
90
server/app/dice/logic/ante_config/DiceAnteConfigLogic.php
Normal file
90
server/app/dice/logic/ante_config/DiceAnteConfigLogic.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\logic\ante_config;
|
||||
|
||||
use app\dice\model\ante_config\DiceAnteConfig;
|
||||
use plugin\saiadmin\basic\think\BaseLogic;
|
||||
|
||||
/**
|
||||
* 底注配置逻辑层
|
||||
*/
|
||||
class DiceAnteConfigLogic extends BaseLogic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->model = new DiceAnteConfig();
|
||||
}
|
||||
|
||||
public function add(array $data): mixed
|
||||
{
|
||||
return $this->transaction(function () use ($data) {
|
||||
$this->normalizeDefaultField($data);
|
||||
if ((int) ($data['is_default'] ?? 0) === 1) {
|
||||
$this->clearOtherDefaults();
|
||||
}
|
||||
return parent::add($data);
|
||||
});
|
||||
}
|
||||
|
||||
public function edit($id, array $data): mixed
|
||||
{
|
||||
return $this->transaction(function () use ($id, $data) {
|
||||
$this->normalizeDefaultField($data);
|
||||
if ((int) ($data['is_default'] ?? 0) === 1) {
|
||||
$this->clearOtherDefaults((int) $id);
|
||||
}
|
||||
return parent::edit($id, $data);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 防止删除后全表无默认:若删除了默认项,自动把最小 id 设为默认。
|
||||
*/
|
||||
public function destroy($ids): bool
|
||||
{
|
||||
return $this->transaction(function () use ($ids) {
|
||||
$idList = is_array($ids) ? $ids : explode(',', (string) $ids);
|
||||
$intIds = [];
|
||||
foreach ($idList as $v) {
|
||||
$iv = (int) $v;
|
||||
if ($iv > 0) {
|
||||
$intIds[] = $iv;
|
||||
}
|
||||
}
|
||||
if ($intIds === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$deletedDefaultCount = $this->model->whereIn('id', $intIds)->where('is_default', 1)->count();
|
||||
$result = $this->model->destroy($intIds);
|
||||
if ($result && $deletedDefaultCount > 0) {
|
||||
$first = $this->model->order('id', 'asc')->find();
|
||||
if ($first) {
|
||||
$this->model->where('id', (int) $first['id'])->update(['is_default' => 1]);
|
||||
}
|
||||
}
|
||||
return (bool) $result;
|
||||
});
|
||||
}
|
||||
|
||||
private function normalizeDefaultField(array &$data): void
|
||||
{
|
||||
if (!array_key_exists('is_default', $data)) {
|
||||
return;
|
||||
}
|
||||
$data['is_default'] = ((int) $data['is_default']) === 1 ? 1 : 0;
|
||||
}
|
||||
|
||||
private function clearOtherDefaults(?int $excludeId = null): void
|
||||
{
|
||||
$query = $this->model->where('is_default', 1);
|
||||
if ($excludeId !== null && $excludeId > 0) {
|
||||
$query->where('id', '<>', $excludeId);
|
||||
}
|
||||
$query->update(['is_default' => 0]);
|
||||
}
|
||||
}
|
||||
48
server/app/dice/model/ante_config/DiceAnteConfig.php
Normal file
48
server/app/dice/model/ante_config/DiceAnteConfig.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\model\ante_config;
|
||||
|
||||
use plugin\saiadmin\basic\think\BaseModel;
|
||||
|
||||
/**
|
||||
* 底注配置模型
|
||||
*
|
||||
* @property int $id ID
|
||||
* @property string $name 名称
|
||||
* @property string $title 标题
|
||||
* @property int $is_default 是否默认底注:0否 1是(全表仅允许一条为1)
|
||||
* @property int $mult 底注倍率
|
||||
* @property string $create_time 创建时间
|
||||
* @property string $update_time 更新时间
|
||||
*/
|
||||
class DiceAnteConfig extends BaseModel
|
||||
{
|
||||
protected $pk = 'id';
|
||||
|
||||
protected $table = 'dice_ante_config';
|
||||
|
||||
public function searchNameAttr($query, $value): void
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('name', 'like', '%' . $value . '%');
|
||||
}
|
||||
}
|
||||
|
||||
public function searchTitleAttr($query, $value): void
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('title', 'like', '%' . $value . '%');
|
||||
}
|
||||
}
|
||||
|
||||
public function searchIsDefaultAttr($query, $value): void
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('is_default', (int) $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: your name
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\dice\validate\ante_config;
|
||||
|
||||
use plugin\saiadmin\basic\BaseValidate;
|
||||
|
||||
/**
|
||||
* 底注配置验证器
|
||||
*/
|
||||
class DiceAnteConfigValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'name' => 'require|max:64',
|
||||
'title' => 'require|max:255',
|
||||
'is_default' => 'require|in:0,1',
|
||||
'mult' => 'require|integer|gt:0',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'name' => '名称必须填写',
|
||||
'title' => '标题必须填写',
|
||||
'is_default' => '默认底注标记必须为 0 或 1',
|
||||
'mult' => '底注倍率必须为大于 0 的整数',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'save' => ['name', 'title', 'is_default', 'mult'],
|
||||
'update' => ['name', 'title', 'is_default', 'mult'],
|
||||
];
|
||||
}
|
||||
17
server/db/dice_ante_config.sql
Normal file
17
server/db/dice_ante_config.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
-- 底注配置表
|
||||
CREATE TABLE IF NOT EXISTS `dice_ante_config` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`name` varchar(64) NOT NULL COMMENT '名称',
|
||||
`title` varchar(255) NOT NULL COMMENT '标题',
|
||||
`is_default` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否默认底注:0否 1是(全表只允许一条)',
|
||||
`mult` int NOT NULL DEFAULT 1 COMMENT '底注倍率',
|
||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_is_default` (`is_default`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Dice 底注配置表';
|
||||
|
||||
-- 可选初始化数据(保留一条默认底注)
|
||||
INSERT INTO `dice_ante_config` (`name`, `title`, `is_default`, `mult`)
|
||||
SELECT 'default', '默认底注', 1, 1
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `dice_ante_config` LIMIT 1);
|
||||
62
server/db/dice_ante_config_menu.sql
Normal file
62
server/db/dice_ante_config_menu.sql
Normal file
@@ -0,0 +1,62 @@
|
||||
-- 底注配置菜单与权限
|
||||
-- 说明:默认挂载在「大富翁」目录(path=/dice)下;若不存在则自动创建目录。
|
||||
|
||||
SET @now = NOW();
|
||||
|
||||
-- 1) 找到或创建 Dice 顶级目录
|
||||
SET @dice_root_id = (
|
||||
SELECT `id` FROM `sa_system_menu`
|
||||
WHERE `path` = '/dice' AND `type` = 1
|
||||
ORDER BY `id` ASC LIMIT 1
|
||||
);
|
||||
|
||||
INSERT INTO `sa_system_menu`
|
||||
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`icon`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
|
||||
SELECT 0, '大富翁', 'Dice', NULL, 1, '/dice', NULL, NULL, 'ri:gamepad-line', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
|
||||
WHERE @dice_root_id IS NULL;
|
||||
|
||||
SET @dice_root_id = (
|
||||
SELECT `id` FROM `sa_system_menu`
|
||||
WHERE `path` = '/dice' AND `type` = 1
|
||||
ORDER BY `id` ASC LIMIT 1
|
||||
);
|
||||
|
||||
-- 2) 创建底注配置菜单
|
||||
INSERT INTO `sa_system_menu`
|
||||
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`icon`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
|
||||
SELECT @dice_root_id, '底注配置', 'AnteConfig', NULL, 2, 'ante_config', '/dice/ante_config/index', NULL, 'ri:coins-line', 92, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM `sa_system_menu` WHERE `path` = 'ante_config' AND `component` = '/dice/ante_config/index' AND `type` = 2
|
||||
);
|
||||
|
||||
SET @ante_menu_id = (
|
||||
SELECT `id` FROM `sa_system_menu`
|
||||
WHERE `path` = 'ante_config' AND `component` = '/dice/ante_config/index' AND `type` = 2
|
||||
ORDER BY `id` ASC LIMIT 1
|
||||
);
|
||||
|
||||
-- 3) 创建按钮权限
|
||||
INSERT INTO `sa_system_menu`
|
||||
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
|
||||
SELECT @ante_menu_id, '数据列表', '', 'dice:ante_config:index:index', 3, '', '', '', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `sa_system_menu` WHERE `slug` = 'dice:ante_config:index:index' AND `type` = 3);
|
||||
|
||||
INSERT INTO `sa_system_menu`
|
||||
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
|
||||
SELECT @ante_menu_id, '读取', '', 'dice:ante_config:index:read', 3, '', '', '', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `sa_system_menu` WHERE `slug` = 'dice:ante_config:index:read' AND `type` = 3);
|
||||
|
||||
INSERT INTO `sa_system_menu`
|
||||
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
|
||||
SELECT @ante_menu_id, '添加', '', 'dice:ante_config:index:save', 3, '', '', '', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `sa_system_menu` WHERE `slug` = 'dice:ante_config:index:save' AND `type` = 3);
|
||||
|
||||
INSERT INTO `sa_system_menu`
|
||||
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
|
||||
SELECT @ante_menu_id, '修改', '', 'dice:ante_config:index:update', 3, '', '', '', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `sa_system_menu` WHERE `slug` = 'dice:ante_config:index:update' AND `type` = 3);
|
||||
|
||||
INSERT INTO `sa_system_menu`
|
||||
(`parent_id`,`name`,`code`,`slug`,`type`,`path`,`component`,`method`,`sort`,`is_iframe`,`is_keep_alive`,`is_hidden`,`is_fixed_tab`,`is_full_page`,`generate_id`,`generate_key`,`status`,`create_time`,`update_time`)
|
||||
SELECT @ante_menu_id, '删除', '', 'dice:ante_config:index:destroy', 3, '', '', '', 100, 2, 2, 2, 2, 2, 0, NULL, 1, @now, @now
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `sa_system_menu` WHERE `slug` = 'dice:ante_config:index:destroy' AND `type` = 3);
|
||||
@@ -118,6 +118,7 @@ Route::group('/core', function () {
|
||||
Route::post('/dice/reward_config/DiceRewardConfig/batchUpdate', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'batchUpdate']);
|
||||
Route::post('/dice/reward_config/DiceRewardConfig/createRewardReference', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'createRewardReference']);
|
||||
Route::post('/dice/reward_config/DiceRewardConfig/runWeightTest', [\app\dice\controller\reward_config\DiceRewardConfigController::class, 'runWeightTest']);
|
||||
fastRoute('dice/ante_config/DiceAnteConfig', \app\dice\controller\ante_config\DiceAnteConfigController::class);
|
||||
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']);
|
||||
|
||||
Reference in New Issue
Block a user