|
|
|
@ -36,7 +36,25 @@ class PaymentService extends AbstractService
|
|
|
|
|
throw new BusinessException('订单号重复');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[$order, $orderSplitInfos] = $this->createOrder($app, $data, $user);
|
|
|
|
|
[$order, $orderSplitInfos] = $this->createOrder($app, $data, $user, 'paymentSplit');
|
|
|
|
|
|
|
|
|
|
$splitInfoList = $this->buildSplitInfoList($orderSplitInfos);
|
|
|
|
|
|
|
|
|
|
return $this->paymentSplit($order, $user, $splitInfoList, $token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function transferPay()
|
|
|
|
|
{
|
|
|
|
|
$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 ($order) {
|
|
|
|
|
throw new BusinessException('订单号重复');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[$order, $orderSplitInfos] = $this->createOrder($app, $data, $user, 'transferSplitPay');
|
|
|
|
|
|
|
|
|
|
$splitInfoList = $this->buildSplitInfoList($orderSplitInfos);
|
|
|
|
|
|
|
|
|
@ -67,7 +85,7 @@ class PaymentService extends AbstractService
|
|
|
|
|
'amount' => $order->amount,
|
|
|
|
|
'paidType' => 'CARD',
|
|
|
|
|
'agreementNo' => $order->agreement_no,
|
|
|
|
|
'pwdPayExpTime' => strtotime($order->expired_at),
|
|
|
|
|
'pwdPayExpTime' => strtotime($order->expires_in),
|
|
|
|
|
'splitInfoList' => $splitInfoList,
|
|
|
|
|
], $token);
|
|
|
|
|
$order->status = 'APPLY_SUCCESS';
|
|
|
|
@ -85,7 +103,36 @@ class PaymentService extends AbstractService
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createOrder(App $app, array $params, User $user) {
|
|
|
|
|
private function transferSplitPay(Order $order, User $user, array $splitInfoList, string $token)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$baofu = new Baofu();
|
|
|
|
|
$result = $baofu->transferSplitPay([
|
|
|
|
|
'loginNo' => $user->member_id,
|
|
|
|
|
'outOrderNo' => $order->order_no,
|
|
|
|
|
'amount' => $order->amount,
|
|
|
|
|
'agreementNo' => $order->agreement_no,
|
|
|
|
|
'expireDate' => date('YmdHis', time() + $order->expires_in),
|
|
|
|
|
'validDate' => $order->valid_date,
|
|
|
|
|
'splitInfoList' => $splitInfoList,
|
|
|
|
|
'marketInfo' => $order->market_info,
|
|
|
|
|
], $token);
|
|
|
|
|
$order->status = 'APPLY_SUCCESS';
|
|
|
|
|
$order->applied_at = date('Y-m-d H:i:s');
|
|
|
|
|
$order->acs_no = $result['acsNo'];
|
|
|
|
|
$order->save();
|
|
|
|
|
return $result['acsNo'];
|
|
|
|
|
} catch (ApiException $e) {
|
|
|
|
|
$order->status = 'APPLY_FAILED';
|
|
|
|
|
$order->applied_at = date('Y-m-d H:i:s');
|
|
|
|
|
$order->error_code = $e->getErrorCode();
|
|
|
|
|
$order->error_message = $e->getMessage();
|
|
|
|
|
$order->save();
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function createOrder(App $app, array $params, User $user, string $payMethod) {
|
|
|
|
|
$expiresIn = $params['expiresIn'] ?? 10 * 60;
|
|
|
|
|
$order = new Order();
|
|
|
|
|
$order->app_id = $app->app_id;
|
|
|
|
@ -95,13 +142,16 @@ class PaymentService extends AbstractService
|
|
|
|
|
$order->out_order_no = $params['outOrderNo'];
|
|
|
|
|
$order->amount = $params['amount'];
|
|
|
|
|
$order->notify_url = $params['notifyUrl'];
|
|
|
|
|
$order->return_url = $params['returnUrl'];
|
|
|
|
|
$order->agreement_no = $params['agreementNo'] ?: '';
|
|
|
|
|
$order->return_url = $params['returnUrl'] ?? '';
|
|
|
|
|
$order->agreement_no = $params['agreementNo'] ?? '';
|
|
|
|
|
$order->status = 'PREPARE';
|
|
|
|
|
$order->pay_channel = 'BAOFU';
|
|
|
|
|
$order->pay_method = 'paymentSplit';
|
|
|
|
|
$order->pay_method = $payMethod;
|
|
|
|
|
$order->pay_type = 'CARD';
|
|
|
|
|
$order->expired_at = date('Y-m-d H:i:s', $expiresIn);
|
|
|
|
|
$order->valid_date = $params['valid_date'] ?? null;
|
|
|
|
|
$order->expires_in = $expiresIn,
|
|
|
|
|
$order->expired_at = date('Y-m-d H:i:s', time() + $expiresIn);
|
|
|
|
|
$order->market_info = $params['marketInfo'] ?? [];
|
|
|
|
|
$order->org_split_info_list = $params['splitInfoList'];
|
|
|
|
|
$order->save();
|
|
|
|
|
|
|
|
|
|