BaseLogic.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. use think\facade\Log;
  16. /**
  17. * 逻辑基类
  18. * Class BaseLogic
  19. * @package app\common\logic
  20. */
  21. class BaseLogic
  22. {
  23. /**
  24. * 错误信息
  25. * @var string
  26. */
  27. protected static $error;
  28. /**
  29. * 返回状态码
  30. * @var int
  31. */
  32. protected static $returnCode = 0;
  33. protected static $returnData;
  34. /**
  35. * @notes 获取错误信息
  36. * @return string
  37. * @author 段誉
  38. * @date 2021/7/21 18:23
  39. */
  40. public static function getError() : string
  41. {
  42. if (false === self::hasError()) {
  43. return '系统错误';
  44. }
  45. return self::$error;
  46. }
  47. /**
  48. * @notes 设置错误信息
  49. * @param $error
  50. * @author 段誉
  51. * @date 2021/7/21 18:20
  52. */
  53. public static function setError($error) : void
  54. {
  55. Log::debug('BaseLogic:setError:'.$error);
  56. !empty($error) && self::$error = $error;
  57. }
  58. /**
  59. * @notes 是否存在错误
  60. * @return bool
  61. * @author 段誉
  62. * @date 2021/7/21 18:32
  63. */
  64. public static function hasError() : bool
  65. {
  66. return !empty(self::$error);
  67. }
  68. /**
  69. * @notes 设置状态码
  70. * @param $code
  71. * @author 段誉
  72. * @date 2021/7/28 17:05
  73. */
  74. public static function setReturnCode($code) : void
  75. {
  76. self::$returnCode = $code;
  77. }
  78. /**
  79. * @notes 特殊场景返回指定状态码,默认为0
  80. * @return int
  81. * @author 段誉
  82. * @date 2021/7/28 15:14
  83. */
  84. public static function getReturnCode() : int
  85. {
  86. return self::$returnCode;
  87. }
  88. /**
  89. * @notes 获取内容
  90. * @return mixed
  91. * @author cjhao
  92. * @date 2021/9/11 17:29
  93. */
  94. public static function getReturnData()
  95. {
  96. return self::$returnData;
  97. }
  98. }