InquiryForwardDayCount.php
2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace App\Console\Commands\Inquiry;
use App\Models\Inquiry\ForwardCount;
use App\Models\Inquiry\InquiryInfo;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
class InquiryForwardDayCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'inquiry_forward_day_count';
/**
* The console command description.
*
* @var string
*/
protected $description = '每日统计询盘转发数量';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
public function handle()
{
$day_start = date('Y-m-d', strtotime('-1 day'));
$day_arr = explode('-', $day_start);
$year = $day_arr[0];
$month = $day_arr[1];
$day = $day_arr[2];
$manage_ids = InquiryInfo::select('operator_id')->where('status', InquiryInfo::STATUS_FINISH)->where('operator_id', '>', 0)->orderBy('operator_id', 'asc')->distinct()->pluck('operator_id')->toArray();
foreach ($manage_ids as $mid) {
$day_count = ForwardCount::where('manage_id', $mid)->where('year', $year)->where('month', $month)->where('day', $day)->first();
if (!$day_count) {
$day_count = new ForwardCount();
$day_count->manage_id = $mid;
$day_count->year = $year;
$day_count->month = $month;
$day_count->day = $day;
}
$day_count->count = InquiryInfo::where('status', InquiryInfo::STATUS_FINISH)->where('operator_id', $mid)->where('updated_at', 'like', $day_start . '%')->count('id') ?? 0;
$day_count->save();
}
Cache::forget('inquiry_manage_count');
$this->output('success');
}
public function output($message)
{
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
}
}