success(Db::name('chat_common_phrase')->where('user_id', $this->uid) ->order('sort', 'desc') ->field(['id', 'content', 'sort', 'created_time']) ->select()); } /** * 添加常用语 */ public function store(Request $request): Response { $content = $request->post('content', ''); $sort = $request->post('sort', 0); if (empty($content) || mb_strlen($content) > 500) { return $this->error('常用语内容不能为空且长度≤500字'); } // 有重复的内容不给添加 $msg = Db::name('chat_common_phrase')->where(['user_id' => $this->uid, 'content' => $content])->find(); if($msg) { return $this->error('此内容已经存在,不能重复添加'); } $res = Db::name('chat_common_phrase')->insert([ 'user_id' => $this->uid, 'content' => $content, 'sort' => $sort, 'created_time' => d(), ]); if($res) { return $this->success(); }else { return $this->error(); } } /** * 删除常用语 */ public function destroy(Request $request): Response { $id = $request->post('id'); $phrase = Db::name('chat_common_phrase')->where([ 'user_id' => $this->uid, 'id' => $id, ])->find(); if (!$phrase) { return $this->error('常用语不存在'); } $phrase_del = Db::name('chat_common_phrase')->where([ 'user_id' => $this->uid, 'id' => $id, ])->delete(); if($phrase_del) { return $this->success(); }else { return $this->error(); } } }