refactor: 修改产品属性类型

This commit is contained in:
2025-02-12 17:58:53 +08:00
parent 5f31649ccb
commit 39c0de87b7
6 changed files with 19 additions and 15 deletions

View File

@@ -74,6 +74,7 @@ class ProductAttr
public function save()
{
$post = request()->post([
'attr_type' => 2,
'attr_name' => '',
'is_system' => 0,
]);
@@ -100,13 +101,15 @@ class ProductAttr
}
// 添加属性特征
foreach ($props as &$prop) {
$prop['attr_id'] = $attr_ret->id;
}
unset($prop);
$props_ret = (new ProductAttrPropModel)->saveAll($props);
if ($props_ret->isEmpty()) {
throw new \Exception("操作失败");
if (!empty($props)) {
foreach ($props as &$prop) {
$prop['attr_id'] = $attr_ret->id;
}
unset($prop);
$props_ret = (new ProductAttrPropModel)->saveAll($props);
if ($props_ret->isEmpty()) {
throw new \Exception("操作失败");
}
}
ProductAttrModel::commit();
@@ -125,7 +128,8 @@ class ProductAttr
{
$id = request()->param('id');
$put = request()->put([
'attr_name' => '',
'attr_type',
'attr_name',
'is_system' => 0,
]);
$attr = array_merge($put, ['language_id' => request()->lang_id]);

View File

@@ -15,11 +15,11 @@ class ProductAttrValidate extends Validate
*/
protected $rule = [
'language_id' => 'require|number',
'attr_type' => 'in:1,2',
'attr_name' => 'require|max:64',
'is_system' => 'in:0,1',
'props.*.prop_type' => 'in:1,2',
'props.*.prop_name' => 'require|max:64',
'props.*.prop_value' => 'require|max:64',
'props.*.prop_name' => 'requireIf:attr_type,1|max:64',
'props.*.prop_value' => 'requireIf:attr_type,1|max:64',
];
/**
@@ -31,10 +31,10 @@ class ProductAttrValidate extends Validate
protected $message = [
'language_id.require' => '语言ID不能为空',
'language_id.number' => '语言ID必须是数字',
'attr_type.in' => '属性类型只能是1或2',
'attr_name.require' => '属性名称不能为空',
'attr_name.max' => '属性名称不能超过64个字符',
'is_system.in' => '是否系统属性只能是0或1',
'props.*.prop_type.in' => '属性特征类型只能是1或2',
'props.*.prop_name.require' => '属性特征名称不能为空',
'props.*.prop_name.max' => '属性特征名称不能超过64个字符',
'props.*.prop_value.require' => '属性特征值不能为空',