This commit is contained in:
2025-07-05 17:35:30 +08:00
5 changed files with 38 additions and 9 deletions

View File

@@ -45,17 +45,39 @@ class Upload
// 获取图片上传配置 // 获取图片上传配置
list( list(
'filename_keep' => $filename_keep, 'filename_keep' => $filename_keep,
'filemd5_unique' => $filemd5_unique 'filemd5_unique' => $filemd5_unique,
'filetype_to' => $filetype_to,
) = $this->getUploadOptions('upload_image'); ) = $this->getUploadOptions('upload_image');
// 获取文件大小
$file_size = $file->getSize();
// 获取文件mime类型
$mime_type = $file->getOriginalMime();
// 是否需要根据文件MD5值检查文件是否已存在 // 是否需要根据文件MD5值检查文件是否已存在
$image_model = $filemd5_unique ? SysImageUploadRecordModel::md5($filemd5)->find() : null; $image_model = $filemd5_unique ? SysImageUploadRecordModel::md5($filemd5)->find() : null;
if (is_null($image_model)) { if (is_null($image_model)) {
// 检查是否需要保留原文件名生成器 // 检查是否需要保留原文件名生成器
$name_rule = fn() => $filename_keep ? $this->filenameGenerator($file) : null; $name_rule = fn() => $filename_keep ? $this->filenameGenerator($file) : null;
$filename = Filesystem::disk('image')->putFile($param['module'], $file, $name_rule());
// 处理图片 // 处理图片
$image_manager = ImageManager::imagick(); $image_manager = ImageManager::imagick();
if ($filetype_to == 'original') {
$filename = Filesystem::disk('image')->putFile($param['module'], $file, $name_rule());
$image = $image_manager->read('.' . $storage . '/' . $filename); $image = $image_manager->read('.' . $storage . '/' . $filename);
}
else if ($filetype_to == 'webp') {
$image = $image_manager->read($file->getRealPath());
// 转换为webp格式
$webp = $image->toWebp(75);
$root = config('filesystem.disks.image.root');
$filename = $param['module'] . '/' . ($name_rule() ?? date('Ymd') . '/' . md5((string)time()) . '.webp');
$webp->save($root . '/' . $filename);
// 获取webp文件大小
$file_size = $webp->size();
// 获取webp文件mime类型
$mime_type = $webp->mimetype();
}
// 水印 // 水印
list( list(
@@ -133,8 +155,8 @@ class Upload
$image_model->module = $param['module']; $image_model->module = $param['module'];
$image_model->image_path = $filename; $image_model->image_path = $filename;
$image_model->image_thumb = $thumb_filename; $image_model->image_thumb = $thumb_filename;
$image_model->file_size = $file->getSize(); $image_model->file_size = $file_size;
$image_model->file_type = $file->getOriginalMime(); $image_model->file_type = $mime_type;
$image_model->file_md5 = $filemd5; $image_model->file_md5 = $filemd5;
$image_model->file_sha1 = $filesha1; $image_model->file_sha1 = $filesha1;
if (!$image_model->save()) { if (!$image_model->save()) {
@@ -179,6 +201,7 @@ class Upload
return [ return [
'filename_keep' => (int)data_get($options, 'filename_keep.value', 0) == 1, 'filename_keep' => (int)data_get($options, 'filename_keep.value', 0) == 1,
'filemd5_unique' => (int)data_get($options, 'filemd5_unique.value', 0) == 1, 'filemd5_unique' => (int)data_get($options, 'filemd5_unique.value', 0) == 1,
'filetype_to' => data_get($options, 'filetype_to.value', 'original'),
]; ];
} }
/** /**

View File

@@ -66,6 +66,8 @@ class Article
]) ])
->withoutField([ ->withoutField([
'language_id', 'language_id',
'author',
'source',
'seo_title', 'seo_title',
'seo_keywords', 'seo_keywords',
'seo_desc', 'seo_desc',

View File

@@ -27,6 +27,8 @@ class ArticleCategory
$categories = ArticleCategoryModel::withoutField([ $categories = ArticleCategoryModel::withoutField([
'language_id', 'language_id',
'unique_label', 'unique_label',
'short_name',
'desc',
'created_at', 'created_at',
'updated_at', 'updated_at',
]) ])

View File

@@ -35,7 +35,6 @@ class Product
'name', 'name',
'short_name', 'short_name',
'cover_image', 'cover_image',
'desc',
'deleted_at' 'deleted_at'
]) ])
->where(function($query) use($params) { ->where(function($query) use($params) {
@@ -76,7 +75,7 @@ class Product
'params' => fn($query) => $query->field(['product_id', 'name', 'value']) 'params' => fn($query) => $query->field(['product_id', 'name', 'value'])
->hidden(['product_id']), ->hidden(['product_id']),
// 关联sku // 关联sku
'skus' => fn($query) => $query->withoutField(['created_at', 'updated_at']) 'skus' => fn($query) => $query->withoutField(['sort', 'created_at', 'updated_at'])
->with([ ->with([
'sku_attr' => fn($query) => $query->with('attr')->hidden(['sku_id', 'attr_id']) 'sku_attr' => fn($query) => $query->with('attr')->hidden(['sku_id', 'attr_id'])
]) ])
@@ -101,6 +100,7 @@ class Product
]) ])
->withoutField([ ->withoutField([
'language_id', 'language_id',
'desc',
'stock_qty', 'stock_qty',
'seo_title', 'seo_title',
'seo_keywords', 'seo_keywords',
@@ -112,7 +112,7 @@ class Product
->bypk($id) ->bypk($id)
->hidden(['category_id']) ->hidden(['category_id'])
->find(); ->find();
// dump($product);exit;
// 处理封面图 // 处理封面图
if (!empty($product['cover_image']) && !str_starts_with($product['cover_image'], 'http')) { if (!empty($product['cover_image']) && !str_starts_with($product['cover_image'], 'http')) {
$product['cover_image'] = image_domain_concat($product['cover_image']); $product['cover_image'] = image_domain_concat($product['cover_image']);

View File

@@ -27,6 +27,8 @@ class ProductCategory
$categories = ProductCategoryModel::withoutField([ $categories = ProductCategoryModel::withoutField([
'language_id', 'language_id',
'unique_id', 'unique_id',
'icon',
'desc',
'related_tco_category', 'related_tco_category',
'created_at', 'created_at',
'updated_at' 'updated_at'