Compare commits
6 Commits
d8a584e9b7
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 71f4b82e4b | |||
| b4b4b914c2 | |||
| d71251fecf | |||
| 77e60ef482 | |||
| 116d788ecc | |||
| 0c20bd0519 |
@@ -121,17 +121,37 @@ class Product
|
|||||||
->hidden(['product']);
|
->hidden(['product']);
|
||||||
|
|
||||||
// 兼容性信息
|
// 兼容性信息
|
||||||
$product->compat = ProductCompatRelModel::withoutField([
|
$compat = ProductCompatRelModel::withoutField([
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
])
|
])
|
||||||
->with(['compat' => function($query) {
|
->withJoin(['compat' => function($query) {
|
||||||
$query->field(['id', 'label_name']);
|
$query->whereNull('deleted_at');
|
||||||
}])
|
}])
|
||||||
->productId($product->id)
|
->productId($product->id)
|
||||||
->select()
|
->select()
|
||||||
?->bindAttr('compat', ['label_name'])
|
?->bindAttr('compat', ['label_name'])
|
||||||
?->hidden(['compat']);
|
?->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);
|
return success('获取成功', $product);
|
||||||
}
|
}
|
||||||
@@ -270,14 +290,15 @@ class Product
|
|||||||
ProductCompatRelModel::productId($id)->delete();
|
ProductCompatRelModel::productId($id)->delete();
|
||||||
|
|
||||||
$compat = [];
|
$compat = [];
|
||||||
$rel_compat = json_decode(data_get($put['compat'], 'compat_id') ?? [], true);
|
$put_compat = json_decode($put['compat'], true);
|
||||||
|
$rel_compat = explode(',', str_replace(',', ',', data_get($put_compat, 'compat_id')));
|
||||||
foreach ($rel_compat as $compat_id) {
|
foreach ($rel_compat as $compat_id) {
|
||||||
$compat[] = [
|
$compat[] = [
|
||||||
'product_id' => $id,
|
'product_id' => $id,
|
||||||
'compat_id' => $compat_id,
|
'compat_id' => $compat_id,
|
||||||
'series_name' => data_get($put['compat'], 'series_name'),
|
'series_name' => data_get($put_compat, 'series_name'),
|
||||||
'show_series_name' => data_get($put['compat'], 'show_series_name') ?? 0,
|
'show_series_name' => data_get($put_compat, 'show_series_name') ?? 0,
|
||||||
'remark' => data_get($put['compat'], 'remark')
|
'remark' => data_get($put_compat, 'remark')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if (!empty($compat)) {
|
if (!empty($compat)) {
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ class ProductCompatParts
|
|||||||
{
|
{
|
||||||
$params = request()->param([
|
$params = request()->param([
|
||||||
'name',
|
'name',
|
||||||
'page/d' => 1,
|
'is_show' => null,
|
||||||
'size/d' => 10
|
'page/d' => 1,
|
||||||
|
'size/d' => 10
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$list = ProductCompatPartsModel::withoutField([
|
$list = ProductCompatPartsModel::withoutField([
|
||||||
@@ -25,6 +26,7 @@ class ProductCompatParts
|
|||||||
'deleted_at'
|
'deleted_at'
|
||||||
])
|
])
|
||||||
->language(request()->lang_id)
|
->language(request()->lang_id)
|
||||||
|
->disabled(is_null($params['is_show']) ? null : ($params['is_show'] == 1 ? 0 : 1))
|
||||||
->withSearch('name', [
|
->withSearch('name', [
|
||||||
'name' => $params['name']??null
|
'name' => $params['name']??null
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -16,13 +16,6 @@ class ProductCompatPartsModel extends ProductCompatPartsBaseModel
|
|||||||
// 软件删除时间字段
|
// 软件删除时间字段
|
||||||
protected $deleteTime = 'deleted_at';
|
protected $deleteTime = 'deleted_at';
|
||||||
|
|
||||||
// 状态获取器
|
|
||||||
public function getStatusTextAttr($value, array $data)
|
|
||||||
{
|
|
||||||
$status = ['启用', '禁用'];
|
|
||||||
return $status[$data['status']];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 按所属语言查询
|
// 按所属语言查询
|
||||||
public function scopeLanguage(\think\db\Query $query, int $value)
|
public function scopeLanguage(\think\db\Query $query, int $value)
|
||||||
{
|
{
|
||||||
@@ -39,6 +32,13 @@ class ProductCompatPartsModel extends ProductCompatPartsBaseModel
|
|||||||
$query->where('name', '=', $value);
|
$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)
|
public function searchNameAttr(\think\db\Query $query, string|null $value, array $data)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,15 +34,12 @@ class CreateProductCompatRel extends Migrator
|
|||||||
'comment' => '产品兼容性关联表'
|
'comment' => '产品兼容性关联表'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$table->addColumn('language_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '语言ID'])
|
$table->addColumn('product_id', 'integer', ['null' => false, 'comment' => '产品id'])
|
||||||
->addColumn('product_id', 'integer', ['null' => false, 'comment' => '产品id'])
|
->addColumn('compat_id', 'int', ['null' => false, 'comment' => '关联的兼容性数据id'])
|
||||||
->addColumn('compat_id', 'json', ['null' => false, 'comment' => '关联的兼容性数据id'])
|
|
||||||
->addColumn('series_name', 'string', ['limit' => 128, 'null' => true, 'comment' => '产品系列名'])
|
->addColumn('series_name', 'string', ['limit' => 128, 'null' => true, 'comment' => '产品系列名'])
|
||||||
->addColumn('show_series_name', 'boolean', ['null' => false, 'default' => 0, 'comment' => '是否显示系列名:0=否,1=是'])
|
->addColumn('show_series_name', 'boolean', ['null' => false, 'default' => 0, 'comment' => '是否显示系列名:0=否,1=是'])
|
||||||
->addColumn('remark', 'string', ['limit' => 512, 'null' => true, 'comment' => '兼容性说明'])
|
->addColumn('remark', 'string', ['limit' => 512, 'null' => true, 'comment' => '兼容性说明'])
|
||||||
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', '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();
|
->create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user