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

142 lines
5.2 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);
$data = $this->userService->unbindCard($data, $app);
return $this->success($data);
}
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 payment(RequestInterface $request) {
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$url = $this->paymentService->payment($data, $app, $token);
return $this->success(['url' => $url]);
}
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 refundApply(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$data = $this->paymentService->refundApply($app, $data);
return $this->success($data);
}
public function refundConfirm(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$this->paymentService->refundConfirm($app, $data, $token);
return $this->success();
}
public function refundCancel(RequestInterface $request)
{
[$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class);
$data = $this->paymentService->refundApply($app, $data);
return $this->success($data);
}
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);
$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);
}
}