| | |
| | | } |
| | | |
| | | /** |
| | | * 关联商品多分类表 |
| | | */ |
| | | 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() |
| | |
| | | $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']) . '%'); |
| | |
| | | "$minPriceSql AS product_min_price", |
| | | "$maxPriceSql AS product_max_price" |
| | | ]) |
| | | ->with(['category', 'image.file', 'sku', 'supplier']) |
| | | ->with(['category', 'image.file', 'sku', 'supplier', 'spec_rel.spec']) |
| | | ->join('supplier supplier', 'product.shop_supplier_id = supplier.shop_supplier_id','left') |
| | | ->where('product.is_delete', '=', 0) |
| | | ->where('supplier.is_delete', '=', 0) |
| | |
| | | // 核销有效时间段 |
| | | 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); |
| | |
| | | 'supplier.logo', |
| | | 'video', |
| | | 'poster', |
| | | 'categorys.category', |
| | | 'contentImage.file', |
| | | ])->where('product_id', '=', $product_id) |
| | | ->find(); |