WeekController.class.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace Admin\Controller;
  3. /**
  4. * 周管理
  5. * @author Devil
  6. * @blog http://gong.gg/
  7. * @version 0.0.1
  8. * @datetime 2016-12-01T21:51:08+0800
  9. */
  10. class WeekController extends CommonController
  11. {
  12. /**
  13. * [_initialize 前置操作-继承公共前置方法]
  14. * @author Devil
  15. * @blog http://gong.gg/
  16. * @version 0.0.1
  17. * @datetime 2016-12-03T12:39:08+0800
  18. */
  19. public function _initialize()
  20. {
  21. // 调用父类前置方法
  22. parent::_initialize();
  23. // 登录校验
  24. $this->Is_Login();
  25. // 权限校验
  26. $this->Is_Power();
  27. }
  28. /**
  29. * [Index 周列表]
  30. * @author Devil
  31. * @blog http://gong.gg/
  32. * @version 0.0.1
  33. * @datetime 2016-12-06T21:31:53+0800
  34. */
  35. public function Index()
  36. {
  37. // 是否启用
  38. $this->assign('common_is_enable_list', L('common_is_enable_list'));
  39. $this->display('Index');
  40. }
  41. /**
  42. * [GetNodeSon 获取节点子列表]
  43. * @author Devil
  44. * @blog http://gong.gg/
  45. * @version 0.0.1
  46. * @datetime 2016-12-25T15:19:45+0800
  47. */
  48. public function GetNodeSon()
  49. {
  50. // 是否ajax请求
  51. if(!IS_AJAX)
  52. {
  53. $this->error(L('common_unauthorized_access'));
  54. }
  55. // 获取数据
  56. $field = array('id', 'name', 'sort', 'is_enable');
  57. $data = M('Week')->field($field)->where(array('pid'=>intval(I('id', 0))))->select();
  58. if(!empty($data))
  59. {
  60. foreach($data as $k=>$v)
  61. {
  62. $data[$k]['is_son'] = 'no';
  63. $data[$k]['ajax_url'] = U('Admin/Week/GetNodeSon', array('id'=>$v['id']));
  64. $data[$k]['delete_url'] = U('Admin/Week/Delete');
  65. $data[$k]['json'] = json_encode($v);
  66. }
  67. }
  68. $msg = empty($data) ? L('common_not_data_tips') : L('common_operation_success');
  69. $this->ajaxReturn($msg, 0, $data);
  70. }
  71. /**
  72. * [Save 周保存]
  73. * @author Devil
  74. * @blog http://gong.gg/
  75. * @version 0.0.1
  76. * @datetime 2016-12-25T22:36:12+0800
  77. */
  78. public function Save()
  79. {
  80. // 是否ajax请求
  81. if(!IS_AJAX)
  82. {
  83. $this->error(L('common_unauthorized_access'));
  84. }
  85. // id为空则表示是新增
  86. $m = D('Week');
  87. // 公共额外数据处理
  88. $m->sort = intval(I('sort'));
  89. // 添加
  90. if(empty($_POST['id']))
  91. {
  92. if($m->create($_POST, 1))
  93. {
  94. // 额外数据处理
  95. $m->add_time = time();
  96. $m->name = I('name');
  97. // 写入数据库
  98. if($m->add())
  99. {
  100. $this->ajaxReturn(L('common_operation_add_success'));
  101. } else {
  102. $this->ajaxReturn(L('common_operation_add_error'), -100);
  103. }
  104. }
  105. } else {
  106. // 编辑
  107. if($m->create($_POST, 2))
  108. {
  109. // 额外数据处理
  110. $m->name = I('name');
  111. // 移除 id
  112. unset($m->id);
  113. // 更新数据库
  114. if($m->where(array('id'=>I('id')))->save())
  115. {
  116. $this->ajaxReturn(L('common_operation_edit_success'));
  117. } else {
  118. $this->ajaxReturn(L('common_operation_edit_error'), -100);
  119. }
  120. }
  121. }
  122. $this->ajaxReturn($m->getError(), -1);
  123. }
  124. /**
  125. * [Delete 周删除]
  126. * @author Devil
  127. * @blog http://gong.gg/
  128. * @version 0.0.1
  129. * @datetime 2016-12-25T22:36:12+0800
  130. */
  131. public function Delete()
  132. {
  133. if(!IS_AJAX)
  134. {
  135. $this->error(L('common_unauthorized_access'));
  136. }
  137. $m = D('Week');
  138. if($m->create($_POST, 5))
  139. {
  140. if($m->delete(I('id')))
  141. {
  142. $this->ajaxReturn(L('common_operation_delete_success'));
  143. } else {
  144. $this->ajaxReturn(L('common_operation_delete_error'), -100);
  145. }
  146. } else {
  147. $this->ajaxReturn($m->getError(), -1);
  148. }
  149. }
  150. }
  151. ?>