OvertimeVerification.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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 OvertimeVerification 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. * @ApiMethod (GET)
  24. */
  25. public function getTab()
  26. {
  27. //get请求
  28. if(!$this->request->isGet()){
  29. $this->error('请求方式错误');
  30. }
  31. $res=db('绩效工资汇总')
  32. ->field('DATE_FORMAT(`sczl_rq`, "%Y%m") as sys_ny,bh')
  33. ->group('DATE_FORMAT(`sczl_rq`, "%Y%m"),bh')
  34. ->whereTime('sczl_rq', '>=', strtotime('-14 months'))
  35. ->order('sczl_rq desc')
  36. ->select();
  37. foreach($res as $v){
  38. $arr[$v['sys_ny'].'('][]=$v['bh'];
  39. }
  40. $rs = db('人事_基本资料')->column('员工编号,所在部门');
  41. foreach($arr as $k=>$v){
  42. foreach($v as $value){
  43. $data[$k.count($v).'人)'][rtrim($rs[$value])][]=rtrim($rs[$value]);
  44. }
  45. $j=0;
  46. foreach($data[$k.count($v).'人)'] as $keys=>$values){
  47. $data[$k.count($v).'人)']['bm'][$j]=$keys;
  48. $data[$k.count($v).'人)'][$keys]=count($values);
  49. $j++;
  50. }
  51. usort($data[$k.count($v).'人)']['bm'], function($a, $b) {
  52. $order = array(
  53. '胶印车间',
  54. '凹印车间',
  55. '丝印车间',
  56. '模切车间',
  57. '检验车间',
  58. '精品试验车间',
  59. '品保部',
  60. '人力资源部',
  61. '生产部',
  62. '营销部'
  63. );
  64. $a_index = array_search($a, $order);
  65. $b_index = array_search($b, $order);
  66. return $a_index - $b_index;
  67. });
  68. foreach($data[$k.count($v).'人)']['bm'] as &$va){
  69. $va=$va.'('.$data[$k.count($v).'人)'][$va].'人)';
  70. }
  71. $data[$k.count($v).'人)']=$data[$k.count($v).'人)']['bm'];
  72. }
  73. $i=0;
  74. foreach($data as $k=>$v){
  75. $datas[$i]['label']=$k;
  76. $gdbh=substr($k,0,strpos($k,'('));
  77. foreach($v as $key=>$value){
  78. $datas[$i]['children'][$key]['label']=$value;
  79. $datas[$i]['children'][$key]['gdbh']=$gdbh;
  80. }
  81. $i++;
  82. }
  83. $this->success('成功',$datas);
  84. }
  85. /**
  86. * 计件员工加班费核查上侧列表
  87. * @ApiMethod (GET)
  88. * @param string $date 年月
  89. * @param string $department 部门
  90. */
  91. public function getList()
  92. {
  93. //get请求
  94. if(!$this->request->isGet()){
  95. $this->error('请求方式错误');
  96. }
  97. $req = $this->request->param();
  98. $res=db('绩效工资汇总')->alias('j')
  99. ->join('人事_基本资料 r','r.员工编号=j.bh')
  100. ->group('j.bh')
  101. ->where('j.sys_ny',$req['date'])
  102. ->where(['r.所在部门'=>['like',$req['department'].'%']])
  103. ->column('CONCAT(j.bh, "-", DATE_FORMAT(j.sczl_rq,"%Y.%m")) AS rq_bh,j.bh,rtrim(j.xm) as 员工姓名,r.工资表类别,DATE_FORMAT(r.聘用日期,"%Y.%m.%d") as 聘用日期,j.法定天数,
  104. sum(j.达标定额) as 当月定额,(sum(j.班组车头产量*j.工序难度系数)+sum(j.班组换算产量)) as 月度合计产量,sum(j.个人计件工资) as 个人计件工资,
  105. sum(j.个人加班工资) as 个人加班工资,sum(j.异常停机工时) as 月计时时数,LEFT(j.sczl_rq, 7) as sczl_rq');
  106. $year=substr($req['date'],0,4);
  107. $month=substr($req['date'],-2);
  108. $start_time = $year . '-' . $month . '-01 00:00:00';
  109. $end_time = date('Y-m-t', strtotime("$year-$month-01")) . ' 23:59:59';
  110. $arr = [];
  111. $columns = ['wgjs_bh1', 'wgjs_bh2', 'wgjs_bh3', 'wgjs_bh4', 'wgjs_bh5', 'wgjs_bh6'];
  112. for ($i = 1; $i <= 6; $i++) {
  113. $column = $columns[$i-1];
  114. $r = db('db_wgjs')
  115. ->field("DATE_FORMAT(wgjs_rq,'%Y.%m') as wgjs_rq, $column as wgjs_bh, wgjs_js$i as wgjs_js, wgjs_冲定额$i as wgjs_冲定额")
  116. ->join('人事_基本资料', "人事_基本资料.员工编号=db_wgjs.$column")
  117. ->where(['wgjs_rq' => ['between', "$start_time,$end_time"], '人事_基本资料.所在部门' => ['like', $req['department'] . '%']])
  118. ->select();
  119. $arr = array_merge($arr, $r);
  120. }
  121. $list = [];
  122. foreach($arr as $v){
  123. if(isset($list[$v['wgjs_bh'].'-'.$v['wgjs_rq']])){
  124. if($v['wgjs_冲定额']=='是'){
  125. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['月计时时数']+=$v['wgjs_js'];
  126. }
  127. }else{
  128. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['bh']=$v['wgjs_bh'];
  129. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['sczl_rq']=$v['wgjs_rq'];
  130. if($v['wgjs_冲定额']=='是'){
  131. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['月计时时数']=$v['wgjs_js'];
  132. }else{
  133. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['月计时时数']=0;
  134. }
  135. }
  136. };
  137. //获取每个员工计时补差天数
  138. $arr1 = db('绩效工资汇总')->alias('j')
  139. ->field('j.bh,j.sczl_rq')
  140. ->join('人事_基本资料 r','r.员工编号=j.bh')
  141. ->group('j.bh,j.sczl_rq')
  142. ->where('j.sys_ny',$req['date'])
  143. ->where('j.达标定额','<>',0)
  144. ->where(['r.所在部门'=>['like',$req['department'].'%']])
  145. ->buildSql();
  146. $arr1 = db()->table($arr1 . ' t')
  147. ->group('t.bh, LEFT(t.sczl_rq, 7)')
  148. ->column('t.bh,count(LEFT(t.sczl_rq, 7)) as num');
  149. //查询每条记录
  150. $arr2 = db('绩效工资汇总')->alias('j')
  151. ->field('j.bh, DATE_FORMAT(j.sczl_rq,"%Y.%m") as sczl_rq,
  152. sum(j.达标定额) as 达标定额, j.Rate, j.千件工价')
  153. ->join('人事_基本资料 r','r.员工编号=j.bh')
  154. ->where('j.sys_ny',$req['date'])
  155. ->where('j.达标定额','<>',0)
  156. ->where(['r.所在部门'=>['like',$req['department'].'%']])
  157. ->group('j.bh,j.sczl_rq,j.sczl_gdbh')
  158. ->select();
  159. //计算每条记录的计时补差
  160. $brr = [];
  161. foreach($arr2 as $v){
  162. $yjsss1 = array_key_exists($v['bh'].'-'.$v['sczl_rq'],$list) ? $list[$v['bh'].'-'.$v['sczl_rq']]['月计时时数'] : 0;
  163. $yjsss2 = array_key_exists($v['bh'].'-'.$v['sczl_rq'],$res) ? $res[$v['bh'].'-'.$v['sczl_rq']]['月计时时数'] : 0;
  164. $yjsss = $yjsss1 + $yjsss2;
  165. $a = $yjsss/$arr1[$v['bh']]/11*0.6*$v['达标定额']*$v['Rate']*0.5/1000*$v['千件工价'];
  166. if(array_key_exists($v['bh'].'-'.$v['sczl_rq'],$brr)){
  167. $brr[$v['bh'].'-'.$v['sczl_rq']] += $a;
  168. }else{
  169. $brr[$v['bh'].'-'.$v['sczl_rq']] = $a;
  170. }
  171. }
  172. foreach($res as $k=>&$v){
  173. if(array_key_exists($k,$list)){
  174. $v['月计时时数'] += $list[$k]['月计时时数'];
  175. }
  176. $v['工资表类别'] = trim($v['工资表类别']);
  177. $v['法定天数'] = round($v['法定天数']);
  178. $v['当月定额'] = round($v['当月定额']);
  179. $v['月度合计产量'] = round($v['月度合计产量']);
  180. $v['月计时时数'] = floatval(number_format($v['月计时时数'],2));
  181. $v['计时补差'] = floatval(number_format($brr[$k],2));
  182. unset($v['rq_bh']);
  183. }
  184. $res = array_values($res);
  185. $this->success('成功',$res);
  186. }
  187. /**
  188. * 计件员工加班费核查下侧列表
  189. * @ApiMethod (GET)
  190. * @param string $date 年月
  191. * @param string $code 员工编号
  192. */
  193. public function getAllList()
  194. {
  195. //get请求
  196. if(!$this->request->isGet()){
  197. $this->error('请求方式错误');
  198. }
  199. $req = $this->request->param();
  200. $res=db('绩效工资汇总')
  201. ->field('LEFT(sczl_rq, 10) as sczl_rq,sczl_gdbh,rtrim(g.成品名称) as Gd_cpmc,sczl_yjno,sczl_gxh,sczl_type,
  202. sczl_jtbh,sum(班组车头产量) as 班组车头产量,工序难度系数 as 产量系数,(sum(班组车头产量*工序难度系数)) as 计件产量,
  203. sum(班组换算产量) as 补产产量,(sum(班组车头产量*工序难度系数)+sum(班组换算产量)) as 核算产量,日定额,sum(达标定额)
  204. as 达标定额,千件工价,补产标准,sum(个人计件工资) as 个人计件工资,sum(个人加班工资) as 个人加班工资,Rate as 个人比例,
  205. sum(装版工时) as 装版工时,sum(保养工时) as 保养工时,sum(打样工时) as 打样工时,sum(计时补差额工资) as 计时补差')
  206. ->join('工单_基本资料 g','g.Gd_gdbh=绩效工资汇总.sczl_gdbh AND g.行号=1')
  207. ->group('LEFT(sczl_rq, 10),sczl_gdbh')
  208. ->where(['sys_ny'=>$req['date'],'bh'=>$req['code']])
  209. ->select();
  210. if(!$res){
  211. $this->error('失败');
  212. }
  213. foreach($res as &$v){
  214. $v['sczl_rq']=str_replace('-','.',$v['sczl_rq']);
  215. if($v['sczl_yjno']>9){
  216. $sczl_yjno=$v['sczl_yjno'];
  217. }else{
  218. $sczl_yjno='0'.$v['sczl_yjno'];
  219. }
  220. unset($v['sczl_yjno']);
  221. if($v['sczl_gxh']>9){
  222. $sczl_gxh=$v['sczl_gxh'];
  223. }else{
  224. $sczl_gxh='0'.$v['sczl_gxh'];
  225. }
  226. unset($v['sczl_gxh']);
  227. $v['sczl_type']=$sczl_yjno.'-'.$sczl_gxh.'-->'.$v['sczl_type'];
  228. }
  229. $this->success('成功',$res);
  230. }
  231. /**
  232. * 计件员工加班费核查详情
  233. * @ApiMethod (GET)
  234. * @param string $date 日期
  235. * @param string $code 员工编号
  236. */
  237. public function getDetail()
  238. {
  239. //get请求
  240. if(!$this->request->isGet()){
  241. $this->error('请求方式错误');
  242. }
  243. $req = $this->request->param();
  244. $start_time=$req['date'].' 00:00:00';
  245. $end_time=$req['date'].' 23:59:59';
  246. $res=db('绩效工资汇总')
  247. ->field('LEFT(sczl_rq, 10) as sczl_rq,sczl_gdbh,rtrim(g.Gd_cpmc) as Gd_cpmc,sczl_yjno,sczl_gxh,sczl_type,
  248. sczl_jtbh,sum(班组车头产量) as 班组车头产量,工序难度系数 as 产量系数,(sum(班组车头产量*工序难度系数)) as 计件产量,
  249. sum(班组换算产量) as 补产产量,(sum(班组车头产量*工序难度系数)+sum(班组换算产量)) as 核算产量,日定额,sum(达标定额)
  250. as 达标定额,千件工价,补产标准,sum(个人计件工资) as 个人计件工资,sum(个人加班工资) as 个人加班工资,Rate as 个人比例,
  251. sum(装版工时) as 装版工时,sum(保养工时) as 保养工时,sum(打样工时) as 打样工时,sum(计时补差额工资) as 计时补差')
  252. ->join('工单_基本资料 g','g.Gd_gdbh=绩效工资汇总.sczl_gdbh','LEFT')
  253. ->group('LEFT(sczl_rq, 10),sczl_gdbh')
  254. ->where(['sczl_rq'=>['between',"$start_time,$end_time"],'bh'=>$req['code']])
  255. ->select();
  256. if(!$res){
  257. $this->error('失败');
  258. }
  259. foreach($res as &$v){
  260. $v['sczl_rq']=str_replace('-','.',$v['sczl_rq']);
  261. if($v['sczl_yjno']>9){
  262. $sczl_yjno=$v['sczl_yjno'];
  263. }else{
  264. $sczl_yjno='0'.$v['sczl_yjno'];
  265. }
  266. unset($v['sczl_yjno']);
  267. if($v['sczl_gxh']>9){
  268. $sczl_gxh=$v['sczl_gxh'];
  269. }else{
  270. $sczl_gxh='0'.$v['sczl_gxh'];
  271. }
  272. unset($v['sczl_gxh']);
  273. $v['sczl_type']=$sczl_yjno.'-'.$sczl_gxh.'-->'.$v['sczl_type'];
  274. }
  275. $this->success('成功',$res);
  276. }
  277. /**
  278. * 定位
  279. * @ApiMethod GET
  280. */
  281. public function search(){
  282. //get请求
  283. if(!$this->request->isGet()){
  284. $this->error('请求方式错误');
  285. }
  286. $req = $this->request->param();
  287. $yg = db()->table('人事_基本资料')->where('员工姓名',$req['search'])->value('员工编号');
  288. // $yg = db()->table('人事_基本资料')->where('员工姓名','like','%'.$req['search'].'%')->column('员工编号');
  289. if($yg){
  290. $req['search']=$yg;
  291. }
  292. $res=db('绩效工资汇总')->alias('j')
  293. ->join('人事_基本资料 r','r.员工编号=j.bh')
  294. ->group('j.bh')
  295. ->where('j.sys_ny',$req['date'])
  296. ->where('j.bh',$req['search'])
  297. // ->where(['r.所在部门'=>['like',$req['department'].'%']])
  298. ->column('CONCAT(j.bh, "-", DATE_FORMAT(sczl_rq,"%Y.%m")) AS rq_bh,j.bh,rtrim(j.xm) as 员工姓名,r.工资表类别,DATE_FORMAT(r.聘用日期,"%Y.%m.%d") as 聘用日期,j.法定天数,
  299. sum(j.达标定额) as 当月定额,(sum(j.班组车头产量*j.工序难度系数)+sum(j.班组换算产量)) as 月度合计产量,sum(j.个人计件工资) as 个人计件工资,
  300. sum(j.个人加班工资) as 个人加班工资,sum(j.异常停机工时) as 月计时时数,LEFT(j.sczl_rq, 7) as sczl_rq');
  301. $year=substr($req['date'],0,4);
  302. $month=substr($req['date'],-2);
  303. $start_time = $year . '-' . $month . '-01 00:00:00';
  304. $end_time = date('Y-m-t', strtotime("$year-$month-01")) . ' 23:59:59';
  305. $arr = [];
  306. $columns = ['wgjs_bh1', 'wgjs_bh2', 'wgjs_bh3', 'wgjs_bh4', 'wgjs_bh5', 'wgjs_bh6'];
  307. for ($i = 1; $i <= 6; $i++) {
  308. $column = $columns[$i-1];
  309. $r = db('db_wgjs')
  310. ->field("DATE_FORMAT(wgjs_rq,'%Y.%m') as wgjs_rq, $column as wgjs_bh, wgjs_js$i as wgjs_js, wgjs_冲定额$i as wgjs_冲定额")
  311. ->join('人事_基本资料', "人事_基本资料.员工编号=db_wgjs.$column")
  312. ->where($column,$req['search'])
  313. ->where(['wgjs_rq' => ['between', "$start_time,$end_time"]])
  314. ->select();
  315. $arr = array_merge($arr, $r);
  316. }
  317. $list = [];
  318. foreach($arr as $v){
  319. if(isset($list[$v['wgjs_bh'].'-'.$v['wgjs_rq']])){
  320. if($v['wgjs_冲定额']=='是'){
  321. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['月计时时数']+=$v['wgjs_js'];
  322. }
  323. }else{
  324. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['bh']=$v['wgjs_bh'];
  325. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['sczl_rq']=$v['wgjs_rq'];
  326. if($v['wgjs_冲定额']=='是'){
  327. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['月计时时数']=$v['wgjs_js'];
  328. }else{
  329. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['月计时时数']=0;
  330. }
  331. }
  332. };
  333. //获取每个员工计时补差天数
  334. $arr1 = db('绩效工资汇总')->alias('j')
  335. ->field('j.bh,j.sczl_rq')
  336. ->join('人事_基本资料 r','r.员工编号=j.bh')
  337. ->group('j.bh,j.sczl_rq')
  338. ->where('j.sys_ny',$req['date'])
  339. ->where('j.bh',$req['search'])
  340. ->where('j.达标定额','<>',0)
  341. // ->where(['r.所在部门'=>['like',$req['department'].'%']])
  342. ->buildSql();
  343. $arr1 = db()->table($arr1 . ' t')
  344. ->group('t.bh, LEFT(t.sczl_rq, 7)')
  345. ->column('t.bh,count(LEFT(t.sczl_rq, 7)) as num');
  346. //查询每条记录
  347. $arr2 = db('绩效工资汇总')->alias('j')
  348. ->field('j.bh, DATE_FORMAT(j.sczl_rq,"%Y.%m") as sczl_rq,
  349. sum(j.达标定额) as 达标定额, j.Rate, j.千件工价')
  350. ->join('人事_基本资料 r','r.员工编号=j.bh')
  351. ->where('j.sys_ny',$req['date'])
  352. ->where('j.达标定额','<>',0)
  353. ->where('j.bh',$req['search'])
  354. // ->where(['r.所在部门'=>['like',$req['department'].'%']])
  355. ->group('j.bh,j.sczl_rq,j.sczl_gdbh')
  356. ->select();
  357. //计算每条记录的计时补差
  358. $brr = [];
  359. foreach($arr2 as $v){
  360. $yjsss1 = array_key_exists($v['bh'].'-'.$v['sczl_rq'],$list) ? $list[$v['bh'].'-'.$v['sczl_rq']]['月计时时数'] : 0;
  361. $yjsss2 = array_key_exists($v['bh'].'-'.$v['sczl_rq'],$res) ? $res[$v['bh'].'-'.$v['sczl_rq']]['月计时时数'] : 0;
  362. $yjsss = $yjsss1 + $yjsss2;
  363. $a = $yjsss/$arr1[$v['bh']]/11*0.6*$v['达标定额']*$v['Rate']*0.5/1000*$v['千件工价'];
  364. if(array_key_exists($v['bh'].'-'.$v['sczl_rq'],$brr)){
  365. $brr[$v['bh'].'-'.$v['sczl_rq']] += $a;
  366. }else{
  367. $brr[$v['bh'].'-'.$v['sczl_rq']] = $a;
  368. }
  369. }
  370. foreach($res as $k=>&$v){
  371. if(array_key_exists($k,$list)){
  372. $v['月计时时数'] += $list[$k]['月计时时数'];
  373. }
  374. $v['工资表类别'] = trim($v['工资表类别']);
  375. $v['法定天数'] = round($v['法定天数']);
  376. $v['当月定额'] = round($v['当月定额']);
  377. $v['月度合计产量'] = round($v['月度合计产量']);
  378. $v['月计时时数'] = floatval(number_format($v['月计时时数'],2));
  379. $v['计时补差'] = floatval(number_format($brr[$k],2));
  380. unset($v['rq_bh']);
  381. }
  382. $res = array_values($res);
  383. $this->success('成功',$res);
  384. $arr = [];
  385. $columns = ['wgjs_bh1', 'wgjs_bh2', 'wgjs_bh3', 'wgjs_bh4', 'wgjs_bh5', 'wgjs_bh6'];
  386. $field = 'wgjs_js';
  387. for ($i = 1; $i <= 6; $i++) {
  388. $column = $columns[$i-1];
  389. $r = db('db_wgjs')
  390. ->field("DATE_FORMAT(wgjs_rq,'%Y.%m') as wgjs_rq, $column as wgjs_bh, ${field}${i} as wgjs_js")
  391. ->join('人事_基本资料', "人事_基本资料.员工编号=db_wgjs.$column")
  392. ->where(['wgjs_rq' => ['between', "$start_time,$end_time"]])
  393. ->select();
  394. $arr = array_merge($arr, $r);
  395. }
  396. $list = [];
  397. foreach($arr as $v){
  398. if(isset($list[$v['wgjs_bh'].'-'.$v['wgjs_rq']])){
  399. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['月计时时数']+=$v['wgjs_js'];
  400. }else{
  401. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['bh']=$v['wgjs_bh'];
  402. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['sczl_rq']=$v['wgjs_rq'];
  403. $list[$v['wgjs_bh'].'-'.$v['wgjs_rq']]['月计时时数']=$v['wgjs_js'];
  404. }
  405. };
  406. foreach($res as $k=>&$v){
  407. if(array_key_exists($k,$list)){
  408. $v['月计时时数'] += $list[$k]['月计时时数'];
  409. }
  410. $v['工资表类别'] = trim($v['工资表类别']);
  411. $v['法定天数'] = round($v['法定天数']);
  412. $v['当月定额'] = round($v['当月定额']);
  413. $v['月度合计产量'] = round($v['月度合计产量']);
  414. $v['月计时时数'] = floatval(number_format($v['月计时时数'],2));
  415. $v['计时补差'] = floatval(bcmul($v['月计时时数'], 9.5, 2));
  416. unset($v['rq_bh']);
  417. }
  418. $res = array_values($res);
  419. $this->success('成功',$res);
  420. }
  421. }