Decision.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. $mouth = date('Y-m',strtotime($param['mouth']));
  116. $team = substr($param['team'],0,1);
  117. $list = \db('设备_产量计酬')
  118. ->alias('a')
  119. ->join('工单_印件资料 c','a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno')
  120. ->join('工单_工艺资料 d','a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh')
  121. ->field([
  122. 'a.sczl_gdbh' => '工单编号',
  123. 'a.sczl_yjno' => '印件号',
  124. 'a.sczl_gxh' => '工序号',
  125. 'c.yj_yjmc' => '印件名称',
  126. 'd.Gy0_gxmc' => '工序名称',
  127. 'DATE(a.sczl_rq)' => '工作日期',
  128. 'a.sczl_jtbh' => '机台编号',
  129. 'a.sczl_bzdh' => '班组编号',
  130. 'SUM(a.sczl_cl)' => '产量',
  131. 'a.sczl_ms' => '墨色数'
  132. ])
  133. ->whereTime('a.sczl_rq',$mouth)
  134. ->where('a.sczl_jtbh',$param['machine'])
  135. ->where('a.sczl_bzdh','like',$team.'%')
  136. ->group('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh')
  137. ->order('工作日期')
  138. ->select();
  139. if (!empty($list)){
  140. foreach ($list as $key=>$value){
  141. $list[$key]['印件名称'] = $value['印件号'].'-'.$value['印件名称'];
  142. $list[$key]['工序名称'] = $value['工序号'].'-'.$value['工序名称'];
  143. unset($list[$key]['印件号'],$list[$key]['工序号']);
  144. }
  145. }
  146. $this->success('成功',$list);
  147. }
  148. /**
  149. * 月度机台运行工时汇总
  150. * @return void
  151. * @throws \think\db\exception\DataNotFoundException
  152. * @throws \think\db\exception\ModelNotFoundException
  153. * @throws \think\exception\DbException
  154. */
  155. public function MachineOperation()
  156. {
  157. if ($this->request->isGet() === false){
  158. $this->error('请求错误');
  159. }
  160. $param = $this->request->param();
  161. if (empty($param['mouth'])){
  162. $this->error('参数错误');
  163. }
  164. $where = [];
  165. if(!empty($param['sist'])){
  166. $where['设备编组'] = $param['sist'];
  167. }
  168. $mouth = date('Y-m',strtotime($param['mouth']));
  169. $list = \db('设备_基本资料')
  170. ->alias('a')
  171. ->join('设备_产量计酬 b','a.设备编号 = b.sczl_jtbh')
  172. ->field([
  173. 'a.设备编号' => '设备编号',
  174. 'rtrim(a.设备名称)' => '设备名称',
  175. 'SUM(b.sczl_cl)' => '产量',
  176. 'SUM(b.sczl_设备运行工时)' => '设备运行工时',
  177. 'SUM(b.sczl_保养工时)' => '保养工时',
  178. 'SUM(b.sczl_打样总工时)' => '打样总工时',
  179. 'SUM(b.sczl_打样工时)' => '打样补产工时',
  180. 'SUM(b.sczl_装版总工时)' => '装板总工时',
  181. 'SUM(b.sczl_装版工时)' => '装板补产工时',
  182. 'SUM(b.sczl_异常停机工时)' => '异常停机工时'
  183. ])
  184. ->where($where)
  185. ->whereTime('b.sczl_rq',$mouth)
  186. ->group('a.设备编号')
  187. ->order('a.设备编号')
  188. ->select();
  189. $total = \db('设备_基本资料')
  190. ->alias('a')
  191. ->join('设备_产量计酬 b','a.设备编号 = b.sczl_jtbh')
  192. ->field([
  193. 'SUM(b.sczl_设备运行工时)' => '设备运行工时',
  194. 'SUM(b.sczl_保养工时)' => '保养工时',
  195. 'SUM(b.sczl_打样总工时)' => '打样总工时',
  196. 'SUM(b.sczl_打样工时)' => '打样补产工时',
  197. 'SUM(b.sczl_装版总工时)' => '装板总工时',
  198. 'SUM(b.sczl_装版工时)' => '装板补产工时',
  199. 'SUM(b.sczl_异常停机工时)' => '异常停机工时'
  200. ])
  201. ->where($where)
  202. ->whereTime('b.sczl_rq',$mouth)
  203. ->find();
  204. $list['total'] = $total;
  205. $this->success('成功',$list);
  206. }
  207. /**
  208. * 设备运行工时机台生产工单数据详情
  209. * @return void
  210. * @throws \think\db\exception\DataNotFoundException
  211. * @throws \think\db\exception\ModelNotFoundException
  212. * @throws \think\exception\DbException
  213. */
  214. public function MachineOperationProductDetail()
  215. {
  216. if ($this->request->isGet() === false){
  217. $this->error('请求错误');
  218. }
  219. $param = $this->request->param();
  220. if (empty($param['mouth']) || empty($param['machine'])){
  221. $this->error('参数错误');
  222. }
  223. $mouth = date('Y-m',strtotime($param['mouth']));
  224. $list = \db('设备_产量计酬')
  225. ->alias('a')
  226. ->join('设备_基本资料 b','a.sczl_jtbh = b.设备编号')
  227. ->join('工单_印件资料 c','a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno')
  228. ->join('工单_工艺资料 d','a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh')
  229. ->field([
  230. 'a.sczl_jtbh' => '设备编号',
  231. 'rtrim(b.设备名称)' => '设备名称',
  232. 'DATE(a.sczl_rq)' => '日期',
  233. 'a.sczl_gdbh' => '工单编号',
  234. 'a.sczl_yjno' => '印件号',
  235. 'a.sczl_gxh' => '工序号',
  236. 'c.yj_yjmc' => '印件名称',
  237. 'd.Gy0_gxmc' => '工序名称',
  238. 'SUM(a.sczl_cl)' => '产量',
  239. 'SUM(a.sczl_设备运行工时)' => '设备运行工时',
  240. 'SUM(a.sczl_保养工时)' => '保养工时',
  241. 'SUM(a.sczl_打样总工时)' => '打样总工时',
  242. 'SUM(a.sczl_打样工时)' => '打样补产工时',
  243. 'SUM(a.sczl_装版总工时)' => '装板总工时',
  244. 'SUM(a.sczl_装版工时)' => '装板补产工时',
  245. 'SUM(a.sczl_异常停机工时)' => '异常停机工时',
  246. 'a.sczl_ms' => '墨色数'
  247. ])
  248. ->whereTime('a.sczl_rq',$mouth)
  249. ->where('a.sczl_jtbh',$param['machine'])
  250. ->group('a.sczl_rq,a.sczl_gdbh')
  251. ->order('a.sczl_rq')
  252. ->select();
  253. if (!empty($list)){
  254. foreach ($list as $key=>$value){
  255. $list[$key]['工序名称'] = $value['印件号'].'-'.$value['工序号'].'-'.$value['工序名称'];
  256. unset($list[$key]['印件号'],$list[$key]['工序号']);
  257. }
  258. }
  259. $this->success('成功',$list);
  260. }
  261. }