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.

135 lines
5.0 KiB

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