|
@@ -303,62 +303,25 @@ class Config extends Controller
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
try {
|
|
try {
|
|
|
$type = request()->input('type', 'image');
|
|
$type = request()->input('type', 'image');
|
|
|
- if ($type == 'image') {
|
|
|
|
|
- request()->validate([
|
|
|
|
|
- 'chatId' => ['required', 'string', 'min:1'],
|
|
|
|
|
- 'type' => ['required', 'string', 'in:image,video,text'],
|
|
|
|
|
- 'image' => ['required', 'url'],
|
|
|
|
|
- 'text' => ['nullable', 'string'],
|
|
|
|
|
- 'isSend' => ['nullable', 'boolean'],
|
|
|
|
|
- 'isTop' => ['nullable', 'boolean'],
|
|
|
|
|
- 'button' => ['array'],
|
|
|
|
|
- 'button.*' => ['required', 'array'],
|
|
|
|
|
- 'button.*.*.text' => ['required', 'string'],
|
|
|
|
|
- 'button.*.*.url' => ['required', 'url'],
|
|
|
|
|
-
|
|
|
|
|
- ]);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- } else if ($type == 'video') {
|
|
|
|
|
- request()->validate([
|
|
|
|
|
- 'chatId' => ['required', 'string', 'min:1'],
|
|
|
|
|
- 'video' => ['required', 'url'],
|
|
|
|
|
- 'text' => ['nullable', 'string'],
|
|
|
|
|
- 'isSend' => ['nullable', 'boolean'],
|
|
|
|
|
- 'isTop' => ['nullable', 'boolean'],
|
|
|
|
|
- ]);
|
|
|
|
|
- } else {
|
|
|
|
|
- request()->validate([
|
|
|
|
|
- 'chatId' => ['required', 'string', 'min:1'],
|
|
|
|
|
- 'text' => ['required', 'string', 'min:1'],
|
|
|
|
|
- 'isSend' => ['nullable', 'boolean'],
|
|
|
|
|
- 'isTop' => ['nullable', 'boolean'],
|
|
|
|
|
- 'button' => ['array'],
|
|
|
|
|
- 'button.*' => ['required', 'array'],
|
|
|
|
|
- 'button.*.*.text' => ['required', 'string'],
|
|
|
|
|
- 'button.*.*.url' => ['required', 'url'],
|
|
|
|
|
-
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+ $validate = [
|
|
|
|
|
+ 'chatId' => ['required', 'string', 'min:1'],
|
|
|
|
|
+ 'type' => ['required', 'string', 'in:image,video,text'],
|
|
|
|
|
+ 'text' => ['nullable', 'string'],
|
|
|
|
|
+ 'isSend' => ['nullable', 'boolean'],
|
|
|
|
|
+ 'isTop' => ['nullable', 'boolean'],
|
|
|
|
|
+ 'button' => ['array'],
|
|
|
|
|
+ 'button.*' => ['required', 'array'],
|
|
|
|
|
+ 'button.*.*.text' => ['required', 'string'],
|
|
|
|
|
+ 'button.*.*.url' => ['required', 'url'],
|
|
|
|
|
+ ];
|
|
|
|
|
+ if (in_array($type, ['image', 'video'])) {
|
|
|
|
|
+ $validate['image'] = ['required', 'url'];
|
|
|
}
|
|
}
|
|
|
- $chatId = request()->input('chatId');
|
|
|
|
|
- $image = request()->input('image');
|
|
|
|
|
- $button = request()->input('button');
|
|
|
|
|
- $text = request()->input('text');
|
|
|
|
|
|
|
+ $params = request()->validate($validate);
|
|
|
$isSend = request()->input('isSend', false);
|
|
$isSend = request()->input('isSend', false);
|
|
|
$isTop = request()->input('isTop', false);
|
|
$isTop = request()->input('isTop', false);
|
|
|
-
|
|
|
|
|
- $video = request()->input('video');
|
|
|
|
|
- ConfigModel::where('field', 'channel_message')
|
|
|
|
|
- ->update([
|
|
|
|
|
- 'val' => json_encode([
|
|
|
|
|
- 'type' => $type,
|
|
|
|
|
- 'chatId' => $chatId,
|
|
|
|
|
- 'image' => $image,
|
|
|
|
|
- 'video' => $video,
|
|
|
|
|
- 'text' => $text,
|
|
|
|
|
- 'button' => $button
|
|
|
|
|
- ])
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+ unset($params['isTop'], $params['isSend']);
|
|
|
|
|
+ ConfigModel::where('field', 'channel_message')->update(['val' => json_encode($params)]);
|
|
|
DB::commit();
|
|
DB::commit();
|
|
|
} catch (ValidationException $e) {
|
|
} catch (ValidationException $e) {
|
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
@@ -412,35 +375,6 @@ class Config extends Controller
|
|
|
return $this->success();
|
|
return $this->success();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// public function sendChannelVideo()
|
|
|
|
|
-// {
|
|
|
|
|
-// $chatId = request()->input('chatId');
|
|
|
|
|
-// $video = request()->input('video');
|
|
|
|
|
-// // $config = ConfigModel::where('field', 'channel_message')
|
|
|
|
|
-// // ->first()->val;
|
|
|
|
|
-// // $config = json_decode($config, true);
|
|
|
|
|
-// $telegram = new Api(config('services.telegram.token'));
|
|
|
|
|
-// // 发送图片消息
|
|
|
|
|
-// $response = $telegram->sendVideo([
|
|
|
|
|
-// 'chat_id' => "@{$chatId}",
|
|
|
|
|
-// 'caption' => '这是一个视频消息',
|
|
|
|
|
-// 'video' => InputFile::create($video),
|
|
|
|
|
-// 'protect_content' => false,
|
|
|
|
|
-// ]);
|
|
|
|
|
-
|
|
|
|
|
-// // 获取消息ID
|
|
|
|
|
-// $messageId = $response->get('message_id');
|
|
|
|
|
-// // 获取消息ID
|
|
|
|
|
-// $messageId = $response->get('message_id');
|
|
|
|
|
-// // 置顶消息
|
|
|
|
|
-// $telegram->pinChatMessage([
|
|
|
|
|
-// 'chat_id' => "@{$chatId}",
|
|
|
|
|
-// 'message_id' => $messageId
|
|
|
|
|
-// ]);
|
|
|
|
|
-// return $this->success($messageId);
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* @api {post} /admin/config/set 修改配置
|
|
* @api {post} /admin/config/set 修改配置
|
|
|
* @apiGroup 配置
|
|
* @apiGroup 配置
|