efps-version
elf 1 year ago
parent 4ef84a20f6
commit 33c21de0d4

@ -122,12 +122,44 @@ class RechargeController extends AbstractController
]); ]);
} }
public function confirmBindCardAndPay(RequestInterface $request) {
[$app, $prePayLog] = $this->checkToken($request->input('stoken', ''));
$amount = $request->input('amount');
if ($prePayLog->amount == 0) {
$amount = $request->input('amount');
if (empty($amount)) {
throw new BusinessException('请输入金额');
}
if (!is_numeric($amount)) {
throw new BusinessException('请输入金额');
}
if ($amount <= 0) {
throw new BusinessException('金额需大于0');
}
}
$outMemberId = $prePayLog->out_member_id;
$outOrderNo = $prePayLog->out_order_no;
$notifyUrl = $prePayLog->notify_url;
$amount = $prePayLog->amount > 0 ? $prePayLog->amount : intval($amount * 100);
$smsNo = $request->input('smsNo');
$smsCode = $request->input('smsCode');
$this->paymentService->protocolPayPreRequest($this->buildConfirmBindAndPay($outMemberId, $outOrderNo, $smsNo, $smsCode, $amount, $notifyUrl, $app));
return $this->success([
'outMemberId' => $prePayLog->out_member_id,
'bizData' => ['outOrderNo' => $prePayLog->out_order_no]
]);
}
public function confirmPay(RequestInterface $request) { public function confirmPay(RequestInterface $request) {
[$app, $prePayLog] = $this->checkToken($request->input('stoken', '')); [$app, $prePayLog] = $this->checkToken($request->input('stoken', ''));
$token = $request->input('token'); $token = $request->input('token');
$protocol = $request->input('protocol'); $protocol = $request->input('protocol');
$smsCode = $request->input('smsCode'); $smsCode = $request->input('smsCode');
$bizData = $this->paymentService->protocolPayConfirm($this->buildConfirmPayParams($token, $protocol, $smsCode, $app)); $this->paymentService->protocolPayConfirm($this->buildConfirmPayParams($token, $protocol, $smsCode, $app));
return $this->success([ return $this->success([
'outMemberId' => $prePayLog->out_member_id, 'outMemberId' => $prePayLog->out_member_id,
'bizData' => ['outOrderNo' => $prePayLog->out_order_no] 'bizData' => ['outOrderNo' => $prePayLog->out_order_no]
@ -174,6 +206,26 @@ class RechargeController extends AbstractController
return $params; return $params;
} }
private function buildConfirmBindAndPay($outMemberId, $outOrderNo, $smsNo, $smsCode, $amount, $notifyUrl, $app)
{
$params = [
'app_id' => $app->app_id,
'timestamp' => time(),
'nonce_str' => StringHelper::getRandomString(32),
'data' => json_encode([
'outMemberId' => $outMemberId,
'outOrderNo' => $outOrderNo,
'payAmount' => $amount,
'notifyUrl' => $notifyUrl,
'smsNo' => $smsNo,
'smsCode' => $smsCode,
]),
];
$sign = \App\Helper\Platform\Signer::sign($params, $app->app_key);
$params['sign'] = $sign;
return $params;
}
private function buildConfirmPayParams($token, $protocol, $smsCode, $app) private function buildConfirmPayParams($token, $protocol, $smsCode, $app)
{ {
$params = [ $params = [

@ -110,10 +110,28 @@ class PaymentService extends AbstractService
$order->save(); $order->save();
throw new BusinessException($result->getMessage()); throw new BusinessException($result->getMessage());
} }
$order->token = $result->get('token', ''); if (is_null($result->get('payResult'))) {
$order->protocol = $result->get('protocol', ''); $order->token = $result->get('token', '');
$order->status = Order::STATUS_WAIT_PAY; $order->protocol = $result->get('protocol', '');
$order->save(); $order->status = Order::STATUS_WAIT_PAY;
$order->save();
} else {
$bankCard = BankCard::where('app_id', $app->app_id)
->where('out_member_id', $data['outMemberId'])
->where('sms_no', $data['smsNo'])
->where('status', BankCard::STATUS_WAIT_CONFIRM)
->first();
if ($bankCard) {
$bankCard->status = BankCard::STATUS_ACTIVE;
$bankCard->protocol = $result->get('protocol', '');
$bankCard->save();
}
$order->protocol = $result->get('protocol', '');
$order->status = Order::STATUS_WAIT_PAY;
$order->save();
}
return $result->getData(); return $result->getData();
} }

@ -28,6 +28,7 @@ Router::addGroup('/payment',function () {
Router::addGroup('/recharge',function () { Router::addGroup('/recharge',function () {
Router::post('/recharge', [RechargeController::class, 'recharge']); Router::post('/recharge', [RechargeController::class, 'recharge']);
Router::post('/confirm-bind-card', [RechargeController::class, 'confirmBindCard']); Router::post('/confirm-bind-card', [RechargeController::class, 'confirmBindCard']);
Router::post('/confirm-bind-card-and-pay', [RechargeController::class, 'confirmBindCardAndPay']);
Router::post('/confirm-pay', [RechargeController::class, 'confirmPay']); Router::post('/confirm-pay', [RechargeController::class, 'confirmPay']);
Router::post('/orders', [RechargeController::class, 'orders']); Router::post('/orders', [RechargeController::class, 'orders']);
Router::post('/login', [RechargeController::class, 'login']); Router::post('/login', [RechargeController::class, 'login']);

@ -56,7 +56,7 @@
</el-row> </el-row>
</el-main> </el-main>
</el-container> </el-container>
<el-dialog title="绑卡验证码" :visible.sync="bindConfirmVisible" width="30%"> <el-dialog title="绑卡支付验证码" :visible.sync="bindConfirmVisible" width="30%">
<el-form :model="bindConfirmForm" label-width="80px"> <el-form :model="bindConfirmForm" label-width="80px">
<el-form-item label="验证码"> <el-form-item label="验证码">
<el-input v-model="bindConfirmForm.smsCode" autocomplete="off"></el-input> <el-input v-model="bindConfirmForm.smsCode" autocomplete="off"></el-input>
@ -64,7 +64,7 @@
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button @click="bindConfirmVisible = false">取 消</el-button> <el-button @click="bindConfirmVisible = false">取 消</el-button>
<el-button type="primary" @click="bindConfirm">确 定</el-button> <el-button type="primary" @click="bindConfirmAndPay">确 定</el-button>
</div> </div>
</el-dialog> </el-dialog>
<el-dialog title="支付验证码" :visible.sync="payConfirmVisible" width="30%"> <el-dialog title="支付验证码" :visible.sync="payConfirmVisible" width="30%">
@ -96,7 +96,8 @@
stoken: '', stoken: '',
smsCode: '', smsCode: '',
smsNo: '', smsNo: '',
outMemberId: '' outMemberId: '',
amount: 1,
}, },
payConfirmVisible: false, payConfirmVisible: false,
hasUser: false, hasUser: false,
@ -196,6 +197,29 @@
}); });
console.log('submit!'); console.log('submit!');
}, },
bindConfirmAndPay() {
this.bindConfirmForm.amount = this.form.amount;
axios.post('/recharge/confirm-bind-card-and-pay', this.bindConfirmForm)
.then( (response) => {
console.log(response);
let result = response.data
if (result.code != 1000) {
return this.$message.error(response.data.message);
}
this.bindConfirmVisible = false;
this.$message.success('支付成功');
this.$alert('请记住您的订单号:' + result.data.bizData.outOrderNo , '支付成功', {
confirmButtonText: '确定',
callback: action => {
}
});
})
.catch((error) => {
this.$message.error('请求错误');
console.log(error);
});
console.log('submit!');
},
payConfirm() { payConfirm() {
axios.post('/recharge/confirm-pay', this.payConfirmForm) axios.post('/recharge/confirm-pay', this.payConfirmForm)
.then( (response) => { .then( (response) => {

Loading…
Cancel
Save