mirror of
https://gitee.com/technical-laohu/mpay.git
synced 2025-09-19 10:16:38 +08:00
新订单缓存更新,更利于维护
This commit is contained in:
parent
504aa6c284
commit
a5d09d0a26
@ -201,9 +201,8 @@ class PayController
|
|||||||
$req_pid = $req_info['pid'];
|
$req_pid = $req_info['pid'];
|
||||||
$req_aid = $req_info['aid'];
|
$req_aid = $req_info['aid'];
|
||||||
// 获取订单
|
// 获取订单
|
||||||
$order_path = runtime_path() . '/order.json';
|
$new_order = cache('order');
|
||||||
if (!file_exists($order_path)) return json(['code' => 3, 'msg' => '订单文件不存在']);
|
if (!$new_order) return json(['code' => 3, 'msg' => '没有找到新订单缓存']);
|
||||||
$new_order = json_decode(file_get_contents($order_path), true);
|
|
||||||
// 检测新订单
|
// 检测新订单
|
||||||
if ($new_order['code'] !== 1) return json($new_order);
|
if ($new_order['code'] !== 1) return json($new_order);
|
||||||
// 订单列表
|
// 订单列表
|
||||||
@ -237,38 +236,31 @@ class PayController
|
|||||||
return json(['code' => 0, 'msg' => '查询空订单'], 320);
|
return json(['code' => 0, 'msg' => '查询空订单'], 320);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// [定时任务]监听新订单,生成JSON文件信息
|
// [定时任务]监听新订单,生成缓存
|
||||||
public function checkOrder($pid = '', $sign = '')
|
public function checkOrder($pid = '', $sign = '')
|
||||||
{
|
{
|
||||||
if (!($pid && $sign)) {
|
if (!($pid && $sign)) return '参数错误';
|
||||||
return '参数错误';
|
|
||||||
}
|
|
||||||
$is_user = User::checkUser($pid, $sign);
|
$is_user = User::checkUser($pid, $sign);
|
||||||
$path = runtime_path() . 'order.json';
|
|
||||||
if ($is_user) {
|
if ($is_user) {
|
||||||
$orders = Order::scope('activeOrder')->field('id,pid,aid,cid,patt')->select();
|
$orders = Order::scope('activeOrder')->field('id,pid,aid,cid,patt')->select();
|
||||||
if (!file_exists($path)) {
|
$old_info = cache('order');
|
||||||
file_put_contents($path, '[]');
|
|
||||||
}
|
|
||||||
$old_info = file_get_contents($path);
|
|
||||||
$num = count($orders);
|
$num = count($orders);
|
||||||
if ($num > 0) {
|
if ($num > 0) {
|
||||||
$info = ['code' => 1, 'msg' => "有{$num}个新订单"];
|
$info = ['code' => 1, 'msg' => "有{$num}个新订单"];
|
||||||
$order_list = ['code' => 1, 'msg' => "有{$num}个新订单", 'orders' => $orders];
|
$order_list = ['code' => 1, 'msg' => "有{$num}个新订单", 'orders' => $orders];
|
||||||
if ($old_info !== json_encode($order_list)) {
|
if ($old_info !== $order_list) {
|
||||||
file_put_contents($path, json_encode($order_list));
|
cache('order', $order_list);
|
||||||
}
|
}
|
||||||
return json($info);
|
return json($info);
|
||||||
} else {
|
} else {
|
||||||
$info = ['code' => 0, 'msg' => '没有新订单'];
|
$info = ['code' => 0, 'msg' => '没有新订单'];
|
||||||
if ($old_info !== json_encode($info, 320)) {
|
if ($old_info !== $info) {
|
||||||
file_put_contents($path, json_encode($info, 320));
|
cache('order', $info);
|
||||||
}
|
}
|
||||||
return json($info);
|
return json($info);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$info = ['code' => 2, 'msg' => '签名错误'];
|
$info = ['code' => 2, 'msg' => '签名错误'];
|
||||||
file_put_contents($path, json_encode($info, 320));
|
|
||||||
return json($info);
|
return json($info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,7 +272,7 @@ class PayController
|
|||||||
if ($action === 'mpay') {
|
if ($action === 'mpay') {
|
||||||
$data = json_decode($info['data'], true);
|
$data = json_decode($info['data'], true);
|
||||||
if (!is_array($data)) return 200;
|
if (!is_array($data)) return 200;
|
||||||
if(!isset($data['aid']) || !isset($data['pid'])) return 202;
|
if (!isset($data['aid']) || !isset($data['pid'])) return 202;
|
||||||
$config = PayAccount::getAccountConfig($data['aid'], $data['pid']);
|
$config = PayAccount::getAccountConfig($data['aid'], $data['pid']);
|
||||||
$payclient_path = "\\payclient\\{$config['payclass']}";
|
$payclient_path = "\\payclient\\{$config['payclass']}";
|
||||||
$Payclient = new $payclient_path($info, $config);
|
$Payclient = new $payclient_path($info, $config);
|
||||||
|
Loading…
Reference in New Issue
Block a user