model = model('Dda'); } /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { $kl = $this->model->order('date', 'desc')->find(); if ($kl) { $start_time = strtotime($kl['date']); } else { $start_time = time() - 86400 * 30; } //如果昨日已更新则跳过 if (date('Ymd', $start_time) != date('Ymd', time() - 86400)) { $data = OrderService::instance()->getOrderKlData($start_time, time())->data; OrderService::instance()->updateKlTable($data); } //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('pkey_name')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $filter = json_decode($this->request->get('filter'), true); $where = []; $end = date('Y-m-d'); if (array_key_exists('date', $filter)) { $times = explode(' - ', $filter['date']); $start = substr($times[0], 0, 10); $end = substr($times[1], 0, 10); $where['date'] = ['between', $start.','.$end]; if(date('Y-m-d') <= $end){ if ($offset == 0) { if ($limit) { $limit -= 1; } } else { if ($offset) { $offset -= 1; } } } } else { if ($offset == 0) { if ($limit) { $limit -= 1; } } else { if ($offset) { $offset -= 1; } } } $total = $this->model ->where($where) ->order($sort, $order) ->count(); if(date('Y-m-d') <= $end){ $total += 1; } $list = $this->model ->where($where) ->order($sort, $order) ->limit($offset, $limit) ->select(); if ($offset == 0 && date('Y-m-d') <= $end) { if (!isset($data)) { $start_time = strtotime(date('Y-m-d')); $data = OrderService::instance()->getOrderKlData($start_time, time())->data; } array_unshift($list, array_pop($data)); } $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } }