love_php/app/Jobs/AddUnionUser.php

67 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2026-04-02 09:20:51 +08:00
<?php
namespace App\Jobs;
use App\Services\UserService;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class AddUnionUser implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $user;
protected $password;
protected $source;
protected $userService;
public $tries = 3;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($user, $password, $source=null)
{
$this->user = $user;
$this->password = $password;
$this->source = $source;
$this->userService = new UserService;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
if(!empty($this->user))
{
$mobile = $this->user->mobile;
if (empty($mobile)) { //公众号不存在手机号
$mobile = 'u'.uniqid();
}
$openid = $this->user->openid;
$password = $this->password;
$email = null;
if ($this->source == 'SPA') {
$email = $this->user->email;
}
//创建基表账号
$union_user = $this->userService->addUnionUser($mobile,$password, $this->source, $email, $openid);
//绑定基表id
if (!empty($union_user) && empty($this->user->uuid))
{
$this->user->uuid = $union_user->id;
$this->user->save();
}
}
}
}