mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-05 19:41:44 +08:00
[更新]代码优化与问题修复
This commit is contained in:
parent
f35faf45bb
commit
d547d5401f
@ -18,7 +18,6 @@ use controller\BasicAdmin;
|
||||
use service\DataService;
|
||||
use service\LogService;
|
||||
use service\PayService;
|
||||
use think\response\View;
|
||||
|
||||
/**
|
||||
* 微信配置管理
|
||||
@ -38,7 +37,7 @@ class Config extends BasicAdmin
|
||||
|
||||
/**
|
||||
* 微信基础参数配置
|
||||
* @return View
|
||||
* @return \think\response\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
@ -54,58 +53,16 @@ class Config extends BasicAdmin
|
||||
|
||||
/**
|
||||
* 微信商户参数配置
|
||||
* @return View
|
||||
* @return \think\response\View
|
||||
*/
|
||||
public function pay()
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
switch ($this->request->get('action')) {
|
||||
// 生成测试支付二维码
|
||||
case 'payqrc':
|
||||
$pay = &load_wechat('pay');
|
||||
// 生成订单号
|
||||
$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);
|
||||
}
|
||||
// 该订单号已经支付
|
||||
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]);
|
||||
}
|
||||
// 生成支付二维码URL失败
|
||||
$this->error("生成支付二维码失败,{$pay->errMsg}[{$pay->errCode}]");
|
||||
break;
|
||||
// 微信支付退款操作
|
||||
case 'refund':
|
||||
$order_no = session('pay-test-order-no');
|
||||
if (empty($order_no)) {
|
||||
$this->error('测试订单号不存在,请重新开始支付测试!');
|
||||
}
|
||||
if (!PayService::isPay($order_no)) {
|
||||
$this->error('测试订单未支付或未收到微信支付通过!');
|
||||
}
|
||||
$pay = &load_wechat('pay');
|
||||
if (!file_exists($pay->ssl_cer) || !file_exists($pay->ssl_key)) {
|
||||
$this->error('微信支付双向证书异常,无法完成退款操作!');
|
||||
}
|
||||
$refund_no = DataService::createSequence(10, 'wechat-pay-test');
|
||||
if (false !== PayService::putWechatRefund($pay, $order_no, 1, $refund_no)) {
|
||||
session('pay-test-order-no', null);
|
||||
$this->success('测试退款操作成功,请查看微信通知!', '');
|
||||
}
|
||||
$this->error("操作退款失败,{$pay->errMsg}[{$pay->errCode}]");
|
||||
break;
|
||||
// 显示支付配置界面
|
||||
default:
|
||||
$this->assign('title', '微信支付配置');
|
||||
return view();
|
||||
$method = strtolower('_pay_' . $this->request->get('action'));
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method();
|
||||
}
|
||||
return view('', ['title' => '微信支付配置']);
|
||||
}
|
||||
$data = $this->request->post();
|
||||
foreach ($data as $key => $vo) {
|
||||
@ -117,10 +74,60 @@ class Config extends BasicAdmin
|
||||
}
|
||||
unset($data['wechat_cert_key_md5'], $data['wechat_cert_cert_md5']);
|
||||
foreach ($data as $key => $vo) {
|
||||
DataService::save($this->table, ['name' => $key, 'value' => $vo], 'name');
|
||||
sysconf($key, $vo);
|
||||
}
|
||||
LogService::write('微信管理', '修改微信支付参数成功');
|
||||
$this->success('数据修改成功!', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成测试支付二维码
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
protected function _pay_payqrc()
|
||||
{
|
||||
$pay = &load_wechat('pay');
|
||||
// 生成订单号
|
||||
$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);
|
||||
}
|
||||
// 该订单号已经支付
|
||||
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]);
|
||||
}
|
||||
// 生成支付二维码URL失败
|
||||
$this->error("生成支付二维码失败, {$pay->errMsg}[{$pay->errCode}]");
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付测试退款
|
||||
*/
|
||||
protected function _pay_refund()
|
||||
{
|
||||
$order_no = session('pay-test-order-no');
|
||||
if (empty($order_no)) {
|
||||
$this->error('测试订单号不存在, 请重新开始支付测试!');
|
||||
}
|
||||
if (!PayService::isPay($order_no)) {
|
||||
$this->error('测试订单未支付或未收到微信支付通过!');
|
||||
}
|
||||
$pay = &load_wechat('pay');
|
||||
if (!file_exists($pay->ssl_cer) || !file_exists($pay->ssl_key)) {
|
||||
$this->error('微信支付双向证书异常, 无法完成退款操作!');
|
||||
}
|
||||
$refund_no = DataService::createSequence(10, 'wechat-pay-test');
|
||||
if (false !== PayService::putWechatRefund($pay, $order_no, 1, $refund_no)) {
|
||||
session('pay-test-order-no', null);
|
||||
$this->success('测试退款操作成功, 请查看微信通知!', '');
|
||||
}
|
||||
$this->error("操作退款失败, {$pay->errMsg}[{$pay->errCode}]");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ require.config({
|
||||
// 开源插件(未修改源码)
|
||||
'pace': ['../plugs/jquery/pace.min'],
|
||||
'json': ['../plugs/jquery/json2.min'],
|
||||
'citys': ['../plugs/juqyer/jquery.citys'],
|
||||
'citys': ['../plugs/jquery/jquery.citys'],
|
||||
'print': ['../plugs/jquery/jquery.PrintArea'],
|
||||
'base64': ['../plugs/jquery/base64.min'],
|
||||
'jquery': ['../plugs/jquery/jquery.min'],
|
||||
|
Loading…
x
Reference in New Issue
Block a user