*/ class MonthlySummaryCommand extends Command { /** * The name of command. * * @var string */ protected $signature = 'manage:monthly-summary'; /** * The description of command. * * @var string */ protected $description = '月度统计'; /** * The type of class being generated. * * @var string */ protected $type = 'manage'; /** * Execute the command. * * @return void * @see fire() */ public function handle() { //分部门统计 $firstDay = Carbon::now()->addMonths(-1)->startOfMonth()->toDateTimeString(); $lastDay = Carbon::now()->addMonths(-1)->endOfMonth()->toDateTimeString(); $month = $firstDay; //全部部门 $departments = Department::getLast(); foreach ($departments as $department) { //部门id $departmentId = $department['id']; //总数量 $totalNums = Message::query()->where('import_department_id', $departmentId)->where('created_at', '>=', $firstDay)->where('created_at', '<', $lastDay)->count(); //指派数 $assignNums = Message::query()->where('import_department_id', $departmentId)->where('is_more_department', '!=', '0')->count(); //完结数 $overNums = Message::query()->where('import_department_id', $departmentId)->where('deal_status', '=', DealStatusEnum::OK)->count(); //办结率 $overRate = 0; if ($totalNums != 0) { $overRate = $overNums / $totalNums; } //满意数量 $satisfiedNums = Message::query()->where('import_department_id', $departmentId)->where('deal_evaluation', '>=', '60')->count(); //满意率 $satisfiedRate = 0; if ($overNums != 0) { $satisfiedRate = $satisfiedNums / $overNums; } //超时次数 $timeoutNums = Message::query()->where('import_department_id', $departmentId)->whereColumn('deal_limit_date', '<', 'deal_time')->count(); //每个部门存一条数据 Examine::query()->create( [ 'month' => $month, 'name' => $departmentId, 'department_id' => $departmentId, 'total_nums' => $totalNums, 'assign_nums' => $assignNums, 'over_nums' => $overNums, 'over_rate' => $overRate, 'satisfaction_rate' => $satisfiedRate, 'overtime_nums' => $timeoutNums ]); } $this->line('操作成功'); } }