Compare commits
2 Commits
3545b82015
...
d8a584e9b7
| Author | SHA1 | Date | |
|---|---|---|---|
| d8a584e9b7 | |||
| 36261488b4 |
@@ -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,19 @@ class Product
|
||||
->bindAttr('product', ['spu'])
|
||||
->hidden(['product']);
|
||||
|
||||
// 兼容性信息
|
||||
$product->compat = ProductCompatRelModel::withoutField([
|
||||
'created_at',
|
||||
'updated_at',
|
||||
])
|
||||
->with(['compat' => function($query) {
|
||||
$query->field(['id', 'label_name']);
|
||||
}])
|
||||
->productId($product->id)
|
||||
->select()
|
||||
?->bindAttr('compat', ['label_name'])
|
||||
?->hidden(['compat']);
|
||||
|
||||
return success('获取成功', $product);
|
||||
}
|
||||
|
||||
@@ -144,6 +158,7 @@ class Product
|
||||
'params' => '',
|
||||
'skus' => '',
|
||||
'related' => '',
|
||||
'compat' => '',
|
||||
'seo_title',
|
||||
'seo_keywords',
|
||||
'seo_desc'
|
||||
@@ -249,6 +264,27 @@ class Product
|
||||
}
|
||||
}
|
||||
|
||||
// 更新兼容性信息
|
||||
if (!empty($put['compat'])) {
|
||||
// 删除原先的兼容信息
|
||||
ProductCompatRelModel::productId($id)->delete();
|
||||
|
||||
$compat = [];
|
||||
$rel_compat = json_decode(data_get($put['compat'], 'compat_id') ?? [], true);
|
||||
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('操作成功');
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user