MachineProductionReportAdd.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * 机台生产日报表维护附加接口
  6. */
  7. class MachineProductionReportAdd 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_sczladd')
  30. ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
  31. ->group('date')
  32. ->order('UniqId desc')
  33. ->limit(60)
  34. ->select();
  35. $arr = db()->table('db_sczladd')
  36. ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(sys_id) as count')
  37. ->where('sys_rq','>=',$rows[59]['date'])
  38. ->group('date, sys_id')
  39. ->select();
  40. foreach($rows as $key=>$value){
  41. $rows[$key]['sys'] = [];
  42. foreach($arr as $k=>$v){
  43. if($value['date'] == $v['date']){
  44. unset($v['date']);
  45. array_push($rows[$key]['sys'],$v);
  46. unset($arr[$k]);
  47. }
  48. }
  49. $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
  50. }
  51. $this->success('成功',$rows);
  52. }
  53. /**
  54. * 获取机台生产日报表附加列表
  55. * @ApiMethod (GET)
  56. * @param string $date 时间
  57. * @param string $sys_id 用户
  58. */
  59. public function getList()
  60. {
  61. //get请求
  62. if(!$this->request->isGet()){
  63. $this->error('请求方式错误');
  64. }
  65. $req = $this->request->param();
  66. $page = 1;
  67. $limit = 15;
  68. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  69. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  70. $where = [];
  71. if (isset($req['date']) && !empty($req['date'])){
  72. $where['sys_rq'] = ['LIKE',$req['date'].'%'];
  73. }else{
  74. $this->error('参数错误');
  75. }
  76. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  77. //来料异常 日定额 千件工价 补产标准
  78. //制程废 次品
  79. $rows = db()->table('db_sczladd')
  80. ->field('LEFT(sczl_rq, 10) as sczl_rq, sczl_jtbh,
  81. sczl_bzdh, CAST(sczl_设备运行工时 AS SIGNED) as sczl_设备运行工时, sczl_desc,
  82. rtrim(sys_id) as sys_id, sys_rq, mod_rq, UniqId')
  83. ->where($where)
  84. ->order('UniqId desc')
  85. ->page($page,$limit)
  86. ->select();
  87. $total = db()->table('db_sczladd')->where($where)->count();
  88. $sb = db()->table('设备_基本资料')->column('设备编号, 设备名称');
  89. foreach ($rows as $key=>$value){
  90. $rows[$key]['mod_rq'] = $value['mod_rq']=='1900-01-01 00:00:00' ? '' :$value['mod_rq'];
  91. $rows[$key]['sczl_sbmc'] = trim($sb[$value['sczl_jtbh']]);
  92. $rows[$key]['sczl_设备运行工时'] = $value['sczl_设备运行工时'] == 0 ? '' : $value['sczl_设备运行工时'];
  93. }
  94. $data = [
  95. 'total' => $total,
  96. 'rows' => $rows,
  97. ];
  98. $this->success('成功',$data);
  99. }
  100. /**
  101. * 获取机台生产日报表附加信息
  102. * @ApiMethod (GET)
  103. * @param string $UniqId UniqId
  104. */
  105. public function getInfo()
  106. {
  107. //get请求
  108. if(!$this->request->isGet()){
  109. $this->error('请求方式错误');
  110. }
  111. $req = $this->request->param();
  112. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  113. $UniqId = $req['UniqId'];
  114. }else{
  115. $this->error('参数错误');
  116. }
  117. $rows = db()->table('db_sczl')->alias('d')
  118. ->field('d.*, ')
  119. ->join('工单_基本资料 g', 'd.')
  120. ->where('d.UniqId',$UniqId)
  121. ->select();
  122. $this->success('成功',$rows);
  123. }
  124. }