移除分类图片

This commit is contained in:
liu
2026-08-14 16:31:18 +08:00
parent f0927e57e9
commit 969eabcd11
11 changed files with 288 additions and 130 deletions
@@ -2,9 +2,7 @@
namespace App\Http\Requests\Product;
use Illuminate\Validation\Rules\Exists;
use Modules\Common\Http\Requests\BaseFormRequest;
use Modules\SystemTool\Models\SysFileModel;
/**
* 商品分类 创建/编辑 验证
@@ -24,7 +22,6 @@ class ProductCategoryFormRequest extends BaseFormRequest
'name' => 'required|string|max:50',
'parent_id' => 'required|integer|min:0',
'sort' => 'nullable|integer',
'icon_id' => ['nullable', 'integer', new Exists(SysFileModel::class, 'id')],
'status' => 'nullable|integer|in:0,1',
];
}
@@ -36,7 +33,6 @@ class ProductCategoryFormRequest extends BaseFormRequest
'name.max' => '分类名称最长 50 个字符',
'parent_id.min' => '父级分类ID不正确',
'status.in' => '状态值不正确',
'icon_id.exists' => '请重新上传图片'
];
}
}
@@ -44,13 +44,17 @@ class ProductFormRequest extends BaseFormRequest
}
/**
* 交叉校验:按成本百分比计价(price_type=1)时上浮百分点必填
* 交叉校验:商品只能挂在末级分类;按成本百分比计价(price_type=1)时上浮百分点必填
* Laravel 12 FormRequest 的 after() 需返回单个 Closure,由容器 call 后注册到 Validator
*/
public function after(): Closure
{
return function (Validator $validator): void {
$data = (array) $validator->getData();
$categoryId = (int) ($data['category_id'] ?? 0);
if ($categoryId > 0 && ProductCategoryModel::where('parent_id', $categoryId)->exists()) {
$validator->errors()->add('category_id', '该分类下存在子分类,请选择末级分类');
}
foreach ((array) ($data['prices'] ?? []) as $index => $row) {
$priceType = (int) ($row['price_type'] ?? ProductPriceModel::PRICE_TYPE_FIXED);
if ($priceType === ProductPriceModel::PRICE_TYPE_PERCENT