| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- namespace addons\AvoidTax\api\controllers;
- use addons\AvoidTax\common\models\TaxUserAuth;
- use addons\AvoidTax\common\service\AuthService;
- use addons\AvoidTax\common\service\UserService;
- use addons\AvoidTax\common\service\XinlongService;
- use api\controllers\OnAuthController;
- use common\enums\ApiStatusEnum;
- use common\helpers\ArrayHelper;
- use Yii;
- class UserController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * @var UserService $service
- */
- public $service;
- public function __construct ($id, $module, $config = [])
- {
- parent::__construct($id, $module, $config);
- }
- public function beforeAction ($action)
- {
- if (!parent::beforeAction($action)) {
- return false;
- }
- $this->service = new UserService(['mall_id'=>$this->mall_id]);
- return true;
- }
- /**
- * 检查是否签约
- * @GetApi(path="actionCheckSign",summary="actionCheckSign")
- * @FormData(key="参数名|中文名", rule="")
- * @FormData(key="参数名|中文名", rule="")
- * @ApiResponse(code="500", template="error")
- * @ApiResponse(code="200", template="success")
- */
- public function actionCheckSign()
- {
- // 检测
- $this->service->checkSign($this->user_id);
- $service = new UserService(['mall_id'=>$this->mall_id]);
- $data = $service->getDefaultSignInfo($this->user_id);
- $data['is_sign'] = !empty($data) ? true : false;
- return $this->success_str('ok', !empty($data) ? $data : []);
- }
- /**
- * 去签约
- * @GetApi(path="actionGoToSign",summary="actionGoToSign")
- * @FormData(key="参数名|中文名", rule="")
- * @FormData(key="参数名|中文名", rule="")
- * @ApiResponse(code="500", template="error")
- * @ApiResponse(code="200", template="success")
- */
- public function actionGoToSign()
- {
- $data = $this->request->post();
- $res = Yii::$app->services->validate->validate($data, [
- [
- ['mobile', 'id_card', 'name', 'ali_account'], 'required'],
- ],
- [
- 'mobile' => '手机号码',
- 'id_card' => '身份证',
- 'name' => '姓名',
- 'ali_account'=> '支付宝账号',
- ]
- );
- if( $res === false ) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $url = $this->service->goToSing($this->user_id,...array_values($data));
- // 已经签约
- if ( $url === true ) return $this->success('已签约,不需要重复签约',['is_sign'=>true,'url'=>'']);
- // 有错误
- if ( $url === false ) return $this->error('签约失败:'.$this->service->error);
- // 跳转url
- return $this->success('跳转url进行签约',['is_sign'=>false,'url'=>$url]);
- }
- /**
- * 获取用户签约列表
- *
- * @return void
- */
- public function actionAuthList()
- {
- $service = new AuthService(['mall_id' => $this->mall_id]);
- return $this->success_str('ok', $service->getUserAuthList($this->user_id));
- }
- /**
- * 创建签约
- *
- * @return void
- */
- public function actionCreateAccount()
- {
- $params = \Yii::$app->request->post();
- $res = \Yii::$app->services->validate->validate($params, [
- [['mobile'], 'required', 'message' => '请填写手机号码'],
- [['id_card'], 'required', 'message' => '请填写身份证号码'],
- [['name'], 'required', 'message' => '请填写姓名'],
- ['mobile', 'match', 'pattern' => '/^1\d{10}/', 'message' => '请输入正确的手机号码'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- try {
- $service = new UserService(['mall_id' => $this->mall_id]);
- // 新龙
- if ($service->getConfigService()->isXLApiType()) {
- $res = $service->xlSign(
- $this->user_id, $params['name'], $params['mobile'], $params['id_card']
- );
- if ($res === true) {
- return $this->success('签约成功');
- }
- if ($res === false) {
- return $this->error($service->getError());
- }
- return $this->success('ok', $res);
- }
- // 鹿用
- if ($service->getConfigService()->isLYApiType()) {
- $res = $service->silentSign($this->user_id, $params['name'], $params['mobile'], $params['id_card']);
- if ($res === false) {
- return $this->error($service->getError());
- }
- return $this->success('签约成功');
- }
- } catch (\Exception $e) {
- return $this->error('申请失败:' . $e->getMessage());
- }
- }
- /**
- * 设置默认
- *
- * @return void
- **/
- public function actionSetDefault()
- {
- $id = $this->request->get('id');
- $service = new AuthService(['mall_id' => $this->mall_id]);
-
- return $service->setAuthDefault($id)
- ? $this->success('ok')
- : $this->error($service->getError());
- }
- /**
- * 解除签约
- *
- * @param integer $id
- * @return string|array
- */
- public function actionLift(int $id)
- {
- $service = new AuthService(['mall_id' => $this->mall_id]);
- return $service->lift($this->user_id, $id)
- ? $this->success('ok')
- : $this->error($service->getError());
- }
- /**
- * 请求成功统消息格式化处理
- * @Author bing
- * @DateTime 2020-10-27 15:43:16
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param string $msg
- * @param array $data
- * @param [type] $code
- * @return void|mixed
- */
- private function success_str($msg = '操作成功', $data = [], $code = ApiStatusEnum::CODE_SUCCESS)
- {
- if (is_object($data)) $data = ArrayHelper::toArray($data);
- Yii::$app->controller->asJson(json_decode(json_encode(array(
- 'code' => $code,
- 'msg' => $msg,
- 'data' => $data
- )), true))->send();
- }
- }
|