PieceWorkSchedule.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * 计件工计时单维护接口
  6. */
  7. class PieceWorkSchedule extends Api
  8. {
  9. protected $noNeedLogin = ['*'];
  10. protected $noNeedRight = ['*'];
  11. /**
  12. * 首页
  13. *
  14. */
  15. public function index()
  16. {
  17. $this->success('请求成功');
  18. }
  19. /**
  20. * 获取计件工计时单侧边栏
  21. * @ApiMethod (GET)
  22. */
  23. public function getTab()
  24. {
  25. //get请求
  26. if(!$this->request->isGet()){
  27. $this->error('请求方式错误');
  28. }
  29. $rows = db()->table('db_wgjs')
  30. ->field('LEFT(wgjs_rq, 7) as date')
  31. ->group('date')
  32. ->order('UniqId desc')
  33. ->limit(15)
  34. ->select();
  35. foreach($rows as $key=>$value){
  36. $rows[$key]['date'] = str_replace('-', '', $rows[$key]['date']);
  37. }
  38. $this->success('成功',$rows);
  39. }
  40. /**
  41. * 获取计件工计时单列表
  42. * @ApiMethod (GET)
  43. * @param string $date 时间
  44. * @param string $Sczl_bh1 员工编号
  45. */
  46. public function getList()
  47. {
  48. //get请求
  49. if(!$this->request->isGet()){
  50. $this->error('请求方式错误');
  51. }
  52. $req = $this->request->param();
  53. $page = 1;
  54. $limit = 15;
  55. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  56. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  57. $where = [];
  58. if (isset($req['date']) && !empty($req['date'])){
  59. $where['wgjs_rq'] = ['LIKE',$req['date'].'%'];
  60. }else{
  61. $this->error('参数错误');
  62. }
  63. $rows = db()->table('db_wgjs')
  64. ->field('LEFT(wgjs_rq, 10) as wgjs_rq,
  65. wgjs_bh1, CAST(wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1,
  66. wgjs_bh2, CAST(wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2,
  67. wgjs_bh3, CAST(wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3,
  68. wgjs_bh4, CAST(wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4,
  69. wgjs_bh5, CAST(wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5,
  70. wgjs_bh6, CAST(wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6')
  71. ->where($where)
  72. ->order('wgjs_rq desc, UniqId asc')
  73. ->page($page,$limit)
  74. ->select();
  75. $total = db()->table('db_wgjs')->where($where)->count();
  76. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名, 所在部门');
  77. foreach ($rows as $key=>$value){
  78. $rows[$key]['wgjs_js1'] = $value['wgjs_js1'] == 0 ? '' : $value['wgjs_js1'];
  79. //存在该员工编号
  80. if (array_key_exists($value['wgjs_bh1'],$rs)){
  81. $rows[$key]['department'] = trim($rs[$value['wgjs_bh1']]['所在部门']);
  82. $rows[$key]['name1'] = trim($rs[$value['wgjs_bh1']]['员工姓名']);
  83. for ($i=2;$i<=6;$i++){
  84. $rows[$key]['wgjs_js'.$i] = $value['wgjs_js'.$i] == '0.0' ? '' : $value['wgjs_js'.$i];
  85. if ($value['wgjs_bh'.$i]){
  86. if ($value['wgjs_bh'.$i]==$value['wgjs_bh1']){
  87. $rows[$key]['name'.$i] = $rows[$key]['name1'];
  88. }else{
  89. $rows[$key]['name'.$i] = trim($rs[$value['wgjs_bh'.$i]]['员工姓名']);
  90. }
  91. }else{
  92. $rows[$key]['name'.$i] = '';
  93. }
  94. }
  95. }else{
  96. $rows[$key]['department'] = '';
  97. $rows[$key]['name1'] = '';
  98. for ($i=2;$i<=6;$i++){
  99. $rows[$key]['wgjs_js'.$i] = $value['wgjs_js'.$i] == '0.0' ? '' : $value['wgjs_js'.$i];
  100. $rows[$key]['name'.$i] = '';
  101. }
  102. }
  103. }
  104. $data = [
  105. 'total' => $total,
  106. 'rows' => $rows,
  107. ];
  108. $this->success('成功',$data);
  109. }
  110. /**
  111. * 获取计件工计时单信息
  112. * @ApiMethod (GET)
  113. * @param string $UniqId UniqId
  114. */
  115. public function getInfo()
  116. {
  117. //get请求
  118. if(!$this->request->isGet()){
  119. $this->error('请求方式错误');
  120. }
  121. $req = $this->request->param();
  122. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  123. $UniqId = $req['UniqId'];
  124. }else{
  125. $this->error('参数错误');
  126. }
  127. $rows = db()->table('db_wgjs')->alias('d')
  128. ->field('d.*, ')
  129. ->join('工单_基本资料 g', 'd.')
  130. ->where('d.UniqId',$UniqId)
  131. ->select();
  132. $this->success('成功',$rows);
  133. }
  134. }