|
|
|
@ -613,6 +613,7 @@ class PaymentService extends AbstractService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withdraw(array $data, App $app, string $token) {
|
|
|
|
|
$withdrawType = $data['withdrawType'] ?? 'normal';
|
|
|
|
|
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
|
|
|
|
|
if (empty($user)) {
|
|
|
|
|
throw new BusinessException('用户不存在');
|
|
|
|
@ -624,17 +625,49 @@ class PaymentService extends AbstractService
|
|
|
|
|
$withdraw->agreement_no = $data['agreementNo'];
|
|
|
|
|
$withdraw->withdraw_no = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_WITHDRAW_NO);
|
|
|
|
|
$withdraw->out_withdraw_no = $data['outWithdrawNo'];
|
|
|
|
|
$withdraw->withdraw_type = $withdrawType;
|
|
|
|
|
$withdraw->amount = $data['amount'];
|
|
|
|
|
$withdraw->status = 'PREPARE';
|
|
|
|
|
$withdraw->applied_at = date('Y-m-d H:i:s');
|
|
|
|
|
$withdraw->notify_url = $data['notifyUrl'];
|
|
|
|
|
$withdraw->save();
|
|
|
|
|
|
|
|
|
|
if ($withdrawType == 'entrust') {
|
|
|
|
|
return $this->doEntrustWithdraw($data, $withdraw);
|
|
|
|
|
} else {
|
|
|
|
|
return $this->doWithdraw($data, $withdraw);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function doWithdraw(array $data, Withdraw $withdraw) {
|
|
|
|
|
try {
|
|
|
|
|
$baofu = new Baofu();
|
|
|
|
|
$result = $baofu->withdraw([
|
|
|
|
|
'amount' => intval($data['amount']),
|
|
|
|
|
'loginNo' => $user->member_id,
|
|
|
|
|
'loginNo' => $withdraw->member_id,
|
|
|
|
|
'agreementNo' => $data['agreementNo'],
|
|
|
|
|
'outOrderNo' => $withdraw->withdraw_no,
|
|
|
|
|
], $token);
|
|
|
|
|
|
|
|
|
|
$withdraw->status = 'APPLY_SUCCESS';
|
|
|
|
|
$withdraw->withdraw_url = $result;
|
|
|
|
|
$withdraw->save();
|
|
|
|
|
return $result;
|
|
|
|
|
} catch (ApiException $e) {
|
|
|
|
|
$withdraw->status = 'APPLY_FAILED';
|
|
|
|
|
$withdraw->error_code = $e->getCode();
|
|
|
|
|
$withdraw->error_message = $e->getMessage();
|
|
|
|
|
$withdraw->save();
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function doEntrustWithdraw(array $data, Withdraw $withdraw) {
|
|
|
|
|
try {
|
|
|
|
|
$baofu = new Baofu();
|
|
|
|
|
$result = $baofu->entrustWithdraw([
|
|
|
|
|
'amount' => intval($data['amount']),
|
|
|
|
|
'loginNo' => $withdraw->member_id,
|
|
|
|
|
'agreementNo' => $data['agreementNo'],
|
|
|
|
|
'outOrderNo' => $withdraw->withdraw_no,
|
|
|
|
|
], $token);
|
|
|
|
|