Decision.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Request;
  6. /**
  7. * 设备运行跟踪
  8. */
  9. class Decision extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. //月度产量统计菜单
  14. public function OutputSstatisticsMenu()
  15. {
  16. if ($this->request->isGet() === false){
  17. $this->error('请求错误');
  18. }
  19. $mouth = \db('设备_产量计酬')
  20. ->whereTime('sczl_rq', 'month')
  21. ->field('DATE_FORMAT(sczl_rq, "%Y-%m") AS month')
  22. ->group('month')
  23. ->order('month desc')
  24. ->select();
  25. $sist = \db('设备_基本资料')
  26. ->field('rtrim(设备编组) as 设备编组')
  27. ->whereNotNull('设备编组')
  28. ->group('设备编组')
  29. ->select();
  30. $data = [];
  31. foreach ($mouth as $key=>$value) {
  32. $time = date('Ym',strtotime($value['month']));
  33. $data[$time] = $sist;
  34. }
  35. $this->success('成功',$data);
  36. }
  37. /**
  38. * 月度产量统计上方机台生产数据
  39. * @return void
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. * @throws \think\exception\DbException
  43. */
  44. public function MachineProduction()
  45. {
  46. if ($this->request->isGet() === false){
  47. $this->error('请求错误');
  48. }
  49. $param = $this->request->param();
  50. if (empty($param['mouth']) || empty($param['sist'])){
  51. $this->error('参数错误');
  52. }
  53. $mouth = date('Y-m',strtotime($param['mouth']));
  54. $machine = \db('设备_基本资料')
  55. ->where('设备编组',$param['sist'])
  56. ->field('设备编号')
  57. ->select();
  58. $day = \db('设备_产量计酬')
  59. ->field('DATE(sczl_rq) as day')
  60. ->whereTime('sczl_rq',$mouth)
  61. ->group('day')
  62. ->order('day')
  63. ->select();
  64. $day = array_reduce($day, function($carry, $item) {
  65. return array_merge($carry, array_values($item));
  66. }, []);
  67. $data = [];
  68. $data['head'] = $day;
  69. foreach ($machine as $key=>$value){
  70. $data['total'][$key] = \db('设备_产量计酬')
  71. ->field('sczl_jtbh,sczl_bzdh,SUM(sczl_cl) as total_cl')
  72. ->whereTime('sczl_rq',$mouth)
  73. ->where('sczl_jtbh',$value['设备编号'])
  74. ->group('sczl_jtbh,sczl_bzdh')
  75. ->order('sczl_jtbh')
  76. ->select();
  77. foreach ($data['total'][$key] as $k=>$v){
  78. $day_total = db('设备_产量计酬')
  79. ->field('DATE(sczl_rq) as day, SUM(sczl_cl) as total_cl')
  80. ->whereTime('sczl_rq', $mouth)
  81. ->where('sczl_jtbh', $value['设备编号'])
  82. ->where('sczl_bzdh', $v['sczl_bzdh'])
  83. ->group('sczl_bzdh,day')
  84. ->select();
  85. $day_total = array_column($day_total, 'total_cl', 'day');
  86. $data['total'][$key][$k]['day_total'] = $day_total;
  87. }
  88. }
  89. $this->success('成功',$data);
  90. }
  91. /**
  92. * 机台班次生产工单明细
  93. * @return void
  94. * @throws \think\db\exception\DataNotFoundException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. * @throws \think\exception\DbException
  97. */
  98. public function MachineProductDetail()
  99. {
  100. if ($this->request->isGet() === false){
  101. $this->error('请求错误');
  102. }
  103. $param = $this->request->param();
  104. if (empty($param['mouth']) || empty($param['machine']) || empty($param['team'])){
  105. $this->error('参数错误');
  106. }
  107. $mouth = date('Y-m',strtotime($param['mouth']));
  108. $team = substr($param['team'],0,1);
  109. $list = \db('设备_产量计酬')
  110. ->alias('a')
  111. ->join('工单_印件资料 c','a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno')
  112. ->join('工单_工艺资料 d','a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh')
  113. ->field([
  114. 'a.sczl_gdbh' => '工单编号',
  115. 'a.sczl_yjno' => '印件号',
  116. 'a.sczl_gxh' => '工序号',
  117. 'c.yj_yjmc' => '印件名称',
  118. 'd.Gy0_gxmc' => '工序名称',
  119. 'DATE(a.sczl_rq)' => '工作日期',
  120. 'a.sczl_jtbh' => '机台编号',
  121. 'a.sczl_bzdh' => '班组编号',
  122. 'SUM(a.sczl_cl)' => '产量',
  123. 'a.sczl_ms' => '墨色数'
  124. ])
  125. ->whereTime('a.sczl_rq',$mouth)
  126. ->where('a.sczl_jtbh',$param['machine'])
  127. ->where('a.sczl_bzdh','like',$team.'%')
  128. ->group('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh')
  129. ->order('工作日期')
  130. ->select();
  131. if (!empty($list)){
  132. foreach ($list as $key=>$value){
  133. $list[$key]['印件名称'] = $value['印件号'].'-'.$value['印件名称'];
  134. $list[$key]['工序名称'] = $value['工序号'].'-'.$value['工序名称'];
  135. unset($list[$key]['印件号'],$list[$key]['工序号']);
  136. }
  137. }
  138. $this->success('成功',$list);
  139. }
  140. /**
  141. * 月度机台运行工时汇总
  142. * @return void
  143. * @throws \think\db\exception\DataNotFoundException
  144. * @throws \think\db\exception\ModelNotFoundException
  145. * @throws \think\exception\DbException
  146. */
  147. public function MachineOperation()
  148. {
  149. if ($this->request->isGet() === false){
  150. $this->error('请求错误');
  151. }
  152. $param = $this->request->param();
  153. if (empty($param['mouth']) || empty($param['sist'])){
  154. $this->error('参数错误');
  155. }
  156. $mouth = date('Y-m',strtotime($param['mouth']));
  157. $list = \db('设备_基本资料')
  158. ->alias('a')
  159. ->join('设备_产量计酬 b','a.设备编号 = b.sczl_jtbh')
  160. ->field([
  161. 'a.设备编号' => '设备编号',
  162. 'rtrim(a.设备名称)' => '设备名称',
  163. 'SUM(b.sczl_cl)' => '产量',
  164. 'SUM(b.sczl_设备运行工时)' => '设备运行工时',
  165. 'SUM(b.sczl_保养工时)' => '保养工时',
  166. 'SUM(b.sczl_打样总工时)' => '打样总工时',
  167. 'SUM(b.sczl_打样工时)' => '打样补产工时',
  168. 'SUM(b.sczl_装版总工时)' => '装板总工时',
  169. 'SUM(b.sczl_装版工时)' => '装板补产工时',
  170. 'SUM(b.sczl_异常停机工时)' => '异常停机工时'
  171. ])
  172. ->where('a.设备编组',$param['sist'])
  173. ->whereTime('b.sczl_rq',$mouth)
  174. ->group('a.设备编号')
  175. ->order('a.设备编号')
  176. ->select();
  177. $total = \db('设备_基本资料')
  178. ->alias('a')
  179. ->join('设备_产量计酬 b','a.设备编号 = b.sczl_jtbh')
  180. ->field([
  181. 'SUM(b.sczl_设备运行工时)' => '设备运行工时',
  182. 'SUM(b.sczl_保养工时)' => '保养工时',
  183. 'SUM(b.sczl_打样总工时)' => '打样总工时',
  184. 'SUM(b.sczl_打样工时)' => '打样补产工时',
  185. 'SUM(b.sczl_装版总工时)' => '装板总工时',
  186. 'SUM(b.sczl_装版工时)' => '装板补产工时',
  187. 'SUM(b.sczl_异常停机工时)' => '异常停机工时'
  188. ])
  189. ->where('a.设备编组',$param['sist'])
  190. ->whereTime('b.sczl_rq',$mouth)
  191. ->find();
  192. $list['total'] = $total;
  193. $this->success('成功',$list);
  194. }
  195. /**
  196. * 设备运行工时机台生产工单数据详情
  197. * @return void
  198. * @throws \think\db\exception\DataNotFoundException
  199. * @throws \think\db\exception\ModelNotFoundException
  200. * @throws \think\exception\DbException
  201. */
  202. public function MachineOperationProductDetail()
  203. {
  204. if ($this->request->isGet() === false){
  205. $this->error('请求错误');
  206. }
  207. $param = $this->request->param();
  208. if (empty($param['mouth']) || empty($param['machine'])){
  209. $this->error('参数错误');
  210. }
  211. $mouth = date('Y-m',strtotime($param['mouth']));
  212. $list = \db('设备_产量计酬')
  213. ->alias('a')
  214. ->join('设备_基本资料 b','a.sczl_jtbh = b.设备编号')
  215. ->join('工单_印件资料 c','a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno')
  216. ->join('工单_工艺资料 d','a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh')
  217. ->field([
  218. 'a.sczl_jtbh' => '设备编号',
  219. 'rtrim(b.设备名称)' => '设备名称',
  220. 'DATE(a.sczl_rq)' => '日期',
  221. 'a.sczl_gdbh' => '工单编号',
  222. 'a.sczl_yjno' => '印件号',
  223. 'a.sczl_gxh' => '工序号',
  224. 'c.yj_yjmc' => '印件名称',
  225. 'd.Gy0_gxmc' => '工序名称',
  226. 'SUM(a.sczl_cl)' => '产量',
  227. 'SUM(a.sczl_设备运行工时)' => '设备运行工时',
  228. 'SUM(a.sczl_保养工时)' => '保养工时',
  229. 'SUM(a.sczl_打样总工时)' => '打样总工时',
  230. 'SUM(a.sczl_打样工时)' => '打样补产工时',
  231. 'SUM(a.sczl_装版总工时)' => '装板总工时',
  232. 'SUM(a.sczl_装版工时)' => '装板补产工时',
  233. 'SUM(a.sczl_异常停机工时)' => '异常停机工时',
  234. 'a.sczl_ms' => '墨色数'
  235. ])
  236. ->whereTime('a.sczl_rq',$mouth)
  237. ->where('a.sczl_jtbh',$param['machine'])
  238. ->group('a.sczl_rq,a.sczl_gdbh')
  239. ->order('a.sczl_rq')
  240. ->select();
  241. if (!empty($list)){
  242. foreach ($list as $key=>$value){
  243. $list[$key]['工序名称'] = $value['印件号'].'-'.$value['工序号'].'-'.$value['工序名称'];
  244. unset($list[$key]['印件号'],$list[$key]['工序号']);
  245. }
  246. }
  247. $this->success('成功',$list);
  248. }
  249. }