From e81134b3abbe687d93a6f260e69dcc6bd03ad4cf Mon Sep 17 00:00:00 2001 From: JerryYan <792602257@qq.com> Date: Mon, 25 May 2020 21:42:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E4=BD=93=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hyhproject/app/controller/Note.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/hyhproject/app/controller/Note.php b/hyhproject/app/controller/Note.php index ff9d518..a99a338 100644 --- a/hyhproject/app/controller/Note.php +++ b/hyhproject/app/controller/Note.php @@ -8,17 +8,19 @@ class Note extends Base { public function index(){ $userId = (int)session('WST_USER.userId'); + $model = model("note")->field(true) + ->where(["user_id"=>$userId])->order("update_time", "desc") + ->select(); + return WSTReturn("OK", 1, $model); } public function detail(){ $userId = (int)session('WST_USER.userId'); if(($id = (int)input( 'id', 0)) > 0){ - return WSTReturn("", 1, [ - "id"=>$id, - "create_time"=>"昨天", - "title"=>"标题", - "content"=>"内容", - ]); + $detail = model("note")->field(true) + ->where(["user_id"=>$userId, "id"=>$id])->select(); + if(!$detail) return WSTReturn("该条内容已被删除",0); + return WSTReturn("OK", 1, $detail); } return WSTReturn("异常请求",0); } @@ -31,6 +33,14 @@ class Note extends Base if(empty($title)) return WSTReturn("请填写标题",0); if(empty($content)) return WSTReturn("请填写内容",0); if($id > 0){ + $detail = model("note")->field(true) + ->where(["user_id"=>$userId, "id"=>$id])->select(); + if(!$detail) return WSTReturn("该条内容已被删除",0); + model("note")->where(["user_id"=>$userId, "id"=>$id]) + ->save([ + "title"=>$title, + "content"=>$content, + ]); return WSTReturn("成功", 1); }elseif($id == 0){ return WSTReturn("成功", 1);