123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace App\Http\Controllers;
- use App\Error;
- use Illuminate\Foundation\Bus\DispatchesJobs;
- use Illuminate\Routing\Controller as BaseController;
- use Illuminate\Foundation\Validation\ValidatesRequests;
- use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
- class Controller extends BaseController
- {
- use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
- /*
- * 初始化
- * */
- public function __construct()
- {
- }
- public static function returnValue($data = [], $errorNo = 0, $errorSuffix = '') {
- return [
- "rst" => $data,
- "errno" => $errorNo . '',
- "err" => empty($errorSuffix) ? Error::getError($errorNo) : $errorSuffix,
- "timestamp" => intval(microtime(true)) . '',
- // 客户端代码版本号,用于客户端自动加载新提交的代码
- // 'v' => (string) get_client_code_version(),
- "auno" => '0'
- ];
- }
- /**
- * 统一分页响应格式
- * @param $data
- * @param $total
- * @param $pageSize
- * @param int $page
- * @param null $extra
- * @return array
- */
- public static function returnPageValue($data, $total, $pageSize, $page, $extra = null)
- {
- $pages = $pageSize > 0 ? ceil($total / $pageSize) : 0;
- $result = [
- 'data' => $data,
- 'pageInfo' => [
- 'total' => $total,
- 'pages' => $pages,
- 'size' => $pageSize,
- 'page' => $page
- ]
- ];
- if( $extra !== null){
- $result['extra'] = $extra;
- }
- return self::returnValue($result);
- }
- }
|