Decision.php 10 KB

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