From 33f004d1196d056b99a3886de070d429315bac39 Mon Sep 17 00:00:00 2001
From: quanwei <419654421@qq.com>
Date: Thu, 11 Dec 2025 18:12:38 +0800
Subject: [PATCH] 将分类改为多选 修复活动报名 实现成为vip会员时根据活动报名信息绑定下级
---
admin/app/common/model/product/Product.php | 35 ++++++++++++++++++++++++++++++++++-
1 files changed, 34 insertions(+), 1 deletions(-)
diff --git a/admin/app/common/model/product/Product.php b/admin/app/common/model/product/Product.php
index a4bb84c..40f00f3 100644
--- a/admin/app/common/model/product/Product.php
+++ b/admin/app/common/model/product/Product.php
@@ -49,6 +49,22 @@
}
/**
+ * 关联商品多分类表
+ */
+ public function categorys()
+ {
+ return $this->hasMany('app\\common\\model\\product\\ProductCategory', 'product_id', 'product_id');
+ }
+
+ /**
+ * 关联商品多分类表
+ */
+ public function category_ids()
+ {
+ return $this->hasMany('app\\common\\model\\product\\ProductCategory', 'product_id', 'product_id');
+ }
+
+ /**
* 关联商品分类表
*/
public function category()
@@ -179,7 +195,12 @@
$model = $this;
if ($params['category_id'] > 0) {
$arr = Category::getSubCategoryId($params['category_id']);
- $model = $model->where('product.category_id', 'IN', $arr);
+ $productIds = ProductCategory::getProductIds($params['category_id']);
+ if ($productIds) {
+ $model = $model->whereRaw('product.category_id in (' . implode(',', $arr) . ') OR product_id in (' . implode(',', $productIds) . ')');
+ } else {
+ $model = $model->where('product.category_id', 'IN', $arr);
+ }
}
if (!empty($params['product_name'])) {
$model = $model->where('product_name', 'like', '%' . trim($params['product_name']) . '%');
@@ -362,6 +383,17 @@
if($product['verify_type'] == 20){
$product['verify_time'] = [date('Y-m-d H:i:s', $product['verify_start_time']), date('Y-m-d H:i:s', $product['verify_end_time'])];
}
+ // 商品多分类 by lyzflash
+ $product['category_ids'] = [];
+ if (!$product['categorys']->isEmpty()) {
+ $product['category_ids'] = helper::getArrayColumn($product['categorys'], 'category_id');
+ $product['category_names'] = implode('、', helper::getArrayColumn((new Category)->getListByIds($product['category_ids']), 'name'));
+ } else {
+ // 兼容没有多分类前的数据 by lyzflash
+ if ($product['category_id']) {
+ $product['category_ids'] = [$product['category_id']];
+ }
+ }
// 回调函数
is_callable($callback) && call_user_func($callback, $product);
}
@@ -508,6 +540,7 @@
'supplier.logo',
'video',
'poster',
+ 'categorys.category',
'contentImage.file',
])->where('product_id', '=', $product_id)
->find();
--
Gitblit v1.9.2