|
@@ -14,6 +14,7 @@ use app\Request;
|
|
|
use app\services\pay\PayServices;
|
|
|
use app\services\other\ExpressServices;
|
|
|
use app\services\product\branch\StoreBranchProductServices;
|
|
|
+use app\services\user\AwardIntegralServices;
|
|
|
use app\services\user\UserAddressServices;
|
|
|
use app\services\user\UserInvoiceServices;
|
|
|
use app\services\user\UserServices;
|
|
@@ -197,7 +198,7 @@ class StoreOrderController
|
|
|
$uid = (int)$request->uid();
|
|
|
if ($checkOrder = $this->services->getOne(['unique' => $key, 'uid' => $uid, 'is_del' => 0], 'id,order_id'))
|
|
|
return app('json')->status('extend_order', '订单已创建,请点击查看完成支付', ['orderId' => $checkOrder['order_id'], 'key' => $key]);
|
|
|
- [$addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $collate_code_id, $bargainId, $newcomerId, $from, $shipping_type, $real_name, $phone, $storeId, $news, $invoice_id, $quitUrl, $discountId, $customForm] = $request->postMore([
|
|
|
+ [$addressId, $couponId, $payType, $useIntegral, $mark, $combinationId, $pinkId, $seckill_id, $collate_code_id, $bargainId, $newcomerId, $from, $shipping_type, $real_name, $phone, $storeId, $news, $invoice_id, $quitUrl, $discountId, $customForm, $yue_pay] = $request->postMore([
|
|
|
[['addressId', 'd'], 0],
|
|
|
[['couponId', 'd'], 0],
|
|
|
['payType', ''],
|
|
@@ -219,6 +220,7 @@ class StoreOrderController
|
|
|
['quitUrl', ''],
|
|
|
[['discountId', 'd'], 0],
|
|
|
['custom_form', []],
|
|
|
+ ['yue_pay', 0]
|
|
|
], true);
|
|
|
$cartGroup = $this->services->getCacheOrderInfo($uid, $key);
|
|
|
if (!$cartGroup) {
|
|
@@ -337,6 +339,9 @@ class StoreOrderController
|
|
|
switch ($payType) {
|
|
|
case PayServices::WEIXIN_PAY:
|
|
|
if ($orderInfo['paid']) return app('json')->fail('支付已支付!');
|
|
|
+ if ($orderInfo['award_price'] <= $yue_pay) {
|
|
|
+ return app('json')->fail('余额支付金额不能大于报单实际支付金额!');
|
|
|
+ }
|
|
|
//支付金额为0
|
|
|
if (bcsub((string)$orderInfo['pay_price'], '0', 2) <= 0) {
|
|
|
//创建订单jspay支付
|
|
@@ -353,7 +358,7 @@ class StoreOrderController
|
|
|
if (!$from && $request->isApp()) {
|
|
|
$from = 'weixin';
|
|
|
}
|
|
|
- $info['jsConfig'] = $payServices->orderPay($orderInfo, $from);
|
|
|
+ $info['jsConfig'] = $payServices->orderPay($orderInfo, $from, $yue_pay);
|
|
|
if ($from == 'weixinh5') {
|
|
|
return app('json')->status('wechat_h5_pay', '订单创建成功', $info);
|
|
|
} else {
|
|
@@ -362,6 +367,13 @@ class StoreOrderController
|
|
|
}
|
|
|
break;
|
|
|
case PayServices::YUE_PAY:
|
|
|
+ $total_price = $order['award_price'];
|
|
|
+ /** @var AwardIntegralServices $awardService */
|
|
|
+ $awardService = app()->make(AwardIntegralServices::class);
|
|
|
+ list($link_order, $reorder_count) = $awardService->checkReorder($uid, $total_price);
|
|
|
+ if ($link_order && $reorder_count >= 2) {
|
|
|
+ return app('json')->status('success', '复投建议使用其他支付或混合支付', ['link_id' => $link_order, 'reorder_count' => $reorder_count, 'order' => $info]);
|
|
|
+ }
|
|
|
/** @var YuePayServices $yueServices */
|
|
|
$yueServices = app()->make(YuePayServices::class);
|
|
|
$pay = $yueServices->yueOrderPay($orderInfo, $uid);
|
|
@@ -385,6 +397,9 @@ class StoreOrderController
|
|
|
} else {
|
|
|
$quitUrl = $url . '?order_id=' . $orderInfo['order_id'];
|
|
|
}
|
|
|
+ if ($orderInfo['award_price'] <= $yue_pay) {
|
|
|
+ return app('json')->fail('余额支付金额不能大于报单实际支付金额!');
|
|
|
+ }
|
|
|
//支付金额为0
|
|
|
if (bcsub((string)$orderInfo['pay_price'], '0', 2) <= 0) {
|
|
|
//创建订单jspay支付
|
|
@@ -398,7 +413,7 @@ class StoreOrderController
|
|
|
} else {
|
|
|
/** @var OrderPayServices $payServices */
|
|
|
$payServices = app()->make(OrderPayServices::class);
|
|
|
- $info['jsConfig'] = $payServices->alipayOrder($orderInfo, $quitUrl, $from == 'routine');
|
|
|
+ $info['jsConfig'] = $payServices->alipayOrder($orderInfo, $quitUrl, $from == 'routine', $yue_pay);
|
|
|
$payKey = md5($orderInfo['order_id']);
|
|
|
CacheService::set($payKey, ['order_id' => $orderInfo['order_id'], 'other_pay_type' => false], 300);
|
|
|
$info['pay_key'] = $payKey;
|
|
@@ -466,11 +481,12 @@ class StoreOrderController
|
|
|
*/
|
|
|
public function pay(Request $request, StorePinkServices $services, OrderPayServices $payServices, YuePayServices $yuePayServices)
|
|
|
{
|
|
|
- [$uni, $paytype, $from, $quitUrl] = $request->postMore([
|
|
|
+ [$uni, $paytype, $from, $quitUrl, $yue_pay] = $request->postMore([
|
|
|
['uni', ''],
|
|
|
['paytype', 'weixin'],
|
|
|
['from', 'weixin'],
|
|
|
- ['quitUrl', '']
|
|
|
+ ['quitUrl', ''],
|
|
|
+ ['yue_pay', 0]
|
|
|
], true);
|
|
|
if (!$uni) return app('json')->fail('参数错误!');
|
|
|
$order = $this->services->getUserOrderDetail($uni, (int)$request->uid());
|
|
@@ -524,7 +540,10 @@ class StoreOrderController
|
|
|
$order['pay_type'] = $paytype; //重新支付选择支付方式
|
|
|
switch ($order['pay_type']) {
|
|
|
case PayServices::WEIXIN_PAY:
|
|
|
- $jsConfig = $payServices->orderPay($order->toArray(), $from);
|
|
|
+ if ($order['award_price'] <= $yue_pay) {
|
|
|
+ return app('json')->fail('余额支付金额不能大于报单实际支付金额!');
|
|
|
+ }
|
|
|
+ $jsConfig = $payServices->orderPay($order->toArray(), $from, $yue_pay);
|
|
|
if ($from == 'weixinh5') {
|
|
|
return app('json')->status('wechat_h5_pay', ['jsConfig' => $jsConfig, 'order_id' => $order['order_id']]);
|
|
|
} elseif ($from == 'weixin' || $from == 'routine') {
|
|
@@ -537,8 +556,11 @@ class StoreOrderController
|
|
|
if (!$quitUrl && $from != 'routine') {
|
|
|
return app('json')->fail('请传入支付宝支付回调URL');
|
|
|
}
|
|
|
+ if ($order['award_price'] <= $yue_pay) {
|
|
|
+ return app('json')->fail('余额支付金额不能大于报单实际支付金额!');
|
|
|
+ }
|
|
|
$isCode = $from == 'routine' || $from == 'pc';
|
|
|
- $jsConfig = $payServices->alipayOrder($order->toArray(), $quitUrl, $isCode);
|
|
|
+ $jsConfig = $payServices->alipayOrder($order->toArray(), $quitUrl, $isCode, $yue_pay);
|
|
|
if ($isCode && !($jsConfig->invalid ?? false)) $jsConfig->invalid = time() + 60;
|
|
|
$payKey = md5($order['order_id']);
|
|
|
CacheService::set($payKey, ['order_id' => $order['order_id'], 'other_pay_type' => false], 300);
|
|
@@ -584,13 +606,13 @@ class StoreOrderController
|
|
|
if (!isset($orderCache['order_id'])) {
|
|
|
return app('json')->fail('该订单无法支付');
|
|
|
}
|
|
|
- $order_id = $orderCache['order_id'];
|
|
|
- if (strpos($orderCache['order_id'], '_')) {
|
|
|
- $orderArr = explode('_', $orderCache['order_id']);
|
|
|
- if (count($orderArr) == 2) {
|
|
|
- $order_id = $orderArr[1] ?? $order_id;
|
|
|
- }
|
|
|
- }
|
|
|
+ $order_id = $orderCache['order_id'];
|
|
|
+ if (strpos($orderCache['order_id'], '_')) {
|
|
|
+ $orderArr = explode('_', $orderCache['order_id']);
|
|
|
+ if (count($orderArr) == 2) {
|
|
|
+ $order_id = $orderArr[1] ?? $order_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
$payType = isset($orderCache['other_pay_type']) && $orderCache['other_pay_type'] == true;
|
|
|
if ($payType) {
|
|
|
$orderInfo = $services->getOne(['order_id' => $order_id, 'is_del' => 0, 'paid' => 0]);
|
|
@@ -779,19 +801,19 @@ class StoreOrderController
|
|
|
$orderData['write_day'] = ($start ? date('Y-m-d', $start) : '') . '/' . ($end ? date('Y-m-d', $end) : '');
|
|
|
}
|
|
|
}
|
|
|
- // 判断是否开启小程序订单管理
|
|
|
- $orderData['order_shipping_open'] = false;
|
|
|
- if (sys_config('order_shipping_open', 0) && MiniProgram::isManaged() && $order['is_channel'] == 1 && $order['pay_type'] == 'weixin') {
|
|
|
- // 判断是否存在子未收货子订单
|
|
|
- if ($order['pid'] > 0) {
|
|
|
- if ($this->services->checkSubOrderNotTake((int)$order['pid'], (int)$order['id'])) {
|
|
|
- $orderData['order_shipping_open'] = true;
|
|
|
- }
|
|
|
- } else {
|
|
|
- $orderData['order_shipping_open'] = true;
|
|
|
- }
|
|
|
+ // 判断是否开启小程序订单管理
|
|
|
+ $orderData['order_shipping_open'] = false;
|
|
|
+ if (sys_config('order_shipping_open', 0) && MiniProgram::isManaged() && $order['is_channel'] == 1 && $order['pay_type'] == 'weixin') {
|
|
|
+ // 判断是否存在子未收货子订单
|
|
|
+ if ($order['pid'] > 0) {
|
|
|
+ if ($this->services->checkSubOrderNotTake((int)$order['pid'], (int)$order['id'])) {
|
|
|
+ $orderData['order_shipping_open'] = true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $orderData['order_shipping_open'] = true;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
return app('json')->successful('ok', $orderData);
|
|
|
}
|
|
|
|
|
@@ -1265,7 +1287,7 @@ class StoreOrderController
|
|
|
{
|
|
|
if (!$id) return app('json')->fail('参数错误');
|
|
|
$uid = $request->uid();
|
|
|
- return app('json')->successful($services->userOrderWriteOffRecords(['oid'=>$id, 'uid'=>$uid]));
|
|
|
+ return app('json')->successful($services->userOrderWriteOffRecords(['oid' => $id, 'uid' => $uid]));
|
|
|
}
|
|
|
|
|
|
}
|