PieceWorkSchedule.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 PieceWorkSchedule 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. $rows = db()->table('db_wgjs')
  32. ->field('LEFT(wgjs_rq, 7) as date')
  33. ->group('date')
  34. ->order('UniqId desc')
  35. ->limit(15)
  36. ->select();
  37. foreach($rows as $key=>$value){
  38. $rows[$key]['date'] = str_replace('-', '', $rows[$key]['date']);
  39. }
  40. $this->success('成功',$rows);
  41. }
  42. /**
  43. * 获取计件工计时单列表
  44. * @ApiMethod (GET)
  45. * @param string $date 时间
  46. * @param string $Sczl_bh1 员工编号
  47. */
  48. public function getList()
  49. {
  50. //get请求
  51. if(!$this->request->isGet()){
  52. $this->error('请求方式错误');
  53. }
  54. $req = $this->request->param();
  55. $page = 1;
  56. $limit = 15;
  57. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  58. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  59. $where = [];
  60. if (isset($req['date']) && !empty($req['date'])){
  61. $where['wgjs_rq'] = ['LIKE',$req['date'].'%'];
  62. }else{
  63. $this->error('参数错误');
  64. }
  65. $rows = db()->table('db_wgjs')
  66. ->field('LEFT(wgjs_rq, 10) as wgjs_rq,
  67. wgjs_bh1, CAST(wgjs_js1 AS SIGNED) as wgjs_js1, rtrim(wgjs_yy1) as wgjs_yy1,
  68. wgjs_bh2, CAST(wgjs_js2 AS SIGNED) as wgjs_js2, rtrim(wgjs_yy2) as wgjs_yy2,
  69. wgjs_bh3, CAST(wgjs_js3 AS SIGNED) as wgjs_js3, rtrim(wgjs_yy3) as wgjs_yy3,
  70. wgjs_bh4, CAST(wgjs_js4 AS SIGNED) as wgjs_js4, rtrim(wgjs_yy4) as wgjs_yy4,
  71. wgjs_bh5, CAST(wgjs_js5 AS SIGNED) as wgjs_js5, rtrim(wgjs_yy5) as wgjs_yy5,
  72. wgjs_bh6, CAST(wgjs_js6 AS SIGNED) as wgjs_js6, rtrim(wgjs_yy6) as wgjs_yy6')
  73. ->where($where)
  74. ->order('wgjs_rq desc, UniqId asc')
  75. ->page($page,$limit)
  76. ->select();
  77. $total = db()->table('db_wgjs')->where($where)->count();
  78. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名, 所在部门');
  79. foreach ($rows as $key=>$value){
  80. $rows[$key]['wgjs_js1'] = $value['wgjs_js1'] == 0 ? '' : $value['wgjs_js1'];
  81. //存在该员工编号
  82. if (array_key_exists($value['wgjs_bh1'],$rs)){
  83. $rows[$key]['department'] = trim($rs[$value['wgjs_bh1']]['所在部门']);
  84. $rows[$key]['name1'] = trim($rs[$value['wgjs_bh1']]['员工姓名']);
  85. for ($i=2;$i<=6;$i++){
  86. $rows[$key]['wgjs_js'.$i] = $value['wgjs_js'.$i] == '0.0' ? '' : $value['wgjs_js'.$i];
  87. if ($value['wgjs_bh'.$i]){
  88. if ($value['wgjs_bh'.$i]==$value['wgjs_bh1']){
  89. $rows[$key]['name'.$i] = $rows[$key]['name1'];
  90. }else{
  91. $rows[$key]['name'.$i] = trim($rs[$value['wgjs_bh'.$i]]['员工姓名']);
  92. }
  93. }else{
  94. $rows[$key]['name'.$i] = '';
  95. }
  96. }
  97. }else{
  98. $rows[$key]['department'] = '';
  99. $rows[$key]['name1'] = '';
  100. for ($i=2;$i<=6;$i++){
  101. $rows[$key]['wgjs_js'.$i] = $value['wgjs_js'.$i] == '0.0' ? '' : $value['wgjs_js'.$i];
  102. $rows[$key]['name'.$i] = '';
  103. }
  104. }
  105. }
  106. $data = [
  107. 'total' => $total,
  108. 'rows' => $rows,
  109. ];
  110. $this->success('成功',$data);
  111. }
  112. /**
  113. * 获取计件工计时单信息
  114. * @ApiMethod (GET)
  115. * @param string $UniqId UniqId
  116. */
  117. public function getInfo()
  118. {
  119. //get请求
  120. if(!$this->request->isGet()){
  121. $this->error('请求方式错误');
  122. }
  123. $req = $this->request->param();
  124. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  125. $UniqId = $req['UniqId'];
  126. }else{
  127. $this->error('参数错误');
  128. }
  129. $rows = db()->table('db_wgjs')->alias('d')
  130. ->field('d.*, ')
  131. ->join('工单_基本资料 g', 'd.')
  132. ->where('d.UniqId',$UniqId)
  133. ->select();
  134. $this->success('成功',$rows);
  135. }
  136. /**
  137. * 定位
  138. * @ApiMethod GET
  139. * @params date $data
  140. * @params string code
  141. */
  142. public function locate(){
  143. if (Request::instance()->isGet() == false){
  144. $this->error('非法请求');
  145. }
  146. $params = Request::instance()->param();
  147. if (!isset($params['code']) || !isset($params['date'])){
  148. $this->error('参数错误');
  149. }
  150. halt($params);
  151. }
  152. }