61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\DrawActivity;
|
|
use App\Models\DrawTicketLog;
|
|
use App\Models\User;
|
|
use App\Services\DrawTicketService;
|
|
use Illuminate\Console\Command;
|
|
|
|
/**
|
|
* 每月赠送用户抽奖次数
|
|
*/
|
|
class DrawTicketSendMonthly extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'draw-activity:ticket-send-monthly';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '每月赠送用户抽奖次数';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
// 有效的抽奖活动
|
|
$drawActivity = DrawActivity::onlyRunning()->first();
|
|
$list = User::query()->all();
|
|
$service = new DrawTicketService();
|
|
foreach ($list as $user) {
|
|
// 如果用户已有抽奖次数, 则不赠送
|
|
$log = DrawTicketLog::where('draw_activity_id', $drawActivity->id)->where('user_id', $user->id)->where('number', '>', 0)->first();
|
|
if (!$log) {
|
|
$service->change($user, $drawActivity, 1);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
}
|