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();