[色子游戏]玩家购买抽奖记录-优化样式

This commit is contained in:
2026-03-03 15:28:13 +08:00
parent 1b62a4f3e0
commit c02d19b1fd
8 changed files with 424 additions and 42 deletions

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}

View File

@@ -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',
],
];