123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace App\Console\Commands\Manage;
- use App\Repositories\Enums\Manage\DealStatusEnum;
- use App\Repositories\Models\Base\Department;
- use App\Repositories\Models\Manage\Message;
- use App\Repositories\Models\Manage\Examine;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- /**
- * 月度统计
- * @package Prettus\Repository\Generators\Commands
- * @author Anderson Andrade <contato@andersonandra.de>
- */
- 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('操作成功');
- }
- }
|