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) {
[$app, $prePayLog] = $this->checkToken($request->input('stoken', ''));
$token = $request->input('token');
$protocol = $request->input('protocol');
$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([
'outMemberId' => $prePayLog->out_member_id,
'bizData' => ['outOrderNo' => $prePayLog->out_order_no]
@ -174,6 +206,26 @@ class RechargeController extends AbstractController
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)
{
$params = [

@ -110,10 +110,28 @@ class PaymentService extends AbstractService
$order->save();
throw new BusinessException($result->getMessage());
}
if (is_null($result->get('payResult'))) {
$order->token = $result->get('token', '');
$order->protocol = $result->get('protocol', '');
$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();
}

@ -28,6 +28,7 @@ Router::addGroup('/payment',function () {
Router::addGroup('/recharge',function () {
Router::post('/recharge', [RechargeController::class, 'recharge']);
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('/orders', [RechargeController::class, 'orders']);
Router::post('/login', [RechargeController::class, 'login']);

@ -56,7 +56,7 @@
</el-row>
</el-main>
</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-item label="验证码">
<el-input v-model="bindConfirmForm.smsCode" autocomplete="off"></el-input>
@ -64,7 +64,7 @@
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="bindConfirmVisible = false">取 消</el-button>
<el-button type="primary" @click="bindConfirm">确 定</el-button>
<el-button type="primary" @click="bindConfirmAndPay">确 定</el-button>
</div>
</el-dialog>
<el-dialog title="支付验证码" :visible.sync="payConfirmVisible" width="30%">
@ -96,7 +96,8 @@
stoken: '',
smsCode: '',
smsNo: '',
outMemberId: ''
outMemberId: '',
amount: 1,
},
payConfirmVisible: false,
hasUser: false,
@ -196,6 +197,29 @@
});
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() {
axios.post('/recharge/confirm-pay', this.payConfirmForm)
.then( (response) => {

Loading…
Cancel
Save