123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <?php
- namespace app\operate\controller;
- use app\common\model\ForumReply;
- use app\common\model\UserForum;
- use app\common\model\UserLevel;
- use app\common\model\UserMessage;
- use library\Controller;
- use think\Db;
- /**
- * 问答
- * Class Forum
- * @package app\operate\controller
- */
- class Forum extends Controller
- {
- protected $table = 'UserForum';
- /**
- * 列表
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function index()
- {
- $this->title = '列表';
- $where = [];
- $where[] = ['f.is_deleted','=',0];
- if($title = input('title')) $where[] = ['f.title','like','%'.$title.'%'];
- if($name = input('name')) $where[] = ['u.name','like','%'.$name.'%'];
- if($phone = input('phone')) $where[] = ['u.phone','=',$phone];
- $query = $this->_query($this->table)->alias('f')
- ->field('f.*,u.name,u.phone,u.headimg')
- ->leftJoin('store_member u','u.id = f.user_id')
- ->where($where)
- ->order('sort desc,f.id desc')->page();
- }
- protected function _index_page_filter(&$data){
- $app_name = sysconf('app_name');
- $app_logo = sysconf('app_logo');
- foreach ($data as &$v)
- {
- if(!$v['user_id']) $v['name'] = $app_name;
- if(!$v['user_id']) $v['headimg'] = $app_logo;
- }
- }
- /**
- * 添加
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function add()
- {
- $this->title = '添加';
- $this->_form($this->table, 'form');
- }
- /**
- * 编辑
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function edit()
- {
- $this->title = '编辑';
- $this->_form($this->table, 'form');
- }
- /**
- * 删除
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function del()
- {
- $this->_save($this->table, ['is_deleted' => '1']);
- }
- /**
- * 回复
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function reply()
- {
- $this->title = '回答列表';
- $where = [];
- $where[] = ['r.is_deleted','=',0];
- $where[] = ['r.forum_id','=',input('id')];
- if($title = input('content')) $where[] = ['r.content','like','%'.$title.'%'];
- if($name = input('name')) $where[] = ['u.name','like','%'.$name.'%'];
- if($phone = input('phone')) $where[] = ['u.phone','=',$phone];
- $list = $this->_query('forum_reply')
- ->alias('r')
- ->field('r.*,u.name,u.phone,u.headimg')
- ->leftJoin('store_member u','u.id = r.user_id')
- ->where($where)
- ->order('r.is_top desc,r.id desc')->page();
- $this->assign('list',$list);
- $this->fetch('');
- }
- protected function _reply_page_filter(&$data){
- $app_name = sysconf('app_name');
- $app_logo = sysconf('app_logo');
- foreach ($data as &$v)
- {
- if(!$v['user_id']) $v['name'] = $app_name;
- if(!$v['user_id']) $v['headimg'] = $app_logo;
- }
- }
- public function del_reply()
- {
- Db::name('forum_reply')->where('id',input('id'))->update(['is_deleted'=>1]);
- $this->success('删除成功');
- }
- protected function _form_result(&$data)
- {
- $this->success('操作成功', 'javascript:history.back()');
- }
- protected function _form_filter(&$data)
- {
- $this->level_arr = UserLevel::column('name','id');
- }
- /**
- * 回答问题
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function reply_forum()
- {
- if($this->request->isGet()) {
- $forum_info = UserForum::where('id',input('forum_id'))->find()->toArray();
- $this->assign('forum_info',$forum_info);
- $this->_form($this->table,'reply_forum');
- }else if ($this->request->isPost()){
- $id = input('post.id');
- $content = input('post.content');
- if(!$content) $this->error('请输入内容');
- $issue_user = UserForum::where('id',$id)->value('user_id');
- $res = ForumReply::create(['user_id'=>0,'content'=>$content,'issue_user'=>$issue_user,'forum_id'=>$id]);
- if($issue_user)UserMessage:: sendUserMessage($issue_user,'forum',5,0,0,$id,'平台回复了您的提问');
- $this->success('回答完成');
- }
- }
- /**
- * 置顶设置
- * @auth true
- * @menu true
- * @param array $data
- */
- public function stick()
- {
- $this->_save('forum_reply', ['is_top' => input('is_top')]);
- }
- }
|