|
|
|
@ -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.']'); |
|
|
|
|