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);