|
|
|
@ -2,6 +2,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use App\Models\Course;
|
|
|
|
|
|
|
|
use App\Models\CourseSign;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Repositories\MeetRepository;
|
|
|
|
use App\Repositories\MeetRepository;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
@ -40,13 +42,38 @@ class UpdateUserNo extends Command
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$users = User::whereNull('no')->get();
|
|
|
|
// 已经开始的课程日期
|
|
|
|
foreach ($users as $user) {
|
|
|
|
$dateList = Course::whereNotNull('start_date')
|
|
|
|
$no = User::updateNo($user->id);
|
|
|
|
->where('start_date', '<=', date('Y-m-d'))
|
|
|
|
$this->info($no . '更新成功');
|
|
|
|
->orderBy('start_date')
|
|
|
|
|
|
|
|
->groupBy('start_date')
|
|
|
|
|
|
|
|
->pluck('start_date')
|
|
|
|
|
|
|
|
->toArray();
|
|
|
|
|
|
|
|
foreach ($dateList as $date) {
|
|
|
|
|
|
|
|
$courses = Course::with(['courseSigns' => function ($query) {
|
|
|
|
|
|
|
|
$query->where('status', 1);
|
|
|
|
|
|
|
|
}])->where('start_date', $date)
|
|
|
|
|
|
|
|
->orderBy('start_date')
|
|
|
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$i = 1;
|
|
|
|
|
|
|
|
// 编号前缀
|
|
|
|
|
|
|
|
$prefix = date('Ymd', strtotime($date));
|
|
|
|
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
|
|
|
|
foreach ($course->courseSigns as $sign) {
|
|
|
|
|
|
|
|
$user = User::find($sign->user_id);
|
|
|
|
|
|
|
|
if ($user->no) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$no = $prefix . str_pad($i, 3, '0', STR_PAD_LEFT);
|
|
|
|
|
|
|
|
// 更新用户编号
|
|
|
|
|
|
|
|
$user->no = $no;
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
$this->info($no);
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->info('更新完成');
|
|
|
|
return $this->info('更新完成');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|