love_php/app/Jobs/AddShareRank.php

57 lines
1.4 KiB
PHP
Raw 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\Wechat;
use App\Models\User;
use App\Models\RankHistory;
class AddShareRank implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $openid;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($openid)
{
$this->openid = $openid;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//判断是否是会员
$user_id = Wechat::where('openid', $openid)->first();
$user = User::where('id', $user_id)->first();
if ($user->rank_id == 0) {
if ($user->type == 'marriage') {
return;
}
//邀请人数
$invite_count = User::where('from_openid', $this->openid)->count();
if ($invite_count >= 5) {
//市级会员
$rank_id = 1;
$user->rank_id = $rank_id;
$user-save();
//添加会员记录
RankHistory::create([
'user_id'=>$user_id,
'rank_id'=>$rank_id,
]);
}
}
}
}