0
0
Files
Babyclass/app/Console/Commands/ProfitCommand.php
2020-08-04 10:09:42 +08:00

60 lines
1.3 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Jobs\ProfitJob;
use App\Models\ProfitLog;
use Carbon\Carbon;
use Illuminate\Console\Command;
use RuLong\Identity\Models\IdentityPoint;
class ProfitCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rulong:ProfitCommand';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
ProfitLog::getnow();
$info = ProfitLog::where('created_at', Carbon::yesterday()->toDateTimeString())->where('status', 0)->first();
if ($info) {
if ($info->price > 0) {
$users = IdentityPoint::where('created_at', '<', $info->end_at)->distinct()->pluck('user_id');
foreach ($users as $key => $user_id) {
ProfitJob::dispatch($user_id, $info);
}
}
$info->status = 1;
$info->save();
}
}
}