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