You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.5 KiB

7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
  1. <?php
  2. namespace App\Common;
  3. class ReturnData
  4. {
  5. //通用
  6. const SUCCESS = 0; //操作成功
  7. const FAIL = 1; //操作失败
  8. const FORBIDDEN = 8001; //权限不足
  9. const SYSTEM_FAIL = 8002; //系统错误,如数据写入失败之类的
  10. const PARAMS_ERROR = 8003; //参数错误
  11. const NOT_FOUND = 8004; //资源未找到
  12. const TOKEN_ERROR = 8005; //token错误
  13. const SIGN_ERROR = 8006; //签名错误
  14. const RECORD_EXIST = 8007; //记录已存在
  15. const RECORD_NOT_EXIST = 8008; //记录不存在
  16. const NOT_MODIFY = 8009; //没有变动
  17. const UNKNOWN_ERROR = 8010; //未知错误
  18. const INVALID_VERIFYCODE = 8011; //无效验证码
  19. //参数相关
  20. const EMAIL_EXIST = 8201; //邮箱已存在
  21. const EMAIL_FORMAT_FAIL = 8202; //邮箱格式不对正确
  22. const MOBILE_NOT_FIND = 8204; //手机号码不存在
  23. const MOBILE_HAS_MORE = 8205; //存在多个手机号码
  24. const NAME_EXIST = 8206; //名称已被使用
  25. const MOBILE_EXIST = 8207; //手机号已存在
  26. const NOT_UP_GRADE = 8208; //不符合升级条件
  27. const NOT_DOWN_GRADE = 8209; //不符合降级条件
  28. //登录、账号相关
  29. const USERNAME_REQUIRED = 8401; //登录账号为必填
  30. const PASSWORD_REQUIRED = 8402; //登录密码为必填
  31. const USERNAME_EXIST = 8403; //登录账号已被使用
  32. const ADMINNAME_REQUIRED = 8404; //管理员姓名不能为空
  33. const PASSWORD_NOT_MATCH = 8405; //密码错误
  34. const OLD_PASSWORD_NOT_MATCH = 8406; //旧密码不匹配
  35. const PASSWORD_CONFIRM_FAIL = 8407; //两次输入的密码不匹配
  36. const PASSWORD_FORMAT_FAIL = 8408; //密码格式不对
  37. const APPLY_SIGN_FAIL = 8510; //注册邀请码错误
  38. //验证码
  39. const CODE_NOT_EXIST = 8801; //当前状态不能操作
  40. //app
  41. const AUTH_FAIL = 9001; //鉴权失败
  42. const TOKEN_EXP = 9002; //Token失效
  43. const MOBILE_FORMAT_FAIL = 9003; //手机格式不正确
  44. const VERIFY_TYPE_FAIL = 9004; //验证码业务类型无效
  45. const BANK_TYPE_FAIL = 9005; //该银行不支持
  46. const INVALID_IDCARD = 9006;//身份证无效
  47. const REQUEST_AMOUNT_MIN_LESS = 9007;//小于最小提现金额
  48. const SERVICE_AMOUNT_NOT_ENOUGH = 9008;//可提现余额不足
  49. //中文错误详情
  50. public static $codeTexts = array(
  51. 0 => '操作成功',
  52. 1 => '操作失败',
  53. 8001 => '权限不足',
  54. 8002 => '系统错误,请联系管理员',
  55. 8003 => '参数错误',
  56. 8004 => '资源未找到',
  57. 8005 => 'token错误',
  58. 8006 => '签名错误',
  59. 8007 => '记录已存在',
  60. 8008 => '记录不存在',
  61. 8009 => '没有变动',
  62. 8010 => '未知错误',
  63. 8011 => '无效验证码',
  64. //参数错误
  65. 8201 => '邮箱已存在',
  66. 8202 => '邮箱格式不对正确',
  67. 8204 => '手机号码不存在',
  68. 8205 => '存在多个手机号码',
  69. 8206 => '名称已被使用',
  70. 8207 => '手机号已存在',
  71. 8208 => '不符合升级条件',
  72. 8209 => '不符合降级条件',
  73. //登录、账号相关
  74. 8401 => '登录账号为必填',
  75. 8402 => '登录密码为必填',
  76. 8403 => '登录账号已被使用',
  77. 8404 => '管理员姓名不能为空',
  78. 8405 => '登录失败',
  79. 8406 => '原密码不匹配',
  80. 8407 => '两次输入的密码不匹配',
  81. 8408 => '密码格式错误,请输入%s到%s位字符',
  82. 8510 => '注册邀请码不存在或已被使用',
  83. //app
  84. 9001 => '鉴权失败',
  85. 9002 => 'Token失效',
  86. 9003 => '手机格式不正确',
  87. 9004 => '验证码业务类型无效',
  88. 9005 => '该银行不支持',
  89. 9006 => '身份证无效',
  90. 9007 => '小于最小提现金额',
  91. 9008 => '可提现余额不足',
  92. //验证码
  93. 8801 =>'验证码无效',
  94. );
  95. public static function create($code, $data = null, $msg = '')
  96. {
  97. if (empty($msg) && isset(self::$codeTexts[$code]))
  98. {
  99. $msg = self::$codeTexts[$code];
  100. }
  101. return self::custom($code, $msg, $data);
  102. }
  103. public static function success($data = null, $msg = '')
  104. {
  105. if (empty($msg) && isset(self::$codeTexts[self::SUCCESS]))
  106. {
  107. $msg = self::$codeTexts[self::SUCCESS];
  108. }
  109. return self::custom(self::SUCCESS, $msg, $data);
  110. }
  111. public static function error($code, $data = null, $msg = '')
  112. {
  113. if (empty($msg) && isset(self::$codeTexts[$code]))
  114. {
  115. $msg = self::$codeTexts[$code];
  116. }
  117. if ($code == self::SUCCESS)
  118. {
  119. $code = self::SYSTEM_FAIL;
  120. $msg = '系统错误';
  121. }
  122. return self::custom($code, $msg, $data);
  123. }
  124. public static function custom($code, $msg = '', $data = null)
  125. {
  126. return array('code' => $code, 'msg' => $msg, 'data' => $data);
  127. }
  128. //判断是否成功
  129. public static function checkSuccess($data)
  130. {
  131. if ($data['code'] == self::SUCCESS){return true;}
  132. return false;
  133. }
  134. public static function getCodeText($code)
  135. {
  136. $res = '';
  137. if (isset(self::$codeTexts[$code]))
  138. {
  139. $res = self::$codeTexts[$code];
  140. }
  141. return $res;
  142. }
  143. }