UserController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace addons\RealAuth\api\modules\v1\controllers;
  3. use addons\RealAuth\common\logic\AuthLogic;
  4. use Yii;
  5. use Exception;
  6. use api\controllers\OnAuthController;
  7. use common\enums\AddonsEnum;
  8. use common\enums\ApiStatusEnum;
  9. /**
  10. * 默认控制器
  11. *
  12. * Class DefaultController
  13. * @package addons\RealAuth\api\modules\v1\controllers
  14. */
  15. class UserController extends OnAuthController
  16. {
  17. public $modelClass = '';
  18. /**
  19. * 不用进行登录验证的方法
  20. *
  21. * 例如: ['index', 'update', 'create', 'view', 'delete']
  22. * 默认全部需要验证
  23. *
  24. * @var array
  25. */
  26. protected $authOptional = ['get-setting'];
  27. /**
  28. * 首页
  29. *
  30. * @return string
  31. */
  32. public function actionAuth()
  33. {
  34. try{
  35. $validateService = Yii::$app->services->validate;
  36. $post = $this->request->post();
  37. $rules = [
  38. [['real_name', 'id_no'], 'required'],
  39. [['real_name', 'id_no'], 'string'],
  40. [['auth_type'],'integer'],
  41. [['detail'],'safe'],
  42. ];
  43. $labels = [
  44. 'real_name' => '姓名',
  45. 'id_no' => '证件号码',
  46. ];
  47. $valid = $validateService->validate($post, $rules,$labels);
  48. if (!$valid) {
  49. throw new \Exception($validateService->getFirstErrorSummary());
  50. }
  51. $logic = new AuthLogic();
  52. $post['user_id'] = $this->user_id;
  53. $post['mall_id'] = $this->mall_id;
  54. $res = $logic->auth($post);
  55. if(!$res){
  56. throw new Exception('认证失败');
  57. }
  58. return $this->success($res);
  59. }catch(Exception $e){
  60. return $this->error($e->getMessage());
  61. }
  62. }
  63. /**
  64. * 认证升级
  65. *
  66. * @return string
  67. */
  68. public function actionAuthUpgrade()
  69. {
  70. try{
  71. $validateService = Yii::$app->services->validate;
  72. $post = $this->request->post();
  73. $rules = [
  74. [['real_name', 'id_no'], 'required'],
  75. [['real_name', 'id_no'], 'string'],
  76. [['auth_type'],'integer'],
  77. [['detail'],'safe'],
  78. ];
  79. $labels = [
  80. 'real_name' => '姓名',
  81. 'id_no' => '证件号码',
  82. ];
  83. $valid = $validateService->validate($post, $rules,$labels);
  84. if (!$valid) {
  85. throw new \Exception($validateService->getFirstErrorSummary());
  86. }
  87. $logic = new AuthLogic();
  88. $post['user_id'] = $this->user_id;
  89. $post['mall_id'] = $this->mall_id;
  90. $res = $logic->authUpgrade($post);
  91. if(!$res){
  92. throw new Exception('认证失败');
  93. }
  94. $config = Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_REAL_AUTH, 'basic');
  95. $msg = '企业信息已提交,工作人员将于'.$config['business_verify_time'].'小时内完成审核';
  96. return $this->success($msg);
  97. }catch(Exception $e){
  98. return $this->error($e->getMessage());
  99. }
  100. }
  101. /**
  102. * 获取设置
  103. *
  104. * @return string
  105. */
  106. public function actionGetSetting()
  107. {
  108. try{
  109. $logic = new AuthLogic();
  110. $data = $logic->getSetting($this->mall_id,$this->user_id);
  111. return $this->success('请求成功', $data);
  112. }catch(Exception $e){
  113. return $this->error($e->getMessage());
  114. }
  115. }
  116. /**
  117. * 认证详情
  118. *
  119. * @return string
  120. */
  121. public function actionAuthDetail()
  122. {
  123. try{
  124. $logic = new AuthLogic();
  125. $data = $logic->getAuthDetail($this->mall_id,$this->user_id);
  126. return $this->success('请求成功', $data,ApiStatusEnum::CODE_SUCCESS,JSON_UNESCAPED_UNICODE);
  127. }catch(Exception $e){
  128. return $this->error($e->getMessage());
  129. }
  130. }
  131. }