HumanResourceController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class HumanResourceController extends DooController {
  6. public function beforeRun($resource, $action) {
  7. }
  8. function __construct() {
  9. if (isset ( $_COOKIE ["staff"] )) {
  10. if (! empty ( $_COOKIE ["staff"] )) {
  11. Doo::loadModel ( 'staff' );
  12. $staff = new staff ();
  13. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  14. return "/";
  15. }
  16. }
  17. Doo::loadCore ( 'uri/DooUriRouter' );
  18. $router = new DooUriRouter ();
  19. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  20. if ($routeRs ['1'] != "login") {
  21. header ( 'Content-Type:text/html;charset=utf-8' );
  22. @header ( "Location: /login" );
  23. }
  24. }
  25. /**
  26. * 员工信息
  27. */
  28. function hrEmployee(){
  29. $data ['staff'] = $this->staff;
  30. $birArray = explode ( '-', $this->staff [0] ['birthday'] );
  31. $data ['year'] = $birArray [0];
  32. $year = date ( 'Y' );
  33. $yearHtml = "";
  34. for(; $year >= 1900; $year --) {
  35. $yearHtml .= '<option ';
  36. if ($data ['year'] == $year)
  37. $yearHtml .= 'selected';
  38. $yearHtml .= ' value="' . $year . '">' . $year . '</option>';
  39. }
  40. $data ['yearHtml'] = $yearHtml;
  41. $data ['month'] = 01;
  42. $data ['day'] = 01;
  43. if (isset ( $birArray [1] )) {
  44. $data ['month'] = $birArray [1];
  45. $data ['day'] = $birArray [2];
  46. }
  47. $data ['msg'] = urldecode ( $this->params ['msg'] );
  48. Doo::loadModel ( 'staff' );
  49. $staff = new staff ();
  50. $stafflist=$staff->getStaff (true);
  51. //生成工号
  52. $jobNumber=$this->createJobNumber();
  53. //获得办事和部门
  54. $this->data ['jobNumber'] = $jobNumber;
  55. $this->data ['stafflist'] = $stafflist;
  56. $this->data ['memu'] = "HumanResource";
  57. $this->data ['hrMemu'] = "hrEmployeeInfo";
  58. $this->render ( "/humanResource/hrEmployee", $this->data );
  59. }
  60. function staffAdd(){
  61. echo 'ddd';
  62. die;
  63. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  64. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 2;
  65. $cid_did = $this->get_args ( 'cid_did' ) ? $this->get_args ( 'cid_did' ) : '';
  66. $position = $this->get_args ( 'position' ) ? $this->get_args ( 'position' ) : '';
  67. $hiredate = $this->get_args ( 'hiredate' ) ? $this->get_args ( 'hiredate' ) : '';
  68. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : '';
  69. $baseWage = $this->get_args ( 'baseWage' ) ? $this->get_args ( 'baseWage' ) : 0;
  70. $postWage = $this->get_args ( 'postWage' ) ? $this->get_args ( 'postWage' ) : 0;
  71. $achievementBonus = $this->get_args ( 'achievementBonus' ) ? $this->get_args ( 'achievementBonus' ) : 0;
  72. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : '';
  73. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  74. $password = $this->get_args ( 'password' ) ? $this->get_args ( 'password' ) : "";
  75. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  76. $hiredate = $this->get_args ( 'hiredate' ) ? $this->get_args ( 'hiredate' ) : "";
  77. $nature = is_numeric ( $this->get_args ( 'nature' ) ) ? $this->get_args ( 'nature' ) : 1;
  78. $didKey = $this->get_args ( 'didKey' ) ? $this->get_args ( 'didKey' ) : array();
  79. if (! empty ( $username ) && ! empty ( $password ) && ! empty ( $cid ) && ! empty ( $hiredate ) && ! empty ( $nature )) {
  80. Doo::loadModel ( 'L_category' );
  81. Doo::loadModel ( 'staff' );
  82. Doo::loadModel ( 'tag' );
  83. Doo::loadModel ( 'holidaystaff' );
  84. $staff = new staff ();
  85. $L_category = new L_category ();
  86. // 加入默认总部分类
  87. $cagegory = $L_category->getCategoryById ( $cid );
  88. // 根据这个分类加入管理权限
  89. if ($cagegory [0] ['defult'] == 1) {
  90. $staff->isadmin = 1;
  91. }
  92. $staff->username = $username;
  93. $staff->passwork = md5 ( $password );
  94. $staff->cid = $cagegory [0] ['cid'];
  95. $staff->category = $cagegory [0] ['title'];
  96. $staff->hiredate = $hiredate;
  97. $staff->nature = $nature;
  98. $staff->did=implode(',', $didKey);
  99. $id = $staff->insert ();
  100. $holidaystaff = new HStaff ();
  101. $holidaystaff->uid = $id;
  102. $holidaystaff->insert ();
  103. $staffmsg = $staff->getUserById ( $id );
  104. $this->updateAnnualLeave ( $staffmsg [0] );
  105. for($i = 1; $i <= 7; $i ++) {
  106. $tag = new tag ();
  107. $tag->name = "个人标签";
  108. $tag->sid = $id;
  109. $tag->colorid = $i;
  110. $tag->insert ();
  111. }
  112. }
  113. }
  114. /**
  115. * 生成工号
  116. */
  117. function createJobNumber(){
  118. Doo::loadModel ( 'staff' );
  119. $staff = new staff ();
  120. $regularStaff=$staff->getStaffJobNumberByNature(1);
  121. $internStaff=$staff->getStaffJobNumberByNature(2);
  122. if (empty($regularStaff['jobNumber']))
  123. $regularStaffJobNumber='Z0001';
  124. else{
  125. $jobNumber=preg_replace('/[^\.0123456789]/s', '', $regularStaff['jobNumber']);
  126. $regularStaffJobNumber='Z'.sprintf("%04d", $jobNumber+1);
  127. }
  128. $internStaffJobNumber=$internStaff['jobNumber'];
  129. if (empty($internStaff['jobNumber']))
  130. $internStaffJobNumber='C0001';
  131. else{
  132. $jobNumber=preg_replace('/[^\.0123456789]/s', '', $internStaff['jobNumber']);
  133. $internStaffJobNumber='Z'.sprintf("%04d", $jobNumber+1);
  134. }
  135. $list=array('regularStaff'=>$regularStaffJobNumber,'internStaff'=>$internStaffJobNumber);
  136. return $list;
  137. }
  138. /**
  139. * 获取get或者POST值
  140. *
  141. * @param string $name 属性名称
  142. * @return fixed 值
  143. */
  144. function get_args($name) {
  145. if (isset ( $_GET [$name] )) {
  146. if (is_array ( $_GET [$name] ))
  147. return $_GET [$name];
  148. else
  149. return addslashes ( $_GET [$name] );
  150. } elseif (isset ( $_POST [$name] )) {
  151. if (is_array ( $_POST [$name] ))
  152. return $_POST [$name];
  153. else
  154. return addslashes ( $_POST [$name] );
  155. } else
  156. return false;
  157. }
  158. }
  159. ?>