feat: 增强管理员功能与数据处理
- 在多个控制器中引入 agent_node_id,以支持基于代理节点的权限和数据过滤。 - 更新 AdminRole 和 AdminUser 模型,新增角色范围和代理节点相关功能,提升角色管理的灵活性。 - 在请求验证中添加 agent_node_id 字段,确保 API 接口支持代理节点的相关操作。 - 优化 LotterySettings 服务,支持批量写入设置,提升配置管理的效率。 - 更新仪表板和报告服务,增强数据统计功能,确保管理员能够获取更全面的统计信息。
This commit is contained in:
@@ -3,12 +3,16 @@
|
||||
namespace App\Http\Controllers\Api\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Middleware\RecordAdminApiAudit;
|
||||
use App\Http\Requests\Admin\AdminSettingBatchUpdateRequest;
|
||||
use App\Http\Requests\Admin\AdminSettingIndexRequest;
|
||||
use App\Http\Requests\Admin\AdminSettingUpdateRequest;
|
||||
use App\Models\LotterySetting;
|
||||
use App\Services\AuditLogger;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Services\LotterySettings;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* 后台:运营配置(KV 设置)读写。
|
||||
@@ -54,4 +58,47 @@ final class AdminSettingController extends Controller
|
||||
'description' => $fresh->description_zh,
|
||||
]);
|
||||
}
|
||||
|
||||
public function batchUpdate(AdminSettingBatchUpdateRequest $request): JsonResponse
|
||||
{
|
||||
/** @var list<array{key: string, value: mixed}> $items */
|
||||
$items = $request->validated('items');
|
||||
|
||||
DB::transaction(static function () use ($items): void {
|
||||
LotterySettings::putMany($items);
|
||||
});
|
||||
|
||||
$keys = array_map(static fn (array $item): string => (string) $item['key'], $items);
|
||||
$rows = LotterySetting::query()
|
||||
->whereIn('setting_key', $keys)
|
||||
->orderBy('setting_key')
|
||||
->get();
|
||||
|
||||
$admin = $request->lotteryAdmin();
|
||||
if ($admin !== null) {
|
||||
AuditLogger::recordForAdmin(
|
||||
$admin,
|
||||
$request,
|
||||
moduleCode: 'settings',
|
||||
actionCode: 'batch_update',
|
||||
targetType: 'lottery_settings',
|
||||
targetId: 'batch',
|
||||
beforeJson: null,
|
||||
afterJson: [
|
||||
'keys' => $keys,
|
||||
'count' => count($keys),
|
||||
],
|
||||
);
|
||||
$request->attributes->set(RecordAdminApiAudit::ATTRIBUTE_AUDIT_RECORDED, true);
|
||||
}
|
||||
|
||||
return ApiResponse::success([
|
||||
'items' => $rows->map(fn (LotterySetting $s): array => [
|
||||
'key' => $s->setting_key,
|
||||
'value' => $s->value_json,
|
||||
'group' => $s->group_name,
|
||||
'description' => $s->description_zh,
|
||||
])->values()->all(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user