Helper.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. namespace SixShop\Core;
  4. use SixShop\Core\Exception\LogicException;
  5. use think\Paginator;
  6. use think\Response;
  7. /**
  8. * 助手类
  9. * @deprecated 类已弃用, 请使用函数版本的助手方法
  10. */
  11. final class Helper
  12. {
  13. /**
  14. * 返回成功数据
  15. * @deprecated 函数已弃用, 请使用 success_response()
  16. */
  17. public static function success_response(mixed $data = [], string $status = 'ok', int $code = 200, string $msg = 'success', string $type = 'json', string $xslt = ''): Response
  18. {
  19. return success_response($data, $status, $code, $msg, $type, $xslt);
  20. }
  21. /**
  22. * 返回分页数据
  23. * @deprecated 函数已弃用, 请使用 page_response()
  24. */
  25. public static function page_response(Paginator $page, mixed $data = [], string $status = 'ok', int $code = 200, string $msg = 'success'): Response
  26. {
  27. return json([
  28. 'code' => $code,
  29. 'status' => $status,
  30. 'msg' => $msg,
  31. 'page' => $page,
  32. 'data' => $data
  33. ]);
  34. }
  35. /**
  36. * 抛出逻辑异常
  37. * @throws LogicException
  38. * @deprecated 函数已弃用, 请使用 throw_logic_exception()
  39. */
  40. public static function throw_logic_exception(string $msg = 'error', int $code = 1, string $status = 'error', mixed $data = [], int $httpCode = 200, $header = [], $options = []): void
  41. {
  42. throw new LogicException(error_response($msg, $status, $code, $data, $httpCode, $header, $options));
  43. }
  44. /**
  45. * 返回失败数据
  46. * @deprecated 函数已弃用, 请使用 error_response()
  47. */
  48. public static function error_response(string $msg = 'error', string $status = 'error', int $code = 1, mixed $data = [], int $httpCode = 400, $header = [], $options = []): Response
  49. {
  50. return json([
  51. 'code' => $code,
  52. 'status' => $status,
  53. 'msg' => $msg,
  54. 'data' => $data
  55. ], $httpCode, $header, $options);
  56. }
  57. }