Staff.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 状态 = '' order by 编号 asc ";
  82. $list = Db::query($sql);
  83. $data = [];
  84. foreach ($list as $key => $value){
  85. $number = $value['编号'];
  86. if (strlen($number) == 2 ){//一级菜单
  87. $sql = "select count(*) as total from 人事_基本资料 where LEFT(部门编码,2)='{$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) >= 4 && substr($num,0,2) == $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. /**
  168. * 员工法定天数修改
  169. * @return void
  170. * @throws \think\Exception
  171. * @throws \think\db\exception\BindParamException
  172. * @throws \think\db\exception\DataNotFoundException
  173. * @throws \think\db\exception\ModelNotFoundException
  174. * @throws \think\exception\DbException
  175. * @throws \think\exception\PDOException
  176. */
  177. public function clockUpdate()
  178. {
  179. if (Request::instance()->isPost() === false){
  180. $this->error('非法请求');
  181. }
  182. $params = Request::instance()->post();
  183. if (empty($params['month']) || empty($params['number'])){
  184. $this->error('参数错误');
  185. }
  186. $staffList = \db('人事_基本资料')
  187. ->field('rtrim(员工编号) as 员工编号,rtrim(班次类型) as 班次类型')
  188. ->where('在职状态','在职')
  189. ->select();
  190. $status = \db('人事_考勤资料')->where('kqzl_ny',$params['month'])->count();
  191. $data = [];
  192. foreach ($staffList as $key => $value){
  193. if ($value['班次类型'] === 'A类(双休班)'){
  194. $hours = $params['typeA'];
  195. }elseif ($value['班次类型'] === 'B类(7.5小时班)'){
  196. $hours = $params['typeB'];
  197. }else{
  198. $hours = $params['typeC'];
  199. }
  200. $data[$key] =[
  201. 'kqzl_ygbh' => $value['员工编号'],
  202. 'kqzl_ny' => $params['month'],
  203. '法定天数' => $params['number'],
  204. '不计定额天数' => 0,
  205. '法定工时' => $hours,
  206. '非考勤天数' => 0,
  207. '非考勤工时' => 0,
  208. '工作日出勤天数' => 0,
  209. '工作日出勤标准工时' => 0,
  210. '工作日出勤总工时' => 0,
  211. '可享法定假小时数' => 0,
  212. '有薪假工时' => 0,
  213. '延时加班' => 0,
  214. '双休加班天数' => 0,
  215. '双休加班' => 0,
  216. '法定假加班' => 0,
  217. '夜班次数' => 0,
  218. '调休类加班' => 0,
  219. '调休' => 0,
  220. '病假工时' => 0,
  221. '工伤工时' => 0,
  222. 'X_旷工工时' => 0,
  223. 'sys_id' => $params['sys_id'],
  224. 'sys_rq' => date('Y-m-d H:i:s',time()),
  225. 'mod_rq' => '1900-01-01 00:00:00',
  226. ];
  227. }
  228. $lastId = \db('人事_考勤资料')->order('UniqId desc')->value('UniqId');
  229. if ($status === 0){
  230. foreach ($data as $key=>$value){
  231. $data[$key]['UniqId'] = $lastId + $key + 1;
  232. }
  233. $sql = \db('人事_考勤资料')->fetchSql(true)->insertAll($data);
  234. $res = \db()->query($sql);
  235. if ($res !== false){
  236. $this->success('成功');
  237. }else{
  238. $this->error('失败');
  239. }
  240. }else{
  241. $i = 0;
  242. foreach ($data as $key=>$value){
  243. $value['mod_rq'] = date('Y-m-d H:i:s',time());
  244. $sql = \db('人事_考勤资料')
  245. ->where('kqzl_ygbh',$value['kqzl_ygbh'])
  246. ->where('kqzl_ny',$value['kqzl_ny'])
  247. ->fetchSql(true)
  248. ->update($value);
  249. $res = \db()->query($sql);
  250. if ($res === false){
  251. $i++;
  252. }
  253. }
  254. if ($i === 0){
  255. $this->success('成功');
  256. }else{
  257. $this->error('失败');
  258. }
  259. }
  260. }
  261. }