更新支付

This commit is contained in:
mkm 2024-01-06 09:37:36 +08:00
parent 9870729a88
commit d347c5b78f
2 changed files with 107 additions and 91 deletions

View File

@ -53,11 +53,11 @@ class StoreOrderCreateRepository extends StoreOrderRepository
//检查购物车失效数据 //检查购物车失效数据
if (count($fail)) { if (count($fail)) {
if ($fail[0]['is_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']) { 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'; $svip_status = $user->is_svip > 0 && systemConfig('svip_switch_status') == '1';
@ -72,30 +72,30 @@ class StoreOrderCreateRepository extends StoreOrderRepository
//检查商品类型, 活动商品只能单独购买 //检查商品类型, 活动商品只能单独购买
foreach ($merchantCartList as $merchantCart) { foreach ($merchantCartList as $merchantCart) {
if(($merchantCart['type_id']!=Merchant::TypeSupplyChain)&&$address){ if (($merchantCart['type_id'] != Merchant::TypeSupplyChain) && $address) {
if($merchantCart['street_id']!=$address['street_code']){ if ($merchantCart['street_id'] != $address['street_code']) {
throw new ValidateException('不支持跨区域购买,请在【我的】-【地址管理】更改后重新购买'); throw new ValidateException('不支持跨区域购买,请在【我的】-【地址管理】更改后重新购买');
} }
} }
foreach ($merchantCart['list'] as $cart) { 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']) 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']) 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).'...'); throw new ValidateException('[超出单次限购数:' . $cart['product']['once_max_count'] . ']' . mb_substr($cart['product']['store_name'], 0, 10) . '...');
if ($cart['product']['pay_limit'] == 2){ 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']) 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']; $order_type = $cart['product_type'];
} }
$source = $cart['source']; $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('活动商品必须单独购买'); throw new ValidateException('活动商品必须单独购买');
} }
if ($cart['product']['type'] && (count($merchantCart['list']) != 1 || count($merchantCartList) != 1)) { 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); $order_extend = json_decode($cart['product']['extend'], true);
} }
if ($address) { 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); $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; $getUrl = env('LOGISTICS_HOST_URL') . '/api/hasCourier?user_address_code=' . $userAddressCode;
$client = new \GuzzleHttp\Client(); $client = new \GuzzleHttp\Client();
@ -161,9 +161,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository
//是否自提 //是否自提
$isTake = in_array($merchantCart['mer_id'], $takes ?? []); $isTake = in_array($merchantCart['mer_id'], $takes ?? []);
// if (!$createOrder && !$isTake) { // if (!$createOrder && !$isTake) {
// $isTake = count($merchantCart['delivery_way']) == 1 && $merchantCart['delivery_way'][0] == '1'; // $isTake = count($merchantCart['delivery_way']) == 1 && $merchantCart['delivery_way'][0] == '1';
// } // }
$merTake = in_array('1', $merchantCart['delivery_way'], true); $merTake = in_array('1', $merchantCart['delivery_way'], true);
$merDelivery = (!$merchantCart['delivery_way'] || !count($merchantCart['delivery_way']) || in_array('2', $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; $deliveryStatus = true;
if ($createOrder && $isTake && !$merTake) { if ($createOrder && $isTake && !$merTake) {
$deliveryStatus = false; $deliveryStatus = false;
// throw new ValidateException('[仅支持快递配送]' . $merchantCart['mer_name']); // throw new ValidateException('[仅支持快递配送]' . $merchantCart['mer_name']);
} }
$product_cart = []; $product_cart = [];
@ -192,12 +192,12 @@ class StoreOrderCreateRepository extends StoreOrderRepository
} }
if ($createOrder && $isTake && !$merTake) { if ($createOrder && $isTake && !$merTake) {
$deliveryStatus = false; $deliveryStatus = false;
// throw new ValidateException('[仅支持快递配送]' . $cart['product']['store_name']); // throw new ValidateException('[仅支持快递配送]' . $cart['product']['store_name']);
} }
} }
if (!$merDelivery && !$merTake) { if (!$merDelivery && !$merTake) {
$deliveryStatus = false; $deliveryStatus = false;
// throw new ValidateException('部分商品配送方式不一致,请单独下单'); // throw new ValidateException('部分商品配送方式不一致,请单独下单');
} }
if ($deliveryStatus && !$isTake && ($merDelivery || $merTake)) { if ($deliveryStatus && !$isTake && ($merDelivery || $merTake)) {
$isTake = $merDelivery ? 0 : 1; $isTake = $merDelivery ? 0 : 1;
@ -225,9 +225,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
} }
$svip_discount = 0; $svip_discount = 0;
$realPrice = $this->cartByPrice($cart); $realPrice = $this->cartByPrice($cart);
$procure = $this->cartByPrice($cart,1); if (in_array($source, [9, 10, 11, 12, 13])) {
if (in_array($source,[9,10,11,12,13])) { if ($realPrice == 0) {
if($realPrice==0){
throw new ValidateException('价格必须大于0'); throw new ValidateException('价格必须大于0');
} }
$cart['product']['price'] = $realPrice; $cart['product']['price'] = $realPrice;
@ -235,8 +234,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$cart['productAttr']['stock'] = $cart['cart_num']; $cart['productAttr']['stock'] = $cart['cart_num'];
} }
$price = bcmul($cart['cart_num'], $realPrice, 2); $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['total_price'] = $price;
$cart['postage_price'] = 0; $cart['postage_price'] = 0;
$cart['svip_discount'] = 0; $cart['svip_discount'] = 0;
@ -376,7 +373,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$merCouponIds = (array)($useCoupon[$merchantCart['mer_id']] ?? []); $merCouponIds = (array)($useCoupon[$merchantCart['mer_id']] ?? []);
$merCouponIds = array_reverse($merCouponIds); $merCouponIds = array_reverse($merCouponIds);
$sortIds = $merCouponIds; $sortIds = $merCouponIds;
// $all_coupon_product = []; // $all_coupon_product = [];
unset($defaultSort); unset($defaultSort);
$defaultSort = []; $defaultSort = [];
if (count($merCouponIds)) { if (count($merCouponIds)) {
@ -419,9 +416,11 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$cart['coupon_price'] = bcsub($_cartTotalPrice, $cartTotalPrice, 2); $cart['coupon_price'] = bcsub($_cartTotalPrice, $cartTotalPrice, 2);
$cart['true_price'] = $cartTotalPrice; $cart['true_price'] = $cartTotalPrice;
} }
$procure = $this->cartByPrice($cart, 1);
$procure_price = bcmul($cart['cart_num'], $procure, 2);
unset($cart, $_k); unset($cart, $_k);
$total_true_price = bcadd($_pay_price, $total_true_price, 2); $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; $orderDeliveryStatus = $orderDeliveryStatus && $deliveryStatus;
} }
$merchantCart['order'] = [ $merchantCart['order'] = [
@ -444,6 +443,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
'delivery_status' => $deliveryStatus, 'delivery_status' => $deliveryStatus,
'svip_discount' => $total_svip_discount, 'svip_discount' => $total_svip_discount,
'use_svip' => $use_svip, 'use_svip' => $use_svip,
'procure_price' => $procure_price
]; ];
$order_total_postage = bcadd($order_total_postage, $postage_price, 2); $order_total_postage = bcadd($order_total_postage, $postage_price, 2);
$order_svip_discount = bcadd($total_svip_discount, $order_svip_discount, 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']['org_price'] = $org_price;
$merchantCart['order']['pay_price'] = $pay_price; $merchantCart['order']['pay_price'] = $pay_price;
$merchantCart['order']['coupon_price'] = $coupon_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_price = bcadd($order_price, $pay_price, 2);
$order_total_price = bcadd($order_total_price, $total_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; $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); $total_coupon = bcadd($order_svip_discount, bcadd(bcadd($total_platform_coupon_price, $order_coupon_price, 2), $order_total_integral_price, 2), 2);
return compact( return compact(
'order_type', 'order_type',
'source', 'source',
'order_model', 'order_model',
'order_extend', 'order_extend',
'order_total_postage', 'order_total_postage',
'order_price', 'order_price',
'total_price', 'total_price',
'community', 'community',
'enabledPlatformCoupon', 'enabledPlatformCoupon',
'platformCoupon', 'platformCoupon',
'usePlatformCouponId', 'usePlatformCouponId',
'order_total_integral', 'order_total_integral',
'order_total_integral_price', 'order_total_integral_price',
'order_total_give_integral', 'order_total_give_integral',
'order_svip_discount', 'order_svip_discount',
'total_platform_coupon_price', 'total_platform_coupon_price',
'total_coupon', 'total_coupon',
'order_coupon_price', 'order_coupon_price',
'order', 'order',
'status', 'status',
'address', 'address',
'openIntegral', 'openIntegral',
'useIntegral', 'useIntegral',
'key' 'key'
) + ['allow_address' => !$allow_no_address, 'order_delivery_status' => $orderDeliveryStatus]; ) + ['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; $uid = $user->uid;
$orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true); $orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true);
@ -770,7 +772,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$_order = [ $_order = [
'cartInfo' => $merchantCart, 'cartInfo' => $merchantCart,
'activity_type' => $orderInfo['order_type'], 'activity_type' => $orderInfo['order_type'],
'source' => $orderInfo['source']??2, 'source' => $orderInfo['source'] ?? 2,
'commission_rate' => (float)$rate, 'commission_rate' => (float)$rate,
'order_type' => $merchantCart['order']['isTake'] ? 1 : 0, 'order_type' => $merchantCart['order']['isTake'] ? 1 : 0,
'is_virtual' => $order_model ? 1 : 0, 'is_virtual' => $order_model ? 1 : 0,
@ -802,7 +804,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
'mark' => $mark[$merchantCart['mer_id']] ?? '', 'mark' => $mark[$merchantCart['mer_id']] ?? '',
'coupon_price' => bcadd($merchantCart['order']['coupon_price'], $merchantCart['order']['platform_coupon_price'], 2), 'coupon_price' => bcadd($merchantCart['order']['coupon_price'], $merchantCart['order']['platform_coupon_price'], 2),
'platform_coupon_price' => $merchantCart['order']['platform_coupon_price'], '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']); $allUseCoupon = array_merge($allUseCoupon, $merchantCart['order']['useCouponIds']);
$orderList[] = $_order; $orderList[] = $_order;

View File

@ -311,29 +311,38 @@ class StoreOrderRepository extends BaseRepository
'financial_record_sn' => $financeSn . ($i++) 'financial_record_sn' => $financeSn . ($i++)
]; ];
$_payPrice = bcsub($order->pay_price, bcadd($order['extension_one'], $order['extension_two'], 3), 2); if($order->source==103){
if ($presell) { $_payPrice = $order->procure_price;
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); $_order_rate=bcsub($order->pay_price,$_payPrice,2);
} }else{
if (isset($order->orderProduct[0]['cart_info']['presell_extension_two']) && $order->orderProduct[0]['cart_info']['presell_extension_two'] > 0) { $_payPrice = $order->pay_price;
$_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'));
} }
} }
$_order_rate = 0; // 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['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 (!$presell) {
if ($order['commission_rate'] > 0) { if ($order['commission_rate'] > 0) {
@ -371,21 +380,21 @@ class StoreOrderRepository extends BaseRepository
'financial_record_sn' => $financeSn . ($i++) 'financial_record_sn' => $financeSn . ($i++)
]; ];
if ($order->platform_coupon_price > 0) { // if ($order->platform_coupon_price > 0) {
$finance[] = [ // $finance[] = [
'order_id' => $order->order_id, // 'order_id' => $order->order_id,
'order_sn' => $order->order_sn, // 'order_sn' => $order->order_sn,
'user_info' => $groupOrder->user->nickname, // 'user_info' => $groupOrder->user->nickname,
'user_id' => $uid, // 'user_id' => $uid,
'financial_type' => $isVipCoupon ? 'order_svip_coupon' : 'order_platform_coupon', // 'financial_type' => $isVipCoupon ? 'order_svip_coupon' : 'order_platform_coupon',
'financial_pm' => 0, // 'financial_pm' => 0,
'type' => 1, // 'type' => 1,
'number' => $order->platform_coupon_price, // 'number' => $order->platform_coupon_price,
'mer_id' => $order->mer_id, // 'mer_id' => $order->mer_id,
'financial_record_sn' => $financeSn . ($i++) // 'financial_record_sn' => $financeSn . ($i++)
]; // ];
$_payPrice = bcadd($_payPrice, $order->platform_coupon_price, 2); // $_payPrice = bcadd($_payPrice, $order->platform_coupon_price, 2);
} // }
if (!$is_combine) { if (!$is_combine) {
app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $_payPrice); 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']; return $cart['productAttr']['price'];
} }
} else { } else {
return $cart['productAttr']['price']; if($type==0){
return $cart['productAttr']['price'];
}else{
return $cart['productAttr']['procure_price'];
}
} }
} }