ArticleController.class.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. * ==========================================================================
  6. * @link https://www.nanodreamtech.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.nanodreamtech.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Controller;
  15. class ArticleController extends CommonController{
  16. protected function _initialize(){
  17. parent::_initialize();
  18. }
  19. public function index()
  20. {
  21. $pindex = I('request.page', 1);
  22. $psize = 20;
  23. $keyword = I('request.keyword');
  24. $this->keyword = $keyword;
  25. if (!empty($keyword)) {
  26. $condition .= ' and title like "%'.$keyword.'%"';
  27. }
  28. $enabled = I('request.enabled',-1);
  29. if (isset($enabled) && $enabled >= 0) {
  30. $condition .= ' and enabled = ' . $enabled;
  31. } else {
  32. $enabled = -1;
  33. }
  34. $this->enabled = $enabled;
  35. $list = M()->query('SELECT id,title,content,displayorder,enabled FROM ' .
  36. C('DB_PREFIX'). "lionfish_comshop_article
  37. WHERE 1=1 " . $condition . ' order by displayorder desc, id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  38. $total = M('lionfish_comshop_article')->where("1=1 ".$condition)->count();
  39. $pager = pagination2($total, $pindex, $psize);
  40. $this->list = $list;
  41. $this->pager = $pager;
  42. $this->display();
  43. }
  44. /**
  45. * 编辑添加
  46. */
  47. public function add()
  48. {
  49. $id = I('request.id');
  50. if (!empty($id)) {
  51. $item = M('lionfish_comshop_article')->where( array('id' => $id) )->find();
  52. $this->id = $id;
  53. $this->item = $item;
  54. }
  55. if (IS_POST) {
  56. $data = I('request.data');
  57. D('Seller/Article')->update($data);
  58. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  59. }
  60. $this->display('Article/post');
  61. }
  62. /**
  63. * 改变状态
  64. */
  65. public function change()
  66. {
  67. $id = I('request.id');
  68. //ids
  69. if (empty($id)) {
  70. $ids = I('request.ids');
  71. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  72. }
  73. if (empty($id)) {
  74. show_json(0, array('message' => '参数错误'));
  75. }
  76. $type = I('request.type');
  77. $value = I('request.value');
  78. if (!(in_array($type, array('enabled', 'displayorder')))) {
  79. show_json(0, array('message' => '参数错误'));
  80. }
  81. $items = M('lionfish_comshop_article')->where( array('id' => array('in', $id) ) )->select();
  82. foreach ($items as $item) {
  83. M('lionfish_comshop_article')->where( array('id' => $item['id']) )->save( array($type => $value) );
  84. }
  85. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  86. }
  87. /**
  88. * 删除公告
  89. */
  90. public function delete()
  91. {
  92. $id = I('request.id');
  93. if (empty($id)) {
  94. $ids = I('request.ids');
  95. $id = (is_array($ids) ? implode(',', $ids) : 0);
  96. }
  97. $items = M('lionfish_comshop_article')->field('id,title')->where( array('id' => array('in', $id) ) )->select();
  98. if (empty($item)) {
  99. $item = array();
  100. }
  101. foreach ($items as $item) {
  102. M('lionfish_comshop_article')->where( array('id' => $item['id']) )->delete();
  103. }
  104. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  105. }
  106. }
  107. ?>