ThemeController.class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace Admin\Controller;
  3. /**
  4. * 样式管理
  5. * @author xusong
  6. * @version 0.0.1
  7. */
  8. class ThemeController extends CommonController {
  9. /**
  10. * [_initialize 前置操作-继承公共前置方法]
  11. */
  12. public function _initialize() {
  13. // 调用父类前置方法
  14. parent::_initialize();
  15. // 登录校验
  16. $this->Is_Login();
  17. // 权限校验
  18. $this->Is_Power();
  19. //要执行的表
  20. }
  21. /**
  22. * 主题列表
  23. * @author Devil
  24. */
  25. public function Index() {
  26. $List = M('theme')->order('id desc')->select();
  27. $this->assign('List', $List);
  28. $this->display('Index');
  29. }
  30. /**
  31. * [SaveInfo 文章添加/编辑页面]
  32. * @author Devil
  33. * @blog http://gong.gg/
  34. * @version 0.0.1
  35. * @datetime 2016-12-14T21:37:02+0800
  36. */
  37. public function SaveInfo() {
  38. $data = M('theme')->find(I('id'));
  39. $this->assign('data', $data);
  40. $this->display($data['view']);
  41. }
  42. /**
  43. * [Save 文章添加/编辑]
  44. * @author Devil
  45. * @blog http://gong.gg/
  46. * @version 0.0.1
  47. * @datetime 2016-12-14T21:37:02+0800
  48. */
  49. public function Save() {
  50. if (!IS_AjAX) {
  51. $this->error(L('common_unauthorized_access'));
  52. }
  53. $data['name'] = trim(I('name'));
  54. $data['code'] = trim(I('code'));
  55. $data['type'] = trim(I('type'));
  56. // 添加
  57. if ($id = I('id')) {
  58. $data['id'] = $id;
  59. if (M('theme')->save($data)) {
  60. $this->ajaxReturn('更新成功');
  61. } else {
  62. $this->ajaxReturn('更新失败',400);
  63. }
  64. } else {
  65. $data['created_at'] = date('Y-m-d H:i:s');
  66. if ($bool=M('theme')->add($data)) {
  67. $this->ajaxReturn('新增成功');
  68. } else {
  69. echo M()->getLastSql();
  70. $this->ajaxReturn('新增失败',400);
  71. }
  72. }
  73. }
  74. /**
  75. * [Delete 删除]
  76. * @author Devil
  77. * @blog http://gong.gg/
  78. * @version 0.0.1
  79. * @datetime 2016-12-15T11:03:30+0800
  80. */
  81. public function Delete() {
  82. // 是否ajax请求
  83. if (!IS_AJAX) {
  84. $this->error(L('common_unauthorized_access'));
  85. }
  86. // 删除数据
  87. if (I('id')) {
  88. // 更新
  89. if (M('theme')->delete(I('id'))) {
  90. $this->ajaxReturn(L('common_operation_delete_success'));
  91. } else {
  92. $this->ajaxReturn(L('common_operation_delete_error'), -100);
  93. }
  94. } else {
  95. $this->ajaxReturn(L('common_param_error'), -1);
  96. }
  97. }
  98. public function export() {
  99. $theme_id = I('theme_id',1);
  100. $where['theme_id'] = $theme_id;
  101. $data = M('theme_detail')->field('date,count(*) as pv,count(distinct(uid)) as uv')->where($where)->group('date')->select();
  102. $title = array(
  103. 'date' => array('col' => 'A', 'name' => 'date'),
  104. 'pv' => array('col' => 'B', 'name' => 'pv'),
  105. 'uv' => array('col' => 'C', 'name' => 'uv'),
  106. // 'vv' => array('col' => 'D', 'name' => 'vv'),
  107. );
  108. // Excel驱动导出数据
  109. $excel = new \My\Excel(array('filename' => '芒果电信运营数据', 'title' => $title, 'data' => $data, 'msg' => L('common_not_data_tips')));
  110. $excel->Export();
  111. }
  112. }