leaveModel.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. //请假条的
  3. class flow_leaveClassModel extends flowModel
  4. {
  5. public function flowrsreplace($rs)
  6. {
  7. $rs['modenum'] = $this->modenum;
  8. $totday = floatval(arrvalue($rs,'totday','0'));
  9. if($totday>0)$rs['totals'].='('.$totday.'天)';
  10. return $rs;
  11. }
  12. protected function flowbillwhere($uid, $lx)
  13. {
  14. $month = $this->rock->post('month');
  15. $where = '';
  16. if($month!=''){
  17. $where.=" and `stime` like '$month%'";
  18. }
  19. return array(
  20. 'where' => $where
  21. );
  22. }
  23. /**
  24. * 年假添加设置(自动添加),可计划任务没有运行一次,兑换为小时的,默认一天8小时
  25. */
  26. public function autoaddleave($ndate='')
  27. {
  28. $type = 0; //根据哪个类型计算年:0根据入职日期,1根据转正日期
  29. $hour = (int)m('option')->getval('kqsbtime', 8); //默认一天8小时(请自己设定)
  30. if($hour<=0)$hour = 8;
  31. if($ndate=='')$ndate = $this->rock->date;
  32. if($ndate > $this->rock->date)return array();
  33. $Y = substr($ndate,0,4);
  34. $niana = array(
  35. // 开始 截止 年假天数
  36. array(0, 0, 0), //0-0年,0天
  37. array(1, 10, 5), //1年(含)-10年(含),5天
  38. array(11, 20, 10), //11年(含)-20年(含),10天
  39. array(21, 9999, 15), //21年(含)以上,15天
  40. );
  41. //配置可根据自己情况修改
  42. $adlx = array('workdate','positivedt');
  43. $adln = array('入职','转正');
  44. $dtobj= c('date');
  45. $usea = $this->db->getall("select `uid` from `[Q]kqinfo` where `kind`='增加年假' and `status`=1 and `optname`='系统' and `stime` like '".$Y."-%'"); //系统已经自动添加过
  46. $uids = '0';
  47. foreach($usea as $k=>$rs)$uids.=','.$rs['uid'].'';
  48. $rows = $this->db->getall("select a.`id`,a.`name`,a.`workdate`,b.`positivedt` from `[Q]admin` a left join `[Q]userinfo` b on a.id=b.id where a.`status`=1 and a.id not in($uids) and b.`state`<>5");
  49. $barr = array();
  50. foreach($rows as $k=>$rs){
  51. $dt = $rs[$adlx[$type]];
  52. if(isempt($dt))continue;
  53. $dttime = strtotime($dt);
  54. $rs['dt'] = $dt;
  55. $jg = $dtobj->datediff('d', $dt, $ndate);
  56. $yea= (int)($jg/365); //年限
  57. if($yea==0)continue;//未满1年
  58. $nianday = 0; //年假条数
  59. foreach($niana as $k1=>$ns){
  60. if($yea>=$ns[0] && $yea<=$ns[1]){
  61. $nianday = $ns[2];
  62. break;
  63. }
  64. }
  65. $dt = date(''.$Y.'-m-d', $dttime);
  66. if(strtotime($dt) > strtotime($ndate) )continue;//还没到对应日期
  67. $rs['nianday'] = $nianday;
  68. $rs['nyear'] = $yea; //入职年限
  69. $rs['stime'] = $dt.' 00:00:00';
  70. $rs['etime'] = $dt.' 23:59:59';
  71. $rs['nianhour'] = $nianday * $hour; //小时
  72. $barr[] = $rs;
  73. }
  74. //添加到kqinfo表上
  75. $dbs = m('kqinfo');
  76. foreach($barr as $k=>$rs){
  77. $uarr['uid'] = $rs['id'];
  78. $uarr['uname'] = $rs['name'];
  79. $uarr['stime'] = $rs['stime'];
  80. $uarr['etime'] = $rs['etime'];
  81. $uarr['kind'] = '增加年假';
  82. $uarr['status'] = '1';
  83. $uarr['totals'] = $rs['nianhour'];
  84. $uarr['optdt'] = $this->rock->now;
  85. $uarr['isturn'] = '1';
  86. $uarr['optname'] = '系统';
  87. $uarr['optid'] = '0';
  88. $uarr['applydt'] = $this->rock->date;
  89. $uarr['totday'] = $rs['nianday'];
  90. $uarr['explain'] = ''.$rs['dt'].''.$adln[$type].'年限满'.$rs['nyear'].'年添加年假'.$rs['nianday'].'天';
  91. $dbs->insert($uarr);
  92. }
  93. $this->updateenddt();
  94. return $barr;
  95. }
  96. /**
  97. * 更新年假/加班单的截止时间
  98. */
  99. public function updateenddt()
  100. {
  101. $dbs = m('option');
  102. $jbuse = (int)$dbs->getval('kqjiabanuse', 0); //加班
  103. $njuse = (int)$dbs->getval('kqnianjiause', 0);
  104. $db = m('kqinfo');
  105. if($jbuse>0){
  106. $key = "CONCAT(date_format(date_add(stime,interval ".$jbuse." month),'%Y-%m-%d'),' ','23:59:59')";
  107. $db->update('enddt='.$key.'',"`kind`='加班' and `enddt` is null"); //兑换调休的
  108. }
  109. if($njuse>0){
  110. $key = "CONCAT(date_format(date_add(stime,interval ".$njuse." month),'%Y-%m-%d'),' ','23:59:59')";
  111. $db->update('enddt='.$key.'',"`kind`='增加年假' and `enddt` is null");
  112. }
  113. }
  114. }
粤ICP备19079148号