[游戏管理]-游戏奖励配置
This commit is contained in:
183
app/admin/controller/game/RewardConfig.php
Normal file
183
app/admin/controller/game/RewardConfig.php
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller\game;
|
||||||
|
|
||||||
|
use Throwable;
|
||||||
|
use app\common\controller\Backend;
|
||||||
|
use support\think\Db;
|
||||||
|
use support\Response;
|
||||||
|
use Webman\Http\Request as WebmanRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 游戏奖励配置
|
||||||
|
*/
|
||||||
|
class RewardConfig extends Backend
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* GameRewardConfig模型对象
|
||||||
|
* @var object|null
|
||||||
|
* @phpstan-var \app\common\model\GameRewardConfig|null
|
||||||
|
*/
|
||||||
|
protected ?object $model = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据范围:非超管仅本人 + 下级管理员负责的渠道
|
||||||
|
*/
|
||||||
|
protected bool|string|int $dataLimit = 'parent';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表/删除按渠道字段限制(实际值为渠道 ID)
|
||||||
|
*/
|
||||||
|
protected string $dataLimitField = 'game_channel_id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表无 admin_id,勿自动写入
|
||||||
|
*/
|
||||||
|
protected bool $dataLimitFieldAutoFill = false;
|
||||||
|
|
||||||
|
protected array|string $preExcludeFields = ['id', 'create_time', 'update_time'];
|
||||||
|
|
||||||
|
protected array $withJoinTable = ['gameChannel'];
|
||||||
|
|
||||||
|
protected string|array $quickSearchField = ['id'];
|
||||||
|
|
||||||
|
protected function initController(WebmanRequest $request): ?Response
|
||||||
|
{
|
||||||
|
$this->model = new \app\common\model\GameRewardConfig();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将可访问管理员 ID 转换为可访问渠道 ID
|
||||||
|
*
|
||||||
|
* @return list<int|string>
|
||||||
|
*/
|
||||||
|
protected function getDataLimitAdminIds(): array
|
||||||
|
{
|
||||||
|
if (!$this->dataLimit || !$this->auth || $this->auth->isSuperAdmin()) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$adminIds = parent::getDataLimitAdminIds();
|
||||||
|
if ($adminIds === []) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$channelIds = Db::name('game_channel')->where('admin_id', 'in', $adminIds)->column('id');
|
||||||
|
if ($channelIds === []) {
|
||||||
|
return [-1];
|
||||||
|
}
|
||||||
|
return array_values(array_unique($channelIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增:非超管仅可写入权限内渠道
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
protected function _add(): Response
|
||||||
|
{
|
||||||
|
if ($this->request && $this->request->method() === 'POST' && !$this->auth->isSuperAdmin()) {
|
||||||
|
$allowedChannelIds = $this->getDataLimitAdminIds();
|
||||||
|
$cid = $this->request->post('game_channel_id');
|
||||||
|
if ($cid === null || $cid === '' || ($allowedChannelIds !== [] && !in_array($cid, $allowedChannelIds))) {
|
||||||
|
return $this->error(__('You have no permission'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parent::_add();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑:非超管锁定渠道,不允许跨渠道改写
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
protected function _edit(): Response
|
||||||
|
{
|
||||||
|
$pk = $this->model->getPk();
|
||||||
|
$id = $this->request ? ($this->request->post($pk) ?? $this->request->get($pk)) : null;
|
||||||
|
$row = $this->model->find($id);
|
||||||
|
if (!$row) {
|
||||||
|
return $this->error(__('Record not found'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$dataLimitAdminIds = $this->getDataLimitAdminIds();
|
||||||
|
if ($dataLimitAdminIds && !in_array($row[$this->dataLimitField], $dataLimitAdminIds)) {
|
||||||
|
return $this->error(__('You have no permission'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->request && $this->request->method() === 'POST') {
|
||||||
|
$data = $this->request->post();
|
||||||
|
if (!$data) {
|
||||||
|
return $this->error(__('Parameter %s can not be empty', ['']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->applyInputFilter($data);
|
||||||
|
$data = $this->excludeFields($data);
|
||||||
|
|
||||||
|
if (!$this->auth->isSuperAdmin()) {
|
||||||
|
$data[$this->dataLimitField] = $row[$this->dataLimitField];
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = false;
|
||||||
|
$this->model->startTrans();
|
||||||
|
try {
|
||||||
|
if ($this->modelValidate) {
|
||||||
|
$validate = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
||||||
|
if (class_exists($validate)) {
|
||||||
|
$validate = new $validate();
|
||||||
|
if ($this->modelSceneValidate) {
|
||||||
|
$validate->scene('edit');
|
||||||
|
}
|
||||||
|
$data[$pk] = $row[$pk];
|
||||||
|
$validate->check($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = $row->save($data);
|
||||||
|
$this->model->commit();
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
$this->model->rollback();
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
if ($result !== false) {
|
||||||
|
return $this->success(__('Update successful'));
|
||||||
|
}
|
||||||
|
return $this->error(__('No rows updated'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->success('', ['row' => $row]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
protected function _index(): Response
|
||||||
|
{
|
||||||
|
// 如果是 select 则转发到 select 方法,若未重写该方法,其实还是继续执行 index
|
||||||
|
if ($this->request && $this->request->get('select')) {
|
||||||
|
return $this->select($this->request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1. withJoin 不可使用 alias 方法设置表别名,别名将自动使用关联模型名称(小写下划线命名规则)
|
||||||
|
* 2. 以下的别名设置了主表别名,同时便于拼接查询参数等
|
||||||
|
* 3. paginate 数据集可使用链式操作 each(function($item, $key) {}) 遍历处理
|
||||||
|
*/
|
||||||
|
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||||
|
$res = $this->model
|
||||||
|
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||||
|
->with($this->withJoinTable)
|
||||||
|
->visible(['gameChannel' => ['name']])
|
||||||
|
->alias($alias)
|
||||||
|
->where($where)
|
||||||
|
->order($order)
|
||||||
|
->paginate($limit);
|
||||||
|
|
||||||
|
return $this->success('', [
|
||||||
|
'list' => $res->items(),
|
||||||
|
'total' => $res->total(),
|
||||||
|
'remark' => get_route_remark(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 若需重写查看、编辑、删除等方法,请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
|
||||||
|
*/
|
||||||
|
}
|
||||||
29
app/common/model/GameRewardConfig.php
Normal file
29
app/common/model/GameRewardConfig.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
use support\think\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GameRewardConfig
|
||||||
|
*/
|
||||||
|
class GameRewardConfig extends Model
|
||||||
|
{
|
||||||
|
// 表名
|
||||||
|
protected $name = 'game_reward_config';
|
||||||
|
|
||||||
|
// 自动写入时间戳字段
|
||||||
|
protected $autoWriteTimestamp = true;
|
||||||
|
|
||||||
|
// 字段类型转换(避免时间戳被写成 'now' 字符串)
|
||||||
|
protected $type = [
|
||||||
|
'create_time' => 'integer',
|
||||||
|
'update_time' => 'integer',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
public function gameChannel(): \think\model\relation\BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(\app\common\model\GameChannel::class, 'game_channel_id', 'id');
|
||||||
|
}
|
||||||
|
}
|
||||||
143
app/common/validate/GameRewardConfig.php
Normal file
143
app/common/validate/GameRewardConfig.php
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\validate;
|
||||||
|
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
class GameRewardConfig extends Validate
|
||||||
|
{
|
||||||
|
protected $failException = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证规则
|
||||||
|
*/
|
||||||
|
protected $rule = [
|
||||||
|
'game_channel_id' => 'require|integer|gt:0',
|
||||||
|
'tier_reward_form' => 'require|checkTierRewardForm',
|
||||||
|
'bigwin_form' => 'require|checkBigwinForm',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提示消息
|
||||||
|
*/
|
||||||
|
protected $message = [
|
||||||
|
'game_channel_id.require' => '请选择渠道',
|
||||||
|
'game_channel_id.integer' => '渠道参数格式错误',
|
||||||
|
'game_channel_id.gt' => '渠道参数格式错误',
|
||||||
|
'tier_reward_form.require' => '档位奖励表单不能为空',
|
||||||
|
'bigwin_form.require' => '超级大奖表单不能为空',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证场景
|
||||||
|
*/
|
||||||
|
protected $scene = [
|
||||||
|
'add' => ['game_channel_id', 'tier_reward_form', 'bigwin_form'],
|
||||||
|
'edit' => ['game_channel_id', 'tier_reward_form', 'bigwin_form'],
|
||||||
|
];
|
||||||
|
|
||||||
|
private function parseJsonArray(mixed $value, string $label): array|string
|
||||||
|
{
|
||||||
|
if (!is_string($value) || trim($value) === '') {
|
||||||
|
return $label . '不能为空';
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$decoded = json_decode($value, true, 512, JSON_THROW_ON_ERROR);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $label . '必须为合法 JSON';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_array($decoded)) {
|
||||||
|
return $label . '格式错误';
|
||||||
|
}
|
||||||
|
return $decoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function checkTierRewardForm($value, $rule, array $data = []): bool|string
|
||||||
|
{
|
||||||
|
$decoded = $this->parseJsonArray($value, '档位奖励表单');
|
||||||
|
if (!is_array($decoded)) {
|
||||||
|
return $decoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
$expectedGrid = range(5, 30);
|
||||||
|
if (count($decoded) !== 26) {
|
||||||
|
return '档位奖励表单必须固定 26 条';
|
||||||
|
}
|
||||||
|
$allowTiers = ['T1', 'T2', 'T3', 'T4', 'T5'];
|
||||||
|
foreach ($decoded as $idx => $row) {
|
||||||
|
$rowNo = $idx + 1;
|
||||||
|
if (!is_array($row)) {
|
||||||
|
return '档位奖励表单第' . $rowNo . '条格式错误';
|
||||||
|
}
|
||||||
|
$gridNumber = $row['grid_number'] ?? null;
|
||||||
|
$uiText = $row['ui_text'] ?? null;
|
||||||
|
$realEv = $row['real_ev'] ?? null;
|
||||||
|
$tier = $row['tier'] ?? null;
|
||||||
|
|
||||||
|
if (!is_numeric($gridNumber)) {
|
||||||
|
return '档位奖励表单第' . $rowNo . '条点数必须为数字';
|
||||||
|
}
|
||||||
|
$gridInt = intval(strval($gridNumber));
|
||||||
|
if ($gridInt !== $expectedGrid[$idx]) {
|
||||||
|
return '档位奖励表单点数必须固定为 5-30 且不可修改';
|
||||||
|
}
|
||||||
|
if (!is_string($uiText) || trim($uiText) === '') {
|
||||||
|
return '档位奖励表单第' . $rowNo . '条显示文本不能为空';
|
||||||
|
}
|
||||||
|
if ($realEv === null || $realEv === '' || !is_numeric($realEv)) {
|
||||||
|
return '档位奖励表单第' . $rowNo . '条实际中奖必须为数字';
|
||||||
|
}
|
||||||
|
if (!is_string($tier) || !in_array($tier, $allowTiers, true)) {
|
||||||
|
return '档位奖励表单第' . $rowNo . '条档位只能是 T1-T5';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function checkBigwinForm($value, $rule, array $data = []): bool|string
|
||||||
|
{
|
||||||
|
$decoded = $this->parseJsonArray($value, '超级大奖表单');
|
||||||
|
if (!is_array($decoded)) {
|
||||||
|
return $decoded;
|
||||||
|
}
|
||||||
|
|
||||||
|
$expectedGrid = [5, 10, 15, 20, 25, 30];
|
||||||
|
if (count($decoded) !== 6) {
|
||||||
|
return '超级大奖表单必须固定 6 条';
|
||||||
|
}
|
||||||
|
foreach ($decoded as $idx => $row) {
|
||||||
|
$rowNo = $idx + 1;
|
||||||
|
if (!is_array($row)) {
|
||||||
|
return '超级大奖表单第' . $rowNo . '条格式错误';
|
||||||
|
}
|
||||||
|
|
||||||
|
$gridNumber = $row['grid_number'] ?? null;
|
||||||
|
$uiText = $row['ui_text'] ?? null;
|
||||||
|
$realEv = $row['real_ev'] ?? null;
|
||||||
|
$tier = $row['tier'] ?? null;
|
||||||
|
|
||||||
|
if (!is_numeric($gridNumber)) {
|
||||||
|
return '超级大奖表单第' . $rowNo . '条点数必须为数字';
|
||||||
|
}
|
||||||
|
$gridInt = intval(strval($gridNumber));
|
||||||
|
if ($gridInt !== $expectedGrid[$idx]) {
|
||||||
|
return '超级大奖表单点数必须固定为 5、10、15、20、25、30 且不可修改';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_string($uiText) || trim($uiText) === '') {
|
||||||
|
return '超级大奖表单第' . $rowNo . '条显示文本不能为空';
|
||||||
|
}
|
||||||
|
if ($realEv === null || $realEv === '' || !is_numeric($realEv)) {
|
||||||
|
return '超级大奖表单第' . $rowNo . '条实际中奖必须为数字';
|
||||||
|
}
|
||||||
|
if (!is_string($tier) || $tier !== 'BIGWIN') {
|
||||||
|
return '超级大奖表单第' . $rowNo . '条档位必须为 BIGWIN';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
web/src/lang/backend/en/game/rewardConfig.ts
Normal file
22
web/src/lang/backend/en/game/rewardConfig.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
export default {
|
||||||
|
id: 'id',
|
||||||
|
game_channel_id: 'game_channel_id',
|
||||||
|
gamechannel__name: 'name',
|
||||||
|
tier_reward_form: 'tier_reward_form',
|
||||||
|
bigwin_form: 'bigwin_form',
|
||||||
|
create_time: 'create_time',
|
||||||
|
update_time: 'update_time',
|
||||||
|
grid_number: 'grid_number',
|
||||||
|
ui_text: 'ui_text',
|
||||||
|
real_ev: 'real_ev',
|
||||||
|
tier: 'tier',
|
||||||
|
tier_t1: 'T1',
|
||||||
|
tier_t2: 'T2',
|
||||||
|
tier_t3: 'T3',
|
||||||
|
tier_t4: 'T4',
|
||||||
|
tier_t5: 'T5',
|
||||||
|
tier_bigwin: 'BIGWIN',
|
||||||
|
tier_reward_form_help: 'Fixed 26 rows (5-30), no add/delete. Editable: ui_text, real_ev, tier.',
|
||||||
|
bigwin_form_help: 'Fixed 6 rows (5,10,15,20,25,30), no add/delete. Editable: ui_text, real_ev.',
|
||||||
|
'quick Search Fields': 'id',
|
||||||
|
}
|
||||||
22
web/src/lang/backend/zh-cn/game/rewardConfig.ts
Normal file
22
web/src/lang/backend/zh-cn/game/rewardConfig.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
export default {
|
||||||
|
id: 'ID',
|
||||||
|
game_channel_id: '渠道',
|
||||||
|
gamechannel__name: '渠道名',
|
||||||
|
tier_reward_form: '档位奖励表单',
|
||||||
|
bigwin_form: '超级大奖表单',
|
||||||
|
create_time: '创建时间',
|
||||||
|
update_time: '更新时间',
|
||||||
|
grid_number: '色子点数',
|
||||||
|
ui_text: '显示文本',
|
||||||
|
real_ev: '实际中奖',
|
||||||
|
tier: '档位',
|
||||||
|
tier_t1: 'T1',
|
||||||
|
tier_t2: 'T2',
|
||||||
|
tier_t3: 'T3',
|
||||||
|
tier_t4: 'T4',
|
||||||
|
tier_t5: 'T5',
|
||||||
|
tier_bigwin: 'BIGWIN',
|
||||||
|
tier_reward_form_help: '固定 26 条(点数 5-30),不可新增或删除,仅可修改显示文本、实际中奖、档位',
|
||||||
|
bigwin_form_help: '固定 6 条(点数 5、10、15、20、25、30),不可新增或删除,仅可修改显示文本、实际中奖',
|
||||||
|
'quick Search Fields': 'ID',
|
||||||
|
}
|
||||||
59
web/src/views/backend/game/rewardConfig/BigwinFormCell.vue
Normal file
59
web/src/views/backend/game/rewardConfig/BigwinFormCell.vue
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<template>
|
||||||
|
<div class="form-cell">
|
||||||
|
<div v-if="rows.length === 0" class="empty">-</div>
|
||||||
|
<div v-for="(row, idx) in rows" :key="idx" class="row">
|
||||||
|
<el-tag size="small" effect="light">{{ row.grid_number }}</el-tag>
|
||||||
|
<el-tag size="small" type="danger" effect="light">{{ row.tier }}</el-tag>
|
||||||
|
<span>{{ row.ui_text }}</span>
|
||||||
|
<span>{{ row.real_ev }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps<{ row?: { bigwin_form?: unknown } }>()
|
||||||
|
|
||||||
|
type FormRow = { grid_number: string; ui_text: string; real_ev: string; tier: string }
|
||||||
|
|
||||||
|
const rows = computed<FormRow[]>(() => {
|
||||||
|
const raw = props.row?.bigwin_form
|
||||||
|
if (typeof raw !== 'string' || raw.trim() === '') return []
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(raw) as unknown
|
||||||
|
if (!Array.isArray(parsed)) return []
|
||||||
|
const out: FormRow[] = []
|
||||||
|
for (const item of parsed) {
|
||||||
|
if (item === null || typeof item !== 'object' || Array.isArray(item)) continue
|
||||||
|
const obj = item as Record<string, unknown>
|
||||||
|
out.push({
|
||||||
|
grid_number: String(obj.grid_number ?? ''),
|
||||||
|
ui_text: String(obj.ui_text ?? ''),
|
||||||
|
real_ev: String(obj.real_ev ?? ''),
|
||||||
|
tier: String(obj.tier ?? ''),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.form-cell {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
.empty {
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<template>
|
||||||
|
<div class="form-cell">
|
||||||
|
<div v-if="rows.length === 0" class="empty">-</div>
|
||||||
|
<div v-for="(row, idx) in rows" :key="idx" class="row">
|
||||||
|
<el-tag size="small" effect="light">{{ row.grid_number }}</el-tag>
|
||||||
|
<el-tag size="small" type="info" effect="light">{{ row.tier }}</el-tag>
|
||||||
|
<span>{{ row.ui_text }}</span>
|
||||||
|
<span>{{ row.real_ev }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
|
const props = defineProps<{ row?: { tier_reward_form?: unknown } }>()
|
||||||
|
|
||||||
|
type FormRow = { grid_number: string; ui_text: string; real_ev: string; tier: string }
|
||||||
|
|
||||||
|
const rows = computed<FormRow[]>(() => {
|
||||||
|
const raw = props.row?.tier_reward_form
|
||||||
|
if (typeof raw !== 'string' || raw.trim() === '') return []
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(raw) as unknown
|
||||||
|
if (!Array.isArray(parsed)) return []
|
||||||
|
const out: FormRow[] = []
|
||||||
|
for (const item of parsed) {
|
||||||
|
if (item === null || typeof item !== 'object' || Array.isArray(item)) continue
|
||||||
|
const obj = item as Record<string, unknown>
|
||||||
|
out.push({
|
||||||
|
grid_number: String(obj.grid_number ?? ''),
|
||||||
|
ui_text: String(obj.ui_text ?? ''),
|
||||||
|
real_ev: String(obj.real_ev ?? ''),
|
||||||
|
tier: String(obj.tier ?? ''),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.form-cell {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
.empty {
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
141
web/src/views/backend/game/rewardConfig/index.vue
Normal file
141
web/src/views/backend/game/rewardConfig/index.vue
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
<template>
|
||||||
|
<div class="default-main ba-table-box">
|
||||||
|
<el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />
|
||||||
|
|
||||||
|
<!-- 表格顶部菜单 -->
|
||||||
|
<!-- 自定义按钮请使用插槽,甚至公共搜索也可以使用具名插槽渲染,参见文档 -->
|
||||||
|
<TableHeader
|
||||||
|
:buttons="headerButtons"
|
||||||
|
:quick-search-placeholder="t('Quick search placeholder', { fields: t('game.rewardConfig.quick Search Fields') })"
|
||||||
|
></TableHeader>
|
||||||
|
|
||||||
|
<!-- 表格 -->
|
||||||
|
<!-- 表格列有多种自定义渲染方式,比如自定义组件、具名插槽等,参见文档 -->
|
||||||
|
<!-- 要使用 el-table 组件原有的属性,直接加在 Table 标签上即可 -->
|
||||||
|
<Table ref="tableRef"></Table>
|
||||||
|
|
||||||
|
<!-- 表单 -->
|
||||||
|
<PopupForm />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, onMounted, provide, useTemplateRef } from 'vue'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import PopupForm from './popupForm.vue'
|
||||||
|
import TierRewardFormCell from './TierRewardFormCell.vue'
|
||||||
|
import BigwinFormCell from './BigwinFormCell.vue'
|
||||||
|
import { baTableApi } from '/@/api/common'
|
||||||
|
import { defaultOptButtons } from '/@/components/table'
|
||||||
|
import TableHeader from '/@/components/table/header/index.vue'
|
||||||
|
import Table from '/@/components/table/index.vue'
|
||||||
|
import { useAdminInfo } from '/@/stores/adminInfo'
|
||||||
|
import baTableClass from '/@/utils/baTable'
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
name: 'game/rewardConfig',
|
||||||
|
})
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
const tableRef = useTemplateRef('tableRef')
|
||||||
|
const adminInfo = useAdminInfo()
|
||||||
|
const isSuperAdmin = computed(() => adminInfo.super === true)
|
||||||
|
const optButtons: OptButton[] = defaultOptButtons(['edit'])
|
||||||
|
const superHeaderButtons: HeaderOptButton[] = ['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']
|
||||||
|
const channelHeaderButtons: HeaderOptButton[] = ['refresh']
|
||||||
|
const tierRewardFormColumn: TableColumn = {
|
||||||
|
label: t('game.rewardConfig.tier_reward_form'),
|
||||||
|
prop: 'tier_reward_form',
|
||||||
|
align: 'center',
|
||||||
|
minWidth: 360,
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
sortable: false,
|
||||||
|
operator: 'LIKE',
|
||||||
|
comSearchRender: 'string',
|
||||||
|
render: 'customRender',
|
||||||
|
customRender: TierRewardFormCell,
|
||||||
|
}
|
||||||
|
const bigwinFormColumn: TableColumn = {
|
||||||
|
label: t('game.rewardConfig.bigwin_form'),
|
||||||
|
prop: 'bigwin_form',
|
||||||
|
align: 'center',
|
||||||
|
minWidth: 360,
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
sortable: false,
|
||||||
|
operator: 'LIKE',
|
||||||
|
comSearchRender: 'string',
|
||||||
|
render: 'customRender',
|
||||||
|
customRender: BigwinFormCell,
|
||||||
|
}
|
||||||
|
const headerButtons = computed(() => {
|
||||||
|
if (isSuperAdmin.value) {
|
||||||
|
return superHeaderButtons
|
||||||
|
}
|
||||||
|
return channelHeaderButtons
|
||||||
|
})
|
||||||
|
const columns: TableColumn[] = [
|
||||||
|
{ type: 'selection', align: 'center', operator: false },
|
||||||
|
{ label: t('game.rewardConfig.id'), prop: 'id', align: 'center', width: 70, operator: 'RANGE', sortable: 'custom' },
|
||||||
|
{
|
||||||
|
label: t('game.rewardConfig.gamechannel__name'),
|
||||||
|
prop: 'gameChannel.name',
|
||||||
|
align: 'center',
|
||||||
|
operatorPlaceholder: t('Fuzzy query'),
|
||||||
|
render: 'tags',
|
||||||
|
operator: 'LIKE',
|
||||||
|
comSearchRender: 'string',
|
||||||
|
},
|
||||||
|
...(isSuperAdmin.value ? [] : [tierRewardFormColumn, bigwinFormColumn]),
|
||||||
|
{
|
||||||
|
label: t('game.rewardConfig.create_time'),
|
||||||
|
prop: 'create_time',
|
||||||
|
align: 'center',
|
||||||
|
render: 'datetime',
|
||||||
|
operator: 'RANGE',
|
||||||
|
comSearchRender: 'datetime',
|
||||||
|
sortable: 'custom',
|
||||||
|
width: 160,
|
||||||
|
timeFormat: 'yyyy-mm-dd hh:MM:ss',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('game.rewardConfig.update_time'),
|
||||||
|
prop: 'update_time',
|
||||||
|
align: 'center',
|
||||||
|
render: 'datetime',
|
||||||
|
operator: 'RANGE',
|
||||||
|
comSearchRender: 'datetime',
|
||||||
|
sortable: 'custom',
|
||||||
|
width: 160,
|
||||||
|
timeFormat: 'yyyy-mm-dd hh:MM:ss',
|
||||||
|
},
|
||||||
|
{ label: t('Operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false },
|
||||||
|
]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* baTable 内包含了表格的所有数据且数据具备响应性,然后通过 provide 注入给了后代组件
|
||||||
|
*/
|
||||||
|
const baTable = new baTableClass(
|
||||||
|
new baTableApi('/admin/game.RewardConfig/'),
|
||||||
|
{
|
||||||
|
pk: 'id',
|
||||||
|
column: columns,
|
||||||
|
dblClickNotEditColumn: [undefined],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
defaultItems: {},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
provide('baTable', baTable)
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
baTable.table.ref = tableRef.value
|
||||||
|
baTable.mount()
|
||||||
|
baTable.getData()?.then(() => {
|
||||||
|
baTable.initSort()
|
||||||
|
baTable.dragSort()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss"></style>
|
||||||
264
web/src/views/backend/game/rewardConfig/popupForm.vue
Normal file
264
web/src/views/backend/game/rewardConfig/popupForm.vue
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
class="ba-operate-dialog"
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:model-value="['Add', 'Edit'].includes(baTable.form.operate!)"
|
||||||
|
@close="baTable.toggleForm"
|
||||||
|
>
|
||||||
|
<template #header>
|
||||||
|
<div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
|
||||||
|
{{ baTable.form.operate ? t(baTable.form.operate) : '' }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
|
||||||
|
<div
|
||||||
|
class="ba-operate-form"
|
||||||
|
:class="'ba-' + baTable.form.operate + '-form'"
|
||||||
|
:style="config.layout.shrink ? '' : 'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
|
||||||
|
>
|
||||||
|
<el-form
|
||||||
|
v-if="!baTable.form.loading"
|
||||||
|
ref="formRef"
|
||||||
|
@submit.prevent=""
|
||||||
|
:model="baTable.form.items"
|
||||||
|
:label-position="config.layout.shrink ? 'top' : 'right'"
|
||||||
|
:label-width="baTable.form.labelWidth + 'px'"
|
||||||
|
:rules="rules"
|
||||||
|
>
|
||||||
|
<FormItem
|
||||||
|
:label="t('game.rewardConfig.game_channel_id')"
|
||||||
|
type="remoteSelect"
|
||||||
|
v-model="baTable.form.items!.game_channel_id"
|
||||||
|
prop="game_channel_id"
|
||||||
|
:input-attr="{ ...channelRemoteAttr, disabled: channelFieldDisabled }"
|
||||||
|
:placeholder="t('Please select field', { field: t('game.rewardConfig.game_channel_id') })"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<el-form-item :label="t('game.rewardConfig.tier_reward_form')" prop="tier_reward_form">
|
||||||
|
<div class="block-editor">
|
||||||
|
<div class="line line-head">
|
||||||
|
<span>{{ t('game.rewardConfig.grid_number') }}</span>
|
||||||
|
<span>{{ t('game.rewardConfig.ui_text') }}</span>
|
||||||
|
<span>{{ t('game.rewardConfig.real_ev') }}</span>
|
||||||
|
<span>{{ t('game.rewardConfig.tier') }}</span>
|
||||||
|
</div>
|
||||||
|
<div v-for="(row, idx) in tierRows" :key="'tier-' + idx" class="line">
|
||||||
|
<el-input v-model="row.grid_number" disabled />
|
||||||
|
<el-input
|
||||||
|
v-model="row.ui_text"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.rewardConfig.ui_text') })"
|
||||||
|
@input="syncPayload"
|
||||||
|
/>
|
||||||
|
<el-input
|
||||||
|
v-model="row.real_ev"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.rewardConfig.real_ev') })"
|
||||||
|
@input="syncPayload"
|
||||||
|
/>
|
||||||
|
<el-select v-model="row.tier" style="width: 120px" @change="syncPayload">
|
||||||
|
<el-option :label="t('game.rewardConfig.tier_t1')" value="T1" />
|
||||||
|
<el-option :label="t('game.rewardConfig.tier_t2')" value="T2" />
|
||||||
|
<el-option :label="t('game.rewardConfig.tier_t3')" value="T3" />
|
||||||
|
<el-option :label="t('game.rewardConfig.tier_t4')" value="T4" />
|
||||||
|
<el-option :label="t('game.rewardConfig.tier_t5')" value="T5" />
|
||||||
|
</el-select>
|
||||||
|
</div>
|
||||||
|
<div class="form-help">{{ t('game.rewardConfig.tier_reward_form_help') }}</div>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item :label="t('game.rewardConfig.bigwin_form')" prop="bigwin_form">
|
||||||
|
<div class="block-editor">
|
||||||
|
<div class="line line-head">
|
||||||
|
<span>{{ t('game.rewardConfig.grid_number') }}</span>
|
||||||
|
<span>{{ t('game.rewardConfig.ui_text') }}</span>
|
||||||
|
<span>{{ t('game.rewardConfig.real_ev') }}</span>
|
||||||
|
<span>{{ t('game.rewardConfig.tier') }}</span>
|
||||||
|
</div>
|
||||||
|
<div v-for="(row, idx) in bigwinRows" :key="'bigwin-' + idx" class="line">
|
||||||
|
<el-input v-model="row.grid_number" disabled />
|
||||||
|
<el-input
|
||||||
|
v-model="row.ui_text"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.rewardConfig.ui_text') })"
|
||||||
|
@input="syncPayload"
|
||||||
|
/>
|
||||||
|
<el-input
|
||||||
|
v-model="row.real_ev"
|
||||||
|
:placeholder="t('Please input field', { field: t('game.rewardConfig.real_ev') })"
|
||||||
|
@input="syncPayload"
|
||||||
|
/>
|
||||||
|
<el-input v-model="row.tier" disabled style="width: 120px" />
|
||||||
|
</div>
|
||||||
|
<div class="form-help">{{ t('game.rewardConfig.bigwin_form_help') }}</div>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</el-scrollbar>
|
||||||
|
<template #footer>
|
||||||
|
<div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
|
||||||
|
<el-button @click="baTable.toggleForm()">{{ t('Cancel') }}</el-button>
|
||||||
|
<el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
|
||||||
|
{{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { FormItemRule } from 'element-plus'
|
||||||
|
import { computed, inject, reactive, ref, useTemplateRef, watch } from 'vue'
|
||||||
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import FormItem from '/@/components/formItem/index.vue'
|
||||||
|
import { useConfig } from '/@/stores/config'
|
||||||
|
import { useAdminInfo } from '/@/stores/adminInfo'
|
||||||
|
import type baTableClass from '/@/utils/baTable'
|
||||||
|
import { buildValidatorData } from '/@/utils/validate'
|
||||||
|
|
||||||
|
type RewardRow = { grid_number: string; ui_text: string; real_ev: string; tier: string }
|
||||||
|
|
||||||
|
const config = useConfig()
|
||||||
|
const formRef = useTemplateRef('formRef')
|
||||||
|
const baTable = inject('baTable') as baTableClass
|
||||||
|
const adminInfo = useAdminInfo()
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const TIER_GRIDS = Array.from({ length: 26 }, (_v, i) => String(i + 5))
|
||||||
|
const BIGWIN_GRIDS = ['5', '10', '15', '20', '25', '30']
|
||||||
|
|
||||||
|
const channelRemoteAttr = { pk: 'game_channel.id', field: 'name', remoteUrl: '/admin/game.Channel/index' }
|
||||||
|
const isSuperAdmin = computed(() => adminInfo.super === true)
|
||||||
|
const channelFieldDisabled = computed(() => !isSuperAdmin.value && baTable.form.operate === 'Edit')
|
||||||
|
|
||||||
|
const tierRows = ref<RewardRow[]>(TIER_GRIDS.map((g) => ({ grid_number: g, ui_text: '', real_ev: '', tier: 'T1' })))
|
||||||
|
const bigwinRows = ref<RewardRow[]>(BIGWIN_GRIDS.map((g) => ({ grid_number: g, ui_text: '', real_ev: '', tier: 'BIGWIN' })))
|
||||||
|
|
||||||
|
function parseRows(raw: unknown): RewardRow[] {
|
||||||
|
if (typeof raw !== 'string' || raw.trim() === '') return []
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(raw) as unknown
|
||||||
|
if (!Array.isArray(parsed)) return []
|
||||||
|
const out: RewardRow[] = []
|
||||||
|
for (const item of parsed) {
|
||||||
|
if (item === null || typeof item !== 'object' || Array.isArray(item)) continue
|
||||||
|
const obj = item as Record<string, unknown>
|
||||||
|
out.push({
|
||||||
|
grid_number: String(obj.grid_number ?? ''),
|
||||||
|
ui_text: String(obj.ui_text ?? ''),
|
||||||
|
real_ev: String(obj.real_ev ?? ''),
|
||||||
|
tier: String(obj.tier ?? ''),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toTierRows(raw: unknown): RewardRow[] {
|
||||||
|
const parsed = parseRows(raw)
|
||||||
|
const map = new Map<string, RewardRow>()
|
||||||
|
for (const r of parsed) map.set(r.grid_number, r)
|
||||||
|
return TIER_GRIDS.map((g) => {
|
||||||
|
const row = map.get(g)
|
||||||
|
return { grid_number: g, ui_text: row?.ui_text ?? '', real_ev: row?.real_ev ?? '', tier: row?.tier && row.tier !== 'BIGWIN' ? row.tier : 'T1' }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function toBigwinRows(raw: unknown): RewardRow[] {
|
||||||
|
const parsed = parseRows(raw)
|
||||||
|
const map = new Map<string, RewardRow>()
|
||||||
|
for (const r of parsed) map.set(r.grid_number, r)
|
||||||
|
return BIGWIN_GRIDS.map((g) => {
|
||||||
|
const row = map.get(g)
|
||||||
|
return { grid_number: g, ui_text: row?.ui_text ?? '', real_ev: row?.real_ev ?? '', tier: 'BIGWIN' }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncPayload() {
|
||||||
|
const items = baTable.form.items
|
||||||
|
if (!items) return
|
||||||
|
items.tier_reward_form = JSON.stringify(tierRows.value)
|
||||||
|
items.bigwin_form = JSON.stringify(bigwinRows.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateForms(): string | undefined {
|
||||||
|
if (tierRows.value.length !== 26 || bigwinRows.value.length !== 6) {
|
||||||
|
return t('Parameter error')
|
||||||
|
}
|
||||||
|
for (let i = 0; i < tierRows.value.length; i++) {
|
||||||
|
const row = tierRows.value[i]
|
||||||
|
if (row.grid_number !== TIER_GRIDS[i]) return t('Parameter error')
|
||||||
|
if (row.ui_text.trim() === '' || row.real_ev.trim() === '') return t('Please input field', { field: t('game.rewardConfig.ui_text') })
|
||||||
|
if (!Number.isFinite(Number(row.real_ev))) return t('game.rewardConfig.real_ev')
|
||||||
|
if (!['T1', 'T2', 'T3', 'T4', 'T5'].includes(row.tier)) return t('Parameter error')
|
||||||
|
}
|
||||||
|
for (let i = 0; i < bigwinRows.value.length; i++) {
|
||||||
|
const row = bigwinRows.value[i]
|
||||||
|
if (row.grid_number !== BIGWIN_GRIDS[i]) return t('Parameter error')
|
||||||
|
if (row.tier !== 'BIGWIN') return t('Parameter error')
|
||||||
|
if (row.ui_text.trim() === '' || row.real_ev.trim() === '') return t('Please input field', { field: t('game.rewardConfig.ui_text') })
|
||||||
|
if (!Number.isFinite(Number(row.real_ev))) return t('game.rewardConfig.real_ev')
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => baTable.form.loading,
|
||||||
|
(loading) => {
|
||||||
|
if (loading === false) {
|
||||||
|
tierRows.value = toTierRows(baTable.form.items?.tier_reward_form)
|
||||||
|
bigwinRows.value = toBigwinRows(baTable.form.items?.bigwin_form)
|
||||||
|
syncPayload()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const rules: Partial<Record<string, FormItemRule[]>> = reactive({
|
||||||
|
game_channel_id: [buildValidatorData({ name: 'required', title: t('game.rewardConfig.game_channel_id') })],
|
||||||
|
tier_reward_form: [
|
||||||
|
{
|
||||||
|
validator: (_rule, _val, callback) => {
|
||||||
|
const err = validateForms()
|
||||||
|
if (err) return callback(new Error(err))
|
||||||
|
callback()
|
||||||
|
},
|
||||||
|
trigger: ['blur', 'change'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
bigwin_form: [
|
||||||
|
{
|
||||||
|
validator: (_rule, _val, callback) => {
|
||||||
|
const err = validateForms()
|
||||||
|
if (err) return callback(new Error(err))
|
||||||
|
callback()
|
||||||
|
},
|
||||||
|
trigger: ['blur', 'change'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.block-editor {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.line {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 110px 1fr 1fr 120px;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
.line-head {
|
||||||
|
margin-bottom: 6px;
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 20px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.form-help {
|
||||||
|
margin-top: 6px;
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user