Is_Login(); // 权限校验 $this->Is_Power(); //要执行的表 } /** * 主题列表 * @author Devil */ public function Index() { $List = M('theme')->order('id desc')->select(); $this->assign('List', $List); $this->display('Index'); } /** * [SaveInfo 文章添加/编辑页面] * @author Devil * @blog http://gong.gg/ * @version 0.0.1 * @datetime 2016-12-14T21:37:02+0800 */ public function SaveInfo() { $data = M('theme')->find(I('id')); $this->assign('data', $data); $this->display($data['view']); } /** * [Save 文章添加/编辑] * @author Devil * @blog http://gong.gg/ * @version 0.0.1 * @datetime 2016-12-14T21:37:02+0800 */ public function Save() { if (!IS_AjAX) { $this->error(L('common_unauthorized_access')); } $data['name'] = trim(I('name')); $data['code'] = trim(I('code')); $data['type'] = trim(I('type')); // 添加 if ($id = I('id')) { $data['id'] = $id; if (M('theme')->save($data)) { $this->ajaxReturn('更新成功'); } else { $this->ajaxReturn('更新失败',400); } } else { $data['created_at'] = date('Y-m-d H:i:s'); if ($bool=M('theme')->add($data)) { $this->ajaxReturn('新增成功'); } else { echo M()->getLastSql(); $this->ajaxReturn('新增失败',400); } } } /** * [Delete 删除] * @author Devil * @blog http://gong.gg/ * @version 0.0.1 * @datetime 2016-12-15T11:03:30+0800 */ public function Delete() { // 是否ajax请求 if (!IS_AJAX) { $this->error(L('common_unauthorized_access')); } // 删除数据 if (I('id')) { // 更新 if (M('theme')->delete(I('id'))) { $this->ajaxReturn(L('common_operation_delete_success')); } else { $this->ajaxReturn(L('common_operation_delete_error'), -100); } } else { $this->ajaxReturn(L('common_param_error'), -1); } } public function export() { $theme_id = I('theme_id',1); $where['theme_id'] = $theme_id; $data = M('theme_detail')->field('date,count(*) as pv,count(distinct(uid)) as uv')->where($where)->group('date')->select(); $title = array( 'date' => array('col' => 'A', 'name' => 'date'), 'pv' => array('col' => 'B', 'name' => 'pv'), 'uv' => array('col' => 'C', 'name' => 'uv'), // 'vv' => array('col' => 'D', 'name' => 'vv'), ); // Excel驱动导出数据 $excel = new \My\Excel(array('filename' => '芒果电信运营数据', 'title' => $title, 'data' => $data, 'msg' => L('common_not_data_tips'))); $excel->Export(); } }