|
|
@@ -12,9 +12,80 @@ use Exception;
|
|
|
use Telegram\Bot\Api;
|
|
|
use Telegram\Bot\Exceptions\TelegramSDKException;
|
|
|
use Telegram\Bot\FileUpload\InputFile;
|
|
|
+use App\Services\ConfigService;
|
|
|
+use Google\Service\ServiceManagement\ConfigSource;
|
|
|
|
|
|
class Config extends Controller
|
|
|
{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 分页数据
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ function index()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ request()->validate([
|
|
|
+ 'field' => ['nullable', 'string'],
|
|
|
+ 'id' => ['nullable', 'string'],
|
|
|
+ ]);
|
|
|
+ $search = request()->all();
|
|
|
+ $result = ConfigService::paginate($search);
|
|
|
+ } catch (ValidationException $e) {
|
|
|
+ return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
|
|
|
+ } catch (Exception $e) {
|
|
|
+ return $this->error(intval($e->getCode()));
|
|
|
+ }
|
|
|
+ return $this->success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 修改|新增
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ public function store()
|
|
|
+ {
|
|
|
+ // try {
|
|
|
+ $params = request()->all();
|
|
|
+
|
|
|
+ $validator = [
|
|
|
+ 'field' => 'required|string|max:50|alpha_dash|unique:config,field',
|
|
|
+ 'val' => 'nullable|string',
|
|
|
+ 'remark' => 'required|nullable|string',
|
|
|
+ ];
|
|
|
+
|
|
|
+ request()->validate($validator);
|
|
|
+
|
|
|
+ $ret = ConfigService::submit($params);
|
|
|
+ if ($ret['code'] == ConfigService::NOT) {
|
|
|
+ return $this->error($ret['code'], $ret['msg']);
|
|
|
+ }
|
|
|
+ // } catch (ValidationException $e) {
|
|
|
+ // return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
|
|
|
+ // } catch (Exception $e) {
|
|
|
+ // return $this->error(intval($e->getCode()));
|
|
|
+ // }
|
|
|
+ return $this->success([], $ret['msg']);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 删除
|
|
|
+ */
|
|
|
+ public function destroy()
|
|
|
+ {
|
|
|
+ $id = request()->post('id');
|
|
|
+ // 示例:通过 ID 删除
|
|
|
+ $info = ConfigService::findOne(['id' => $id]);
|
|
|
+ if (!$info) {
|
|
|
+ return $this->error(0, '配置不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ $info->delete();
|
|
|
+
|
|
|
+ return $this->success([], '删除成功');
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @api {get} /admin/config/get 获取指定配置
|
|
|
* @apiGroup 配置
|