HolidayController.php 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  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){
  659. $day = $_POST['day'];
  660. $hstaff->uid = $_POST['uid'];
  661. $hstaff->addnum = floatval($hstaffmsg['addnum'])+1;
  662. $result = $hstaff->update();
  663. if($result){
  664. $dayjson = array('holiday' => [$day.'_1']);
  665. $holiday->uid = $_POST['uid'];
  666. $holiday->type = $_POST['type'];
  667. $holiday->dayjson = json_encode($dayjson);
  668. $holiday->daynum = 1.0;
  669. $holiday->status = 3;
  670. $holiday->addtime = time();
  671. $holiday->approvetime = time();
  672. $holiday->description = $_POST['description'];
  673. $id = $holiday->insert();
  674. Doo::loadModel('holidayday');
  675. $hday = new HDay();
  676. $hday->hid = $id;
  677. $hday->uid = $_POST['uid'];
  678. $hday->type = $_POST['type'];
  679. $hday->daytime = $day;
  680. $hday->daymsg = 1.0;
  681. $hday->insert();
  682. return '/holidayovertime';
  683. }else{
  684. exit('添加到holidaystaff出错');
  685. }
  686. }elseif($_POST['type'] == 13){
  687. $daynum = $_POST['tixian'];
  688. if($daynum > $hstaffmsg['addnum']){
  689. exit('提现天数超过存假天数了');
  690. }else{
  691. $hstaff->uid = $_POST['uid'];
  692. $hstaff->addnum = $hstaffmsg['addnum']-$daynum;
  693. $result = $hstaff->update();
  694. if($result){
  695. $holiday->uid = $_POST['uid'];
  696. $holiday->type = 13;
  697. $holiday->daynum = $daynum;
  698. $holiday->status = 3;
  699. $holiday->addtime = time();
  700. $holiday->approvetime = time();
  701. $holiday->description = $_POST['description'];
  702. $holiday->insert();
  703. return '/holidayovertime';
  704. }else{
  705. exit('添加到holidaystaff出错');
  706. }
  707. }
  708. }
  709. }
  710. exit('添加加值班或提现出错');
  711. }
  712. public function holidayVacation(){
  713. $checkadmin = $this->checkisadmin();
  714. if(!$checkadmin){
  715. exit('非假期管理员无法访问此页面');
  716. }
  717. $data['cansee'] = 1;
  718. //获取办事处列表
  719. Doo::loadModel('staff');
  720. Doo::loadModel('holidaystaff');
  721. $staff = new staff();
  722. $hstaff = new HStaff();
  723. $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';
  724. $query = Doo::db ()->query ( $sql );
  725. $result = $query->fetchAll ();
  726. $data['category'] = $result;
  727. $stafflist = array();
  728. if(isset($this->params['cid']) && is_numeric($this->params['cid'])){
  729. $data['thiscid'] = $this->params['cid'];
  730. foreach($result as $k => $v){
  731. if($this->params['cid'] == $v['cid']){
  732. $stafflist[0]['categoryname'] = $v['title'];
  733. $stafflist[0]['count'] = $v['count'];
  734. $cidstafflist = $staff->getStaffByCid($v['cid']);
  735. foreach($cidstafflist as $ck => $cv){
  736. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$cv['sid'], 'asArray' => TRUE));
  737. $yearnum = $this->CheckAnnualLeave($cv);
  738. $cidstafflist[$ck]['yearnum'] = floatval($yearnum) != 0 ? floatval($yearnum) : '';
  739. $cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
  740. $cidstafflist[$ck]['hunjianum'] = $hstaffmsg['hunjianum'] != 0.0 ? floatval($hstaffmsg['hunjianum']) : '';
  741. $cidstafflist[$ck]['chanjianum'] = $hstaffmsg['chanjianum'] != 0.0 ? floatval($hstaffmsg['chanjianum']) : '';
  742. $cidstafflist[$ck]['sangjianum'] = $hstaffmsg['sangjianum'] != 0.0 ? floatval($hstaffmsg['sangjianum']) : '';
  743. $cidstafflist[$ck]['gongjianum'] = $hstaffmsg['gongjianum'] != 0.0 ? floatval($hstaffmsg['gongjianum']) : '';
  744. $cidstafflist[$ck]['yearround'] = $cv['nature'] == 1 ? $this->getYearRoundtime($hstaffmsg['hadyear'],$cv['hiredate']) : '';
  745. $cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
  746. }
  747. $stafflist[0]['cidstafflist'] = $cidstafflist;
  748. break;
  749. }
  750. }
  751. }else{
  752. foreach($result as $k => $v){
  753. $stafflist[$k]['categoryname'] = $v['title'];
  754. $stafflist[$k]['count'] = $v['count'];
  755. $cidstafflist = $staff->getStaffByCid($v['cid']);
  756. foreach($cidstafflist as $ck => $cv){
  757. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$cv['sid'], 'asArray' => TRUE));
  758. $yearnum = $this->CheckAnnualLeave($cv);
  759. $cidstafflist[$ck]['yearnum'] = floatval($yearnum) != 0 ? floatval($yearnum) : '';
  760. $cidstafflist[$ck]['addnum'] = $hstaffmsg['addnum'] != 0.0 ? floatval($hstaffmsg['addnum']) : '';
  761. $cidstafflist[$ck]['hunjianum'] = $hstaffmsg['hunjianum'] != 0.0 ? floatval($hstaffmsg['hunjianum']) : '';
  762. $cidstafflist[$ck]['chanjianum'] = $hstaffmsg['chanjianum'] != 0.0 ? floatval($hstaffmsg['chanjianum']) : '';
  763. $cidstafflist[$ck]['sangjianum'] = $hstaffmsg['sangjianum'] != 0.0 ? floatval($hstaffmsg['sangjianum']) : '';
  764. $cidstafflist[$ck]['gongjianum'] = $hstaffmsg['gongjianum'] != 0.0 ? floatval($hstaffmsg['gongjianum']) : '';
  765. $cidstafflist[$ck]['yearround'] = $cv['nature'] == 1 ? $this->getYearRoundtime($hstaffmsg['hadyear'],$cv['hiredate']) : '';
  766. $cidstafflist[$ck]['first'] = $ck == 0 ? 1 : ''; // 是否第一个
  767. }
  768. $stafflist[$k]['cidstafflist'] = $cidstafflist;
  769. }
  770. }
  771. $zongbu = $staff->getStaffByCid(12);
  772. $data['zongbu'] = $zongbu;
  773. $hstaff2 = new HStaff();
  774. $hstaffmsg2 = $hstaff2->getOne(array('select' => 'yearnum', 'where' => 'uid='.$zongbu[0]['sid'], 'asArray' => TRUE));
  775. $data['thisnum'] = floatval($hstaffmsg2['yearnum']);
  776. $data['stafflist'] = $stafflist;
  777. $data ['memu'] = 'holiday';
  778. $data ['holidaymenu'] = 'vacation';
  779. $data ['staff'] = $this->staff;
  780. $data['noindexjs'] = 'noindexjs';
  781. $this->render ( "/holiday-vacation", $data );
  782. }
  783. public function setStaffHoliday(){
  784. if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['typeholiday']) && isset($_POST['addnum'])){
  785. Doo::loadModel('holidaystaff');
  786. $hstaff = new HStaff();
  787. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$_POST['uid'], 'asArray' => TRUE));
  788. $hstaff->uid = $_POST['uid'];
  789. $type = '';
  790. switch($_POST['typeholiday']){
  791. case 'yearnum':
  792. $hstaff->yearnum = $hstaffmsg['yearnum']+$_POST['addnum'];
  793. $type = 15;
  794. break;
  795. case 'hunjianum':
  796. $hstaff->hunjianum = $hstaffmsg['hunjianum']+$_POST['addnum'];
  797. $type = 16;
  798. break;
  799. case 'chanjianum':
  800. $hstaff->chanjianum = $hstaffmsg['chanjianum']+$_POST['addnum'];
  801. $type = 17;
  802. break;
  803. case 'sangjianum':
  804. $hstaff->sangjianum = $hstaffmsg['sangjianum']+$_POST['addnum'];
  805. $type = 18;
  806. break;
  807. case 'gongjianum':
  808. $hstaff->gongjianum = $hstaffmsg['gongjianum']+$_POST['addnum'];
  809. $type = 19;
  810. break;
  811. }
  812. $hstaff->update();
  813. Doo::loadModel('holiday');
  814. $holiday = new Holiday();
  815. $holiday->uid = $_POST['uid'];
  816. $holiday->type = $type;
  817. $holiday->daynum = $_POST['addnum'];
  818. $holiday->status = 3;
  819. $holiday->addtime = time();
  820. $holiday->approvetime = time();
  821. $holiday->description = $_POST['description'];
  822. $holiday->insert();
  823. return '/holidayvacation';
  824. }else{
  825. exit('增加出错');
  826. }
  827. }
  828. public function getStaffCategory(){
  829. if(isset($_POST['cid']) && is_numeric($_POST['cid'])){
  830. Doo::loadModel('staff');
  831. $staff = new staff();
  832. $stafflist = $staff->getStaffByCid($_POST['cid']);
  833. Doo::loadModel('holidaystaff');
  834. $hstaff = new HStaff();
  835. $hstaffmsg = $hstaff->getOne(array('select' => 'yearnum', 'where' => 'uid='.$stafflist[0]['sid'], 'asArray' => TRUE));
  836. exit(json_encode(array('code' => 200, 'stafflist' => $stafflist, 'thisnum' => floatval($hstaffmsg['yearnum']))));
  837. }
  838. exit(json_encode(array('code' => 400)));
  839. }
  840. public function getHolidayStaff(){
  841. if(isset($_POST['uid']) && is_numeric($_POST['uid']) && isset($_POST['type'])){
  842. Doo::loadModel('holidaystaff');
  843. $hstaff = new HStaff();
  844. $staffmsg = $hstaff->getOne(array('select' => $_POST['type'], 'where' => 'uid='.$_POST['uid'], 'asArray' => TRUE));
  845. exit(json_encode(array('code' => 200, 'thisnum' => floatval($staffmsg[$_POST['type']]))));
  846. }
  847. exit(json_encode(array('code' => 400)));
  848. }
  849. public function holidayAttendance(){
  850. $checkadmin = $this->checkisadmin();
  851. if($checkadmin){
  852. $data['cansee'] = 1;
  853. }
  854. Doo::loadModel('holidayday');
  855. Doo::loadModel('holiday');
  856. Doo::loadModel('holidaystaff');
  857. Doo::loadModel('holidaytype');
  858. Doo::loadModel('staff');
  859. $hday = new HDay();
  860. $holiday = new Holiday();
  861. $hstaff = new HStaff();
  862. $type = new HType();
  863. $staff = new staff();
  864. $sqlstr = '';
  865. $pagestr = '';
  866. if(isset($this->params['day'])){
  867. $today = $this->params['day'];
  868. $todayarr = explode('~',$today);
  869. if(count($todayarr) != 2){
  870. $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].'")))';
  871. }else{
  872. $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].'"))))';
  873. }
  874. }else{
  875. $today = date('Y-m-d',time());
  876. $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.'")))';
  877. }
  878. $pagestr .= '/day/'.$today;
  879. $data['today'] = $today;
  880. if(isset($this->params['cate'])){
  881. $cate = 'headquarters';
  882. $pagestr .= '/cate/'.$cate;
  883. $data['cate'] = 1;
  884. $sqlstr .= ' and uid in (select sid from `CLD_staff` where cid=12 and departmentID=0)';
  885. }else{
  886. $data['cate'] = 0;
  887. }
  888. $data['typeurl'] = $pagestr;
  889. if(isset($this->params['type'])){
  890. $data['type'] = $this->params['type'];
  891. $pagestr .= '/type/'.$this->params['type'];
  892. if($this->params['type'] == 4 ){//加班、值班
  893. $sqlstr .= ' and (type=4 or type=5)';
  894. }elseif($this->params['type'] == 6){//其他长假
  895. $sqlstr .= ' and type in(3,6,7,8,9)';
  896. }else{
  897. $sqlstr .= ' and type='.$this->params['type'];
  898. }
  899. }else{
  900. $data['type'] = '';
  901. }
  902. Doo::loadHelper('DooPager');
  903. $totalArchive = $holiday->count(array('where' => 'status=1'.$sqlstr, 'asArray' => TRUE));
  904. $pager = new DooPager(Doo::conf()->APP_URL . "holidayattendance".$pagestr."/page", $totalArchive, 10, 10);
  905. if (isset($this->params['pindex']))
  906. $pager->paginate(intval($this->params['pindex']));
  907. else
  908. $pager->paginate(1);
  909. if ($pager->limit != ' -10,10')
  910. $holidaymsg = $holiday->find(array('where' => 'status=1'.$sqlstr, 'limit' => $pager->limit, 'asArray' => TRUE));
  911. if(isset($holidaymsg) && !empty($holidaymsg)){
  912. foreach($holidaymsg as $k => $v){
  913. $staffmsg = $staff->getOne(array('where' => 'sid=?', 'param' => array($v['uid']), 'asArray' => TRUE));
  914. $holidaymsg[$k]['username'] = $staffmsg['username'];
  915. $holidaymsg[$k]['category'] = $staffmsg['cid'] == 12 && $staffmsg['departmentID'] == 1 ? '总部(造价研究中心)' : $staffmsg['category'];
  916. $holidaymsg[$k]['typename'] = $type->getTypeNamebyid($v['type']);
  917. $holidaymsg[$k]['daynum'] = floatval($v['daynum']);
  918. $holidaymsg[$k]['approvetime'] = !empty($v['approvetime']) ? date('Y-m-d H:i:s',$v['approvetime']) : '';
  919. $msg = '';
  920. if(in_array($v['type'],array(1,2,3,4,5,10,11,12))){
  921. $dayjson = json_decode($v['dayjson']);
  922. if($v['type'] != 11){
  923. $holidaydays = $this->geyDayMsg($dayjson->holiday);
  924. foreach($holidaydays as $hk => $hv){
  925. $msg .= $hv['daytime'].' '.$hv['daymsg'].',';
  926. }
  927. $msg = substr($msg,0,strlen($msg)-1);
  928. }else{
  929. $msg .= '休假时间:';
  930. $holidaydays = $this->geyDayMsg($dayjson->holiday);
  931. foreach($holidaydays as $hk => $hv){
  932. $msg .= $hv['daytime'].' '.$hv['daymsg'].',';
  933. }
  934. $msg = substr($msg,0,strlen($msg)-1);
  935. $msg .= '<br>加班时间:';
  936. $overtimedays = $this->geyDayMsg($dayjson->overtime);
  937. foreach($overtimedays as $ok => $ov){
  938. $msg .= $ov['daytime'].' '.$ov['daymsg'].',';
  939. }
  940. $msg = substr($msg,0,strlen($msg)-1);
  941. }
  942. }elseif(in_array($v['type'],array(6,7,8,9))){
  943. $msg .= $v['starttime']. ' 至 '.$v['endtime'];
  944. }elseif(in_array($v['type'],array(13,14,15,16,17,18,19))){
  945. $msg .= date('Y-m-d H:i:s',$v['addtime']);
  946. }
  947. $holidaymsg[$k]['daymsg'] = $msg;
  948. }
  949. $data['holidaylist'] = $holidaymsg;
  950. }
  951. $data['pager'] = $pager->output;
  952. $data ['memu'] = 'holiday';
  953. $data ['holidaymenu'] = 'borad';
  954. $data ['staff'] = $this->staff;
  955. $data['noindexjs'] = 'noindexjs';
  956. $this->render ( "/holiday-allList2", $data );
  957. }
  958. private function geyDayMsg($dayjson){
  959. $holidayday = array();
  960. foreach($dayjson as $dk => $dv){
  961. $oneday = explode('_',$dv);
  962. if($oneday[1] != 0){
  963. $holidayday[$dk]['daytime'] = $oneday[0];
  964. $holidayday[$dk]['daymsg'] = $oneday[1] == 1 ? '' : ($oneday[1] == 2 ? '上午' : '下午');
  965. }
  966. }
  967. return $holidayday;
  968. }
  969. //获取某日期的月初月末时间戳
  970. private function getMonthTime($time){
  971. $starttime = strtotime(date('Y-m-01',strtotime($time)));
  972. $endtime = strtotime("+1 months", strtotime(date('Y-m-01',strtotime($time))))-1;
  973. return array('start' => $starttime, 'end' => $endtime);
  974. }
  975. //获取本年的每个月的时间戳
  976. private function getYearMonthTime($thisyear){
  977. $monthdata = array();
  978. for($i = 0; $i < 12; $i++){
  979. $j = $i+1;
  980. $j = $j < 10 ? '0'.$j : $j;
  981. $nowmonth = $thisyear.'-'.$j.'-01';
  982. $monthdata[$i]['starttime'] = strtotime($nowmonth);
  983. $monthdata[$i]['endtime'] = strtotime("+1 months", strtotime($nowmonth))-1;
  984. }
  985. return $monthdata;
  986. }
  987. //获取本年当事人的年假周期
  988. private function getYearRoundtime($hadyear,$hiredate){
  989. $month = date('m', strtotime($hiredate));
  990. $date = date('d', strtotime($hiredate));
  991. $monthday = intval($month).'月'.intval($date).'日';
  992. $year = date('Y',time());
  993. //每隔4年加一天
  994. if(date('Y',(strtotime($hiredate)+(86400*365*$hadyear)+intval($hadyear/4)*86400)) < $year){
  995. $lastyear = intval($year)-1;
  996. return intval($lastyear).'年'.$monthday.'~'.intval($year).'年'.$monthday;
  997. }else{
  998. $nextyear = intval($year)+1;
  999. return intval($year).'年'.$monthday.'~'.intval($nextyear).'年'.$monthday;
  1000. }
  1001. }
  1002. private function checkisadmin(){
  1003. Doo::loadModel('holidayadmin');
  1004. $admin = new HAdmin();
  1005. $adminmsg = $admin->getOne(array('where' => 'uid='.$this->staff[0]['sid'], 'asArray' => TRUE));
  1006. if(!empty($adminmsg)){
  1007. return TRUE;
  1008. }else{
  1009. return FALSE;
  1010. }
  1011. }
  1012. //检查年假是否过期并更新年假
  1013. private function CheckAnnualLeave($staff){
  1014. if($staff['nature'] == 2){
  1015. return 0;
  1016. }
  1017. $hiredate = $staff['hiredate'];
  1018. if($hiredate == ''){
  1019. return 0;
  1020. }
  1021. Doo::loadModel('holidaystaff');
  1022. $hstaff = new HStaff();
  1023. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$staff['sid'],'asArray' => TRUE));
  1024. $hadyear = intval((time()-strtotime($hiredate))/(86400*365));
  1025. if($hadyear != $hstaffmsg['hadyear']){
  1026. $hstaff->uid = $staff['sid'];
  1027. $hstaff->hadyear = $hadyear;
  1028. $hstaff->yearnum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
  1029. $hstaff->update();
  1030. $daynum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
  1031. }else{
  1032. $daynum = $hstaffmsg['yearnum'];
  1033. }
  1034. return $daynum;
  1035. }
  1036. }
  1037. ?>