WorkOrderSpotCheck.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * 工单抽检记录维护接口
  6. */
  7. class WorkOrderSpotCheck 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_抽检记录')
  30. ->field('LEFT(Sys_rq, 10) as date, COUNT(*) as counts')
  31. ->group('date')
  32. ->order('UniqId desc')
  33. ->limit(45)
  34. ->select();
  35. $arr = db()->table('db_抽检记录')
  36. ->field('LEFT(Sys_rq, 10) as date, rtrim(Sys_id) as Sys_id, COUNT(Sys_id) as count')
  37. ->where('Sys_rq','>=',$rows[44]['date'])
  38. ->group('date, Sys_id')
  39. ->order('UniqId desc')
  40. ->select();
  41. foreach($rows as $key=>$value){
  42. $rows[$key]['sys'] = [];
  43. foreach($arr as $k=>$v){
  44. if($value['date'] == $v['date']){
  45. unset($v['date']);
  46. array_push($rows[$key]['sys'],$v);
  47. unset($arr[$k]);
  48. }
  49. }
  50. $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
  51. }
  52. $this->success('成功',$rows);
  53. }
  54. /**
  55. * 获取工单抽检记录列表
  56. * @ApiMethod (GET)
  57. * @param string $date 时间
  58. * @param string $sys_id 用户
  59. */
  60. public function getList()
  61. {
  62. //get请求
  63. if(!$this->request->isGet()){
  64. $this->error('请求方式错误');
  65. }
  66. $req = $this->request->param();
  67. $page = 1;
  68. $limit = 15;
  69. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  70. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  71. $where = [];
  72. if (isset($req['date']) && !empty($req['date'])){
  73. $where['Sys_rq'] = ['LIKE',$req['date'].'%'];
  74. }else{
  75. $this->error('参数错误');
  76. }
  77. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['Sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  78. $rows = db()->table('db_抽检记录')
  79. ->field('LEFT(Sczl_rq, 10) as Sczl_rq, Sczl_bh, Sczl_gdbh, rtrim(Sczl_gxmc) as Sczl_gxmc,
  80. sczl_yjno, sczl_gxh, Sczl_num, Sczl_抽检数, sczl_A类废, sczl_B类废, sczl_C类废,
  81. rtrim(Sczl_desc) as Sczl_desc, rtrim(Sys_id) as Sys_id, Sys_rq, Mod_rq, UniqId')
  82. ->where($where)
  83. ->order('UniqId asc')
  84. ->page($page,$limit)
  85. ->select();
  86. $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
  87. $rs = db()->table('人事_基本资料')->column('员工编号, 员工姓名');
  88. foreach ($rows as $key=>$value) {
  89. $rows[$key]['Mod_rq'] = $value['Mod_rq']=='1900-01-01 00:00:00' ? '' :$value['Mod_rq'];
  90. $rows[$key]['Gd_cpmc'] = array_key_exists($value['Sczl_gdbh'],$gd) ? trim($gd[$value['Sczl_gdbh']]) : '';
  91. $rows[$key]['name'] = array_key_exists($value['Sczl_bh'],$rs) ? trim($rs[$value['Sczl_bh']]) : '';
  92. }
  93. $data = [
  94. 'rows' => $rows,
  95. ];
  96. $this->success('成功',$data);
  97. }
  98. /**
  99. * 获取工单抽检记录信息
  100. * @ApiMethod (GET)
  101. * @param string $UniqId UniqId
  102. */
  103. public function getInfo()
  104. {
  105. //get请求
  106. if(!$this->request->isGet()){
  107. $this->error('请求方式错误');
  108. }
  109. $req = $this->request->param();
  110. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  111. $UniqId = $req['UniqId'];
  112. }else{
  113. $this->error('参数错误');
  114. }
  115. $rows = db()->table('db_抽检记录')->alias('d')
  116. ->field('d.*, ')
  117. ->join('工单_基本资料 g', 'd.')
  118. ->where('d.UniqId',$UniqId)
  119. ->select();
  120. $this->success('成功',$rows);
  121. }
  122. }