diff --git a/application/wechat/controller/Config.php b/application/wechat/controller/Config.php index 11bb6402d..bd2e246ff 100644 --- a/application/wechat/controller/Config.php +++ b/application/wechat/controller/Config.php @@ -65,27 +65,35 @@ class Config extends BasicAdmin { $order_no = session('pay-test-order-no'); if (empty($order_no)) { $order_no = DataService::createSequence(10, 'wechat-pay-test'); - session('pay-test-order-no',$order_no); + session('pay-test-order-no', $order_no); } // 该订单号已经支付 - if(PayService::isPay($order_no)){ - return json(['code'=>2,'order_no'=>$order_no]); + if (PayService::isPay($order_no)) { + return json(['code' => 2, 'order_no' => $order_no]); } // 订单号未支付,生成支付二维码URL $url = PayService::createWechatPayQrc($pay, $order_no, 1, '扫码支付测试!'); if ($url !== false) { - return json(['code'=>1,'url'=>$url,'order_no'=>$order_no]); + return json(['code' => 1, 'url' => $url, 'order_no' => $order_no]); } // 生成支付二维码URL失败 $this->error("生成支付二维码失败,{$pay->errMsg}[{$pay->errCode}]"); break; // 检查订单是否支付成功 - case 'check': - $order_no = $this->request->get('order_no'); - if (PayService::isPay($order_no)) { - $this->success('已经支付成功!', ''); + case 'refund': + $order_no = session('pay-test-order-no'); + if (empty($order_no)) { + $this->error('指定测试订单号不存在,请重新开始支付测试!'); } - $this->error('订单尚未支付!'); + if (!PayService::isPay($order_no)) { + $this->error('指定测试订单未支付或未收到微信支付通过!'); + } + $pay = &load_wechat('pay'); + $refund_no = DataService::createSequence(10, 'wechat-pay-test'); + if (false !== PayService::putWechatRefund($pay, $order_no, 1, $refund_no)) { + $this->success('操作退款成功!', ''); + } + $this->error("操作退款失败,{$pay->errMsg}[{$pay->errCode}]"); break; default: $this->assign('title', '微信支付配置'); diff --git a/application/wechat/view/config.pay.html b/application/wechat/view/config.pay.html index ab9396ea1..b98f7f33c 100644 --- a/application/wechat/view/config.pay.html +++ b/application/wechat/view/config.pay.html @@ -106,7 +106,6 @@ if (ret.code === 2) { ret.url = '__STATIC__/theme/default/img/wechat/qrc_payed.jpg'; timer && window.clearInterval(timer), timer = null; - $('[refund-qrc-test]').removeClass('hide'); } if (isShow) { $('.pay-qrc-test').attr('src', ret.url) @@ -115,29 +114,27 @@ type: 1, title: false, closeBtn: 1, shadeClose: true, content: '' + '

请用微信扫码测试支付!

' - + '

退款测试

', + + '

退款测试

', end: function () { - isShow = false; timer && window.clearInterval(timer), timer = null; + isShow = false; }, success: function (layero, index) { isShow = true; - timer = setInterval(payTest, 1000); - if(ret.code===2){ - $('[refund-qrc-test]').removeClass('hide'); - } + timer = setInterval(payTest, 3000); } }); } } return false; - }); + }, !isShow); } $('[data-pay-test]').on('click', payTest); - $('body').on('click', '[refund-qrc-test] a', function () { - $.msg.success('退款功能开发中哦!'); + /*! 发起退款操作 */ + $('body').on('click', '.refund-qrc-test a', function () { + $.form.load('{:url("pay")}?action=refund'); }); });