isAjax()) { $param = input('param.'); $limit = $param['pageSize']; $offset = (($param['pageNumber'] - 1) * $limit); $where = []; if (empty($param['searchText']) === false) { $where['robot_name'] = $param['searchText']; } $join = [ 'groups b' => 'a.groups_id = b.id', 'robotgroups c' => 'a.robotgroups_id = c.robotgroups_id', ]; $result = model('Robot')->selectJoin($join, $where, $offset, $limit); foreach ($result as $key => $vo) { // 优化显示状态. if(1 === $vo['robot_status']) { $result[$key]['robot_status'] = '启用'; } else { $result[$key]['robot_status'] = '禁用'; } // 优化显示热点问题. if (1 === $vo['robot_host']) { $result[$key]['robot_host'] = ''; } else { $result[$key]['robot_host'] = ''; } // 生成操作按钮. $result[$key]['operate'] = $this->makeBtn($vo['robot_id']); } // 总数据. $return['total'] = model('Robot')->count($where); $return['rows'] = $result; return json($return); } return $this->fetch(); } // 添加智能问答 public function addWord() { if(request()->isPost()){ $param = input('post.'); $param['robot_content'] = trim($param['robot_content']); $robotWhere = [ 'robot_name' => $param['robot_name'], 'groups_id' => $param['groups_id'], 'robotgroups_id' => $param['robotgroups_id'], ]; $has = db('robot')->field('robot_id')->where($robotWhere)->find(); if(!empty($has)){ return json(['code' => -1, 'data' => '', 'msg' => '该智能问答已经存在']); } $param['robot_addTime'] = date('Y-m-d H:i:s'); $param['robot_updateTime'] = date('Y-m-d H:i:s'); try{ db('robot')->insert($param); }catch(\Exception $e){ return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]); } return json(['code' => 1, 'data' => '', 'msg' => '添加智能问答成功']); } $groups = db('groups')->where('status', 1)->select(); $robotgroups = db('robotgroups')->where('robotgroups_status', 1)->select(); $this->assign([ 'status' => config('kf_status'), 'host' => config('host'), 'groups' => $groups, 'robotgroups' => $robotgroups, ]); return $this->fetch(); } // 编辑智能问答 public function editWord() { if(request()->isAjax()){ $param = input('post.'); $param['robot_content'] = trim($param['robot_content']); $param['robot_updateTime'] = date('Y-m-d H:i:s'); $robotWhere = [ 'robot_name' => $param['robot_name'], 'groups_id' => $param['groups_id'], 'robotgroups_id' => $param['robotgroups_id'], ]; // 检测用户修改的智能问答是否重复 $has = db('robot')->where($robotWhere)->count(); if($has>1){ return json(['code' => -1, 'data' => '', 'msg' => '该智能问答已经存在']); } try{ db('robot')->where('robot_id', $param['robot_id'])->update($param); }catch(\Exception $e){ return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]); } return json(['code' => 1, 'data' => '', 'msg' => '编辑智能问答成功']); } $id = input('param.robot_id/d'); $info = db('robot')->where('robot_id', $id)->find(); $groups = db('groups')->where('status', 1)->select(); $robotgroups = db('robotgroups')->where('robotgroups_status', 1)->select(); $this->assign([ 'info' => $info, 'host' => config('host'), 'groups' => $groups, 'robotgroups' => $robotgroups, 'status' => config('kf_status') ]); return $this->fetch(); } // 删除智能问答 public function delWord() { if(request()->isAjax()){ $id = input('param.id/d'); try{ db('robot')->where('robot_id', $id)->delete(); }catch(\Exception $e){ return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]); } return json(['code' => 1, 'data' => '', 'msg' => '删除智能问答成功']); } } // 生成按钮 private function makeBtn($id) { $operate = ''; $operate .= ' '; $operate .= ' '; return $operate; } }