insert([ "text"=>$post['content'], "imgs"=>json_encode($post['imgs']), "userid"=>$userid, "createtime"=>time(), "click"=>0 ]); Db::name("student")->inc("article_count",1)->where("id",$userid)->update(); return show("发布成功!",SUCCESS_CODE,[]); } public function delete(){ $userid = $GLOBALS['data']['userid']; if(empty($userid)){ return show("请登录后操作!",NEED_LOGIN); } $article_id = $GLOBALS['data']['data']["article_id"]; if(empty($article_id)){ return show("请上输入动态ID"); } $info = Db::name("app_article")->where("id",$article_id)->find(); if(empty($info) || $info['userid']!=$userid){ return show("找不到该动态信息!"); } Db::name("app_article")->where("id",$article_id)->delete(); return show("删除成功!",SUCCESS_CODE,[]); } public function lists(){ $userid = $GLOBALS['data']['userid']; if(empty($userid)){ return show("请登录后操作!",NEED_LOGIN); } $lastIndex = empty($GLOBALS['data']['data']["lastindex"])?0:$GLOBALS['data']['data']["lastindex"]; if($lastIndex == 0){ $where = "userid={$userid} and id>0"; }else{ $where = "userid={$userid} and id<".$lastIndex; } $result["lastIndex"] = 0; $result["list"] = []; $list = Db::name("app_article")->where($where)->order('id desc')->limit(env("page_count"))->select()->toArray(); foreach($list as $vo){ $result['lastIndex'] = $vo['id']; $result["list"][] = $vo; } if(count($list)where("id",$article_id)->find(); if(empty($info)) return show("找不到该动态信息!"); if(!empty($info['imgs'])) { $info['imgs'] = json_decode(str_replace(['{', '}'], ['[', ']'], $info['imgs']), true); } if(empty($info['imgs'])) $info['imgs'] = []; $info['other_list'] = []; $lists = Db::name('app_article') ->where("userid",$info["userid"]) ->where("id","<>",$info['id']) ->order("id desc") ->limit(env("page_count")) ->select(); foreach($lists as $vo){ $vo['imgs'] = ""; if(!empty($vo['imgs'])) { $vo['imgs'] = json_decode(str_replace(['{', '}'], ['[', ']'], $vo['imgs']), true); $vo['imgs']= $vo['imgs'][0]; } $info['other_list'][] = $vo; } $info['userinfo']=[]; $userinfo = Db::name("student")->where("id",$info['userid'])->field("nickname,avatar,age,type,disabled as is_disabled,city,school,hot")->find(); $info['userinfo'] = $userinfo; return show(SUCCESS_MESSAGE,SUCCESS_CODE,$info); } public function getlists(){ /* $userid = $GLOBALS['data']['userid']; if(empty($userid)){ return show("请登录后操作!"); } */ if(empty($GLOBALS['data']['data']['student_userid'])){ return show("请输入用户ID!"); } $student_userid = $GLOBALS['data']['data']['student_userid']; $student = Db::name("student")->field("id")->where("id",$student_userid)->find(); if(empty($student)) return show("找不到用户信息!"); $lastIndex = empty($GLOBALS['data']['data']["lastindex"])?0:$GLOBALS['data']['data']["lastindex"]; if($lastIndex == 0){ $where = "userid={$student_userid} and id>0"; }else{ $where = "userid={$student_userid} and id<".$lastIndex; } $result["lastIndex"] = 0; $result["list"] = []; $list = Db::name("app_article")->where($where)->order("id desc")->order('id desc')->limit(env("page_count"))->select()->toArray(); foreach($list as $vo){ $result['lastIndex'] = $vo['id']; $result["list"][] = $vo; } if(count($list)