modify('-30 days')->format('Y-m-d'); $end_at = now()->format('Y-m-d'); $default_daterange = $start . ' - ' . $end_at; $this->view->assign('default_daterange',$default_daterange); return $this->view->fetch(); } public function getData() { $car_num = Db::query('SELECT COUNT(IF(car_type = 1,1,null)) new_car, COUNT(IF(car_type = 3,1,null)) rent_car, COUNT(IF(car_type = 2,1,null)) old_car FROM cars;')[0]; $start = now()->modify('-30 days')->format('Y-m-d'); $end_at = now()->format('Y-m-d 23:29:59'); $filter = request()->get('range',''); if (!empty($filter)){ $arr = explode(' - ', $filter); if (trim($arr[0])) { $start = trim($arr[0]). ' 00:00:00'; } if (trim($arr[1])) { $end_at = trim($arr[1]) . ' 23:29:59'; } } $build = new Sales(); $build->whereBetween('finish_at', [$start, $end_at]); $group = \model('auth_group_access')->where('uid', $this->auth->id)->find()->group_id ?? 0; if (!in_array($group,[1,2])){ $build->where('saler_id',$this->auth->id); } $sale = $build->field([ "count(if(type=1,1,null)) new_count", "count(if(type=2,1,null)) old_count", "count(if(type=3,1,null)) rent_count", "sum(if(type=1,total_price,0)) new_sum", "sum(if(type=2,total_price,0)) old_sum", "sum(if(type=3,total_price,0)) rent_sum", "sum(total_price) total_price", ])->select()[0]->toArray(); $this->success(data:[ ...$car_num,...$sale ]); } }