generated from panliang/owl-admin-starter
console
parent
a5737eebf6
commit
fda7e4a02b
|
|
@ -3,3 +3,7 @@
|
|||
- php >= 8.1
|
||||
- Laravel 10.x
|
||||
- slowlyo/owl-admin latest
|
||||
|
||||
## 安装
|
||||
|
||||
- 定时任务
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@ class CateRank extends Command
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:cate-rank {--quarter=1}';
|
||||
protected $signature = 'app:cate-rank {--sn=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '生成党支部排名记录, quarter: 上一季度';
|
||||
protected $description = '生成党支部排名记录';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
|
|
@ -30,10 +30,11 @@ class CateRank extends Command
|
|||
public function handle()
|
||||
{
|
||||
$now = now();
|
||||
$time = $now->copy()->subQuarters($this->option('quarter'));
|
||||
$start = $time->copy()->startOfQuarter();
|
||||
$end = $time->copy()->endOfQuarter();
|
||||
$sn = $time->year . '-' . $time->quarter;
|
||||
$sn = $this->option('sn');
|
||||
if (!$sn) {
|
||||
$time = $now->copy()->subQuarter();
|
||||
$sn = $time->year . '-' . $time->quarter;
|
||||
}
|
||||
$list = [];
|
||||
CateRankModel::where('sn', $sn)->delete();
|
||||
$cateList = PartyCate::withCount(['users'])->get();
|
||||
|
|
@ -43,7 +44,7 @@ class CateRank extends Command
|
|||
'cate_id' => $item->id,
|
||||
'score' => $item->current_score,
|
||||
'count' => $item->users_count,
|
||||
'avg_score' => floor($item->score/$item->users_count),
|
||||
'avg_score' => $item->users_count ? floor($item->score/$item->users_count) : 0,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@ class UserRank extends Command
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:user-rank {--quarter=1}';
|
||||
protected $signature = 'app:user-rank {--sn=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '生成党员排名记录, quarter: 上一季度';
|
||||
protected $description = '生成党员排名记录';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
|
|
@ -30,25 +30,22 @@ class UserRank extends Command
|
|||
public function handle()
|
||||
{
|
||||
$now = now();
|
||||
$time = $now->copy()->subQuarters($this->option('quarter'));
|
||||
$start = $time->copy()->startOfQuarter();
|
||||
$end = $time->copy()->endOfQuarter();
|
||||
$sn = $time->year . '-' . $time->quarter;
|
||||
$sn = $this->option('sn');
|
||||
if (!$sn) {
|
||||
$time = $now->copy()->subQuarter();
|
||||
$sn = $time->year . '-' . $time->quarter;
|
||||
}
|
||||
$list = [];
|
||||
|
||||
UserRankModel::where('sn', $sn)->delete();
|
||||
|
||||
$scoreList = UserScore::with(['user'])
|
||||
->whereBetween('created_at', [$start, $end])
|
||||
->select('user_id', DB::raw('sum(`score`) as `score`'))
|
||||
->groupBy('user_id')
|
||||
->get();
|
||||
foreach ($scoreList as $item) {
|
||||
$userList = PartyUser::get();
|
||||
foreach ($userList as $item) {
|
||||
$list[] = [
|
||||
'sn' => $sn,
|
||||
'cate_id' => $item->user->cate_id,
|
||||
'user_id' => $item->user_id,
|
||||
'score' => $item->score,
|
||||
'cate_id' => $item->cate_id,
|
||||
'user_id' => $item->id,
|
||||
'score' => $item->current_score,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ class Kernel extends ConsoleKernel
|
|||
*/
|
||||
protected function schedule(Schedule $schedule): void
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
$schedule->command('app:user-rank')->quarterly();
|
||||
$schedule->command('app:cate-rank')->quarterly();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class CateRankController extends Controller
|
|||
'id' => $item->id,
|
||||
'name' => $item->name,
|
||||
'count' => $item->users_count,
|
||||
'score' => floor($item->current_score / $item->users_count),
|
||||
'score' => $item->users_count ? floor($item->current_score / $item->users_count) : 0,
|
||||
]);
|
||||
}
|
||||
$rankList = $rankList->sortByDesc('score');
|
||||
|
|
|
|||
|
|
@ -20,7 +20,15 @@ class PartyUserSeeder extends Seeder
|
|||
{
|
||||
PartyCate::truncate();
|
||||
PartyUser::truncate();
|
||||
PartyCate::factory()->count(20)->create();
|
||||
PartyCate::factory()->count(20)->create([
|
||||
'scores' => [
|
||||
'score_cate_1' => 0,
|
||||
'score_cate_2' => 0,
|
||||
'score_cate_3' => 0,
|
||||
'score_cate_4' => 0,
|
||||
'score_cate_5' => 0,
|
||||
]
|
||||
]);
|
||||
(new PartyUserFactory())->count(100)->create([
|
||||
'scores' => [
|
||||
'score_cate_1' => 0,
|
||||
|
|
|
|||
Loading…
Reference in New Issue