- 在 SyncAdminAuthorizationCommand 中新增对代理线路和结算菜单操作的同步功能,确保缺失的菜单操作行能够被创建。 - 更新多个控制器中的权限检查逻辑,使用 hasPermissionCode 替代原有的权限验证方式,提升权限管理的灵活性。 - 在 AdminPlayerStoreController 中引入对玩家创建能力的验证,确保只有具备相应权限的管理员能够创建玩家。 - 更新请求验证逻辑,新增 credit_limit、rebate_rate 和 extra_rebate_rate 字段,以支持更细粒度的玩家管理。 - 在 AdminUser 和 AgentNode 模型中增强角色与用户的权限管理功能,支持更细粒度的权限控制。
101 lines
2.9 KiB
PHP
101 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Player;
|
|
|
|
use App\Models\Player;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
final class PlayerCreditService
|
|
{
|
|
/**
|
|
* @param array{credit_limit?: int} $payload
|
|
*/
|
|
public function upsertAccount(Player $player, array $payload): void
|
|
{
|
|
$limit = max(0, (int) ($payload['credit_limit'] ?? 0));
|
|
|
|
DB::table('player_credit_accounts')->updateOrInsert(
|
|
['player_id' => $player->id],
|
|
[
|
|
'credit_limit' => $limit,
|
|
'used_credit' => DB::raw('COALESCE(used_credit, 0)'),
|
|
'frozen_credit' => DB::raw('COALESCE(frozen_credit, 0)'),
|
|
'updated_at' => now(),
|
|
'created_at' => now(),
|
|
],
|
|
);
|
|
}
|
|
|
|
public function availableCredit(Player $player): int
|
|
{
|
|
$row = DB::table('player_credit_accounts')->where('player_id', $player->id)->first();
|
|
if ($row === null) {
|
|
return 0;
|
|
}
|
|
|
|
return max(0, (int) $row->credit_limit - (int) $row->used_credit - (int) $row->frozen_credit);
|
|
}
|
|
|
|
public function holdForBet(Player $player, int $amount): void
|
|
{
|
|
if ($amount <= 0) {
|
|
return;
|
|
}
|
|
|
|
if (! \App\Support\CreditLineMode::isEnabledForSiteCode((string) $player->site_code)) {
|
|
return;
|
|
}
|
|
|
|
$available = $this->availableCredit($player);
|
|
if ($amount > $available) {
|
|
throw ValidationException::withMessages([
|
|
'credit' => ['insufficient'],
|
|
]);
|
|
}
|
|
|
|
DB::table('player_credit_accounts')
|
|
->where('player_id', $player->id)
|
|
->update([
|
|
'used_credit' => DB::raw('used_credit + '.$amount),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
DB::table('credit_ledger')->insert([
|
|
'owner_type' => 'player',
|
|
'owner_id' => $player->id,
|
|
'amount' => -$amount,
|
|
'reason' => 'bet_hold',
|
|
'ref_type' => 'bet',
|
|
'ref_id' => null,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
}
|
|
|
|
public function releaseFromSettlement(Player $player, int $amount, int $billId): void
|
|
{
|
|
if ($amount <= 0) {
|
|
return;
|
|
}
|
|
|
|
DB::table('player_credit_accounts')
|
|
->where('player_id', $player->id)
|
|
->update([
|
|
'used_credit' => DB::raw('GREATEST(0, used_credit - '.$amount.')'),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
DB::table('credit_ledger')->insert([
|
|
'owner_type' => 'player',
|
|
'owner_id' => $player->id,
|
|
'amount' => $amount,
|
|
'reason' => 'settlement_confirm',
|
|
'ref_type' => 'settlement_bill',
|
|
'ref_id' => $billId,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
}
|
|
}
|