WorkLog.class.php文件,主要负责将用户工作信息与日历信息结合起来。
<?php
namespace Util;
class WorkLog{
private $uid;//用户id
private $calendar;//日历对象
private $lastMonth;//上一个月
private $curMonth; //本月
private $nextMonth;//下一个月
private $monthWorkedDays;//当月工作的天数
private $workLog=null;//当前月的工作日历
public function __construct($uid=0,$daytime=null){
$this->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
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
$uid=1;
$daytime=I('daytime');
if(!empty($daytime)){
$daytime=date('Y-m-d',$daytime);
}
$WorkLog=new \Util\WorkLog($uid,$daytime);
$curDay=$WorkLog->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
<extend name="Public/base" />
<block name="css">
<style type="text/css">
*{margin: 0; padding: 0; border: 0; font-size: 16px;}
body{background-color: #4d56a3;}
ul{list-style: none;}
#mainBox{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;}
</style>
</block>
<block name="title">日历</block>
<block name="main">
<div id="mainBox">
<div id='leftBox'>
<div id="calendartitle">
<ul>
<li id="logoImg">
</li>
<li >
<div style="height:45px; line-height:45px; font-size:20px;">{$nowTime}</div>
<div style="height:45px; line-height:45px; font-size:20px;">{$curDay}</div>
</li>
</ul>
</div>
<div id="calendarcell">
<div id="cellHead">
<table cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td align="center">周日</td>
<td align="center">周一</td>
<td align="center">周二</td>
<td align="center">周三</td>
<td align="center">周四</td>
<td align="center">周五</td>
<td align="center">周六</td>
</tr>
</table>
</div>
<table cellpadding="0" cellspacing="0" border="0" id='calendarTable' align="center">
<tr>
<volist name="info" id="dayinfo" key='flag'>
<td align="center" class="{$dayinfo['info']['class']}">{$dayinfo['info']['day']}</td>
<if condition="$flag % 7 == 0 && $flag % 7 != 42 ">
</tr><tr>
</if>
</volist>
</table>
</div>
</div>
<div id='rightBox'>
<div id="action1" class="actionBox">
<ul>
<li><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="aBlock" onclick="todayAction(1)">工作</a></li>
<li><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="aBlock" onclick="todayAction(2)">休息</a></li>
</ul>
</div>
<div id="action2" class="actionBox">
<ul>
<li><a href="?daytime={$lastMDay}" rel="external nofollow" class="ainblock" >上一月</a><a href="?daytime={$nextMDay}" rel="external nofollow" class="ainblock" >下一月</a></li>
</ul>
</div>
<div id="action3" class="actionBox">
<ul>
<li>本月共计:{$curDaySum} 天</li>
<li>本月已工作:{$workDays} 天</li>
<li>本月剩余工作日:** 天</li>
<li>预计工资:**天</li>
</ul>
</div>
<div id="action4" class="actionBox">
<ul>
<li><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="aBlock">设置</a></li>
</ul>
</div>
</div>
</div>
</block>
<block name="js">
<script type="text/javascript" src="__JS__/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
function todayAction(type){
$.post("{:U('Log/addLog')}",{'type':type},function(data){
if(data['status']==1){
alert('数据添加完成');
}else{
alert('数据异常');
}
});
}
</script>
</block>
思路分析
ThinkPHP实现转换数据库查询结果数据到对应类型的方法这篇文章主要介绍了ThinkPHP实现转换数据库查询结果数据到对应类型的方法,涉及thinkPHP模型类操作及针对源码文件的相
thinkPHP中钩子的使用方法实例分析这篇文章主要介绍了thinkPHP中钩子的使用方法,结合实例形式分析了thinkPHP钩子的创建、添加、使用等相关操作技巧与注
学习thinkphp5.0验证类使用方法这篇文章主要介绍了thinkphp5.0验证类的简单有效的使用方法,一起学习下。
thinkphp5.0自定义验证规则使用方法本文主要讲了thinkphp5.0版本中自定义验证规则的使用方法和一些注意事项。
thinkPHP基于反射实现钩子的方法分析这篇文章主要介绍了thinkPHP基于反射实现钩子的方法,结合实例形式分析了php基于系统自带的ReflectionClass、ReflectionMet
thinkPHP通用控制器实现方法示例这篇文章主要介绍了thinkPHP通用控制器实现方法,结合实例形式分析了thinkPHP针对数据库的基本CURD操作方法的封装实现