[色子游戏]玩家钱包流水记录-优化样式
This commit is contained in:
@@ -9,6 +9,7 @@ namespace app\dice\controller\player_wallet_record;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use app\dice\logic\player_wallet_record\DicePlayerWalletRecordLogic;
|
||||
use app\dice\validate\player_wallet_record\DicePlayerWalletRecordValidate;
|
||||
use app\dice\model\player\DicePlayer;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
@@ -38,6 +39,9 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
{
|
||||
$where = $request->more([
|
||||
['type', ''],
|
||||
['username', ''],
|
||||
['coin_min', ''],
|
||||
['coin_max', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$query->with([
|
||||
@@ -47,6 +51,41 @@ class DicePlayerWalletRecordController extends BaseController
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取玩家选项(id、username)用于下拉
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家钱包流水列表', 'dice:player_wallet_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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定玩家当前平台币(用于钱包操作前)
|
||||
* 类型 0=充值 1=提现 2=购买抽奖次数,操作前均为当前平台币
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('玩家钱包流水读取', 'dice:player_wallet_record:index:read')]
|
||||
public function getPlayerWalletBefore(Request $request): Response
|
||||
{
|
||||
$playerId = $request->input('player_id');
|
||||
if ($playerId === null || $playerId === '') {
|
||||
return $this->fail('缺少 player_id');
|
||||
}
|
||||
$player = DicePlayer::field('coin')->where('id', $playerId)->find();
|
||||
if (!$player) {
|
||||
return $this->fail('玩家不存在');
|
||||
}
|
||||
return $this->success(['wallet_before' => (float) $player['coin']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
|
||||
@@ -24,4 +24,15 @@ class DicePlayerWalletRecordLogic extends BaseLogic
|
||||
$this->model = new DicePlayerWalletRecord();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加数据(补全抽奖次数字段默认值)
|
||||
*/
|
||||
public function add(array $data): mixed
|
||||
{
|
||||
$data['total_draw_count'] = $data['total_draw_count'] ?? 0;
|
||||
$data['paid_draw_count'] = $data['paid_draw_count'] ?? 0;
|
||||
$data['free_draw_count'] = $data['free_draw_count'] ?? 0;
|
||||
return parent::add($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,12 +17,13 @@ use plugin\saiadmin\basic\think\BaseModel;
|
||||
* @property $id ID
|
||||
* @property $player_id 用户id
|
||||
* @property $coin 平台币变化
|
||||
* @property $type 类型
|
||||
* @property $type 类型:0=充值 1=提现 2=购买抽奖次数
|
||||
* @property $wallet_before 钱包操作前
|
||||
* @property $wallet_after 钱包操作后
|
||||
* @property $total_draw_count 总抽奖次数
|
||||
* @property $paid_draw_count 购买抽奖次数
|
||||
* @property $free_draw_count 赠送抽奖次数
|
||||
* @property $remark 备注
|
||||
* @property $create_time 创建时间
|
||||
* @property $update_time 修改时间
|
||||
*/
|
||||
@@ -48,4 +49,49 @@ class DicePlayerWalletRecord extends BaseModel
|
||||
return $this->belongsTo(DicePlayer::class, 'player_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 类型 搜索
|
||||
*/
|
||||
public function searchTypeAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('type', '=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按关联玩家用户名搜索(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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台币下限 搜索(withSearch 用 Str::studly 故方法名为 searchCoinMinAttr)
|
||||
*/
|
||||
public function searchCoinMinAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('coin', '>=', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台币上限 搜索(withSearch 用 Str::studly 故方法名为 searchCoinMaxAttr)
|
||||
*/
|
||||
public function searchCoinMaxAttr($query, $value)
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
$query->where('coin', '<=', $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,47 +16,31 @@ class DicePlayerWalletRecordValidate extends BaseValidate
|
||||
/**
|
||||
* 定义验证规则
|
||||
*/
|
||||
protected $rule = [
|
||||
protected $rule = [
|
||||
'player_id' => 'require',
|
||||
'coin' => 'require',
|
||||
'type' => 'require',
|
||||
'total_draw_count' => 'require',
|
||||
'paid_draw_count' => 'require',
|
||||
'free_draw_count' => 'require',
|
||||
'wallet_before' => 'require',
|
||||
'wallet_after' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
*/
|
||||
protected $message = [
|
||||
'player_id' => '用户id必须填写',
|
||||
protected $message = [
|
||||
'player_id' => '用户必须选择',
|
||||
'coin' => '平台币变化必须填写',
|
||||
'type' => '类型必须填写',
|
||||
'total_draw_count' => '总抽奖次数必须填写',
|
||||
'paid_draw_count' => '购买抽奖次数必须填写',
|
||||
'free_draw_count' => '赠送抽奖次数必须填写',
|
||||
'wallet_before' => '钱包操作前不能为空',
|
||||
'wallet_after' => '钱包操作后不能为空',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义场景
|
||||
*/
|
||||
protected $scene = [
|
||||
'save' => [
|
||||
'player_id',
|
||||
'coin',
|
||||
'type',
|
||||
'total_draw_count',
|
||||
'paid_draw_count',
|
||||
'free_draw_count',
|
||||
],
|
||||
'update' => [
|
||||
'player_id',
|
||||
'coin',
|
||||
'type',
|
||||
'total_draw_count',
|
||||
'paid_draw_count',
|
||||
'free_draw_count',
|
||||
],
|
||||
'save' => ['player_id', 'coin', 'type', 'wallet_before', 'wallet_after'],
|
||||
'update' => ['player_id', 'coin', 'type', 'wallet_before', 'wallet_after'],
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user