Commit 97e375f2 by lizhilin

更新

parent 29c68379
...@@ -67,11 +67,15 @@ protected function form() ...@@ -67,11 +67,15 @@ protected function form()
return Form::make(new Carousel(), function (Form $form) { return Form::make(new Carousel(), function (Form $form) {
$form->text('title'); $form->text('title');
$form->image('imgUrl') $form->image('imgUrl')
->accept('jpg,jpeg,png')
->maxSize(4096)
->url('upload/carousel') ->url('upload/carousel')
->help('仅支持jpg、jpeg、png格式图片上传(首页 600px*450px)') ->deleteUrl('upload/delete-public-oss-file')
->autoUpload(); ->autoUpload();
// $form->image('imgUrl')
// ->accept('jpg,jpeg,png')
// ->maxSize(4096)
// ->url('upload/carousel')
// ->help('仅支持jpg、jpeg、png格式图片上传(首页 600px*450px)')
// ->autoUpload();
$form->switch('status')->default(1); $form->switch('status')->default(1);
}); });
} }
......
...@@ -146,19 +146,29 @@ protected function form() ...@@ -146,19 +146,29 @@ protected function form()
$form->text('merchant_commission', '商家佣金比例')->help("比例如:10"); $form->text('merchant_commission', '商家佣金比例')->help("比例如:10");
$form->text('sale', '销量'); $form->text('sale', '销量');
$form->text('high_opinion', '好评率'); $form->text('high_opinion', '好评率');
//$form->text('box_size');
$form->image('cover_img') $form->image('cover_img')
->accept('jpg,jpeg,png')
->maxSize(4096)
->url('upload/goods') ->url('upload/goods')
->help('仅支持jpg、jpeg、png格式图片上传(320px * 320px)') ->deleteUrl('upload/delete-public-oss-file')
->autoUpload(); ->autoUpload();
// $form->image('cover_img')
// ->accept('jpg,jpeg,png')
// ->maxSize(4096)
// ->url('upload/goods')
// ->help('仅支持jpg、jpeg、png格式图片上传(320px * 320px)')
// ->autoUpload();
// $form->multipleImage('carousel', '产品图')
// ->accept('jpg,jpeg,png')
// ->maxSize(51200)
// ->url('upload/goods')
// ->help('仅支持jpg、jpeg、png格式图片上传(尺寸 750px*750px)')
// ->limit(5)
// ->autoUpload()->saveAsJson();
$form->multipleImage('carousel', '产品图') $form->multipleImage('carousel', '产品图')
->accept('jpg,jpeg,png') ->accept('jpg,jpeg,png')
->maxSize(51200) ->maxSize(51200)
->url('upload/goods') ->url('upload/goods')
->help('仅支持jpg、jpeg、png格式图片上传(尺寸 750px*750px)') ->help('仅支持jpg、jpeg、png格式图片上传')
->limit(5) ->limit(9)
->autoUpload()->saveAsJson(); ->autoUpload()->saveAsJson();
$form->switch('is_show', '上架状态')->default(1); $form->switch('is_show', '上架状态')->default(1);
$form->switch('is_hot', '是否推荐')->default(0); $form->switch('is_hot', '是否推荐')->default(0);
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
namespace App\Admin\Controllers; namespace App\Admin\Controllers;
use App\Handlers\AilOss;
use OSS\Core\OssException;
use Dcat\Admin\Traits\HasUploadedFile; use Dcat\Admin\Traits\HasUploadedFile;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
...@@ -13,6 +14,29 @@ class UploadController ...@@ -13,6 +14,29 @@ class UploadController
use HasUploadedFile; use HasUploadedFile;
/**
* 删除OSS私有桶资源文件
*/
public function deleteOssFile()
{
$ossPath = request()->post('key') ?? '';
$aliOss = new AilOss();
$res = $aliOss->delete($ossPath);
return $res ? $this->responseDeleted() : $this->responseDeleteFailed('文件删除失败');
}
/**
* 删除OSS公有桶资源文件
*/
public function deletePublicOssFile()
{
$ossPath = request()->post('key') ?? '';
$aliOss = new AilOss();
$res = $aliOss->delete($ossPath); //, 'OSS_BUCKET'
return $res ? $this->responseDeleted() : $this->responseDeleteFailed('文件删除失败');
}
public function merchantUpload() public function merchantUpload()
{ {
$disk = $this->disk(); $disk = $this->disk();
...@@ -78,9 +102,38 @@ public function userUpload() ...@@ -78,9 +102,38 @@ public function userUpload()
: $this->responseErrorMessage('文件上传失败'); : $this->responseErrorMessage('文件上传失败');
} }
/**
* 上传资源库图片
*/
public function goodsUpload() public function goodsUpload()
{ {
$aliOss = new AilOss();
// 获取上传的文件
$file = $this->file();
$ext = $file->getClientOriginalExtension();
Image::make($file->getRealPath())
->resize(640, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->encode('jpg', 90);
$fileName = md5(uniqid()) . '.' . $ext;
$date = date('Ymd');
$ossFilePath = 'goods/' . $date . '/' . $fileName;
//获取文件的绝对路径
$path = $file->getRealPath();
$res = $aliOss->upload($ossFilePath, $path, 'OSS_PUBLIC_BUCKET');
return $res
? $this->responseUploaded(env('OSS_PUBLIC_IMAGE_URL') . $ossFilePath, '')
: $this->responseErrorMessage('文件上传失败');
}
public function goodsUpload2()
{
$disk = $this->disk(); $disk = $this->disk();
// 判断是否是删除文件请求 // 判断是否是删除文件请求
...@@ -92,6 +145,7 @@ public function goodsUpload() ...@@ -92,6 +145,7 @@ public function goodsUpload()
// 获取上传的文件 // 获取上传的文件
$file = $this->file(); $file = $this->file();
//获取文件扩展名 //获取文件扩展名
$ext = $file->getClientOriginalExtension(); $ext = $file->getClientOriginalExtension();
$img = Image::make($file->getRealPath()) $img = Image::make($file->getRealPath())
...@@ -114,6 +168,24 @@ public function goodsUpload() ...@@ -114,6 +168,24 @@ public function goodsUpload()
//商品规格图 //商品规格图
public function uploadSkuImage(Request $request) public function uploadSkuImage(Request $request)
{ {
$aliOss = new AilOss();
if ($request->hasFile('file')) {
$file = $request->file('file');
$disk = $this->disk();
//获取文件扩展名
$ext = $file->getClientOriginalExtension();
$fileName = md5(uniqid()) . '.' . $ext;
$date = date('Ymd');
$path = $file->getRealPath();
$ossFilePath = 'goods/' . $date . '/' . $fileName;
$res = $aliOss->upload($ossFilePath, $path, 'OSS_PUBLIC_BUCKET');
return ['url' => env('OSS_PUBLIC_IMAGE_URL') . $ossFilePath];
}
}
public function uploadSkuImage2(Request $request)
{
if ($request->hasFile('file')) { if ($request->hasFile('file')) {
$file = $request->file('file'); $file = $request->file('file');
//$disk = Storage::disk('cosv5'); //$disk = Storage::disk('cosv5');
...@@ -145,6 +217,29 @@ public function uploadSkuImage(Request $request) ...@@ -145,6 +217,29 @@ public function uploadSkuImage(Request $request)
public function carouselUpload() public function carouselUpload()
{ {
$aliOss = new AilOss();
// 获取上传的文件
$file = $this->file();;
Image::make($file->getRealPath())
->resize(640, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->encode('jpg', 90);
$fileName = md5(uniqid()) . '.jpg';
$date = date('Ymd');
$ossFilePath = 'carousel/' . $date . '/' . $fileName;
//获取文件的绝对路径
$path = $file->getRealPath();
$res = $aliOss->upload($ossFilePath, $path, 'OSS_PUBLIC_BUCKET');
return $res
? $this->responseUploaded(env('OSS_PUBLIC_IMAGE_URL') . $ossFilePath, '')
: $this->responseErrorMessage('文件上传失败');
}
public function carouselUpload2()
{
$disk = $this->disk(); $disk = $this->disk();
// 判断是否是删除文件请求 // 判断是否是删除文件请求
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
], function (Router $router) { ], function (Router $router) {
/****************************************************** 图片文件上传组件Start *********************************************************/ /****************************************************** 图片文件上传组件Start *********************************************************/
$router->match(['put', 'post'], 'upload/delete-oss-file', 'UploadController@deleteOssFile'); //删除OSS私有资源文件
$router->match(['put', 'post'], 'upload/delete-public-oss-file', 'UploadController@deletePublicOssFile'); //删除OSS公有资源文件
//$router->match(['put', 'post'], 'upload/goods', 'UploadController@uploadResourceImg'); //上传资源图
$router->match(['put', 'post'], 'upload/user', 'UploadController@userUpload'); //头像图上传 $router->match(['put', 'post'], 'upload/user', 'UploadController@userUpload'); //头像图上传
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace App\Handlers; namespace App\Handlers;
use OSS\OssClient; use OSS\OssClient;
require_once '../vendor/aliyuncs/oss-sdk-php/autoload.php'; require_once '../vendor/aliyuncs/oss-sdk-php/autoload.php';
...@@ -29,7 +30,7 @@ public function __construct() ...@@ -29,7 +30,7 @@ public function __construct()
* @return bool 上传是否成功 * @return bool 上传是否成功
* @throws \OSS\Core\OssException * @throws \OSS\Core\OssException
*/ */
public function upload($object, $filepath,$bucket ='OSS_BUCKET') public function upload($object, $filepath, $bucket = 'OSS_BUCKET')
{ {
$res = false; $res = false;
$bucket = env($bucket); //获取阿里云oss的bucket $bucket = env($bucket); //获取阿里云oss的bucket
...@@ -45,11 +46,12 @@ public function upload($object, $filepath,$bucket ='OSS_BUCKET') ...@@ -45,11 +46,12 @@ public function upload($object, $filepath,$bucket ='OSS_BUCKET')
* @param $object string 被删除的文件名 * @param $object string 被删除的文件名
* @return bool 删除是否成功 * @return bool 删除是否成功
*/ */
public function delete(string $object,$bucket = 'OSS_BUCKET') public function delete(string $object, $bucket = 'OSS_BUCKET')
{ {
$res = false; $res = false;
$bucket = env($bucket); $bucket = env($bucket);
if (self::$oss->deleteObject($bucket, $object)){ //调用deleteObject方法把服务器文件上传到阿里云oss
if (self::$oss->deleteObject($bucket, $object)) { //调用deleteObject方法把服务器文件上传到阿里云oss
$res = true; $res = true;
} }
...@@ -61,11 +63,11 @@ public function delete(string $object,$bucket = 'OSS_BUCKET') ...@@ -61,11 +63,11 @@ public function delete(string $object,$bucket = 'OSS_BUCKET')
* @param $object 被删除的文件名 * @param $object 被删除的文件名
* @return bool 删除是否成功 * @return bool 删除是否成功
*/ */
public function delete_array($objects,$bucket ='OSS_BUCKET') public function delete_array($objects, $bucket = 'OSS_BUCKET')
{ {
$res = false; $res = false;
$bucket = env($bucket); $bucket = env($bucket);
if (self::$oss->deleteObjects($bucket, $objects)){ //调用deleteObject方法把服务器文件上传到阿里云oss if (self::$oss->deleteObjects($bucket, $objects)) { //调用deleteObject方法把服务器文件上传到阿里云oss
$res = true; $res = true;
} }
...@@ -74,12 +76,12 @@ public function delete_array($objects,$bucket ='OSS_BUCKET') ...@@ -74,12 +76,12 @@ public function delete_array($objects,$bucket ='OSS_BUCKET')
/*获取文件的临时访问URL*/ /*获取文件的临时访问URL*/
public function getUrl($OssFilePath,$time = 1800,$bucket ='OSS_BUCKET') public function getUrl($OssFilePath, $time = 1800, $bucket = 'OSS_BUCKET')
{ {
// 生成一个带签名的URL,有效期是3600秒,可以直接使用浏览器访问。 // 生成一个带签名的URL,有效期是3600秒,可以直接使用浏览器访问。
$timeout = $time; $timeout = $time;
$bucket = env($bucket); $bucket = env($bucket);
return self::$oss->signUrl($bucket,$OssFilePath,$timeout,"GET"); return self::$oss->signUrl($bucket, $OssFilePath, $timeout, "GET");
} }
...@@ -92,7 +94,7 @@ public function getUrl($OssFilePath,$time = 1800,$bucket ='OSS_BUCKET') ...@@ -92,7 +94,7 @@ public function getUrl($OssFilePath,$time = 1800,$bucket ='OSS_BUCKET')
* @param string $dirName 文件夹名称 * @param string $dirName 文件夹名称
* @return bool * @return bool
*/ */
public function createDir($dirName,$bucket = 'OSS_BUCKET') public function createDir($dirName, $bucket = 'OSS_BUCKET')
{ {
$res = false; $res = false;
$bucket = env($bucket); $bucket = env($bucket);
...@@ -104,7 +106,8 @@ public function createDir($dirName,$bucket = 'OSS_BUCKET') ...@@ -104,7 +106,8 @@ public function createDir($dirName,$bucket = 'OSS_BUCKET')
} }
/*获取指定目录下的目录与文件*/ /*获取指定目录下的目录与文件*/
public function fileList($dir, $maxKey = 1000, $delimiter = '/', $nextMarker = '') { public function fileList($dir, $maxKey = 1000, $delimiter = '/', $nextMarker = '')
{
$fileList = []; // 获取的文件列表, 数组的一阶表示分页结果 $fileList = []; // 获取的文件列表, 数组的一阶表示分页结果
$dirList = []; // 获取的目录列表, 数组的一阶表示分页结果 $dirList = []; // 获取的目录列表, 数组的一阶表示分页结果
$storageList = [ $storageList = [
...@@ -132,28 +135,29 @@ public function fileList($dir, $maxKey = 1000, $delimiter = '/', $nextMarker = ' ...@@ -132,28 +135,29 @@ public function fileList($dir, $maxKey = 1000, $delimiter = '/', $nextMarker = '
$dirList[] = $dirItem; $dirList[] = $dirItem;
if ($nextMarker === '') break; if ($nextMarker === '') break;
} }
foreach ($fileList[0] as $item){ foreach ($fileList[0] as $item) {
$storageList['file'][] = $this->objectInfoParse($item); $storageList['file'][] = $this->objectInfoParse($item);
} }
foreach ($dirList[0] as $item){ foreach ($dirList[0] as $item) {
$storageList['dir'][] = $this->prefixInfoParse($item); $storageList['dir'][] = $this->prefixInfoParse($item);
} }
return $storageList; // 发送正确信息 return $storageList; // 发送正确信息
} }
/* 解析 prefixInfo 类 */ /* 解析 prefixInfo 类 */
private function prefixInfoParse($prefixInfo){ private function prefixInfoParse($prefixInfo)
{
return [ return [
'dir' => $prefixInfo->getPrefix(), 'dir' => $prefixInfo->getPrefix(),
]; ];
} }
/* 解析 objectInfo 类 */ /* 解析 objectInfo 类 */
public function objectInfoParse($objectInfo) { public function objectInfoParse($objectInfo)
{
return [ return [
'name' => $objectInfo->getKey(), 'name' => $objectInfo->getKey(),
'size' => $objectInfo->getSize(), 'size' => $objectInfo->getSize(),
'update_at' => $objectInfo->getLastModified(), 'update_at' => $objectInfo->getLastModified(),
]; ];
} }
} }
...@@ -21,7 +21,7 @@ public function getList() ...@@ -21,7 +21,7 @@ public function getList()
->get(); ->get();
foreach ($list as $key => $val) { foreach ($list as $key => $val) {
$list[$key]['imgUrl'] = ($val->imgUrl ? env('IMAGE_URL') . $val->imgUrl : ""); $list[$key]['imgUrl'] = ($val->imgUrl ? $val->imgUrl : "");
} }
return $this->JsonResponse($list); return $this->JsonResponse($list);
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
"laravel/framework": "^9.19", "laravel/framework": "^9.19",
"laravel/sanctum": "^3.0", "laravel/sanctum": "^3.0",
"laravel/tinker": "^2.7", "laravel/tinker": "^2.7",
"league/flysystem": "^3.15", "league/flysystem": "^3.29",
"lty5240/dcat-easy-sku": "^1.1", "lty5240/dcat-easy-sku": "^1.1",
"maatwebsite/excel": "~3.1.0", "maatwebsite/excel": "~3.1.0",
"overtrue/wechat": "~5.0", "overtrue/wechat": "~5.0",
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "2de385384bfeb7aaa53fa17945063127", "content-hash": "1b40207476190f175adf99e702616055",
"packages": [ "packages": [
{ {
"name": "abbotton/dcat-sku-plus", "name": "abbotton/dcat-sku-plus",
......
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
'upload' => [ 'upload' => [
// Disk in `config/filesystem.php`. // Disk in `config/filesystem.php`.
'disk' => 'admin', 'disk' => 'public_oss', //admin
// Image and file upload path under the disk above. // Image and file upload path under the disk above.
'directory' => [ 'directory' => [
...@@ -272,6 +272,19 @@ ...@@ -272,6 +272,19 @@
], ],
// 'tinymce' => [
// // ...
// 'upload_image_config' => [
// 'url' => '/tinymce/upload', // 修改为你新定义的上传路由
// // ...
// ],
// ],
'providers' => [
// ...
App\Admin\Providers\TinyMceServiceProvider::class,
// ...
],
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| dcat-admin database settings | dcat-admin database settings
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
| based disks are available to your application. Just store away! | based disks are available to your application. Just store away!
| |
*/ */
//'default' => env('FILESYSTEM_DISK', 'cos'),
'default' => env('FILESYSTEM_DISK', 'cos'), 'default' => env('FILESYSTEM_DISK', 'public_oss'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
'root' => storage_path('app'), 'root' => storage_path('app'),
'throw' => false, 'throw' => false,
], ],
'public_oss' => [ 'public_oss' => [
'driver' => 'oss', 'driver' => 'oss',
'access_id' => env('OSS_ACCESS_KEY_ID'), //Your Aliyun OSS AccessKeyId 'access_id' => env('OSS_ACCESS_KEY_ID'), //Your Aliyun OSS AccessKeyId
......
<?php <?php
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Dcat\Admin\Http\Controllers\AdminController;
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Web Routes | Web Routes
...@@ -12,9 +12,10 @@ ...@@ -12,9 +12,10 @@
| contains the "web" middleware group. Now create something great! | contains the "web" middleware group. Now create something great!
| |
*/ */
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user(); // Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
}); // return $request->user();
// });
Route::get('/', function () { Route::get('/', function () {
return view('welcome'); return view('welcome');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment