|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Service;
|
|
|
|
namespace App\Service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use App\Exception\BasicException;
|
|
|
|
use App\Exception\BusinessException;
|
|
|
|
use App\Exception\BusinessException;
|
|
|
|
use App\Helper\Baofu\Baofu;
|
|
|
|
use App\Helper\Baofu\Baofu;
|
|
|
|
use App\Helper\Efps\Api;
|
|
|
|
use App\Helper\Efps\Api;
|
|
|
@ -13,6 +14,7 @@ use App\Helper\StringHelper;
|
|
|
|
use App\Model\App;
|
|
|
|
use App\Model\App;
|
|
|
|
use App\Model\BankCard;
|
|
|
|
use App\Model\BankCard;
|
|
|
|
use App\Model\Order;
|
|
|
|
use App\Model\Order;
|
|
|
|
|
|
|
|
use App\Model\OrderSplitInfo;
|
|
|
|
use App\Model\PrePayLog;
|
|
|
|
use App\Model\PrePayLog;
|
|
|
|
use App\Model\RefundOrder;
|
|
|
|
use App\Model\RefundOrder;
|
|
|
|
use App\Model\User;
|
|
|
|
use App\Model\User;
|
|
|
@ -25,6 +27,7 @@ use App\Request\ProtocolPayPreRequest;
|
|
|
|
use App\Request\RefundQueryRequest;
|
|
|
|
use App\Request\RefundQueryRequest;
|
|
|
|
use App\Request\RefundRequest;
|
|
|
|
use App\Request\RefundRequest;
|
|
|
|
use App\Request\UnBindCardRequest;
|
|
|
|
use App\Request\UnBindCardRequest;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
|
|
|
|
class PaymentService extends AbstractService
|
|
|
|
class PaymentService extends AbstractService
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -44,28 +47,127 @@ class PaymentService extends AbstractService
|
|
|
|
if ($user) {
|
|
|
|
if ($user) {
|
|
|
|
throw new BusinessException('用户已存在');
|
|
|
|
throw new BusinessException('用户已存在');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$order = Order::where('app_id', $app->app_id)->where('out_order_no', $reqData['outOrderNo'])->first();
|
|
|
|
|
|
|
|
if ($order) {
|
|
|
|
|
|
|
|
throw new BusinessException('订单号重复');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[$order, $orderSplitInfos] = $this->createOrder($app, $reqData, $user);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$splitInfoList = [];
|
|
|
|
|
|
|
|
foreach ($orderSplitInfos as $splitInfo) {
|
|
|
|
|
|
|
|
$splitInfoList[] = [
|
|
|
|
|
|
|
|
'subOutOrderNo' => $splitInfo['sub_order_no'],
|
|
|
|
|
|
|
|
'contractNo' => $splitInfo['contract_no'],
|
|
|
|
|
|
|
|
'customerType' => $splitInfo['split_user_type'],
|
|
|
|
|
|
|
|
'splitAmount' => $splitInfo['split_amount'],
|
|
|
|
|
|
|
|
'sellerFlag' => $splitInfo['seller_flag'],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$baofu = new Baofu();
|
|
|
|
$baofu = new Baofu();
|
|
|
|
$baofu->paymentSplit([
|
|
|
|
try {
|
|
|
|
|
|
|
|
$url = $baofu->paymentSplit([
|
|
|
|
'loginNo' => $user->member_id,
|
|
|
|
'loginNo' => $user->member_id,
|
|
|
|
'outOrderNo' => '',
|
|
|
|
'outOrderNo' => $order->order_no,
|
|
|
|
'amount' => $user->member_id,
|
|
|
|
'amount' => $user->member_id,
|
|
|
|
'paidType' => 'CARD',
|
|
|
|
'paidType' => 'CARD',
|
|
|
|
'agreementNo' => $reqData[''],
|
|
|
|
'agreementNo' => $order->agreement_no,
|
|
|
|
'pwdPayExpTime' => $reqData[''],
|
|
|
|
'pwdPayExpTime' => $order->getExpiresIn(),
|
|
|
|
|
|
|
|
'splitInfoList' => $splitInfoList,
|
|
|
|
'notifyUrl' => '',
|
|
|
|
'notifyUrl' => '',
|
|
|
|
], $token);
|
|
|
|
], $token);
|
|
|
|
|
|
|
|
$order->status = 'APPLY_SUCCESS';
|
|
|
|
|
|
|
|
$order->applied_at = date('Y-m-d H:i:s');
|
|
|
|
|
|
|
|
$order->pay_url = $url;
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
|
|
|
|
} catch (BasicException $e) {
|
|
|
|
|
|
|
|
$order->status = 'APPLY_FAILED';
|
|
|
|
|
|
|
|
$order->applied_at = date('Y-m-d H:i:s');
|
|
|
|
|
|
|
|
$order->error_code = $e->getCode();
|
|
|
|
|
|
|
|
$order->error_message = $e->getMessage();
|
|
|
|
|
|
|
|
$order->save();
|
|
|
|
|
|
|
|
throw $e;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function createOrder(App $app, array $params, $user) {
|
|
|
|
public function createOrder(App $app, array $params, User $user) {
|
|
|
|
|
|
|
|
$expiresIn = $params['expiresIn'] ?: 15 * 60;
|
|
|
|
$order = new Order();
|
|
|
|
$order = new Order();
|
|
|
|
$order->app_id = $app->app_id;
|
|
|
|
$order->app_id = $app->app_id;
|
|
|
|
|
|
|
|
$order->user_id = $user->user_id;
|
|
|
|
$order->member_id = $user->member_id;
|
|
|
|
$order->member_id = $user->member_id;
|
|
|
|
$order->out_member_id = $params['outMemberId'] ?? '';
|
|
|
|
$order->order_no = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_PAY);
|
|
|
|
$order->out_order_no = $params['outOrderNo'] ?? '';
|
|
|
|
$order->out_order_no = $params['outOrderNo'];
|
|
|
|
$order->amount = $params['payAmount'] ?? 0;
|
|
|
|
$order->amount = $params['amount'];
|
|
|
|
$order->notify_url = $params['notifyUrl'] ?? '';
|
|
|
|
$order->notify_url = $params['notifyUrl'];
|
|
|
|
$order->order_info = json_encode($params['orderInfo'] ?? [], JSON_UNESCAPED_UNICODE);
|
|
|
|
$order->return_url = $params['returnUrl'];
|
|
|
|
|
|
|
|
$order->agreement_no = $params['agreementNo'] ?: '';
|
|
|
|
|
|
|
|
$order->status = 'PREPARE';
|
|
|
|
|
|
|
|
$order->pay_channel = 'BAOFU';
|
|
|
|
|
|
|
|
$order->pay_method = 'paymentSplit';
|
|
|
|
|
|
|
|
$order->pay_type = 'CARD';
|
|
|
|
|
|
|
|
$order->expired_at = date('Y-m-d H:i:s', $expiresIn);
|
|
|
|
|
|
|
|
$order->save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$fee = floor($order->amount * 0.007);
|
|
|
|
|
|
|
|
$orderSplitInfos = [];
|
|
|
|
|
|
|
|
$splitUserIds = array_column($params['splitInfoList'], 'userId');
|
|
|
|
|
|
|
|
$users = User::where('app_id', $app->app_id)->whereIn('user_id', $splitUserIds)->get()->keyBy('user_id');
|
|
|
|
|
|
|
|
$platformAccount = User::getPlatformAccount();
|
|
|
|
|
|
|
|
foreach ($params['splitInfoList'] as $splitInfo) {
|
|
|
|
|
|
|
|
$splitUser = $users[$splitInfo['userId']];
|
|
|
|
|
|
|
|
$splitAmount = $splitInfo['sellerFlag'] == 1 ? ($splitInfo['amount'] - $fee): $splitInfo['amount'];
|
|
|
|
|
|
|
|
$orderSplitInfos[] = [
|
|
|
|
|
|
|
|
'app_id' => $app->app_id,
|
|
|
|
|
|
|
|
'user_id' => $user->user_id,
|
|
|
|
|
|
|
|
'member_id' => $user->member_id,
|
|
|
|
|
|
|
|
'split_member_id' => $splitUser->member_id,
|
|
|
|
|
|
|
|
'split_user_id' => $splitInfo['userId'],
|
|
|
|
|
|
|
|
'split_user_type' => $splitUser->user_type,
|
|
|
|
|
|
|
|
'order_no' => $order->order_no,
|
|
|
|
|
|
|
|
'out_order_no' => $order->out_order_no,
|
|
|
|
|
|
|
|
'sub_order_no' => StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_PAY_SPLIT),
|
|
|
|
|
|
|
|
'sub_out_order_no' => $splitInfo['subOutOrderNo'],
|
|
|
|
|
|
|
|
'split_amount' => $splitAmount,
|
|
|
|
|
|
|
|
'contract_no' => $splitUser->contract_no,
|
|
|
|
|
|
|
|
'seller_flag' => $splitInfo['sellerFlag'],
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($fee) {
|
|
|
|
|
|
|
|
$feeSubOrderNo = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_PAY_SPLIT);
|
|
|
|
|
|
|
|
$orderSplitInfos[] = [
|
|
|
|
|
|
|
|
'app_id' => $app->app_id,
|
|
|
|
|
|
|
|
'user_id' => $user->user_id,
|
|
|
|
|
|
|
|
'member_id' => $user->member_id,
|
|
|
|
|
|
|
|
'split_member_id' => $platformAccount->member_id,
|
|
|
|
|
|
|
|
'split_user_id' => $platformAccount->user_id,
|
|
|
|
|
|
|
|
'split_user_type' => $platformAccount->user_type,
|
|
|
|
|
|
|
|
'order_no' => $order->order_no,
|
|
|
|
|
|
|
|
'out_order_no' => $order->out_order_no,
|
|
|
|
|
|
|
|
'sub_order_no' => $feeSubOrderNo,
|
|
|
|
|
|
|
|
'sub_out_order_no' => $feeSubOrderNo,
|
|
|
|
|
|
|
|
'split_amount' => $fee,
|
|
|
|
|
|
|
|
'contract_no' => $platformAccount->contract_no,
|
|
|
|
|
|
|
|
'seller_flag' => 0,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OrderSplitInfo::insert($orderSplitInfos);
|
|
|
|
|
|
|
|
return [$order, $orderSplitInfos];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function updateOrder($params) {
|
|
|
|
|
|
|
|
$order = Order::where('order_no', $params['order_no'])->where('status', 'APPLY_FAILED')->first();
|
|
|
|
|
|
|
|
if (empty($order)) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$order->third_order_no = $params['third_order_no'];
|
|
|
|
|
|
|
|
$order->status = $params['status'];
|
|
|
|
|
|
|
|
$order->finished_at = date('Y-m-d H:i:s', strtotime($params['finished_at']));
|
|
|
|
|
|
|
|
$order->error_message = $params['error_message'];
|
|
|
|
|
|
|
|
$order->transaction_id = $params['transaction_id'];
|
|
|
|
|
|
|
|
$order->out_transaction_id = $params['out_transaction_id'];
|
|
|
|
|
|
|
|
$order->save();
|
|
|
|
return $order;
|
|
|
|
return $order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|