From 413675eb24e9524c9d2d3e9ea652c69f9886126f Mon Sep 17 00:00:00 2001 From: weigang Date: Mon, 19 Oct 2020 14:55:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E6=88=B7=E4=B8=8D=E8=83=BD=E8=B4=AD?= =?UTF-8?q?=E4=B9=B0=E8=87=AA=E5=B7=B1=E5=B8=82=E5=9C=BA=E6=88=96=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E5=BA=97=E9=93=BA=E7=9A=84=E6=B4=BB=E5=8A=A8=E5=95=86?= =?UTF-8?q?=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/Implementations/OrderOnlineService.php | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index 4b5748e..f73e17c 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -199,6 +199,13 @@ class OrderOnlineService implements OrderOnlineServiceInterface $activityGoodsIds = []; # 活动商品IDs $shopcartIds = []; + // 获取当前用户的商户信息,主要用于限制当前商户购买自己或本市场的活动商品 + $userStore = Store::query() + ->withoutGlobalScope('normal') + ->withTrashed() + ->where(['user_id' => $userId])->orWhere(['admin_id' => $userId]) + ->first(); + foreach ($storeList as $key => &$storeItem) { $storeId = $storeItem->store_id; @@ -206,14 +213,15 @@ class OrderOnlineService implements OrderOnlineServiceInterface // 子订单金额 $subAmount = 0; - // 店铺分类 + // 店铺信息 $store = Store::query()->where(['id' => $storeId])->first(); // 禁止店铺自己下自己的单 - if (in_array($userId, [$store->user_id, $store->admin_id])) { - throw new ErrorCodeException(ErrorCode::ORDER_ONLINE_LIMIT_STORE_BUY_SELF, '', ['store' => json_encode($store), 'user_id' => $userId, 'store_item' => $storeItem]); - } + // if (in_array($userId, [$store->user_id, $store->admin_id])) { + // throw new ErrorCodeException(ErrorCode::ORDER_ONLINE_LIMIT_STORE_BUY_SELF, '', ['store' => json_encode($store), 'user_id' => $userId, 'store_item' => $storeItem]); + // } + // 店铺分类 $storeType = $store->category_id; $storeTypeIds[] = (string)$storeType; // 店铺今天的订单数 @@ -240,10 +248,25 @@ class OrderOnlineService implements OrderOnlineServiceInterface throw new ErrorCodeException($check, '['.$goods->name.']'); } } elseif ($cart->activity_type == 2) { + $goods = GoodsActivity::query()->lockForUpdate()->with('store')->find($cart->goods_id); if (empty($goods)) { throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_NOT_EXISTS, '['.$cart->goods_id.']'); } + + // 商户不能购买自己市场或自己店铺的活动商品 + if (!is_null($userStore)) { // 当前用户是商户 + if (in_array($userStore->market_id, json_decode($goods->market_ids, true)) || $userStore->id == $goods->store_id) { // 如果活动商品是当前市场或者自己店铺的,滚粗不让买 + throw new ErrorCodeException(ErrorCode::ORDER_ONLINE_LIMIT_STORE_BUY_SELF, '', [ + 'user_store' => json_encode($userStore), + 'store' => json_encode($store), + 'user_id' => $userId, + 'store_item' => $storeItem, + 'ac_goods' => json_encode($goods) + ]); + } + } + $check = $this->goodsActivityService->check($goods, $cart->num, $userId); if (true !== $check) { throw new ErrorCodeException($check, '['.$goods->name.']');