Index.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 首页接口
  7. */
  8. class Index extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 首页
  14. *
  15. */
  16. public function index()
  17. {
  18. $this->success('请求成功');
  19. }
  20. //计划/排程/制程工单数量同步Redis
  21. public function numDbToRedis()
  22. {
  23. $numDbToRedis = [];
  24. //获取计划中的订单数量
  25. $jhz = db('工单_基本资料')
  26. ->where('gd_statu','like','%计划中%')
  27. ->count('Gd_gdbh');
  28. if($jhz!==false){
  29. $numDbToRedis['jhz'] = $jhz;
  30. }else{
  31. $numDbToRedis['jhz'] = 0;
  32. }
  33. //获取生产中的所有数据
  34. $rows = db('工单_基本资料')
  35. ->distinct('Gd_gdbh')
  36. ->where('gd_statu','like','%生产中%')
  37. ->column('Gd_gdbh');
  38. if($rows===false){
  39. $numDbToRedis['pcz'] = 0;
  40. $numDbToRedis['zcz'] = 0;
  41. $bool = cache('numDbToRedis',$jhz);
  42. if($bool===false) $this->error('订单数量存入redis失败','','000001');
  43. $this->success('请求成功');
  44. }
  45. //查询Gy0_sj1不等于1900-01-01 00:00:00的数据
  46. $data = db('工单_印件资料')->alias('y')
  47. ->join('工单_工艺资料 g','y.Yj_Gdbh = g.Gy0_gdbh AND y.yj_Yjno = g.Gy0_yjno')
  48. ->where('g.Gy0_sj1','<>','1900-01-01 00:00:00')
  49. ->where('y.Yj_Gdbh','in',$rows)
  50. ->group('y.Yj_Gdbh')
  51. ->column('y.Yj_Gdbh');
  52. $zcz = count($data);
  53. $pcz = count($rows) - count($data);
  54. $numDbToRedis['pcz'] = $pcz;
  55. $numDbToRedis['zcz'] = $zcz;
  56. $bool = cache('numDbToRedis',$numDbToRedis);
  57. if($bool===false) $this->error('订单数量存入redis失败','','000002');
  58. $this->success('同步成功');
  59. }
  60. //获取计划中工单数量
  61. public function getJhzByRedis()
  62. {
  63. $row = cache('numDbToRedis');
  64. if($row){
  65. $data = [
  66. 'status'=>0,
  67. 'msg'=>'',
  68. 'data'=>[
  69. 'name'=>'',
  70. 'value'=>$row['jhz']
  71. ]
  72. ];
  73. return json($data);
  74. }else{
  75. $data = [
  76. 'status'=>0,
  77. 'msg'=>'失败',
  78. 'data'=>[
  79. 'name'=>'',
  80. 'value'=>''
  81. ]
  82. ];
  83. return json($data);
  84. }
  85. }
  86. //获取排程中工单数量
  87. public function getPczByRedis()
  88. {
  89. $row = cache('numDbToRedis');
  90. if($row){
  91. $data = [
  92. 'status'=>0,
  93. 'msg'=>'',
  94. 'data'=>[
  95. 'name'=>'',
  96. 'value'=>$row['pcz']
  97. ]
  98. ];
  99. return json($data);
  100. }else{
  101. $data = [
  102. 'status'=>0,
  103. 'msg'=>'失败',
  104. 'data'=>[
  105. 'name'=>'',
  106. 'value'=>''
  107. ]
  108. ];
  109. return json($data);
  110. }
  111. }
  112. //获取制程中工单数量
  113. public function getZczByRedis()
  114. {
  115. $row = cache('numDbToRedis');
  116. if($row){
  117. $data = [
  118. 'status'=>0,
  119. 'msg'=>'',
  120. 'data'=>[
  121. 'name'=>'',
  122. 'value'=>$row['zcz']
  123. ]
  124. ];
  125. return json($data);
  126. }else{
  127. $data = [
  128. 'status'=>0,
  129. 'msg'=>'失败',
  130. 'data'=>[
  131. 'name'=>'',
  132. 'value'=>''
  133. ]
  134. ];
  135. return json($data);
  136. }
  137. }
  138. //印刷车间生产进度数据同步Redis
  139. public function yscjDbToRedis()
  140. {
  141. $yscjDbToRedis = [];
  142. //获取所有印刷车间
  143. // $rows = db('设备_基本资料')
  144. // ->where('使用部门','凹丝印车间')
  145. // ->column('设备编号');
  146. $rows = db('设备_基本资料')
  147. ->whereIn('使用部门', ['凹丝印车间', '胶印车间'])
  148. ->column('设备编号');
  149. foreach($rows as $value){
  150. $row = db('设备_产量采集')->alias('c')
  151. ->field('c.设备编号 as 机台号,
  152. c.工单编号 as 在产工单号,
  153. j.Gd_cpmc as 工单名称,
  154. c.工序名称 as 工序,
  155. g.Gy0_计划接货数 as 计划产量,
  156. g.Gy0_小时产能 as 小时产能,
  157. c.当前状态 as 机台状态
  158. ')
  159. ->join('工单_工艺资料 g','c.设备编号 = g.Gy0_sbbh AND c.工单编号 = g.Gy0_gdbh AND c.印件号 = g.Gy0_yjno')
  160. ->join('工单_基本资料 j','j.Gd_gdbh = c.工单编号')
  161. ->where('c.设备编号',$value)
  162. ->order('c.UniqId desc')
  163. ->find();
  164. if(!$row) continue;
  165. $cl = db('设备_产量计酬')
  166. ->where(['sczl_gdbh'=>$row['在产工单号'], 'sczl_jtbh' => $row['机台号']])
  167. ->sum('sczl_cl');
  168. $row['已完成产量'] = $cl;
  169. array_push($yscjDbToRedis, $row);
  170. }
  171. $bool = cache('yscjDbToRedis',$yscjDbToRedis);
  172. if($bool===false) $this->error('存入redis失败','','000002');
  173. $this->success('同步成功');
  174. }
  175. //印后车间生产进度数据同步Redis
  176. public function yhcjDbToRedis()
  177. {
  178. $yhcjDbToRedis = [];
  179. //获取所有印后车间
  180. $rows = db('设备_基本资料')
  181. ->where('使用部门','印后车间')
  182. ->column('设备编号');
  183. foreach($rows as $value){
  184. $row = db('设备_产量采集')->alias('c')
  185. ->field('c.设备编号 as 机台号,
  186. c.工单编号 as 在产工单号,
  187. j.Gd_cpmc as 工单名称,
  188. c.工序名称 as 工序,
  189. g.Gy0_计划接货数 as 计划产量,
  190. g.Gy0_小时产能 as 小时产能,
  191. c.当前状态 as 机台状态
  192. ')
  193. ->join('工单_工艺资料 g','c.设备编号 = g.Gy0_sbbh AND c.工单编号 = g.Gy0_gdbh AND c.印件号 = g.Gy0_yjno')
  194. ->join('工单_基本资料 j','j.Gd_gdbh = c.工单编号')
  195. ->where('c.设备编号',$value)
  196. ->order('c.UniqId desc')
  197. ->find();
  198. if(!$row) continue;
  199. $cl = db('设备_产量计酬')
  200. ->where(['sczl_gdbh'=>$row['在产工单号'], 'sczl_jtbh' => $row['机台号']])
  201. ->sum('sczl_cl');
  202. $row['已完成产量'] = $cl;
  203. array_push($yhcjDbToRedis, $row);
  204. }
  205. $bool = cache('yhcjDbToRedis',$yhcjDbToRedis);
  206. if($bool===false) $this->error('存入redis失败','','000002');
  207. $this->success('同步成功');
  208. }
  209. //获取印刷车间生产进度数据
  210. public function getYscjByRedis()
  211. {
  212. $row = cache('yscjDbToRedis');
  213. if (empty($row)) {
  214. return json([
  215. 'status' => 0,
  216. 'msg' => '',
  217. 'data' => [] // 或者可以返回 []
  218. ]);
  219. }
  220. $result['columns'] = [
  221. ['name' => '机台号', 'id' => 'jtbh', 'width' => '11', 'autoWrap' => "true", 'textAlign' => 'left'],
  222. ['name' => '在产工单号', 'id' => 'gdbh', 'width' => '15', 'textAlign' => 'left'],
  223. ['name' => '工单名称', 'id' => 'gdmc', 'width' => '35', 'autoWrap' => "true", 'textAlign' => 'left'],
  224. ['name' => '工序', 'id' => 'gx', 'width' => '15', 'textAlign' => 'left'],
  225. ['name' => '计划产量', 'id' => 'jhcl', 'width' => '8', 'autoWrap' => "true", 'textAlign' => 'left'],
  226. ['name' => '已完成产量', 'id' => 'wccl', 'width' => '9', 'autoWrap' => "true", 'textAlign' => 'center'],
  227. ['name' => '小时产能', 'id' => 'xscn', 'width' => '8', 'autoWrap' => "true", 'textAlign' => 'center'],
  228. ['name' => '机台状态', 'id' => 'status', 'width' => '8', 'autoWrap' => "true", 'textAlign' => 'center'],
  229. ];
  230. foreach ($row as $k => $v) {
  231. $result['rows'][$k] = [
  232. 'jtbh' => $v['机台号'],
  233. 'gdbh' => $v['在产工单号'],
  234. 'gdmc' => $v['工单名称'],
  235. 'gx' => $v['工序'],
  236. 'jhcl' => $v['计划产量'],
  237. 'wccl' => $v['已完成产量'],
  238. 'xscn' => $v['小时产能'],
  239. 'status' => $v['机台状态'],
  240. ];
  241. }
  242. return json([
  243. 'status' => 0,
  244. 'msg' => '',
  245. 'data' => $result
  246. ]);
  247. }
  248. //获取印后车间生产进度数据
  249. public function getYhcjByRedis()
  250. {
  251. $row = cache('yhcjDbToRedis');
  252. $result['columns']=[
  253. ['name'=>'机台号','id'=>'jtbh','width'=>'11','autoWrap'=>"true",'textAlign'=>'left'],
  254. ['name'=>'在产工单号','id'=>'gdbh','width'=>'15','textAlign'=>'left'],
  255. ['name'=>'工单名称','id'=>'gdmc','width'=>'35','autoWrap'=>"true",'textAlign'=>'left'],
  256. ['name'=>'工序','id'=>'gx','width'=>'15','textAlign'=>'left'],
  257. ['name'=>'计划产量','id'=>'jhcl','width'=>'8','autoWrap'=>"true",'textAlign'=>'left'],
  258. ['name'=>'已完成产量','id'=>'wccl','width'=>'9','autoWrap'=>"true",'textAlign'=>'center'],
  259. ['name'=>'小时产能','id'=>'xscn','width'=>'8','autoWrap'=>"true",'textAlign'=>'center'],
  260. ['name'=>'机台状态','id'=>'status','width'=>'8','autoWrap'=>"true",'textAlign'=>'center'],
  261. ];
  262. if($row){
  263. foreach($row as $k=>$v){
  264. $result['rows'][$k]['jtbh']=$v['机台号'];
  265. $result['rows'][$k]['gdbh']=$v['在产工单号'];
  266. $result['rows'][$k]['gdmc']=$v['工单名称'];
  267. $result['rows'][$k]['gx']=$v['工序'];
  268. $result['rows'][$k]['jhcl'] = $v['计划产量'];
  269. $result['rows'][$k]['wccl'] = $v['已完成产量'];
  270. $result['rows'][$k]['xscn'] = $v['小时产能'];
  271. $result['rows'][$k]['status'] = $v['机台状态'];
  272. }
  273. }
  274. $res['status']=0;
  275. $res['msg']='';
  276. $res['data']=$result;
  277. return json($res);
  278. }
  279. //车间产量数据同步Redis
  280. public function jtClDbToRedis()
  281. {
  282. $jtClDbToRedis = [];
  283. //获取机台
  284. $rows = db('设备_基本资料')
  285. ->whereNotNull('sys_sbID')
  286. ->column('设备编号');
  287. //获取24小时内的hour组成数组
  288. $hour = date('H');
  289. $arr1 = range($hour+1,'23');
  290. $arr2 = range('00',$hour);
  291. $arr = array_merge($arr1,$arr2);
  292. $arr = array_map(function($num) {
  293. return sprintf("%02d", $num);
  294. }, $arr);
  295. foreach($rows as $value){
  296. $brr = [];
  297. //查询该机台24内的产量数据
  298. $row = db('设备_产量计酬')
  299. ->where('sys_rq', '>', date('Y-m-d H:i:s', strtotime('-23 hours')))
  300. ->where('sczl_jtbh', $value)
  301. ->group('LEFT(sys_rq, 13)')
  302. ->order('sys_rq')
  303. ->column('DATE_FORMAT(sys_rq, "%H") as hour, SUM(sczl_cl) as total_cl');
  304. //将产量数据赋值给小时
  305. foreach($arr as $v){
  306. $brr[$v] = array_key_exists($v,$row) ? $row[$v] : '0';
  307. }
  308. $jtClDbToRedis[$value] = $brr;
  309. }
  310. $bool = cache('jtClDbToRedis',$jtClDbToRedis);
  311. if($bool===false) $this->error('存入redis失败','','000002');
  312. $this->success('同步成功');
  313. }
  314. //获取机台产量数据
  315. public function getJtClDbByRedis()
  316. {
  317. $req = $this->request->param();
  318. if (isset($req['jtbh']) && !empty($req['jtbh'])){
  319. $jtbh = $req['jtbh'];
  320. }else{
  321. $this->error('参数错误');
  322. }
  323. $row = cache('jtClDbToRedis');
  324. $result['categories']=[];
  325. $result['series'][0]['name']=$jtbh;
  326. $result['series'][0]['data']=[];
  327. if($row && array_key_exists($jtbh,$row)){
  328. $result['categories'] = array_map('strval', array_keys($row[$jtbh]));
  329. $result['series'][0]['data'] = array_values($row[$jtbh]);
  330. }
  331. $res['status']=0;
  332. $res['msg']='';
  333. $res['data']=$result;
  334. return json($res);
  335. }
  336. /**
  337. * 班组工作中心负荷
  338. */
  339. public function bzDbToRedis()
  340. {
  341. $bzDbToRedis = [];
  342. //计算当天时间
  343. $sczlTime = date('Y-m-d H:i:s',time());
  344. if ($sczlTime>date('Y-m-d 00:00:00') && $sczlTime<date('Y-m-d 08:30:00')){
  345. $time = date('Y-m-d 00:00:00',time()-86400);
  346. }else{
  347. $time = date('Y-m-d 00:00:00');
  348. }
  349. //获取所有机台数据
  350. $machineList = db('设备_基本资料')
  351. ->where('sys_sbID','<>','')
  352. ->where('使用部门','in',['印刷车间','印后车间'])
  353. ->field('设备编号')
  354. ->select();
  355. //循环获取班组、工单、生产数据
  356. foreach ($machineList as $key=>$value){
  357. //获取正在生产工单信息
  358. $workOrder = \db('设备_产量采集')
  359. ->where('设备编号',$value['设备编号'])
  360. ->field('工单编号,印件号,工序号,工序名称,当前状态')
  361. ->order('UniqId desc')
  362. ->find();
  363. if (!$workOrder) continue;
  364. //获取生产信息
  365. $list = db('设备_产量计酬')
  366. ->alias('a')
  367. ->join('工单_基本资料 b','b.Gd_gdbh = a.sczl_gdbh')
  368. ->join('工单_工艺资料 c','a.sczl_gdbh = c.Gy0_gdbh AND a.sczl_yjno = c.Gy0_yjno AND a.sczl_gxh = c.Gy0_gxh')
  369. ->field([
  370. 'SUM(a.sczl_cl)' => '已完成产量',
  371. 'b.成品名称' => '产品名称',
  372. 'c.Gy0_计划接货数' => '计划产量',
  373. 'c.Gy0_小时产能' => '小时产能',
  374. 'a.sczl_bzdh' => '班组代号'
  375. ])
  376. ->where([
  377. 'a.sczl_jtbh' => $value['设备编号'],
  378. 'a.sczl_gdbh' => $workOrder['工单编号'],
  379. 'a.sczl_yjno' => $workOrder['印件号'],
  380. 'a.sczl_gxh' => $workOrder['工序号'],
  381. 'a.sczl_rq' => $time
  382. ])
  383. ->group('a.sczl_jtbh,a.sczl_bzdh')
  384. ->select();
  385. if (!$list) continue;
  386. foreach ($list as $v){
  387. $v['机台号'] = $value['设备编号'];
  388. $v['机台状态'] = $workOrder['当前状态'];
  389. $v['工单编号'] = $workOrder['工单编号'];
  390. $v['印件号'] = $workOrder['印件号'];
  391. $v['工序名称'] = $workOrder['工序名称'];
  392. array_push($bzDbToRedis,$v);
  393. }
  394. }
  395. $bool = cache('bzDbToRedis',$bzDbToRedis);
  396. if($bool===false) $this->error('存入redis失败','','000002');
  397. $this->success('同步成功');
  398. }
  399. /**
  400. * 获取班组工作负荷数据
  401. */
  402. public function getBzByRedis()
  403. {
  404. $row = cache('bzDbToRedis');
  405. $result['columns']=[
  406. ['name'=>'机台号','id'=>'jtbh','width'=>'14','autoWrap'=>"true",'textAlign'=>'left'],
  407. ['name'=>'班组','id'=>'bzdh','width'=>'16','autoWrap'=>"true",'textAlign'=>'left'],
  408. ['name'=>'在产工单号','id'=>'gdbh','width'=>'16','textAlign'=>'left'],
  409. ['name'=>'工单名称','id'=>'gdmc','width'=>'20','autoWrap'=>"true",'textAlign'=>'left'],
  410. ['name'=>'印件号','id'=>'yjno','width'=>'16','autoWrap'=>"true",'textAlign'=>'left'],
  411. ['name'=>'工序','id'=>'gx','width'=>'16','autoWrap'=>"true",'textAlign'=>'left'],
  412. ['name'=>'计划产量','id'=>'jhcl','width'=>'14','autoWrap'=>"true",'textAlign'=>'left'],
  413. ['name'=>'已完成产量','id'=>'wccl','width'=>'14','autoWrap'=>"true",'textAlign'=>'center'],
  414. ['name'=>'小时产能','id'=>'xscn','width'=>'14','autoWrap'=>"true",'textAlign'=>'center'],
  415. ['name'=>'机台状态','id'=>'status','width'=>'14','autoWrap'=>"true",'textAlign'=>'center'],
  416. ];
  417. if($row){
  418. foreach($row as $k=>$v){
  419. $result['rows'][$k]['jtbh']=$v['机台号'];
  420. $result['rows'][$k]['bzdh']=$v['班组代号'];
  421. $result['rows'][$k]['gdbh']=$v['工单编号'];
  422. $result['rows'][$k]['gdmc']=$v['产品名称'];
  423. $result['rows'][$k]['yjno']=$v['机台号'];
  424. $result['rows'][$k]['gx']=$v['工序名称'];
  425. $result['rows'][$k]['jhcl'] = $v['计划产量'];
  426. $result['rows'][$k]['wccl'] = $v['已完成产量'];
  427. $result['rows'][$k]['xscn'] = $v['小时产能'];
  428. $result['rows'][$k]['status'] = $v['机台状态'];
  429. }
  430. }else{
  431. $result['rows'][0]['jtbh']='';
  432. $result['rows'][0]['bzdh']='';
  433. $result['rows'][0]['gdbh']='';
  434. $result['rows'][0]['gdmc']='';
  435. $result['rows'][0]['yjno']='';
  436. $result['rows'][0]['gx']='';
  437. $result['rows'][0]['jhcl'] = '';
  438. $result['rows'][0]['wccl'] = '';
  439. $result['rows'][0]['xscn'] = '';
  440. $result['rows'][0]['status'] = '';
  441. }
  442. $res['status']=0;
  443. $res['msg']='';
  444. $res['data']=$result;
  445. return json($res);
  446. }
  447. /**
  448. * 决策支持月度设备运行数据统计->班组(接口)
  449. */
  450. public function TeamsgGoups()
  451. {
  452. // 获取设备编组信息
  453. $result = \db('设备_基本资料')
  454. ->whereNotNull('设备编组')
  455. ->group('设备编组')
  456. ->column('rtrim(设备编组) as 设备编组');
  457. $data = [
  458. "columns" => [
  459. ["id" => "subsys"]
  460. ],
  461. "rows" => []
  462. ];
  463. foreach ($result as $value) {
  464. $data["rows"][] = ["subsys" => $value];
  465. }
  466. $res = [
  467. 'status' => 0,
  468. 'msg' => '',
  469. 'data' => $data
  470. ];
  471. return json($res);
  472. }
  473. /**
  474. * 决策支持月度设备运行数据统计->机台运行工时汇总(接口)
  475. */
  476. public function MonthlyEquipment() {
  477. // 获取请求参数,默认为 '01、切纸机组'
  478. $postData = input('post.dependence.item.subsys', '01、切纸机组');
  479. // 查询条件
  480. $where = [];
  481. if (!empty($postData)) {
  482. $where['设备编组'] = $postData;
  483. }
  484. // 获取当前年月
  485. $currentYearMonth = date('Y-m');
  486. // 获取去年的同月
  487. $lastYearMonth = date('Y-m', strtotime('-1 year'));
  488. // 查询 **今年** 当月的数据
  489. $currentData = \db('设备_基本资料')
  490. ->alias('a')
  491. ->join('设备_产量计酬 b', 'a.设备编号 = b.sczl_jtbh')
  492. ->field([
  493. 'a.设备编号' => '设备编号',
  494. 'SUM(b.sczl_cl)' => '产量'
  495. ])
  496. ->where($where)
  497. ->whereTime('b.sczl_rq', '>=', $currentYearMonth . '-01') // 查询当前月的第一天
  498. ->whereTime('b.sczl_rq', '<', date('Y-m-d', strtotime('next month', strtotime($currentYearMonth . '-01')))) // 下个月的第一天
  499. ->group('a.设备编号')
  500. ->order('a.设备编号')
  501. ->select();
  502. // 查询 **去年** 同月的数据
  503. $lastYearData = \db('设备_基本资料')
  504. ->alias('a')
  505. ->join('设备_产量计酬 b', 'a.设备编号 = b.sczl_jtbh')
  506. ->field([
  507. 'a.设备编号' => '设备编号',
  508. 'SUM(b.sczl_cl)' => '产量'
  509. ])
  510. ->where($where)
  511. ->whereTime('b.sczl_rq', '>=', $lastYearMonth . '-01') // 查询去年的同月第一天
  512. ->whereTime('b.sczl_rq', '<', date('Y-m-d', strtotime('next month', strtotime($lastYearMonth . '-01')))) // 下个月的第一天
  513. ->group('a.设备编号')
  514. ->order('a.设备编号')
  515. ->select();
  516. // 格式化数据
  517. $categories = [];
  518. $currentYearSeries = [];
  519. $lastYearSeries = [];
  520. // 转换查询结果为关联数组,方便查找
  521. $currentYearMap = [];
  522. $lastYearMap = [];
  523. foreach ($currentData as $item) {
  524. $currentYearMap[$item['设备编号']] = $item['产量'];
  525. }
  526. foreach ($lastYearData as $item) {
  527. $lastYearMap[$item['设备编号']] = $item['产量'];
  528. }
  529. // 统一设备编号,确保数据完整
  530. $allDevices = array_unique(array_merge(array_keys($currentYearMap), array_keys($lastYearMap)));
  531. foreach ($allDevices as $device) {
  532. $categories[] = $device;
  533. $currentYearSeries[] = isset($currentYearMap[$device]) ? intval($currentYearMap[$device]) : 0; // 今年产量
  534. $lastYearSeries[] = isset($lastYearMap[$device]) ? intval($lastYearMap[$device]) : 0; // 去年产量
  535. }
  536. // 组织返回数据
  537. $response = [
  538. 'status' => 0,
  539. 'msg' => '',
  540. 'data' => [
  541. 'categories' => $categories,
  542. 'series' => [
  543. [
  544. 'name' => '今年产量',
  545. 'data' => $currentYearSeries,
  546. 'type' => 'bar',
  547. 'yAxisIndex' => 0
  548. ],
  549. [
  550. 'name' => '去年产量',
  551. 'data' => $lastYearSeries,
  552. 'type' => 'bar',
  553. 'yAxisIndex' => 0
  554. ]
  555. ]
  556. ]
  557. ];
  558. return json($response);
  559. }
  560. /**
  561. * 决策支持月度设备运行数据统计->机台运行工时汇总列表(接口)
  562. */
  563. public function Equipmenttable(){
  564. // 获取请求数据
  565. $postData = input('post.dependence.item.subsys', '01、切纸机组');
  566. $where = [];
  567. if (!empty($postData)) {
  568. $where['设备编组'] = $postData;
  569. }
  570. // 获取当前月份
  571. $mouth = date_create_from_format('Ym', date('Ym'))->format('Y-m');
  572. // 查询设备数据
  573. $list = \db('设备_基本资料')->alias('a')
  574. ->join('设备_产量计酬 b', 'a.设备编号 = b.sczl_jtbh')
  575. ->field([
  576. 'a.设备编号' => '设备编号',
  577. 'rtrim(a.设备名称)' => '设备名称',
  578. 'SUM(b.sczl_cl)' => '产量',
  579. 'SUM(b.sczl_设备运行工时)' => '设备运行工时',
  580. 'SUM(b.sczl_保养工时)' => '保养工时',
  581. 'SUM(b.sczl_打样总工时)' => '打样总工时',
  582. 'SUM(b.sczl_打样工时)' => '打样补产工时',
  583. 'SUM(b.sczl_装版总工时)' => '装板总工时',
  584. 'SUM(b.sczl_装版工时)' => '装板补产工时',
  585. 'SUM(b.sczl_异常停机工时)' => '异常停机工时'
  586. ])
  587. ->where($where)
  588. ->whereTime('b.sczl_rq', $mouth)
  589. ->group('a.设备编号')
  590. ->order('a.设备编号')
  591. ->select();
  592. $rows = [];
  593. foreach ($list as $item) {
  594. $rows[] = [
  595. 'subsys' => $item['设备编号'],
  596. 'module' => $item['设备名称'],
  597. 'business' => $item['产量'],
  598. 'sbyxgs' => $item['设备运行工时'],
  599. 'dyzgs' => $item['打样总工时'],
  600. 'dybcgs' => $item['打样补产工时'],
  601. 'zbzgs' => $item['装板总工时'],
  602. 'zbbcgs' => $item['装板补产工时'],
  603. 'yctjgs' => $item['异常停机工时']
  604. ];
  605. }
  606. // 最终响应格式
  607. $response = [
  608. 'status' => 0,
  609. 'msg' => '',
  610. 'data' => [
  611. 'total' => count($rows),
  612. 'columns' => [
  613. ['name' => '设备编号','id' => 'subsys'],
  614. ['name' => '设备名称','id' => 'module'],
  615. ['name' => '产量','id' => 'business'],
  616. ['name' => '设备运行工时','id' => 'sbyxgs'],
  617. ['name' => '打样总工时','id' => 'dyzgs'],
  618. ['name' => '打样补产工时','id' => 'dybcgs'],
  619. ['name' => '装板总工时','id' => 'zbzgs'],
  620. ['name' => '装板补产工时','id' => 'zbbcgs'],
  621. ['name' => '异常停机工时','id' => 'yctjgs',]
  622. ],
  623. // 'superHeaders' => [
  624. // [
  625. // [
  626. // 'name' => '设备信息',
  627. // 'colspan' => 3
  628. // ],
  629. // [
  630. // 'name' => '工时统计',
  631. // 'colspan' => 2
  632. // ]
  633. // ]
  634. // ],
  635. 'rows' => $rows
  636. ]
  637. ];
  638. return json($response);
  639. }
  640. /**
  641. * 工序产出率月统计报表(接口)
  642. */
  643. public function Monthlystatistical(){
  644. }
  645. }