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']);
            $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();