/** * export csv * * @return csv */ public function exportExcel() { $sort = $this->request->data('sidx'); $order = $this->request->data('sord'); $keywords = $this->request->data('keywords'); $begin_time = $this->request->data('begin_time'); $end_time = $this->request->data('end_time'); $where = []; if (!empty($keywords)) { $where[' username like'] = "%{$keywords}%"; } if (!empty($begin_time) && !empty($end_time)) { $begin_time = date('Y-m-d', strtotime($begin_time)); $end_time = date('Y-m-d', strtotime($end_time)); $where['and'] = [['date(`ctime`) >' => $begin_time], ['date(`ctime`) <' => $end_time]]; } $Table = $this->Menu; $column = ['节点名称', '路径', '父ID', '样式', '排序', '是否在菜单显示', '状态', '备注']; $query = $Table->find(); $query->hydrate(false); $query->select(['name', 'node', 'pid', 'class', 'rank', 'is_menu', 'status', 'remark']); if (!empty($where)) { $query->where($where); } if (!empty($sort) && !empty($order)) { $query->order([$sort => $order]); } $res = $query->toArray(); $this->autoRender = false; $filename = 'Menu_' . date('Y-m-d') . '.csv'; \Admin\Utils\Export::exportCsv($column, $res, $filename); }
/** * export csv * * @return csv */ public function exportExcel() { $sort = $this->request->data('sidx'); $order = $this->request->data('sord'); $keywords = $this->request->data('keywords'); $begin_time = $this->request->data('begin_time'); $end_time = $this->request->data('end_time'); $where = []; if (!empty($keywords)) { $where[' username like'] = "%{$keywords}%"; } if (!empty($begin_time) && !empty($end_time)) { $begin_time = date('Y-m-d', strtotime($begin_time)); $end_time = date('Y-m-d', strtotime($end_time)); $where['and'] = [['date(`ctime`) >' => $begin_time], ['date(`ctime`) <' => $end_time]]; } $Table = $this->Movie; $column = ['id', 'pic', 'movie', 'url', 'ctime', 'hits', 'utime']; $query = $Table->find(); $query->hydrate(false); if (!empty($where)) { $query->where($where); } if (!empty($sort) && !empty($order)) { $query->order([$sort => $order]); } $res = $query->toArray(); $this->autoRender = false; $filename = 'Movie_' . date('Y-m-d') . '.csv'; \Admin\Utils\Export::exportCsv($column, $res, $filename); }