| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace addons\RealAuth\api\modules\v1\controllers;
- use addons\RealAuth\common\logic\AuthLogic;
- use Yii;
- use Exception;
- use api\controllers\OnAuthController;
- use common\enums\AddonsEnum;
- use common\enums\ApiStatusEnum;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\RealAuth\api\modules\v1\controllers
- */
- class UserController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['get-setting'];
- /**
- * 首页
- *
- * @return string
- */
- public function actionAuth()
- {
- try{
- $validateService = Yii::$app->services->validate;
- $post = $this->request->post();
- $rules = [
- [['real_name', 'id_no'], 'required'],
- [['real_name', 'id_no'], 'string'],
- [['auth_type'],'integer'],
- [['detail'],'safe'],
- ];
- $labels = [
- 'real_name' => '姓名',
- 'id_no' => '证件号码',
- ];
- $valid = $validateService->validate($post, $rules,$labels);
- if (!$valid) {
- throw new \Exception($validateService->getFirstErrorSummary());
- }
- $logic = new AuthLogic();
- $post['user_id'] = $this->user_id;
- $post['mall_id'] = $this->mall_id;
- $res = $logic->auth($post);
- if(!$res){
- throw new Exception('认证失败');
- }
- return $this->success($res);
- }catch(Exception $e){
- return $this->error($e->getMessage());
- }
- }
- /**
- * 认证升级
- *
- * @return string
- */
- public function actionAuthUpgrade()
- {
- try{
- $validateService = Yii::$app->services->validate;
- $post = $this->request->post();
- $rules = [
- [['real_name', 'id_no'], 'required'],
- [['real_name', 'id_no'], 'string'],
- [['auth_type'],'integer'],
- [['detail'],'safe'],
- ];
- $labels = [
- 'real_name' => '姓名',
- 'id_no' => '证件号码',
- ];
- $valid = $validateService->validate($post, $rules,$labels);
- if (!$valid) {
- throw new \Exception($validateService->getFirstErrorSummary());
- }
- $logic = new AuthLogic();
- $post['user_id'] = $this->user_id;
- $post['mall_id'] = $this->mall_id;
- $res = $logic->authUpgrade($post);
- if(!$res){
- throw new Exception('认证失败');
- }
- $config = Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_REAL_AUTH, 'basic');
- $msg = '企业信息已提交,工作人员将于'.$config['business_verify_time'].'小时内完成审核';
- return $this->success($msg);
- }catch(Exception $e){
- return $this->error($e->getMessage());
- }
- }
- /**
- * 获取设置
- *
- * @return string
- */
- public function actionGetSetting()
- {
- try{
- $logic = new AuthLogic();
- $data = $logic->getSetting($this->mall_id,$this->user_id);
- return $this->success('请求成功', $data);
- }catch(Exception $e){
- return $this->error($e->getMessage());
- }
- }
- /**
- * 认证详情
- *
- * @return string
- */
- public function actionAuthDetail()
- {
- try{
- $logic = new AuthLogic();
- $data = $logic->getAuthDetail($this->mall_id,$this->user_id);
- return $this->success('请求成功', $data,ApiStatusEnum::CODE_SUCCESS,JSON_UNESCAPED_UNICODE);
- }catch(Exception $e){
- return $this->error($e->getMessage());
- }
- }
- }
|