feat : phone pool
This commit is contained in:
@@ -203,6 +203,7 @@ abstract class LoginBaseService extends BaseService
|
||||
$model->nickname = '用户'.StringUtil::randStr(6);
|
||||
$model->avatar_id = 0;
|
||||
$model->reg_ip = SystemUtil::getClientIp();
|
||||
$model->mobile = $this->mobile;
|
||||
|
||||
if (!$model->save()) throw new ErrException('数据保存失败-注册失败');
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use App\Event\RegistrationEvent;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\UserAccount;
|
||||
use App\Model\UserThird;
|
||||
use App\Service\ServiceTrait\Api\PhonePoolTrait;
|
||||
use App\Service\ServiceTrait\Api\WxMiniTrait;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@@ -26,6 +27,7 @@ use RedisException;
|
||||
class WxFastLoginService extends LoginBaseService
|
||||
{
|
||||
use WxMiniTrait;
|
||||
use PhonePoolTrait;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
@@ -56,6 +58,7 @@ class WxFastLoginService extends LoginBaseService
|
||||
|
||||
$wxPhone = $this->jsCodeGetPhoneNumber($phoneCode);
|
||||
$this->mobile = $wxPhone['phone_info']['purePhoneNumber'] ?? '';
|
||||
if ($this->mobile == '') throw new ErrException('手机号获取失败');
|
||||
|
||||
$this->checkLock(self::LOGIN_TYPE);
|
||||
|
||||
@@ -72,6 +75,8 @@ class WxFastLoginService extends LoginBaseService
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function updateMobile(): void
|
||||
{
|
||||
@@ -82,6 +87,8 @@ class WxFastLoginService extends LoginBaseService
|
||||
$this->userInfo->mobile = $this->mobile;
|
||||
|
||||
if (!$this->userInfo->save()) throw new ErrException('更新手机号失败');
|
||||
|
||||
$this->addMobilePhone($this->mobile);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
34
app/Service/ServiceTrait/Api/PhonePoolTrait.php
Normal file
34
app/Service/ServiceTrait/Api/PhonePoolTrait.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\ServiceTrait\Api;
|
||||
|
||||
use App\Lib\Log;
|
||||
use App\Model\PhonePool;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
trait PhonePoolTrait
|
||||
{
|
||||
/**
|
||||
* @var Log
|
||||
*/
|
||||
#[Inject]
|
||||
protected Log $log;
|
||||
|
||||
/**
|
||||
* @param string $mobile
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function addMobilePhone(string $mobile): void
|
||||
{
|
||||
if (empty($mobile)) return;
|
||||
|
||||
$insertModel = new PhonePool();
|
||||
|
||||
$insertModel->phone = $mobile;
|
||||
if (!$insertModel->save()) $this->log->error('添加手机号到池子失败,mobile:'.$mobile);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user