php 日历排班的例子,基于ThinkPHP实现的日历功能实例详解
搜索热词
本文实例讲述了基于ThinkPHP实现的日历功能。分享给大家供大家参考,具体如下:
开发环境介绍
最新,闲来没事,便开发了一款简单的日历,来统计工作情况。为了开发便捷,使用ThinkPHP架构。界面如下图
备注:每页包含上一个月,当前月,下一个月的日期,并用不同的颜色区分,如果某天工作了,便圈出来。
主要是以下两个文件
重要文件描述
CalenDar.class.PHP主要负责,获取日历详细信息的,不涉及用户数据操作。
代码如下:
PHP;">
curYear=$_get['yeal'];
}else{
$this->curYear=date('Y');
}
if(isset($_get['month']) && is_numeric($_get['month'])){
$this->curMonth=$_get['month'];
}else{
$this->curMonth=date('n');
}
if(isset($_get['day']) && is_numeric($_get['day'])){
$this->curDay=$_get['day'];
}else{
$this->curDay=date('j');
}
$this->init($dateTime);
$this->createCalendar();
}
/**
*初始化
*/
public function init($dateTime=null){
if(!empty($dateTime)){ //当月
$this->curYear=date('Y',strtotime($dateTime));
$this->curMonth=date('n',strtotime($dateTime));
$this->curDay=date('j',strtotime($dateTime));
}
$this->curWek=date('w',strtotime($this->curYear.'-'.$this->curMonth.'-1'));
//上一个月
$this->lastMonth=$this->curMonth-1; //上一个月
$this->lastYear=$this->curYear; //上一个月属于哪一年
if($this->lastMonth<0){
$this->lastMonth=12;
$this->lastYear-=1;
}
//下一个月
$this->nextMonth=$this->curMonth+1;//下一个月
$this->nextYear=$this->curYear; //下一个月属于哪一年
if($this->nextMonth > 12){
$this->nextMonth=1;
$this->nextYear+=1;
}
}
public function getCalendar(){
return $this->calendar;
}
/**
*创建日历从周日 周一 周二 周三 周四 周五 周六,7*5方格,前面补上月后几天,后面补下月开始几天
**/
public function createCalendar(){
//判断当月共计多少天
$nextStr=$this->nextYear.'-'.$this->nextMonth.'-1 -1 days';
$curDaySum=date('j',strtotime($nextStr));
//判断上一个月最后一天是多少号
$lastStr=$this->curYear.'-'.$this->curMonth.'-1 -1 days';
$lastDaySum=date('j',strtotime($lastStr));
$prefixLId=$this->lastYear.'-'.$this->lastMonth;
$prefixCId=$this->curYear.'-'.$this->curMonth;
$prefixNId=$this->nextYear.'-'.$this->nextMonth;
if($this->curWek == 0){
$lastMonthSum=7; //需要添加上个月的$lastMonthSum天
}else{
$lastMonthSum=$this->curWek;
}
$lastMonthStart=$lastDaySum - $lastMonthSum+1;
for($i=0,$j=1,$k=1;$i<42;$i++){
$dateInfo=array();
if($icalendar[]=array('id'=>$id,'info'=>$dateInfo);
}else if($j > $curDaySum){//下一个月
$id=$prefixNId.'-'.$k;
$dateInfo['day']=$k;
$dateInfo['type']=3;
$this->calendar[]=array('id'=>$id,'info'=>$dateInfo);
$k++;
}else{//本月
$dateInfo['day']=$j;
$dateInfo['type']=2;
$this->calendar[]=array('id'=>($prefixCId.'-'.$j),'info'=>$dateInfo);
$j++;
$this->curDaySum+=1;
}
}
}
public function getDayTime(){
return $this->curYear.'-'.$this->curMonth.'-'.$this->curDay;
}
/**
*获取当前月属于哪个月
**/
public function getCurMonth(){
return $this->curYear.'-'.$this->curMonth;
}
/**
*获取上一个月属于哪个月
**/
public function getLastMonth(){
return $this->lastYear.'-'.$this->lastMonth;
}
/**
*获取下一个月属于哪个月
**/
public function getNextMonth(){
return $this->nextYear.'-'.$this->nextMonth;
}
/**
*判断当前月有多少天
**/
public function getCurDaySum(){
return $this->curDaySum;
}
}
WorkLog.class.PHP文件,主要负责将用户工作信息与日历信息结合起来。
PHP;">
uid=$uid;
$this->calendar=new \Util\CalenDar($daytime);
$this->lastMonth=$this->calendar->getLastMonth();
$this->curMonth=$this->calendar->getCurMonth();
$this->nextMonth=$this->calendar->getNextMonth();
$this->init();
}
public function init(){
$info=$this->calendar->getCalendar();
$userLog=array();
if($this->uid !=0){
$lastMonth=explode('-',$this->lastMonth);
$curMonth=explode('-',$this->curMonth);
$nextMonth=explode('-',$this->nextMonth);
//获取上一个月,当前月,下一个月的工作日志,后期使用缓存
$where='uid='.$this->uid.' AND ((`year`='.$lastMonth[0].' AND `month`='.$lastMonth[1].' ) or (`year`='.$curMonth[0].' AND `month`='.$curMonth[1].' ) or (`year`='.$nextMonth[0].' AND `month`='.$nextMonth[1].' ))';
$rs=M('work_log')->field('year,month,day,status')->where($where)->select();
foreach ($rs as $value) {
$userLog[$value['year'].'-'.$value['month'].'-'.$value['day']]=$value['status'];
}
}
$flag=1;
foreach ($info as $key=>$value) {
if($flag % 7 ==1 || $flag % 7 ==0){
$cellbgtype=3;//没有工作
}else{
$cellbgtype=1;//没有工作
}
if(isset($userLog[$value['id']]) && $userLog[$value['id']] ==1){
//判断是不是当前月份
$str=date('Y-n',strtotime($value['id']));
if($this->curMonth == $str){
$this->monthWorkedDays+=1;
}
$cellbgtype+=1;
}
$cellbgtype='daytype'.$cellbgtype.'_'.$value['info']['type'];
$info[$key]['info']['class']=$cellbgtype;
$flag++;
}
$this->workLog=$info;
}
public function getLastMonth(){
return $this->lastMonth;
}
public function getCurMonth(){
return $this->curMonth;
}
public function getNextMonth(){
return $this->nextMonth;
}
/**
*当月已经工作的天数
*/
public function monthWorkedDays(){
return $this->monthWorkedDays;
}
/**
*当月的天数
**/
public function monthDays(){
return $this->calendar->getCurDaySum();
}
/**
*获取累计工作的天数
**/
public function workedDays(){
}
/**
*当前工作日历的月份
**/
public function logMonth(){
}
/**
*当月截止到目前可得薪水
**/
public function hadSalary(){
}
/**
*预计可得最高薪水
**/
public function maxSalary(){
}
/**
*当前的工作日历
**/
public function workInfo(){
return $this->workLog;
}
}
IndexController.class.PHP
PHP;">
getCurMonth();
$lastMDay=strtotime($curDay.' -1 month');
$nextMDay=strtotime($curDay.' +1 month');
$nowTime=date('当前时间:Y年m月d号 H:i:s');
$curDayStr=date('日历时间:Y年m月d号',strtotime($curDay));
$info=$WorkLog->workInfo();
$curDaySum=$WorkLog->monthDays();
$workDays=$WorkLog->monthWorkedDays();
$this->assign('lastMDay',$lastMDay);
$this->assign('nextMDay',$nextMDay);
$this->assign('nowTime',$nowTime);
$this->assign('curDay',$curDayStr);
$this->assign('info',$info);
$this->assign('curDaySum',$curDaySum);
$this->assign('workDays',$workDays);
$this->display();
}
}
index.html
PHP;">
Box{width: 1024px; height:auto; margin:10px auto 0 auto; }
#leftBox{width:60%; height: 700px; float: left; border-radius:15px; margin-right:3%; background-color:#ffbd66; }
#rightBox{width:37%; height: 700px; float: right; border-radius:15px; background-color:#faf7dd}
#calendartitle{width: 95%; margin: 10px auto 5px auto; height: 110px; }
#calendartitle ul li{float: left; margin-right: 10px;}
#logoImg{width: 100px; height: 100px; border-radius: 10px; background-image: url('__IMG__/logo.png');background-repeat: no-repeat;}
#cellHead{width: 95%; background-color:#ffe786; border-radius:10px 10px 0 0; }
#cellHead td{width:80px; height:45px; font-size: 22px; }
#calendarcell{width: 95%; margin: 0 auto;}
#calendarTable td{width:80px; height:80px;background-repeat: no-repeat; border: 1px; font-size: 18px; }
.daytype1_1{background-image:url("__IMG__/cellbg1_0_1.png");}
.daytype2_1{background-image:url("__IMG__/cellbg1_1_1.png");}
.daytype1_2{background-image:url("__IMG__/cellbg1_0_2.png");}
.daytype2_2{background-image:url("__IMG__/cellbg1_1_2.png");}
.daytype1_3{background-image:url("__IMG__/cellbg1_0_3.png");}
.daytype2_3{background-image:url("__IMG__/cellbg1_1_3.png");}
.daytype3_1{background-image:url("__IMG__/cellbg2_0_1.png");}
.daytype4_1{background-image:url("__IMG__/cellbg2_1_1.png");}
.daytype3_2{background-image:url("__IMG__/cellbg2_0_2.png");}
.daytype4_2{background-image:url("__IMG__/cellbg2_1_2.png");}
.daytype3_3{background-image:url("__IMG__/cellbg2_0_3.png");}
.daytype4_3{background-image:url("__IMG__/cellbg2_1_3.png");}
.aBlock{display: block; text-decoration: none;}
.ainblock{display: inline-block; text-decoration: none;}
.actionBox{width: 80%; margin: 0 auto; margin-top:15px; background-color:#fadfbb; height: auto; padding-top: 20px; padding-bottom: 20px; border-radius: 10px; text-align: center;}
#action1 a{width:80%; margin: 0 auto 15px auto; height: 45px; background-color: #ffec42; border-radius: 10px; line-height: 45px; text-align: center; font-size: 22px; color: #ad5408; font-weight: 700;}
#action1 a:hover{font-size: 24px; color:#F12;}
#action2{text-align: center;}
#action2 a{width: 80px; background-color: #ffec42; border-radius: 10px; height: 35px; line-height: 35px; text-align: center; margin-right: 10px;}
#action3{text-align: left;}
#action3 ul li{margin-left:20px; border-bottom: 1px dashed #999;margin-right:10px; margin-bottom: 10px; font-size: 20px;}
Box">
logoImg">
Box">
Box">
本月共计:{$curDaySum} 天
本月已工作:{$workDays} 天
本月剩余工作日:** 天
预计工资:**天
Box">
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
php 日历排班的例子,基于ThinkPHP实现的日历功能实例详解相关推荐
- java mysql教程基于_java基于jdbc连接mysql数据库功能实例详解
本文实例讲述了java基于jdbc连接mysql数据库的方法.分享给大家供大家参考,具体如下: 一.JDBC简介 Java 数据库连接,(Java Database Connectivity,简称JD ...
- php 调用日历控制,基于ThinkPHP实现的日历功能实例详解
本文实例讲述了基于ThinkPHP实现的日历功能.分享给大家供大家参考,具体如下: 开发环境介绍 最新,闲来没事,便开发了一款简单的日历,来统计工作情况.为了开发便捷,使用ThinkPHP架构.界面如 ...
- python对象编程例子-Python3.5面向对象编程图文与实例详解
本文实例讲述了Python3.5面向对象编程.分享给大家供大家参考,具体如下: 1.面向过程与面向对象的比较 (1)面向过程编程(procedural programming) 面向过程编程又被称为: ...
- php选择符和举例子,关于CSS3中选择符的实例详解
英文原文: www.456bereastreet.com/archive/200601/css_3_selectors_explained/ 中文翻译: www.dudo.org/article.as ...
- tomcat处理html流程,基于Tomcat运行HTML5 WebSocket echo实例详解
一.概述 作为HTML5新特性之一的WebSocket组件,在实时性有一定要求的WEB应用开 发中还是有一定用武之地,高版本的IE.Chrome.FF浏览器都支持Websocket,标准的Websoc ...
- php日历排班表,日历排班表软件下载
日历排班表软件app是一款掌上智能排版助手.日历排班表软件app主要为有倒班.值班需求的工作人员提供智能排班功能,您可以通过日历排班表软件app输入对应的数据,就可以精准算出自己的上班.值班时间,非常 ...
- php日历排班表,排班表 : 轮班工作者必备的排班神器
排班表是一款实用的排班软件, 它帮助有规律轮班的人群清晰记录白班.夜班.休息时间,并用多种颜色.图标进行标注,解决繁琐的排班问题.支持同步到系统日历和通知中心下拉查看,还支持农历和起床闹钟. 清晰易用 ...
- 巡检路线排班问题matlab,基于数学建模的巡检线路排班设计
黄家云:基于数学建模的巡检线路排班设计 49 基于数学建模的巡检线路排班设计 黄家云 夏伟 蒋娜 张磊 (芜湖职业技术学院基础部,安徽芜湖,241003) 摘 要:巡检线路的排班设计是 2017 年全 ...
- php字段验证规则,ThinkPHP 自动验证及验证规则详解
ThinkPHP 自动验证及验证规则详解 ThinkPHP 自动验证 ThinkPHP 内置了数据对象的自动验证功能来完成模型的业务规则验证.自动验证是基于数据对象的,而大多情况下数据对象是基于 $_ ...
最新文章
- SQL Server 2012入门T-SQL基础篇:(1)环境准备
- 如何设置VSS源代码管理工具使用KDiff3
- 抽象工厂+反射+依赖注入 实现对数据访问层和业务逻辑层的优化
- 前端dashboard框架_微前端在网易七鱼的实践
- 第47讲:scrapy-redis分布式爬虫介绍
- jpa获取数据库当前时间_SpringDataJPA存储数据时通过注解自动设置创建时间和修改时间...
- UVa OJ 128 - Software CRC (软件CRC)
- 波段顶底 tdx 副图指标
- 移动硬盘“脱机”(签名冲突)的硬盘如何正常使用
- SQL Server 2005 彻底卸载、重装问题
- 6、微信小程序的布局
- 做好ToB运营:避开4个误区和掌握3个获客方式
- 用计算机清点木材的数量,木材检验员培训课件-木材出入库管理.ppt
- 计算机屏幕怎么设置键盘,[怎么用屏幕键盘]怎么用键盘调屏幕分辨率
- load_weights` requires h5py when loading weights from HDF5
- 今天是2019年最后一天,全球金融危机,离我们已经过去十年了
- 安装SQLSERVER2000时出现以前的某个程序安装已在安装计算机上创建挂起的文件操作
- 致远OA,小地球启动报错:读取系统初始化信息失败!
- 经典算法之基数排序两种实现
- 动手学习深度学习感悟