| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- <?php
- namespace addons\AvoidTax\common\service;
- use addons\AvoidTax\common\models\LySilentSign;
- use addons\AvoidTax\common\models\TaxUserAuth;
- use Yii;
- /**
- * 签约相关
- * @package addons\AvoidTax\common\service
- */
- class UserService extends BaseService
- {
- /**
- * 是否签约
- *
- * @param integer $user_id
- * @return array|boolean
- */
- public function checkSign($user_id)
- {
- if ($this->getConfigService()->isXLApiType()) {
- $auth_user = TaxUserAuth::getAccountUser($this->mall_id, $user_id);
- if (empty($auth_user)) {
- return false;
- }
- if ($auth_user['status'] == TaxUserAuth::STATUS_WAIT) {
- // 签约中,查询签约结果
- $service = new XinlongService(['mall_id' => $this->mall_id]);
- $res = $service->signQuery($auth_user);
- if ($res == TaxUserAuth::STATUS_OK) {
- // 已签约成功
- return [
- 'name' => $auth_user['name'],
- 'id_card' => $auth_user['id_card_no'],
- 'mobile' => $auth_user['mobile']
- ];
- }
- }
- if ($auth_user['status'] == TaxUserAuth::STATUS_OK) {
- // 签约成功
- return [
- 'name' => $auth_user['name'],
- 'id_card' => $auth_user['id_card_no'],
- 'mobile' => $auth_user['mobile']
- ];
- }
- return false;
- }
- if ($this->getConfigService()->isLYApiType()) {
- $auth_user = LySilentSign::getSignUser($user_id);
- if (empty($auth_user)) {
- return false;
- }
- return [
- 'name' => $auth_user->name,
- 'id_card' => $auth_user->id_card,
- 'mobile' => $auth_user->phone
- ];
- }
- }
- /**
- * 获取默认详情
- *
- * @param integer $user_id
- * @return array|false
- */
- public function getDefaultSignInfo(int $user_id)
- {
- if ($this->getConfigService()->isXLApiType()) {
- /**
- * @var TaxUserAuth
- */
- $static = TaxUserAuth::class;
- }
- if ($this->getConfigService()->isLYApiType()) {
- /**
- * @var LySilentSign
- */
- $static = LySilentSign::class;
- }
- $auth = $static::getDefaultSignInfo($this->mall_id, $user_id);
- if (empty($auth)) {
- return $this->error('还没有默认提现信息');
- }
- // 如果设置了支付宝账号则替换
- $auth['account'] && $auth['mobile'] = $auth['account'];
- return $auth;
- }
- /**
- * 去签约
- *
- * @FormData(key="参数名|中文名", rule="")
- * @FormData(key="参数名|中文名", rule="")
- * @ApiResponse(code="500", template="error")
- * @ApiResponse(code="200", template="success")
- * @param $user_id
- * @param $mobile
- * @param $id_card
- * @param $name
- *
- * @return bool|array true 已经签约 false 有错误信息 array {签约的url, }
- */
- public function goToSing($user_id, $mobile, $id_card, $name, $redirect_url = null)
- {
- // 签约前校验
- // if (!$this->beforeSignCheckAccount($mobile, $id_card, $name)) {
- // return $this->error('实名信息不一致');
- // }
- try {
- $service = new XinlongService(['mall_id' => $this->mall_id]);
- // 开账户
- $auth_user_model = $service->createAccount($user_id, $mobile, $id_card, $name);
- if ($auth_user_model == false) {
- return $this->error($service->error);
- }
- // 生成签约链接
- $url = $service->goToSign($auth_user_model, $redirect_url);
- return $url === false
- ? $this->error($service->error)
- : [
- 'url' => $url,
- 'accountId' => $auth_user_model->accountId,
- 'flowId' => $auth_user_model->flowId,
- ];
- } catch (\Exception$e) {
- return $this->error($e->getMessage());
- }
- }
- /**
- * 身份信息是否签约, 是否当前签约, 如果不是生成一条已签约记录
- *
- * @param string $idcard
- * @param string $name
- * @param integer $user_id
- * @return boolean
- */
- public function idIsSignAndAddAuthOfUid(string $idcard, string $name, int $user_id, string $mobile = '')
- {
- // xl
- if ($this->getConfigService()->isXLApiType()) {
- $auth = TaxUserAuth::getAutnByIdcardAndName($this->mall_id, $idcard, $name);
- if (empty($auth)) {
- return false;
- }
- // 当前用户已经签约
- if (TaxUserAuth::uidIsSign($this->mall_id, $user_id)) {
- return true;
- }
- // 生成一条新的记录
- if ($auth->createNewAuth($user_id, $mobile) === false) {
- throw new \Exception('生成签约记录失败');
- }
- return true;
- }
- // ly
- if ($this->getConfigService()->isLYApiType()) {
- $auth = LySilentSign::getAutnByIdcardAndName($this->mall_id, $idcard, $name);
- if (empty($auth)) {
- return false;
- }
- // 当前用户已经签约
- if (LySilentSign::uidIsSign($this->mall_id, $user_id)) {
- return true;
- }
- // 生成一条新的记录
- if ($auth->createNewAuth($user_id, $mobile) === false) {
- throw new \Exception('生成签约记录失败');
- }
- return true;
- }
- return false;
- }
- /**
- * 签约
- *
- * @param integer $uid
- * @param string $name
- * @param string $phone
- * @param string $id_card
- * @return boolean
- */
- public function silentSign(int $uid, string $name, string $phone, string $id_card)
- {
- $service = new LuYongService(['mall_id' => $this->mall_id]);
- // 1、查询用户是否签约
- if ($service->querySignUserByIdCard($id_card)) {
- // 1.1、使用签约返回用户信息
- $response = $service->getResponse();
- if (empty($user_data = $response['data'])) return $this->error('未查询到用户签约信息');
- // 1.2、生成签约记录
- if (LySilentSign::addSilentSign(
- $this->mall_id,
- $uid,
- $user_data['name'],
- $phone,
- $user_data['id_card'],
- $this->getConfigService()->getAccountId(),
- $response
- )) {
- return true;
- }
- return $this->error('生成签约记录失败');
- }
- // 2、查询用户是否注册
- if (!$service->queryRegisterUser($id_card)) {
- // 2.1、导入用户信息
- if (!$service->importSignUser($uid, $name, $phone, $id_card)) {
- return $this->error($service->getError());
- }
- }
- // 3、电签
- if ($service->silentSign($uid, $name, $phone, $id_card)) {
- return true;
- }
- return $this->error($service->getError());
- }
- /**
- * 新龙签约
- *
- * @param integer $uid
- * @param string $name
- * @param string $mobile
- * @param string $id_card
- * @return boolean|array
- */
- public function xlSign(int $uid, string $name, string $mobile, string $id_card, $url = '')
- {
- $auth = TaxUserAuth::getAutnByIdcardAndName($this->mall_id, $id_card, $name);
- if (!empty($auth)) {
- if ($auth->createNewAuth($uid, $mobile) === false) {
- return $this->error('添加失败');
- }
- return true;
- }
- // if (TaxUserAuth::isSignWait($uid, $name, $mobile, $id_card)) {
- // return true;
- // }
- // $service = $this->getXlService();
- $res = $this->goToSing(
- $uid,
- $mobile,
- $id_card,
- $name,
- $url
- );
- if ($res === false) {
- return $this->error($this->getError());
- }
- return $res;
- }
- /**
- * 签约前校验账号是否正确(需要跳转到支付宝 无法完成)
- *
- * @param string $mobile
- * @param string $id_card
- * @param string $name
- * @return boolean
- */
- public function beforeSignCheckAccount($mobile, $id_card, $name)
- {
- $service = new AlipayService($this->mall_id);
- $res = $service->certdocCertverifyPreconsult($mobile, $id_card, $name);
- if (!($res && $res->code == '10000')) {
- return $this->error('支付宝配置有误');
- }
- // 验证id
- $verify_id = $res->verify_id;
- $url = $service->getAppAuthorizeUrl($verify_id);
- header('Location:' . $url);
- die;
- $res = $service->certdocCertverifyConsult($verify_id);
- dd($res);
- }
- }
|