diff --git a/app/common/dao/store/product/SpuDao.php b/app/common/dao/store/product/SpuDao.php index c3447373..6f967d03 100644 --- a/app/common/dao/store/product/SpuDao.php +++ b/app/common/dao/store/product/SpuDao.php @@ -121,6 +121,11 @@ class SpuDao extends BaseDao $query->where('P.mer_id', $merId); } elseif ($where['mer_type'] == 2) { $query->where('P.mer_id', '<>', $merId); + } elseif ($where['mer_type'] == 3) { + $labelId = ProductLabel::where('label_name', '名优特产')->value('product_label_id'); + if (!empty($labelId)) { + $query->whereLike('S.sys_labels',"%,{$labelId},%"); + } } }) ->when(isset($where['cate_pid']) && $where['cate_pid'], function ($query) use ($where) { @@ -187,12 +192,6 @@ class SpuDao extends BaseDao ->when(isset($where['spu_status']) && $where['spu_status'] !== '',function($query)use($where){ $query->where('S.status',$where['spu_status']); }) - ->when(isset($where['label_name']) && $where['label_name'] !== '',function($query)use($where){ - $labelId = ProductLabel::where('label_name', $where['label_name'])->value('product_label_id'); - if (!empty($labelId)) { - $query->whereLike('S.sys_labels',"%,{$labelId},%"); - } - }) ->when(isset($where['sys_labels']) && $where['sys_labels'] !== '',function($query)use($where){ $query->whereLike('S.sys_labels',"%,{$where['sys_labels']},%"); }) diff --git a/app/common/repositories/store/product/ProductLabelRepository.php b/app/common/repositories/store/product/ProductLabelRepository.php index d01742ba..d48720a0 100644 --- a/app/common/repositories/store/product/ProductLabelRepository.php +++ b/app/common/repositories/store/product/ProductLabelRepository.php @@ -159,6 +159,9 @@ class ProductLabelRepository extends BaseRepository $labels = reset_index($labels, 'product_label_id'); foreach ($list as &$item) { $item['mer_label_name'] = []; + if ($this->isWholeSale === true) { + $item['mer_label_name'][] = '批发价'; + } if ($this->isOrder === true) { if (isset($item['cart_info']['mer_labels'])) { $item['mer_labels'] = explode(',', trim($item['cart_info']['mer_labels'], ',')); @@ -166,12 +169,12 @@ class ProductLabelRepository extends BaseRepository $merTypeId = $this->merTypeId > 0 ?? $item['merchant']['type_id']; $item['mer_label_name'][] = $merTypeId == 22 ? '里海云仓商品' : '综合云市场商品'; } - if ($this->isWholeSale === true) { - $item['mer_label_name'][] = '批发价'; - } if (!empty($item['mer_labels'])) { foreach ($item['mer_labels'] as $labelId) { - $item['mer_label_name'][] = $labels[$labelId]['label_name'] ?? ''; + $labelName = $labels[$labelId]['label_name'] ?? ''; + if (!empty($labelName)) { + $item['mer_label_name'][] = $labelName; + } } } } diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index c296eba3..993c8448 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -10,6 +10,7 @@ // +---------------------------------------------------------------------- namespace app\controller\api\store\product; +use app\common\Enum; use app\common\model\store\product\ProductLabel; use app\common\model\system\merchant\Merchant; use app\common\repositories\store\product\ProductLabelRepository; @@ -92,6 +93,7 @@ class StoreSpu extends BaseController $merIds = array_unique(array_column($list, 'mer_id')); /** @var ProductLabelRepository $labelRepo */ $labelRepo = app()->make(ProductLabelRepository::class); + $labelRepo->isWholeSale = $where['sale_type'] == Enum::SALE_TYPE_WHOLESALE; $list = $labelRepo->appendLabel($merIds, $list); return app('json')->success(['count' => $count, 'list' => $list]); } @@ -107,14 +109,21 @@ class StoreSpu extends BaseController { [$page, $limit] = $this->getPage(); $where = $this->request->params([ - 'keyword', 'cate_id', 'order', 'price_on', 'price_off', 'brand_id', 'pid', 'mer_cate_id', ['product_type', 0], 'action', 'common', 'deduction_rate' + 'keyword', 'cate_id', 'order', 'price_on', 'price_off', 'brand_id', 'pid', 'mer_cate_id', ['product_type', 0], 'action', 'common', 'deduction_rate', 'sale_type' ]); if ($where['action']) unset($where['product_type']); $where['mer_id'] = $id; $where['is_gift_bag'] = 0; $where['order'] = $where['order'] ? $where['order'] : 'sort'; $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo); - return app('json')->success($data); + $count = $data['count']; + $list = $data['list']->toArray(); + $merIds = array_unique(array_column($list, 'mer_id')); + /** @var ProductLabelRepository $labelRepo */ + $labelRepo = app()->make(ProductLabelRepository::class); + $labelRepo->isWholeSale = $where['sale_type'] == Enum::SALE_TYPE_WHOLESALE; + $list = $labelRepo->appendLabel($merIds, $list); + return app('json')->success(['count' => $count, 'list' => $list]); } /** @@ -153,7 +162,14 @@ class StoreSpu extends BaseController $where['product_type'] = 0; $where['is_stock'] = 1; $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo); - return app('json')->success($data); + $count = $data['count']; + $list = $data['list']->toArray(); + $merIds = array_unique(array_column($list, 'mer_id')); + /** @var ProductLabelRepository $labelRepo */ + $labelRepo = app()->make(ProductLabelRepository::class); + $labelRepo->isWholeSale = $where['sale_type'] == Enum::SALE_TYPE_WHOLESALE; + $list = $labelRepo->appendLabel($merIds, $list); + return app('json')->success(['count' => $count, 'list' => $list]); } /**