This commit is contained in:
knowpia
2022-09-08 15:23:13 +08:00
commit 96a49d1bd6
26 changed files with 1597 additions and 0 deletions

116
app/controller/Article.php Normal file
View File

@@ -0,0 +1,116 @@
<?php
namespace app\controller;
use think\facade\Db;
class Article
{
public function plus()
{
$post = $GLOBALS['data']['data'];
$userid = $GLOBALS['data']['userid'];
if(empty($userid)){
return show("请登录后再发布!");
}
if(empty($post['content'])){
return show("内容不能为空!");
}
if(empty($post['imgs'])){
return show("图片不能为空!");
}
Db::name("app_article")->insert([
"text"=>$post['content'],
"imgs"=>$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("请登录后操作!");
}
$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("请登录后操作!");
}
$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;
$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)<env("page_count")){
$result["lastIndex"] = 0;
}
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$result);
}
public function detail(){
if(empty($GLOBALS['data']['data']['article_id'])){
return show("请上传动态ID");
}
$article_id = $GLOBALS['data']['data']['article_id'];
$info = Db::name('app_article')->where("id",$article_id)->find();
if(empty($info)) return show("找不到该动态信息!");
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;
$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)<env("page_count")){
$result["lastIndex"] = 0;
}
return show(SUCCESS_MESSAGE,SUCCESS_CODE,$result);
}
}