yangsai@163.com 6 months ago
parent f873b788a5
commit 06f9a74256
  1. 145
      application/controllers/Api/Remind.php
  2. 14
      application/models/Remind.php

@ -6,97 +6,72 @@
* @version 1.0
*/
class Api_RemindController extends Ctrl_Api{
public $SquirrelModel;
public $newSquirrelModel;
public $SquirrelSetModel;
public $CageModel;
public function init(){
$SquirrelModel = new SquirrelModel();
$newSquirrelModel = new NewSquirrelModel();
$SquirrelSetModel = new SquirrelSetModel();
$CageModel = new CageModel();
$this->POST =json_decode(file_get_contents('php://input'),true);
}
public function getListAction(){
$uid = empty($this->POST['uid'])?Tool_Fnc::apiMsg('请先登录', '500'):$this->POST['uid'];
//查询鼠提示信息
$Squirrel = $this->SquirrelModel->field('*')->where("c_user_id={$uid} and is_kill = 0 and is_delete=0")->fList();
$newSquirrel = $this->newSquirrelModel->field('*')->where("c_user_id={$uid} and is_kill = 0 and is_delete=0")->fList();
foreach($Squirrel as $key => $val){
//获取笼位号
$cage = $this->CageModel->field("number,type")->where("cage={$val['cage']}")->fRow();
$type = $cage['type']==1?"库存笼":"繁殖笼";
//断奶提醒
if($val['weaning_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】里{$val['number']}于{$val['weaning_time']}断奶";
}
//护理结束提醒
if($val['weaning_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】里{$val['number']}于{$val['weaning_time']}结束护理";
}
//性成熟时间提醒
if($val['grow_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】里{$val['number']}于{$val['weaning_time']}成熟";
}
//不育鼠时间提醒
if($val['infertility_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】里{$val['number']}于{$val['weaning_time']}结束不育时间";
}
//处死提醒
if($val['kill_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】里{$val['number']}{$val['weaning_time']}已到处死时间";
}
//删除提醒
if($val['del_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】里{$val['number']}{$val['weaning_time']}已到删除时间";
}
//剪尾提醒
if($val['jianwei_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】里{$val['number']}{$val['weaning_time']}改进行剪尾";
}
//实验提醒
if($val['test_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】里{$val['number']}已到可实验时间{$val['weaning_time']}";
}
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 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']);
}
foreach($newSquirrel as $key => $v){
//获取笼位号
$cage = $this->CageModel->field("number,type")->where("cage={$v['cage']}")->fRow();
$type = $cage['type']==1?"库存笼":"繁殖笼";
//断奶提醒
if($v['weaning_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】幼崽已到{$v['weaning_time']}断奶";
}
//护理结束提醒
if($v['weaning_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】幼崽已到{$v['weaning_time']}结束护理";
}
//性成熟时间提醒
if($v['grow_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】幼崽已到{$v['weaning_time']}成熟";
}
//不育鼠时间提醒
if($v['infertility_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】幼崽已到{$v['weaning_time']}结束不育时间";
}
//处死提醒
if($v['kill_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】幼崽已到{$v['weaning_time']}已到处死时间";
}
//删除提醒
if($v['del_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】幼崽已到{$v['weaning_time']}已到删除时间";
}
//剪尾提醒
if($v['jianwei_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】幼崽已到{$v['weaning_time']}改进行剪尾";
}
//实验提醒
if($v['test_time']==date("Y-m-d",time())){
$remind[] = "{$type}【{$cage['number']}】幼崽已到可实验时间{$v['weaning_time']}";
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);
}
}
}
}
}
Tool_Fnc::apiMsg('获取成功', '200');
}
}

@ -0,0 +1,14 @@
<?php
class RemindModel extends Orm_Base{
public $table = 'remind';
public $field = array(
'id' => array('type' => "int(11)",'comment' => ''),
'content' => array('type' => "varchar(45)",'comment' => '实验室名称'),
'created' => array('type' => "varchar(45)",'comment' => '是否删除'),
'user_id' => array('type' => "int(11)",'comment' => '添加时间'),
'status' => array('type' => "int(11)",'comment' => '添加时间'),
'is_delete' => array('type' => "int(11)",'comment' => '添加时间'),
);
public $pk = 'id';
}
Loading…
Cancel
Save