鼠笼管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.4 KiB

7 months ago
<?php
/**
* 待办接口
* @author YS
* @version 1.0
*/
class Api_RemindController extends Ctrl_Api{
public function init(){
$this->POST =json_decode(file_get_contents('php://input'),true);
}
7 months ago
public function addAction(){
$uid= empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$content = empty($this->POST['content'])?Tool_Fnc::apiMsg('未填写内容', '500'):$this->POST['content'];
$RemindModel = new RemindModel();
$data['user_id'] = $uid;
$data['content'] = $content;
$data['created'] = date("Y-m-d H:i:s",time());
if(!$RemindModel->insert($data)) Tool_Fnc::apiMsg('添加失败', '500');
Tool_Fnc::apiMsg('添加成功', '200');
}
7 months ago
public function getNoReadAction(){
$RemindModel = new RemindModel();
$uid= empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$list = $RemindModel->field("count(*) num")->where("is_delete=0 and user_id='{$uid}' and status=0")->fRow();
Tool_Fnc::apiMsg('获取成功', '200',$list);
}
7 months ago
public function getlistAction(){
$RemindModel = new RemindModel();
$uid= empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$list = $RemindModel->field("*")->where("is_delete=0 and user_id='{$uid}'")->order('id desc')->fList();
foreach($list as $key => &$val){
$val['created'] = $this->time_tran($val['created']);
7 months ago
}
7 months ago
Tool_Fnc::apiMsg('获取成功', '200',$list);
}
public function delAction(){
$RemindModel = new RemindModel();
$uid= empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$id= empty($this->POST['id'])?Tool_Fnc::apiMsg('待办ID缺失', '500'):$this->POST['id'];
$data['id'] = $id;
$data['is_delete'] = 1;
if(!$RemindModel->update($data)) Tool_Fnc::apiMsg('删除失败', '500');
Tool_Fnc::apiMsg('已删除', '200');
}
public function readremindAction(){
$RemindModel = new RemindModel();
$uid= empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
$id= empty($this->POST['id'])?Tool_Fnc::apiMsg('待办ID缺失', '500'):$this->POST['id'];
$data['id'] = $id;
$data['status'] = 1;
if(!$RemindModel->update($data)) Tool_Fnc::apiMsg('删除失败', '500');
Tool_Fnc::apiMsg('成功', '200');
}
function time_tran($the_time) {
$now_time = time();
$show_time = strtotime($the_time);
$dur = $now_time - $show_time;
if ($dur < 0) {
return date("m/d",$show_time);
} else {
if ($dur < 60) {
//return $dur . '秒前';
return '刚刚';
} else {
if ($dur < 3600) {
return floor($dur / 60) . '分钟前';
} else {
if ($dur < 86400) {
return floor($dur / 3600) . '小时前';
} else {
if ($dur < 259200) { // 3天内
return floor($dur / 86400) . '天前';
} else {
return date("m/d",$show_time);
}
}
}
7 months ago
}
}
}
}