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(); } }