|
|
|
<?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);
|
|
|
|
}
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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']);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|