Staff.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. if ($params['转正日期'] === ''){
  158. $params['转正日期'] = null;
  159. }
  160. $staffCode = $params['员工编号'];
  161. unset($params['员工编号']);
  162. $sql = db('人事_基本资料')->where('员工编号',$staffCode)->fetchSql(true)->update($params);
  163. $res = Db::query($sql);
  164. if ($res !== false){
  165. $this->success('更新成功');
  166. }else{
  167. $this->error('更新失败');
  168. }
  169. }
  170. /**
  171. * 员工法定天数修改
  172. * @return void
  173. * @throws \think\Exception
  174. * @throws \think\db\exception\BindParamException
  175. * @throws \think\db\exception\DataNotFoundException
  176. * @throws \think\db\exception\ModelNotFoundException
  177. * @throws \think\exception\DbException
  178. * @throws \think\exception\PDOException
  179. */
  180. public function clockUpdate()
  181. {
  182. if (Request::instance()->isPost() === false){
  183. $this->error('非法请求');
  184. }
  185. $params = Request::instance()->post();
  186. if (empty($params['month']) || empty($params['number'])){
  187. $this->error('参数错误');
  188. }
  189. $staffList = \db('人事_基本资料')
  190. ->field('rtrim(员工编号) as 员工编号,rtrim(班次类型) as 班次类型')
  191. ->where('在职状态','在职')
  192. ->select();
  193. $status = \db('人事_考勤资料')->where('kqzl_ny',$params['month'])->count();
  194. $data = [];
  195. foreach ($staffList as $key => $value){
  196. if ($value['班次类型'] === 'A类(双休班)'){
  197. $hours = $params['typeA'];
  198. }elseif ($value['班次类型'] === 'B类(7.5小时班)'){
  199. $hours = $params['typeB'];
  200. }else{
  201. $hours = $params['typeC'];
  202. }
  203. $data[$key] =[
  204. 'kqzl_ygbh' => $value['员工编号'],
  205. 'kqzl_ny' => $params['month'],
  206. '法定天数' => $params['number'],
  207. '不计定额天数' => 0,
  208. '法定工时' => $hours,
  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. '调休' => 0,
  223. '病假工时' => 0,
  224. '工伤工时' => 0,
  225. 'X_旷工工时' => 0,
  226. 'sys_id' => $params['sys_id'],
  227. 'sys_rq' => date('Y-m-d H:i:s',time()),
  228. 'mod_rq' => '1900-01-01 00:00:00',
  229. ];
  230. }
  231. $lastId = \db('人事_考勤资料')->order('UniqId desc')->value('UniqId');
  232. if ($status === 0){
  233. foreach ($data as $key=>$value){
  234. $data[$key]['UniqId'] = $lastId + $key + 1;
  235. }
  236. $sql = \db('人事_考勤资料')->fetchSql(true)->insertAll($data);
  237. $res = \db()->query($sql);
  238. if ($res !== false){
  239. $this->success('成功');
  240. }else{
  241. $this->error('失败');
  242. }
  243. }else{
  244. $i = 0;
  245. foreach ($data as $key=>$value){
  246. $value['mod_rq'] = date('Y-m-d H:i:s',time());
  247. $sql = \db('人事_考勤资料')
  248. ->where('kqzl_ygbh',$value['kqzl_ygbh'])
  249. ->where('kqzl_ny',$value['kqzl_ny'])
  250. ->fetchSql(true)
  251. ->update($value);
  252. $res = \db()->query($sql);
  253. if ($res === false){
  254. $i++;
  255. }
  256. }
  257. if ($i === 0){
  258. $this->success('成功');
  259. }else{
  260. $this->error('失败');
  261. }
  262. }
  263. }
  264. }