PackagingProcessOutput.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * 包装工序产量维护接口
  6. */
  7. class PackagingProcessOutput 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(30)
  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[29]['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. }
  50. $this->success('成功',$rows);
  51. }
  52. /**
  53. * 获取包装工序产量列表
  54. * @ApiMethod (GET)
  55. * @param string $date 时间
  56. * @param string $sys_id 用户
  57. */
  58. public function getList()
  59. {
  60. //get请求
  61. if(!$this->request->isGet()){
  62. $this->error('请求方式错误');
  63. }
  64. $req = $this->request->param();
  65. $page = 1;
  66. $limit = 15;
  67. if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
  68. if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
  69. $where = [];
  70. if (isset($req['date']) && !empty($req['date'])){
  71. $where['sys_rq'] = ['LIKE',$req['date'].'%'];
  72. }else{
  73. $this->error('参数错误');
  74. }
  75. if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
  76. $rows = db()->table('db_包装产量预报')
  77. ->field('rtrim(sys_id) as sys_id, sczl_rq,
  78. sczl_cl1 + sczl_cl2 + sczl_cl3 + sczl_cl4 + sczl_cl5 + sczl_cl6 as sczl_cl,
  79. (sczl_cl1 * sczl_PgCl1 + sczl_clAdd1) + (sczl_cl2 * sczl_PgCl2 + sczl_clAdd2) + (sczl_cl3 * sczl_PgCl3 + sczl_clAdd3) + (sczl_cl4 * sczl_PgCl4 + sczl_clAdd4) + (sczl_cl5 * sczl_PgCl5 + sczl_clAdd5) + (sczl_cl6 * sczl_PgCl6 + sczl_clAdd6) as sczl_PgCl,
  80. sys_rq, mod_rq, UniqId')
  81. ->where($where)
  82. ->page($page,$limit)
  83. ->select();
  84. $sczl_cls = $sczl_PgCls = 0;
  85. foreach ($rows as $row){
  86. $sczl_cls += $row['sczl_cl'];
  87. $sczl_PgCls += $row['sczl_PgCl'];
  88. }
  89. $data = [
  90. 'sczl_cls' => $sczl_cls,
  91. 'sczl_PgCls' => $sczl_PgCls,
  92. 'rows' => $rows,
  93. ];
  94. $this->success('成功',$data);
  95. }
  96. /**
  97. * 获取包装工序产量信息
  98. * @ApiMethod (GET)
  99. * @param string $UniqId UniqId
  100. */
  101. public function getInfo()
  102. {
  103. //get请求
  104. if(!$this->request->isGet()){
  105. $this->error('请求方式错误');
  106. }
  107. $req = $this->request->param();
  108. if (isset($req['UniqId']) && !empty($req['UniqId'])){
  109. $UniqId = $req['UniqId'];
  110. }else{
  111. $this->error('参数错误');
  112. }
  113. $rows = db()->table('db_包装产量预报')->alias('d')
  114. ->field('d.*, g1.Gd_cpmc, g2.Gd_cpmc, g3.Gd_cpmc, g4.Gd_cpmc, g5.Gd_cpmc, g6.Gd_cpmc')
  115. ->join(['工单_基本资料'=>'g'], 'd.sczl_gdbh1 = g.Gd_gdbh or '.
  116. 'd.sczl_gdbh2 = g.Gd_gdbh or '.
  117. 'd.sczl_gdbh3 = g.Gd_gdbh or '.
  118. 'd.sczl_gdbh4 = g.Gd_gdbh or '.
  119. 'd.sczl_gdbh5 = g.Gd_gdbh or '.
  120. 'd.sczl_gdbh6 = g.Gd_gdbh')
  121. ->where('d.UniqId',$UniqId)
  122. ->select();
  123. $this->success('成功',$rows);
  124. }
  125. }