NavFooterController.class.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 NavFooterController 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('list', $this->GetNavList());
  39. // 文章分类
  40. $this->assign('article_class_list', M('ArticleClass')->field(array('id', 'name'))->where(array('is_enable'=>1))->select());
  41. // 自定义页面
  42. $this->assign('customview_list', M('CustomView')->field(array('id', 'title'))->where(array('is_enable'=>1))->select());
  43. // 是否新窗口打开
  44. $this->assign('common_is_new_window_open_list', L('common_is_new_window_open_list'));
  45. // 是否显示
  46. $this->assign('common_is_show_list', L('common_is_show_list'));
  47. $this->display('Index');
  48. }
  49. /**
  50. * [GetNavList 获取数据列表]
  51. * @author Devil
  52. * @blog http://gong.gg/
  53. * @version 0.0.1
  54. * @datetime 2016-12-10T22:16:29+0800
  55. */
  56. private function GetNavList()
  57. {
  58. $m = M('Navigation');
  59. $field = array('id', 'name', 'url', 'value', 'data_type', 'sort', 'is_show', 'is_new_window_open');
  60. return NavDataDealWith($m->field($field)->where(array('nav_type'=>'footer'))->order('sort')->select());
  61. }
  62. /**
  63. * [Save 添加/编辑]
  64. * @author Devil
  65. * @blog http://gong.gg/
  66. * @version 0.0.1
  67. * @datetime 2016-12-07T21:58:19+0800
  68. */
  69. public function Save()
  70. {
  71. // 是否ajax请求
  72. if(!IS_AJAX)
  73. {
  74. $this->error(L('common_unauthorized_access'));
  75. }
  76. // 请求类型
  77. switch(I('data_type'))
  78. {
  79. // 自定义导航
  80. case 'custom':
  81. $this->DataSave(5);
  82. break;
  83. // 文章分类导航
  84. case 'article_class':
  85. $this->DataSave(6);
  86. break;
  87. // 自读页面导航
  88. case 'customview':
  89. $this->DataSave(7);
  90. break;
  91. }
  92. $this->ajaxReturn(L('common_param_error'), -1);
  93. }
  94. /**
  95. * [DataSave 导航数据保存]
  96. * @author Devil
  97. * @blog http://gong.gg/
  98. * @version 0.0.1
  99. * @datetime 2017-02-05T20:12:30+0800
  100. * @param [int] $check_type [校验类型]
  101. */
  102. private function DataSave($check_type)
  103. {
  104. $m = D('Navigation');
  105. // 数据校验
  106. if($m->create($_POST, $check_type))
  107. {
  108. // 非自定义导航数据处理
  109. if(empty($_POST['name']))
  110. {
  111. switch(I('data_type'))
  112. {
  113. // 文章分类导航
  114. case 'article_class':
  115. $temp_name = M('ArticleClass')->where(array('id'=>I('value')))->getField('name');
  116. break;
  117. // 自读页面导航
  118. case 'customview':
  119. $temp_name = M('CustomView')->where(array('id'=>I('value')))->getField('title');
  120. break;
  121. }
  122. // 只截取16个字符
  123. $m->name = mb_substr($temp_name, 0, 16, C('DEFAULT_CHARSET'));
  124. } else {
  125. $m->name = I('name');
  126. }
  127. // 清除缓存
  128. S(C('cache_common_home_nav_footer_key'), null);
  129. // id为空则表示是新增
  130. if(empty($_POST['id']))
  131. {
  132. // 额外数据处理
  133. $m->add_time = time();
  134. $m->nav_type = 'footer';
  135. // 写入数据库
  136. if($m->add())
  137. {
  138. $this->ajaxReturn(L('common_operation_add_success'));
  139. } else {
  140. $this->ajaxReturn(L('common_operation_add_error'), -100);
  141. }
  142. } else {
  143. // 数据编辑
  144. if($m->where(array('id'=>I('id')))->save())
  145. {
  146. $this->ajaxReturn(L('common_operation_edit_success'));
  147. } else {
  148. $this->ajaxReturn(L('common_operation_edit_error'), -100);
  149. }
  150. }
  151. } else {
  152. $this->ajaxReturn($m->getError(), -1);
  153. }
  154. }
  155. /**
  156. * [Delete 删除]
  157. * @author Devil
  158. * @blog http://gong.gg/
  159. * @version 0.0.1
  160. * @datetime 2016-12-09T21:13:47+0800
  161. */
  162. public function Delete()
  163. {
  164. if(!IS_AJAX)
  165. {
  166. $this->error(L('common_unauthorized_access'));
  167. }
  168. $m = D('Navigation');
  169. if($m->create($_POST, 4))
  170. {
  171. if($m->delete($id))
  172. {
  173. // 清除缓存
  174. S(C('cache_common_home_nav_footer_key'), null);
  175. $this->ajaxReturn(L('common_operation_delete_success'));
  176. } else {
  177. $this->ajaxReturn(L('common_operation_delete_error'), -100);
  178. }
  179. } else {
  180. $this->ajaxReturn($m->getError(), -1);
  181. }
  182. }
  183. /**
  184. * [StateUpdate 状态更新]
  185. * @author Devil
  186. * @blog http://gong.gg/
  187. * @version 0.0.1
  188. * @datetime 2017-01-12T22:23:06+0800
  189. */
  190. public function StateUpdate()
  191. {
  192. // 参数
  193. if(empty($_POST['id']) || !isset($_POST['state']))
  194. {
  195. $this->ajaxReturn(L('common_param_error'), -1);
  196. }
  197. // 数据更新
  198. if(M('Navigation')->where(array('id'=>I('id')))->save(array('is_show'=>I('state'))))
  199. {
  200. // 清除缓存
  201. S(C('cache_common_home_nav_footer_key'), null);
  202. $this->ajaxReturn(L('common_operation_edit_success'));
  203. } else {
  204. $this->ajaxReturn(L('common_operation_edit_error'), -100);
  205. }
  206. }
  207. }
  208. ?>