diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 89705a45..ff85ff68 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -6,6 +6,7 @@ use app\common\dao\store\coupon\StoreCouponUserDao; use app\common\Enum; use app\common\model\store\order\StoreOrder; use app\common\model\store\product\ProductCate; +use app\common\model\store\product\Spu; use app\common\model\system\merchant\Merchant; use app\common\repositories\system\form\FormRepository; use app\common\repositories\system\RecordRepository; @@ -1330,6 +1331,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository 'productAttr' => $cart['productAttr'], 'product_type' => $cart['product_type'] ]; + $order_cart['mer_labels'] = Spu::where('product_id', $cart['product_id'])->value('mer_labels'); if ($cart['product_type'] == '2') { $order_cart['productPresell'] = $cart['productPresell']; diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 4707630c..757a1e6c 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -13,6 +13,7 @@ namespace app\common\repositories\store\order; use app\common\dao\store\order\StoreOrderDao; use app\common\dao\system\financial\FinancialRecordDao; +use app\common\Enum; use app\common\model\store\order\StoreGroupOrder; use app\common\model\store\order\StoreOrder; use app\common\model\store\order\StoreRefundOrder; @@ -28,6 +29,7 @@ use app\common\repositories\store\product\ProductAssistSetRepository; use app\common\repositories\store\product\ProductAttrValueRepository; use app\common\repositories\store\product\ProductCopyRepository; use app\common\repositories\store\product\ProductGroupBuyingRepository; +use app\common\repositories\store\product\ProductLabelRepository; use app\common\repositories\store\product\ProductPresellSkuRepository; use app\common\repositories\store\product\ProductRepository; use app\common\repositories\store\product\StoreDiscountRepository; @@ -1794,7 +1796,7 @@ class StoreOrderRepository extends BaseRepository 'orderProduct', 'presellOrder', 'merchant' => function ($query) { - return $query->field('mer_id,mer_name'); + return $query->field('mer_id,mer_name,type_id'); }, 'community', 'receipt' => function ($query) { @@ -1814,8 +1816,17 @@ class StoreOrderRepository extends BaseRepository $order->takeOrderCount = count($order['takeOrderList']); unset($order['takeOrderList']); } - - return compact( 'count','list'); + $orders = $list->toArray(); + $merIds = array_unique(array_column($orders, 'mer_id')); + /** @var ProductLabelRepository $labelRepo */ + $labelRepo = app()->make(ProductLabelRepository::class); + foreach ($orders as &$order) { + $labelRepo->isOrder = true; + $labelRepo->merTypeId = $order['merchant']['type_id']; + $labelRepo->isWholeSale = $order['sale_type'] == Enum::SALE_TYPE_WHOLESALE; + $order['orderProduct'] = $labelRepo->appendLabel($merIds, $order['orderProduct']); + } + return compact( 'count','orders'); } public function userList($uid, $page, $limit) diff --git a/app/common/repositories/store/product/ProductLabelRepository.php b/app/common/repositories/store/product/ProductLabelRepository.php index e4af6c5e..d01742ba 100644 --- a/app/common/repositories/store/product/ProductLabelRepository.php +++ b/app/common/repositories/store/product/ProductLabelRepository.php @@ -11,6 +11,7 @@ namespace app\common\repositories\store\product; use app\common\dao\store\product\ProductLabelDao; +use app\common\model\store\product\ProductLabel; use app\common\repositories\BaseRepository; use FormBuilder\Factory\Elm; use think\exception\ValidateException; @@ -19,6 +20,9 @@ use think\facade\Route; class ProductLabelRepository extends BaseRepository { protected $dao; + public $isOrder = false; //是否订单列表 + public $isWholeSale = false; //是否为批发订单 + public $merTypeId = 0; //店铺类型id public function __construct(ProductLabelDao $dao) { @@ -136,4 +140,42 @@ class ProductLabelRepository extends BaseRepository return $this->dao->query([$this->dao->getPk() => $label_id])->value('label_name') ?? ''; } + /** + * 商品列表追加标签 + * @param array $merIds 商户id + * @param array $list 商品列表 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function appendLabel($merIds, $list) + { + $labels = ProductLabel::field('product_label_id,label_name,value') + ->whereIn('mer_id', $merIds) + ->where('status', 1) + ->where('is_del', 0) + ->select()->toArray(); + $labels = reset_index($labels, 'product_label_id'); + foreach ($list as &$item) { + $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'], ',')); + } + $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'] ?? ''; + } + } + } + return $list; + } + } diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index b2787d7a..c296eba3 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -12,6 +12,7 @@ namespace app\controller\api\store\product; use app\common\model\store\product\ProductLabel; use app\common\model\system\merchant\Merchant; +use app\common\repositories\store\product\ProductLabelRepository; use app\common\repositories\store\StoreCategoryRepository; use app\common\repositories\system\merchant\MerchantRepository; use app\common\repositories\user\UserHistoryRepository; @@ -86,7 +87,13 @@ class StoreSpu extends BaseController $where['order'] = $where['order'] ?: 'star'; if ($where['is_trader'] != 1) unset($where['is_trader']); $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); + $list = $labelRepo->appendLabel($merIds, $list); + return app('json')->success(['count' => $count, 'list' => $list]); } /**