diff --git a/saiadmin-artd/src/views/plugin/dice/api/player_coin_record/index.ts b/saiadmin-artd/src/views/plugin/dice/api/player_coin_record/index.ts index 185d80e..c9dae7e 100644 --- a/saiadmin-artd/src/views/plugin/dice/api/player_coin_record/index.ts +++ b/saiadmin-artd/src/views/plugin/dice/api/player_coin_record/index.ts @@ -61,5 +61,14 @@ export default { url: '/dice/player_coin_record/DicePlayerCoinRecord/destroy', data: params }) + }, + + /** + * 获取玩家选项(id、username)用于下拉 + */ + getPlayerOptions() { + return request.get({ + url: '/dice/player_coin_record/DicePlayerCoinRecord/getPlayerOptions' + }) } } diff --git a/saiadmin-artd/src/views/plugin/dice/player_coin_record/index/index.vue b/saiadmin-artd/src/views/plugin/dice/player_coin_record/index/index.vue index 89a8840..f4701e4 100644 --- a/saiadmin-artd/src/views/plugin/dice/player_coin_record/index/index.vue +++ b/saiadmin-artd/src/views/plugin/dice/player_coin_record/index/index.vue @@ -79,12 +79,30 @@ // 搜索表单 - const searchForm = ref({ + const searchForm = ref>({ + username: undefined, + use_coins_min: undefined, + use_coins_max: undefined, + total_draw_count_min: undefined, + total_draw_count_max: undefined, + paid_draw_count_min: undefined, + paid_draw_count_max: undefined, + free_draw_count_min: undefined, + free_draw_count_max: undefined, + create_time_min: undefined, + create_time_max: undefined, + create_time: undefined as [string, string] | undefined }) - // 搜索处理 + // 搜索处理(将创建时间范围 create_time 转为 create_time_min / create_time_max) const handleSearch = (params: Record) => { - Object.assign(searchParams, params) + const p = { ...params } + if (Array.isArray(p.create_time) && p.create_time.length === 2) { + p.create_time_min = p.create_time[0] + p.create_time_max = p.create_time[1] + } + delete p.create_time + Object.assign(searchParams, p) getData() } @@ -105,15 +123,22 @@ } = useTable({ core: { apiFn: api.list, - columnsFactory: () => [ - { type: 'selection' }, - { prop: 'player_id', label: '玩家id' }, - { prop: 'use_coins', label: '消耗硬币' }, - { prop: 'total_draw_count', label: '总抽奖次数' }, - { prop: 'paid_draw_count', label: '购买抽奖次数' }, - { prop: 'free_draw_count', label: '赠送抽奖次数' }, - { prop: 'operation', label: '操作', width: 100, fixed: 'right', useSlot: true } - ] + columnsFactory: () => { + const usernameFormatter = (row: Record) => + row?.dicePlayer?.username ?? row?.player_id ?? '-' + return [ + { type: 'selection' }, + { prop: 'id', label: 'ID', width: 80 }, + { prop: 'player_id', label: '玩家用户名', formatter: (row: Record) => usernameFormatter(row) }, + { prop: 'use_coins', label: '消耗硬币' }, + { prop: 'total_draw_count', label: '总抽奖次数' }, + { prop: 'paid_draw_count', label: '购买抽奖次数' }, + { prop: 'free_draw_count', label: '赠送抽奖次数' }, + { prop: 'remark', label: '备注', width: 100, showOverflowTooltip: true }, + { prop: 'create_time', label: '创建时间', width: 170 }, + { prop: 'operation', label: '操作', width: 100, fixed: 'right', useSlot: true } + ] + } } }) diff --git a/saiadmin-artd/src/views/plugin/dice/player_coin_record/index/modules/edit-dialog.vue b/saiadmin-artd/src/views/plugin/dice/player_coin_record/index/modules/edit-dialog.vue index 9a6fbf2..9ea0915 100644 --- a/saiadmin-artd/src/views/plugin/dice/player_coin_record/index/modules/edit-dialog.vue +++ b/saiadmin-artd/src/views/plugin/dice/player_coin_record/index/modules/edit-dialog.vue @@ -8,20 +8,59 @@ @close="handleClose" > - - + + + + - - - - + - + - + + + + + + + @@ -60,3 +163,22 @@ } } + + diff --git a/server/app/dice/controller/player_coin_record/DicePlayerCoinRecordController.php b/server/app/dice/controller/player_coin_record/DicePlayerCoinRecordController.php index 18ef80d..6d8d119 100644 --- a/server/app/dice/controller/player_coin_record/DicePlayerCoinRecordController.php +++ b/server/app/dice/controller/player_coin_record/DicePlayerCoinRecordController.php @@ -9,6 +9,7 @@ namespace app\dice\controller\player_coin_record; use plugin\saiadmin\basic\BaseController; use app\dice\logic\player_coin_record\DicePlayerCoinRecordLogic; use app\dice\validate\player_coin_record\DicePlayerCoinRecordValidate; +use app\dice\model\player\DicePlayer; use plugin\saiadmin\service\Permission; use support\Request; use support\Response; @@ -37,6 +38,17 @@ class DicePlayerCoinRecordController extends BaseController public function index(Request $request): Response { $where = $request->more([ + ['username', ''], + ['use_coins_min', ''], + ['use_coins_max', ''], + ['total_draw_count_min', ''], + ['total_draw_count_max', ''], + ['paid_draw_count_min', ''], + ['paid_draw_count_max', ''], + ['free_draw_count_min', ''], + ['free_draw_count_max', ''], + ['create_time_min', ''], + ['create_time_max', ''], ]); $query = $this->logic->search($where); $query->with([ @@ -46,6 +58,21 @@ class DicePlayerCoinRecordController extends BaseController return $this->success($data); } + /** + * 获取玩家选项(id、username)用于下拉 + * @param Request $request + * @return Response + */ + #[Permission('玩家购买抽奖记录列表', 'dice:player_coin_record:index:index')] + public function getPlayerOptions(Request $request): Response + { + $list = DicePlayer::field('id,username')->select(); + $data = $list->map(function ($item) { + return ['id' => $item['id'], 'username' => $item['username'] ?? '']; + })->toArray(); + return $this->success($data); + } + /** * 读取数据 * @param Request $request diff --git a/server/app/dice/logic/player_coin_record/DicePlayerCoinRecordLogic.php b/server/app/dice/logic/player_coin_record/DicePlayerCoinRecordLogic.php index f472d5c..8a6a8c0 100644 --- a/server/app/dice/logic/player_coin_record/DicePlayerCoinRecordLogic.php +++ b/server/app/dice/logic/player_coin_record/DicePlayerCoinRecordLogic.php @@ -24,4 +24,29 @@ class DicePlayerCoinRecordLogic extends BaseLogic $this->model = new DicePlayerCoinRecord(); } + /** + * 添加前:总抽奖次数 = 购买抽奖次数 + 赠送抽奖次数 + */ + public function add(array $data): mixed + { + $data = $this->fillTotalDrawCount($data); + return parent::add($data); + } + + /** + * 修改前:总抽奖次数 = 购买抽奖次数 + 赠送抽奖次数 + */ + public function edit($id, array $data): mixed + { + $data = $this->fillTotalDrawCount($data); + return parent::edit($id, $data); + } + + private function fillTotalDrawCount(array $data): array + { + $paid = isset($data['paid_draw_count']) ? (int) $data['paid_draw_count'] : 0; + $free = isset($data['free_draw_count']) ? (int) $data['free_draw_count'] : 0; + $data['total_draw_count'] = $paid + $free; + return $data; + } } diff --git a/server/app/dice/model/player_coin_record/DicePlayerCoinRecord.php b/server/app/dice/model/player_coin_record/DicePlayerCoinRecord.php index eb25d37..e033550 100644 --- a/server/app/dice/model/player_coin_record/DicePlayerCoinRecord.php +++ b/server/app/dice/model/player_coin_record/DicePlayerCoinRecord.php @@ -6,7 +6,9 @@ // +---------------------------------------------------------------------- namespace app\dice\model\player_coin_record; +use app\dice\model\player\DicePlayer; use plugin\saiadmin\basic\think\BaseModel; +use think\model\relation\BelongsTo; /** * 玩家购买抽奖记录模型 @@ -40,9 +42,104 @@ class DicePlayerCoinRecord extends BaseModel /** * 关联模型 dicePlayer */ - public function dicePlayer() + public function dicePlayer(): BelongsTo { return $this->belongsTo(DicePlayer::class, 'player_id', 'id'); } + /** + * 按关联玩家用户名搜索(dicePlayer.username) + */ + public function searchUsernameAttr($query, $value) + { + if ($value === '' || $value === null) { + return; + } + $playerIds = DicePlayer::where('username', 'like', '%' . $value . '%')->column('id'); + if (!empty($playerIds)) { + $query->whereIn('player_id', $playerIds); + } else { + $query->whereRaw('1=0'); + } + } + + /** 消耗硬币下限 */ + public function searchUseCoinsMinAttr($query, $value) + { + if ($value !== '' && $value !== null) { + $query->where('use_coins', '>=', $value); + } + } + + /** 消耗硬币上限 */ + public function searchUseCoinsMaxAttr($query, $value) + { + if ($value !== '' && $value !== null) { + $query->where('use_coins', '<=', $value); + } + } + + /** 总抽奖次数下限 */ + public function searchTotalDrawCountMinAttr($query, $value) + { + if ($value !== '' && $value !== null) { + $query->where('total_draw_count', '>=', $value); + } + } + + /** 总抽奖次数上限 */ + public function searchTotalDrawCountMaxAttr($query, $value) + { + if ($value !== '' && $value !== null) { + $query->where('total_draw_count', '<=', $value); + } + } + + /** 购买抽奖次数下限 */ + public function searchPaidDrawCountMinAttr($query, $value) + { + if ($value !== '' && $value !== null) { + $query->where('paid_draw_count', '>=', $value); + } + } + + /** 购买抽奖次数上限 */ + public function searchPaidDrawCountMaxAttr($query, $value) + { + if ($value !== '' && $value !== null) { + $query->where('paid_draw_count', '<=', $value); + } + } + + /** 赠送抽奖次数下限 */ + public function searchFreeDrawCountMinAttr($query, $value) + { + if ($value !== '' && $value !== null) { + $query->where('free_draw_count', '>=', $value); + } + } + + /** 赠送抽奖次数上限 */ + public function searchFreeDrawCountMaxAttr($query, $value) + { + if ($value !== '' && $value !== null) { + $query->where('free_draw_count', '<=', $value); + } + } + + /** 创建时间起始 */ + public function searchCreateTimeMinAttr($query, $value) + { + if ($value !== '' && $value !== null) { + $query->where('create_time', '>=', $value); + } + } + + /** 创建时间结束 */ + public function searchCreateTimeMaxAttr($query, $value) + { + if ($value !== '' && $value !== null) { + $query->where('create_time', '<=', $value); + } + } } diff --git a/server/app/dice/validate/player_coin_record/DicePlayerCoinRecordValidate.php b/server/app/dice/validate/player_coin_record/DicePlayerCoinRecordValidate.php index cb42aec..05af46d 100644 --- a/server/app/dice/validate/player_coin_record/DicePlayerCoinRecordValidate.php +++ b/server/app/dice/validate/player_coin_record/DicePlayerCoinRecordValidate.php @@ -22,6 +22,7 @@ class DicePlayerCoinRecordValidate extends BaseValidate 'total_draw_count' => 'require', 'paid_draw_count' => 'require', 'free_draw_count' => 'require', + 'remark' => 'require', ]; /** @@ -33,6 +34,7 @@ class DicePlayerCoinRecordValidate extends BaseValidate 'total_draw_count' => '总抽奖次数必须填写', 'paid_draw_count' => '购买抽奖次数必须填写', 'free_draw_count' => '赠送抽奖次数必须填写', + 'remark' => '备注必须填写', ]; /** @@ -45,6 +47,7 @@ class DicePlayerCoinRecordValidate extends BaseValidate 'total_draw_count', 'paid_draw_count', 'free_draw_count', + 'remark', ], 'update' => [ 'player_id', @@ -52,6 +55,7 @@ class DicePlayerCoinRecordValidate extends BaseValidate 'total_draw_count', 'paid_draw_count', 'free_draw_count', + 'remark', ], ];