Commit 97e375f2 by lizhilin

更新

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