|
|
@ -26,22 +26,26 @@ class RechargeController extends AbstractController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getMemberInfo(RequestInterface $request) {
|
|
|
|
public function getMemberInfo(RequestInterface $request) {
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('token', ''));
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('stoken', ''));
|
|
|
|
$user = User::where('out_member_id', $prePayLog->out_member_id)->first();
|
|
|
|
$user = User::where('out_member_id', $prePayLog->out_member_id)->first();
|
|
|
|
$bankCard = null;
|
|
|
|
$bankCard = null;
|
|
|
|
|
|
|
|
$userInfo = null;
|
|
|
|
if ($user) {
|
|
|
|
if ($user) {
|
|
|
|
$bankCard = BankCard::where('member_id', $user->member_id)->where('status', BankCard::STATUS_ACTIVE)->first();
|
|
|
|
$bankCard = BankCard::where('member_id', $user->member_id)->where('status', BankCard::STATUS_ACTIVE)->first();
|
|
|
|
|
|
|
|
$userInfo = [
|
|
|
|
|
|
|
|
'name' => $user->real_name ?? '',
|
|
|
|
|
|
|
|
'cardNo' => $user->card_no ?? '',
|
|
|
|
|
|
|
|
'mobile' => $user->mobile ?? '',
|
|
|
|
|
|
|
|
'bankCardNo' => $bankCard->bank_card_no ?? '',
|
|
|
|
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success([
|
|
|
|
return $this->success([
|
|
|
|
'name' => $user->real_name ?? '',
|
|
|
|
'user' => $userInfo
|
|
|
|
'card_no' => $user->card_no ?? '',
|
|
|
|
|
|
|
|
'mobile' => $user->mobile ?? '',
|
|
|
|
|
|
|
|
'bank_card_no' => $bankCard->bank_card_no ?? '',
|
|
|
|
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function recharge(RequestInterface $request) {
|
|
|
|
public function recharge(RequestInterface $request) {
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('token', ''));
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('stoken', ''));
|
|
|
|
$name = $request->input('name');
|
|
|
|
$name = $request->input('name');
|
|
|
|
if (empty($name)) {
|
|
|
|
if (empty($name)) {
|
|
|
|
throw new BusinessException('请输入姓名');
|
|
|
|
throw new BusinessException('请输入姓名');
|
|
|
@ -72,13 +76,17 @@ class RechargeController extends AbstractController
|
|
|
|
$user = User::where('member_id', $memberId)->first();
|
|
|
|
$user = User::where('member_id', $memberId)->first();
|
|
|
|
$bankCard = null;
|
|
|
|
$bankCard = null;
|
|
|
|
if ($user) {
|
|
|
|
if ($user) {
|
|
|
|
|
|
|
|
if (empty($user->out_member_id)) {
|
|
|
|
|
|
|
|
$user->out_member_id = $prePayLog->out_member_id;
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
}
|
|
|
|
$bankCard = BankCard::where('member_id', $user->member_id)->where('bank_card_no', $bankCardNo)->where('status', BankCard::STATUS_ACTIVE)->first();
|
|
|
|
$bankCard = BankCard::where('member_id', $user->member_id)->where('bank_card_no', $bankCardNo)->where('status', BankCard::STATUS_ACTIVE)->first();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($bankCard) {
|
|
|
|
if ($bankCard) {
|
|
|
|
$outTradeNo = $prePayLog->out_order_no;
|
|
|
|
$outOrderNo = $prePayLog->out_order_no;
|
|
|
|
$nextStep = 'confirm-pay';
|
|
|
|
$nextStep = 'confirm-pay';
|
|
|
|
$bizData = $this->paymentService->protocolPayPreRequest($this->buildPrepayParams($prePayLog->out_member_id, $outTradeNo, $bankCard->protocol, intval($amount * 100), $app));
|
|
|
|
$bizData = $this->paymentService->protocolPayPreRequest($this->buildPrepayParams($prePayLog->out_member_id, $outOrderNo, $bankCard->protocol, intval($amount * 100), $app));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$mchOrderNo = StringHelper::generateBankCardOrderNo();
|
|
|
|
$mchOrderNo = StringHelper::generateBankCardOrderNo();
|
|
|
|
$nextStep = 'confirm-bind';
|
|
|
|
$nextStep = 'confirm-bind';
|
|
|
@ -94,7 +102,7 @@ class RechargeController extends AbstractController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function confirmBindCard(RequestInterface $request) {
|
|
|
|
public function confirmBindCard(RequestInterface $request) {
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('token', ''));
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('stoken', ''));
|
|
|
|
$outMemberId = $request->input('outMemberId');
|
|
|
|
$outMemberId = $request->input('outMemberId');
|
|
|
|
$smsNo = $request->input('smsNo');
|
|
|
|
$smsNo = $request->input('smsNo');
|
|
|
|
$smsCode = $request->input('smsCode');
|
|
|
|
$smsCode = $request->input('smsCode');
|
|
|
@ -106,7 +114,7 @@ class RechargeController extends AbstractController
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function confirmPay(RequestInterface $request) {
|
|
|
|
public function confirmPay(RequestInterface $request) {
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('token', ''));
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('stoken', ''));
|
|
|
|
$outMemberId = $request->input('outMemberId');
|
|
|
|
$outMemberId = $request->input('outMemberId');
|
|
|
|
$token = $request->input('token');
|
|
|
|
$token = $request->input('token');
|
|
|
|
$protocol = $request->input('protocol');
|
|
|
|
$protocol = $request->input('protocol');
|
|
|
@ -139,7 +147,7 @@ class RechargeController extends AbstractController
|
|
|
|
return $params;
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function buildPrepayParams($outMemberId, $outTradeNo, $protocol, $amount, $app)
|
|
|
|
private function buildPrepayParams($outMemberId, $outOrderNo, $protocol, $amount, $app)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$params = [
|
|
|
|
$params = [
|
|
|
|
'app_id' => $app->app_id,
|
|
|
|
'app_id' => $app->app_id,
|
|
|
@ -147,7 +155,7 @@ class RechargeController extends AbstractController
|
|
|
|
'nonce_str' => StringHelper::getRandomString(32),
|
|
|
|
'nonce_str' => StringHelper::getRandomString(32),
|
|
|
|
'data' => json_encode([
|
|
|
|
'data' => json_encode([
|
|
|
|
'outMemberId' => $outMemberId,
|
|
|
|
'outMemberId' => $outMemberId,
|
|
|
|
'outTradeNo' => $outTradeNo,
|
|
|
|
'outOrderNo' => $outOrderNo,
|
|
|
|
'protocol' => $protocol,
|
|
|
|
'protocol' => $protocol,
|
|
|
|
'payAmount' => $amount,
|
|
|
|
'payAmount' => $amount,
|
|
|
|
]),
|
|
|
|
]),
|
|
|
@ -195,16 +203,53 @@ class RechargeController extends AbstractController
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$page = $request->input('page', 1);
|
|
|
|
$page = $request->input('page', 1);
|
|
|
|
$pageSize = $request->input('pageSize', 20);
|
|
|
|
$pageSize = $request->input('pageSize', 20);
|
|
|
|
|
|
|
|
$status = $request->input('status', 0);
|
|
|
|
|
|
|
|
$timeRange = $request->input('timeRange', null);
|
|
|
|
$token = $request->input('token');
|
|
|
|
$token = $request->input('token');
|
|
|
|
|
|
|
|
$mobile = $request->input('mobile', '');
|
|
|
|
|
|
|
|
$cardNo = $request->input('cardNo', '');
|
|
|
|
|
|
|
|
$orderNo = $request->input('orderNo', '');
|
|
|
|
|
|
|
|
$outOrderNo = $request->input('outOrderNo', '');
|
|
|
|
|
|
|
|
$bankCardNo = $request->input('bankCardNo', '');
|
|
|
|
|
|
|
|
|
|
|
|
$value = Redis::get('token:' . $token);
|
|
|
|
$appId = Redis::get('token:' . $token);
|
|
|
|
$users = $this->getUsers();
|
|
|
|
if (empty($appId)) {
|
|
|
|
if (empty($value) || !isset($users[$value])) {
|
|
|
|
|
|
|
|
throw new UnauthorizedException();
|
|
|
|
throw new UnauthorizedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$offset = ($page - 1) * $pageSize;
|
|
|
|
$offset = ($page - 1) * $pageSize;
|
|
|
|
$orders = Order::query()->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
|
|
|
|
$query = Order::query()->where('app_id', $appId);
|
|
|
|
|
|
|
|
if ($status) {
|
|
|
|
|
|
|
|
$query->where('status', $status);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($mobile) {
|
|
|
|
|
|
|
|
$memberIds = User::where('app_id', $appId)->where('mobile', $mobile)->get(['member_id'])->pluck('member_id')->toArray();
|
|
|
|
|
|
|
|
$query->whereIn('member_id', $memberIds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cardNo) {
|
|
|
|
|
|
|
|
$memberIds = User::where('app_id', $appId)->where('card_no', $cardNo)->get(['member_id'])->pluck('member_id')->toArray();
|
|
|
|
|
|
|
|
$query->whereIn('member_id', $memberIds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($bankCardNo) {
|
|
|
|
|
|
|
|
$protocols = BankCard::where('app_id', $appId)->where('bank_card_no', $bankCardNo)->get(['protocol'])->pluck('protocol')->toArray();
|
|
|
|
|
|
|
|
$query->whereIn('protocol', $protocols);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($orderNo) {
|
|
|
|
|
|
|
|
$query->where('order_no', $orderNo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($outOrderNo) {
|
|
|
|
|
|
|
|
$query->where('out_order_no', $outOrderNo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($timeRange) {
|
|
|
|
|
|
|
|
$timeRange[0] .= ' 00:00:00';
|
|
|
|
|
|
|
|
$timeRange[1] .= ' 23:59:59';
|
|
|
|
|
|
|
|
$query->whereBetween('created_at', $timeRange);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$countQuery = clone $query;
|
|
|
|
|
|
|
|
$sumQuery = clone $query;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$orders = $query->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
|
|
|
|
$protocols = $orders->pluck('protocol');
|
|
|
|
$protocols = $orders->pluck('protocol');
|
|
|
|
$bankCards = BankCard::whereIn('protocol', $protocols)->get();
|
|
|
|
$bankCards = BankCard::whereIn('protocol', $protocols)->get();
|
|
|
|
$bankCards = $bankCards->keyBy('protocol');
|
|
|
|
$bankCards = $bankCards->keyBy('protocol');
|
|
|
@ -225,10 +270,12 @@ class RechargeController extends AbstractController
|
|
|
|
];
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$total = Order::query()->count();
|
|
|
|
$total = $countQuery->count();
|
|
|
|
|
|
|
|
$amount = $sumQuery->sum('amount');
|
|
|
|
return $this->success([
|
|
|
|
return $this->success([
|
|
|
|
'records' => $records,
|
|
|
|
'records' => $records,
|
|
|
|
'total' => $total,
|
|
|
|
'total' => $total,
|
|
|
|
|
|
|
|
'amount' => $amount / 100,
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -241,28 +288,31 @@ class RechargeController extends AbstractController
|
|
|
|
throw new BusinessException('账号或密码错误');
|
|
|
|
throw new BusinessException('账号或密码错误');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$users = $this->getUsers();
|
|
|
|
$user = $this->getUser($username);
|
|
|
|
|
|
|
|
if (!$user) {
|
|
|
|
|
|
|
|
throw new BusinessException('账号或密码错误');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($users[$username]) && $users[$username] === $password) {
|
|
|
|
if ($user['password'] !== $password) {
|
|
|
|
$token = md5(microtime() . $username . $password);
|
|
|
|
throw new BusinessException('账号或密码错误');
|
|
|
|
Redis::set('token:' . $token, $username);
|
|
|
|
|
|
|
|
Redis::expire('token:' . $token, 60*60);
|
|
|
|
|
|
|
|
return $this->success(['token' => $token]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new BusinessException('账号或密码错误');
|
|
|
|
|
|
|
|
|
|
|
|
$token = md5(microtime() . $username . $password);
|
|
|
|
|
|
|
|
Redis::set('token:' . $token, $user['app_id']);
|
|
|
|
|
|
|
|
Redis::expire('token:' . $token, 60*60);
|
|
|
|
|
|
|
|
return $this->success(['token' => $token]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function getUsers() {
|
|
|
|
private function getUser($username) {
|
|
|
|
return [
|
|
|
|
$users = [
|
|
|
|
'owx0tlx' => 'lSoLW28NxtMlxUazC8p',
|
|
|
|
'owx0tlx' => ['password' => 'lSoLW28NxtMlxUazC8p', 'app_id' => '202304270000004'],
|
|
|
|
'ioexlp2' => 'wwU8Ir3Xp0rxXssA9NV'
|
|
|
|
'ioexlp2' => ['password' => 'wwU8Ir3Xp0rxXssA9NV', 'app_id' => '202305270000001'],
|
|
|
|
|
|
|
|
'lix73nxIN' => ['password' => 'a01@lWl3dfNmT', 'app_id' => '202306140000001'],
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
return $users[$username] ?? null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function checkToken($token) {
|
|
|
|
private function checkToken($token) {
|
|
|
|
$app = App::query()->orderBy('id', 'asc')->first();
|
|
|
|
|
|
|
|
return $app;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($token)) {
|
|
|
|
if (empty($token)) {
|
|
|
|
throw new BusinessException('token异常');
|
|
|
|
throw new BusinessException('token异常');
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -273,10 +323,6 @@ class RechargeController extends AbstractController
|
|
|
|
if ($log->created_at->timestamp < time() - 5*60) {
|
|
|
|
if ($log->created_at->timestamp < time() - 5*60) {
|
|
|
|
throw new BusinessException('支付超时,请重新请求');
|
|
|
|
throw new BusinessException('支付超时,请重新请求');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$order = Order::where('app_id', $log->app_id)->where('out_order_no', $log->out_order_no)->first();
|
|
|
|
|
|
|
|
if ($order) {
|
|
|
|
|
|
|
|
throw new BusinessException('订单重复,请重新请求');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$app = App::where('app_id', $log->app_id)->first();
|
|
|
|
$app = App::where('app_id', $log->app_id)->first();
|
|
|
|
if (empty($app)) {
|
|
|
|
if (empty($app)) {
|
|
|
|
throw new BusinessException('应用异常');
|
|
|
|
throw new BusinessException('应用异常');
|
|
|
|