Staff.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. $limit = $params['limit'];
  50. if (empty($limit)){
  51. $limit = 15;
  52. }
  53. $pages = $params['page'];
  54. if (empty($pages)){
  55. $pages = 1;
  56. }
  57. $field = '员工编号,rtrim(员工姓名) as 员工姓名,性别,聘用日期,转正日期,rtrim(所在部门) as 所在部门,rtrim(职称职务) as 职称职务,rtrim(身份证号) as 身份证号,出生日期,
  58. rtrim(人员性质) as 人员性质,rtrim(人员类别) as 人员类别,班次类型,工资表类别,薪酬核算分组,rtrim(在职状态) as 在职状态,rtrim(U8在职) as U8在职,U8离职日期,rtrim(sys_id) as sys_id,sys_rq,mod_rq';
  59. $list = Db::name('人事_基本资料')->where($where)->field($field)->page($pages)->limit($limit)->order('UniqID asc')->select();
  60. $total = Db::name('人事_基本资料')->where($where)->count();
  61. $data['list'] = $list;
  62. $data['total'] = $total;
  63. $this->success('请求成功',$data);
  64. }
  65. /**
  66. * 获取部门列表
  67. *
  68. * @ApiMethod (GET)
  69. *
  70. */
  71. public function getDepartment(){
  72. if (Request::instance()->isGet() == false){
  73. $this->error('非法请求');
  74. }
  75. $sql = "select rtrim(编号) as 编号,rtrim(名称) as 名称 from 人事_组织结构 where 状态 = '' ";
  76. $list = Db::query($sql);
  77. $data = [];
  78. foreach ($list as $key => $value){
  79. $number = $value['编号'];
  80. if (strlen($number) == 1 ){//一级菜单
  81. $sql = "select count(*) as total from 人事_基本资料 where SUBSTRING(部门编码,1,1)='{$number}' and 在职状态 = '在职' and U8在职 = '在职'";
  82. $res = Db::query($sql);
  83. $value['num'] = $res[0]['total'];
  84. $list[$key] = $value;
  85. $data[$number] = $value;
  86. }else { //二级菜单
  87. $sql = "select count(*) as total from 人事_基本资料 where 部门编码='{$number}' and 在职状态 = '在职' and U8在职 = '在职'";
  88. $res = Db::query($sql);
  89. $value['num'] = $res[0]['total'];
  90. $list[$key] = $value;
  91. }
  92. }
  93. foreach ($data as $k=>$v){
  94. $i = 0;
  95. $data[$k]['children'] = [];
  96. foreach ($list as $item){
  97. $num = $item['编号'];
  98. if (strlen($num) >= 3 && substr($num,0,1) == $k){
  99. if ($item['num'] > 0){
  100. $data[$k]['children'][$i] = $item;
  101. $i++;
  102. }
  103. }
  104. }
  105. }
  106. $data = array_values($data);
  107. $this->success('请求成功',$data);
  108. }
  109. }