<?php

/**
 * @author darkredz
 */

class HolidayController extends DooController {

	public $staff;

	function __construct() {
		if(isset($_COOKIE["staff"])){
			if(!empty($_COOKIE["staff"])){
				Doo::loadModel ( 'staff' );
				$staff = new staff ();
				$this->staff=$staff->getUserByIdList($_COOKIE["staff"]);

				return "/";
			}
		}

		Doo::loadCore ( 'uri/DooUriRouter' );
		$router = new DooUriRouter ();
		$routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );

		if($routeRs['1']!="login"){
			header ( 'Content-Type:text/html;charset=utf-8' );
			@header ( "Location: /login"  );
		}
	}

	public function myList(){
		$checkadmin = $this->checkisadmin();
		if($checkadmin){
			$data['cansee'] = 1;
		}
		Doo::loadModel('holidayday');
		Doo::loadModel('holiday');
		Doo::loadModel('holidaystaff');
		$hday = new HDay();
		$holiday = new Holiday();
		$hstaff = new HStaff();

		$thisyear = date('Y',time());
//		$thisyear = date('Y',1546358400);
		$num = intval($thisyear)-2017;
		$html = '';
		$yearnum = isset($this->params['yearnum']) && is_numeric($this->params['yearnum']) ? $this->params['yearnum'] : '';
		for($i = $num; $i >= 0; $i--){
			if($yearnum == (2017+$i)){
				$html .= '<option value="'.(2017+$i).'" selected>'.(2017+$i).'</option>';
			}else{
				$html .= '<option value="'.(2017+$i).'">'.(2017+$i).'</option>';
			}
		}
		$data['option'] = $html;
		$yeartime = isset($this->params['yearnum']) && is_numeric($this->params['yearnum']) ? $this->getYearMonthTime($this->params['yearnum']) : $this->getYearMonthTime($thisyear);
		//记录事，病，旷，加，值，补,调的信息
		$holidaymsg = array('1'=> array(), '2' => array(), '3' => array(), '4' => array(), '5' => array(), '10' => array(), '11' => array());
		foreach(array(1,2,3,4,5,10,11) as $k => $v){
			$all = 0;
			for($i = 0; $i < 12; $i++){
				if($v == 11){
					$typeholiday = $holiday->find(array('where' => 'status=1 and type='.$v.' and uid='.$this->staff[0]['sid'].' and addtime between '.$yeartime[$i]['starttime'].' and '.$yeartime[$i]['endtime'],'asArray' => TRUE));
					$holidaymsg[$v][$i+1] = 0;
					if(!empty($typeholiday)){
						foreach($typeholiday as $tk => $tv){
							$holidaymsg[$v][$i+1] += floatval($tv['daynum']);
							$all += floatval($tv['daynum']);
						}
					}
					$holidaymsg[$v][$i+1] = $holidaymsg[$v][$i+1] != 0 ? $holidaymsg[$v][$i+1] : '';
				}else{
					$typeholiday = $hday->find(array('where' => 'type='.$v.' and uid='.$this->staff[0]['sid'].' and UNIX_TIMESTAMP(daytime) between '.$yeartime[$i]['starttime'].' and '.$yeartime[$i]['endtime'],'asArray' => TRUE));
					$holidaymsg[$v][$i+1] = 0;
					if(!empty($typeholiday)){
						foreach($typeholiday as $tk => $tv){
							$holidaymsg[$v][$i+1] += floatval($tv['daymsg']);
							$all += floatval($tv['daymsg']);
						}
					}
					$holidaymsg[$v][$i+1] = $holidaymsg[$v][$i+1] != 0 ? $holidaymsg[$v][$i+1] : '';
				}
			}
			$holidaymsg[$v]['all'] = $all != 0 ? $all : '';
		}

		$hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$this->staff[0]['sid'], 'asArray' => TRUE));
		$data['yearnum'] = floatval($hstaffmsg['yearnum']);
		$data['overtimetnum'] = floatval($holidaymsg[4]['all'])+floatval($holidaymsg[5]['all']);
		$data['addnum'] = floatval($hstaffmsg['addnum']);
		$data['hunjianum'] = floatval($hstaffmsg['hunjianum']);
		$data['chanjianum'] = floatval($hstaffmsg['chanjianum']);
		$data['sangjianum'] = floatval($hstaffmsg['sangjianum']);
		$data['gongjianum'] = floatval($hstaffmsg['gongjianum']);

		$data['yearround'] = $this->getYearRoundtime($hstaffmsg['hadyear'],$this->staff[0]['hiredate'],$this->staff[0]['hireBiasDate']);

//		var_dump($holidaymsg);
//		exit;

		$data['holidaymsg'] = $holidaymsg;

		$data ['memu'] = 'holiday';
		$data ['holidaymenu'] = 'mylist';
		$data ['staff'] = $this->staff;
		$data['noindexjs'] = 'noindexjs';
		$this->render ( "/holiday-myList", $data );
	}

	public function holidayBorad(){
		$checkadmin = $this->checkisadmin();
		if($checkadmin){
			$data['cansee'] = 1;
		}
		Doo::loadModel('holiday');
		Doo::loadModel('holidayday');
		Doo::loadModel('holidaystaff');
		Doo::loadModel('holidaytype');
		$thismonth = $this->getMonthTime(date('Y-m-d',time()));
		$data['countmonth'] = date("Y年m月",time());

		$holiday = new Holiday();
		$hday  = new HDay();
		$hstaff = new HStaff();
		$type = new HType();

		$holidaycount =array();
		foreach(array(1,2,3,4,5) as $k => $v){
			$typeholiday = $hday->find(array('where' => 'type='.$v.' and uid='.$this->staff[0]['sid'].' and UNIX_TIMESTAMP(daytime) between '.$thismonth['start'].' and '.$thismonth['end'],'asArray' => TRUE));
			$holidaycount[$k] = 0;
			if(!empty($typeholiday)){
				foreach($typeholiday as $tk => $tv){
					$holidaycount[$k] += floatval($tv['daymsg']);
				}
			}
		}

		$hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$this->staff[0]['sid'], 'asArray' => TRUE));
		$holidaycount[5] = floatval($hstaffmsg['yearnum']);
		$holidaycount[6] = floatval($hstaffmsg['addnum']);

		$data['holidaycount'] = $holidaycount;

		$holidaymsg = $holiday->find(array('where' => 'uid='.$this->staff[0]['sid'], 'limit' => 10, 'desc' => 'approvetime', 'desc' => 'id', 'asArray' => TRUE));
		if(!empty($holidaymsg)){
			foreach($holidaymsg as $k => $v){
				$holidaymsg[$k]['typename'] = $type->getTypeNamebyid($v['type']);
				$holidaymsg[$k]['daynum'] = floatval($v['daynum']);
				$holidaymsg[$k]['approvetime'] = !empty($v['approvetime']) ? date('Y-m-d H:i:s',$v['approvetime']) : '';
				$msg = '';
				if(in_array($v['type'],array(1,2,3,4,5,10,11,12))){
					$dayjson = json_decode($v['dayjson']);
					if($v['type'] != 11){
						$holidaydays = $this->geyDayMsg($dayjson->holiday);
						foreach($holidaydays as $hk => $hv){
							$msg .= $hv['daytime'].' '.$hv['daymsg'].',';
						}
						$msg = substr($msg,0,strlen($msg)-1);
					}else{
						$msg .= '休假时间：';
						$holidaydays = $this->geyDayMsg($dayjson->holiday);
						foreach($holidaydays as $hk => $hv){
							$msg .= $hv['daytime'].' '.$hv['daymsg'].',';
						}
						$msg = substr($msg,0,strlen($msg)-1);
						$msg .= '
加班时间：';
						$overtimedays = $this->geyDayMsg($dayjson->overtime);
						foreach($overtimedays as $ok => $ov){
							$msg .= $ov['daytime'].' '.$ov['daymsg'].',';
						}
						$msg = substr($msg,0,strlen($msg)-1);
					}
				}elseif(in_array($v['type'],array(6,7,8,9))){
					$msg .= $v['starttime']. ' 至 '.$v['endtime'];
				}elseif(in_array($v['type'],array(13,14,15,16,17,18,19))){
					$msg .= date('Y-m-d H:i:s',$v['addtime']);
				}
				$holidaymsg[$k]['daymsg'] = $msg;
			}
			$data['holidaylist'] = $holidaymsg;
		}

		$data ['memu'] = 'holiday';
		$data ['holidaymenu'] = 'borad';
		$data ['staff'] = $this->staff;
		$data['noindexjs'] = 'noindexjs';

		//公司每日考勤内容
		if($hstaffmsg['isadmin'] == 1 || $hstaffmsg['iscc'] == 1){
			$data['youcantseeme'] = 0;
			//今日请假人员,区分总部和办事处
			Doo::loadModel('staff');
			$staff = new staff();
			$headquarters = $branch = $leaves = array();
			$today = date('Y-m-d',time());
			$data['today'] = date('m月d日',time());
			//短假的
			$hdayarr = $hday->find(array('where' => 'daytime=?', 'param' => array($today), 'asArray' => TRUE));
			if(!empty($hdayarr)){
				foreach($hdayarr as $hk => $hv){
					$onearr = array();
					$onehmsg = $holiday->getOne(array('where' => 'id=?', 'param' => array($hv['hid']), 'asArray' => TRUE));
					$staffmsg = $staff->getOne(array('where' => 'sid=?', 'param' => array($hv['uid']), 'asArray' => TRUE));
					$onearr['type'] = $type->getTypeNamebyid($onehmsg['type']);
					$onearr['staff'] = $staffmsg['username'];
					$onearr['day'] = floatval($onehmsg['daynum']);
					if($staffmsg['cid'] == 12){
						array_push($headquarters,$onearr);
					}else{
						array_push($branch,$onearr);
					}
					array_push($leaves,$hv['uid']);
				}
			}
			//长假的
			$hdayarr2 = $holiday->find(array('where' => 'status=1 and type in (6,7,8,9) and UNIX_TIMESTAMP(starttime)<=UNIX_TIMESTAMP(?) and UNIX_TIMESTAMP(endtime)>=UNIX_TIMESTAMP(?)', 'param' => array($today,$today), 'asArray' => TRUE));
			if(!empty($hdayarr2)){
				foreach($hdayarr2 as $hk2 => $hv2){
					$onearr = array();
					$staffmsg = $staff->getOne(array('where' => 'sid=?', 'param' => array($hv2['uid']), 'asArray' => TRUE));
					$onearr['type'] = $type->getTypeNamebyid($hv2['type']);
					$onearr['staff'] = $staffmsg['username'];
					$onearr['day'] = floatval($hv2['daynum']);
					if($staffmsg['cid'] == 12){
						array_push($headquarters,$onearr);
					}else{
						array_push($branch,$onearr);
					}
					array_push($leaves,$hv2['uid']);
				}
			}
			$data['headquarters'] = $headquarters;
			$data['branch'] = $branch;

			//今天在勤人员名单
			$hqstaffarr = $staff->find(array('where' => 'cid=12 and departmentID=0', 'asArray' => TRUE));
			$onlinehq = array();
			foreach($hqstaffarr as $hqk => $hqv){
				if(!in_array($hqv['sid'],$leaves)){
					array_push($onlinehq,$hqv['username']);
				}
			}
			$onlinebr = array();
			Doo::loadModel('L_category');
			$lcate = new L_category();
			$catearr = $lcate->find(array('where' => 'cid!=34', 'asArray' => TRUE));
			foreach($catearr as $ck => $cv){
				if($cv['cid'] == 12){
					$brstaffarr = $staff->find(array('where' => 'cid=? and departmentID=1', 'param' => array($cv['cid']), 'asArray' => TRUE));
				}else{
					$brstaffarr = $staff->find(array('where' => 'cid=?', 'param' => array($cv['cid']), 'asArray' => TRUE));
				}
				$brsarr = array();
				if(!empty($brstaffarr)){
					foreach($brstaffarr as $brk => $brv){
						if(!in_array($brv['sid'],$leaves)) {
							array_push($brsarr, $brv['username']);
						}
					}
				}
				$brstaffstr = !empty($brsarr) ? implode('、', $brsarr) : '';
				$title = $cv['cid'] == 12 ? '总部-造价研究中心' : $cv['title'];
				$onebrarr = array('title' => $title,'online' => $brstaffstr);
				array_push($onlinebr,$onebrarr);
			}
//			var_dump($onlinebr);
//			$brstaffarr = $staff->find(array('where' => ''));
			$data['onlineheadquarters'] = implode('、',$onlinehq);
			$data['onlinebranch'] = $onlinebr;

//			var_dump(array_unique($leaves));
		}else{
			$data['youcantseeme'] = 1;
		}
		$this->render ( "/holiday-borad", $data );
	}

	public function allList(){
		$checkadmin = $this->checkisadmin();
		if($checkadmin){
			$data['cansee'] = 1;
		}
		Doo::loadModel('holiday');
		Doo::loadModel('holidaytype');
		$holiday = new Holiday();
		$type = new HType();
		if(isset($this->params['type'])){
			if($this->params['type'] == 4 ){//加班、值班
				$sql = ' and (type=4 or type=5)';
			}elseif($this->params['type'] == 6){//其他，管理员操作
				$sql = ' and type in(3,6,7,8,9,13,14,15,16,17,18,19)';
			}else{
				$sql = ' and type='.$this->params['type'];
			}
			$pagemsg = '/type/'.$this->params['type'];
			$data['thistype'] = $this->params['type'];
		}else{
			$sql = '';
			$pagemsg = '';
			$data['thistype'] = '';
		}

		Doo::loadHelper('DooPager');
		$totalArchive = $holiday->count(array('where' => 'uid='.$this->staff[0]['sid'].$sql, 'asArray' => TRUE));
		$pager = new DooPager(Doo::conf()->APP_URL . "holidayallList".$pagemsg."/page", $totalArchive, 10, 10);
		if (isset($this->params['pindex']))
			$pager->paginate(intval($this->params['pindex']));
		else
			$pager->paginate(1);
		if ($pager->limit != ' -10,10')
			$holidaymsg = $holiday->find(array('where' => 'uid='.$this->staff[0]['sid'].$sql, 'limit' => $pager->limit, 'desc' => 'id', 'asArray' => TRUE));
		if(isset($holidaymsg) && !empty($holidaymsg)){
			foreach($holidaymsg as $k => $v){
				$holidaymsg[$k]['typename'] = $type->getTypeNamebyid($v['type']);
				$holidaymsg[$k]['daynum'] = floatval($v['daynum']);
				$holidaymsg[$k]['approvetime'] = !empty($v['approvetime']) ? date('Y-m-d H:i:s',$v['approvetime']) : '';
				$msg = '';
				if(in_array($v['type'],array(1,2,3,4,5,10,11,12))){
					$dayjson = json_decode($v['dayjson']);
					if($v['type'] != 11){
						$holidaydays = $this->geyDayMsg($dayjson->holiday);
						foreach($holidaydays as $hk => $hv){
							$msg .= $hv['daytime'].' '.$hv['daymsg'].',';
						}
						$msg = substr($msg,0,strlen($msg)-1);
					}else{
						$msg .= '休假时间：';
						$holidaydays = $this->geyDayMsg($dayjson->holiday);
						foreach($holidaydays as $hk => $hv){
							$msg .= $hv['daytime'].' '.$hv['daymsg'].',';
						}
						$msg = substr($msg,0,strlen($msg)-1);
						$msg .= '<br>加班时间：';
						$overtimedays = $this->geyDayMsg($dayjson->overtime);
						foreach($overtimedays as $ok => $ov){
							$msg .= $ov['daytime'].' '.$ov['daymsg'].',';
						}
						$msg = substr($msg,0,strlen($msg)-1);
					}
				}elseif(in_array($v['type'],array(6,7,8,9))){
					$msg .= $v['starttime']. ' 至 '.$v['endtime'];
				}elseif(in_array($v['type'],array(13,14,15,16,17,18,19))){
					$msg .= date('Y-m-d H:i:s',$v['addtime']);
				}
				$holidaymsg[$k]['daymsg'] = $msg;
			}
			$data['holidaylist'] = $holidaymsg;
		}
		$data['pager'] = $pager->output;
		$data ['memu'] = 'holiday';
		$data ['holidaymenu'] = 'borad';
		$data ['staff'] = $this->staff;
		$data['noindexjs'] = 'noindexjs';
		$this->render ( "/holiday-allList", $data );
	}

	public function holidayClose(){
		$checkadmin = $this->checkisadmin();
		if(!$checkadmin){
			exit('非假期管理员无法访问此页面');
		}
		$data['cansee'] = 1;
	//获取办事处列表
		Doo::loadModel('staff');
		Doo::loadModel('holidaystaff');
		Doo::loadModel('holidayday');
		Doo::loadModel('holiday');
		$staff = new staff();
		$hstaff = new HStaff();
		$hday = new HDay();
		$holiday = new Holiday();

		$sql = 'SELECT `CLD_L_category`.cid,`CLD_L_category`.title,count(`CLD_staff`.sid) as count FROM `CLD_L_category` left join `CLD_staff` on `CLD_L_category`.cid=`CLD_staff`.cid where `CLD_staff`.nature=1 group by `CLD_staff`.cid HAVING count(`CLD_staff`.sid)>0 order by count(`CLD_staff`.sid) desc';
		$query = Doo::db ()->query ( $sql );
		$result = $query->fetchAll ();
		$data['category'] = $result;


		$thisyear = date('Y',time());
//		$thisyear = date('Y',1546358400);
		$data['thismonth'] = intval(date('m',time()));
		$num = intval($thisyear)-2017;
		$html = '';
		$yearnum = isset($this->params['year']) && is_numeric($this->params['year']) ? $this->params['year'] : '';
		for($i = $num; $i >= 0; $i--){
			if($yearnum == (2017+$i)){
				$html .= '<option value="'.(2017+$i).'" selected>'.(2017+$i).'</option>';
			}else{
				$html .= '<option value="'.(2017+$i).'">'.(2017+$i).'</option>';
			}
		}
		$data['option'] = $html;
		if(isset($this->params['year']) && isset($this->params['month'])){
			$month = intval($this->params['month']) < 10 ? '0'.$this->params['month'] : $this->params['month'];
			$date = $this->params['year'].'-'.$month.'-01';
			$thismonth = $this->getMonthTime($date);
			$data['thismonth'] = $this->params['month'];
		}else{
			$thismonth = $this->getMonthTime(date('Y-m-d',time()));
		}

		foreach($result as $k => $v){
			$stafflist[$k]['categoryname'] = $v['title'];
			$stafflist[$k]['count'] = $v['count'];
			$cidstafflist = $staff->find(array('where' => 'cid='.$v['cid'].' and nature=1', 'asArray' => TRUE));
			foreach($cidstafflist as $ck => $cv) {
				foreach (array(1, 2, 3) as $tk => $tv) {
					$typeholiday = $hday->find(array('where' => 'type=' . $tv . ' and uid=' . $cv['sid'] . ' and UNIX_TIMESTAMP(daytime) between ' . $thismonth['start'] . ' and ' . $thismonth['end'], 'asArray' => TRUE));
					$cidstafflist[$ck][$tv] = 0;
					if (!empty($typeholiday)) {
						foreach ($typeholiday as $thk => $thv) {
							$cidstafflist[$ck][$tv] += floatval($thv['daymsg']);
						}
					}
					$cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
				}
				$cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
			}
			$stafflist[$k]['cidstafflist'] = $cidstafflist;
		}

		$data['stafflist'] = $stafflist;

		$zongbu = $staff->find(array('where' => 'cid=12 and nature=1', 'asArray' => TRUE));
		$data['zongbu'] = $zongbu;

		$data ['memu'] = 'holiday';
		$data ['holidaymenu'] = 'close';
		$data ['staff'] = $this->staff;
		$data['noindexjs'] = 'noindexjs';
		$this->render ( "/holiday-close", $data );
	}

	public function holidayClose2(){
		$checkadmin = $this->checkisadmin();
		if(!$checkadmin){
			exit('非假期管理员无法访问此页面');
		}
		$data['cansee'] = 1;
		//获取办事处列表
		Doo::loadModel('staff');
		Doo::loadModel('holidaystaff');
		Doo::loadModel('holidayday');
		Doo::loadModel('holiday');
		$staff = new staff();
		$hstaff = new HStaff();
		$hday = new HDay();
		$holiday = new Holiday();

		$sql = 'SELECT `CLD_L_category`.cid,`CLD_L_category`.title,count(`CLD_staff`.sid) as count FROM `CLD_L_category` left join `CLD_staff` on `CLD_L_category`.cid=`CLD_staff`.cid where `CLD_staff`.nature=2 group by `CLD_staff`.cid HAVING count(`CLD_staff`.sid)>0 order by count(`CLD_staff`.sid) desc';
		$query = Doo::db ()->query ( $sql );
		$result = $query->fetchAll ();
		$data['category'] = $result;

		$thisyear = date('Y',time());
//		$thisyear = date('Y',1546358400);
		$data['thismonth'] = intval(date('m',time()));
		$num = intval($thisyear)-2017;
		$html = '';
		$yearnum = isset($this->params['year']) && is_numeric($this->params['year']) ? $this->params['year'] : '';
		for($i = $num; $i >= 0; $i--){
			if($yearnum == (2017+$i)){
				$html .= '<option value="'.(2017+$i).'" selected>'.(2017+$i).'</option>';
			}else{
				$html .= '<option value="'.(2017+$i).'">'.(2017+$i).'</option>';
			}
		}
		$data['option'] = $html;
		if(isset($this->params['year']) && isset($this->params['month'])){
			$month = intval($this->params['month']) < 10 ? '0'.$this->params['month'] : $this->params['month'];
			$date = $this->params['year'].'-'.$month.'-01';
			$thismonth = $this->getMonthTime($date);
			$data['thismonth'] = $this->params['month'];
		}else{
			$thismonth = $this->getMonthTime(date('Y-m-d',time()));
		}

		$stafflist = array();
		foreach($result as $k => $v){
			$stafflist[$k]['categoryname'] = $v['title'];
			$stafflist[$k]['count'] = $v['count'];
			$cidstafflist = $staff->find(array('where' => 'cid='.$v['cid'].' and nature=2', 'asArray' => TRUE));
			foreach($cidstafflist as $ck => $cv) {
				foreach (array(1, 2, 3, 14) as $tk => $tv) {
					if($tv == 14){
						$typeholiday = $holiday->getOne(array('where' => 'status=3 and type='.$tv.' and uid='.$cv['sid'].' and starttime="'.$thismonth['start'].'" and endtime="'.$thismonth['end'].'"', 'desc' => 'id', 'asArray' => TRUE));
						$cidstafflist[$ck][$tv] = $typeholiday['daynum'] != 0 ? floatval($typeholiday['daynum']) : '';
					}else{
						$typeholiday = $hday->find(array('where' => 'type=' . $tv . ' and uid=' . $cv['sid'] . ' and UNIX_TIMESTAMP(daytime) between ' . $thismonth['start'] . ' and ' . $thismonth['end'], 'asArray' => TRUE));
						$cidstafflist[$ck][$tv] = 0;
						if (!empty($typeholiday)) {
							foreach ($typeholiday as $thk => $thv) {
								$cidstafflist[$ck][$tv] += floatval($thv['daymsg']);
							}
						}
						$cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
					}
				}
				$cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
			}
			$stafflist[$k]['cidstafflist'] = $cidstafflist;
		}

		$data['stafflist'] = $stafflist;

		$data['internstafflist'] = $staff->find(array('where' => 'nature=2', 'asArray' => TRUE));

		//获取上月和本月，录用 实习生上班天数
		$nowmonth = intval(date('m',time()));
		$nowday = date('Y-m-d',time());
		$lastmonth = intval(date('m',strtotime("-1 month")));
		$lastmonthday = date('Y-m-d',strtotime("-1 month"));
		$data['monthlist'] = '<option value="0">选择月份</option><option value="'.$lastmonthday.'">'.$lastmonth.'月</option><option value="'.$nowday.'">'.$nowmonth.'月</option>';


		$data ['memu'] = 'holiday';
		$data ['holidaymenu'] = 'close';
		$data ['staff'] = $this->staff;
		$data['noindexjs'] = 'noindexjs';
		$this->render ( "/holiday-close2", $data );
	}

	public function addHoliday2(){
		if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['type']) && is_numeric($_POST['type'])){
			Doo::loadModel('holiday');
			$holiday = new Holiday();
			if(in_array($_POST['type'],array(1,2,3))){
				$daytype = isset($_POST['daytype']) && is_numeric($_POST['daytype']) ? $_POST['daytype'] : 1;
				$adddaynum = $daytype != 1 ? 0.5 : 1.0;
				$day = $_POST['day'];
				$dayjson = array('holiday' => [$day.'_'.$daytype]);
				$holiday->uid = $_POST['uid'];
				$holiday->type = $_POST['type'];
				$holiday->dayjson = json_encode($dayjson);
				$holiday->daynum = $adddaynum;
				$holiday->status = 3;
				$holiday->addtime = time();
				$holiday->approvetime = time();
				$holiday->description = $_POST['description'];
				$id = $holiday->insert();

				Doo::loadModel('holidayday');
				$hday = new HDay();
				$hday->hid = $id;
				$hday->uid = $_POST['uid'];
				$hday->type = $_POST['type'];
				$hday->daytime = $day;
				$hday->daymsg = $adddaynum;
				$hday->insert();
				if(isset($_POST['close2'])){
					return '/holidayclose2';
				}else{
					return '/holidayclose';
				}
			}elseif($_POST['type'] == 14){
				$thismonth = $this->getMonthTime($_POST['monthselect']);
				$holiday->uid = $_POST['uid'];
				$holiday->type = $_POST['type'];
				$holiday->starttime = $thismonth['start'];
				$holiday->endtime = $thismonth['end'];
				$holiday->daynum = $_POST['daynum'];
				$holiday->status = 3;
				$holiday->addtime = time();
				$holiday->approvetime = time();
				$holiday->description = $_POST['description'];
				$holiday->insert();
				return '/holidayclose2';
			}
		}
		exit('添加事病假、旷工出错');
	}

	public function holidayOvertime(){
		$checkadmin = $this->checkisadmin();
		if(!$checkadmin){
			exit('非假期管理员无法访问此页面');
		}
		$data['cansee'] = 1;
		//获取办事处列表
		Doo::loadModel('staff');
		Doo::loadModel('holidaystaff');
		Doo::loadModel('holidayday');
		Doo::loadModel('holiday');
		$staff = new staff();
		$hstaff = new HStaff();
		$hday = new HDay();
		$holiday = new Holiday();

		$sql = 'SELECT `CLD_L_category`.cid,`CLD_L_category`.title,count(`CLD_staff`.sid) as count FROM `CLD_L_category` left join `CLD_staff` on `CLD_L_category`.cid=`CLD_staff`.cid where `CLD_staff`.nature!=4 group by `CLD_staff`.cid HAVING count(`CLD_staff`.sid)>0 order by count(`CLD_staff`.sid) desc';
		$query = Doo::db ()->query ( $sql );
		$result = $query->fetchAll ();
		$data['category'] = $result;

		$thisyear = date('Y',time());
//		$thisyear = date('Y',1546358400);
		$data['thismonth'] = intval(date('m',time()));
		$num = intval($thisyear)-2017;
		$html = '';
		$yearnum = isset($this->params['year']) && is_numeric($this->params['year']) ? $this->params['year'] : '';
		for($i = $num; $i >= 0; $i--){
			if($yearnum == (2017+$i)){
				$html .= '<option value="'.(2017+$i).'" selected>'.(2017+$i).'</option>';
			}else{
				$html .= '<option value="'.(2017+$i).'">'.(2017+$i).'</option>';
			}
		}
		$data['option'] = $html;
		if(isset($this->params['year']) && isset($this->params['month'])){
			$month = intval($this->params['month']) < 10 ? '0'.$this->params['month'] : $this->params['month'];
			$date = $this->params['year'].'-'.$month.'-01';
			$thismonth = $this->getMonthTime($date);
			$data['thismonth'] = $this->params['month'];
		}else{
			$thismonth = $this->getMonthTime(date('Y-m-d',time()));
		}

		$stafflist = array();
		if(isset($this->params['cid']) && is_numeric($this->params['cid'])){
			$data['thiscid'] = $this->params['cid'];
			foreach($result as $k => $v){
				if($this->params['cid'] == $v['cid']){
					$stafflist[0]['categoryname'] = $v['title'];
					$stafflist[0]['count'] = $v['count'];
					$cidstafflist = $staff->getStaffByCid($v['cid']);
					foreach($cidstafflist as $ck => $cv){
						$hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$cv['sid'], 'asArray' => TRUE));
						$cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
						foreach(array(4,5,10,11) as $tk => $tv){
							if($tv == 11){
								$typeholiday = $holiday->find(array('where' => 'status=1 and type='.$tv.' and uid='.$cv['sid'].' and addtime between '.$thismonth['start'].' and '.$thismonth['end'],'asArray' => TRUE));
								$cidstafflist[$ck][$tv] = 0;
								if(!empty($typeholiday)){
									foreach($typeholiday as $thk => $thv){
										$cidstafflist[$ck][$tv] += floatval($thv['daynum']);
									}
								}
								$cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
							}else{
								$typeholiday = $hday->find(array('where' => 'type='.$tv.' and uid='.$cv['sid'].' and UNIX_TIMESTAMP(daytime) between '.$thismonth['start'].' and '.$thismonth['end'],'asArray' => TRUE));
								$cidstafflist[$ck][$tv] = 0;
								if(!empty($typeholiday)){
									foreach($typeholiday as $thk => $thv){
										$cidstafflist[$ck][$tv] += floatval($thv['daymsg']);
									}
								}
								$cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
							}
						}
						$cidstafflist[$ck]['countnum'] = floatval($cidstafflist[$ck][4])+floatval($cidstafflist[$ck][5]) != 0 ? floatval($cidstafflist[$ck][4]) + floatval($cidstafflist[$ck][5]) : '';
						$cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
					}
					$stafflist[0]['cidstafflist'] = $cidstafflist;
					break;
				}
			}
		}else{
			foreach($result as $k => $v){
				$stafflist[$k]['categoryname'] = $v['title'];
				$stafflist[$k]['count'] = $v['count'];
				$cidstafflist = $staff->getStaffByCid($v['cid']);
				foreach($cidstafflist as $ck => $cv) {
					$hstaffmsg = $hstaff->getOne(array('where' => 'uid=' . $cv['sid'], 'asArray' => TRUE));
					$cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
					foreach (array(4, 5, 10, 11) as $tk => $tv) {
						if ($tv == 11) {
							$typeholiday = $holiday->find(array('where' => 'status=1 and type=' . $tv . ' and uid=' . $cv['sid'] . ' and addtime between ' . $thismonth['start'] . ' and ' . $thismonth['end'], 'asArray' => TRUE));
							$cidstafflist[$ck][$tv] = 0;
							if (!empty($typeholiday)) {
								foreach ($typeholiday as $thk => $thv) {
									$cidstafflist[$ck][$tv] += floatval($thv['daynum']);
								}
							}
							$cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
						} else {
							$typeholiday = $hday->find(array('where' => 'type=' . $tv . ' and uid=' . $cv['sid'] . ' and UNIX_TIMESTAMP(daytime) between ' . $thismonth['start'] . ' and ' . $thismonth['end'], 'asArray' => TRUE));
							$cidstafflist[$ck][$tv] = 0;
							if (!empty($typeholiday)) {
								foreach ($typeholiday as $thk => $thv) {
									$cidstafflist[$ck][$tv] += floatval($thv['daymsg']);
								}
							}
							$cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
						}
					}
					$cidstafflist[$ck]['countnum'] = floatval($cidstafflist[$ck][4])+floatval($cidstafflist[$ck][5]) != 0 ? floatval($cidstafflist[$ck][4]) + floatval($cidstafflist[$ck][5]) : '';
					$cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
				}
				$stafflist[$k]['cidstafflist'] = $cidstafflist;
			}
		}

		$data['stafflist'] = $stafflist;

		$zongbu = $staff->getStaffByCid(12);
		$data['zongbu'] = $zongbu;

		$data ['memu'] = 'holiday';
		$data ['holidaymenu'] = 'overtime';
		$data ['staff'] = $this->staff;
		$data['noindexjs'] = 'noindexjs';
		$this->render ( "/holiday-overtime", $data );
	}

	public function addHoliday(){
		if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['type']) && is_numeric($_POST['type'])){
			Doo::loadModel('holidaystaff');
			Doo::loadModel('holiday');
			$holiday = new Holiday();
			$hstaff = new HStaff();
			$hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$_POST['uid'], 'asArray' => TRUE));
			if(($_POST['type'] == 4 || $_POST['type'] == 5) && isset($_POST['daytype']) && is_numeric($_POST['daytype'])){
				$day = $_POST['day'];
				$hstaff->uid = $_POST['uid'];
				$daytype = $_POST['daytype'];
				$adddaynum = $daytype != 1 ? 0.5 : 1.0;
				$hstaff->addnum = floatval($hstaffmsg['addnum'])+$adddaynum;
				$result = $hstaff->update();
				if($result){
					$dayjson = array('holiday' => [$day.'_'.$daytype]);
					$holiday->uid = $_POST['uid'];
					$holiday->type = $_POST['type'];
					$holiday->dayjson = json_encode($dayjson);
					$holiday->daynum = $adddaynum;
					$holiday->status = 3;
					$holiday->addtime = time();
					$holiday->approvetime = time();
					$holiday->description = $_POST['description'];
					$id = $holiday->insert();

					Doo::loadModel('holidayday');
					$hday = new HDay();
					$hday->hid = $id;
					$hday->uid = $_POST['uid'];
					$hday->type = $_POST['type'];
					$hday->daytime = $day;
					$hday->daymsg = $adddaynum;
					$hday->insert();

					return '/holidayovertime';
				}else{
					exit('添加到holidaystaff出错');
				}
			}elseif($_POST['type'] == 13){
				$daynum = $_POST['tixian'];
				if($daynum > $hstaffmsg['addnum']){
					exit('提现天数超过存假天数了');
				}else{
					$hstaff->uid = $_POST['uid'];
					$hstaff->addnum = $hstaffmsg['addnum']-$daynum;
					$result = $hstaff->update();
					if($result){
						$holiday->uid = $_POST['uid'];
						$holiday->type = 13;
						$holiday->daynum = $daynum;
						$holiday->status = 3;
						$holiday->addtime = time();
						$holiday->approvetime = time();
						$holiday->description = $_POST['description'];
						$holiday->insert();

						return '/holidayovertime';
					}else{
						exit('添加到holidaystaff出错');
					}
				}
			}
		}
		exit('添加加值班或提现出错');
	}

	public function holidayVacation(){
		$checkadmin = $this->checkisadmin();
		if(!$checkadmin){
			exit('非假期管理员无法访问此页面');
		}
		$data['cansee'] = 1;
		//获取办事处列表
		Doo::loadModel('staff');
		Doo::loadModel('holidaystaff');
		$staff = new staff();
		$hstaff = new HStaff();

		$sql = 'SELECT `CLD_L_category`.cid,`CLD_L_category`.title,count(`CLD_staff`.sid) as count FROM `CLD_L_category` left join `CLD_staff` on `CLD_L_category`.cid=`CLD_staff`.cid where `CLD_staff`.nature!=4 group by `CLD_staff`.cid HAVING count(`CLD_staff`.sid)>0 order by count(`CLD_staff`.sid) desc';
		$query = Doo::db ()->query ( $sql );
		$result = $query->fetchAll ();
		$data['category'] = $result;

		$stafflist = array();
		if(isset($this->params['cid']) && is_numeric($this->params['cid'])){
			$data['thiscid'] = $this->params['cid'];
			foreach($result as $k => $v){
				if($this->params['cid'] == $v['cid']){
					$stafflist[0]['categoryname'] = $v['title'];
					$stafflist[0]['count'] = $v['count'];
					$cidstafflist = $staff->getStaffByCid($v['cid']);
					foreach($cidstafflist as $ck => $cv){
						$hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$cv['sid'], 'asArray' => TRUE));
						$yearnum = $this->CheckAnnualLeave($cv);
						$cidstafflist[$ck]['yearnum'] = floatval($yearnum) != 0 ? floatval($yearnum) : '';
						$cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
						$cidstafflist[$ck]['hunjianum'] = $hstaffmsg['hunjianum'] != 0.0 ? floatval($hstaffmsg['hunjianum']) : '';
						$cidstafflist[$ck]['chanjianum'] = $hstaffmsg['chanjianum'] != 0.0 ? floatval($hstaffmsg['chanjianum']) : '';
						$cidstafflist[$ck]['sangjianum'] = $hstaffmsg['sangjianum'] != 0.0 ? floatval($hstaffmsg['sangjianum']) : '';
						$cidstafflist[$ck]['gongjianum'] = $hstaffmsg['gongjianum'] != 0.0 ? floatval($hstaffmsg['gongjianum']) : '';
						$cidstafflist[$ck]['yearround'] = $cv['nature'] == 1 ? $this->getYearRoundtime($hstaffmsg['hadyear'],$cv['hiredate'],$cv['hireBiasDate']) : '';
						$cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
					}
					$stafflist[0]['cidstafflist'] = $cidstafflist;
					break;
				}
			}
		}else{
			foreach($result as $k => $v){
				$stafflist[$k]['categoryname'] = $v['title'];
				$stafflist[$k]['count'] = $v['count'];
				$cidstafflist = $staff->getStaffByCid($v['cid']);
				foreach($cidstafflist as $ck => $cv){
					$hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$cv['sid'], 'asArray' => TRUE));
					$yearnum = $this->CheckAnnualLeave($cv);
					$cidstafflist[$ck]['yearnum'] = floatval($yearnum) != 0 ? floatval($yearnum) : '';
					$cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
					$cidstafflist[$ck]['hunjianum'] = $hstaffmsg['hunjianum'] != 0.0 ? floatval($hstaffmsg['hunjianum']) : '';
					$cidstafflist[$ck]['chanjianum'] = $hstaffmsg['chanjianum'] != 0.0 ? floatval($hstaffmsg['chanjianum']) : '';
					$cidstafflist[$ck]['sangjianum'] = $hstaffmsg['sangjianum'] != 0.0 ? floatval($hstaffmsg['sangjianum']) : '';
					$cidstafflist[$ck]['gongjianum'] = $hstaffmsg['gongjianum'] != 0.0 ? floatval($hstaffmsg['gongjianum']) : '';
					$cidstafflist[$ck]['yearround'] = $cv['nature'] == 1 ? $this->getYearRoundtime($hstaffmsg['hadyear'],$cv['hiredate'],$cv['hireBiasDate']) : '';
					$cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
				}
				$stafflist[$k]['cidstafflist'] = $cidstafflist;
			}
		}

		$zongbu = $staff->getStaffByCid(12);
		$data['zongbu'] = $zongbu;
		$hstaff2 = new HStaff();
		$hstaffmsg2 = $hstaff2->getOne(array('select' => 'yearnum', 'where' => 'uid='.$zongbu[0]['sid'], 'asArray' => TRUE));
		$data['thisnum'] = floatval($hstaffmsg2['yearnum']);

		$data['stafflist'] = $stafflist;

		$data ['memu'] = 'holiday';
		$data ['holidaymenu'] = 'vacation';
		$data ['staff'] = $this->staff;
		$data['noindexjs'] = 'noindexjs';
		$this->render ( "/holiday-vacation", $data );
	}

	public function setStaffHoliday(){
		if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['typeholiday']) && isset($_POST['addnum'])){
			Doo::loadModel('holidaystaff');
			$hstaff = new HStaff();
			$hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$_POST['uid'], 'asArray' => TRUE));
			$hstaff->uid = $_POST['uid'];
			$type = '';
			switch($_POST['typeholiday']){
				case 'yearnum':
					$hstaff->yearnum = $hstaffmsg['yearnum']+$_POST['addnum'];
					$type = 15;
					break;
				case 'hunjianum':
					$hstaff->hunjianum = $hstaffmsg['hunjianum']+$_POST['addnum'];
					$type = 16;
					break;
				case 'chanjianum':
					$hstaff->chanjianum = $hstaffmsg['chanjianum']+$_POST['addnum'];
					$type = 17;
					break;
				case 'sangjianum':
					$hstaff->sangjianum = $hstaffmsg['sangjianum']+$_POST['addnum'];
					$type = 18;
					break;
				case 'gongjianum':
					$hstaff->gongjianum = $hstaffmsg['gongjianum']+$_POST['addnum'];
					$type = 19;
					break;
			}
			$hstaff->update();

			Doo::loadModel('holiday');
			$holiday = new Holiday();
			$holiday->uid = $_POST['uid'];
			$holiday->type = $type;
			$holiday->daynum = $_POST['addnum'];
			$holiday->status = 3;
			$holiday->addtime = time();
			$holiday->approvetime = time();
			$holiday->description = $_POST['description'];
			$holiday->insert();

			return '/holidayvacation';
		}else{
			exit('增加出错');
		}

	}

	public function getStaffCategory(){
		if(isset($_POST['cid']) && is_numeric($_POST['cid'])){
			Doo::loadModel('staff');
			$staff = new staff();
			$stafflist = $staff->getStaffByCid($_POST['cid']);
			Doo::loadModel('holidaystaff');
			$hstaff = new HStaff();
			$hstaffmsg = $hstaff->getOne(array('select' => 'yearnum', 'where' => 'uid='.$stafflist[0]['sid'], 'asArray' => TRUE));
			exit(json_encode(array('code' => 200, 'stafflist' => $stafflist, 'thisnum' => floatval($hstaffmsg['yearnum']))));
		}
		exit(json_encode(array('code' => 400)));
	}

	public function getHolidayStaff(){
		if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['type'])){
			Doo::loadModel('holidaystaff');
			$hstaff = new HStaff();
			$staffmsg = $hstaff->getOne(array('select' => $_POST['type'], 'where' => 'uid='.$_POST['uid'], 'asArray' => TRUE));
			exit(json_encode(array('code' => 200, 'thisnum' => floatval($staffmsg[$_POST['type']]))));
		}
		exit(json_encode(array('code' => 400)));
	}

	public function holidayAttendance(){
		$checkadmin = $this->checkisadmin();
		if($checkadmin){
			$data['cansee'] = 1;
		}

		Doo::loadModel('holidayday');
		Doo::loadModel('holiday');
		Doo::loadModel('holidaystaff');
		Doo::loadModel('holidaytype');
		Doo::loadModel('staff');
		$hday = new HDay();
		$holiday = new Holiday();
		$hstaff = new HStaff();
		$type = new HType();
		$staff = new staff();

		$sqlstr = '';
		$pagestr = '';
		if(isset($this->params['day'])){
			$today = $this->params['day'];
			$todayarr = explode('~',$today);
			if(count($todayarr) != 2){
				$sqlstr .= ' and ((UNIX_TIMESTAMP(starttime)<=UNIX_TIMESTAMP("'.$todayarr[0].'") and UNIX_TIMESTAMP(endtime)>=UNIX_TIMESTAMP("'.$todayarr[0].'")) OR (id in (select hid From `holiday_day` where daytime="'.$todayarr[0].'")))';
			}else{
				$sqlstr .= ' and ((UNIX_TIMESTAMP(starttime)<=UNIX_TIMESTAMP("'.$todayarr[0].'") and UNIX_TIMESTAMP(endtime)>=UNIX_TIMESTAMP("'.$todayarr[0].'")) OR (UNIX_TIMESTAMP(starttime)<=UNIX_TIMESTAMP("'.$todayarr[1].'") and UNIX_TIMESTAMP(endtime)>=UNIX_TIMESTAMP("'.$todayarr[1].'")) OR (id in (select hid From `holiday_day` where UNIX_TIMESTAMP(daytime) between UNIX_TIMESTAMP("'.$todayarr[0].'") and UNIX_TIMESTAMP("'.$todayarr[1].'"))))';
			}
		}else{
			$today = date('Y-m-d',time());
			$sqlstr .= ' and ((UNIX_TIMESTAMP(starttime)<=UNIX_TIMESTAMP("'.$today.'") and UNIX_TIMESTAMP(endtime)>=UNIX_TIMESTAMP("'.$today.'")) OR (id in (select hid from `holiday_day` where daytime="'.$today.'")))';
		}
		$pagestr .= '/day/'.$today;
		$data['today'] = $today;

		if(isset($this->params['cate'])){
			$cate = 'headquarters';
			$pagestr .= '/cate/'.$cate;
			$data['cate'] = 1;
			$sqlstr .= ' and uid in (select sid from `CLD_staff` where cid=12 and departmentID=0)';
		}else{
			$data['cate'] = 0;
		}
		$data['typeurl'] = $pagestr;
		if(isset($this->params['type'])){
			$data['type'] = $this->params['type'];
			$pagestr .= '/type/'.$this->params['type'];
			if($this->params['type'] == 4 ){//加班、值班
				$sqlstr .= ' and (type=4 or type=5)';
			}elseif($this->params['type'] == 6){//其他长假
				$sqlstr .= ' and type in(3,6,7,8,9)';
			}else{
				$sqlstr .= ' and type='.$this->params['type'];
			}
		}else{
			$data['type'] = '';
		}

		Doo::loadHelper('DooPager');
		$totalArchive = $holiday->count(array('where' => 'status=1'.$sqlstr, 'asArray' => TRUE));
		$pager = new DooPager(Doo::conf()->APP_URL . "holidayattendance".$pagestr."/page", $totalArchive, 10, 10);
		if (isset($this->params['pindex']))
			$pager->paginate(intval($this->params['pindex']));
		else
			$pager->paginate(1);
		if ($pager->limit != ' -10,10')
			$holidaymsg = $holiday->find(array('where' => 'status=1'.$sqlstr, 'limit' => $pager->limit, 'asArray' => TRUE));
		if(isset($holidaymsg) && !empty($holidaymsg)){
			foreach($holidaymsg as $k => $v){
				$staffmsg = $staff->getOne(array('where' => 'sid=?', 'param' => array($v['uid']), 'asArray' => TRUE));
				$holidaymsg[$k]['username'] = $staffmsg['username'];
				$holidaymsg[$k]['category'] = $staffmsg['cid'] == 12 && $staffmsg['departmentID'] == 1 ? '总部（造价研究中心）' : $staffmsg['category'];
				$holidaymsg[$k]['typename'] = $type->getTypeNamebyid($v['type']);
				$holidaymsg[$k]['daynum'] = floatval($v['daynum']);
				$holidaymsg[$k]['approvetime'] = !empty($v['approvetime']) ? date('Y-m-d H:i:s',$v['approvetime']) : '';
				$msg = '';
				if(in_array($v['type'],array(1,2,3,4,5,10,11,12))){
					$dayjson = json_decode($v['dayjson']);
					if($v['type'] != 11){
						$holidaydays = $this->geyDayMsg($dayjson->holiday);
						foreach($holidaydays as $hk => $hv){
							$msg .= $hv['daytime'].' '.$hv['daymsg'].',';
						}
						$msg = substr($msg,0,strlen($msg)-1);
					}else{
						$msg .= '休假时间：';
						$holidaydays = $this->geyDayMsg($dayjson->holiday);
						foreach($holidaydays as $hk => $hv){
							$msg .= $hv['daytime'].' '.$hv['daymsg'].',';
						}
						$msg = substr($msg,0,strlen($msg)-1);
						$msg .= '<br>加班时间：';
						$overtimedays = $this->geyDayMsg($dayjson->overtime);
						foreach($overtimedays as $ok => $ov){
							$msg .= $ov['daytime'].' '.$ov['daymsg'].',';
						}
						$msg = substr($msg,0,strlen($msg)-1);
					}
				}elseif(in_array($v['type'],array(6,7,8,9))){
					$msg .= $v['starttime']. ' 至 '.$v['endtime'];
				}elseif(in_array($v['type'],array(13,14,15,16,17,18,19))){
					$msg .= date('Y-m-d H:i:s',$v['addtime']);
				}
				$holidaymsg[$k]['daymsg'] = $msg;
			}
			$data['holidaylist'] = $holidaymsg;
		}
		$data['pager'] = $pager->output;
		$data ['memu'] = 'holiday';
		$data ['holidaymenu'] = 'borad';
		$data ['staff'] = $this->staff;
		$data['noindexjs'] = 'noindexjs';
		$this->render ( "/holiday-allList2", $data );
	}


	private function geyDayMsg($dayjson){
		$holidayday = array();
		foreach($dayjson as $dk => $dv){
			$oneday = explode('_',$dv);
			if($oneday[1] != 0){
				$holidayday[$dk]['daytime'] = $oneday[0];
				$holidayday[$dk]['daymsg'] = $oneday[1] == 1 ? '' : ($oneday[1] == 2 ? '上午' : '下午');
			}
		}
		return $holidayday;
	}

	//获取某日期的月初月末时间戳
	private function getMonthTime($time){
		$starttime = strtotime(date('Y-m-01',strtotime($time)));
		$endtime = strtotime("+1 months", strtotime(date('Y-m-01',strtotime($time))))-1;
		return array('start' => $starttime, 'end' => $endtime);
	}


	//获取本年的每个月的时间戳
	private function getYearMonthTime($thisyear){
		$monthdata = array();
		for($i = 0; $i < 12; $i++){
			$j = $i+1;
			$j = $j < 10 ? '0'.$j : $j;
			$nowmonth = $thisyear.'-'.$j.'-01';
			$monthdata[$i]['starttime'] = strtotime($nowmonth);
			$monthdata[$i]['endtime'] = strtotime("+1 months", strtotime($nowmonth))-1;
		}

		return $monthdata;
	}

	//获取本年当事人的年假周期
	private function getYearRoundtime($hadyear,$hiredate,$hireBiasDate){
		// 新算法，算出最新入职日期-前入职时间之和天数为年假周期的月日
		$hireRound = strtotime($hiredate) - $hireBiasDate*86400;
		$month = date('m', $hireRound);
		$date = date('d', $hireRound);
		$monthday = intval($month).'-'.intval($date);
		$year = date('Y',time());
		//每隔4年加一天
		if(date('Y',($hireRound+(86400*365*$hadyear)+intval($hadyear/4)*86400)) < $year){
			$lastyear = intval($year)-1;
			$startday = date('Y年m月d日', strtotime(intval($lastyear).'-'.$monthday));
			$endday = date('Y年m月d日', strtotime(intval($year).'-'.$monthday)- 86400);
			return $startday.'~'.$endday;
		}else{
			$nextyear = intval($year)+1;
			$startday = date('Y年m月d日', strtotime(intval($year).'-'.$monthday));
			$endday = date('Y年m月d日', strtotime(intval($nextyear).'-'.$monthday) - 86400);
			return $startday.'~'.$endday;
		}
	}

	private function checkisadmin(){
		Doo::loadModel('holidayadmin');
		$admin = new HAdmin();
		$adminmsg = $admin->getOne(array('where' => 'uid='.$this->staff[0]['sid'], 'asArray' => TRUE));
		if(!empty($adminmsg)){
			return TRUE;
		}else{
			return FALSE;
		}
	}

	//检查年假是否过期并更新年假
	private function CheckAnnualLeave($staff){
		if($staff['nature'] == 2){
			return 0;
		}
		$hiredate = $staff['hiredate'];
		$hireBiasDate = $staff['hireBiasDate'];
		if($hiredate == ''){
			return 0;
		}
		Doo::loadModel('holidaystaff');
		$hstaff = new HStaff();
		$hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$staff['sid'],'asArray' => TRUE));
		$hadyear = intval((time()-strtotime($hiredate) + 86400*$hireBiasDate)/(86400*365));
		if($hadyear != $hstaffmsg['hadyear']){
			$hstaff->uid = $staff['sid'];
			$hstaff->hadyear = $hadyear;
			$hstaff->yearnum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
			$hstaff->update();
			$daynum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
		}else{
			$daynum = $hstaffmsg['yearnum'];
		}
		return $daynum;
	}

}

?>