diff --git a/app/admin/controller/v1/ProductCompat.php b/app/admin/controller/v1/ProductCompat.php index 4c36ea2f..86178bfa 100644 --- a/app/admin/controller/v1/ProductCompat.php +++ b/app/admin/controller/v1/ProductCompat.php @@ -4,7 +4,9 @@ declare (strict_types = 1); namespace app\admin\controller\v1; use app\admin\model\v1\ProductCompatModel; +use app\admin\model\v1\ProductCompatModelsModel; use app\admin\model\v1\ProductCompatPartsModel; +use app\admin\model\v1\ProductCompatTypesModel; use app\admin\validate\v1\ProductCompatValidate; class ProductCompat @@ -15,8 +17,11 @@ class ProductCompat public function index() { $params = request()->param([ - 'label_name', + 'compatible_model', 'model', + 'type_id', + 'part_id', + 'brand_name', 'page/d' => 1, 'size/d' => 10 ]); @@ -25,21 +30,46 @@ class ProductCompat 'language_id', 'deleted_at' ]) - ->with(['parts' => function ($query) { - $query->field(['id', 'name']); - }]) + ->with([ + 'types' => function ($query) { + $query->field(['id', 'name']); + }, + 'parts' => function ($query) { + $query->field(['id', 'name']); + }, + 'compatible_models' => function ($query) { + $query->field(['compat_id', 'compatible_model']); + } + ]) ->language(request()->lang_id) - ->withSearch(['label_name', 'model'], [ - 'label_name' => $params['label_name'] ?? null, - 'model' => $params['model'] ?? null, + ->where(function ($query) use($params) { + if (!empty($params['type_id'])) { + $query->typeId($params['type_id']); + } + if (!empty($params['part_id'])) { + $query->partId($params['part_id']); + } + }) + ->withSearch(['model', 'brand_name', 'compatible_model'], [ + 'model' => $params['model'] ?? null, + 'brand_name' => $params['brand_name'] ?? null, + 'compatible_model' => $params['compatible_model'] ?? null, ]) ->order(['updated_at' => 'desc']) ->paginate([ 'list_rows' => $params['size'], 'page' => $params['page'], ]) + ?->bindAttr('types', ['type_name' => 'name']) ?->bindAttr('parts', ['part_name' => 'name']) - ?->hidden(['parts']); + ?->hidden(['types', 'parts']) + ?->each(function ($item) { + $compatible_models = []; + foreach ($item['compatible_models'] as $model) { + $compatible_models[] = $model['compatible_model']; + } + $item['compatible_models'] = implode(',', $compatible_models); + }); return success("获取成功", $list); } @@ -58,16 +88,16 @@ class ProductCompat // 读取文件 $keys_map = [ - 'A' => 'label_name', + 'A' => 'type_name', 'B' => 'part_name', 'C' => 'brand_name', 'D' => 'level_name', - 'E' => 'class_name', + 'E' => 'spec_name', 'F' => 'series_name', 'G' => 'model', - 'H' => 'capacity', - 'I' => 'interface_type', - 'J' => 'compat_status', + 'H' => 'frequency', + 'I' => 'capacity', + 'J' => 'compatible_models', ]; $chunk = 500; // 每批次处理的条数 @@ -96,41 +126,111 @@ class ProductCompat \think\facade\Db::rollback(); return error($th->getMessage()); } - \think\facade\Db::commit(); + \think\facade\Db::commit(); return success('操作成功'); } private function handleImport(array $xlsx_data, int $lang_id): void { - $compat_datas = $this->matchExistCompatData($xlsx_data, $lang_id); + list( + $models, + $exists_compat_ids, + $compat_models, + $compat_datas + ) = $this->matchExistsCompatData($xlsx_data, $lang_id); // 校验数据并组装sql语句 $raw_sql = $this->validateAndBuildSql($compat_datas); if (false === \think\facade\Db::execute($raw_sql)) { throw new \Exception(sprintf('第【%s】行执行导入 SQL 失败', implode(',', array_column($xlsx_data, 'seq_no')))); } + + // 清除旧兼容型号数据 + if (!empty($exists_compat_ids)) { + ProductCompatModelsModel::destroy(function ($query) use($exists_compat_ids) { + $query->where('compat_id', 'in', $exists_compat_ids); + }); + } + // 为不遗漏id重新查询 + $compat_map = ProductCompatModel::language($lang_id) + ->modelName($models) + ->column('id', 'model'); + // 插入兼容型号数据 + $compatible_models = []; + foreach ($compat_models as $m) { + $compat_id = $compat_map[$m['model']]; + foreach ($m['compatible_models'] as $compatible_model) { + $compatible_models[] = [ + 'compat_id' => $compat_id, + 'compatible_model' => $compatible_model, + ]; + } + } + if (!empty($compatible_models)) { + ProductCompatModelsModel::insertAll($compatible_models); + } } - private function matchExistCompatData(array $datas, int $lang_id) + private function matchExistsCompatData(array $datas, int $lang_id) { $models = array_column($datas, 'model'); $compat_map = ProductCompatModel::language($lang_id) ->modelName($models) ->column('id', 'model'); + $type_names = array_unique(array_column($datas, 'type_name')); + $type_map = ProductCompatTypesModel::language($lang_id) + ->typeName($type_names) + ->column('id', 'name'); + $part_names = array_unique(array_column($datas, 'part_name')); $part_map = ProductCompatPartsModel::language($lang_id) ->partName($part_names) ->column('id', 'name'); - // 匹配已存在数据的主键、配件id + // 匹配已存在数据的主键、类型id及配件id + $exists_compat_ids = []; + $errors = []; + $compat_models = []; foreach ($datas as &$d) { - $d['id'] = $compat_map[$d['model']] ?? null; + // 确认要更新的数据的主键 + $d['id'] = null; + if (isset($compat_map[$d['model']])) { + $d['id'] = $compat_map[$d['model']]; + $exists_compat_ids[] = $d['id']; + } + // 所属语言 $d['language_id'] = $lang_id; - $d['part_id'] = $part_map[$d['part_name']] ?? 0; + + // 确认产品类型id + if (empty($type_map[$d['type_name']])) { + $errors[] = "第【{$d['seq_no']}】行,产品类型【{$d['type_name']}】无效"; + continue; + } + $d['type_id'] = $type_map[$d['type_name']]; + + // 确认配件类型id + if (empty($part_map[$d['part_name']])) { + $errors[] = "第【{$d['seq_no']}】行,配件类型【{$d['part_name']}】无效"; + continue; + } + $d['part_id'] = $part_map[$d['part_name']]; + + // 处理兼容型号数据 + $compatible_models_str = str_replace(',', ',', $d['compatible_models']); + $compatible_models_arr = explode(',', $compatible_models_str); + if (!empty($compatible_models_arr)) { + $compat_models[] = [ + 'model' => $d['model'], + 'compatible_models' => $compatible_models_arr, + ]; + } } unset($d); + if (!empty($errors)) { + throw new \Exception(implode("\n", $errors)); + } - return $datas; + return [$models, $exists_compat_ids, $compat_models, $datas]; } private function validateAndBuildSql(array $compat_datas) { @@ -153,19 +253,18 @@ class ProductCompat { $pdo = \think\facade\Db::connect()->getPdo(); return sprintf( - '(%d, %d, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s)', + '(%d, %d, %d, %d, %s, %s, %s, %s, %s, %s, %s)', $compat['id'], $compat['language_id'], + $compat['type_id'], $compat['part_id'], - is_string($compat['label_name']) ? $pdo->quote($compat['label_name']) : $compat['label_name'], + is_string($compat['model']) ? $pdo->quote($compat['model']) : $compat['model'], is_string($compat['brand_name']) ? $pdo->quote($compat['brand_name']) : $compat['brand_name'], is_string($compat['level_name']) ? $pdo->quote($compat['level_name']) : $compat['level_name'], - is_string($compat['class_name']) ? $pdo->quote($compat['class_name']) : $compat['class_name'], + is_string($compat['spec_name']) ? $pdo->quote($compat['spec_name']) : $compat['spec_name'], is_string($compat['series_name']) ? $pdo->quote($compat['series_name']) : $compat['series_name'], - is_string($compat['model']) ? $pdo->quote($compat['model']) : $compat['model'], is_string($compat['capacity']) ? $pdo->quote($compat['capacity']) : $compat['capacity'], - is_string($compat['interface_type']) ? $pdo->quote($compat['interface_type']) : $compat['interface_type'], - is_string($compat['compat_status']) ? $pdo->quote($compat['compat_status']) : $compat['compat_status'] + is_string($compat['frequency']) ? $pdo->quote($compat['frequency']) : $compat['frequency'] ); } private function buildRawSql(array $values) @@ -174,28 +273,26 @@ class ProductCompat 'INSERT INTO %s ( `id`, `language_id`, + `type_id`, `part_id`, - `label_name`, + `model`, `brand_name`, `level_name`, - `class_name`, + `spec_name`, `series_name`, - `model`, `capacity`, - `interface_type`, - `compat_status` + `frequency` ) VALUES %s ON DUPLICATE KEY UPDATE + `type_id` = VALUES(`type_id`), `part_id` = VALUES(`part_id`), - `label_name` = VALUES(`label_name`), + `model` = VALUES(`model`), `brand_name` = VALUES(`brand_name`), `level_name` = VALUES(`level_name`), - `class_name` = VALUES(`class_name`), + `spec_name` = VALUES(`spec_name`), `series_name` = VALUES(`series_name`), - `model` = VALUES(`model`), `capacity` = VALUES(`capacity`), - `interface_type` = VALUES(`interface_type`), - `compat_status` = VALUES(`compat_status`) + `frequency` = VALUES(`frequency`) ', (new ProductCompatModel)->getTable(), implode(',', $values) @@ -208,16 +305,16 @@ class ProductCompat public function save() { $post = request()->post([ + 'type_id', 'part_id', - 'label_name', + 'model', 'brand_name', 'level_name', - 'class_name', + 'spec_name', 'series_name', - 'model', 'capacity', - 'interface_type', - 'compat_status', + 'frequency', + 'compatible_models', 'sort', 'disabled' ]); @@ -229,11 +326,31 @@ class ProductCompat return error($validate->getError()); } - $compat = ProductCompatModel::create($data); - if ($compat->isEmpty()) { - return error('操作失败'); + \think\facade\Db::startTrans(); + try { + $compat = ProductCompatModel::create($data); + if ($compat->isEmpty()) { + throw new \Exception('操作失败'); + } + + $compatible_models = []; + $models = explode(',', str_replace(',', ',', $post['compatible_models'])); + foreach ($models as $model) { + $compatible_models[] = [ + 'compat_id' => $compat->id, + 'compatible_model' => trim($model), + ]; + } + if (empty($compatible_models)) { + throw new \Exception('请确认兼容型号数据为有效'); + } + ProductCompatModelsModel::insertAll($compatible_models); + } catch (\Throwable $e) { + \think\facade\Db::rollback(); + return error($e->getMessage()); } + \think\facade\Db::commit(); return success('操作成功'); } @@ -244,11 +361,23 @@ class ProductCompat { $id = request()->param('id'); $data = ProductCompatModel::withoutField(['language_id', 'deleted_at']) + ->with([ + 'compatible_models' => function ($query) { + $query->field(['compat_id', 'compatible_model']); + } + ]) ->bypk($id) ->find(); if (empty($data)) { return error('获取失败'); } + if (!empty($data->compatible_models)) { + $compatible_models = []; + foreach ($data->compatible_models as $model) { + $compatible_models[] = $model['compatible_model']; + } + $data->compatible_models = implode(',', $compatible_models); + } return success("获取成功", $data); } @@ -260,16 +389,16 @@ class ProductCompat { $id = request()->param('id'); $put = request()->put([ + 'type_id', 'part_id', - 'label_name', + 'model', 'brand_name', 'level_name', - 'class_name', + 'spec_name', 'series_name', - 'model', 'capacity', - 'interface_type', - 'compat_status', + 'frequency', + 'compatible_models', 'sort', 'disabled' ]); @@ -281,14 +410,41 @@ class ProductCompat return error($validate->getError()); } - $compat = ProductCompatModel::bypk($id)->find(); - if (empty($compat)) { - return error('请确认操作对象是否正确'); - } - if (!$compat->save($data)) { - return error('操作失败'); + \think\facade\Db::startTrans(); + try { + $compat = ProductCompatModel::bypk($id)->find(); + if (empty($compat)) { + throw new \Exception('请确认操作对象是否正确'); + } + if (!$compat->save($data)) { + throw new \Exception('操作失败'); + } + + $compatible_models = []; + $models = explode(',', str_replace(',', ',', $put['compatible_models'])); + foreach ($models as $model) { + $compatible_models[] = [ + 'compat_id' => $compat->id, + 'compatible_model' => trim($model), + ]; + } + if (empty($compatible_models)) { + throw new \Exception('请确认兼容型号数据为有效'); + } + // 清除旧数据 + $deleted = ProductCompatModelsModel::destroy(function($query) use ($compat) { + $query->where('compat_id', '=', $compat->id); + }); + if (!$deleted) { + throw new \Exception('删除兼容型号数据失败'); + } + ProductCompatModelsModel::insertAll($compatible_models); + } catch (\Throwable $e) { + \think\facade\Db::rollback(); + return error($e->getMessage()); } + \think\facade\Db::commit(); return success('操作成功'); } diff --git a/app/admin/controller/v1/ProductCompatParts.php b/app/admin/controller/v1/ProductCompatParts.php index 543001c1..712da24f 100644 --- a/app/admin/controller/v1/ProductCompatParts.php +++ b/app/admin/controller/v1/ProductCompatParts.php @@ -4,132 +4,34 @@ declare (strict_types = 1); namespace app\admin\controller\v1; use app\admin\model\v1\ProductCompatPartsModel; -use app\admin\validate\v1\ProductCompatPartsValidate; -use think\Request; class ProductCompatParts { /** * 兼容配件列表 */ - public function index() + public function list() { $params = request()->param([ 'name', - 'is_show' => null, - 'page/d' => 1, - 'size/d' => 10 ]); $list = ProductCompatPartsModel::withoutField([ 'language_id', + 'sort', + 'disabled', + 'created_at', + 'updated_at', 'deleted_at' ]) ->language(request()->lang_id) - ->disabled(is_null($params['is_show']) ? null : ($params['is_show'] == 1 ? 0 : 1)) + ->disabled(false) ->withSearch('name', [ 'name' => $params['name']??null ]) ->order(['id' => 'desc']) - ->paginate([ - 'list_rows' => $params['size'], - 'page' => $params['page'], - ]); + ->select(); return success('获取成功', $list); } - - /** - * 添加兼容配件 - */ - public function save() - { - $post = request()->post([ - 'name', - 'sort', - 'disabled' - ]); - $data = array_merge($post, ['language_id' => request()->lang_id]); - - // 校验输入 - $validate = new ProductCompatPartsValidate; - if (!$validate->scene('add')->check($data)) { - return error($validate->getError()); - } - - $parts = ProductCompatPartsModel::create($data); - if ($parts->isEmpty()) { - return error('操作失败'); - } - - return success('操作成功'); - } - - /** - * 兼容配件详细 - */ - public function read() - { - $id = request()->param('id'); - - $parts = ProductCompatPartsModel::withoutField([ - 'language_id', - 'deleted_at' - ]) - ->bypk($id) - ->find(); - if (empty($parts)) { - return error('获取失败'); - } - - return success('获取成功', $parts); - } - - /** - * 兼容配件更新 - */ - public function update() - { - $id = request()->param('id'); - $put = request()->put([ - 'name', - 'sort', - 'disabled' - ]); - $data = array_merge($put, ['id' => $id, 'language_id' => request()->lang_id]); - - $validate = new ProductCompatPartsValidate; - if (!$validate->scene('edit')->check($data)) { - return error($validate->getError()); - } - - $parts = ProductCompatPartsModel::bypk($id)->find(); - if (empty($parts)) { - return error('请确认操作对象是否正确'); - } - - if (!$parts->save($put)) { - return error('操作失败'); - } - - return success('操作成功'); - } - - /** - * 兼容配件删除 - */ - public function delete() - { - $id = request()->param('id'); - $parts = ProductCompatPartsModel::bypk($id)->find(); - if (empty($parts)) { - return error('请确认操作对象是否正确'); - } - - if (!$parts->delete()) { - return error("操作失败"); - } - - return success("操作成功"); - } } diff --git a/app/admin/controller/v1/ProductCompatTypes.php b/app/admin/controller/v1/ProductCompatTypes.php new file mode 100644 index 00000000..e34073a7 --- /dev/null +++ b/app/admin/controller/v1/ProductCompatTypes.php @@ -0,0 +1,38 @@ +param([ + 'name', + ]); + + $list = ProductCompatTypesModel::withoutField([ + 'language_id', + 'sort', + 'disabled', + 'created_at', + 'updated_at', + 'deleted_at' + ]) + ->language(request()->lang_id) + ->disabled(false) + ->withSearch('name', [ + 'name' => $params['name']??null + ]) + ->order(['id' => 'desc']) + ->select(); + + return success('获取成功', $list); + } +} diff --git a/app/admin/model/v1/ProductCompatModel.php b/app/admin/model/v1/ProductCompatModel.php index 6c5dc919..625d11a2 100644 --- a/app/admin/model/v1/ProductCompatModel.php +++ b/app/admin/model/v1/ProductCompatModel.php @@ -16,18 +16,42 @@ class ProductCompatModel extends ProductCompatBaseModel // 软件删除时间字段 protected $deleteTime = 'deleted_at'; + // 关联产品类型 + public function types() + { + return $this->hasOne(ProductCompatTypesModel::class, 'id', 'type_id'); + } + // 关联配件类型 public function parts() { return $this->hasOne(ProductCompatPartsModel::class, 'id', 'part_id'); } + // 关联兼容型号 + public function compatibleModels() + { + return $this->hasMany(ProductCompatModelsModel::class, 'compat_id'); + } + // 按所属语言查询 public function scopeLanguage(\think\db\Query $query, int $value) { $query->where('language_id', $value); } + // 按类型查询 + public function scopeTypeId(\think\db\Query $query, int $value) + { + $query->where('type_id', '=', $value); + } + + // 按配件查询 + public function scopePartId(\think\db\Query $query, int $value) + { + $query->where('part_id', '=', $value); + } + // 按型号查询 public function scopeModelName(\think\db\Query $query, string|array $value) { @@ -39,11 +63,11 @@ class ProductCompatModel extends ProductCompatBaseModel $query->where('model', '=', $value); } - // 按标签名称搜索 - public function searchLabelNameAttr(\think\db\Query $query, string|null $value, array $data) + // 按品牌名称搜索 + public function searchBrandNameAttr(\think\db\Query $query, string|null $value, array $data) { if (is_null($value)) return; - $query->where('label_name', 'like', '%' . $value . '%'); + $query->where('brand_name', 'like', '%' . $value . '%'); } // 按型号搜索 @@ -52,4 +76,18 @@ class ProductCompatModel extends ProductCompatBaseModel if (is_null($value)) return; $query->where('model', 'like', '%' . $value . '%'); } + + // 按兼容型号搜索 + public function searchCompatibleModelAttr(\think\db\Query $query, string|null $value, array $data) + { + if (is_null($value)) return; + + $table = $this->getTable(); + $relation_table = ProductCompatModelsModel::getTable(); + $where = ProductCompatModelsModel::where($relation_table . '.compatible_model', 'like', '%' . $value . '%') + ->where('compat_id', '=', $table . '.id') + ->fetchSql(true) + ->select(); + $query->whereExists($where); + } } diff --git a/app/admin/model/v1/ProductCompatModelsModel.php b/app/admin/model/v1/ProductCompatModelsModel.php new file mode 100644 index 00000000..1aef1b2e --- /dev/null +++ b/app/admin/model/v1/ProductCompatModelsModel.php @@ -0,0 +1,14 @@ +where('disabled', '=', $disabled); + $query->where('disabled', '=', (int)$disabled); } // 查询配件类型名称搜索 diff --git a/app/admin/model/v1/ProductCompatTypesModel.php b/app/admin/model/v1/ProductCompatTypesModel.php new file mode 100644 index 00000000..b0364c7d --- /dev/null +++ b/app/admin/model/v1/ProductCompatTypesModel.php @@ -0,0 +1,48 @@ +where('language_id', $value); + } + + // 按类型名称查询 + public function scopeTypeName(\think\db\Query $query, string|array $value) + { + if (is_array($value)) { + $query->where('name', 'in', $value); + return; + } + $query->where('name', '=', $value); + } + + // 按状态查询 + public function scopeDisabled(\think\db\Query $query, bool|null $disabled) + { + if (is_null($disabled)) return; + $query->where('disabled', '=', (int)$disabled); + } + + // 查询配件类型名称搜索 + public function searchNameAttr(\think\db\Query $query, string|null $value, array $data) + { + if (is_null($value)) return; + $query->where('name', 'like', '%' . $value . '%'); + } +} diff --git a/app/admin/route/v1.php b/app/admin/route/v1.php index 8889da17..f83e6ff3 100644 --- a/app/admin/route/v1.php +++ b/app/admin/route/v1.php @@ -387,23 +387,11 @@ Route::group('v1', function () { // 兼容性数据删除 Route::delete('delete/:id', 'ProductCompat/delete'); - // 配件类型管理 - Route::group('parts', function () { - // 配件列表 - Route::get('index', 'ProductCompatParts/index'); + // 产品兼容性 - 配件类型 + Route::get('parts/list', 'ProductCompatParts/list'); - // 配件详情 - Route::get('read/:id', 'ProductCompatParts/read'); - - // 配件添加 - Route::post('save', 'ProductCompatParts/save'); - - // 配件更新 - Route::put('update/:id', 'ProductCompatParts/update'); - - // 配件删除 - Route::delete('delete/:id', 'ProductCompatParts/delete'); - }); + // 产品兼容性 - 产品类型 + Route::get('types/list', 'ProductCompatTypes/list'); }); }); diff --git a/app/admin/validate/v1/ProductCompatValidate.php b/app/admin/validate/v1/ProductCompatValidate.php index c2ccdc73..85e601c9 100644 --- a/app/admin/validate/v1/ProductCompatValidate.php +++ b/app/admin/validate/v1/ProductCompatValidate.php @@ -14,17 +14,19 @@ class ProductCompatValidate extends Validate * @var array */ protected $rule = [ - 'language_id' => 'require|integer', - 'part_id' => 'require|integer', - 'label_name' =>'max: 128', - 'brand_name' => 'max:128', - 'level_name' => 'max:32', - 'class_name' => 'max:128', - 'series_name' => 'max:128', - 'model' => 'require|max:128', - 'capacity' => 'max:32', - 'interface_type' => 'max:64', - 'compat_status' => 'max:64' + 'language_id' => 'require|integer', + 'type_id' => 'require|integer', + 'part_id' => 'require|integer', + 'model' => 'require|max:128', + 'brand_name' => 'require|max:128', + 'level_name' => 'max:128', + 'spec_name' => 'max:128', + 'series_name' => 'max:128', + 'capacity' => 'max:32', + 'frequency' => 'max:128', + 'compatible_models' => 'require|max:512', + 'sort' => 'integer', + 'disabled' => 'in:0,1' ]; /** @@ -38,18 +40,23 @@ class ProductCompatValidate extends Validate 'id.integer' => 'ID必须为整数', 'language_id.require' => '语言ID必须', 'language_id.integer' => '语言ID必须为整数', - 'part_id.require' => '零件ID必须', - 'part_id.integer' => '零件ID必须为整数', - 'label_name.max' => '标签名称不能超过:rule个字符', - 'brand_name.max' => '品牌名称不能超过:rule个字符', - 'level_name.max' => '等级名称不能超过:rule个字符', - 'class_name.max' => '类型名称不能超过:rule个字符', - 'series_name.max' => '系列名称不能超过:rule个字符', + 'type_id.require' => '类型ID必须', + 'type_id.integer' => '类型ID必须为整数', + 'part_id.require' => '配件ID必须', + 'part_id.integer' => '配件ID必须为整数', 'model.require' => '型号必须', 'model.max' => '型号不能超过:rule个字符', + 'brand_name.require' => '品牌必须', + 'brand_name.max' => '品牌不能超过:rule个字符', + 'level_name.max' => '等级不能超过:rule个字符', + 'spec_name.max' => '规格不能超过:rule个字符', + 'series_name.max' => '系列不能超过:rule个字符', 'capacity.max' => '容量不能超过:rule个字符', - 'interface_type.max' => '接口类型不能超过:rule个字符', - 'compat_status.max' => '兼容状态不能超过:rule个字符', + 'frequency.max' => '接口类型不能超过:rule个字符', + 'compatible_models.v' => '兼容型号必须', + 'compatible_models.max' => '兼容型号不能超过:rule个字符', + 'sort.integer' => '排序必须为整数', + 'disabled.in' => '禁用状态必须为0或1', ]; // 新增场景 diff --git a/app/common/model/ProductCompatBaseModel.php b/app/common/model/ProductCompatBaseModel.php index 63cf07bf..8e596781 100644 --- a/app/common/model/ProductCompatBaseModel.php +++ b/app/common/model/ProductCompatBaseModel.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace app\common\model; /** + * 产品兼容性模型 * @mixin \think\Model */ class ProductCompatBaseModel extends BaseModel @@ -18,16 +19,15 @@ class ProductCompatBaseModel extends BaseModel protected $schema = [ "id" => "int", "language_id" => "int", + "type_id" => "int", "part_id" => "int", - "label_name" => "string", + "model" => "string", "brand_name" => "string", "level_name" => "string", - "class_name" => "string", + "spec_name" => "string", "series_name" => "string", - "model" => "string", "capacity" => "string", - "interface_type" => "string", - "compat_status" => "string", + "frequency" => "string", "sort" => "int", "disabled" => "int", "created_at" => "datetime", diff --git a/app/common/model/ProductCompatModelsBaseModel.php b/app/common/model/ProductCompatModelsBaseModel.php new file mode 100644 index 00000000..6b42670d --- /dev/null +++ b/app/common/model/ProductCompatModelsBaseModel.php @@ -0,0 +1,26 @@ + "int", + "compat_id" => "int", + "compatible_model" => "string", + ]; +} diff --git a/app/common/model/ProductCompatPartsBaseModel.php b/app/common/model/ProductCompatPartsBaseModel.php index 0dc6f619..7c41d586 100644 --- a/app/common/model/ProductCompatPartsBaseModel.php +++ b/app/common/model/ProductCompatPartsBaseModel.php @@ -4,6 +4,7 @@ declare (strict_types = 1); namespace app\common\model; /** + * 产品兼容性 - 配件类型模型 * @mixin \think\Model */ class ProductCompatPartsBaseModel extends BaseModel diff --git a/app/common/model/ProductCompatTypesBaseModel.php b/app/common/model/ProductCompatTypesBaseModel.php new file mode 100644 index 00000000..d70940c4 --- /dev/null +++ b/app/common/model/ProductCompatTypesBaseModel.php @@ -0,0 +1,31 @@ + "int", + "language_id" => "int", + "name" => "string", + "sort" => "int", + "disabled" => "int", + "created_at" => "datetime", + "updated_at" => "datetime", + "deleted_at" => "datetime", + ]; +} diff --git a/database/migrations/20260707030708_create_product_compat.php b/database/migrations/20260707030708_create_product_compat.php index 613704b8..5b069600 100644 --- a/database/migrations/20260707030708_create_product_compat.php +++ b/database/migrations/20260707030708_create_product_compat.php @@ -29,28 +29,27 @@ class CreateProductCompat extends Migrator public function change() { $table = $this->table('product_compat', [ - 'engine' => 'MyISAM', + 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '产品兼容性表' ]); $table->addColumn('language_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '语言ID']) - ->addColumn('part_id', 'integer', ['null' => false, 'comment' => '配件id']) - ->addColumn('label_name', 'string', ['limit' => 128, 'null' => false, 'comment' => '标签名称']) - ->addColumn('brand_name', 'string', ['limit' => 128, 'null' => true, 'comment' => '品牌']) - ->addColumn('level_name', 'string', ['limit' => 32 , 'null' => true, 'comment' => '级别']) - ->addColumn('class_name', 'string', ['limit' => 128, 'null' => true, 'comment' => '类别']) - ->addColumn('series_name', 'string', ['limit' => 128, 'null' => true, 'comment' => '系列']) + ->addColumn('type_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '类型id']) + ->addColumn('part_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '配件id']) ->addColumn('model', 'string', ['limit' => 128, 'null' => false, 'comment' => '型号']) + ->addColumn('brand_name', 'string', ['limit' => 128, 'null' => false, 'comment' => '品牌']) + ->addColumn('level_name', 'string', ['limit' => 128 , 'null' => true, 'comment' => '级别']) + ->addColumn('spec_name', 'string', ['limit' => 128, 'null' => true, 'comment' => '规格']) + ->addColumn('series_name', 'string', ['limit' => 128, 'null' => true, 'comment' => '系列']) ->addColumn('capacity', 'string', ['limit' => 32, 'null' => true, 'comment' => '容量']) - ->addColumn('interface_type', 'string', ['limit' => 64, 'null' => true, 'comment' => '接口类型']) - ->addColumn('compat_status', 'string', ['limit' => 64, 'null' => true, 'comment' => '兼容性状态']) + ->addColumn('frequency', 'string', ['limit' => 128, 'null' => true, 'comment' => '频率']) ->addColumn('sort', 'integer', ['default' => 0, 'comment' => '排序']) ->addColumn('disabled', 'boolean', ['default' => 0, 'comment' => '是否禁用 0:启用 1:禁用']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间']) ->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间']) ->addColumn('deleted_at', 'timestamp', ['null' => true, 'comment' => '删除时间']) - ->addIndex(['language_id'], ['name' => 'idx_language_id']) + ->addIndex(['language_id', 'model'], ['unique' => true]) ->create(); } } diff --git a/database/migrations/20260707034159_create_product_compat_types.php b/database/migrations/20260707034159_create_product_compat_types.php index 88bd2393..817b9dea 100644 --- a/database/migrations/20260707034159_create_product_compat_types.php +++ b/database/migrations/20260707034159_create_product_compat_types.php @@ -31,7 +31,7 @@ class CreateProductCompatTypes extends Migrator $table = $this->table('product_compat_types', [ 'engine' => 'MyISAM', 'collation' => 'utf8mb4_general_ci', - 'comment' => '产品兼容性-产品类型' + 'comment' => '产品兼容性-产品类型表' ]); $table->addColumn('language_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '语言ID']) diff --git a/database/migrations/20260811031643_create_product_compat_models.php b/database/migrations/20260811031643_create_product_compat_models.php new file mode 100644 index 00000000..b07212d6 --- /dev/null +++ b/database/migrations/20260811031643_create_product_compat_models.php @@ -0,0 +1,41 @@ +table('product_compat_models', [ + 'engine' => 'InnoDB', + 'collation' => 'utf8mb4_general_ci', + 'comment' => '产品兼容性-兼容型号表' + ]); + + $table->addColumn('compat_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '产品兼容性id']) + ->addColumn('compatible_model', 'string', ['limit' => 128, 'null' => true, 'comment' => '兼容型号']) + ->create(); + } +} diff --git a/database/seeds/ProductCompatPartsInit.php b/database/seeds/ProductCompatPartsInit.php new file mode 100644 index 00000000..037e9a87 --- /dev/null +++ b/database/seeds/ProductCompatPartsInit.php @@ -0,0 +1,33 @@ + 1, 'language_id' => 1, 'name' => '机械硬盘', 'sort' => 1, 'disabled' => 0], + ['id' => 2, 'language_id' => 1, 'name' => '2.5 寸固态硬盘', 'sort' => 2, 'disabled' => 0], + ['id' => 3, 'language_id' => 1, 'name' => 'M.2 固态硬盘', 'sort' => 3, 'disabled' => 0], + ['id' => 4, 'language_id' => 1, 'name' => '内存条', 'sort' => 4, 'disabled' => 0], + ['id' => 5, 'language_id' => 1, 'name' => 'UPS 不间断电源', 'sort' => 5, 'disabled' => 0] + ]; + + $table = $this->table('product_compat_parts'); + + // empty the table + $table->truncate(); + + // insert data + $table->insert($data)->saveData(); + } +} diff --git a/database/seeds/ProductCompatTypesInit.php b/database/seeds/ProductCompatTypesInit.php new file mode 100644 index 00000000..d4995055 --- /dev/null +++ b/database/seeds/ProductCompatTypesInit.php @@ -0,0 +1,30 @@ + 1, 'language_id' => 1, 'name' => '私有云存储 NAS', 'sort' => 1, 'disabled' => 0], + ['id' => 2, 'language_id' => 1, 'name' => '直连储存 DAS', 'sort' => 2, 'disabled' => 0] + ]; + + $table = $this->table('product_compat_types'); + + // empty the table + $table->truncate(); + + // insert data + $table->insert($data)->saveData(); + } +}