TestCreate.php
3.03 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace App\Console\Commands;
use App\Modules\Models\DayIncome\DayIncome;
use App\Modules\Models\GuideRecord\GuideRecord;
use App\Modules\Models\Production\Production;
use App\Modules\Models\Spot\Spot;
use Illuminate\Console\Command;
class TestCreate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'TestCreate {--day=}';
/**
* The console command description.
*
* @var string
*/
protected $description = '统计每天的不同景区总价格';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$time = $this->option('day');
if( empty($time) ){
$time = date('Y-m-d');
}
$day = date( "Y-m-d", strtotime( "$time -1 day" ) );
$start_time = $day.' 00:00:00';
$end_time = $day.' 23:59:59';
//昨天的钱数讲解器租借
$info=Production::select('rent.spot_id','rent.business_id','rent.real_total','production.return_time')
->leftJoin('rent', 'production.rent_id', '=', 'rent.id')
->where('production.return_time', '>=', $start_time)
->where('production.return_time','<=',$end_time)
->where('production.is_return',1)
->get()
->toArray();
$data = [];
$data1 =[];
//每天同游共听的钱
$where = [
['is_pay', '=', 1],
['pay_time', '>=', $start_time],
['pay_time', '<=', $end_time],
];
$res=GuideRecord::where($where)->get();
if(!empty($info)){
for($i=0;$i<count($info);$i++){
if(!isset( $data[ $info[$i]['spot_id'] ]['real_total'])){
$data[ $info[$i]['spot_id'] ]['real_total'] = 0;
}
$data[ $info[$i]['spot_id'] ]['real_total'] += $info[$i]['real_total'];
}
}
if(!empty($res)){
for($i=0;$i<count($res);$i++){
if(!isset($data1[$res[$i]['spot_id']]['real_total'])){
$data1[$res[$i]['spot_id']]['real_total']=0;
}
$data1[$res[$i]['spot_id']]['real_total']+=$res[$i]['real_total'];
}
}
$insert_data = [];
$spots = Spot::select('*')->get()->toArray();
foreach ( $spots as $k => $v ){
$insert_data[$k]['day'] = $day;
$insert_data[$k]['business_id'] = (int)$v['business_id'];
$insert_data[$k]['spot_id'] = (int)$v['id'];
$insert_data[$k]['total'] = empty($data[$v['id']]['real_total']) ? 0 :$data[$v['id']]['real_total'];
$insert_data[$k]['guide_total'] = empty($data1[$v['id']]['real_total'])? 0: $data1[$v['id']['real_total']];
}
$res = DayIncome::insert($insert_data);
}
}