Staff.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use \think\Request;
  5. use \think\Db;
  6. /**
  7. * 员工资料接口
  8. */
  9. class Staff extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 首页
  15. *
  16. */
  17. public function index()
  18. {
  19. $this->success('请求成功');
  20. }
  21. /**
  22. * 获取员工列表信息
  23. *
  24. * @ApiMethod (GET)
  25. * @param string department_code
  26. * @param string mes_online
  27. * @param string u8_online
  28. * @param string limit
  29. * @param string page
  30. *
  31. */
  32. public function getStaffList(){
  33. if (Request::instance()->isGet() == false){
  34. $this->error('非法请求');
  35. }
  36. $params = Request::instance()->param();
  37. $where = [];
  38. $where['在职状态'] = '在职';
  39. if (isset($params['mes_online'])){
  40. $where['在职状态'] = $params['mes_online'] > 1 ? '离职':'在职';
  41. }
  42. $where['U8在职'] = '在职';
  43. if (isset($params['u8_online'])){
  44. $where['U8在职'] = $params['u8_online'] > 1 ? '离职':'在职';
  45. }
  46. $where['员工编号|员工姓名'] = array('like','%'.$params['search'].'%');
  47. $limit = $params['limit'];
  48. if (empty($limit)){
  49. $limit = 15;
  50. }
  51. $pages = $params['page'];
  52. if (empty($pages)){
  53. $pages = 1;
  54. }
  55. $field = '员工编号,rtrim(员工姓名) as 员工姓名,性别,聘用日期,转正日期,rtrim(所在部门) as 所在部门,rtrim(部门编码) as 部门编码,rtrim(职称职务) as 职称职务,rtrim(身份证号) as 身份证号,出生日期,
  56. rtrim(人员性质) as 人员性质,rtrim(人员类别) as 人员类别,班次类型,工资表类别,薪酬核算分组,rtrim(在职状态) as 在职状态,rtrim(U8在职) as U8在职,U8离职日期,rtrim(sys_id) as sys_id,sys_rq,mod_rq';
  57. if (strlen($params['department_code']) > 1){
  58. $list = db('人事_基本资料')->where($where)->where('部门编码',$params['department_code'])->field($field)->page($pages)->limit($limit)->order('UniqID asc')->select();
  59. $total = db('人事_基本资料')->where($where)->where('部门编码',$params['department_code'])->count();
  60. }else if (strlen($params['department_code']) == 1){
  61. $list = db('人事_基本资料')->where($where)->where('LEFT(部门编码,1)='.$params['department_code'])->field($field)->page($pages)->limit($limit)->order('UniqID asc')->select();
  62. $total = db('人事_基本资料')->where($where)->where('LEFT(部门编码,1)='.$params['department_code'])->count();
  63. }else{
  64. $list = db('人事_基本资料')->where($where)->field($field)->page($pages)->limit($limit)->order('UniqID asc')->select();
  65. $total = db('人事_基本资料')->where($where)->count();
  66. }
  67. $data['list'] = $list;
  68. $data['total'] = $total;
  69. $this->success('请求成功',$data);
  70. }
  71. /**
  72. * 获取部门列表
  73. *
  74. * @ApiMethod (GET)
  75. *
  76. */
  77. public function getDepartment(){
  78. if (Request::instance()->isGet() == false){
  79. $this->error('非法请求');
  80. }
  81. $sql = "select rtrim(编号) as 编号,rtrim(名称) as 名称 from 人事_组织结构 where 状态 = '' ";
  82. $list = Db::query($sql);
  83. $data = [];
  84. foreach ($list as $key => $value){
  85. $number = $value['编号'];
  86. if (strlen($number) == 1 ){//一级菜单
  87. $sql = "select count(*) as total from 人事_基本资料 where SUBSTRING(部门编码,1,1)='{$number}' and 在职状态 = '在职' and U8在职 = '在职'";
  88. $res = Db::query($sql);
  89. $value['num'] = $res[0]['total'];
  90. $list[$key] = $value;
  91. $data[$number] = $value;
  92. }else { //二级菜单
  93. $sql = "select count(*) as total from 人事_基本资料 where 部门编码='{$number}' and 在职状态 = '在职' and U8在职 = '在职'";
  94. $res = Db::query($sql);
  95. $value['num'] = $res[0]['total'];
  96. $list[$key] = $value;
  97. }
  98. }
  99. $six = db('人事_基本资料')->where('在职状态','在职')->where('U8在职','离职')->count();
  100. $sixArr['编号'] = '';
  101. $sixArr['名称'] = '离职工资结算中';
  102. $sixArr['total'] = $six;
  103. $sev = db('人事_基本资料')->where('在职状态','离职')->where('U8在职','离职')->count();
  104. $sevArr['编号'] = '';
  105. $sevArr['名称'] = '离职清单';
  106. $sevArr['total'] = $sev;
  107. array_push($data,$sixArr,$sevArr);
  108. foreach ($data as $k=>$v){
  109. $i = 0;
  110. $data[$k]['children'] = [];
  111. foreach ($list as $item){
  112. $num = $item['编号'];
  113. if (strlen($num) >= 3 && substr($num,0,1) == $k){
  114. if ($item['num'] > 0){
  115. $data[$k]['children'][$i] = $item;
  116. $i++;
  117. }
  118. }
  119. }
  120. }
  121. $data = array_values($data);
  122. $this->success('请求成功',$data);
  123. }
  124. /**
  125. * 获取员工资料
  126. * @ApiMethod GET
  127. * @params string code
  128. */
  129. public function getStaffInfo(){
  130. if (Request::instance()->isGet() == false){
  131. $this->error('非法请求');
  132. }
  133. $params = Request::instance()->param();
  134. $where = [];
  135. if (isset($params['code'])){
  136. $where['员工编号'] = $params['code'] ;
  137. }
  138. $field = '员工编号,rtrim(员工姓名) as 员工姓名,性别,聘用日期,转正日期,rtrim(所在部门) as 所在部门,rtrim(部门编码) as 部门编码,rtrim(职称职务) as 职称职务,rtrim(身份证号) as 身份证号,出生日期,
  139. rtrim(人员性质) as 人员性质,rtrim(人员类别) as 人员类别,班次类型,工资表类别,薪酬核算分组,rtrim(在职状态) as 在职状态,rtrim(U8在职) as U8在职,U8离职日期,rtrim(sys_id) as sys_id,sys_rq,mod_rq';
  140. $data = db('人事_基本资料')->where($where)->field($field)->find();
  141. $this->success('请求成功',$data);
  142. }
  143. /**
  144. * 修改员工资料
  145. *
  146. * @ApiMethod POST
  147. *
  148. */
  149. public function edit(){
  150. if (Request::instance()->isPost() == false){
  151. $this->error('非法请求');
  152. }
  153. $params = Request::instance()->param();
  154. if (empty($params['员工编号'])){
  155. $this->error('参数不能为空');
  156. }
  157. $staffCode = $params['员工编号'];
  158. unset($params['员工编号']);
  159. $sql = db('人事_基本资料')->where('员工编号',$staffCode)->fetchSql(true)->update($params);
  160. $res = Db::query($sql);
  161. if ($res !== false){
  162. $this->success('更新成功');
  163. }else{
  164. $this->error('更新失败');
  165. }
  166. }
  167. }