mirror of
				https://gitee.com/technical-laohu/mpay.git
				synced 2025-11-04 08:43:42 +08:00 
			
		
		
		
	优化可读性
This commit is contained in:
		@@ -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)
 | 
			
		||||
    {
 | 
			
		||||
@@ -307,6 +272,41 @@ class PayController
 | 
			
		||||
            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
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user