diff --git a/app/Http/Admin/Controllers/UploadController.php b/app/Http/Admin/Controllers/UploadController.php index 6c51b97e..432e5129 100644 --- a/app/Http/Admin/Controllers/UploadController.php +++ b/app/Http/Admin/Controllers/UploadController.php @@ -7,6 +7,7 @@ namespace App\Http\Admin\Controllers; +use App\Http\Admin\Services\Upload as UploadService; use App\Services\MyStorage as StorageService; use App\Services\Vod as VodService; use App\Validators\Validator as AppValidator; @@ -119,20 +120,25 @@ class UploadController extends Controller */ public function uploadDefaultImageAction() { - $service = new StorageService(); + $service = new UploadService(); $items = []; + $items['category_icon'] = $service->uploadDefaultCategoryIcon(); $items['user_avatar'] = $service->uploadDefaultUserAvatar(); + $items['article_cover'] = $service->uploadDefaultArticleCover(); $items['course_cover'] = $service->uploadDefaultCourseCover(); $items['package_cover'] = $service->uploadDefaultPackageCover(); $items['topic_cover'] = $service->uploadDefaultTopicCover(); + $items['slide_cover'] = $service->uploadDefaultSlideCover(); $items['gift_cover'] = $service->uploadDefaultGiftCover(); $items['vip_cover'] = $service->uploadDefaultVipCover(); - $items['category_icon'] = $service->uploadDefaultCategoryIcon(); - foreach ($items as $item) { - if (!$item) return $this->jsonError(['msg' => '上传文件失败']); + foreach ($items as $key => $item) { + $msg = sprintf('上传文件失败: %s', $key); + if (!$item) { + return $this->jsonError(['msg' => $msg]); + } } return $this->jsonSuccess(['msg' => '上传文件成功']); diff --git a/app/Http/Admin/Services/Upload.php b/app/Http/Admin/Services/Upload.php new file mode 100644 index 00000000..9fa53961 --- /dev/null +++ b/app/Http/Admin/Services/Upload.php @@ -0,0 +1,153 @@ +storage = new MyStorage(); + } + + /** + * 上传默认用户头像 + * + * @return false|mixed|string + */ + public function uploadDefaultUserAvatar() + { + $filename = static_path('admin/img/default/user_avatar.png'); + + $key = '/img/default/user_avatar.png'; + + return $this->storage->putFile($key, $filename); + } + + /** + * 上传默认课程封面 + * + * @return false|mixed|string + */ + public function uploadDefaultCourseCover() + { + $filename = static_path('admin/img/default/course_cover.png'); + + $key = '/img/default/course_cover.png'; + + return $this->storage->putFile($key, $filename); + } + + /** + * 上传默认套餐封面 + * + * @return false|mixed|string + */ + public function uploadDefaultPackageCover() + { + $filename = static_path('admin/img/default/package_cover.png'); + + $key = '/img/default/package_cover.png'; + + return $this->storage->putFile($key, $filename); + } + + /** + * 上传默认话题封面 + * + * @return false|mixed|string + */ + public function uploadDefaultTopicCover() + { + $filename = static_path('admin/img/default/topic_cover.png'); + + $key = '/img/default/topic_cover.png'; + + return $this->storage->putFile($key, $filename); + } + + /** + * 上传默认会员封面 + * + * @return false|mixed|string + */ + public function uploadDefaultVipCover() + { + $filename = static_path('admin/img/default/vip_cover.png'); + + $key = '/img/default/vip_cover.png'; + + return $this->storage->putFile($key, $filename); + } + + /** + * 上传默认专栏封面 + * + * @return false|mixed|string + */ + public function uploadDefaultArticleCover() + { + $filename = static_path('admin/img/default/article_cover.png'); + + $key = '/img/default/article_cover.png'; + + return $this->storage->putFile($key, $filename); + } + + /** + * 上传默认礼品封面 + * + * @return false|mixed|string + */ + public function uploadDefaultGiftCover() + { + $filename = static_path('admin/img/default/gift_cover.png'); + + $key = '/img/default/gift_cover.png'; + + return $this->storage->putFile($key, $filename); + } + + /** + * 上传默认轮播图片 + * + * @return false|mixed|string + */ + public function uploadDefaultSlideCover() + { + $filename = static_path('admin/img/default/slide_cover.png'); + + $key = '/img/default/slide_cover.png'; + + return $this->storage->putFile($key, $filename); + } + + /** + * 上传默认分类图标 + * + * @return false|mixed|string + */ + public function uploadDefaultCategoryIcon() + { + $filename = static_path('admin/img/default/category_icon.png'); + + $key = '/img/default/category_icon.png'; + + return $this->storage->putFile($key, $filename); + } + + +} diff --git a/app/Http/Admin/Views/setting/storage.volt b/app/Http/Admin/Views/setting/storage.volt index fc7a574d..98b37f78 100644 --- a/app/Http/Admin/Views/setting/storage.volt +++ b/app/Http/Admin/Views/setting/storage.volt @@ -141,6 +141,10 @@ 礼品封面 public/static/admin/img/default/gift_cover.png + + 轮播封面 + public/static/admin/img/default/slide_cover.png + diff --git a/app/Services/MyStorage.php b/app/Services/MyStorage.php index 36c2f35c..c65c4237 100644 --- a/app/Services/MyStorage.php +++ b/app/Services/MyStorage.php @@ -11,6 +11,7 @@ use App\Library\Utils\FileInfo; use App\Models\Upload as UploadModel; use App\Repos\Upload as UploadRepo; use InvalidArgumentException; +use RuntimeException; class MyStorage extends Storage { @@ -36,104 +37,6 @@ class MyStorage extends Storage return $this->putString($key, $value); } - /** - * 上传默认用户头像 - * - * @return false|mixed|string - */ - public function uploadDefaultUserAvatar() - { - $filename = static_path('admin/img/default/user_avatar.png'); - - $key = '/img/default/user_avatar.png'; - - return $this->putFile($key, $filename); - } - - /** - * 上传默认课程封面 - * - * @return false|mixed|string - */ - public function uploadDefaultCourseCover() - { - $filename = static_path('admin/img/default/course_cover.png'); - - $key = '/img/default/course_cover.png'; - - return $this->putFile($key, $filename); - } - - /** - * 上传默认套餐封面 - * - * @return false|mixed|string - */ - public function uploadDefaultPackageCover() - { - $filename = static_path('admin/img/default/package_cover.png'); - - $key = '/img/default/package_cover.png'; - - return $this->putFile($key, $filename); - } - - /** - * 上传默认话题封面 - * - * @return false|mixed|string - */ - public function uploadDefaultTopicCover() - { - $filename = static_path('admin/img/default/topic_cover.png'); - - $key = '/img/default/topic_cover.png'; - - return $this->putFile($key, $filename); - } - - /** - * 上传默认会员封面 - * - * @return false|mixed|string - */ - public function uploadDefaultVipCover() - { - $filename = static_path('admin/img/default/vip_cover.png'); - - $key = '/img/default/vip_cover.png'; - - return $this->putFile($key, $filename); - } - - /** - * 上传默认礼品封面 - * - * @return false|mixed|string - */ - public function uploadDefaultGiftCover() - { - $filename = static_path('admin/img/default/gift_cover.png'); - - $key = '/img/default/gift_cover.png'; - - return $this->putFile($key, $filename); - } - - /** - * 上传分类默认图标 - * - * @return false|mixed|string - */ - public function uploadDefaultCategoryIcon() - { - $filename = static_path('admin/img/default/category_icon.png'); - - $key = '/img/default/category_icon.png'; - - return $this->putFile($key, $filename); - } - /** * 上传封面图片 * @@ -218,6 +121,10 @@ class MyStorage extends Storage $path = $this->putFile($keyName, $file->getTempName()); + if (!$path) { + throw new RuntimeException('Upload File Failed'); + } + $upload = new UploadModel(); $upload->name = $name; diff --git a/public/static/admin/img/default/article_cover.png b/public/static/admin/img/default/article_cover.png new file mode 100644 index 00000000..c0916261 Binary files /dev/null and b/public/static/admin/img/default/article_cover.png differ