From 2a9ac60b85e6f3aa82c28641b2ab1196923f8740 Mon Sep 17 00:00:00 2001 From: wisp-x <1591788658@qq.com> Date: Thu, 31 Oct 2019 11:37:18 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=A2=9E=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=9B=BE=E7=89=87=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Image.php | 42 ++++++++++++++++++++++++++++ application/common/model/Images.php | 2 ++ route/route.php | 6 ++-- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 application/api/controller/Image.php diff --git a/application/api/controller/Image.php b/application/api/controller/Image.php new file mode 100644 index 00000000..2fd06123 --- /dev/null +++ b/application/api/controller/Image.php @@ -0,0 +1,42 @@ + + * Date: 2019/10/31 + * Time: 11:10 上午 + * Link: https://github.com/wisp-x + */ + +namespace app\api\controller; + +use app\common\model\Images; + +class Image extends Base +{ + private $model; + + public function initialize() + { + parent::initialize(); + $this->model = new Images(); + $this->model = $this->model->where('user_id', $this->user->id); + } + + public function find() + { + $id = $this->param('id'); + $image = $this->model->where(['id' => $id])->find(); + $this->response('success', $image); + } + + public function items() + { + $page = $this->param('page', 1); + $rows = $this->param('rows', 20); + $images = $this->model->paginate(null, false, [ + 'page' => $page, + 'list_rows' => $rows, + ]); + $this->response('success', $images); + } +} \ No newline at end of file diff --git a/application/common/model/Images.php b/application/common/model/Images.php index b583f13a..5b1afa06 100644 --- a/application/common/model/Images.php +++ b/application/common/model/Images.php @@ -16,6 +16,8 @@ class Images extends Model protected $insert = ['ip']; + protected $append = ['url']; + public function getUrlAttr($url, $data) { // 图片链接 diff --git a/route/route.php b/route/route.php index b5d21b26..8a94a2c0 100644 --- a/route/route.php +++ b/route/route.php @@ -15,8 +15,10 @@ Route::view('compatibility', 'index@tpl/compatibility'); // [Api Route] Route::group('api', function () { - Route::post('token', 'api/Token/index'); - Route::post('upload', 'api/Upload/index'); + Route::any('token', 'api/Token/index'); + Route::any('upload', 'api/Upload/index'); + Route::any('image', 'api/Image/find'); + Route::any('images', 'api/Image/items'); }) ->header('Access-Control-Allow-Headers', 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With, Token') ->allowCrossDomain();