HolidayController.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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. $data ['memu'] = 'holiday';
  855. $data ['holidaymenu'] = 'borad';
  856. $data ['staff'] = $this->staff;
  857. $data['noindexjs'] = 'noindexjs';
  858. $this->render ( "/holiday-allList2", $data );
  859. }
  860. private function geyDayMsg($dayjson){
  861. $holidayday = array();
  862. foreach($dayjson as $dk => $dv){
  863. $oneday = explode('_',$dv);
  864. if($oneday[1] != 0){
  865. $holidayday[$dk]['daytime'] = $oneday[0];
  866. $holidayday[$dk]['daymsg'] = $oneday[1] == 1 ? '' : ($oneday[1] == 2 ? '上午' : '下午');
  867. }
  868. }
  869. return $holidayday;
  870. }
  871. //获取某日期的月初月末时间戳
  872. private function getMonthTime($time){
  873. $starttime = strtotime(date('Y-m-01',strtotime($time)));
  874. $endtime = strtotime("+1 months", strtotime(date('Y-m-01',strtotime($time))))-1;
  875. return array('start' => $starttime, 'end' => $endtime);
  876. }
  877. //获取本年的每个月的时间戳
  878. private function getYearMonthTime($thisyear){
  879. $monthdata = array();
  880. for($i = 0; $i < 12; $i++){
  881. $j = $i+1;
  882. $j = $j < 10 ? '0'.$j : $j;
  883. $nowmonth = $thisyear.'-'.$j.'-01';
  884. $monthdata[$i]['starttime'] = strtotime($nowmonth);
  885. $monthdata[$i]['endtime'] = strtotime("+1 months", strtotime($nowmonth))-1;
  886. }
  887. return $monthdata;
  888. }
  889. //获取本年当事人的年假周期
  890. private function getYearRoundtime($hadyear,$hiredate){
  891. $month = date('m', strtotime($hiredate));
  892. $date = date('d', strtotime($hiredate));
  893. $monthday = intval($month).'月'.intval($date).'日';
  894. $year = date('Y',time());
  895. //每隔4年加一天
  896. if(date('Y',(strtotime($hiredate)+(86400*365*$hadyear)+intval($hadyear/4)*86400)) < $year){
  897. $lastyear = intval($year)-1;
  898. return intval($lastyear).'年'.$monthday.'~'.intval($year).'年'.$monthday;
  899. }else{
  900. $nextyear = intval($year)+1;
  901. return intval($year).'年'.$monthday.'~'.intval($nextyear).'年'.$monthday;
  902. }
  903. }
  904. private function checkisadmin(){
  905. Doo::loadModel('holidayadmin');
  906. $admin = new HAdmin();
  907. $adminmsg = $admin->getOne(array('where' => 'uid='.$this->staff[0]['sid'], 'asArray' => TRUE));
  908. if(!empty($adminmsg)){
  909. return TRUE;
  910. }else{
  911. return FALSE;
  912. }
  913. }
  914. //检查年假是否过期并更新年假
  915. private function CheckAnnualLeave($staff){
  916. if($staff['nature'] == 2){
  917. return 0;
  918. }
  919. $hiredate = $staff['hiredate'];
  920. if($hiredate == ''){
  921. return 0;
  922. }
  923. Doo::loadModel('holidaystaff');
  924. $hstaff = new HStaff();
  925. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$staff['sid'],'asArray' => TRUE));
  926. $hadyear = intval((time()-strtotime($hiredate))/(86400*365));
  927. if($hadyear != $hstaffmsg['hadyear']){
  928. $hstaff->uid = $staff['sid'];
  929. $hstaff->hadyear = $hadyear;
  930. $hstaff->yearnum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
  931. $hstaff->update();
  932. $daynum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
  933. }else{
  934. $daynum = $hstaffmsg['yearnum'];
  935. }
  936. return $daynum;
  937. }
  938. }
  939. ?>