HolidayController.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class HolidayController extends DooController {
  6. public $staff;
  7. function __construct() {
  8. if(isset($_COOKIE["staff"])){
  9. if(!empty($_COOKIE["staff"])){
  10. Doo::loadModel ( 'staff' );
  11. $staff = new staff ();
  12. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  13. return "/";
  14. }
  15. }
  16. Doo::loadCore ( 'uri/DooUriRouter' );
  17. $router = new DooUriRouter ();
  18. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  19. if($routeRs['1']!="login"){
  20. header ( 'Content-Type:text/html;charset=utf-8' );
  21. @header ( "Location: /login" );
  22. }
  23. }
  24. public function myList(){
  25. $checkadmin = $this->checkisadmin();
  26. if($checkadmin){
  27. $data['cansee'] = 1;
  28. }
  29. Doo::loadModel('holidayday');
  30. Doo::loadModel('holiday');
  31. Doo::loadModel('holidaystaff');
  32. $hday = new HDay();
  33. $holiday = new Holiday();
  34. $hstaff = new HStaff();
  35. $thisyear = date('Y',time());
  36. // $thisyear = date('Y',1546358400);
  37. $num = intval($thisyear)-2017;
  38. $html = '';
  39. $yearnum = isset($this->params['yearnum']) && is_numeric($this->params['yearnum']) ? $this->params['yearnum'] : '';
  40. for($i = $num; $i >= 0; $i--){
  41. if($yearnum == (2017+$i)){
  42. $html .= '<option value="'.(2017+$i).'" selected>'.(2017+$i).'</option>';
  43. }else{
  44. $html .= '<option value="'.(2017+$i).'">'.(2017+$i).'</option>';
  45. }
  46. }
  47. $data['option'] = $html;
  48. $yeartime = isset($this->params['yearnum']) && is_numeric($this->params['yearnum']) ? $this->getYearMonthTime($this->params['yearnum']) : $this->getYearMonthTime($thisyear);
  49. //记录事,病,旷,加,值,补,调的信息
  50. $holidaymsg = array('1'=> array(), '2' => array(), '3' => array(), '4' => array(), '5' => array(), '10' => array(), '11' => array());
  51. foreach(array(1,2,3,4,5,10,11) as $k => $v){
  52. $all = 0;
  53. for($i = 0; $i < 12; $i++){
  54. if($v == 11){
  55. $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));
  56. $holidaymsg[$v][$i+1] = 0;
  57. if(!empty($typeholiday)){
  58. foreach($typeholiday as $tk => $tv){
  59. $holidaymsg[$v][$i+1] += floatval($tv['daynum']);
  60. $all += floatval($tv['daynum']);
  61. }
  62. }
  63. $holidaymsg[$v][$i+1] = $holidaymsg[$v][$i+1] != 0 ? $holidaymsg[$v][$i+1] : '';
  64. }else{
  65. $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));
  66. $holidaymsg[$v][$i+1] = 0;
  67. if(!empty($typeholiday)){
  68. foreach($typeholiday as $tk => $tv){
  69. $holidaymsg[$v][$i+1] += floatval($tv['daymsg']);
  70. $all += floatval($tv['daymsg']);
  71. }
  72. }
  73. $holidaymsg[$v][$i+1] = $holidaymsg[$v][$i+1] != 0 ? $holidaymsg[$v][$i+1] : '';
  74. }
  75. }
  76. $holidaymsg[$v]['all'] = $all != 0 ? $all : '';
  77. }
  78. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$this->staff[0]['sid'], 'asArray' => TRUE));
  79. $data['yearnum'] = floatval($hstaffmsg['yearnum']);
  80. $data['overtimetnum'] = floatval($holidaymsg[4]['all'])+floatval($holidaymsg[5]['all']);
  81. $data['addnum'] = floatval($hstaffmsg['addnum']);
  82. $data['hunjianum'] = floatval($hstaffmsg['hunjianum']);
  83. $data['chanjianum'] = floatval($hstaffmsg['chanjianum']);
  84. $data['sangjianum'] = floatval($hstaffmsg['sangjianum']);
  85. $data['gongjianum'] = floatval($hstaffmsg['gongjianum']);
  86. $data['yearround'] = $this->getYearRoundtime($hstaffmsg['hadyear'],$this->staff[0]['hiredate']);
  87. // var_dump($holidaymsg);
  88. // exit;
  89. $data['holidaymsg'] = $holidaymsg;
  90. $data ['memu'] = 'holiday';
  91. $data ['holidaymenu'] = 'mylist';
  92. $data ['staff'] = $this->staff;
  93. $data['noindexjs'] = 'noindexjs';
  94. $this->render ( "/holiday-myList", $data );
  95. }
  96. public function holidayBorad(){
  97. $checkadmin = $this->checkisadmin();
  98. if($checkadmin){
  99. $data['cansee'] = 1;
  100. }
  101. Doo::loadModel('holiday');
  102. Doo::loadModel('holidayday');
  103. Doo::loadModel('holidaystaff');
  104. Doo::loadModel('holidaytype');
  105. $thismonth = $this->getMonthTime(date('Y-m-d',time()));
  106. $data['countmonth'] = date("Y年m月",time());
  107. $holiday = new Holiday();
  108. $hday = new HDay();
  109. $hstaff = new HStaff();
  110. $type = new HType();
  111. $holidaycount =array();
  112. foreach(array(1,2,3,4,5) as $k => $v){
  113. $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));
  114. $holidaycount[$k] = 0;
  115. if(!empty($typeholiday)){
  116. foreach($typeholiday as $tk => $tv){
  117. $holidaycount[$k] += floatval($tv['daymsg']);
  118. }
  119. }
  120. }
  121. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$this->staff[0]['sid'], 'asArray' => TRUE));
  122. $holidaycount[5] = floatval($hstaffmsg['yearnum']);
  123. $holidaycount[6] = floatval($hstaffmsg['addnum']);
  124. $data['holidaycount'] = $holidaycount;
  125. $holidaymsg = $holiday->find(array('where' => 'uid='.$this->staff[0]['sid'], 'limit' => 10, 'desc' => 'approvetime', 'desc' => 'id', 'asArray' => TRUE));
  126. if(!empty($holidaymsg)){
  127. foreach($holidaymsg as $k => $v){
  128. $holidaymsg[$k]['typename'] = $type->getTypeNamebyid($v['type']);
  129. $holidaymsg[$k]['daynum'] = floatval($v['daynum']);
  130. $holidaymsg[$k]['approvetime'] = !empty($v['approvetime']) ? date('Y-m-d H:i:s',$v['approvetime']) : '';
  131. $msg = '';
  132. if(in_array($v['type'],array(1,2,3,4,5,10,11,12))){
  133. $dayjson = json_decode($v['dayjson']);
  134. if($v['type'] != 11){
  135. $holidaydays = $this->geyDayMsg($dayjson->holiday);
  136. foreach($holidaydays as $hk => $hv){
  137. $msg .= $hv['daytime'].' '.$hv['daymsg'].',';
  138. }
  139. $msg = substr($msg,0,strlen($msg)-1);
  140. }else{
  141. $msg .= '休假时间:';
  142. $holidaydays = $this->geyDayMsg($dayjson->holiday);
  143. foreach($holidaydays as $hk => $hv){
  144. $msg .= $hv['daytime'].' '.$hv['daymsg'].',';
  145. }
  146. $msg = substr($msg,0,strlen($msg)-1);
  147. $msg .= '
  148. 加班时间:';
  149. $overtimedays = $this->geyDayMsg($dayjson->overtime);
  150. foreach($overtimedays as $ok => $ov){
  151. $msg .= $ov['daytime'].' '.$ov['daymsg'].',';
  152. }
  153. $msg = substr($msg,0,strlen($msg)-1);
  154. }
  155. }elseif(in_array($v['type'],array(6,7,8,9))){
  156. $msg .= $v['starttime']. ' 至 '.$v['endtime'];
  157. }elseif(in_array($v['type'],array(13,14,15,16,17,18,19))){
  158. $msg .= date('Y-m-d H:i:s',$v['addtime']);
  159. }
  160. $holidaymsg[$k]['daymsg'] = $msg;
  161. }
  162. $data['holidaylist'] = $holidaymsg;
  163. }
  164. $data ['memu'] = 'holiday';
  165. $data ['holidaymenu'] = 'borad';
  166. $data ['staff'] = $this->staff;
  167. $data['noindexjs'] = 'noindexjs';
  168. //公司每日考勤内容
  169. if($hstaffmsg['isadmin'] == 1 || $hstaffmsg['iscc'] == 1){
  170. $data['youcantseeme'] = 0;
  171. //今日请假人员,区分总部和办事处
  172. Doo::loadModel('staff');
  173. $staff = new staff();
  174. $headquarters = $branch = $leaves = array();
  175. $today = date('Y-m-d',time());
  176. $data['today'] = date('m月d日',time());
  177. //短假的
  178. $hdayarr = $hday->find(array('where' => 'daytime=?', 'param' => array($today), 'asArray' => TRUE));
  179. if(!empty($hdayarr)){
  180. foreach($hdayarr as $hk => $hv){
  181. $onearr = array();
  182. $onehmsg = $holiday->getOne(array('where' => 'id=?', 'param' => array($hv['hid']), 'asArray' => TRUE));
  183. $staffmsg = $staff->getOne(array('where' => 'sid=?', 'param' => array($hv['uid']), 'asArray' => TRUE));
  184. $onearr['type'] = $type->getTypeNamebyid($onehmsg['type']);
  185. $onearr['staff'] = $staffmsg['username'];
  186. $onearr['day'] = floatval($onehmsg['daynum']);
  187. if($staffmsg['cid'] == 12){
  188. array_push($headquarters,$onearr);
  189. }else{
  190. array_push($branch,$onearr);
  191. }
  192. array_push($leaves,$hv['uid']);
  193. }
  194. }
  195. //长假的
  196. $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));
  197. if(!empty($hdayarr2)){
  198. foreach($hdayarr2 as $hk2 => $hv2){
  199. $onearr = array();
  200. $staffmsg = $staff->getOne(array('where' => 'sid=?', 'param' => array($hv2['uid']), 'asArray' => TRUE));
  201. $onearr['type'] = $type->getTypeNamebyid($hv2['type']);
  202. $onearr['staff'] = $staffmsg['username'];
  203. $onearr['day'] = floatval($hv2['daynum']);
  204. if($staffmsg['cid'] == 12){
  205. array_push($headquarters,$onearr);
  206. }else{
  207. array_push($branch,$onearr);
  208. }
  209. array_push($leaves,$hv2['uid']);
  210. }
  211. }
  212. $data['headquarters'] = $headquarters;
  213. $data['branch'] = $branch;
  214. //今天在勤人员名单
  215. $hqstaffarr = $staff->find(array('where' => 'cid=12 and departmentID=0', 'asArray' => TRUE));
  216. $onlinehq = array();
  217. foreach($hqstaffarr as $hqk => $hqv){
  218. if(!in_array($hqv['sid'],$leaves)){
  219. array_push($onlinehq,$hqv['username']);
  220. }
  221. }
  222. $onlinebr = array();
  223. Doo::loadModel('L_category');
  224. $lcate = new L_category();
  225. $catearr = $lcate->find(array('where' => 'cid!=34', 'asArray' => TRUE));
  226. foreach($catearr as $ck => $cv){
  227. if($cv['cid'] == 12){
  228. $brstaffarr = $staff->find(array('where' => 'cid=? and departmentID=1', 'param' => array($cv['cid']), 'asArray' => TRUE));
  229. }else{
  230. $brstaffarr = $staff->find(array('where' => 'cid=?', 'param' => array($cv['cid']), 'asArray' => TRUE));
  231. }
  232. $brsarr = array();
  233. if(!empty($brstaffarr)){
  234. foreach($brstaffarr as $brk => $brv){
  235. if(!in_array($brv['sid'],$leaves)) {
  236. array_push($brsarr, $brv['username']);
  237. }
  238. }
  239. }
  240. $brstaffstr = !empty($brsarr) ? implode('、', $brsarr) : '';
  241. $title = $cv['cid'] == 12 ? '总部-造价研究中心' : $cv['title'];
  242. $onebrarr = array('title' => $title,'online' => $brstaffstr);
  243. array_push($onlinebr,$onebrarr);
  244. }
  245. // var_dump($onlinebr);
  246. // $brstaffarr = $staff->find(array('where' => ''));
  247. $data['onlineheadquarters'] = implode('、',$onlinehq);
  248. $data['onlinebranch'] = $onlinebr;
  249. // var_dump(array_unique($leaves));
  250. }else{
  251. $data['youcantseeme'] = 1;
  252. }
  253. $this->render ( "/holiday-borad", $data );
  254. }
  255. public function allList(){
  256. $checkadmin = $this->checkisadmin();
  257. if($checkadmin){
  258. $data['cansee'] = 1;
  259. }
  260. Doo::loadModel('holiday');
  261. Doo::loadModel('holidaytype');
  262. $holiday = new Holiday();
  263. $type = new HType();
  264. if(isset($this->params['type'])){
  265. if($this->params['type'] == 4 ){//加班、值班
  266. $sql = ' and (type=4 or type=5)';
  267. }elseif($this->params['type'] == 6){//其他,管理员操作
  268. $sql = ' and type in(3,6,7,8,9,13,14,15,16,17,18,19)';
  269. }else{
  270. $sql = ' and type='.$this->params['type'];
  271. }
  272. $pagemsg = '/type/'.$this->params['type'];
  273. $data['thistype'] = $this->params['type'];
  274. }else{
  275. $sql = '';
  276. $pagemsg = '';
  277. $data['thistype'] = '';
  278. }
  279. Doo::loadHelper('DooPager');
  280. $totalArchive = $holiday->count(array('where' => 'uid='.$this->staff[0]['sid'].$sql, 'asArray' => TRUE));
  281. $pager = new DooPager(Doo::conf()->APP_URL . "holidayallList".$pagemsg."/page", $totalArchive, 10, 10);
  282. if (isset($this->params['pindex']))
  283. $pager->paginate(intval($this->params['pindex']));
  284. else
  285. $pager->paginate(1);
  286. if ($pager->limit != ' -10,10')
  287. $holidaymsg = $holiday->find(array('where' => 'uid='.$this->staff[0]['sid'].$sql, 'limit' => $pager->limit, 'desc' => 'id', 'asArray' => TRUE));
  288. if(isset($holidaymsg) && !empty($holidaymsg)){
  289. foreach($holidaymsg as $k => $v){
  290. $holidaymsg[$k]['typename'] = $type->getTypeNamebyid($v['type']);
  291. $holidaymsg[$k]['daynum'] = floatval($v['daynum']);
  292. $holidaymsg[$k]['approvetime'] = !empty($v['approvetime']) ? date('Y-m-d H:i:s',$v['approvetime']) : '';
  293. $msg = '';
  294. if(in_array($v['type'],array(1,2,3,4,5,10,11,12))){
  295. $dayjson = json_decode($v['dayjson']);
  296. if($v['type'] != 11){
  297. $holidaydays = $this->geyDayMsg($dayjson->holiday);
  298. foreach($holidaydays as $hk => $hv){
  299. $msg .= $hv['daytime'].' '.$hv['daymsg'].',';
  300. }
  301. $msg = substr($msg,0,strlen($msg)-1);
  302. }else{
  303. $msg .= '休假时间:';
  304. $holidaydays = $this->geyDayMsg($dayjson->holiday);
  305. foreach($holidaydays as $hk => $hv){
  306. $msg .= $hv['daytime'].' '.$hv['daymsg'].',';
  307. }
  308. $msg = substr($msg,0,strlen($msg)-1);
  309. $msg .= '<br>加班时间:';
  310. $overtimedays = $this->geyDayMsg($dayjson->overtime);
  311. foreach($overtimedays as $ok => $ov){
  312. $msg .= $ov['daytime'].' '.$ov['daymsg'].',';
  313. }
  314. $msg = substr($msg,0,strlen($msg)-1);
  315. }
  316. }elseif(in_array($v['type'],array(6,7,8,9))){
  317. $msg .= $v['starttime']. ' 至 '.$v['endtime'];
  318. }elseif(in_array($v['type'],array(13,14,15,16,17,18,19))){
  319. $msg .= date('Y-m-d H:i:s',$v['addtime']);
  320. }
  321. $holidaymsg[$k]['daymsg'] = $msg;
  322. }
  323. $data['holidaylist'] = $holidaymsg;
  324. }
  325. $data['pager'] = $pager->output;
  326. $data ['memu'] = 'holiday';
  327. $data ['holidaymenu'] = 'borad';
  328. $data ['staff'] = $this->staff;
  329. $data['noindexjs'] = 'noindexjs';
  330. $this->render ( "/holiday-allList", $data );
  331. }
  332. public function holidayClose(){
  333. $checkadmin = $this->checkisadmin();
  334. if(!$checkadmin){
  335. exit('非假期管理员无法访问此页面');
  336. }
  337. $data['cansee'] = 1;
  338. //获取办事处列表
  339. Doo::loadModel('staff');
  340. Doo::loadModel('holidaystaff');
  341. Doo::loadModel('holidayday');
  342. Doo::loadModel('holiday');
  343. $staff = new staff();
  344. $hstaff = new HStaff();
  345. $hday = new HDay();
  346. $holiday = new Holiday();
  347. $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';
  348. $query = Doo::db ()->query ( $sql );
  349. $result = $query->fetchAll ();
  350. $data['category'] = $result;
  351. $thisyear = date('Y',time());
  352. // $thisyear = date('Y',1546358400);
  353. $data['thismonth'] = intval(date('m',time()));
  354. $num = intval($thisyear)-2017;
  355. $html = '';
  356. $yearnum = isset($this->params['year']) && is_numeric($this->params['year']) ? $this->params['year'] : '';
  357. for($i = $num; $i >= 0; $i--){
  358. if($yearnum == (2017+$i)){
  359. $html .= '<option value="'.(2017+$i).'" selected>'.(2017+$i).'</option>';
  360. }else{
  361. $html .= '<option value="'.(2017+$i).'">'.(2017+$i).'</option>';
  362. }
  363. }
  364. $data['option'] = $html;
  365. if(isset($this->params['year']) && isset($this->params['month'])){
  366. $month = intval($this->params['month']) < 10 ? '0'.$this->params['month'] : $this->params['month'];
  367. $date = $this->params['year'].'-'.$month.'-01';
  368. $thismonth = $this->getMonthTime($date);
  369. $data['thismonth'] = $this->params['month'];
  370. }else{
  371. $thismonth = $this->getMonthTime(date('Y-m-d',time()));
  372. }
  373. foreach($result as $k => $v){
  374. $stafflist[$k]['categoryname'] = $v['title'];
  375. $stafflist[$k]['count'] = $v['count'];
  376. $cidstafflist = $staff->find(array('where' => 'cid='.$v['cid'].' and nature=1', 'asArray' => TRUE));
  377. foreach($cidstafflist as $ck => $cv) {
  378. foreach (array(1, 2, 3) as $tk => $tv) {
  379. $typeholiday = $hday->find(array('where' => 'type=' . $tv . ' and uid=' . $cv['sid'] . ' and UNIX_TIMESTAMP(daytime) between ' . $thismonth['start'] . ' and ' . $thismonth['end'], 'asArray' => TRUE));
  380. $cidstafflist[$ck][$tv] = 0;
  381. if (!empty($typeholiday)) {
  382. foreach ($typeholiday as $thk => $thv) {
  383. $cidstafflist[$ck][$tv] += floatval($thv['daymsg']);
  384. }
  385. }
  386. $cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
  387. }
  388. $cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
  389. }
  390. $stafflist[$k]['cidstafflist'] = $cidstafflist;
  391. }
  392. $data['stafflist'] = $stafflist;
  393. $zongbu = $staff->find(array('where' => 'cid=12 and nature=1', 'asArray' => TRUE));
  394. $data['zongbu'] = $zongbu;
  395. $data ['memu'] = 'holiday';
  396. $data ['holidaymenu'] = 'close';
  397. $data ['staff'] = $this->staff;
  398. $data['noindexjs'] = 'noindexjs';
  399. $this->render ( "/holiday-close", $data );
  400. }
  401. public function holidayClose2(){
  402. $checkadmin = $this->checkisadmin();
  403. if(!$checkadmin){
  404. exit('非假期管理员无法访问此页面');
  405. }
  406. $data['cansee'] = 1;
  407. //获取办事处列表
  408. Doo::loadModel('staff');
  409. Doo::loadModel('holidaystaff');
  410. Doo::loadModel('holidayday');
  411. Doo::loadModel('holiday');
  412. $staff = new staff();
  413. $hstaff = new HStaff();
  414. $hday = new HDay();
  415. $holiday = new Holiday();
  416. $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';
  417. $query = Doo::db ()->query ( $sql );
  418. $result = $query->fetchAll ();
  419. $data['category'] = $result;
  420. $thisyear = date('Y',time());
  421. // $thisyear = date('Y',1546358400);
  422. $data['thismonth'] = intval(date('m',time()));
  423. $num = intval($thisyear)-2017;
  424. $html = '';
  425. $yearnum = isset($this->params['year']) && is_numeric($this->params['year']) ? $this->params['year'] : '';
  426. for($i = $num; $i >= 0; $i--){
  427. if($yearnum == (2017+$i)){
  428. $html .= '<option value="'.(2017+$i).'" selected>'.(2017+$i).'</option>';
  429. }else{
  430. $html .= '<option value="'.(2017+$i).'">'.(2017+$i).'</option>';
  431. }
  432. }
  433. $data['option'] = $html;
  434. if(isset($this->params['year']) && isset($this->params['month'])){
  435. $month = intval($this->params['month']) < 10 ? '0'.$this->params['month'] : $this->params['month'];
  436. $date = $this->params['year'].'-'.$month.'-01';
  437. $thismonth = $this->getMonthTime($date);
  438. $data['thismonth'] = $this->params['month'];
  439. }else{
  440. $thismonth = $this->getMonthTime(date('Y-m-d',time()));
  441. }
  442. $stafflist = array();
  443. foreach($result as $k => $v){
  444. $stafflist[$k]['categoryname'] = $v['title'];
  445. $stafflist[$k]['count'] = $v['count'];
  446. $cidstafflist = $staff->find(array('where' => 'cid='.$v['cid'].' and nature=2', 'asArray' => TRUE));
  447. foreach($cidstafflist as $ck => $cv) {
  448. foreach (array(1, 2, 3, 14) as $tk => $tv) {
  449. if($tv == 14){
  450. $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));
  451. $cidstafflist[$ck][$tv] = $typeholiday['daynum'] != 0 ? floatval($typeholiday['daynum']) : '';
  452. }else{
  453. $typeholiday = $hday->find(array('where' => 'type=' . $tv . ' and uid=' . $cv['sid'] . ' and UNIX_TIMESTAMP(daytime) between ' . $thismonth['start'] . ' and ' . $thismonth['end'], 'asArray' => TRUE));
  454. $cidstafflist[$ck][$tv] = 0;
  455. if (!empty($typeholiday)) {
  456. foreach ($typeholiday as $thk => $thv) {
  457. $cidstafflist[$ck][$tv] += floatval($thv['daymsg']);
  458. }
  459. }
  460. $cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
  461. }
  462. }
  463. $cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
  464. }
  465. $stafflist[$k]['cidstafflist'] = $cidstafflist;
  466. }
  467. $data['stafflist'] = $stafflist;
  468. $data['internstafflist'] = $staff->find(array('where' => 'nature=2', 'asArray' => TRUE));
  469. //获取上月和本月,录用 实习生上班天数
  470. $nowmonth = intval(date('m',time()));
  471. $nowday = date('Y-m-d',time());
  472. $lastmonth = intval(date('m',strtotime("-1 month")));
  473. $lastmonthday = date('Y-m-d',strtotime("-1 month"));
  474. $data['monthlist'] = '<option value="0">选择月份</option><option value="'.$lastmonthday.'">'.$lastmonth.'月</option><option value="'.$nowday.'">'.$nowmonth.'月</option>';
  475. $data ['memu'] = 'holiday';
  476. $data ['holidaymenu'] = 'close';
  477. $data ['staff'] = $this->staff;
  478. $data['noindexjs'] = 'noindexjs';
  479. $this->render ( "/holiday-close2", $data );
  480. }
  481. public function addHoliday2(){
  482. if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['type']) && is_numeric($_POST['type'])){
  483. Doo::loadModel('holiday');
  484. $holiday = new Holiday();
  485. if(in_array($_POST['type'],array(1,2,3))){
  486. $daytype = isset($_POST['daytype']) && is_numeric($_POST['daytype']) ? $_POST['daytype'] : 1;
  487. $adddaynum = $daytype != 1 ? 0.5 : 1.0;
  488. $day = $_POST['day'];
  489. $dayjson = array('holiday' => [$day.'_'.$daytype]);
  490. $holiday->uid = $_POST['uid'];
  491. $holiday->type = $_POST['type'];
  492. $holiday->dayjson = json_encode($dayjson);
  493. $holiday->daynum = $adddaynum;
  494. $holiday->status = 3;
  495. $holiday->addtime = time();
  496. $holiday->approvetime = time();
  497. $holiday->description = $_POST['description'];
  498. $id = $holiday->insert();
  499. Doo::loadModel('holidayday');
  500. $hday = new HDay();
  501. $hday->hid = $id;
  502. $hday->uid = $_POST['uid'];
  503. $hday->type = $_POST['type'];
  504. $hday->daytime = $day;
  505. $hday->daymsg = $adddaynum;
  506. $hday->insert();
  507. if(isset($_POST['close2'])){
  508. return '/holidayclose2';
  509. }else{
  510. return '/holidayclose';
  511. }
  512. }elseif($_POST['type'] == 14){
  513. $thismonth = $this->getMonthTime($_POST['monthselect']);
  514. $holiday->uid = $_POST['uid'];
  515. $holiday->type = $_POST['type'];
  516. $holiday->starttime = $thismonth['start'];
  517. $holiday->endtime = $thismonth['end'];
  518. $holiday->daynum = $_POST['daynum'];
  519. $holiday->status = 3;
  520. $holiday->addtime = time();
  521. $holiday->approvetime = time();
  522. $holiday->description = $_POST['description'];
  523. $holiday->insert();
  524. return '/holidayclose2';
  525. }
  526. }
  527. exit('添加事病假、旷工出错');
  528. }
  529. public function holidayOvertime(){
  530. $checkadmin = $this->checkisadmin();
  531. if(!$checkadmin){
  532. exit('非假期管理员无法访问此页面');
  533. }
  534. $data['cansee'] = 1;
  535. //获取办事处列表
  536. Doo::loadModel('staff');
  537. Doo::loadModel('holidaystaff');
  538. Doo::loadModel('holidayday');
  539. Doo::loadModel('holiday');
  540. $staff = new staff();
  541. $hstaff = new HStaff();
  542. $hday = new HDay();
  543. $holiday = new Holiday();
  544. $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 group by `CLD_staff`.cid HAVING count(`CLD_staff`.sid)>0 order by count(`CLD_staff`.sid) desc';
  545. $query = Doo::db ()->query ( $sql );
  546. $result = $query->fetchAll ();
  547. $data['category'] = $result;
  548. $thisyear = date('Y',time());
  549. // $thisyear = date('Y',1546358400);
  550. $data['thismonth'] = intval(date('m',time()));
  551. $num = intval($thisyear)-2017;
  552. $html = '';
  553. $yearnum = isset($this->params['year']) && is_numeric($this->params['year']) ? $this->params['year'] : '';
  554. for($i = $num; $i >= 0; $i--){
  555. if($yearnum == (2017+$i)){
  556. $html .= '<option value="'.(2017+$i).'" selected>'.(2017+$i).'</option>';
  557. }else{
  558. $html .= '<option value="'.(2017+$i).'">'.(2017+$i).'</option>';
  559. }
  560. }
  561. $data['option'] = $html;
  562. if(isset($this->params['year']) && isset($this->params['month'])){
  563. $month = intval($this->params['month']) < 10 ? '0'.$this->params['month'] : $this->params['month'];
  564. $date = $this->params['year'].'-'.$month.'-01';
  565. $thismonth = $this->getMonthTime($date);
  566. $data['thismonth'] = $this->params['month'];
  567. }else{
  568. $thismonth = $this->getMonthTime(date('Y-m-d',time()));
  569. }
  570. $stafflist = array();
  571. if(isset($this->params['cid']) && is_numeric($this->params['cid'])){
  572. $data['thiscid'] = $this->params['cid'];
  573. foreach($result as $k => $v){
  574. if($this->params['cid'] == $v['cid']){
  575. $stafflist[0]['categoryname'] = $v['title'];
  576. $stafflist[0]['count'] = $v['count'];
  577. $cidstafflist = $staff->getStaffByCid($v['cid']);
  578. foreach($cidstafflist as $ck => $cv){
  579. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$cv['sid'], 'asArray' => TRUE));
  580. $cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
  581. foreach(array(4,5,10,11) as $tk => $tv){
  582. if($tv == 11){
  583. $typeholiday = $holiday->find(array('where' => 'status=1 and type='.$tv.' and uid='.$cv['sid'].' and addtime between '.$thismonth['start'].' and '.$thismonth['end'],'asArray' => TRUE));
  584. $cidstafflist[$ck][$tv] = 0;
  585. if(!empty($typeholiday)){
  586. foreach($typeholiday as $thk => $thv){
  587. $cidstafflist[$ck][$tv] += floatval($thv['daynum']);
  588. }
  589. }
  590. $cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
  591. }else{
  592. $typeholiday = $hday->find(array('where' => 'type='.$tv.' and uid='.$cv['sid'].' and UNIX_TIMESTAMP(daytime) between '.$thismonth['start'].' and '.$thismonth['end'],'asArray' => TRUE));
  593. $cidstafflist[$ck][$tv] = 0;
  594. if(!empty($typeholiday)){
  595. foreach($typeholiday as $thk => $thv){
  596. $cidstafflist[$ck][$tv] += floatval($thv['daymsg']);
  597. }
  598. }
  599. $cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
  600. }
  601. }
  602. $cidstafflist[$ck]['countnum'] = floatval($cidstafflist[$ck][4])+floatval($cidstafflist[$ck][5]) != 0 ? floatval($cidstafflist[$ck][4]) + floatval($cidstafflist[$ck][5]) : '';
  603. $cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
  604. }
  605. $stafflist[0]['cidstafflist'] = $cidstafflist;
  606. break;
  607. }
  608. }
  609. }else{
  610. foreach($result as $k => $v){
  611. $stafflist[$k]['categoryname'] = $v['title'];
  612. $stafflist[$k]['count'] = $v['count'];
  613. $cidstafflist = $staff->getStaffByCid($v['cid']);
  614. foreach($cidstafflist as $ck => $cv) {
  615. $hstaffmsg = $hstaff->getOne(array('where' => 'uid=' . $cv['sid'], 'asArray' => TRUE));
  616. $cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
  617. foreach (array(4, 5, 10, 11) as $tk => $tv) {
  618. if ($tv == 11) {
  619. $typeholiday = $holiday->find(array('where' => 'status=1 and type=' . $tv . ' and uid=' . $cv['sid'] . ' and addtime between ' . $thismonth['start'] . ' and ' . $thismonth['end'], 'asArray' => TRUE));
  620. $cidstafflist[$ck][$tv] = 0;
  621. if (!empty($typeholiday)) {
  622. foreach ($typeholiday as $thk => $thv) {
  623. $cidstafflist[$ck][$tv] += floatval($thv['daynum']);
  624. }
  625. }
  626. $cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
  627. } else {
  628. $typeholiday = $hday->find(array('where' => 'type=' . $tv . ' and uid=' . $cv['sid'] . ' and UNIX_TIMESTAMP(daytime) between ' . $thismonth['start'] . ' and ' . $thismonth['end'], 'asArray' => TRUE));
  629. $cidstafflist[$ck][$tv] = 0;
  630. if (!empty($typeholiday)) {
  631. foreach ($typeholiday as $thk => $thv) {
  632. $cidstafflist[$ck][$tv] += floatval($thv['daymsg']);
  633. }
  634. }
  635. $cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
  636. }
  637. }
  638. $cidstafflist[$ck]['countnum'] = floatval($cidstafflist[$ck][4])+floatval($cidstafflist[$ck][5]) != 0 ? floatval($cidstafflist[$ck][4]) + floatval($cidstafflist[$ck][5]) : '';
  639. $cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
  640. }
  641. $stafflist[$k]['cidstafflist'] = $cidstafflist;
  642. }
  643. }
  644. $data['stafflist'] = $stafflist;
  645. $zongbu = $staff->getStaffByCid(12);
  646. $data['zongbu'] = $zongbu;
  647. $data ['memu'] = 'holiday';
  648. $data ['holidaymenu'] = 'overtime';
  649. $data ['staff'] = $this->staff;
  650. $data['noindexjs'] = 'noindexjs';
  651. $this->render ( "/holiday-overtime", $data );
  652. }
  653. public function addHoliday(){
  654. if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['type']) && is_numeric($_POST['type'])){
  655. Doo::loadModel('holidaystaff');
  656. Doo::loadModel('holiday');
  657. $holiday = new Holiday();
  658. $hstaff = new HStaff();
  659. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$_POST['uid'], 'asArray' => TRUE));
  660. if(($_POST['type'] == 4 || $_POST['type'] == 5) && isset($_POST['daytype']) && is_numeric($_POST['daytype'])){
  661. $day = $_POST['day'];
  662. $hstaff->uid = $_POST['uid'];
  663. $daytype = $_POST['daytype'];
  664. $adddaynum = $daytype != 1 ? 0.5 : 1.0;
  665. $hstaff->addnum = floatval($hstaffmsg['addnum'])+$adddaynum;
  666. $result = $hstaff->update();
  667. if($result){
  668. $dayjson = array('holiday' => [$day.'_'.$daytype]);
  669. $holiday->uid = $_POST['uid'];
  670. $holiday->type = $_POST['type'];
  671. $holiday->dayjson = json_encode($dayjson);
  672. $holiday->daynum = $adddaynum;
  673. $holiday->status = 3;
  674. $holiday->addtime = time();
  675. $holiday->approvetime = time();
  676. $holiday->description = $_POST['description'];
  677. $id = $holiday->insert();
  678. Doo::loadModel('holidayday');
  679. $hday = new HDay();
  680. $hday->hid = $id;
  681. $hday->uid = $_POST['uid'];
  682. $hday->type = $_POST['type'];
  683. $hday->daytime = $day;
  684. $hday->daymsg = $adddaynum;
  685. $hday->insert();
  686. return '/holidayovertime';
  687. }else{
  688. exit('添加到holidaystaff出错');
  689. }
  690. }elseif($_POST['type'] == 13){
  691. $daynum = $_POST['tixian'];
  692. if($daynum > $hstaffmsg['addnum']){
  693. exit('提现天数超过存假天数了');
  694. }else{
  695. $hstaff->uid = $_POST['uid'];
  696. $hstaff->addnum = $hstaffmsg['addnum']-$daynum;
  697. $result = $hstaff->update();
  698. if($result){
  699. $holiday->uid = $_POST['uid'];
  700. $holiday->type = 13;
  701. $holiday->daynum = $daynum;
  702. $holiday->status = 3;
  703. $holiday->addtime = time();
  704. $holiday->approvetime = time();
  705. $holiday->description = $_POST['description'];
  706. $holiday->insert();
  707. return '/holidayovertime';
  708. }else{
  709. exit('添加到holidaystaff出错');
  710. }
  711. }
  712. }
  713. }
  714. exit('添加加值班或提现出错');
  715. }
  716. public function holidayVacation(){
  717. $checkadmin = $this->checkisadmin();
  718. if(!$checkadmin){
  719. exit('非假期管理员无法访问此页面');
  720. }
  721. $data['cansee'] = 1;
  722. //获取办事处列表
  723. Doo::loadModel('staff');
  724. Doo::loadModel('holidaystaff');
  725. $staff = new staff();
  726. $hstaff = new HStaff();
  727. $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 group by `CLD_staff`.cid HAVING count(`CLD_staff`.sid)>0 order by count(`CLD_staff`.sid) desc';
  728. $query = Doo::db ()->query ( $sql );
  729. $result = $query->fetchAll ();
  730. $data['category'] = $result;
  731. $stafflist = array();
  732. if(isset($this->params['cid']) && is_numeric($this->params['cid'])){
  733. $data['thiscid'] = $this->params['cid'];
  734. foreach($result as $k => $v){
  735. if($this->params['cid'] == $v['cid']){
  736. $stafflist[0]['categoryname'] = $v['title'];
  737. $stafflist[0]['count'] = $v['count'];
  738. $cidstafflist = $staff->getStaffByCid($v['cid']);
  739. foreach($cidstafflist as $ck => $cv){
  740. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$cv['sid'], 'asArray' => TRUE));
  741. $yearnum = $this->CheckAnnualLeave($cv);
  742. $cidstafflist[$ck]['yearnum'] = floatval($yearnum) != 0 ? floatval($yearnum) : '';
  743. $cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
  744. $cidstafflist[$ck]['hunjianum'] = $hstaffmsg['hunjianum'] != 0.0 ? floatval($hstaffmsg['hunjianum']) : '';
  745. $cidstafflist[$ck]['chanjianum'] = $hstaffmsg['chanjianum'] != 0.0 ? floatval($hstaffmsg['chanjianum']) : '';
  746. $cidstafflist[$ck]['sangjianum'] = $hstaffmsg['sangjianum'] != 0.0 ? floatval($hstaffmsg['sangjianum']) : '';
  747. $cidstafflist[$ck]['gongjianum'] = $hstaffmsg['gongjianum'] != 0.0 ? floatval($hstaffmsg['gongjianum']) : '';
  748. $cidstafflist[$ck]['yearround'] = $cv['nature'] == 1 ? $this->getYearRoundtime($hstaffmsg['hadyear'],$cv['hiredate']) : '';
  749. $cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
  750. }
  751. $stafflist[0]['cidstafflist'] = $cidstafflist;
  752. break;
  753. }
  754. }
  755. }else{
  756. foreach($result as $k => $v){
  757. $stafflist[$k]['categoryname'] = $v['title'];
  758. $stafflist[$k]['count'] = $v['count'];
  759. $cidstafflist = $staff->getStaffByCid($v['cid']);
  760. foreach($cidstafflist as $ck => $cv){
  761. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$cv['sid'], 'asArray' => TRUE));
  762. $yearnum = $this->CheckAnnualLeave($cv);
  763. $cidstafflist[$ck]['yearnum'] = floatval($yearnum) != 0 ? floatval($yearnum) : '';
  764. $cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
  765. $cidstafflist[$ck]['hunjianum'] = $hstaffmsg['hunjianum'] != 0.0 ? floatval($hstaffmsg['hunjianum']) : '';
  766. $cidstafflist[$ck]['chanjianum'] = $hstaffmsg['chanjianum'] != 0.0 ? floatval($hstaffmsg['chanjianum']) : '';
  767. $cidstafflist[$ck]['sangjianum'] = $hstaffmsg['sangjianum'] != 0.0 ? floatval($hstaffmsg['sangjianum']) : '';
  768. $cidstafflist[$ck]['gongjianum'] = $hstaffmsg['gongjianum'] != 0.0 ? floatval($hstaffmsg['gongjianum']) : '';
  769. $cidstafflist[$ck]['yearround'] = $cv['nature'] == 1 ? $this->getYearRoundtime($hstaffmsg['hadyear'],$cv['hiredate']) : '';
  770. $cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
  771. }
  772. $stafflist[$k]['cidstafflist'] = $cidstafflist;
  773. }
  774. }
  775. $zongbu = $staff->getStaffByCid(12);
  776. $data['zongbu'] = $zongbu;
  777. $hstaff2 = new HStaff();
  778. $hstaffmsg2 = $hstaff2->getOne(array('select' => 'yearnum', 'where' => 'uid='.$zongbu[0]['sid'], 'asArray' => TRUE));
  779. $data['thisnum'] = floatval($hstaffmsg2['yearnum']);
  780. $data['stafflist'] = $stafflist;
  781. $data ['memu'] = 'holiday';
  782. $data ['holidaymenu'] = 'vacation';
  783. $data ['staff'] = $this->staff;
  784. $data['noindexjs'] = 'noindexjs';
  785. $this->render ( "/holiday-vacation", $data );
  786. }
  787. public function setStaffHoliday(){
  788. if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['typeholiday']) && isset($_POST['addnum'])){
  789. Doo::loadModel('holidaystaff');
  790. $hstaff = new HStaff();
  791. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$_POST['uid'], 'asArray' => TRUE));
  792. $hstaff->uid = $_POST['uid'];
  793. $type = '';
  794. switch($_POST['typeholiday']){
  795. case 'yearnum':
  796. $hstaff->yearnum = $hstaffmsg['yearnum']+$_POST['addnum'];
  797. $type = 15;
  798. break;
  799. case 'hunjianum':
  800. $hstaff->hunjianum = $hstaffmsg['hunjianum']+$_POST['addnum'];
  801. $type = 16;
  802. break;
  803. case 'chanjianum':
  804. $hstaff->chanjianum = $hstaffmsg['chanjianum']+$_POST['addnum'];
  805. $type = 17;
  806. break;
  807. case 'sangjianum':
  808. $hstaff->sangjianum = $hstaffmsg['sangjianum']+$_POST['addnum'];
  809. $type = 18;
  810. break;
  811. case 'gongjianum':
  812. $hstaff->gongjianum = $hstaffmsg['gongjianum']+$_POST['addnum'];
  813. $type = 19;
  814. break;
  815. }
  816. $hstaff->update();
  817. Doo::loadModel('holiday');
  818. $holiday = new Holiday();
  819. $holiday->uid = $_POST['uid'];
  820. $holiday->type = $type;
  821. $holiday->daynum = $_POST['addnum'];
  822. $holiday->status = 3;
  823. $holiday->addtime = time();
  824. $holiday->approvetime = time();
  825. $holiday->description = $_POST['description'];
  826. $holiday->insert();
  827. return '/holidayvacation';
  828. }else{
  829. exit('增加出错');
  830. }
  831. }
  832. public function getStaffCategory(){
  833. if(isset($_POST['cid']) && is_numeric($_POST['cid'])){
  834. Doo::loadModel('staff');
  835. $staff = new staff();
  836. $stafflist = $staff->getStaffByCid($_POST['cid']);
  837. Doo::loadModel('holidaystaff');
  838. $hstaff = new HStaff();
  839. $hstaffmsg = $hstaff->getOne(array('select' => 'yearnum', 'where' => 'uid='.$stafflist[0]['sid'], 'asArray' => TRUE));
  840. exit(json_encode(array('code' => 200, 'stafflist' => $stafflist, 'thisnum' => floatval($hstaffmsg['yearnum']))));
  841. }
  842. exit(json_encode(array('code' => 400)));
  843. }
  844. public function getHolidayStaff(){
  845. if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['type'])){
  846. Doo::loadModel('holidaystaff');
  847. $hstaff = new HStaff();
  848. $staffmsg = $hstaff->getOne(array('select' => $_POST['type'], 'where' => 'uid='.$_POST['uid'], 'asArray' => TRUE));
  849. exit(json_encode(array('code' => 200, 'thisnum' => floatval($staffmsg[$_POST['type']]))));
  850. }
  851. exit(json_encode(array('code' => 400)));
  852. }
  853. public function holidayAttendance(){
  854. $checkadmin = $this->checkisadmin();
  855. if($checkadmin){
  856. $data['cansee'] = 1;
  857. }
  858. Doo::loadModel('holidayday');
  859. Doo::loadModel('holiday');
  860. Doo::loadModel('holidaystaff');
  861. Doo::loadModel('holidaytype');
  862. Doo::loadModel('staff');
  863. $hday = new HDay();
  864. $holiday = new Holiday();
  865. $hstaff = new HStaff();
  866. $type = new HType();
  867. $staff = new staff();
  868. $sqlstr = '';
  869. $pagestr = '';
  870. if(isset($this->params['day'])){
  871. $today = $this->params['day'];
  872. $todayarr = explode('~',$today);
  873. if(count($todayarr) != 2){
  874. $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].'")))';
  875. }else{
  876. $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].'"))))';
  877. }
  878. }else{
  879. $today = date('Y-m-d',time());
  880. $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.'")))';
  881. }
  882. $pagestr .= '/day/'.$today;
  883. $data['today'] = $today;
  884. if(isset($this->params['cate'])){
  885. $cate = 'headquarters';
  886. $pagestr .= '/cate/'.$cate;
  887. $data['cate'] = 1;
  888. $sqlstr .= ' and uid in (select sid from `CLD_staff` where cid=12 and departmentID=0)';
  889. }else{
  890. $data['cate'] = 0;
  891. }
  892. $data['typeurl'] = $pagestr;
  893. if(isset($this->params['type'])){
  894. $data['type'] = $this->params['type'];
  895. $pagestr .= '/type/'.$this->params['type'];
  896. if($this->params['type'] == 4 ){//加班、值班
  897. $sqlstr .= ' and (type=4 or type=5)';
  898. }elseif($this->params['type'] == 6){//其他长假
  899. $sqlstr .= ' and type in(3,6,7,8,9)';
  900. }else{
  901. $sqlstr .= ' and type='.$this->params['type'];
  902. }
  903. }else{
  904. $data['type'] = '';
  905. }
  906. Doo::loadHelper('DooPager');
  907. $totalArchive = $holiday->count(array('where' => 'status=1'.$sqlstr, 'asArray' => TRUE));
  908. $pager = new DooPager(Doo::conf()->APP_URL . "holidayattendance".$pagestr."/page", $totalArchive, 10, 10);
  909. if (isset($this->params['pindex']))
  910. $pager->paginate(intval($this->params['pindex']));
  911. else
  912. $pager->paginate(1);
  913. if ($pager->limit != ' -10,10')
  914. $holidaymsg = $holiday->find(array('where' => 'status=1'.$sqlstr, 'limit' => $pager->limit, 'asArray' => TRUE));
  915. if(isset($holidaymsg) && !empty($holidaymsg)){
  916. foreach($holidaymsg as $k => $v){
  917. $staffmsg = $staff->getOne(array('where' => 'sid=?', 'param' => array($v['uid']), 'asArray' => TRUE));
  918. $holidaymsg[$k]['username'] = $staffmsg['username'];
  919. $holidaymsg[$k]['category'] = $staffmsg['cid'] == 12 && $staffmsg['departmentID'] == 1 ? '总部(造价研究中心)' : $staffmsg['category'];
  920. $holidaymsg[$k]['typename'] = $type->getTypeNamebyid($v['type']);
  921. $holidaymsg[$k]['daynum'] = floatval($v['daynum']);
  922. $holidaymsg[$k]['approvetime'] = !empty($v['approvetime']) ? date('Y-m-d H:i:s',$v['approvetime']) : '';
  923. $msg = '';
  924. if(in_array($v['type'],array(1,2,3,4,5,10,11,12))){
  925. $dayjson = json_decode($v['dayjson']);
  926. if($v['type'] != 11){
  927. $holidaydays = $this->geyDayMsg($dayjson->holiday);
  928. foreach($holidaydays as $hk => $hv){
  929. $msg .= $hv['daytime'].' '.$hv['daymsg'].',';
  930. }
  931. $msg = substr($msg,0,strlen($msg)-1);
  932. }else{
  933. $msg .= '休假时间:';
  934. $holidaydays = $this->geyDayMsg($dayjson->holiday);
  935. foreach($holidaydays as $hk => $hv){
  936. $msg .= $hv['daytime'].' '.$hv['daymsg'].',';
  937. }
  938. $msg = substr($msg,0,strlen($msg)-1);
  939. $msg .= '<br>加班时间:';
  940. $overtimedays = $this->geyDayMsg($dayjson->overtime);
  941. foreach($overtimedays as $ok => $ov){
  942. $msg .= $ov['daytime'].' '.$ov['daymsg'].',';
  943. }
  944. $msg = substr($msg,0,strlen($msg)-1);
  945. }
  946. }elseif(in_array($v['type'],array(6,7,8,9))){
  947. $msg .= $v['starttime']. ' 至 '.$v['endtime'];
  948. }elseif(in_array($v['type'],array(13,14,15,16,17,18,19))){
  949. $msg .= date('Y-m-d H:i:s',$v['addtime']);
  950. }
  951. $holidaymsg[$k]['daymsg'] = $msg;
  952. }
  953. $data['holidaylist'] = $holidaymsg;
  954. }
  955. $data['pager'] = $pager->output;
  956. $data ['memu'] = 'holiday';
  957. $data ['holidaymenu'] = 'borad';
  958. $data ['staff'] = $this->staff;
  959. $data['noindexjs'] = 'noindexjs';
  960. $this->render ( "/holiday-allList2", $data );
  961. }
  962. private function geyDayMsg($dayjson){
  963. $holidayday = array();
  964. foreach($dayjson as $dk => $dv){
  965. $oneday = explode('_',$dv);
  966. if($oneday[1] != 0){
  967. $holidayday[$dk]['daytime'] = $oneday[0];
  968. $holidayday[$dk]['daymsg'] = $oneday[1] == 1 ? '' : ($oneday[1] == 2 ? '上午' : '下午');
  969. }
  970. }
  971. return $holidayday;
  972. }
  973. //获取某日期的月初月末时间戳
  974. private function getMonthTime($time){
  975. $starttime = strtotime(date('Y-m-01',strtotime($time)));
  976. $endtime = strtotime("+1 months", strtotime(date('Y-m-01',strtotime($time))))-1;
  977. return array('start' => $starttime, 'end' => $endtime);
  978. }
  979. //获取本年的每个月的时间戳
  980. private function getYearMonthTime($thisyear){
  981. $monthdata = array();
  982. for($i = 0; $i < 12; $i++){
  983. $j = $i+1;
  984. $j = $j < 10 ? '0'.$j : $j;
  985. $nowmonth = $thisyear.'-'.$j.'-01';
  986. $monthdata[$i]['starttime'] = strtotime($nowmonth);
  987. $monthdata[$i]['endtime'] = strtotime("+1 months", strtotime($nowmonth))-1;
  988. }
  989. return $monthdata;
  990. }
  991. //获取本年当事人的年假周期
  992. private function getYearRoundtime($hadyear,$hiredate){
  993. $month = date('m', strtotime($hiredate));
  994. $date = date('d', strtotime($hiredate));
  995. $monthday = intval($month).'月'.intval($date).'日';
  996. $year = date('Y',time());
  997. //每隔4年加一天
  998. if(date('Y',(strtotime($hiredate)+(86400*365*$hadyear)+intval($hadyear/4)*86400)) < $year){
  999. $lastyear = intval($year)-1;
  1000. return intval($lastyear).'年'.$monthday.'~'.intval($year).'年'.$monthday;
  1001. }else{
  1002. $nextyear = intval($year)+1;
  1003. return intval($year).'年'.$monthday.'~'.intval($nextyear).'年'.$monthday;
  1004. }
  1005. }
  1006. private function checkisadmin(){
  1007. Doo::loadModel('holidayadmin');
  1008. $admin = new HAdmin();
  1009. $adminmsg = $admin->getOne(array('where' => 'uid='.$this->staff[0]['sid'], 'asArray' => TRUE));
  1010. if(!empty($adminmsg)){
  1011. return TRUE;
  1012. }else{
  1013. return FALSE;
  1014. }
  1015. }
  1016. //检查年假是否过期并更新年假
  1017. private function CheckAnnualLeave($staff){
  1018. if($staff['nature'] == 2){
  1019. return 0;
  1020. }
  1021. $hiredate = $staff['hiredate'];
  1022. $hireBiasDates = $staff['hireBiasDates'];
  1023. if($hiredate == ''){
  1024. return 0;
  1025. }
  1026. Doo::loadModel('holidaystaff');
  1027. $hstaff = new HStaff();
  1028. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$staff['sid'],'asArray' => TRUE));
  1029. $hadyear = intval((time()-strtotime($hiredate) + 86400*$hireBiasDates)/(86400*365));
  1030. if($hadyear != $hstaffmsg['hadyear']){
  1031. $hstaff->uid = $staff['sid'];
  1032. $hstaff->hadyear = $hadyear;
  1033. $hstaff->yearnum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
  1034. $hstaff->update();
  1035. $daynum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
  1036. }else{
  1037. $daynum = $hstaffmsg['yearnum'];
  1038. }
  1039. return $daynum;
  1040. }
  1041. }
  1042. ?>