<?php

namespace app\util;

use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Firebase\JWT\ExpiredException;
use Firebase\JWT\SignatureInvalidException;
use support\exception\BusinessException;
use support\Request;

class Util
{
    /**
     * 参数是否为空
     */
    public static function isEmpty($param)
    {
        if(!empty($param) || $param == 0){
            $result = false;
        }else{
            $result = true;
        }
        return $result;
    }

    /**
     * 参数是否为空
     */
    public static function getParam(Request $request,$param,$default='')
    {
        $param = $request->input($param,$default);
        return $param;
    }

    /**
     * 失败
     */
    public static function fail($data = [],$message = '',  $code = '500')
    {
        $result = [
            'code' => $code,
            'message' => $message,
            'data' => $data
        ];
        return json($result);
    }

    /**
     * 成功
     */
    public static function success($data = [],$message = '',  $code = '200')
    {
        $result = [
            'code' => $code,
            'message' => $message,
            'data' => $data
        ];
        return json($result);
    }

    /**
     * 分页查询返回
     */
    public static function page($data,$message = '',  $code = '200')
    {
        $result = [
            'code' => $code,
            'message' => $message
        ];

        $result['data'] = [
            'list' => $data->items(),      // 当前页数据
            'total' => $data->total(),     // 总记录数
            'current_page' => $data->currentPage(),
            'per_page' => $data->perPage(),
            'last_page' => $data->lastPage()
        ];
        return json($result);
    }


}