123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace Admin\Controller;
- /**
- * 样式管理
- * @author xusong
- * @version 0.0.1
- */
- class ThemeController extends CommonController {
- /**
- * [_initialize 前置操作-继承公共前置方法]
- */
- public function _initialize() {
- // 调用父类前置方法
- parent::_initialize();
- // 登录校验
- $this->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();
- }
- }
|