Decision.php 10 KB

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