Press.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\operate\controller;
  3. use app\common\model\User;
  4. use library\Controller;
  5. use think\Db;
  6. /**
  7. * 新闻
  8. * Class Press
  9. * @package app\operate\controller
  10. */
  11. class Press extends Controller
  12. {
  13. protected $table = 'Press';
  14. /**
  15. * 列表
  16. * @auth true
  17. * @menu true
  18. * @throws \think\Exception
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. * @throws \think\exception\DbException
  22. * @throws \think\exception\PDOException
  23. */
  24. public function index()
  25. {
  26. $this->title = '列表';
  27. $where = [];
  28. $where[] = ['f.is_deleted','=',0];
  29. if($title = input('title')) $where[] = ['f.title','like','%'.$title.'%'];
  30. $query = $this->_query($this->table)->alias('f')
  31. ->field('f.*')
  32. ->where($where)
  33. ->order('sort desc,f.id desc')->page();
  34. }
  35. /**
  36. * 添加
  37. * @auth true
  38. * @menu true
  39. * @throws \think\Exception
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. * @throws \think\exception\DbException
  43. * @throws \think\exception\PDOException
  44. */
  45. public function add()
  46. {
  47. $this->title = '添加';
  48. $this->_form($this->table, 'form');
  49. }
  50. /**
  51. * 编辑
  52. * @auth true
  53. * @menu true
  54. * @throws \think\Exception
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. * @throws \think\exception\DbException
  58. * @throws \think\exception\PDOException
  59. */
  60. public function edit()
  61. {
  62. $this->title = '编辑';
  63. $this->_form($this->table, 'form');
  64. }
  65. /**
  66. * 删除
  67. * @auth true
  68. * @throws \think\Exception
  69. * @throws \think\exception\PDOException
  70. */
  71. public function del()
  72. {
  73. $this->_save($this->table, ['is_deleted' => '1']);
  74. }
  75. /**
  76. * 回复
  77. * @auth true
  78. * @menu true
  79. * @throws \think\Exception
  80. * @throws \think\db\exception\DataNotFoundException
  81. * @throws \think\db\exception\ModelNotFoundException
  82. * @throws \think\exception\DbException
  83. * @throws \think\exception\PDOException
  84. */
  85. public function reply()
  86. {
  87. $this->title = '回复列表';
  88. $where = [];
  89. $where[] = ['r.is_deleted','=',0];
  90. $where[] = ['r.forum_id','=',input('id')];
  91. if($title = input('content')) $where[] = ['r.content','like','%'.$title.'%'];
  92. if($name = input('name')) $where[] = ['u.name','like','%'.$name.'%'];
  93. if($phone = input('phone')) $where[] = ['u.phone','=',$phone];
  94. $list = $this->_query('forum_reply')
  95. ->alias('r')
  96. ->field('r.*,u.name,u.phone,u.headimg')
  97. ->leftJoin('store_member u','u.id = r.user_id')
  98. ->where($where)
  99. ->order('r.id desc')->page();
  100. $this->assign('list',$list);
  101. $this->fetch('');
  102. }
  103. protected function _form_filter(&$data){
  104. if($this->request->isPost())
  105. {
  106. if(empty($data['title']))$this->error('请输入标题');
  107. if(empty($data['images']))$this->error('请上传封面');
  108. if(!empty($data['phone'])) {
  109. $user_id = User::where('phone|email',$data['phone'])->value('id');
  110. if(!$user_id) $this->error('账号未注册');
  111. $data['user_id'] = $user_id;
  112. }else{
  113. $data['user_id'] = '';
  114. }
  115. }
  116. }
  117. public function del_reply()
  118. {
  119. Db::name('forum_reply')->where('id',input('id'))->update(['is_deleted'=>1]);
  120. $this->success('删除成功');
  121. }
  122. protected function _form_result(&$data)
  123. {
  124. $this->success('操作成功', 'javascript:history.back()');
  125. }
  126. }