refactor: 修改产品属性类型
This commit is contained in:
@@ -74,6 +74,7 @@ class ProductAttr
|
|||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
$post = request()->post([
|
$post = request()->post([
|
||||||
|
'attr_type' => 2,
|
||||||
'attr_name' => '',
|
'attr_name' => '',
|
||||||
'is_system' => 0,
|
'is_system' => 0,
|
||||||
]);
|
]);
|
||||||
@@ -100,13 +101,15 @@ class ProductAttr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 添加属性特征
|
// 添加属性特征
|
||||||
foreach ($props as &$prop) {
|
if (!empty($props)) {
|
||||||
$prop['attr_id'] = $attr_ret->id;
|
foreach ($props as &$prop) {
|
||||||
}
|
$prop['attr_id'] = $attr_ret->id;
|
||||||
unset($prop);
|
}
|
||||||
$props_ret = (new ProductAttrPropModel)->saveAll($props);
|
unset($prop);
|
||||||
if ($props_ret->isEmpty()) {
|
$props_ret = (new ProductAttrPropModel)->saveAll($props);
|
||||||
throw new \Exception("操作失败");
|
if ($props_ret->isEmpty()) {
|
||||||
|
throw new \Exception("操作失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProductAttrModel::commit();
|
ProductAttrModel::commit();
|
||||||
@@ -125,7 +128,8 @@ class ProductAttr
|
|||||||
{
|
{
|
||||||
$id = request()->param('id');
|
$id = request()->param('id');
|
||||||
$put = request()->put([
|
$put = request()->put([
|
||||||
'attr_name' => '',
|
'attr_type',
|
||||||
|
'attr_name',
|
||||||
'is_system' => 0,
|
'is_system' => 0,
|
||||||
]);
|
]);
|
||||||
$attr = array_merge($put, ['language_id' => request()->lang_id]);
|
$attr = array_merge($put, ['language_id' => request()->lang_id]);
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ class ProductAttrValidate extends Validate
|
|||||||
*/
|
*/
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'language_id' => 'require|number',
|
'language_id' => 'require|number',
|
||||||
|
'attr_type' => 'in:1,2',
|
||||||
'attr_name' => 'require|max:64',
|
'attr_name' => 'require|max:64',
|
||||||
'is_system' => 'in:0,1',
|
'is_system' => 'in:0,1',
|
||||||
'props.*.prop_type' => 'in:1,2',
|
'props.*.prop_name' => 'requireIf:attr_type,1|max:64',
|
||||||
'props.*.prop_name' => 'require|max:64',
|
'props.*.prop_value' => 'requireIf:attr_type,1|max:64',
|
||||||
'props.*.prop_value' => 'require|max:64',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,10 +31,10 @@ class ProductAttrValidate extends Validate
|
|||||||
protected $message = [
|
protected $message = [
|
||||||
'language_id.require' => '语言ID不能为空',
|
'language_id.require' => '语言ID不能为空',
|
||||||
'language_id.number' => '语言ID必须是数字',
|
'language_id.number' => '语言ID必须是数字',
|
||||||
|
'attr_type.in' => '属性类型只能是1或2',
|
||||||
'attr_name.require' => '属性名称不能为空',
|
'attr_name.require' => '属性名称不能为空',
|
||||||
'attr_name.max' => '属性名称不能超过64个字符',
|
'attr_name.max' => '属性名称不能超过64个字符',
|
||||||
'is_system.in' => '是否系统属性只能是0或1',
|
'is_system.in' => '是否系统属性只能是0或1',
|
||||||
'props.*.prop_type.in' => '属性特征类型只能是1或2',
|
|
||||||
'props.*.prop_name.require' => '属性特征名称不能为空',
|
'props.*.prop_name.require' => '属性特征名称不能为空',
|
||||||
'props.*.prop_name.max' => '属性特征名称不能超过64个字符',
|
'props.*.prop_name.max' => '属性特征名称不能超过64个字符',
|
||||||
'props.*.prop_value.require' => '属性特征值不能为空',
|
'props.*.prop_value.require' => '属性特征值不能为空',
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class ProductAttrBaseModel extends BaseModel
|
|||||||
protected $schema = [
|
protected $schema = [
|
||||||
'id' => 'int',
|
'id' => 'int',
|
||||||
'language_id' => 'int',
|
'language_id' => 'int',
|
||||||
|
'attr_type' => 'string',
|
||||||
'attr_name' => 'string',
|
'attr_name' => 'string',
|
||||||
'is_system' => 'string',
|
'is_system' => 'string',
|
||||||
'created_at' => 'datetime',
|
'created_at' => 'datetime',
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ class ProductAttrPropBaseModel extends BaseModel
|
|||||||
// 字段信息
|
// 字段信息
|
||||||
protected $schema = [
|
protected $schema = [
|
||||||
'attr_id' => 'int',
|
'attr_id' => 'int',
|
||||||
'prop_type' => 'int',
|
|
||||||
'prop_name' => 'string',
|
'prop_name' => 'string',
|
||||||
'prop_value' => 'string',
|
'prop_value' => 'string',
|
||||||
'created_at' => 'datetime',
|
'created_at' => 'datetime',
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Phinx\Db\Adapter\MysqlAdapter;
|
||||||
use think\migration\Migrator;
|
use think\migration\Migrator;
|
||||||
|
|
||||||
class CreateProductAttr extends Migrator
|
class CreateProductAttr extends Migrator
|
||||||
@@ -29,6 +30,7 @@ class CreateProductAttr extends Migrator
|
|||||||
{
|
{
|
||||||
$table = $this->table('product_attr', ['engine' => 'InnoDB', 'comment' => '商品属性表']);
|
$table = $this->table('product_attr', ['engine' => 'InnoDB', 'comment' => '商品属性表']);
|
||||||
$table->addColumn('language_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '语言ID'])
|
$table->addColumn('language_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '语言ID'])
|
||||||
|
->addColumn('attr_type', MysqlAdapter::INT_TINY, ['limit' => 3, 'null' => false, 'default' => 2, 'comment' => '类型:1为选项类型,2为文本输入类型'])
|
||||||
->addColumn('attr_name', 'string', ['limit' => 64, 'signed' => false, 'null' => false, 'comment' => '属性ID'])
|
->addColumn('attr_name', 'string', ['limit' => 64, 'signed' => false, 'null' => false, 'comment' => '属性ID'])
|
||||||
->addColumn('is_system', 'boolean', ['null' => false, 'default' => 0, 'comment' => '是否系统属性:1是,0否'])
|
->addColumn('is_system', 'boolean', ['null' => false, 'default' => 0, 'comment' => '是否系统属性:1是,0否'])
|
||||||
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '新增时间'])
|
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '新增时间'])
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Phinx\Db\Adapter\MysqlAdapter;
|
|
||||||
use think\migration\Migrator;
|
use think\migration\Migrator;
|
||||||
|
|
||||||
class CreateProductAttrProp extends Migrator
|
class CreateProductAttrProp extends Migrator
|
||||||
@@ -30,7 +29,6 @@ class CreateProductAttrProp extends Migrator
|
|||||||
{
|
{
|
||||||
$table = $this->table('product_attr_prop', ['id' => false, 'engine' => 'InnoDB', 'comment' => '商品属性特征表']);
|
$table = $this->table('product_attr_prop', ['id' => false, 'engine' => 'InnoDB', 'comment' => '商品属性特征表']);
|
||||||
$table->addColumn('attr_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '属性ID'])
|
$table->addColumn('attr_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '属性ID'])
|
||||||
->addColumn('prop_type', MysqlAdapter::INT_TINY, ['limit' => 3, 'null' => false, 'default' => 2, 'comment' => '类型:1为选项类型,2为文本输入类型'])
|
|
||||||
->addColumn('prop_name', 'string', ['limit' => 64, 'null' => false, 'comment' => '特征名'])
|
->addColumn('prop_name', 'string', ['limit' => 64, 'null' => false, 'comment' => '特征名'])
|
||||||
->addColumn('prop_value', 'string', ['limit' => 64, 'null' => false, 'comment' => '特征值'])
|
->addColumn('prop_value', 'string', ['limit' => 64, 'null' => false, 'comment' => '特征值'])
|
||||||
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '新增时间'])
|
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '新增时间'])
|
||||||
|
|||||||
Reference in New Issue
Block a user