优化可读性

This commit is contained in:
技术老胡 2024-08-29 15:45:41 +08:00
parent 7a7f690e6e
commit 8eb3f85c37

View File

@ -208,41 +208,6 @@ class PayController
} }
} }
} }
// [定时任务]监听新订单,生成JSON文件信息
public function checkOrder($pid = '', $sign = '')
{
if (!($pid && $sign)) {
return '参数错误';
}
$is_user = User::checkUser($pid, $sign);
$path = '../runtime/order.json';
if ($is_user) {
$orders = Order::scope('activeOrder')->field('id,pid,aid,cid')->select();
if (!file_exists($path)) {
file_put_contents($path, '[]');
}
$old_info = file_get_contents($path);
$num = count($orders);
if ($num > 0) {
$info = ['code' => 1, 'msg' => "{$num}个新订单"];
$order_list = ['code' => 1, 'msg' => "{$num}个新订单", 'orders' => $orders];
if ($old_info !== json_encode($order_list)) {
file_put_contents($path, json_encode($order_list));
}
return json($info);
} else {
$info = ['code' => 0, 'msg' => '没有新订单'];
if ($old_info !== json_encode($info, 320)) {
file_put_contents($path, json_encode($info, 320));
}
return json($info);
}
} else {
$info = ['code' => 2, 'msg' => '签名错误'];
file_put_contents($path, json_encode($info, 320));
return json($info);
}
}
// 获取收款通知,提交收款订单明细 // 获取收款通知,提交收款订单明细
public function checkPayResult(Request $request) public function checkPayResult(Request $request)
{ {
@ -307,6 +272,41 @@ class PayController
return \json(['code' => 0, 'msg' => '查询空订单'], 320); return \json(['code' => 0, 'msg' => '查询空订单'], 320);
} }
} }
// [定时任务]监听新订单,生成JSON文件信息
public function checkOrder($pid = '', $sign = '')
{
if (!($pid && $sign)) {
return '参数错误';
}
$is_user = User::checkUser($pid, $sign);
$path = '../runtime/order.json';
if ($is_user) {
$orders = Order::scope('activeOrder')->field('id,pid,aid,cid')->select();
if (!file_exists($path)) {
file_put_contents($path, '[]');
}
$old_info = file_get_contents($path);
$num = count($orders);
if ($num > 0) {
$info = ['code' => 1, 'msg' => "{$num}个新订单"];
$order_list = ['code' => 1, 'msg' => "{$num}个新订单", 'orders' => $orders];
if ($old_info !== json_encode($order_list)) {
file_put_contents($path, json_encode($order_list));
}
return json($info);
} else {
$info = ['code' => 0, 'msg' => '没有新订单'];
if ($old_info !== json_encode($info, 320)) {
file_put_contents($path, json_encode($info, 320));
}
return json($info);
}
} else {
$info = ['code' => 2, 'msg' => '签名错误'];
file_put_contents($path, json_encode($info, 320));
return json($info);
}
}
// 签名 // 签名
private static function getSign(array $param = [], string $key = ''): string private static function getSign(array $param = [], string $key = ''): string
{ {