Decision.php 10 KB

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