1. 新增完整的后台玩家管理CRUD接口,包括列表、创建、详情、更新、删除 2. 新增转账订单冲正和人工处理功能,支持待对账订单状态变更 3. 扩展钱包流水和转账订单的状态支持,新增reversed、manually_processed等状态 4. 新增玩家API数据统一输出类,标准化玩家信息返回格式
52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Player;
|
|
|
|
use App\Models\Player;
|
|
use App\Lottery\ErrorCode;
|
|
use App\Support\ApiResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\JsonResponse;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
/** DELETE /api/v1/admin/players/{player} */
|
|
final class AdminPlayerDestroyController extends Controller
|
|
{
|
|
public function __invoke(Request $request, Player $player): JsonResponse
|
|
{
|
|
$hasWallets = Player::query()
|
|
->whereKey($player->getKey())
|
|
->whereHas('wallets', static fn (HasMany $q) => $q->whereRaw('balance != 0'))
|
|
->exists();
|
|
|
|
if ($hasWallets) {
|
|
return ApiResponse::error(
|
|
'该玩家钱包仍有余额,请先清空后再删除',
|
|
ErrorCode::ValidationFailed->value,
|
|
null,
|
|
422,
|
|
);
|
|
}
|
|
|
|
$hasTickets = Player::query()
|
|
->whereKey($player->getKey())
|
|
->whereHas('ticketOrders')
|
|
->exists();
|
|
|
|
if ($hasTickets) {
|
|
return ApiResponse::error(
|
|
'该玩家存在注单记录,无法删除',
|
|
ErrorCode::ValidationFailed->value,
|
|
null,
|
|
422,
|
|
);
|
|
}
|
|
|
|
$player->wallets()->delete();
|
|
$player->delete();
|
|
|
|
return ApiResponse::success(['deleted' => true]);
|
|
}
|
|
}
|