diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 29d838f8..24f54394 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -53,11 +53,11 @@ class StoreOrderCreateRepository extends StoreOrderRepository //检查购物车失效数据 if (count($fail)) { if ($fail[0]['is_fail']) - throw new ValidateException('[已失效]' . mb_substr($fail[0]['product']['store_name'],0,10).'...'); + throw new ValidateException('[已失效]' . mb_substr($fail[0]['product']['store_name'], 0, 10) . '...'); if (in_array($fail[0]['product_type'], [1, 2, 3]) && !$fail[0]['userPayCount']) { - throw new ValidateException('[超出限购数]' . mb_substr($fail[0]['product']['store_name'],0,10).'...'); + throw new ValidateException('[超出限购数]' . mb_substr($fail[0]['product']['store_name'], 0, 10) . '...'); } - throw new ValidateException('[已失效]' . mb_substr($fail[0]['product']['store_name'],0,10).'...'); + throw new ValidateException('[已失效]' . mb_substr($fail[0]['product']['store_name'], 0, 10) . '...'); } $svip_status = $user->is_svip > 0 && systemConfig('svip_switch_status') == '1'; @@ -72,30 +72,30 @@ class StoreOrderCreateRepository extends StoreOrderRepository //检查商品类型, 活动商品只能单独购买 foreach ($merchantCartList as $merchantCart) { - if(($merchantCart['type_id']!=Merchant::TypeSupplyChain)&&$address){ - if($merchantCart['street_id']!=$address['street_code']){ + if (($merchantCart['type_id'] != Merchant::TypeSupplyChain) && $address) { + if ($merchantCart['street_id'] != $address['street_code']) { throw new ValidateException('不支持跨区域购买,请在【我的】-【地址管理】更改后重新购买'); } } foreach ($merchantCart['list'] as $cart) { - if ($cart['product_type']==0) { + if ($cart['product_type'] == 0) { if ($cart['product']['once_min_count'] > 0 && $cart['product']['once_min_count'] > $cart['cart_num']) - throw new ValidateException('[低于起购数:'.$cart['product']['once_min_count'].']'.mb_substr($cart['product']['store_name'],0,10).'...'); + throw new ValidateException('[低于起购数:' . $cart['product']['once_min_count'] . ']' . mb_substr($cart['product']['store_name'], 0, 10) . '...'); if ($cart['product']['pay_limit'] == 1 && $cart['product']['once_max_count'] < $cart['cart_num']) - throw new ValidateException('[超出单次限购数:'.$cart['product']['once_max_count'].']'.mb_substr($cart['product']['store_name'],0,10).'...'); - if ($cart['product']['pay_limit'] == 2){ + throw new ValidateException('[超出单次限购数:' . $cart['product']['once_max_count'] . ']' . mb_substr($cart['product']['store_name'], 0, 10) . '...'); + if ($cart['product']['pay_limit'] == 2) { //如果长期限购 //已购买数量 - $count = app()->make(StoreOrderRepository::class)->getMaxCountNumber($cart['uid'],$cart['product_id']); + $count = app()->make(StoreOrderRepository::class)->getMaxCountNumber($cart['uid'], $cart['product_id']); if (($cart['cart_num'] + $count) > $cart['product']['once_max_count']) - throw new ValidateException('[超出限购总数:'. $cart['product']['once_max_count'].']'.mb_substr($cart['product']['store_name'],0,10).'...'); + throw new ValidateException('[超出限购总数:' . $cart['product']['once_max_count'] . ']' . mb_substr($cart['product']['store_name'], 0, 10) . '...'); } } - if ($cart['product_type'] > 0){ + if ($cart['product_type'] > 0) { $order_type = $cart['product_type']; } $source = $cart['source']; - if ($cart['product_type']<=97 &&$cart['product_type'] > 0 && (($cart['product_type'] != 10 && count($merchantCart['list']) != 1) || count($merchantCartList) != 1)) { + if ($cart['product_type'] <= 97 && $cart['product_type'] > 0 && (($cart['product_type'] != 10 && count($merchantCart['list']) != 1) || count($merchantCartList) != 1)) { throw new ValidateException('活动商品必须单独购买'); } if ($cart['product']['type'] && (count($merchantCart['list']) != 1 || count($merchantCartList) != 1)) { @@ -106,7 +106,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $order_extend = json_decode($cart['product']['extend'], true); } if ($address) { - if ($cart['source']== 0) { + if ($cart['source'] == 0) { $userAddressCode = ($address['province_code'] ?? '') . ',' . ($address['city_code'] ?? '') . ',' . ($address['district_code'] ?? '') . ',' . ($address['street_code'] ?? '') . ',' . ($address['village_code'] ?? '') . ',' . ($address['brigade_id'] ?? 0); $getUrl = env('LOGISTICS_HOST_URL') . '/api/hasCourier?user_address_code=' . $userAddressCode; $client = new \GuzzleHttp\Client(); @@ -161,9 +161,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository //是否自提 $isTake = in_array($merchantCart['mer_id'], $takes ?? []); -// if (!$createOrder && !$isTake) { -// $isTake = count($merchantCart['delivery_way']) == 1 && $merchantCart['delivery_way'][0] == '1'; -// } + // if (!$createOrder && !$isTake) { + // $isTake = count($merchantCart['delivery_way']) == 1 && $merchantCart['delivery_way'][0] == '1'; + // } $merTake = in_array('1', $merchantCart['delivery_way'], true); $merDelivery = (!$merchantCart['delivery_way'] || !count($merchantCart['delivery_way']) || in_array('2', $merchantCart['delivery_way'], true)); @@ -172,7 +172,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $deliveryStatus = true; if ($createOrder && $isTake && !$merTake) { $deliveryStatus = false; -// throw new ValidateException('[仅支持快递配送]' . $merchantCart['mer_name']); + // throw new ValidateException('[仅支持快递配送]' . $merchantCart['mer_name']); } $product_cart = []; @@ -192,12 +192,12 @@ class StoreOrderCreateRepository extends StoreOrderRepository } if ($createOrder && $isTake && !$merTake) { $deliveryStatus = false; -// throw new ValidateException('[仅支持快递配送]' . $cart['product']['store_name']); + // throw new ValidateException('[仅支持快递配送]' . $cart['product']['store_name']); } } if (!$merDelivery && !$merTake) { $deliveryStatus = false; -// throw new ValidateException('部分商品配送方式不一致,请单独下单'); + // throw new ValidateException('部分商品配送方式不一致,请单独下单'); } if ($deliveryStatus && !$isTake && ($merDelivery || $merTake)) { $isTake = $merDelivery ? 0 : 1; @@ -225,9 +225,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository } $svip_discount = 0; $realPrice = $this->cartByPrice($cart); - $procure = $this->cartByPrice($cart,1); - if (in_array($source,[9,10,11,12,13])) { - if($realPrice==0){ + if (in_array($source, [9, 10, 11, 12, 13])) { + if ($realPrice == 0) { throw new ValidateException('价格必须大于0'); } $cart['product']['price'] = $realPrice; @@ -235,8 +234,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository $cart['productAttr']['stock'] = $cart['cart_num']; } $price = bcmul($cart['cart_num'], $realPrice, 2); - $procure_price = bcmul($cart['cart_num'], $procure, 2); - $cart['procure_price'] = $procure_price; $cart['total_price'] = $price; $cart['postage_price'] = 0; $cart['svip_discount'] = 0; @@ -376,7 +373,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $merCouponIds = (array)($useCoupon[$merchantCart['mer_id']] ?? []); $merCouponIds = array_reverse($merCouponIds); $sortIds = $merCouponIds; -// $all_coupon_product = []; + // $all_coupon_product = []; unset($defaultSort); $defaultSort = []; if (count($merCouponIds)) { @@ -394,7 +391,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $pay_price = max(bcsub($valid_total_price, $coupon_price, 2), 0); $_pay_price = $pay_price; - + $productCouponRate = []; $storeCouponRate = null; @@ -419,9 +416,11 @@ class StoreOrderCreateRepository extends StoreOrderRepository $cart['coupon_price'] = bcsub($_cartTotalPrice, $cartTotalPrice, 2); $cart['true_price'] = $cartTotalPrice; } + $procure = $this->cartByPrice($cart, 1); + $procure_price = bcmul($cart['cart_num'], $procure, 2); unset($cart, $_k); $total_true_price = bcadd($_pay_price, $total_true_price, 2); - if(count($merchantCartList) > 1 || count($merchantCart['list']) > 1){ + if (count($merchantCartList) > 1 || count($merchantCart['list']) > 1) { $orderDeliveryStatus = $orderDeliveryStatus && $deliveryStatus; } $merchantCart['order'] = [ @@ -444,6 +443,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository 'delivery_status' => $deliveryStatus, 'svip_discount' => $total_svip_discount, 'use_svip' => $use_svip, + 'procure_price' => $procure_price ]; $order_total_postage = bcadd($order_total_postage, $postage_price, 2); $order_svip_discount = bcadd($total_svip_discount, $order_svip_discount, 2); @@ -546,6 +546,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository $merchantCart['order']['org_price'] = $org_price; $merchantCart['order']['pay_price'] = $pay_price; $merchantCart['order']['coupon_price'] = $coupon_price; + $merchantCart['order']['postage_price'] = $merchantCart['order']['postage_price']; + $merchantCart['order']['procure_price'] = $merchantCart['order']['procure_price']; $order_price = bcadd($order_price, $pay_price, 2); $order_total_price = bcadd($order_total_price, $total_price, 2); @@ -571,34 +573,34 @@ class StoreOrderCreateRepository extends StoreOrderRepository $openIntegral = $merIntegralFlag && !$order_type && $sysIntegralConfig['integral_status'] && $sysIntegralConfig['integral_money'] > 0; $total_coupon = bcadd($order_svip_discount, bcadd(bcadd($total_platform_coupon_price, $order_coupon_price, 2), $order_total_integral_price, 2), 2); return compact( - 'order_type', - 'source', - 'order_model', - 'order_extend', - 'order_total_postage', - 'order_price', - 'total_price', - 'community', - 'enabledPlatformCoupon', - 'platformCoupon', - 'usePlatformCouponId', - 'order_total_integral', - 'order_total_integral_price', - 'order_total_give_integral', - 'order_svip_discount', - 'total_platform_coupon_price', - 'total_coupon', - 'order_coupon_price', - 'order', - 'status', - 'address', - 'openIntegral', - 'useIntegral', - 'key' - ) + ['allow_address' => !$allow_no_address, 'order_delivery_status' => $orderDeliveryStatus]; + 'order_type', + 'source', + 'order_model', + 'order_extend', + 'order_total_postage', + 'order_price', + 'total_price', + 'community', + 'enabledPlatformCoupon', + 'platformCoupon', + 'usePlatformCouponId', + 'order_total_integral', + 'order_total_integral_price', + 'order_total_give_integral', + 'order_svip_discount', + 'total_platform_coupon_price', + 'total_coupon', + 'order_coupon_price', + 'order', + 'status', + 'address', + 'openIntegral', + 'useIntegral', + 'key' + ) + ['allow_address' => !$allow_no_address, 'order_delivery_status' => $orderDeliveryStatus]; } - public function v2CreateOrder(int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, array $post,int $product_type=0) + public function v2CreateOrder(int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, array $post, int $product_type = 0) { $uid = $user->uid; $orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true); @@ -770,7 +772,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $_order = [ 'cartInfo' => $merchantCart, 'activity_type' => $orderInfo['order_type'], - 'source' => $orderInfo['source']??2, + 'source' => $orderInfo['source'] ?? 2, 'commission_rate' => (float)$rate, 'order_type' => $merchantCart['order']['isTake'] ? 1 : 0, 'is_virtual' => $order_model ? 1 : 0, @@ -802,7 +804,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository 'mark' => $mark[$merchantCart['mer_id']] ?? '', 'coupon_price' => bcadd($merchantCart['order']['coupon_price'], $merchantCart['order']['platform_coupon_price'], 2), 'platform_coupon_price' => $merchantCart['order']['platform_coupon_price'], - 'pay_type' => $pay_type + 'pay_type' => $pay_type, + 'procure_price' => $merchantCart['order']['procure_price'], ]; $allUseCoupon = array_merge($allUseCoupon, $merchantCart['order']['useCouponIds']); $orderList[] = $_order; diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index bf93bd97..bf44c42d 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -311,29 +311,38 @@ class StoreOrderRepository extends BaseRepository 'financial_record_sn' => $financeSn . ($i++) ]; - $_payPrice = bcsub($order->pay_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2); - if ($presell) { - if (isset($order->orderProduct[0]['cart_info']['presell_extension_one']) && $order->orderProduct[0]['cart_info']['presell_extension_one'] > 0) { - $_payPrice = bcadd($_payPrice, $order->orderProduct[0]['cart_info']['presell_extension_one'], 2); - } - if (isset($order->orderProduct[0]['cart_info']['presell_extension_two']) && $order->orderProduct[0]['cart_info']['presell_extension_two'] > 0) { - $_payPrice = bcadd($_payPrice, $order->orderProduct[0]['cart_info']['presell_extension_two'], 2); + if($order->source==103){ + $_payPrice = $order->procure_price; + //计算手续费 + $_order_rate=bcsub($order->pay_price,$_payPrice,2); + }else{ + $_payPrice = $order->pay_price; + $_order_rate = 0; + + //平台手续费 + if ($order['commission_rate'] > 0) { + + $commission_rate = ($order['commission_rate'] / 100); + + $_order_rate = bcmul($_payPrice, $commission_rate, 2); + + $_payPrice = bcsub($_payPrice, $_order_rate, 2); + // 结算各镇 小组佣金 + // event('order.paySuccessOrder', compact('order', '_order_rate')); } } + + // bcsub($order->pay_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2); + // if ($presell) { + // if (isset($order->orderProduct[0]['cart_info']['presell_extension_one']) && $order->orderProduct[0]['cart_info']['presell_extension_one'] > 0) { + // $_payPrice = bcadd($_payPrice, $order->orderProduct[0]['cart_info']['presell_extension_one'], 2); + // } + // if (isset($order->orderProduct[0]['cart_info']['presell_extension_two']) && $order->orderProduct[0]['cart_info']['presell_extension_two'] > 0) { + // $_payPrice = bcadd($_payPrice, $order->orderProduct[0]['cart_info']['presell_extension_two'], 2); + // } + // } - $_order_rate = 0; - //平台手续费 - if ($order['commission_rate'] > 0) { - - $commission_rate = ($order['commission_rate'] / 100); - - $_order_rate = bcmul($_payPrice, $commission_rate, 2); - - $_payPrice = bcsub($_payPrice, $_order_rate, 2); - // 结算各镇 小组佣金 - event('order.paySuccessOrder', compact('order', '_order_rate')); - } if (!$presell) { if ($order['commission_rate'] > 0) { @@ -371,21 +380,21 @@ class StoreOrderRepository extends BaseRepository 'financial_record_sn' => $financeSn . ($i++) ]; - if ($order->platform_coupon_price > 0) { - $finance[] = [ - 'order_id' => $order->order_id, - 'order_sn' => $order->order_sn, - 'user_info' => $groupOrder->user->nickname, - 'user_id' => $uid, - 'financial_type' => $isVipCoupon ? 'order_svip_coupon' : 'order_platform_coupon', - 'financial_pm' => 0, - 'type' => 1, - 'number' => $order->platform_coupon_price, - 'mer_id' => $order->mer_id, - 'financial_record_sn' => $financeSn . ($i++) - ]; - $_payPrice = bcadd($_payPrice, $order->platform_coupon_price, 2); - } + // if ($order->platform_coupon_price > 0) { + // $finance[] = [ + // 'order_id' => $order->order_id, + // 'order_sn' => $order->order_sn, + // 'user_info' => $groupOrder->user->nickname, + // 'user_id' => $uid, + // 'financial_type' => $isVipCoupon ? 'order_svip_coupon' : 'order_platform_coupon', + // 'financial_pm' => 0, + // 'type' => 1, + // 'number' => $order->platform_coupon_price, + // 'mer_id' => $order->mer_id, + // 'financial_record_sn' => $financeSn . ($i++) + // ]; + // $_payPrice = bcadd($_payPrice, $order->platform_coupon_price, 2); + // } if (!$is_combine) { app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $_payPrice); } @@ -576,7 +585,11 @@ class StoreOrderRepository extends BaseRepository return $cart['productAttr']['price']; } } else { - return $cart['productAttr']['price']; + if($type==0){ + return $cart['productAttr']['price']; + }else{ + return $cart['productAttr']['procure_price']; + } } }