|
|
|
@ -26,22 +26,26 @@ class RechargeController extends AbstractController
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
$bankCard = null;
|
|
|
|
|
$userInfo = null;
|
|
|
|
|
if ($user) {
|
|
|
|
|
$bankCard = BankCard::where('member_id', $user->member_id)->where('status', BankCard::STATUS_ACTIVE)->first();
|
|
|
|
|
}
|
|
|
|
|
return $this->success([
|
|
|
|
|
$userInfo = [
|
|
|
|
|
'name' => $user->real_name ?? '',
|
|
|
|
|
'card_no' => $user->card_no ?? '',
|
|
|
|
|
'cardNo' => $user->card_no ?? '',
|
|
|
|
|
'mobile' => $user->mobile ?? '',
|
|
|
|
|
'bank_card_no' => $bankCard->bank_card_no ?? '',
|
|
|
|
|
'bankCardNo' => $bankCard->bank_card_no ?? '',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
return $this->success([
|
|
|
|
|
'user' => $userInfo
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function recharge(RequestInterface $request) {
|
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('token', ''));
|
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('stoken', ''));
|
|
|
|
|
$name = $request->input('name');
|
|
|
|
|
if (empty($name)) {
|
|
|
|
|
throw new BusinessException('请输入姓名');
|
|
|
|
@ -72,13 +76,17 @@ class RechargeController extends AbstractController
|
|
|
|
|
$user = User::where('member_id', $memberId)->first();
|
|
|
|
|
$bankCard = null;
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($bankCard) {
|
|
|
|
|
$outTradeNo = $prePayLog->out_order_no;
|
|
|
|
|
$outOrderNo = $prePayLog->out_order_no;
|
|
|
|
|
$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 {
|
|
|
|
|
$mchOrderNo = StringHelper::generateBankCardOrderNo();
|
|
|
|
|
$nextStep = 'confirm-bind';
|
|
|
|
@ -94,7 +102,7 @@ class RechargeController extends AbstractController
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function confirmBindCard(RequestInterface $request) {
|
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('token', ''));
|
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('stoken', ''));
|
|
|
|
|
$outMemberId = $request->input('outMemberId');
|
|
|
|
|
$smsNo = $request->input('smsNo');
|
|
|
|
|
$smsCode = $request->input('smsCode');
|
|
|
|
@ -106,7 +114,7 @@ class RechargeController extends AbstractController
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function confirmPay(RequestInterface $request) {
|
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('token', ''));
|
|
|
|
|
[$app, $prePayLog] = $this->checkToken($request->input('stoken', ''));
|
|
|
|
|
$outMemberId = $request->input('outMemberId');
|
|
|
|
|
$token = $request->input('token');
|
|
|
|
|
$protocol = $request->input('protocol');
|
|
|
|
@ -139,7 +147,7 @@ class RechargeController extends AbstractController
|
|
|
|
|
return $params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function buildPrepayParams($outMemberId, $outTradeNo, $protocol, $amount, $app)
|
|
|
|
|
private function buildPrepayParams($outMemberId, $outOrderNo, $protocol, $amount, $app)
|
|
|
|
|
{
|
|
|
|
|
$params = [
|
|
|
|
|
'app_id' => $app->app_id,
|
|
|
|
@ -147,7 +155,7 @@ class RechargeController extends AbstractController
|
|
|
|
|
'nonce_str' => StringHelper::getRandomString(32),
|
|
|
|
|
'data' => json_encode([
|
|
|
|
|
'outMemberId' => $outMemberId,
|
|
|
|
|
'outTradeNo' => $outTradeNo,
|
|
|
|
|
'outOrderNo' => $outOrderNo,
|
|
|
|
|
'protocol' => $protocol,
|
|
|
|
|
'payAmount' => $amount,
|
|
|
|
|
]),
|
|
|
|
@ -195,16 +203,53 @@ class RechargeController extends AbstractController
|
|
|
|
|
{
|
|
|
|
|
$page = $request->input('page', 1);
|
|
|
|
|
$pageSize = $request->input('pageSize', 20);
|
|
|
|
|
$status = $request->input('status', 0);
|
|
|
|
|
$timeRange = $request->input('timeRange', null);
|
|
|
|
|
$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);
|
|
|
|
|
$users = $this->getUsers();
|
|
|
|
|
if (empty($value) || !isset($users[$value])) {
|
|
|
|
|
$appId = Redis::get('token:' . $token);
|
|
|
|
|
if (empty($appId)) {
|
|
|
|
|
throw new UnauthorizedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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');
|
|
|
|
|
$bankCards = BankCard::whereIn('protocol', $protocols)->get();
|
|
|
|
|
$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([
|
|
|
|
|
'records' => $records,
|
|
|
|
|
'total' => $total,
|
|
|
|
|
'amount' => $amount / 100,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -241,28 +288,31 @@ class RechargeController extends AbstractController
|
|
|
|
|
throw new BusinessException('账号或密码错误');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$users = $this->getUsers();
|
|
|
|
|
$user = $this->getUser($username);
|
|
|
|
|
if (!$user) {
|
|
|
|
|
throw new BusinessException('账号或密码错误');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($user['password'] !== $password) {
|
|
|
|
|
throw new BusinessException('账号或密码错误');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($users[$username]) && $users[$username] === $password) {
|
|
|
|
|
$token = md5(microtime() . $username . $password);
|
|
|
|
|
Redis::set('token:' . $token, $username);
|
|
|
|
|
Redis::set('token:' . $token, $user['app_id']);
|
|
|
|
|
Redis::expire('token:' . $token, 60*60);
|
|
|
|
|
return $this->success(['token' => $token]);
|
|
|
|
|
}
|
|
|
|
|
throw new BusinessException('账号或密码错误');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getUsers() {
|
|
|
|
|
return [
|
|
|
|
|
'owx0tlx' => 'lSoLW28NxtMlxUazC8p',
|
|
|
|
|
'ioexlp2' => 'wwU8Ir3Xp0rxXssA9NV'
|
|
|
|
|
private function getUser($username) {
|
|
|
|
|
$users = [
|
|
|
|
|
'owx0tlx' => ['password' => 'lSoLW28NxtMlxUazC8p', 'app_id' => '202304270000004'],
|
|
|
|
|
'ioexlp2' => ['password' => 'wwU8Ir3Xp0rxXssA9NV', 'app_id' => '202305270000001'],
|
|
|
|
|
'lix73nxIN' => ['password' => 'a01@lWl3dfNmT', 'app_id' => '202306140000001'],
|
|
|
|
|
];
|
|
|
|
|
return $users[$username] ?? null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function checkToken($token) {
|
|
|
|
|
$app = App::query()->orderBy('id', 'asc')->first();
|
|
|
|
|
return $app;
|
|
|
|
|
|
|
|
|
|
if (empty($token)) {
|
|
|
|
|
throw new BusinessException('token异常');
|
|
|
|
|
}
|
|
|
|
@ -273,10 +323,6 @@ class RechargeController extends AbstractController
|
|
|
|
|
if ($log->created_at->timestamp < time() - 5*60) {
|
|
|
|
|
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();
|
|
|
|
|
if (empty($app)) {
|
|
|
|
|
throw new BusinessException('应用异常');
|
|
|
|
|