8 Commits

Author SHA1 Message Date
71f4b82e4b fix: 处理产品兼容性信息回显数据结构问题
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 4s
2026-07-09 11:27:04 +08:00
b4b4b914c2 fix: 修复兼容配件类型状态筛选bug
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 3s
2026-07-09 10:09:46 +08:00
d71251fecf refactor: 去除兼容配件类型model中不必要的获取器代码
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 3s
2026-07-09 09:56:23 +08:00
77e60ef482 fix: 兼容配件遗漏状态筛选问题
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 3s
2026-07-09 09:46:09 +08:00
116d788ecc fix: 修复产品兼容性信息更新问题
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 2s
2026-07-08 18:01:24 +08:00
0c20bd0519 refactor: 更新产品兼容性关联表迁移文件
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 3s
2026-07-08 17:52:09 +08:00
d8a584e9b7 refactor: 产品详细兼容性信息输入及更新
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 6s
2026-07-08 17:45:48 +08:00
36261488b4 feat: 产品更新时可编辑兼容性数据 2026-07-08 17:26:18 +08:00
5 changed files with 81 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ declare (strict_types = 1);
namespace app\admin\controller\v1;
use app\admin\model\v1\ProductCompatRelModel;
use app\admin\model\v1\ProductModel;
use app\admin\model\v1\ProductParamsModel;
use app\admin\model\v1\ProductRelatedModel;
@@ -119,6 +120,39 @@ class Product
->bindAttr('product', ['spu'])
->hidden(['product']);
// 兼容性信息
$compat = ProductCompatRelModel::withoutField([
'created_at',
'updated_at',
])
->withJoin(['compat' => function($query) {
$query->whereNull('deleted_at');
}])
->productId($product->id)
->select()
?->bindAttr('compat', ['label_name'])
?->hidden(['compat']);
$compat_map = [];
if (!empty($compat)) {
foreach ($compat as $item) {
if (!isset($compat_map[$item['product_id']])) {
$compat_map[$item['product_id']] = [
'product_id' => $item['product_id'],
'compat' => [],
'series_name' => $item['series_name'],
'show_series_name' => $item['show_series_name'],
'remark' => $item['remark'],
];
}
$compat_map[$item['product_id']]['compat'][] = [
'compat_id' => $item['compat_id'],
'label_name' => $item['label_name'],
];
}
$compat_map = array_values($compat_map);
}
$product->compat = $compat_map;
return success('获取成功', $product);
}
@@ -144,6 +178,7 @@ class Product
'params' => '',
'skus' => '',
'related' => '',
'compat' => '',
'seo_title',
'seo_keywords',
'seo_desc'
@@ -249,6 +284,28 @@ class Product
}
}
// 更新兼容性信息
if (!empty($put['compat'])) {
// 删除原先的兼容信息
ProductCompatRelModel::productId($id)->delete();
$compat = [];
$put_compat = json_decode($put['compat'], true);
$rel_compat = explode(',', str_replace('', ',', data_get($put_compat, 'compat_id')));
foreach ($rel_compat as $compat_id) {
$compat[] = [
'product_id' => $id,
'compat_id' => $compat_id,
'series_name' => data_get($put_compat, 'series_name'),
'show_series_name' => data_get($put_compat, 'show_series_name') ?? 0,
'remark' => data_get($put_compat, 'remark')
];
}
if (!empty($compat)) {
ProductCompatRelModel::insertAll($compat);
}
}
return success('操作成功');
}

View File

@@ -16,8 +16,9 @@ class ProductCompatParts
{
$params = request()->param([
'name',
'page/d' => 1,
'size/d' => 10
'is_show' => null,
'page/d' => 1,
'size/d' => 10
]);
$list = ProductCompatPartsModel::withoutField([
@@ -25,6 +26,7 @@ class ProductCompatParts
'deleted_at'
])
->language(request()->lang_id)
->disabled(is_null($params['is_show']) ? null : ($params['is_show'] == 1 ? 0 : 1))
->withSearch('name', [
'name' => $params['name']??null
])

View File

@@ -16,13 +16,6 @@ class ProductCompatPartsModel extends ProductCompatPartsBaseModel
// 软件删除时间字段
protected $deleteTime = 'deleted_at';
// 状态获取器
public function getStatusTextAttr($value, array $data)
{
$status = ['启用', '禁用'];
return $status[$data['status']];
}
// 按所属语言查询
public function scopeLanguage(\think\db\Query $query, int $value)
{
@@ -39,6 +32,13 @@ class ProductCompatPartsModel extends ProductCompatPartsBaseModel
$query->where('name', '=', $value);
}
// 按状态查询
public function scopeDisabled(\think\db\Query $query, int|null $disabled)
{
if (is_null($disabled)) return;
$query->where('disabled', '=', $disabled);
}
// 查询配件类型名称搜索
public function searchNameAttr(\think\db\Query $query, string|null $value, array $data)
{

View File

@@ -10,5 +10,15 @@ use app\common\model\ProductCompatRelBaseModel;
*/
class ProductCompatRelModel extends ProductCompatRelBaseModel
{
//
// 关联兼容性数据
public function compat()
{
return $this->hasOne(ProductCompatModel::class, 'id', 'compat_id');
}
// 按所属产品查询
public function scopeProductId(\think\db\Query $query, int $id)
{
$query->where('product_id', '=', $id);
}
}

View File

@@ -34,15 +34,12 @@ class CreateProductCompatRel extends Migrator
'comment' => '产品兼容性关联表'
]);
$table->addColumn('language_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '语言ID'])
->addColumn('product_id', 'integer', ['null' => false, 'comment' => '产品id'])
->addColumn('compat_id', 'json', ['null' => false, 'comment' => '关联的兼容性数据id'])
$table->addColumn('product_id', 'integer', ['null' => false, 'comment' => '产品id'])
->addColumn('compat_id', 'int', ['null' => false, 'comment' => '关联的兼容性数据id'])
->addColumn('series_name', 'string', ['limit' => 128, 'null' => true, 'comment' => '产品系列名'])
->addColumn('show_series_name', 'boolean', ['null' => false, 'default' => 0, 'comment' => '是否显示系列名0=否1=是'])
->addColumn('remark', 'string', ['limit' => 512, 'null' => true, 'comment' => '兼容性说明'])
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间'])
->addIndex(['language_id'], ['name' => 'idx_language_id'])
->create();
}
}