ForwardInquiryCount.php
1.8 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
69
70
71
<?php
/**
* @remark :
* @name :ForwardInquiryCount.php
* @author :lyh
* @method :post
* @time :2023/8/18 9:41
*/
namespace App\Console\Commands\MonthlyCount;
use App\Models\Inquiry\ForwardCount;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* @remark :转发询盘人员统计
* @name :ForwardInquiryCount
* @author :lyh
* @method :post
* @time :2023/8/18 9:42
*/
class ForwardInquiryCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'forward_count';
/**
* The console command description.
*
* @var string
*/
protected $description = '月转发报告统计';
/**
* @remark :统计报告
* @name :handle
* @author :lyh
* @method :post
* @time :2023/8/18 9:52
*/
public function handle(){
// 获取上个月的开始时间
$startTime = Carbon::now()->subMonth()->startOfMonth()->toDateString();
// 获取上个月的结束时间
$endTime = Carbon::now()->subMonth()->endOfMonth()->toDateString();
$list = DB::table('gl_inquiry_info')->groupBy('user_name')
->select("user_name",DB::raw('COUNT(*) as count'))
->where('send_time','>=',$startTime.' 00:00:00')
->where('send_time','<=',$endTime.' 23:59:59')
->get();
if(!empty($list)){
$list = $list->toArray();
$forwardModel = new ForwardCount();
foreach ($list as $v){
$data = [
'date'=>Carbon::now()->subMonth()->format('Y-m'),
'name'=>$v['user_name'],
'count'=>$v['count']
];
$forwardModel->add($data);
}
}
return 1;
}
}