From 56e0af48df72dbf11c7db8ef47bd8d8300b973c4 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 13 Mar 2024 17:06:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=95=86=E5=93=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/Enum.php | 10 ++++++++++ app/common/dao/store/product/SpuDao.php | 7 +++++++ .../store/order/StoreOrderCreateRepository.php | 4 ++++ .../repositories/store/product/ProductRepository.php | 5 ++++- .../system/merchant/MerchantCategoryRepository.php | 2 +- app/controller/api/store/product/StoreProduct.php | 1 + app/controller/api/store/product/StoreSpu.php | 5 +++-- 7 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/common/Enum.php b/app/common/Enum.php index a7e2fe25..ba300880 100644 --- a/app/common/Enum.php +++ b/app/common/Enum.php @@ -2,14 +2,24 @@ namespace app\common; +/** + * 枚举类 + */ class Enum { + /** 购物车、订单相关 */ const SALE_TYPE_RETAIL = 1; //零售类型 const SALE_TYPE_WHOLESALE = 2; //批发类型 + /** 通用状态 */ const STATUS_ENABLE = 1; //允许状态 const STATUS_DISABLE = 0; //禁用状态 + /** 店铺相关 */ + const RETAIL_ONLY = 0; //仅零售 + const WHOLESALE_ONLY = 1; //仅批发 + const RETAIL_WHOLESALE = 2; //零售和批发 + /** @const MAP */ const MAP = [ self::SALE_TYPE_RETAIL => '零售', self::SALE_TYPE_WHOLESALE => '批发', diff --git a/app/common/dao/store/product/SpuDao.php b/app/common/dao/store/product/SpuDao.php index 6167e979..84de165a 100644 --- a/app/common/dao/store/product/SpuDao.php +++ b/app/common/dao/store/product/SpuDao.php @@ -11,9 +11,11 @@ namespace app\common\dao\store\product; use app\common\dao\BaseDao; +use app\common\Enum; use app\common\model\store\product\ProductCate; use app\common\model\store\product\Spu; use app\common\model\store\StoreCategory; +use app\common\model\system\merchant\Merchant; use app\common\repositories\store\StoreCategoryRepository; use app\common\repositories\system\merchant\MerchantRepository; use crmeb\services\VicWordService; @@ -68,6 +70,11 @@ class SpuDao extends BaseDao ->when(isset($where['mer_ids']) && $where['mer_ids'] !== '',function($query)use($where){ $query->whereIn('P.mer_id',$where['mer_ids']); }) + ->when(isset($where['sale_type']) && $where['sale_type'] !== '',function($query)use($where){ + $saleType = $where['sale_type'] == Enum::SALE_TYPE_RETAIL ? [Enum::RETAIL_ONLY, Enum::RETAIL_WHOLESALE] : [Enum::WHOLESALE_ONLY]; + $merIds = Merchant::whereIn('wholesale', $saleType)->column('mer_id'); + $query->whereIn('P.mer_id', $merIds); + }) ->when(isset($where['product_ids']) && $where['product_ids'] !== '',function($query)use($where){ $query->whereIn('P.product_id',$where['product_ids']); }) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index a7e0edea..89705a45 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -133,6 +133,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository } foreach ($merchantCart['list'] as $k => $cart) { + if ($isWholeSale) { + $merchantCart['list'][$k]['productAttr']['price'] = $cart['productAttr']['wholesale_price']; + $merchantCart['list'][$k]['product']['price'] = $cart['productAttr']['wholesale_price']; + } //获取订单商品支持的配送类型 if ($cart['product']['delivery_way']) { $delivery_way = explode(',', $cart['product']['delivery_way']); diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index fa07030f..520634f8 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -12,6 +12,7 @@ namespace app\common\repositories\store\product; +use app\common\model\store\order\StoreOrder; use app\common\model\store\product\ProductLabel; use app\common\model\user\User; use app\common\repositories\community\CommunityRepository; @@ -61,6 +62,8 @@ class ProductRepository extends BaseRepository /** @var $isWholesale bool 是否批发 */ public $isWholesale = false; + /** @var $saleType int 售卖类型 */ + public $saleType; protected $dao; const CREATE_PARAMS = [ "is_copy", "image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "guarantee_template_id", "cate_id", "unit_name", "sort", "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free', 'param_temp_id', 'extend', 'mer_form_id', @@ -1379,7 +1382,7 @@ class ProductRepository extends BaseRepository ], $userInfo['uid'] ); - $this->isWholesale = $product->merchant->isWholesale() && $userInfo->getMerId() > 0; + $this->isWholesale = StoreOrder::isWholesale($product->merchant['wholesale'], $userInfo->getMerId(), $this->saleType); } if (systemConfig('sys_reply_status')) { diff --git a/app/common/repositories/system/merchant/MerchantCategoryRepository.php b/app/common/repositories/system/merchant/MerchantCategoryRepository.php index b45c8b4f..d07ffc72 100644 --- a/app/common/repositories/system/merchant/MerchantCategoryRepository.php +++ b/app/common/repositories/system/merchant/MerchantCategoryRepository.php @@ -114,7 +114,7 @@ class MerchantCategoryRepository extends BaseRepository */ public function getSelect() { - $query = $this->search([])->field('merchant_category_id,category_name'); + $query = $this->search([])->field('merchant_category_id,category_name,background'); $list = $query->select()->toArray(); return $list; } diff --git a/app/controller/api/store/product/StoreProduct.php b/app/controller/api/store/product/StoreProduct.php index eafa9039..373e8425 100644 --- a/app/controller/api/store/product/StoreProduct.php +++ b/app/controller/api/store/product/StoreProduct.php @@ -67,6 +67,7 @@ class StoreProduct extends BaseController */ public function detail($id) { + $this->repository->saleType = $this->request->get('sale_type', 1); $data = $this->repository->detail((int)$id, $this->userInfo); if (!$data) { app()->make(SpuRepository::class)->changeStatus($id, 0); diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index 10d932d6..d86d2f7a 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -61,7 +61,8 @@ class StoreSpu extends BaseController 'filter_params', 'mer_type_id', 'sys_labels', - 'deduction_rate' + 'deduction_rate', + 'sale_type', ]); $where['is_gift_bag'] = 0; $where['product_type'] = 0; @@ -101,7 +102,7 @@ class StoreSpu extends BaseController public function recommend() { [$page, $limit] = $this->getPage(); - $where = $this->request->params(['common','mer_id']); + $where = $this->request->params(['common', 'mer_id', 'sale_type']); $where['is_gift_bag'] = 0; //1:星级 //2:用户收藏