refactor: 清理产品兼容性与产品关联相关
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 4s
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 4s
This commit is contained in:
@@ -3,7 +3,6 @@ declare (strict_types = 1);
|
|||||||
|
|
||||||
namespace app\admin\controller\v1;
|
namespace app\admin\controller\v1;
|
||||||
|
|
||||||
use app\admin\model\v1\ProductCompatRelModel;
|
|
||||||
use app\admin\model\v1\ProductModel;
|
use app\admin\model\v1\ProductModel;
|
||||||
use app\admin\model\v1\ProductParamsModel;
|
use app\admin\model\v1\ProductParamsModel;
|
||||||
use app\admin\model\v1\ProductRelatedModel;
|
use app\admin\model\v1\ProductRelatedModel;
|
||||||
@@ -120,39 +119,6 @@ class Product
|
|||||||
->bindAttr('product', ['spu'])
|
->bindAttr('product', ['spu'])
|
||||||
->hidden(['product']);
|
->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);
|
return success('获取成功', $product);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +144,6 @@ class Product
|
|||||||
'params' => '',
|
'params' => '',
|
||||||
'skus' => '',
|
'skus' => '',
|
||||||
'related' => '',
|
'related' => '',
|
||||||
'compat' => '',
|
|
||||||
'seo_title',
|
'seo_title',
|
||||||
'seo_keywords',
|
'seo_keywords',
|
||||||
'seo_desc'
|
'seo_desc'
|
||||||
@@ -284,28 +249,6 @@ 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('操作成功');
|
return success('操作成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare (strict_types = 1);
|
|
||||||
|
|
||||||
namespace app\admin\model\v1;
|
|
||||||
|
|
||||||
use app\common\model\ProductCompatRelBaseModel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @mixin \think\Model
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare (strict_types = 1);
|
|
||||||
|
|
||||||
namespace app\common\model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @mixin \think\Model
|
|
||||||
*/
|
|
||||||
class ProductCompatRelBaseModel extends BaseModel
|
|
||||||
{
|
|
||||||
// 表名
|
|
||||||
protected $name = "product_compat_rel";
|
|
||||||
|
|
||||||
// 主键
|
|
||||||
protected $pk = "id";
|
|
||||||
|
|
||||||
// 字段信息
|
|
||||||
protected $schema = [
|
|
||||||
"id" => "int",
|
|
||||||
"language_id" => "int",
|
|
||||||
"product_id" => "int",
|
|
||||||
"compat_id" => "int",
|
|
||||||
"series_name" => "string",
|
|
||||||
"show_series_name" => "int",
|
|
||||||
"remark" => "int",
|
|
||||||
"created_at" => "datetime",
|
|
||||||
"updated_at" => "datetime",
|
|
||||||
];
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user