鼠笼管理系统
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.

60 lines
4.1 KiB

7 months ago
<?php
class Admin_SquirrelController extends Ctrl_Admin{
7 months ago
public function indexAction(){
}
7 months ago
public function getlistAction(){
7 months ago
$SquirrelModel = new SquirrelModel();
7 months ago
$p = $_REQUEST;
$page = $p['page'];
$limit = $p['limit'];
$offset = ($page-1)*$limit;
6 months ago
$sql = "select * from {$SquirrelModel->table}";
7 months ago
$count = $SquirrelModel->query($sql);
6 months ago
$sql = "select * from {$SquirrelModel->table} order by id desc limit {$offset},{$limit} ";
7 months ago
$data = $SquirrelModel->query($sql);
foreach($data as $key => &$val){
$val['sex'] = $val['sex']==1?'公':'母';
}
$return['code'] = 0;
$return['count'] = count($count);
$return['data'] = $data;
$return['msg'] = "成功";
echo json_encode($return);die;
7 months ago
}
6 months ago
public function editAction(){
$SquirrelModel = new SquirrelModel();
$data['id'] = empty($_POST['id'])||!isset($_POST['id'])?Tool_Fnc::apiMsg('系统错误', '500'):Tool_Fnc::safe_string($_POST['id']);
$field = empty($_POST['field'])||!isset($_POST['field'])?Tool_Fnc::apiMsg('系统错误', '500'):Tool_Fnc::safe_string($_POST['field']);
$status = empty($_POST['status'])||!isset($_POST['status'])?0:Tool_Fnc::safe_string($_POST['status']);
$data[$field] = $status;
if(!$SquirrelModel->update($data)) Tool_Fnc::ajaxMsg('变更失败', '500');
Tool_Fnc::ajaxMsg('变更成功', '1');
}
public function editinfoAction(){
$SquirrelSetModel = new SquirrelSetModel();
$SquirrelModel = new SquirrelModel();
$data['id'] = empty($_POST['id'])||!isset($_POST['id'])?Tool_Fnc::apiMsg('系统错误', '500'):Tool_Fnc::safe_string($_POST['id']);
$data['uid'] = empty($_POST['uid'])||!isset($_POST['uid'])?Tool_Fnc::apiMsg('系统错误', '500'):Tool_Fnc::safe_string($_POST['uid']);
$data['sex'] =empty($_POST['sex'])||!isset($_POST['sex'])?Tool_Fnc::apiMsg('请选择性别', '500'):Tool_Fnc::safe_string($_POST['sex']);
$data['birthday'] =empty($_POST['birthday'])||!isset($_POST['birthday'])?Tool_Fnc::apiMsg('请填写生日', '500'):Tool_Fnc::safe_string($_POST['birthday']);
$data['father'] = empty($_POST['father'])||!isset($_POST['father'])?0:Tool_Fnc::safe_string($_POST['father']);
$data['mother'] = empty($_POST['mother'])||!isset($_POST['father'])?0:Tool_Fnc::safe_string($_POST['mother']);
$data['strains_id'] =empty($_POST['strains_id'])||!isset($_POST['strains_id'])?Tool_Fnc::apiMsg('请选择品系', '500'):Tool_Fnc::safe_string($_POST['strains_id']);
$data['gene'] =empty($_POST['gene'])||!isset($_POST['gene'])?Tool_Fnc::apiMsg('请填写基因', '500'):Tool_Fnc::safe_string($_POST['gene']);
$data['hair_color'] =empty($_POST['hair_color'])||!isset($_POST['hair_color'])?Tool_Fnc::apiMsg('请选择毛色', '500'):Tool_Fnc::safe_string($_POST['hair_color']);
$data['remark'] = empty($_POST['remark'])||!isset($_POST['remark'])?'':Tool_Fnc::safe_string($_POST['remark']);
//获取当前用户仓鼠的配置
$params['user_id'] = $data['uid'];
$squirrelSet = $SquirrelSetModel->getsetinfo($params);
//根据生日获取各个提醒时间
$data['weaning_time'] = date("Y-m-d",strtotime("+{$squirrelSet['weaning_time']} day",strtotime($data['birthday'])));
$data['nursing_time'] = date("Y-m-d",strtotime("+{$squirrelSet['nursing_time']} day",strtotime($data['birthday'])));
$data['grow_time'] =$data['sex']==1? date("Y-m-d",strtotime("+{$squirrelSet['male_grow_time']} days",strtotime($data['birthday']))):date("Y-m-d",strtotime("+{$squirrelSet['female_grow_time']} days",strtotime($data['birthday'])));
$data['infertility_time'] = date("Y-m-d",strtotime("+{$squirrelSet['infertility_time']} month",strtotime($data['birthday'])));
$data['dose_time'] = date("Y-m-d",strtotime("+{$squirrelSet['dose_time']} day",strtotime($data['birthday'])));
$ret = $SquirrelModel->update($data);
if(!$ret) Tool_Fnc::ajaxMsg('信息未变更', '500');
Tool_Fnc::ajaxMsg('信息更新成功', '1');
}
7 months ago
}