LinkController.class.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 LinkController 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. $list = M('Link')->field(array('id', 'name', 'url', 'describe', 'sort', 'is_enable', 'is_new_window_open'))->order('sort')->select();
  39. $this->assign('list', $list);
  40. // 是否新窗口打开
  41. $this->assign('common_is_new_window_open_list', L('common_is_new_window_open_list'));
  42. // 是否启用
  43. $this->assign('common_is_enable_list', L('common_is_enable_list'));
  44. $this->display('Index');
  45. }
  46. /**
  47. * [Save 数据保存]
  48. * @author Devil
  49. * @blog http://gong.gg/
  50. * @version 0.0.1
  51. * @datetime 2017-02-05T20:12:30+0800
  52. */
  53. public function Save()
  54. {
  55. // 是否ajax请求
  56. if(!IS_AJAX)
  57. {
  58. $this->error(L('common_unauthorized_access'));
  59. }
  60. // id为空则表示是新增
  61. $m = D('Link');
  62. // 公共额外数据处理
  63. $m->sort = intval(I('sort'));
  64. $m->describe = I('describe');
  65. // 添加
  66. if(empty($_POST['id']))
  67. {
  68. if($m->create($_POST, 1))
  69. {
  70. // 额外数据处理
  71. $m->add_time = time();
  72. $m->name = I('name');
  73. $m->describe = I('describe');
  74. // 写入数据库
  75. if($m->add())
  76. {
  77. $this->ajaxReturn(L('common_operation_add_success'));
  78. } else {
  79. $this->ajaxReturn(L('common_operation_add_error'), -100);
  80. }
  81. }
  82. } else {
  83. // 编辑
  84. if($m->create($_POST, 2))
  85. {
  86. // 额外数据处理
  87. $m->name = I('name');
  88. $m->describe = I('describe');
  89. // 移除 id
  90. unset($m->id);
  91. // 更新数据库
  92. if($m->where(array('id'=>I('id')))->save())
  93. {
  94. $this->ajaxReturn(L('common_operation_edit_success'));
  95. } else {
  96. $this->ajaxReturn(L('common_operation_edit_error'), -100);
  97. }
  98. }
  99. }
  100. $this->ajaxReturn($m->getError(), -1);
  101. }
  102. /**
  103. * [Delete 删除]
  104. * @author Devil
  105. * @blog http://gong.gg/
  106. * @version 0.0.1
  107. * @datetime 2016-12-09T21:13:47+0800
  108. */
  109. public function Delete()
  110. {
  111. if(!IS_AJAX)
  112. {
  113. $this->error(L('common_unauthorized_access'));
  114. }
  115. $m = D('Link');
  116. if($m->create($_POST, 4))
  117. {
  118. if($m->delete($id))
  119. {
  120. $this->ajaxReturn(L('common_operation_delete_success'));
  121. } else {
  122. $this->ajaxReturn(L('common_operation_delete_error'), -100);
  123. }
  124. } else {
  125. $this->ajaxReturn($m->getError(), -1);
  126. }
  127. }
  128. /**
  129. * [StateUpdate 状态更新]
  130. * @author Devil
  131. * @blog http://gong.gg/
  132. * @version 0.0.1
  133. * @datetime 2017-01-12T22:23:06+0800
  134. */
  135. public function StateUpdate()
  136. {
  137. // 参数
  138. if(empty($_POST['id']) || !isset($_POST['state']))
  139. {
  140. $this->ajaxReturn(L('common_param_error'), -1);
  141. }
  142. // 数据更新
  143. if(M('Link')->where(array('id'=>I('id')))->save(array('is_enable'=>I('state'))))
  144. {
  145. $this->ajaxReturn(L('common_operation_edit_success'));
  146. } else {
  147. $this->ajaxReturn(L('common_operation_edit_error'), -100);
  148. }
  149. }
  150. }
  151. ?>