Common.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Common.php UTF-8
  4. *
  5. *
  6. * @date : 2021/5/6 09:49
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HUOSDK-IDENTITY 1.0
  11. */
  12. namespace huoIdentify\controller;
  13. use huolib\status\IdentifyStatus;
  14. class Common {
  15. /**
  16. * 返回错误信息
  17. *
  18. * @param int $code
  19. * @param string $msg
  20. * @param array $data
  21. *
  22. * @return array
  23. */
  24. public function huoError($code = 400, $msg = '', $data = []) {
  25. return $this->huoSuccess($code, $msg, $data);
  26. }
  27. /**
  28. * 逻辑处理返回信息
  29. *
  30. * @param int $code
  31. * @param string $msg
  32. * @param array $data
  33. *
  34. * @return array
  35. */
  36. public function huoSuccess($code = IdentifyStatus::NO_ERROR, $msg = '', $data = []) {
  37. $_rdata['code'] = $code;
  38. $_rdata['msg'] = $msg;
  39. $_rdata['data'] = $data;
  40. return $_rdata;
  41. }
  42. /**
  43. * @param array $data
  44. *
  45. * @return array
  46. */
  47. public function huoReturn($data) {
  48. return $this->huoSuccess($data['code'], $data['msg'], $data['data']);
  49. }
  50. /**
  51. * @param int $code
  52. * @param array $data
  53. *
  54. * @return array
  55. */
  56. protected function retSucMsg($code = IdentifyStatus::NO_ERROR, $data = []) {
  57. $_msg = IdentifyStatus::getMsg($code);
  58. return $this->huoSuccess($code, $_msg, $data);
  59. }
  60. /**
  61. * @param $code
  62. *
  63. * @return mixed
  64. */
  65. protected function retErrMsg($code) {
  66. $_err_msg = IdentifyStatus::getMsg($code);
  67. return $this->huoError($code, $_err_msg);
  68. }
  69. }