getPage($params); $limit = $this->getLimit($params); if ($this->getConfigService()->isXLApiType()) { return TaxUserAuth::getPageList($page, $limit, function ($model) use ($params) { // 查询用户表 $model->with(['user' => function ($query) { $query->select('id, avatar_url, nickname, username, mobile'); }]); $model->where(['mall_id' => $this->mall_id, 'status' => TaxUserAuth::STATUS_OK]); if (!empty($params['keyword'])) { $ids = User::getIdsByKeywordAndMallId($this->mall_id, $params['keyword']); $model->andWhere(['in', 'user_id', $ids]); } }); } if ($this->getConfigService()->isLYApiType()) { return LySilentSign::getPageList($page, $limit, function ($model) use ($params) { // 查询用户表 $model->with(['user' => function ($query) { $query->select('id, avatar_url, nickname, username, mobile'); }]); $model->where(['mall_id' => $this->mall_id, 'status' => 1]); $model->select('*, id_card as id_card_no, phone as mobile'); if (!empty($params['keyword'])) { $ids = User::getIdsByKeywordAndMallId($this->mall_id, $params['keyword']); $model->andWhere(['in', 'user_id', $ids]); } }); } } /** * 获取当前用户的认证列表 * * @param integer $user_id * @return array */ public function getUserAuthList(int $user_id) { if ($this->getConfigService()->isXLApiType()) { // 获取前先验证 $list = TaxUserAuth::getUserNotAuthListByOneDay($this->mall_id, $user_id); foreach ($list as $v) { $this->getXlService()->signQuery($v); } return TaxUserAuth::getUserAuthList($this->mall_id, $user_id); } if ($this->getConfigService()->isLYApiType()) { return LySilentSign::getUserAuthList($this->mall_id, $user_id); } } /** * 设置默认 * * @param integer $id * @return boolean */ public function setAuthDefault(int $id) { $db = Yii::$app->db->beginTransaction(); try { if ($this->getConfigService()->isXLApiType()) { /** * @var TaxUserAuth */ $static = TaxUserAuth::class; } if ($this->getConfigService()->isLYApiType()) { /** * @var LySilentSign */ $static = LySilentSign::class; } $auth = $static::getAuthById($this->mall_id, $id); if (empty($auth)) return $this->error('记录不存在'); if ($auth->default == 1) return true; // 设置0 $static::setNotDefault($this->mall_id, $auth->user_id); // 设置默认 $auth->setDefault(); $db->commit(); return true; } catch (\Exception $e) { $db->callback(); return $this->error($e->getMessage()); } } /** * 修改支付宝账号 * * @param integer $id * @param string $mobile * @param string|null $mobile * @return boolean */ public function changeMobile(int $id, string $mobile, $account) { if ($this->getConfigService()->isXLApiType()) { $auth = TaxUserAuth::getUserByIdAndMallId($this->mall_id, $id); if (empty($auth)) { return $this->error('用户账号不存在'); } } if ($this->getConfigService()->isLYApiType()) { $auth = LySilentSign::getUserByIdAndMallId($this->mall_id, $id); if (empty($auth)) { return $this->error('用户账号不存在'); } } return $auth->changeMobile($mobile, $account); } /** * 转换 * * @return boolean */ public function convert() { $users = TaxUserAuth::getAllAuthUsers($this->mall_id); foreach ($users as $user) { $data = [ 'mall_id' => $this->mall_id, 'sign_user' => [ 'user_id' => $user->user_id, 'name' => $user->name, 'id_card' => $user->id_card_no, 'mobile' => $user->mobile, ], ]; // 添加异步导入任务 Yii::$app->services->rabbitMq->push( RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, $data, static::class, 'asyncImportSignUser' ); } } /** * 异步导入 * * @param array $data * [ * 'mall_id' => int, * 'user_id' => int, * 'sign_user' => array * ] * @return void */ public static function asyncImportSignUser(array $data) { $mall_id = $data['mall_id']; $sign_user = $data['sign_user']; $service = new UserService(['mall_id' => $mall_id]); // 查询用户是否签约 $is_sgin = LySilentSign::userIsSignByNMI( $sign_user['user_id'], $sign_user['name'], $sign_user['mobile'], $sign_user['id_card'] ); if (!$is_sgin) { $service->silentSign( $sign_user['user_id'], $sign_user['name'], $sign_user['mobile'], $sign_user['id_card'] ); } } /** * 解除绑定 * * @param integer $id * @return boolean */ public function unbind(int $id) { if ($this->getConfigService()->isXLApiType()) { $auth = TaxUserAuth::getOkAuthById($this->mall_id, $id); if (empty($auth)) { return $this->error('记录不存在'); } return $auth->unbind() ? true : $this->error('解绑失败'); } if ($this->getConfigService()->isLYApiType()) { $auth = LySilentSign::getOkAuthById($this->mall_id, $id); if (empty($auth)) { return $this->error('记录不存在'); } return $auth->setLift() ? true : $this->error('解绑失败'); } } /** * 解除绑定 * * @param integer $user_id * @param integer $id * @return boolean */ public function lift(int $user_id, int $id) { if ($this->getConfigService()->isXLApiType()) { return $this->error('该功能暂未开放'); } if ($this->getConfigService()->isLYApiType()) { $auth = LySilentSign::getSignById($user_id, $id); if (empty($auth)) { return $this->error('记录不存在'); } if ($auth->default) return $this->error('默认签约不能解绑'); return $auth->lift() ? true : $this->error('解绑失败'); } } }