Staff.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. if (!empty($params['department_code'])){
  39. $where['部门编码'] = $params['department_code'];
  40. }
  41. $where['在职状态'] = '在职';
  42. if (isset($params['mes_online'])){
  43. $where['在职状态'] = $params['mes_online'] > 1 ? '离职':'在职';
  44. }
  45. $where['U8在职'] = '在职';
  46. if (isset($params['u8_online'])){
  47. $where['U8在职'] = $params['u8_online'] > 1 ? '离职':'在职';
  48. }
  49. $where['员工编号|员工姓名'] = array('like','%'.$params['search'].'%');
  50. $limit = $params['limit'];
  51. if (empty($limit)){
  52. $limit = 15;
  53. }
  54. $pages = $params['page'];
  55. if (empty($pages)){
  56. $pages = 1;
  57. }
  58. $field = '员工编号,rtrim(员工姓名) as 员工姓名,性别,聘用日期,转正日期,rtrim(所在部门) as 所在部门,rtrim(部门编码) as 部门编码,rtrim(职称职务) as 职称职务,rtrim(身份证号) as 身份证号,出生日期,
  59. rtrim(人员性质) as 人员性质,rtrim(人员类别) as 人员类别,班次类型,工资表类别,薪酬核算分组,rtrim(在职状态) as 在职状态,rtrim(U8在职) as U8在职,U8离职日期,rtrim(sys_id) as sys_id,sys_rq,mod_rq';
  60. $list = Db::name('人事_基本资料')->where($where)->field($field)->page($pages)->limit($limit)->order('UniqID asc')->select();
  61. $total = Db::name('人事_基本资料')->where($where)->count();
  62. $data['list'] = $list;
  63. $data['total'] = $total;
  64. $this->success('请求成功',$data);
  65. }
  66. /**
  67. * 获取部门列表
  68. *
  69. * @ApiMethod (GET)
  70. *
  71. */
  72. public function getDepartment(){
  73. if (Request::instance()->isGet() == false){
  74. $this->error('非法请求');
  75. }
  76. $sql = "select rtrim(编号) as 编号,rtrim(名称) as 名称 from 人事_组织结构 where 状态 = '' ";
  77. $list = Db::query($sql);
  78. $data = [];
  79. foreach ($list as $key => $value){
  80. $number = $value['编号'];
  81. if (strlen($number) == 1 ){//一级菜单
  82. $sql = "select count(*) as total from 人事_基本资料 where SUBSTRING(部门编码,1,1)='{$number}' and 在职状态 = '在职' and U8在职 = '在职'";
  83. $res = Db::query($sql);
  84. $value['num'] = $res[0]['total'];
  85. $list[$key] = $value;
  86. $data[$number] = $value;
  87. }else { //二级菜单
  88. $sql = "select count(*) as total from 人事_基本资料 where 部门编码='{$number}' and 在职状态 = '在职' and U8在职 = '在职'";
  89. $res = Db::query($sql);
  90. $value['num'] = $res[0]['total'];
  91. $list[$key] = $value;
  92. }
  93. }
  94. foreach ($data as $k=>$v){
  95. $i = 0;
  96. $data[$k]['children'] = [];
  97. foreach ($list as $item){
  98. $num = $item['编号'];
  99. if (strlen($num) >= 3 && substr($num,0,1) == $k){
  100. if ($item['num'] > 0){
  101. $data[$k]['children'][$i] = $item;
  102. $i++;
  103. }
  104. }
  105. }
  106. }
  107. $data = array_values($data);
  108. $this->success('请求成功',$data);
  109. }
  110. /**
  111. * 修改员工资料
  112. *
  113. * @ApiMethod POST
  114. *
  115. */
  116. public function edit(){
  117. if (Request::instance()->isPost() == false){
  118. $this->error('非法请求');
  119. }
  120. $params = Request::instance()->param();
  121. if (empty($params['员工编号'])){
  122. $this->error('参数不能为空');
  123. }
  124. $staffCode = $params['员工编号'];
  125. unset($params['员工编号']);
  126. $sql = Db::name('人事_基本资料')->where('员工编号',$staffCode)->fetchSql(true)->update($params);
  127. $res = Db::query($sql);
  128. if ($res !== false){
  129. $this->success('更新成功');
  130. }else{
  131. $this->error('更新失败');
  132. }
  133. }
  134. }