Decision.php 11 KB

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