|
|
@ -43,7 +43,7 @@ class PaymentService extends AbstractService
|
|
|
|
return $this->paymentSplit($order, $user, $splitInfoList, $token);
|
|
|
|
return $this->paymentSplit($order, $user, $splitInfoList, $token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function transferPay()
|
|
|
|
public function transferPay(array $data, App $app, string $token)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
|
|
|
|
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
|
|
|
|
if (empty($user)) {
|
|
|
|
if (empty($user)) {
|
|
|
@ -58,7 +58,7 @@ class PaymentService extends AbstractService
|
|
|
|
|
|
|
|
|
|
|
|
$splitInfoList = $this->buildSplitInfoList($orderSplitInfos);
|
|
|
|
$splitInfoList = $this->buildSplitInfoList($orderSplitInfos);
|
|
|
|
|
|
|
|
|
|
|
|
return $this->paymentSplit($order, $user, $splitInfoList, $token);
|
|
|
|
return $this->transferSplitPay($order, $user, $splitInfoList, $token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function buildSplitInfoList($orderSplitInfos) {
|
|
|
|
private function buildSplitInfoList($orderSplitInfos) {
|
|
|
@ -110,10 +110,11 @@ class PaymentService extends AbstractService
|
|
|
|
$result = $baofu->transferSplitPay([
|
|
|
|
$result = $baofu->transferSplitPay([
|
|
|
|
'loginNo' => $user->member_id,
|
|
|
|
'loginNo' => $user->member_id,
|
|
|
|
'outOrderNo' => $order->order_no,
|
|
|
|
'outOrderNo' => $order->order_no,
|
|
|
|
|
|
|
|
'goodsName' => $order->goods_name,
|
|
|
|
'amount' => $order->amount,
|
|
|
|
'amount' => $order->amount,
|
|
|
|
'agreementNo' => $order->agreement_no,
|
|
|
|
'agreementNo' => $order->agreement_no,
|
|
|
|
'expireDate' => date('YmdHis', time() + $order->expires_in),
|
|
|
|
'expireDate' => date('YmdHis', time() + $order->expires_in),
|
|
|
|
'validDate' => $order->valid_date,
|
|
|
|
'validDate' => date('Ymd', strtotime($order->valid_date)),
|
|
|
|
'splitInfoList' => $splitInfoList,
|
|
|
|
'splitInfoList' => $splitInfoList,
|
|
|
|
'marketInfo' => $order->market_info,
|
|
|
|
'marketInfo' => $order->market_info,
|
|
|
|
], $token);
|
|
|
|
], $token);
|
|
|
@ -141,6 +142,7 @@ class PaymentService extends AbstractService
|
|
|
|
$order->order_no = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_PAY);
|
|
|
|
$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['amount'];
|
|
|
|
$order->amount = $params['amount'];
|
|
|
|
|
|
|
|
$order->goods_name = $params['goodsName'] ?? '';
|
|
|
|
$order->notify_url = $params['notifyUrl'];
|
|
|
|
$order->notify_url = $params['notifyUrl'];
|
|
|
|
$order->return_url = $params['returnUrl'] ?? '';
|
|
|
|
$order->return_url = $params['returnUrl'] ?? '';
|
|
|
|
$order->agreement_no = $params['agreementNo'] ?? '';
|
|
|
|
$order->agreement_no = $params['agreementNo'] ?? '';
|
|
|
@ -148,8 +150,8 @@ class PaymentService extends AbstractService
|
|
|
|
$order->pay_channel = 'BAOFU';
|
|
|
|
$order->pay_channel = 'BAOFU';
|
|
|
|
$order->pay_method = $payMethod;
|
|
|
|
$order->pay_method = $payMethod;
|
|
|
|
$order->pay_type = 'CARD';
|
|
|
|
$order->pay_type = 'CARD';
|
|
|
|
$order->valid_date = $params['valid_date'] ?? null;
|
|
|
|
$order->valid_date = $params['validDate'] ?? null;
|
|
|
|
$order->expires_in = $expiresIn,
|
|
|
|
$order->expires_in = $expiresIn;
|
|
|
|
$order->expired_at = date('Y-m-d H:i:s', time() + $expiresIn);
|
|
|
|
$order->expired_at = date('Y-m-d H:i:s', time() + $expiresIn);
|
|
|
|
$order->market_info = $params['marketInfo'] ?? [];
|
|
|
|
$order->market_info = $params['marketInfo'] ?? [];
|
|
|
|
$order->org_split_info_list = $params['splitInfoList'];
|
|
|
|
$order->org_split_info_list = $params['splitInfoList'];
|
|
|
@ -161,7 +163,10 @@ class PaymentService extends AbstractService
|
|
|
|
$splitUserIds = array_column($params['splitInfoList'], 'splitUserId');
|
|
|
|
$splitUserIds = array_column($params['splitInfoList'], 'splitUserId');
|
|
|
|
$users = User::where('app_id', $app->app_id)->whereIn('user_id', $splitUserIds)->get()->keyBy('user_id');
|
|
|
|
$users = User::where('app_id', $app->app_id)->whereIn('user_id', $splitUserIds)->get()->keyBy('user_id');
|
|
|
|
foreach ($params['splitInfoList'] as $splitInfo) {
|
|
|
|
foreach ($params['splitInfoList'] as $splitInfo) {
|
|
|
|
$splitUser = $users[$splitInfo['splitUserId']];
|
|
|
|
$splitUser = $users[$splitInfo['splitUserId']] ?? null;
|
|
|
|
|
|
|
|
if (empty($splitUser)) {
|
|
|
|
|
|
|
|
throw new BusinessException('分账用户不存在');
|
|
|
|
|
|
|
|
}
|
|
|
|
$splitAmount = $splitInfo['sellerFlag'] == 1 ? ($splitInfo['splitAmount'] - $fee): $splitInfo['splitAmount'];
|
|
|
|
$splitAmount = $splitInfo['sellerFlag'] == 1 ? ($splitInfo['splitAmount'] - $fee): $splitInfo['splitAmount'];
|
|
|
|
$orderSplitInfos[] = [
|
|
|
|
$orderSplitInfos[] = [
|
|
|
|
'app_id' => $app->app_id,
|
|
|
|
'app_id' => $app->app_id,
|
|
|
@ -367,4 +372,49 @@ class PaymentService extends AbstractService
|
|
|
|
$refund->save();
|
|
|
|
$refund->save();
|
|
|
|
return $refund;
|
|
|
|
return $refund;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function confirmPay(array $data, App $app, string $token)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
|
|
|
|
|
|
|
|
if (empty($user)) {
|
|
|
|
|
|
|
|
throw new BusinessException('用户不存在');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$order = Order::where('app_id', $app->app_id)->where('out_order_no', $data['outOrderNo'])->first();
|
|
|
|
|
|
|
|
if (empty($order)) {
|
|
|
|
|
|
|
|
throw new BusinessException('订单不存在');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($order->status != Order::STATUS_APPLY_SUCCESS) {
|
|
|
|
|
|
|
|
throw new BusinessException('订单状态异常');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$confirmSplitInfoList = [];
|
|
|
|
|
|
|
|
foreach ($order->orderSplitInfos as $orderSplitInfo) {
|
|
|
|
|
|
|
|
$confirmSplitInfoList[] = [
|
|
|
|
|
|
|
|
'oldSubOutOrderNo' => $orderSplitInfo->sub_order_no,
|
|
|
|
|
|
|
|
'splitAmount' => $orderSplitInfo->split_amount,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
$baofu = new Baofu();
|
|
|
|
|
|
|
|
$result = $baofu->confirmAssurePortfolioPay([
|
|
|
|
|
|
|
|
'loginNo' => $user->member_id,
|
|
|
|
|
|
|
|
'oldOutOrderNo' => $order->order_no,
|
|
|
|
|
|
|
|
'assureConfirmSplitInfoList' => $confirmSplitInfoList,
|
|
|
|
|
|
|
|
'outOrderNo' => StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_CONFIRM_PAY),
|
|
|
|
|
|
|
|
'amount' => $data['amount'],
|
|
|
|
|
|
|
|
'notifyUrl' => $data['notifyUrl'],
|
|
|
|
|
|
|
|
], $token);
|
|
|
|
|
|
|
|
$order->status = 'CONFIRM_SUCCESS';
|
|
|
|
|
|
|
|
$order->save();
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
} catch (ApiException $e) {
|
|
|
|
|
|
|
|
$order->status = 'CONFIRM_FAILED';
|
|
|
|
|
|
|
|
$order->error_code = $e->getCode();
|
|
|
|
|
|
|
|
$order->error_message = $e->getMessage();
|
|
|
|
|
|
|
|
$order->save();
|
|
|
|
|
|
|
|
throw $e;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|