BaseLogic.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\common\logic;
  15. /**
  16. * 逻辑基类
  17. * Class BaseLogic
  18. * @package app\common\logic
  19. */
  20. class BaseLogic
  21. {
  22. /**
  23. * 错误信息
  24. * @var string
  25. */
  26. protected static $error;
  27. /**
  28. * 返回状态码
  29. * @var int
  30. */
  31. protected static $returnCode = 0;
  32. protected static $returnData;
  33. /**
  34. * @notes 获取错误信息
  35. * @return string
  36. * @author 段誉
  37. * @date 2021/7/21 18:23
  38. */
  39. public static function getError() : string
  40. {
  41. if (false === self::hasError()) {
  42. return '系统错误';
  43. }
  44. return self::$error;
  45. }
  46. /**
  47. * @notes 设置错误信息
  48. * @param $error
  49. * @author 段誉
  50. * @date 2021/7/21 18:20
  51. */
  52. public static function setError($error) : void
  53. {
  54. !empty($error) && self::$error = $error;
  55. }
  56. /**
  57. * @notes 是否存在错误
  58. * @return bool
  59. * @author 段誉
  60. * @date 2021/7/21 18:32
  61. */
  62. public static function hasError() : bool
  63. {
  64. return !empty(self::$error);
  65. }
  66. /**
  67. * @notes 设置状态码
  68. * @param $code
  69. * @author 段誉
  70. * @date 2021/7/28 17:05
  71. */
  72. public static function setReturnCode($code) : void
  73. {
  74. self::$returnCode = $code;
  75. }
  76. /**
  77. * @notes 特殊场景返回指定状态码,默认为0
  78. * @return int
  79. * @author 段誉
  80. * @date 2021/7/28 15:14
  81. */
  82. public static function getReturnCode() : int
  83. {
  84. return self::$returnCode;
  85. }
  86. /**
  87. * @notes 获取内容
  88. * @return mixed
  89. * @author cjhao
  90. * @date 2021/9/11 17:29
  91. */
  92. public static function getReturnData()
  93. {
  94. return self::$returnData;
  95. }
  96. }