|
|
|
@ -15,6 +15,7 @@ use App\Model\OrderSplitInfo;
|
|
|
|
|
use App\Model\Refund;
|
|
|
|
|
use App\Model\RefundSplitInfo;
|
|
|
|
|
use App\Model\User;
|
|
|
|
|
use App\Model\Withdraw;
|
|
|
|
|
use App\Model\WithdrawApply;
|
|
|
|
|
|
|
|
|
|
class PaymentService extends AbstractService
|
|
|
|
@ -481,6 +482,27 @@ class PaymentService extends AbstractService
|
|
|
|
|
|
|
|
|
|
public function queryOrder(array $data, App $app)
|
|
|
|
|
{
|
|
|
|
|
$type = $data['type'] ?? 'PAYMENT';
|
|
|
|
|
$orderNo = null;
|
|
|
|
|
$memberId = null;
|
|
|
|
|
if ($type == 'WITHDRAW') {
|
|
|
|
|
$withdraw = Withdraw::where('app_id', $app->app_id)->where('out_withdraw_no', $data['outOrderNo'])->first();
|
|
|
|
|
if (empty($withdraw)) {
|
|
|
|
|
throw new BusinessException('提现记录不存在');
|
|
|
|
|
}
|
|
|
|
|
$memberId = $withdraw->member_id;
|
|
|
|
|
$orderNo = $withdraw->withdraw_no;
|
|
|
|
|
} elseif ($type == 'PAYMENT') {
|
|
|
|
|
$order = Order::where('app_id', $app->app_id)->where('out_order_no', $data['outOrderNo'])->first();
|
|
|
|
|
if (empty($order)) {
|
|
|
|
|
throw new BusinessException('订单不存在');
|
|
|
|
|
}
|
|
|
|
|
$memberId = $order->member_id;
|
|
|
|
|
$orderNo = $order->order_no;
|
|
|
|
|
} else {
|
|
|
|
|
throw new BusinessException('查询类型错误');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$order = Order::where('app_id', $app->app_id)->where('out_order_no', $data['outOrderNo'])->first();
|
|
|
|
|
if (empty($order)) {
|
|
|
|
|
throw new BusinessException('订单不存在');
|
|
|
|
@ -488,23 +510,30 @@ class PaymentService extends AbstractService
|
|
|
|
|
|
|
|
|
|
$baofu = new Baofu();
|
|
|
|
|
$result = $baofu->queryOrder([
|
|
|
|
|
'loginNo' => $order->member_id,
|
|
|
|
|
'tradeId' => $order->order_no,
|
|
|
|
|
'loginNo' => $orderNo,
|
|
|
|
|
'tradeId' => $memberId,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$info = [
|
|
|
|
|
'member_id' => $order->member_id,
|
|
|
|
|
'order_no' => $order->order_no,
|
|
|
|
|
'member_id' => $memberId,
|
|
|
|
|
'order_no' => $orderNo,
|
|
|
|
|
'third_order_no' => $result['requestNo'] ?? '',
|
|
|
|
|
'status' => $result['status'],
|
|
|
|
|
'amount' => $result['amount'],
|
|
|
|
|
'fee' => $result['feeAmt'] ?? 0,
|
|
|
|
|
'fee_acc' => $result['feeAcc'] ?? 0,
|
|
|
|
|
'finished_at' => $result['finishDate'],
|
|
|
|
|
'error_message' => $result['errorMsg'] ?? '',
|
|
|
|
|
'transaction_id' => $result['transactionId'] ?? '',
|
|
|
|
|
'out_transaction_id' => $result['outTransactionId'] ?? '',
|
|
|
|
|
];
|
|
|
|
|
return $this->updateOrder($info);
|
|
|
|
|
|
|
|
|
|
if ($result['tradeType'] == 'WITHDRAW') {
|
|
|
|
|
return $this->updateWithdraw($info);
|
|
|
|
|
} elseif (in_array($result['tradeType'], ['ASSURE_RECHARGE', 'PAYMENT_SPLIT_API', 'ASSURE_PORTFOLIO_PAY'])) {
|
|
|
|
|
return $this->updateOrder($info);
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withdrawApply(array $data, App $app) {
|
|
|
|
@ -519,8 +548,8 @@ class PaymentService extends AbstractService
|
|
|
|
|
$apply->account_name = $data['accountName'];
|
|
|
|
|
$apply->batch_num = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_WITHDRAW_APPLY_BATCH_NUM);
|
|
|
|
|
$apply->apply_no = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_WITHDRAW_APPLY_NO);
|
|
|
|
|
$apply->out_apply_no = $params['outApplyNo'];
|
|
|
|
|
$apply->amount = $params['amount'];
|
|
|
|
|
$apply->out_apply_no = $data['outApplyNo'];
|
|
|
|
|
$apply->amount = $data['amount'];
|
|
|
|
|
$apply->status = 'PREPARE';
|
|
|
|
|
$apply->summary = $data['summary'] ?? '转账';
|
|
|
|
|
$apply->save();
|
|
|
|
@ -538,23 +567,127 @@ class PaymentService extends AbstractService
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
$result = $baofu->transferWithdraw($data);
|
|
|
|
|
if ($result['header']['sysRespCode'] == 'S_0000' && $result['body']['transHeader']['returnCode'] == '0000') {
|
|
|
|
|
try {
|
|
|
|
|
$result = $baofu->transferWithdraw($data);
|
|
|
|
|
$apply->third_apply_no = $result[0]['transOrderId'];
|
|
|
|
|
$apply->third_batch_num = $result[0]['transBatchId'];
|
|
|
|
|
$apply->status = 'APPLY_SUCCESS';
|
|
|
|
|
} else {
|
|
|
|
|
$apply->save();
|
|
|
|
|
|
|
|
|
|
return ['batchNum' => $apply->batch_num, 'applyNo' => $apply->apply_no];
|
|
|
|
|
} catch (ApiException $e) {
|
|
|
|
|
$apply->status = 'APPLY_FAILED';
|
|
|
|
|
$apply->error_code = $e->getCode();
|
|
|
|
|
$apply->error_message = $e->getMessage();
|
|
|
|
|
$apply->save();
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
$apply->save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withdraw(array $data, App $app, string $token) {
|
|
|
|
|
public function withdrawApplyQuery(array $data, App $app) {
|
|
|
|
|
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
|
|
|
|
|
if (empty($user)) {
|
|
|
|
|
throw new BusinessException('用户不存在');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$apply = WithdrawApply::where('app_id', $app->app_id)->where('out_apply_no', $data['outApplyNo'])->first();
|
|
|
|
|
|
|
|
|
|
$baofu = new Baofu();
|
|
|
|
|
return $baofu->withdraw([
|
|
|
|
|
'amount' => $data['amount'],
|
|
|
|
|
'loginNo' => $data['amount'],
|
|
|
|
|
'agreementNo' => $data['agreementNo'],
|
|
|
|
|
'outOrderNo' => $data['outOrderNo'],
|
|
|
|
|
], $token);
|
|
|
|
|
$data = [
|
|
|
|
|
'transContent' => [
|
|
|
|
|
[
|
|
|
|
|
'transNo' => $apply->apply_no,
|
|
|
|
|
'transBatchId' => $apply->batch_num,
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
try {
|
|
|
|
|
$result = $baofu->transferWithdrawQuery($data);
|
|
|
|
|
$item = $result[0];
|
|
|
|
|
$apply->fee = intval($item['transFee'] * 100);
|
|
|
|
|
$apply->third_apply_no = $item['transOrderId'];
|
|
|
|
|
$apply->third_batch_num = $item['transBatchId'];
|
|
|
|
|
$apply->status = WithdrawApply::getStatusByShortStatus($item['state']);
|
|
|
|
|
$apply->save();
|
|
|
|
|
|
|
|
|
|
return ['fee' => $apply->fee, 'status' => $apply->status, 'amount' => $apply->amount];
|
|
|
|
|
} catch (ApiException $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withdraw(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('用户不存在');
|
|
|
|
|
}
|
|
|
|
|
$withdraw = new Withdraw();
|
|
|
|
|
$withdraw->app_id = $app->app_id;
|
|
|
|
|
$withdraw->user_id = $user->user_id;
|
|
|
|
|
$withdraw->member_id = $user->member_id;
|
|
|
|
|
$withdraw->agreement_no = $data['agreementNo'];
|
|
|
|
|
$withdraw->withdraw_no = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_WITHDRAW_NO);
|
|
|
|
|
$withdraw->out_withdraw_no = $data['outWithdrawNo'];
|
|
|
|
|
$withdraw->amount = $data['amount'];
|
|
|
|
|
$withdraw->status = 'PREPARE';
|
|
|
|
|
$withdraw->notify_url = $data['notifyUrl'];
|
|
|
|
|
$withdraw->save();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$baofu = new Baofu();
|
|
|
|
|
$result = $baofu->withdraw([
|
|
|
|
|
'amount' => $data['amount'],
|
|
|
|
|
'loginNo' => $user->member_id,
|
|
|
|
|
'agreementNo' => $data['agreementNo'],
|
|
|
|
|
'outOrderNo' => $data['outWithdrawNo'],
|
|
|
|
|
], $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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateWithdraw($params, array $statusList = null) {
|
|
|
|
|
$withdraw = Withdraw::where('withdraw_no', $params['order_no'])->first();
|
|
|
|
|
if (empty($withdraw)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($statusList && !in_array($withdraw->status, $statusList)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$withdraw->third_order_no = $params['third_order_no'];
|
|
|
|
|
$withdraw->status = $params['status'];
|
|
|
|
|
$withdraw->fee = $params['fee'];
|
|
|
|
|
$withdraw->fee_acc = $params['fee_acc'] ?? '';
|
|
|
|
|
$withdraw->save();
|
|
|
|
|
return $withdraw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updateWithdrawApply($params, array $statusList = null) {
|
|
|
|
|
$apply = WithdrawApply::where('apply_no', $params['transNo'])->first();
|
|
|
|
|
if (empty($apply)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($statusList && !in_array($apply->status, $statusList)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$apply->fee = intval($params['transFee'] * 100);
|
|
|
|
|
$apply->third_apply_no = $params['transOrderId'];
|
|
|
|
|
$apply->third_batch_num = $params['transBatchId'];
|
|
|
|
|
$apply->status = WithdrawApply::getStatusByShortStatus($params['state']);
|
|
|
|
|
$apply->save();
|
|
|
|
|
return $apply;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|