title = '用户咨询管理'; $this->engineer_id = session('user.engineer_id'); $this->byWhere(1)->field('a.*,b.name,b.headimg')->order('a.id desc')->page(); } /** * 搜索条件 * @return \library\helper\QueryHelper */ protected function byWhere($type) { if ($type == 1) { $query = $this->_query($this->table); } elseif ($type == 2) { $query = Db::name($this->table); } $query = $query->alias('a')->join('store_member b', 'a.user_id=b.id'); $query->where('a.type = 1'); $engineer_id = session('user.engineer_id'); if($engineer_id > 0){ $query->where('a.from_user_id = '.$engineer_id.' or a.is_answer = 0'); } if (isset($_GET['create_time']) && $_GET['create_time']) { $time = explode(' - ', $_GET['create_time']); $start_date_time = $time[0] . ' 00:00:00'; $end_date_time = $time[1] . ' 23:59:59'; $query->whereBetweenTime('a.create_time', $start_date_time, $end_date_time); } if (isset($_GET['user_info']) && $_GET['user_info']) { $query->where('b.name|b.phone', '=', $_GET['user_info'] ); } return $query; } /**咨询列表处理 * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ protected function _index_page_filter(array &$data) { $mids = array_unique(array_merge(array_column($data, 'user_id'), array_column($data, 'from_mid'))); $memberList = Db::name('StoreMember')->whereIn('id', $mids)->select(); foreach ($data as &$vo) { list($vo['member'], $vo['from_member'], $vo['list']) = [[], [], []]; foreach ($memberList as $member) if ($member['id'] === $vo['user_id']) { $vo['member'] = $member; } } } /** * 立即解答 * @auth true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function answer() { $id = $this->app->request->get('id'); $this->assign('id', $id); $post = $this->app->request->post(); if (isset($post['id']) && $post['id']) { $root_consult_id = Db::name('store_consult')->where('id',$id)->value('root_consult_id'); $consult_data = array( 'user_id' => session('user.engineer_id'), 'content' => $post['answer_content'], 'consult_id' => $id, 'root_consult_id' => $root_consult_id, 'type' => 2 ); Db::name('store_consult')->where('id',$id)->update(array('is_answer'=>1,'from_user_id'=>session('user.engineer_id'))); Db::name('store_consult')->insert($consult_data); //添加消息通知 $user_id = Db::name('store_consult')->where('id',$id)->value('user_id'); $new_data = array( 'user_id' => $user_id, 'content' => '您咨询的问题得到了新的回复,赶紧快来查看~', 'consult_id' => $root_consult_id, 'type' => 2 ); Db::name('store_news')->insert($new_data); $this->success('解答成功'); } else { $this->_form($this->table, 'answer'); } } }