#feature: some update
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\ErpRequestReportService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class ErpRequestReportConfigController extends Controller
|
||||
{
|
||||
public function __construct(private readonly ConfigService $configService) {}
|
||||
|
||||
public function show(): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'dingtalk_token_configured' => filled($this->configService->get(ErpRequestReportService::DINGTALK_TOKEN_CONFIG_KEY)),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'dingtalk_token' => ['required', 'string', 'max:2048'],
|
||||
]);
|
||||
|
||||
$token = trim($validated['dingtalk_token']);
|
||||
if ($token === '') {
|
||||
throw ValidationException::withMessages([
|
||||
'dingtalk_token' => 'Token 不能为空',
|
||||
]);
|
||||
}
|
||||
|
||||
$this->configService->set(
|
||||
ErpRequestReportService::DINGTALK_TOKEN_CONFIG_KEY,
|
||||
$token,
|
||||
'ERP 请求日报钉钉机器人 Token'
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'ERP 请求日报钉钉机器人 Token 已保存',
|
||||
'data' => [
|
||||
'dingtalk_token_configured' => true,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user