Files
lotteryLaravel/app/Http/Controllers/Api/V1/Admin/Currency/AdminCurrencyDestroyController.php
kang 8ccf39dff5 refactor: 迁移彩票设置至 LotterySettings 服务
- 更新多个控制器和服务,使用 LotterySettings 服务获取彩票相关配置,如默认币种、开奖间隔、下注窗口等,提升代码一致性与可维护性。
- 移除 .env.example 中不再使用的配置项,建议通过后台管理进行设置。
2026-05-28 14:50:25 +08:00

71 lines
2.2 KiB
PHP

<?php
namespace App\Http\Controllers\Api\V1\Admin\Currency;
use App\Models\Currency;
use App\Lottery\ErrorCode;
use App\Support\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\DB;
use App\Services\LotterySettings;
use App\Http\Controllers\Controller;
final class AdminCurrencyDestroyController extends Controller
{
public function __invoke(Currency $currency): JsonResponse
{
$code = strtoupper((string) $currency->code);
if ($code === LotterySettings::defaultCurrency()) {
return ApiResponse::error(
'默认币种不可删除',
ErrorCode::ValidationFailed->value,
null,
422,
);
}
$references = $this->referenceSummary($code);
if ($references !== []) {
return ApiResponse::error(
'该币种已被业务数据引用,暂不可删除:'.implode('、', $references),
ErrorCode::ValidationFailed->value,
['references' => $references],
422,
);
}
$id = (int) $currency->id;
$currency->delete();
return ApiResponse::success([
'deleted' => true,
'id' => $id,
'code' => $code,
]);
}
/** @return list<string> */
private function referenceSummary(string $code): array
{
$checks = [
'玩家默认币种' => DB::table('players')->where('default_currency', $code),
'玩家钱包' => DB::table('player_wallets')->where('currency_code', $code),
'转账单' => DB::table('transfer_orders')->where('currency_code', $code),
'注单' => DB::table('ticket_orders')->where('currency_code', $code),
'赔率配置' => DB::table('odds_items')->where('currency_code', $code),
'奖池' => DB::table('jackpot_pools')->where('currency_code', $code),
'Jackpot 贡献记录' => DB::table('jackpot_contributions')->where('currency_code', $code),
];
$references = [];
foreach ($checks as $label => $query) {
if ($query->exists()) {
$references[] = $label;
}
}
return $references;
}
}