love_php/app/Jobs/AddLiveGuestRank.php

73 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2026-04-02 09:20:51 +08:00
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Models\User;
use App\Utils\Messenger;
use App\Models\Message;
use App\Models\RankHistory;
class AddLiveGuestRank implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $user_ids;
protected $type;
protected $month;
protected $message;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($array)
{
$this->user_ids = $array['user_ids'];
$this->type = $array['type'];
$this->month = $array['month'];
$this->message = $array['message'];
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$user_ids = $this->user_ids;
if (empty(count($user_ids))) return;
$message = $this->message;
$type = $this->type;
foreach ($user_ids as $user_id) {
$user = User::find($user_id);
if (empty($user) || $user->type != 'single') continue;
//增加会员
$log = RankHistory::where('user_id', $user_id)->where('type', $type)->first();
if ($log) continue;
$user->addSuperRank(0, $this->month, $type);
//短信通知
$this->sentMessage($user->mobile, $message);
}
}
//发送普通消息
function sentMessage($mobile, $message){
if (empty($mobile)) {
return true;
}
Message::create([
'phone'=>$mobile,
'message'=>$message,
'confirmed' => 1,
'ip' => request()?request()->ip():'127.0.0.1',
]);
Messenger::sendSMS($mobile, $message);
return true;
}
}