Article.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\store\controller;
  15. use library\Controller;
  16. use think\Db;
  17. use app\common\model\User;
  18. /**
  19. * 文章管理
  20. * Class Article
  21. * @package app\store\controller
  22. */
  23. class Article extends Controller
  24. {
  25. /**
  26. * 绑定数据表
  27. * @var string
  28. */
  29. protected $table = 'Article';
  30. /**
  31. * 文章信息管理
  32. * @auth true
  33. * @menu true
  34. * @throws \think\Exception
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. * @throws \think\exception\DbException
  38. * @throws \think\exception\PDOException
  39. */
  40. public function index()
  41. {
  42. $this->title = '文章管理';
  43. $type = $this->request->get('type');
  44. $cate = $this->request->get('cate');
  45. $this->_query($this->table)->like('title')->equal('type,cate,status')->dateBetween('create_at')
  46. ->where('is_del',1)
  47. ->order('id desc')
  48. ->page();
  49. }
  50. /**
  51. * 列表数据处理
  52. * @param array $data
  53. */
  54. protected function _index_page_filter(&$data)
  55. {
  56. //dump($data);
  57. }
  58. /**
  59. * 禁用
  60. * @auth true
  61. * @throws \think\Exception
  62. * @throws \think\exception\PDOException
  63. */
  64. public function forbid()
  65. {
  66. $this->_save($this->table, ['status' => '0']);
  67. }
  68. /**
  69. * 启用
  70. * @auth true
  71. * @throws \think\Exception
  72. * @throws \think\exception\PDOException
  73. */
  74. public function resume()
  75. {
  76. $this->_save($this->table, ['status' => '1']);
  77. }
  78. /**
  79. * 添加
  80. * @auth true
  81. * @throws \think\Exception
  82. * @throws \think\db\exception\DataNotFoundException
  83. * @throws \think\db\exception\ModelNotFoundException
  84. * @throws \think\exception\DbException
  85. * @throws \think\exception\PDOException
  86. */
  87. public function add()
  88. {
  89. $this->title = '添加文章';
  90. $this->create_at = date('Y-m-d H:i:s');
  91. $this->_form($this->table, 'form');
  92. }
  93. /**
  94. * 编辑
  95. * @auth true
  96. * @throws \think\Exception
  97. * @throws \think\db\exception\DataNotFoundException
  98. * @throws \think\db\exception\ModelNotFoundException
  99. * @throws \think\exception\DbException
  100. * @throws \think\exception\PDOException
  101. */
  102. public function edit()
  103. {
  104. $this->title = '编辑文章';
  105. $this->_form($this->table, 'form');
  106. }
  107. /**
  108. * 表单数据处理
  109. * @param array $data
  110. * @throws \think\Exception
  111. * @throws \think\db\exception\DataNotFoundException
  112. * @throws \think\db\exception\ModelNotFoundException
  113. * @throws \think\exception\DbException
  114. * @throws \think\exception\PDOException
  115. */
  116. protected function _form_filter(&$data)
  117. {
  118. if ($this->request->isGet()) {
  119. if (!empty($data)){
  120. $catelist = Db::name('cate')->where('type',$data['type'])->where('is_del',1)->where('status',1)->select();
  121. dump($catelist);
  122. }else{
  123. $catelist = Db::name('cate')->where('type',1)->where('is_del',1)->where('status',1)->select();
  124. }
  125. $this->catelist = $catelist;
  126. }else{
  127. if (!isset($data['icon']) || $data['icon']==''){
  128. $this->error('请上传图标');
  129. }
  130. if (!isset($data['content']) || $data['content']==''){
  131. $this->error('请填写内容');
  132. }
  133. }
  134. }
  135. /**
  136. * 处理成功回调
  137. */
  138. public function _form_result($result,$data){
  139. if ($result) {
  140. $this->success('成功',url('/#/store/article/index'));
  141. }
  142. }
  143. /**
  144. * 删除
  145. * @auth true
  146. * @throws \think\Exception
  147. * @throws \think\exception\PDOException
  148. */
  149. public function del()
  150. {
  151. $this->_save($this->table, ['is_del' => '0']);
  152. }
  153. /**
  154. * 获取类别
  155. */
  156. public function getcate(){
  157. $id=input('id');
  158. $add = Db::name('cate')->where('is_del',1)->where('status',1)->where('type', $id)->select();
  159. return $add;
  160. }
  161. }