抖音小程序

Controller.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Error;
  4. use Illuminate\Foundation\Bus\DispatchesJobs;
  5. use Illuminate\Routing\Controller as BaseController;
  6. use Illuminate\Foundation\Validation\ValidatesRequests;
  7. use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  8. class Controller extends BaseController
  9. {
  10. use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
  11. /*
  12. * 初始化
  13. * */
  14. public function __construct()
  15. {
  16. }
  17. public static function returnValue($data = [], $errorNo = 0, $errorSuffix = '') {
  18. return [
  19. "rst" => $data,
  20. "errno" => $errorNo . '',
  21. "err" => empty($errorSuffix) ? Error::getError($errorNo) : $errorSuffix,
  22. "timestamp" => intval(microtime(true)) . '',
  23. // 客户端代码版本号,用于客户端自动加载新提交的代码
  24. // 'v' => (string) get_client_code_version(),
  25. "auno" => '0'
  26. ];
  27. }
  28. /**
  29. * 统一分页响应格式
  30. * @param $data
  31. * @param $total
  32. * @param $pageSize
  33. * @param int $page
  34. * @param null $extra
  35. * @return array
  36. */
  37. public static function returnPageValue($data, $total, $pageSize, $page, $extra = null)
  38. {
  39. $pages = $pageSize > 0 ? ceil($total / $pageSize) : 0;
  40. $result = [
  41. 'data' => $data,
  42. 'pageInfo' => [
  43. 'total' => $total,
  44. 'pages' => $pages,
  45. 'size' => $pageSize,
  46. 'page' => $page
  47. ]
  48. ];
  49. if( $extra !== null){
  50. $result['extra'] = $extra;
  51. }
  52. return self::returnValue($result);
  53. }
  54. }