fisrt
This commit is contained in:
36
app/Console/Commands/MonthPerfCommand.php
Normal file
36
app/Console/Commands/MonthPerfCommand.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\Bonus\MonthPerfJob;
|
||||
use Illuminate\Console\Command;
|
||||
use Modules\User\Models\User;
|
||||
|
||||
class MonthPerfCommand extends Command
|
||||
{
|
||||
protected $signature = 'Bonus:MonthPerf {last?}';
|
||||
|
||||
protected $description = '分红:计算用户月度业绩';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$last = $this->argument('last') ?: 0;
|
||||
|
||||
User::whereHas('identities', function ($query) {
|
||||
$query->where('id', 6);
|
||||
})
|
||||
->whereHas('identityMiddle', function ($query) {
|
||||
$query->where('star', '>', 0);
|
||||
})
|
||||
->chunkById(100, function ($users) use ($last) {
|
||||
foreach ($users as $user) {
|
||||
MonthPerfJob::dispatch($user, $last);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
57
app/Console/Commands/StartBounsCommand.php
Normal file
57
app/Console/Commands/StartBounsCommand.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\Bonus\SendBounsJob;
|
||||
use App\Models\Bouns;
|
||||
use App\Models\BounsUserPerf;
|
||||
use Illuminate\Console\Command;
|
||||
use Exception;
|
||||
|
||||
class StartBounsCommand extends Command
|
||||
{
|
||||
protected $signature = 'Bonus:StartMonth {star} {last?}';
|
||||
|
||||
protected $description = '分红:开始分红 {1-5} {last?}';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$star = $this->argument('star') ?: 0;
|
||||
if (!in_array($star, Bouns::TYPEARRAY)) {
|
||||
throw new Exception('星级参数不正确');
|
||||
}
|
||||
$last = $this->argument('last') ?: 0;
|
||||
|
||||
$time = now()->startOfMonth()->toDateTimeString();
|
||||
if ($last) {
|
||||
$time = now()->subMonth()->startOfMonth()->toDateTimeString();
|
||||
}
|
||||
$bouns = Bouns::where('date', $time)
|
||||
->where('type', $star)
|
||||
->where('status', Bouns::STATUS_INIT)
|
||||
->first();
|
||||
if (!$bouns) {
|
||||
throw new Exception('分红内容不存在或状态不正确');
|
||||
}
|
||||
$bounsUserPerf = BounsUserPerf::where('date', $bouns->date)
|
||||
->where('star', '>=', $bouns->type)
|
||||
->get();
|
||||
if ($bounsUserPerf->count() > 0) {
|
||||
$allOld = bcmul($bounsUserPerf->sum('old_perf'), 0.3, 4);//累计业绩
|
||||
$allNew = bcmul($bounsUserPerf->sum('new_perf'), 0.7, 4);//新增业绩
|
||||
$allPerf = bcadd($allOld, $allNew, 4);//总业绩
|
||||
$price = bcdiv($bouns->total, $allPerf, 6);//单价
|
||||
$bouns->doIng();
|
||||
foreach ($bounsUserPerf as $bounsPerf) {
|
||||
SendBounsJob::dispatch($bounsPerf, $price, $bouns);
|
||||
}
|
||||
} else {
|
||||
$bouns->doEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
66
app/Console/Kernel.php
Normal file
66
app/Console/Kernel.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use Nwidart\Modules\Facades\Module as ModuleManager;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
$schedule->command('Bonus:MonthPerf 1')->monthlyOn(1, '00:01');
|
||||
$schedule->command('Bonus:StartMonth 1 1')->monthlyOn(1, '00:10');
|
||||
$schedule->command('Bonus:StartMonth 2 1')->monthlyOn(1, '00:15');
|
||||
$schedule->command('Bonus:StartMonth 3 1')->monthlyOn(1, '00:20');
|
||||
$schedule->command('Bonus:StartMonth 4 1')->monthlyOn(1, '00:25');
|
||||
$schedule->command('Bonus:StartMonth 5 1')->monthlyOn(1, '00:30');
|
||||
$this->modules($schedule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 要执行任务的位置增加Console\Kernel类
|
||||
* 类中 runCommand(Schedule $schedule)
|
||||
* 模型中的command在模型的ServiceProvider自行注册
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
*/
|
||||
protected function modules(Schedule $schedule)
|
||||
{
|
||||
$data = ModuleManager::toCollection();
|
||||
foreach ($data as $name => $module) {
|
||||
$nameSpace = "\\Modules\\$name\\Console\\Kernel";
|
||||
if (class_exists($nameSpace)) {
|
||||
$runKernel = resolve($nameSpace);
|
||||
$runKernel->runCommand($schedule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
// require base_path('routes/console.php');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user