You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
payment/app/Controller/Payment/PaymentController.php

214 lines
7.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Controller\Payment;
use App\Exception\BusinessException;
use App\Model\User;
use App\Request\BindCardRequest;
use App\Request\RegisterRequest;
use App\Request\UnbindCardRequest;
use Hyperf\HttpServer\Contract\RequestInterface;
use App\Service\PaymentService;
use App\Service\UserService;
use Hyperf\Context\Context;
class PaymentController extends AbstractController
{
private UserService $userService;
private PaymentService $paymentService;
public function __construct(PaymentService $paymentService, UserService $userService)
{
$this->userService = $userService;
$this->paymentService = $paymentService;
}
private function parseReqest($request, $requestClass)
{
$app = Context::get('app');
$requestLog = Context::get('requestLog');
$req = new $requestClass($request->all());
return [$app, $req->getData(), $requestLog->request_token];
}
public function companyRegister(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, RegisterRequest::class);
$result = $this->userService->companyRegister($data, $app, $token);
return $this->success(['result' => $result]);
}
public function register(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, RegisterRequest::class);
$url = $this->userService->register($data, $app, $token);
return $this->success(['url' => $url]);
}
public function bindCard(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, BindCardRequest::class);
$url = $this->userService->bindCard($data, $app, $token);
return $this->success(['url' => $url]);
}
public function unbindCard(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$this->userService->unbindCard($data, $app);
return $this->success();
}
public function pwdForget(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$url = $this->userService->pwdForget($data, $app, $token);
return $this->success(['url' => $url]);
}
public function pwdModify(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$url = $this->userService->pwdModify($data, $app, $token);
return $this->success(['url' => $url]);
}
public function getBalance(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
if (empty($user)) {
throw new BusinessException('用户不存在');
}
$result = $this->userService->getBalance($user->member_id);
return $this->success(['result' => $result]);
}
public function payment(RequestInterface $request) {
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$data = $this->paymentService->payment($data, $app, $token);
return $this->success($data);
}
public function transferPay(RequestInterface $request) {
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$acsNo = $this->paymentService->transferPay($data, $app, $token);
return $this->success(['acsNo' => $acsNo]);
}
public function confirmPay(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$result = $this->paymentService->confirmPay($data, $app, $token);
return $this->success(['result' => $result]);
}
public function refundApply(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$this->paymentService->refundApply($data, $app);
return $this->success();
}
public function refundConfirm(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$this->paymentService->refundConfirm($data, $app, $token);
return $this->success();
}
public function refundCancel(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$this->paymentService->refundApply($data, $app);
return $this->success();
}
public function queryBindCards(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
if (empty($user)) {
throw new BusinessException('用户不存在');
}
$this->userService->rsyncBankCards($user->member_id);
$records = $this->userService->getUserBankCards($data['userId'], $app);
return $this->success(['result' => $records]);
}
public function queryUser(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first();
if (empty($user)) {
throw new BusinessException('用户不存在');
}
$user = $this->userService->rsyncUser($user->member_id, $app->app_id, $data['userId']);
$result = [
'realnameFlag' => $user->realname_flag,
'bindCardFlag' => $user->bind_bard_flag,
'setPwdFlag' => $user->set_pwd_flag,
'email' => $user->email,
'mobile' => $user->mobile,
'certificateNo' => $user->certificate_no,
];
return $this->success($result);
}
public function queryOrder(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$order = $this->paymentService->queryOrder($data, $app);
$result = [
'finishTime' => $order->finished_at,
'amount' => $order->amount,
'status' => $order->status,
];
return $this->success($result);
}
public function withdraw(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$url = $this->paymentService->withdraw($data, $app, $token);
return $this->success(['url' => $url]);
}
public function withdrawApply(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$data = $this->paymentService->withdrawApply($data, $app);
return $this->success($data);
}
public function withdrawApplyQuery(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$data = $this->paymentService->withdrawApplyQuery($data, $app);
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]);
}
}