HolidayController.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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. $day = $_POST['day'];
  487. $dayjson = array('holiday' => [$day.'_1']);
  488. $holiday->uid = $_POST['uid'];
  489. $holiday->type = $_POST['type'];
  490. $holiday->dayjson = json_encode($dayjson);
  491. $holiday->daynum = 1.0;
  492. $holiday->status = 3;
  493. $holiday->addtime = time();
  494. $holiday->approvetime = time();
  495. $holiday->description = $_POST['description'];
  496. $id = $holiday->insert();
  497. Doo::loadModel('holidayday');
  498. $hday = new HDay();
  499. $hday->hid = $id;
  500. $hday->uid = $_POST['uid'];
  501. $hday->type = $_POST['type'];
  502. $hday->daytime = $day;
  503. $hday->daymsg = 1.0;
  504. $hday->insert();
  505. if(isset($_POST['close2'])){
  506. return '/holidayclose2';
  507. }else{
  508. return '/holidayclose';
  509. }
  510. }elseif($_POST['type'] == 14){
  511. $thismonth = $this->getMonthTime($_POST['monthselect']);
  512. $holiday->uid = $_POST['uid'];
  513. $holiday->type = $_POST['type'];
  514. $holiday->starttime = $thismonth['start'];
  515. $holiday->endtime = $thismonth['end'];
  516. $holiday->daynum = $_POST['daynum'];
  517. $holiday->status = 3;
  518. $holiday->addtime = time();
  519. $holiday->approvetime = time();
  520. $holiday->description = $_POST['description'];
  521. $holiday->insert();
  522. return '/holidayclose2';
  523. }
  524. }
  525. exit('添加事病假、旷工出错');
  526. }
  527. public function holidayOvertime(){
  528. $checkadmin = $this->checkisadmin();
  529. if(!$checkadmin){
  530. exit('非假期管理员无法访问此页面');
  531. }
  532. $data['cansee'] = 1;
  533. //获取办事处列表
  534. Doo::loadModel('staff');
  535. Doo::loadModel('holidaystaff');
  536. Doo::loadModel('holidayday');
  537. Doo::loadModel('holiday');
  538. $staff = new staff();
  539. $hstaff = new HStaff();
  540. $hday = new HDay();
  541. $holiday = new Holiday();
  542. $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';
  543. $query = Doo::db ()->query ( $sql );
  544. $result = $query->fetchAll ();
  545. $data['category'] = $result;
  546. $thisyear = date('Y',time());
  547. // $thisyear = date('Y',1546358400);
  548. $data['thismonth'] = intval(date('m',time()));
  549. $num = intval($thisyear)-2017;
  550. $html = '';
  551. $yearnum = isset($this->params['year']) && is_numeric($this->params['year']) ? $this->params['year'] : '';
  552. for($i = $num; $i >= 0; $i--){
  553. if($yearnum == (2017+$i)){
  554. $html .= '<option value="'.(2017+$i).'" selected>'.(2017+$i).'</option>';
  555. }else{
  556. $html .= '<option value="'.(2017+$i).'">'.(2017+$i).'</option>';
  557. }
  558. }
  559. $data['option'] = $html;
  560. if(isset($this->params['year']) && isset($this->params['month'])){
  561. $month = intval($this->params['month']) < 10 ? '0'.$this->params['month'] : $this->params['month'];
  562. $date = $this->params['year'].'-'.$month.'-01';
  563. $thismonth = $this->getMonthTime($date);
  564. $data['thismonth'] = $this->params['month'];
  565. }else{
  566. $thismonth = $this->getMonthTime(date('Y-m-d',time()));
  567. }
  568. $stafflist = array();
  569. if(isset($this->params['cid']) && is_numeric($this->params['cid'])){
  570. $data['thiscid'] = $this->params['cid'];
  571. foreach($result as $k => $v){
  572. if($this->params['cid'] == $v['cid']){
  573. $stafflist[0]['categoryname'] = $v['title'];
  574. $stafflist[0]['count'] = $v['count'];
  575. $cidstafflist = $staff->getStaffByCid($v['cid']);
  576. foreach($cidstafflist as $ck => $cv){
  577. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$cv['sid'], 'asArray' => TRUE));
  578. $cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
  579. foreach(array(4,5,10,11) as $tk => $tv){
  580. if($tv == 11){
  581. $typeholiday = $holiday->find(array('where' => 'status=1 and type='.$tv.' and uid='.$cv['sid'].' and addtime between '.$thismonth['start'].' and '.$thismonth['end'],'asArray' => TRUE));
  582. $cidstafflist[$ck][$tv] = 0;
  583. if(!empty($typeholiday)){
  584. foreach($typeholiday as $thk => $thv){
  585. $cidstafflist[$ck][$tv] += floatval($thv['daynum']);
  586. }
  587. }
  588. $cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
  589. }else{
  590. $typeholiday = $hday->find(array('where' => 'type='.$tv.' and uid='.$cv['sid'].' and UNIX_TIMESTAMP(daytime) between '.$thismonth['start'].' and '.$thismonth['end'],'asArray' => TRUE));
  591. $cidstafflist[$ck][$tv] = 0;
  592. if(!empty($typeholiday)){
  593. foreach($typeholiday as $thk => $thv){
  594. $cidstafflist[$ck][$tv] += floatval($thv['daymsg']);
  595. }
  596. }
  597. $cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
  598. }
  599. }
  600. $cidstafflist[$ck]['countnum'] = floatval($cidstafflist[$ck][4])+floatval($cidstafflist[$ck][5]) != 0 ? floatval($cidstafflist[$ck][4]) + floatval($cidstafflist[$ck][5]) : '';
  601. $cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
  602. }
  603. $stafflist[0]['cidstafflist'] = $cidstafflist;
  604. break;
  605. }
  606. }
  607. }else{
  608. foreach($result as $k => $v){
  609. $stafflist[$k]['categoryname'] = $v['title'];
  610. $stafflist[$k]['count'] = $v['count'];
  611. $cidstafflist = $staff->getStaffByCid($v['cid']);
  612. foreach($cidstafflist as $ck => $cv) {
  613. $hstaffmsg = $hstaff->getOne(array('where' => 'uid=' . $cv['sid'], 'asArray' => TRUE));
  614. $cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
  615. foreach (array(4, 5, 10, 11) as $tk => $tv) {
  616. if ($tv == 11) {
  617. $typeholiday = $holiday->find(array('where' => 'status=1 and type=' . $tv . ' and uid=' . $cv['sid'] . ' and addtime between ' . $thismonth['start'] . ' and ' . $thismonth['end'], 'asArray' => TRUE));
  618. $cidstafflist[$ck][$tv] = 0;
  619. if (!empty($typeholiday)) {
  620. foreach ($typeholiday as $thk => $thv) {
  621. $cidstafflist[$ck][$tv] += floatval($thv['daynum']);
  622. }
  623. }
  624. $cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
  625. } else {
  626. $typeholiday = $hday->find(array('where' => 'type=' . $tv . ' and uid=' . $cv['sid'] . ' and UNIX_TIMESTAMP(daytime) between ' . $thismonth['start'] . ' and ' . $thismonth['end'], 'asArray' => TRUE));
  627. $cidstafflist[$ck][$tv] = 0;
  628. if (!empty($typeholiday)) {
  629. foreach ($typeholiday as $thk => $thv) {
  630. $cidstafflist[$ck][$tv] += floatval($thv['daymsg']);
  631. }
  632. }
  633. $cidstafflist[$ck][$tv] = $cidstafflist[$ck][$tv] != 0 ? $cidstafflist[$ck][$tv] : '';
  634. }
  635. }
  636. $cidstafflist[$ck]['countnum'] = floatval($cidstafflist[$ck][4])+floatval($cidstafflist[$ck][5]) != 0 ? floatval($cidstafflist[$ck][4]) + floatval($cidstafflist[$ck][5]) : '';
  637. $cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
  638. }
  639. $stafflist[$k]['cidstafflist'] = $cidstafflist;
  640. }
  641. }
  642. $data['stafflist'] = $stafflist;
  643. $zongbu = $staff->getStaffByCid(12);
  644. $data['zongbu'] = $zongbu;
  645. $data ['memu'] = 'holiday';
  646. $data ['holidaymenu'] = 'overtime';
  647. $data ['staff'] = $this->staff;
  648. $data['noindexjs'] = 'noindexjs';
  649. $this->render ( "/holiday-overtime", $data );
  650. }
  651. public function addHoliday(){
  652. if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['type']) && is_numeric($_POST['type'])){
  653. Doo::loadModel('holidaystaff');
  654. Doo::loadModel('holiday');
  655. $holiday = new Holiday();
  656. $hstaff = new HStaff();
  657. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$_POST['uid'], 'asArray' => TRUE));
  658. if(($_POST['type'] == 4 || $_POST['type'] == 5) && isset($_POST['daytype']) && is_numeric($_POST['daytype'])){
  659. $day = $_POST['day'];
  660. $hstaff->uid = $_POST['uid'];
  661. $daytype = $_POST['daytype'];
  662. $adddaynum = $daytype != 1 ? 0.5 : 1.0;
  663. $hstaff->addnum = floatval($hstaffmsg['addnum'])+$adddaynum;
  664. $result = $hstaff->update();
  665. if($result){
  666. $dayjson = array('holiday' => [$day.'_'.$daytype]);
  667. $holiday->uid = $_POST['uid'];
  668. $holiday->type = $_POST['type'];
  669. $holiday->dayjson = json_encode($dayjson);
  670. $holiday->daynum = $adddaynum;
  671. $holiday->status = 3;
  672. $holiday->addtime = time();
  673. $holiday->approvetime = time();
  674. $holiday->description = $_POST['description'];
  675. $id = $holiday->insert();
  676. Doo::loadModel('holidayday');
  677. $hday = new HDay();
  678. $hday->hid = $id;
  679. $hday->uid = $_POST['uid'];
  680. $hday->type = $_POST['type'];
  681. $hday->daytime = $day;
  682. $hday->daymsg = $adddaynum;
  683. $hday->insert();
  684. return '/holidayovertime';
  685. }else{
  686. exit('添加到holidaystaff出错');
  687. }
  688. }elseif($_POST['type'] == 13){
  689. $daynum = $_POST['tixian'];
  690. if($daynum > $hstaffmsg['addnum']){
  691. exit('提现天数超过存假天数了');
  692. }else{
  693. $hstaff->uid = $_POST['uid'];
  694. $hstaff->addnum = $hstaffmsg['addnum']-$daynum;
  695. $result = $hstaff->update();
  696. if($result){
  697. $holiday->uid = $_POST['uid'];
  698. $holiday->type = 13;
  699. $holiday->daynum = $daynum;
  700. $holiday->status = 3;
  701. $holiday->addtime = time();
  702. $holiday->approvetime = time();
  703. $holiday->description = $_POST['description'];
  704. $holiday->insert();
  705. return '/holidayovertime';
  706. }else{
  707. exit('添加到holidaystaff出错');
  708. }
  709. }
  710. }
  711. }
  712. exit('添加加值班或提现出错');
  713. }
  714. public function holidayVacation(){
  715. $checkadmin = $this->checkisadmin();
  716. if(!$checkadmin){
  717. exit('非假期管理员无法访问此页面');
  718. }
  719. $data['cansee'] = 1;
  720. //获取办事处列表
  721. Doo::loadModel('staff');
  722. Doo::loadModel('holidaystaff');
  723. $staff = new staff();
  724. $hstaff = new HStaff();
  725. $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';
  726. $query = Doo::db ()->query ( $sql );
  727. $result = $query->fetchAll ();
  728. $data['category'] = $result;
  729. $stafflist = array();
  730. if(isset($this->params['cid']) && is_numeric($this->params['cid'])){
  731. $data['thiscid'] = $this->params['cid'];
  732. foreach($result as $k => $v){
  733. if($this->params['cid'] == $v['cid']){
  734. $stafflist[0]['categoryname'] = $v['title'];
  735. $stafflist[0]['count'] = $v['count'];
  736. $cidstafflist = $staff->getStaffByCid($v['cid']);
  737. foreach($cidstafflist as $ck => $cv){
  738. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$cv['sid'], 'asArray' => TRUE));
  739. $yearnum = $this->CheckAnnualLeave($cv);
  740. $cidstafflist[$ck]['yearnum'] = floatval($yearnum) != 0 ? floatval($yearnum) : '';
  741. $cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
  742. $cidstafflist[$ck]['hunjianum'] = $hstaffmsg['hunjianum'] != 0.0 ? floatval($hstaffmsg['hunjianum']) : '';
  743. $cidstafflist[$ck]['chanjianum'] = $hstaffmsg['chanjianum'] != 0.0 ? floatval($hstaffmsg['chanjianum']) : '';
  744. $cidstafflist[$ck]['sangjianum'] = $hstaffmsg['sangjianum'] != 0.0 ? floatval($hstaffmsg['sangjianum']) : '';
  745. $cidstafflist[$ck]['gongjianum'] = $hstaffmsg['gongjianum'] != 0.0 ? floatval($hstaffmsg['gongjianum']) : '';
  746. $cidstafflist[$ck]['yearround'] = $cv['nature'] == 1 ? $this->getYearRoundtime($hstaffmsg['hadyear'],$cv['hiredate']) : '';
  747. $cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
  748. }
  749. $stafflist[0]['cidstafflist'] = $cidstafflist;
  750. break;
  751. }
  752. }
  753. }else{
  754. foreach($result as $k => $v){
  755. $stafflist[$k]['categoryname'] = $v['title'];
  756. $stafflist[$k]['count'] = $v['count'];
  757. $cidstafflist = $staff->getStaffByCid($v['cid']);
  758. foreach($cidstafflist as $ck => $cv){
  759. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$cv['sid'], 'asArray' => TRUE));
  760. $yearnum = $this->CheckAnnualLeave($cv);
  761. $cidstafflist[$ck]['yearnum'] = floatval($yearnum) != 0 ? floatval($yearnum) : '';
  762. $cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
  763. $cidstafflist[$ck]['hunjianum'] = $hstaffmsg['hunjianum'] != 0.0 ? floatval($hstaffmsg['hunjianum']) : '';
  764. $cidstafflist[$ck]['chanjianum'] = $hstaffmsg['chanjianum'] != 0.0 ? floatval($hstaffmsg['chanjianum']) : '';
  765. $cidstafflist[$ck]['sangjianum'] = $hstaffmsg['sangjianum'] != 0.0 ? floatval($hstaffmsg['sangjianum']) : '';
  766. $cidstafflist[$ck]['gongjianum'] = $hstaffmsg['gongjianum'] != 0.0 ? floatval($hstaffmsg['gongjianum']) : '';
  767. $cidstafflist[$ck]['yearround'] = $cv['nature'] == 1 ? $this->getYearRoundtime($hstaffmsg['hadyear'],$cv['hiredate']) : '';
  768. $cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
  769. }
  770. $stafflist[$k]['cidstafflist'] = $cidstafflist;
  771. }
  772. }
  773. $zongbu = $staff->getStaffByCid(12);
  774. $data['zongbu'] = $zongbu;
  775. $hstaff2 = new HStaff();
  776. $hstaffmsg2 = $hstaff2->getOne(array('select' => 'yearnum', 'where' => 'uid='.$zongbu[0]['sid'], 'asArray' => TRUE));
  777. $data['thisnum'] = floatval($hstaffmsg2['yearnum']);
  778. $data['stafflist'] = $stafflist;
  779. $data ['memu'] = 'holiday';
  780. $data ['holidaymenu'] = 'vacation';
  781. $data ['staff'] = $this->staff;
  782. $data['noindexjs'] = 'noindexjs';
  783. $this->render ( "/holiday-vacation", $data );
  784. }
  785. public function setStaffHoliday(){
  786. if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['typeholiday']) && isset($_POST['addnum'])){
  787. Doo::loadModel('holidaystaff');
  788. $hstaff = new HStaff();
  789. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$_POST['uid'], 'asArray' => TRUE));
  790. $hstaff->uid = $_POST['uid'];
  791. $type = '';
  792. switch($_POST['typeholiday']){
  793. case 'yearnum':
  794. $hstaff->yearnum = $hstaffmsg['yearnum']+$_POST['addnum'];
  795. $type = 15;
  796. break;
  797. case 'hunjianum':
  798. $hstaff->hunjianum = $hstaffmsg['hunjianum']+$_POST['addnum'];
  799. $type = 16;
  800. break;
  801. case 'chanjianum':
  802. $hstaff->chanjianum = $hstaffmsg['chanjianum']+$_POST['addnum'];
  803. $type = 17;
  804. break;
  805. case 'sangjianum':
  806. $hstaff->sangjianum = $hstaffmsg['sangjianum']+$_POST['addnum'];
  807. $type = 18;
  808. break;
  809. case 'gongjianum':
  810. $hstaff->gongjianum = $hstaffmsg['gongjianum']+$_POST['addnum'];
  811. $type = 19;
  812. break;
  813. }
  814. $hstaff->update();
  815. Doo::loadModel('holiday');
  816. $holiday = new Holiday();
  817. $holiday->uid = $_POST['uid'];
  818. $holiday->type = $type;
  819. $holiday->daynum = $_POST['addnum'];
  820. $holiday->status = 3;
  821. $holiday->addtime = time();
  822. $holiday->approvetime = time();
  823. $holiday->description = $_POST['description'];
  824. $holiday->insert();
  825. return '/holidayvacation';
  826. }else{
  827. exit('增加出错');
  828. }
  829. }
  830. public function getStaffCategory(){
  831. if(isset($_POST['cid']) && is_numeric($_POST['cid'])){
  832. Doo::loadModel('staff');
  833. $staff = new staff();
  834. $stafflist = $staff->getStaffByCid($_POST['cid']);
  835. Doo::loadModel('holidaystaff');
  836. $hstaff = new HStaff();
  837. $hstaffmsg = $hstaff->getOne(array('select' => 'yearnum', 'where' => 'uid='.$stafflist[0]['sid'], 'asArray' => TRUE));
  838. exit(json_encode(array('code' => 200, 'stafflist' => $stafflist, 'thisnum' => floatval($hstaffmsg['yearnum']))));
  839. }
  840. exit(json_encode(array('code' => 400)));
  841. }
  842. public function getHolidayStaff(){
  843. if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['type'])){
  844. Doo::loadModel('holidaystaff');
  845. $hstaff = new HStaff();
  846. $staffmsg = $hstaff->getOne(array('select' => $_POST['type'], 'where' => 'uid='.$_POST['uid'], 'asArray' => TRUE));
  847. exit(json_encode(array('code' => 200, 'thisnum' => floatval($staffmsg[$_POST['type']]))));
  848. }
  849. exit(json_encode(array('code' => 400)));
  850. }
  851. public function holidayAttendance(){
  852. $checkadmin = $this->checkisadmin();
  853. if($checkadmin){
  854. $data['cansee'] = 1;
  855. }
  856. Doo::loadModel('holidayday');
  857. Doo::loadModel('holiday');
  858. Doo::loadModel('holidaystaff');
  859. Doo::loadModel('holidaytype');
  860. Doo::loadModel('staff');
  861. $hday = new HDay();
  862. $holiday = new Holiday();
  863. $hstaff = new HStaff();
  864. $type = new HType();
  865. $staff = new staff();
  866. $sqlstr = '';
  867. $pagestr = '';
  868. if(isset($this->params['day'])){
  869. $today = $this->params['day'];
  870. $todayarr = explode('~',$today);
  871. if(count($todayarr) != 2){
  872. $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].'")))';
  873. }else{
  874. $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].'"))))';
  875. }
  876. }else{
  877. $today = date('Y-m-d',time());
  878. $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.'")))';
  879. }
  880. $pagestr .= '/day/'.$today;
  881. $data['today'] = $today;
  882. if(isset($this->params['cate'])){
  883. $cate = 'headquarters';
  884. $pagestr .= '/cate/'.$cate;
  885. $data['cate'] = 1;
  886. $sqlstr .= ' and uid in (select sid from `CLD_staff` where cid=12 and departmentID=0)';
  887. }else{
  888. $data['cate'] = 0;
  889. }
  890. $data['typeurl'] = $pagestr;
  891. if(isset($this->params['type'])){
  892. $data['type'] = $this->params['type'];
  893. $pagestr .= '/type/'.$this->params['type'];
  894. if($this->params['type'] == 4 ){//加班、值班
  895. $sqlstr .= ' and (type=4 or type=5)';
  896. }elseif($this->params['type'] == 6){//其他长假
  897. $sqlstr .= ' and type in(3,6,7,8,9)';
  898. }else{
  899. $sqlstr .= ' and type='.$this->params['type'];
  900. }
  901. }else{
  902. $data['type'] = '';
  903. }
  904. Doo::loadHelper('DooPager');
  905. $totalArchive = $holiday->count(array('where' => 'status=1'.$sqlstr, 'asArray' => TRUE));
  906. $pager = new DooPager(Doo::conf()->APP_URL . "holidayattendance".$pagestr."/page", $totalArchive, 10, 10);
  907. if (isset($this->params['pindex']))
  908. $pager->paginate(intval($this->params['pindex']));
  909. else
  910. $pager->paginate(1);
  911. if ($pager->limit != ' -10,10')
  912. $holidaymsg = $holiday->find(array('where' => 'status=1'.$sqlstr, 'limit' => $pager->limit, 'asArray' => TRUE));
  913. if(isset($holidaymsg) && !empty($holidaymsg)){
  914. foreach($holidaymsg as $k => $v){
  915. $staffmsg = $staff->getOne(array('where' => 'sid=?', 'param' => array($v['uid']), 'asArray' => TRUE));
  916. $holidaymsg[$k]['username'] = $staffmsg['username'];
  917. $holidaymsg[$k]['category'] = $staffmsg['cid'] == 12 && $staffmsg['departmentID'] == 1 ? '总部(造价研究中心)' : $staffmsg['category'];
  918. $holidaymsg[$k]['typename'] = $type->getTypeNamebyid($v['type']);
  919. $holidaymsg[$k]['daynum'] = floatval($v['daynum']);
  920. $holidaymsg[$k]['approvetime'] = !empty($v['approvetime']) ? date('Y-m-d H:i:s',$v['approvetime']) : '';
  921. $msg = '';
  922. if(in_array($v['type'],array(1,2,3,4,5,10,11,12))){
  923. $dayjson = json_decode($v['dayjson']);
  924. if($v['type'] != 11){
  925. $holidaydays = $this->geyDayMsg($dayjson->holiday);
  926. foreach($holidaydays as $hk => $hv){
  927. $msg .= $hv['daytime'].' '.$hv['daymsg'].',';
  928. }
  929. $msg = substr($msg,0,strlen($msg)-1);
  930. }else{
  931. $msg .= '休假时间:';
  932. $holidaydays = $this->geyDayMsg($dayjson->holiday);
  933. foreach($holidaydays as $hk => $hv){
  934. $msg .= $hv['daytime'].' '.$hv['daymsg'].',';
  935. }
  936. $msg = substr($msg,0,strlen($msg)-1);
  937. $msg .= '<br>加班时间:';
  938. $overtimedays = $this->geyDayMsg($dayjson->overtime);
  939. foreach($overtimedays as $ok => $ov){
  940. $msg .= $ov['daytime'].' '.$ov['daymsg'].',';
  941. }
  942. $msg = substr($msg,0,strlen($msg)-1);
  943. }
  944. }elseif(in_array($v['type'],array(6,7,8,9))){
  945. $msg .= $v['starttime']. ' 至 '.$v['endtime'];
  946. }elseif(in_array($v['type'],array(13,14,15,16,17,18,19))){
  947. $msg .= date('Y-m-d H:i:s',$v['addtime']);
  948. }
  949. $holidaymsg[$k]['daymsg'] = $msg;
  950. }
  951. $data['holidaylist'] = $holidaymsg;
  952. }
  953. $data['pager'] = $pager->output;
  954. $data ['memu'] = 'holiday';
  955. $data ['holidaymenu'] = 'borad';
  956. $data ['staff'] = $this->staff;
  957. $data['noindexjs'] = 'noindexjs';
  958. $this->render ( "/holiday-allList2", $data );
  959. }
  960. private function geyDayMsg($dayjson){
  961. $holidayday = array();
  962. foreach($dayjson as $dk => $dv){
  963. $oneday = explode('_',$dv);
  964. if($oneday[1] != 0){
  965. $holidayday[$dk]['daytime'] = $oneday[0];
  966. $holidayday[$dk]['daymsg'] = $oneday[1] == 1 ? '' : ($oneday[1] == 2 ? '上午' : '下午');
  967. }
  968. }
  969. return $holidayday;
  970. }
  971. //获取某日期的月初月末时间戳
  972. private function getMonthTime($time){
  973. $starttime = strtotime(date('Y-m-01',strtotime($time)));
  974. $endtime = strtotime("+1 months", strtotime(date('Y-m-01',strtotime($time))))-1;
  975. return array('start' => $starttime, 'end' => $endtime);
  976. }
  977. //获取本年的每个月的时间戳
  978. private function getYearMonthTime($thisyear){
  979. $monthdata = array();
  980. for($i = 0; $i < 12; $i++){
  981. $j = $i+1;
  982. $j = $j < 10 ? '0'.$j : $j;
  983. $nowmonth = $thisyear.'-'.$j.'-01';
  984. $monthdata[$i]['starttime'] = strtotime($nowmonth);
  985. $monthdata[$i]['endtime'] = strtotime("+1 months", strtotime($nowmonth))-1;
  986. }
  987. return $monthdata;
  988. }
  989. //获取本年当事人的年假周期
  990. private function getYearRoundtime($hadyear,$hiredate){
  991. $month = date('m', strtotime($hiredate));
  992. $date = date('d', strtotime($hiredate));
  993. $monthday = intval($month).'月'.intval($date).'日';
  994. $year = date('Y',time());
  995. //每隔4年加一天
  996. if(date('Y',(strtotime($hiredate)+(86400*365*$hadyear)+intval($hadyear/4)*86400)) < $year){
  997. $lastyear = intval($year)-1;
  998. return intval($lastyear).'年'.$monthday.'~'.intval($year).'年'.$monthday;
  999. }else{
  1000. $nextyear = intval($year)+1;
  1001. return intval($year).'年'.$monthday.'~'.intval($nextyear).'年'.$monthday;
  1002. }
  1003. }
  1004. private function checkisadmin(){
  1005. Doo::loadModel('holidayadmin');
  1006. $admin = new HAdmin();
  1007. $adminmsg = $admin->getOne(array('where' => 'uid='.$this->staff[0]['sid'], 'asArray' => TRUE));
  1008. if(!empty($adminmsg)){
  1009. return TRUE;
  1010. }else{
  1011. return FALSE;
  1012. }
  1013. }
  1014. //检查年假是否过期并更新年假
  1015. private function CheckAnnualLeave($staff){
  1016. if($staff['nature'] == 2){
  1017. return 0;
  1018. }
  1019. $hiredate = $staff['hiredate'];
  1020. if($hiredate == ''){
  1021. return 0;
  1022. }
  1023. Doo::loadModel('holidaystaff');
  1024. $hstaff = new HStaff();
  1025. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$staff['sid'],'asArray' => TRUE));
  1026. $hadyear = intval((time()-strtotime($hiredate))/(86400*365));
  1027. if($hadyear != $hstaffmsg['hadyear']){
  1028. $hstaff->uid = $staff['sid'];
  1029. $hstaff->hadyear = $hadyear;
  1030. $hstaff->yearnum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
  1031. $hstaff->update();
  1032. $daynum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
  1033. }else{
  1034. $daynum = $hstaffmsg['yearnum'];
  1035. }
  1036. return $daynum;
  1037. }
  1038. }
  1039. ?>