ljl 1 year ago
parent 1e13a50ce0
commit f082399caf

@ -178,4 +178,25 @@ class PaymentController extends AbstractController
$data = $this->paymentService->withdrawApplyQuery($data, $app); $data = $this->paymentService->withdrawApplyQuery($data, $app);
return $this->success($data); return $this->success($data);
} }
public function unbindWithdrawEntrust(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, RegisterRequest::class);
$url = $this->userService->unbindWithdrawEntrust($data, $app, $token);
return $this->success(['url' => $url]);
}
public function signWithdrawEntrust(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, RegisterRequest::class);
$url = $this->userService->signWithdrawEntrust($data, $app, $token);
return $this->success(['url' => $url]);
}
public function querySignEntrust(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, RegisterRequest::class);
$result = $this->userService->querySignEntrust($data, $app);
return $this->success(['result' => $result]);
}
} }

@ -154,6 +154,16 @@ class ApiList
'description' => '企业注册-聚合交易商户报备-v3.1版本-授权目录报备', 'description' => '企业注册-聚合交易商户报备-v3.1版本-授权目录报备',
'url' => '/api/aggregationReport/v3.1.0/authBind', 'url' => '/api/aggregationReport/v3.1.0/authBind',
'signParams' => 'orgNo|merchantNo|terminalNo|simId|authType|authContent' 'signParams' => 'orgNo|merchantNo|terminalNo|simId|authType|authContent'
],
'entrust-withdraw' => [
'description' => '委托提现交易',
'url' => '/api/order/v3.0.0/entrustWithdraw',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|outOrderNo|amount|agreementNo'
],
'find-sign-entrust-result' => [
'description' => '委托授权查询',
'url' => '/api/cust/v3.0.0/findSignEntrustResult',
'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate'
] ]
]; ];

@ -547,4 +547,37 @@ class Baofu
throw new BusinessException($msg); throw new BusinessException($msg);
} }
} }
public function signWithdrawEntrust($loginNo, $token)
{
$data = [];
$data['loginNo'] = $loginNo;
return $this->h5('sign-withdraw-entrust', $data, $token);
}
public function unbindWithdrawEntrust($loginNo, $token)
{
$data = [];
$data['loginNo'] = $loginNo;
return $this->h5('unbind-withdraw-entrust', $data, $token);
}
public function entrustWithdraw($params, $token)
{
$data = [];
$data['amount'] = $params['amount'];
$data['loginNo'] = $params['loginNo'];
$data['agreementNo'] = Rsa::encryptByCERFile($params['agreementNo'], $this->getCerFilePath());
$data['outOrderNo'] = $params['outOrderNo'];
$data['notifyUrl'] = NotifyList::getNotifyUrl('withdraw', $token);
return $this->withReturnUrl($this->api('entrust-withdraw', $data), $token);
}
public function findSignEntrustResult($loginNo, $agreementType = 'W_ENTRUST')
{
$data = [];
$data['loginNo'] = $loginNo;
$data['agreementType'] = $agreementType;
return $this->api('find-sign-entrust-result', $data);
}
} }

@ -58,6 +58,18 @@ class H5List
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|null', 'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|null',
'callType' => 'BM_PWDMODIFY' 'callType' => 'BM_PWDMODIFY'
], ],
'sign-withdraw-entrust' => [
'description' => '委托提现授权',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|dataContent',
'callType' => 'SIGN_WITHDRAW_ENTRUST',
],
'unbind-withdraw-entrust' => [
'description' => '委托提现解权',
'url' => '/api/wallet/v3.0.0/login',
'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|dataContent',
'callType' => 'UNBIND_WITHDRAW_ENTRUST',
],
]; ];
public static function get($h5Name) public static function get($h5Name)

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

@ -234,4 +234,40 @@ class UserService extends AbstractService
$baofu = new Baofu(); $baofu = new Baofu();
return $baofu->getBalance($memberId); return $baofu->getBalance($memberId);
} }
public function signWithdrawEntrust(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('用户不存在');
}
$baofu = new Baofu();
$url = $baofu->signWithdrawEntrust($user->member_id, $token);
return $url;
}
public function unbindWithdrawEntrust(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('用户不存在');
}
$baofu = new Baofu();
$url = $baofu->unbindWithdrawEntrust($user->member_id, $token);
return $url;
}
public function querySignEntrust(array $data, App $app)
{
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
if (empty($user)) {
throw new BusinessException('用户不存在');
}
$baofu = new Baofu();
$result = $baofu->findSignEntrustResult($user->member_id);
return $result;
}
} }

@ -30,6 +30,9 @@ Router::addGroup('/payment',function () {
Router::post('/withdraw-apply', [PaymentController::class, 'withdrawApply']); Router::post('/withdraw-apply', [PaymentController::class, 'withdrawApply']);
Router::post('/withdraw-apply-query', [PaymentController::class, 'withdrawApplyQuery']); Router::post('/withdraw-apply-query', [PaymentController::class, 'withdrawApplyQuery']);
Router::post('/withdraw', [PaymentController::class, 'withdraw']); Router::post('/withdraw', [PaymentController::class, 'withdraw']);
Router::post('/unbind-withdraw-entrust', [PaymentController::class, 'unbindWithdrawEntrust']);
Router::post('/sign-withdraw-entrust', [PaymentController::class, 'signWithdrawEntrust']);
Router::post('/query-sign-entrust', [PaymentController::class, 'querySignEntrust']);
}, ['middleware' => [\App\Middleware\RequestLogMiddleware::class, \App\Middleware\AppAuthMiddleWare::class]]); }, ['middleware' => [\App\Middleware\RequestLogMiddleware::class, \App\Middleware\AppAuthMiddleWare::class]]);
Router::addGroup('/notify',function () { Router::addGroup('/notify',function () {

Loading…
Cancel
Save