/** * @brief 担保交易支付 * * @return public function * @retval * @see * @note * @author 吕宝贵 * @date 2015/12/08 22:35:00 **/ public function actionPay() { $payForm = new PayForm(); if ($payForm->load(Yii::$app->request->post())) { //根据form产生trans,trans处于未支付状态 $userAccount = Yii::$app->account->getUserAccount(Yii::$app->user->uid); $trans = $payForm->generateTrans(); //如果账户余额大于交易的总金额,则直接支付 if ($userAccount->balance >= $trans->total_money) { $transaction = $this->beginTransaction(); if (Yii::$app->account->pay($trans)) { $transaction->commit(); //设置通知消息 Yii::$app->success('订单支付成功'); //跳转到订单页面 $this->redirect(); } else { $transaction->rollback(); Yii::$app->error('订单支付失败'); } } else { $receivable = Yii::$app->account->chargeForTrans($trans); //如果账户余额不足,则根据$receivable的金额去充值, //下面的操作将会引起用户端页面的跳转或者是微信支付页面弹出 die(Yii::$app->payment->generateUserRequest($receivable)); } } else { //如果用户没有提交支付,则认为是需要渲染页面 return $this->render('pay', ['model' => $payForm]); } }
<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', ['id' => 'pay-from', 'enableAjaxValidation' => false, 'enableClientValidation' => true, 'type' => 'vertical']); ?> <h2>Пополнить счет</h2> <?php // echo $form->errorSummary($PayForm); ?> <div class="row"> <section class="col-sm-3"> <?php echo $form->textFieldGroup($PayForm, 'summ'); ?> </section> <section class="col-sm-6"> <?php echo $form->dropDownListGroup($PayForm, 'paySystem', ['widgetOptions' => ['data' => PayForm::getPaySystems()]]); ?> </section> <section class="col-sm-3"> <?php $this->widget('bootstrap.widgets.TbButton', ['buttonType' => 'submit', 'htmlOptions' => ['name' => 'save', 'value' => 'save'], 'label' => Yii::t('CabinetModule.pay', 'Оплатить')]); ?> </section> </div> <?php $this->endWidget();