LargeScreenService.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. <?php
  2. namespace App\Service;
  3. use App\Model\ApplyOrder;
  4. use App\Model\ApplyOrderDetail;
  5. use App\Model\DeviceOrder;
  6. use App\Model\DeviceOrderInfo;
  7. use App\Model\DispatchSub;
  8. use App\Model\DXJ;
  9. use App\Model\Employee;
  10. use App\Model\Equipment;
  11. use App\Model\OrdersProduct;
  12. use App\Model\Process;
  13. use App\Model\ReportWorkingDetail;
  14. use App\Model\SaleOrdersProduct;
  15. use App\Model\Scrapp;
  16. use App\Model\ScrappCount;
  17. use App\Model\SystemL;
  18. use Carbon\Carbon;
  19. use Illuminate\Support\Facades\DB;
  20. use Illuminate\Support\Facades\Redis;
  21. class LargeScreenService extends Service
  22. {
  23. public function integratedDashboard($data)
  24. {
  25. //总产值 ------------------------------------------------
  26. $total = SaleOrdersProduct::where('del_time', 0)
  27. ->where('crt_time', ">=", strtotime(date("Y-01-01 00:00:00")))
  28. ->select(DB::raw("sum(finished_num) as total"))
  29. ->value('total');
  30. //总产值 ------------------------------------------------
  31. //当日产量 当月产量 ---------------------------------------------
  32. $data_one = SaleOrdersProduct::where('del_time', 0)
  33. ->where('crt_time', ">=", strtotime(date("Y-m-01 00:00:00")))
  34. ->where('crt_time', "<=", strtotime(date("Y-m-t 23:59:59")))
  35. ->select('finished_num', 'order_quantity', 'crt_time')
  36. ->get()->toArray();
  37. //当日产量 当月产量
  38. $today_total = $month_total = $order_total = 0;
  39. $timeStamp = strtotime(date("Y-m-d 00:00:00"));
  40. $timeStampE = strtotime(date("Y-m-d 23:59:59"));
  41. foreach ($data_one as $value) {
  42. $order_total = bcadd($order_total, $value['order_quantity'], 3);
  43. $month_total = bcadd($month_total, $value['finished_num'], 3);
  44. if ($timeStamp <= $value['crt_time'] && $timeStampE >= $value['crt_time']) $today_total = bcadd($today_total, $value['finished_num'], 3);
  45. }
  46. //当日产量 当月产量 ---------------------------------------------
  47. //月计划完成率--------------------------------------------------------------------
  48. $month_rate = floatval($order_total) > 0 ? bcdiv($month_total, $order_total, 4) : 0;
  49. $month_rate = bcmul($month_rate, 100, 2) . "%";
  50. //月计划完成率--------------------------------------------------------------------
  51. //月注塑合格率----------------------------------------------------------------------
  52. $data_two = ScrappCount::where('del_time', 0)
  53. ->where('crt_time', ">=", strtotime(date("Y-m-01 00:00:00")))
  54. ->where('crt_time', "<=", strtotime(date("Y-m-t 23:59:59")))
  55. ->where('process_id', 14)
  56. ->select(DB::raw("sum(quantity) as quantity"), DB::raw("sum(scrapp_num) as waste"))
  57. ->get()->toArray();
  58. $total_zj = $total_blp = 0;
  59. foreach ($data_two as $value) {
  60. $total_zj = bcadd($total_zj, $value['quantity'], 3);
  61. $total_zj = bcadd($total_zj, $value['waste'], 3);
  62. $total_blp = bcadd($total_blp, $value['waste'], 3);
  63. }
  64. $process_14_total = bcadd($total_zj, $total_blp, 3);
  65. $process_14_rate = floatval($process_14_total) > 0 ? bcdiv($total_zj, $process_14_total, 4) : 0;
  66. $process_14_rate = bcmul($process_14_rate, 100, 2) . "%";
  67. //月注塑合格率----------------------------------------------------------------------
  68. //设备监控状态----------------------------------------------------------------------
  69. $deviceList = $this->deviceState();
  70. //设备监控状态----------------------------------------------------------------------
  71. //质量管理--------------------------------------------------------------------------
  72. $dates = [];
  73. for ($i = 7; $i >= 0; $i--) {
  74. $timestamp = strtotime("-{$i} days");
  75. $date = date('m-d', $timestamp);
  76. $dates[] = $date;
  77. }
  78. $zl_data = [];
  79. $data_three = ScrappCount::where('del_time', 0)
  80. ->where('crt_time', "<=", time())
  81. ->where('crt_time', ">=", strtotime(date("Y-m-d 00:00:00", time() - 7 * 24 * 60 * 60)))
  82. ->where('process_id', 14)
  83. ->select('quantity', "scrapp_num as waste", "crt_time")
  84. ->get()->toArray();
  85. foreach ($data_three as $value) {
  86. $day = date("m-d", $value['crt_time']);
  87. $tmp = bcadd($value['quantity'], $value['waste'], 3);
  88. if (isset($zl_data[$day])) {
  89. $zl_data[$day]['quantity'] = bcadd($zl_data[$day]['quantity'], $value['quantity'], 3);
  90. $zl_data[$day]['total'] = bcadd($zl_data[$day]['total'], $tmp, 3);
  91. } else {
  92. $zl_data[$day] = [
  93. 'quantity' => $value['quantity'],
  94. 'total' => $tmp
  95. ];
  96. }
  97. }
  98. $zj_data_final = [];
  99. foreach ($dates as $value) {
  100. $tmp = [
  101. "day" => $value,
  102. "total" => 0,
  103. "rate" => 0,
  104. ];
  105. if (isset($zl_data[$value])) {
  106. $tmp['total'] = $zl_data[$value]['total'];
  107. $tmp['rate'] = bcmul(bcdiv($zl_data[$value]['quantity'], $zl_data[$value]['total'], 4), 100, 2);
  108. }
  109. $zj_data_final[] = $tmp;
  110. }
  111. //质量管理--------------------------------------------------------------------------
  112. //物料管理--------------------------------------------------------------------------
  113. $thing = [
  114. ["name" => '物料一', 'rate' => 50],
  115. ["name" => '物料二', 'rate' => 60],
  116. ["name" => '物料三', 'rate' => 34],
  117. ["name" => '物料四', 'rate' => 22],
  118. ["name" => '物料五', 'rate' => 11],
  119. ["name" => '物料六', 'rate' => 22],
  120. ["name" => '物料七', 'rate' => 44],
  121. ["name" => '物料八', 'rate' => 32],
  122. ["name" => '物料九', 'rate' => 34],
  123. ["name" => '物料十', 'rate' => 51],
  124. ];
  125. //物料管理--------------------------------------------------------------------------
  126. //销售管理--------------------------------------------------------------------------
  127. $xs = SaleOrdersProduct::where('del_time', 0)
  128. ->where('crt_time', ">=", strtotime(date("Y-01-01 00:00:00")))
  129. ->select(DB::raw("sum(finished_num) as total"), 'technology_name as color')
  130. ->groupBy('technology_name')
  131. ->orderBy('total', 'desc')
  132. ->get()->toArray();
  133. //销售管理--------------------------------------------------------------------------
  134. //总装各线体目标/完成量---------------------------------------------------------------
  135. $zx_12_dispatch_quantity = $zx_12_finished_num = 0;
  136. $zx_14_dispatch_quantity_8 = $zx_14_finished_num_8 = 0;
  137. $zx_14_dispatch_quantity_9 = $zx_14_finished_num_9 = 0;
  138. $zx_14_dispatch_quantity_12 = $zx_14_finished_num_12 = 0;
  139. $zx_14_dispatch_quantity_13 = $zx_14_finished_num_13 = 0;
  140. $dispatch = DispatchSub::where('del_time', 0)
  141. ->where('crt_time', ">=", strtotime(date("Y-01-01 00:00:00")))
  142. ->whereIn('process_id', [12, 14])
  143. ->select('dispatch_quantity', 'finished_num', 'process_id', 'device_id')
  144. ->get()->toArray();
  145. foreach ($dispatch as $value) {
  146. if ($value['process_id'] == 12) {
  147. $zx_12_dispatch_quantity = bcadd($zx_12_dispatch_quantity, $value['dispatch_quantity'], 3);
  148. $zx_12_finished_num = bcadd($zx_12_finished_num, $value['finished_num'], 3);
  149. } else {
  150. if ($value['device_id'] == 8) {
  151. $zx_14_dispatch_quantity_8 = bcadd($zx_14_dispatch_quantity_8, $value['dispatch_quantity'], 3);
  152. $zx_14_finished_num_8 = bcadd($zx_14_finished_num_8, $value['finished_num'], 3);
  153. } elseif ($value['device_id'] == 9) {
  154. $zx_14_dispatch_quantity_9 = bcadd($zx_14_dispatch_quantity_9, $value['dispatch_quantity'], 3);
  155. $zx_14_finished_num_9 = bcadd($zx_14_finished_num_9, $value['finished_num'], 3);
  156. } elseif ($value['device_id'] == 12) {
  157. $zx_14_dispatch_quantity_12 = bcadd($zx_14_dispatch_quantity_12, $value['dispatch_quantity'], 3);
  158. $zx_14_finished_num_12 = bcadd($zx_14_finished_num_12, $value['finished_num'], 3);
  159. } elseif ($value['device_id'] == 13) {
  160. $zx_14_dispatch_quantity_13 = bcadd($zx_14_dispatch_quantity_13, $value['dispatch_quantity'], 3);
  161. $zx_14_finished_num_13 = bcadd($zx_14_finished_num_13, $value['finished_num'], 3);
  162. }
  163. }
  164. }
  165. $diff_num = bcsub($zx_12_dispatch_quantity, $zx_12_finished_num, 3);
  166. $diff_num_8 = bcsub($zx_14_dispatch_quantity_8, $zx_14_finished_num_8, 3);
  167. $diff_num_9 = bcsub($zx_14_dispatch_quantity_9, $zx_14_finished_num_9, 3);
  168. $diff_num_12 = bcsub($zx_14_dispatch_quantity_12, $zx_14_finished_num_12, 3);
  169. $diff_num_13 = bcsub($zx_14_dispatch_quantity_13, $zx_14_finished_num_13, 3);
  170. $xt = [
  171. [
  172. "name" => "清洗脱水产线", "sj_num" => $zx_12_finished_num, "jh_num" => $zx_12_dispatch_quantity, "diff_num" => $diff_num
  173. ], [
  174. "name" => "注塑一号产线", "sj_num" => $zx_14_finished_num_8, "jh_num" => $zx_14_dispatch_quantity_8, "diff_num" => $diff_num_8
  175. ], [
  176. "name" => "注塑二号产线", "sj_num" => $zx_14_finished_num_9, "jh_num" => $zx_14_dispatch_quantity_9, "diff_num" => $diff_num_9
  177. ], [
  178. "name" => "注塑三号产线", "sj_num" => $zx_14_finished_num_12, "jh_num" => $zx_14_dispatch_quantity_12, "diff_num" => $diff_num_12
  179. ], [
  180. "name" => "注塑四号产线", "sj_num" => $zx_14_finished_num_13, "jh_num" => $zx_14_dispatch_quantity_13, "diff_num" => $diff_num_13
  181. ],
  182. ];
  183. //总装各线体目标/完成量---------------------------------------------------------------
  184. //订单完成进度-----------------------------------------------------------------
  185. $orderBy = [11 => "破碎分离", 12 => "清洗脱水", 15 => "混合搅拌", 13 => "挤出造粒", 14 => "注塑成型"];
  186. $order = OrdersProduct::where('del_time', 0)
  187. ->select('production_no as order_number', 'id', 'technology_name as color', 'production_quantity', 'dispatch_complete_quantity', 'finished_num')
  188. ->orderBy('id', 'desc')
  189. ->limit(10)
  190. ->get()->toArray();
  191. $dispatch_num = DispatchSub::where('del_time', 0)
  192. ->whereIn('order_product_id', array_column($order, 'id'))
  193. ->select('order_product_id', 'process_id', 'finished_num', 'dispatch_quantity', 'waste_num')
  194. ->get()->toArray();
  195. $details = [];
  196. foreach ($dispatch_num as $value) {
  197. $new = $value['order_product_id'] . $value['process_id'];
  198. $finished_num = bcadd($value['finished_num'], $value['waste_num'], 3);
  199. if (isset($details[$new])) {
  200. $details[$new]['dispatch_quantity'] = bcadd($details[$new]['dispatch_quantity'], $value['dispatch_quantity'], 3);
  201. $details[$new]['finished_num'] = bcadd($details[$new]['finished_num'], $finished_num, 3);
  202. } else {
  203. $details[$new] = [
  204. "dispatch_quantity" => $value['dispatch_quantity'],
  205. "finished_num" => $finished_num,
  206. ];
  207. }
  208. }
  209. foreach ($order as $key => $value) {
  210. $d_tmp = [];
  211. foreach ($orderBy as $k => $v) {
  212. $new = $value['id'] . $k;
  213. $tmpS = $details[$new] ?? [];
  214. $rate = 0;
  215. if (!empty($tmpS)) {
  216. $rate = bcdiv($tmpS['finished_num'], $tmpS['dispatch_quantity'], 4);
  217. $rate = bcmul($rate, 100, 2);
  218. }
  219. $d_tmp[] = [
  220. "name" => $v,
  221. "rate" => $rate
  222. ];
  223. }
  224. $order[$key]['detail'] = $d_tmp;
  225. if ($value['production_quantity'] <= $value['finished_num']) {
  226. $state = "已完成";
  227. } else {
  228. $state = "进行中";
  229. }
  230. $order[$key]['state_title'] = $state;
  231. }
  232. //订单完成进度-----------------------------------------------------------------
  233. // dd($total, $today_total, $month_total, $month_rate, $process_14_rate, $deviceList, $zj_data_final, $thing, $xs, $xt,$order);
  234. $return = [
  235. 'total' => $total, //年总产量
  236. 'today_total' => $today_total, //当日产量
  237. 'month_total' => $month_total, //当月产量
  238. 'month_rate' => $month_rate, // 月计划完成比例
  239. 'process_14_rate' => $process_14_rate, // 注塑产线合格率
  240. 'device' => $deviceList, // 设备监控状态
  241. 'zj_result' => $zj_data_final, //质量管理
  242. 'thing' => $thing, //物料管理
  243. 'xs' => $xs, //销售管理
  244. 'xt' => $xt, //总装各线体目标/完成量
  245. 'order' => $order, // 订单完成进度
  246. ];
  247. return [true, $return];
  248. }
  249. private function deviceState(){
  250. $deviceList = Equipment::where('del_time', 0)
  251. ->where('model', '<>', 1)
  252. ->select('id', 'title', 'code', 'status')
  253. ->get()->toArray();
  254. foreach ($deviceList as $key => $value) {
  255. $status_title = Equipment::$status_title[$value['status']] ?? "";
  256. $deviceList[$key]['status_title'] = $status_title;
  257. }
  258. return $deviceList;
  259. }
  260. public function productionExecution($data)
  261. {
  262. //生产进度实时监控-----------------------------------------------------
  263. $order = OrdersProduct::where('del_time', 0)
  264. ->limit(15)
  265. ->orderBy('id', 'desc')
  266. ->pluck('id')
  267. ->toArray();
  268. $dispatch = $this->getDispatch($order);
  269. $process_map = Process::whereIn('id', array_column($dispatch, 'process_id'))
  270. ->pluck('title', 'id')
  271. ->toArray();
  272. foreach ($dispatch as $key => $value) {
  273. if (in_array($value['process_id'], [11, 12])) {
  274. $cx = "清洗脱水产线";
  275. } else {
  276. if ($value['device_id'] == 8) {
  277. $cx = "注塑一号产线";
  278. } elseif ($value['device_id'] == 9) {
  279. $cx = "注塑二号产线";
  280. } elseif ($value['device_id'] == 12) {
  281. $cx = "注塑三号产线";
  282. } else {
  283. $cx = "注塑四号产线";
  284. }
  285. }
  286. $dispatch[$key]['cx'] = $cx;
  287. $dispatch[$key]['process_name'] = $process_map[$value['process_id']] ?? '';
  288. }
  289. //生产进度实时监控-----------------------------------------------------
  290. //订单看板-----------------------------------------------------
  291. $sales = SaleOrdersProduct::where('del_time', 0)
  292. ->select('out_order_no as order_number', 'customer_name', 'product_title', 'technology_name as color', 'order_quantity', 'pre_shipment_time', 'finished_num', 'production_quantity')
  293. ->limit(10)
  294. ->orderBy('id', 'desc')
  295. ->get()->toArray();
  296. foreach ($sales as $key => $value) {
  297. $sales[$key]['pre_shipment_time'] = $value['pre_shipment_time'] ? date('Y-m-d', $value['pre_shipment_time']) : '';
  298. if (floatval($value['production_quantity']) <= 0.0) {
  299. $state_title = "未排产";
  300. } elseif ($value['finished_num'] < $value['order_quantity']) {
  301. $state_title = "进行中";
  302. } else {
  303. $state_title = "已完成";
  304. }
  305. $sales[$key]['state_title'] = $state_title;
  306. $sales[$key]['pre_shipment_time'] = date("Y-m-d", $value['pre_shipment_time']);
  307. }
  308. //订单看板-----------------------------------------------------
  309. //工序负荷全览-----------------------------------------------------
  310. $process = Process::where('del_time', 0)->get()->toArray();
  311. $return = ApplyOrderDetail::selectRaw('
  312. DATE(FROM_UNIXTIME(crt_time)) as date,
  313. ROUND(SUM(quantity), 3) as dispatch_quantity
  314. ')
  315. ->where('del_time', 0)
  316. ->where('type', ApplyOrder::type_one)
  317. ->groupBy('date')
  318. ->orderBy('date', 'desc') // 可选:按日期倒序
  319. ->get()
  320. ->map(function ($item) {
  321. $item->date = str_replace('-', '', $item->date); // 转为 Ymd 格式字符串
  322. return $item;
  323. })
  324. ->pluck('dispatch_quantity', 'date')
  325. ->toArray();
  326. $maxValue = empty($return) ? 0 : max($return);
  327. $today = $return[date("Ymd")] ?? 0;
  328. $rate = $maxValue ? intval($today / $maxValue * 100) : 0;
  329. $array_p = [];
  330. foreach ($process as $value) {
  331. $array_p[] = [
  332. 'title' => $value['title'],
  333. 'rate' => $rate
  334. ];
  335. }
  336. //工序负荷全览-----------------------------------------------------
  337. //双周生产计划达成率-----------------------------------------------------
  338. $dates = [];
  339. $first = $end = 0;
  340. for ($i = 14; $i >= 0; $i--) {
  341. $timestamp = strtotime("-{$i} days");
  342. if ($i == 14) $first = strtotime(date("Y-m-d 00:00:00", $timestamp));
  343. if ($i == 0) $end = strtotime(date("Y-m-d 00:00:00", $timestamp));
  344. $dates[] = strtotime(date("Y-m-d 00:00:00", $timestamp));
  345. }
  346. $results = DispatchSub::where('del_time', 0)
  347. ->where('dispatch_time_start', '>=', $first) // 计划开始 < 给定结束
  348. ->where('dispatch_time_end', '<=', $end) // 计划结束 > 给定开始
  349. ->where('process_id', 14)
  350. ->select('dispatch_time_start as crt_time', DB::raw("sum(dispatch_quantity) as quantity"))
  351. ->groupBy('dispatch_time_start')
  352. ->get()->toArray();
  353. $map = array_column($results, 'quantity', 'crt_time');
  354. $jd = [];
  355. foreach ($dates as $value) {
  356. if (isset($map[$value])) {
  357. $jd[$value] = [
  358. 'plan_num' => $map[$value],
  359. 'sj_num' => 0,
  360. 'rate' => 0,
  361. 'day' => date("m-d", $value)
  362. ];
  363. } else {
  364. $jd[$value] = [
  365. 'plan_num' => 0,
  366. 'sj_num' => 0,
  367. 'rate' => 0,
  368. 'day' => date("m-d", $value)
  369. ];
  370. }
  371. }
  372. $pending = 0; // 待完成的任务量(滚存)
  373. foreach ($jd as $timestamp => &$item) {
  374. $totalWork = $pending + $item['plan_num']; // 可用任务总量(含滚存)
  375. // 当天最多完成
  376. $item['sj_num'] = min(42, $totalWork);
  377. // 剩余未完成任务,滚入下一天
  378. $pending = bcsub($totalWork, $item['sj_num'], 3);
  379. // 计算 rate
  380. if ($item['plan_num'] == 0) {
  381. // 没有计划 → 完成率 0%
  382. $item['rate'] = 0;
  383. } else {
  384. // 有计划 → 完成率 = 实际 / 计划
  385. $item['rate'] = round(($item['sj_num'] / $item['plan_num']) * 100, 2);
  386. }
  387. }
  388. //双周生产计划达成率-----------------------------------------------------
  389. list($status, $return) = (new ApplyOrderService())->reportList(['page_size' => 3, 'page_index' => 1, 'not_need' => 1]);
  390. $cs = $return['list'] ?? [];
  391. $cs = $cs['data'] ?? [];
  392. $cs = array_column($cs, 'message');
  393. $return = [
  394. 'dispatch' => $dispatch, //生产进度实时监控
  395. 'sales' => $sales, //订单看板
  396. 'array_p' => $array_p, //工序负荷全览
  397. 'jd' => array_values($jd), // 生产进度实时监控
  398. 'cs' => $cs
  399. ];
  400. return [true, $return];
  401. }
  402. private function getDispatch($order)
  403. {
  404. $customOrder = [11, 12, 15, 13, 14];
  405. $priorityMap = array_flip($customOrder); // [11=>0, 12=>1, 15=>2, 13=>3, 14=>4]
  406. // 先从数据库取出数据(只需按 id 倒序即可)
  407. $dispatch = DispatchSub::where('del_time', 0)
  408. ->whereIn('order_product_id', $order)
  409. ->where('dispatch_quantity', '>', 1)
  410. ->select(
  411. 'process_id',
  412. 'dispatch_quantity',
  413. 'finished_num',
  414. DB::raw('finished_num as bg_num'),
  415. DB::raw('finished_num as hg_num'),
  416. 'waste_num',
  417. 'device_id',
  418. 'order_product_id',
  419. 'id',
  420. 'technology_name as color',
  421. 'product_title'
  422. )
  423. ->orderBy('id', 'desc')
  424. ->get()
  425. ->toArray();
  426. // === 在 PHP 中分组并排序 ===
  427. $grouped = [];
  428. foreach ($dispatch as $item) {
  429. $grouped[$item['order_product_id']][] = $item;
  430. }
  431. // 对每一组按 process_id 自定义顺序排序
  432. foreach ($grouped as &$group) {
  433. usort($group, function ($a, $b) use ($priorityMap) {
  434. $posA = $priorityMap[$a['process_id']] ?? 999;
  435. $posB = $priorityMap[$b['process_id']] ?? 999;
  436. return $posA <=> $posB; // 升序:11(0), 12(1), 15(2), 13(3), 14(4)
  437. });
  438. }
  439. unset($group);
  440. // 合并成扁平数组(保持 order_product_id 之间的顺序为 id 倒序)
  441. $sortedDispatch = [];
  442. $seenOrderIds = [];
  443. // 按原始 id 倒序决定 order_product_id 的出现顺序
  444. foreach ($dispatch as $item) {
  445. $orderId = $item['order_product_id'];
  446. if (!in_array($orderId, $seenOrderIds)) {
  447. $seenOrderIds[] = $orderId;
  448. }
  449. }
  450. // 按首次出现的 order_product_id 顺序(即 id 倒序)拼接每组数据
  451. foreach ($seenOrderIds as $orderId) {
  452. if (isset($grouped[$orderId])) {
  453. foreach ($grouped[$orderId] as $item) {
  454. $sortedDispatch[] = $item;
  455. }
  456. }
  457. }
  458. return $sortedDispatch;
  459. }
  460. public function qualityDashboard($data)
  461. {
  462. //质量趋势图 以及 合格率----------------------------------------------------
  463. // 近15天日期戳
  464. $dates = [];
  465. for ($i = 14; $i >= 0; $i--) {
  466. $timestamp = strtotime("-{$i} days");
  467. $dates[] = strtotime(date("Y-m-d 00:00:00", $timestamp));
  468. }
  469. $dispatch = ScrappCount::where('del_time', 0)
  470. ->where('crt_time', '>=', strtotime(date("Y-m-01 00:00:00")))
  471. ->whereIn('process_id', [12, 14])
  472. ->select('scrapp_num as dispatch_quantity', 'quantity as finished_num', 'process_id', 'equipment_id as device_id', 'crt_time')
  473. ->get()
  474. ->toArray();
  475. // 数据聚合
  476. $time_map = []; // 清洗脱水线
  477. $time_map_2 = []; // 注塑多条产线
  478. $total_map = []; // 所有产线总汇总
  479. foreach ($dispatch as $value) {
  480. $time_tmp = strtotime(date("Ymd 00:00:00", $value['crt_time']));
  481. $total = bcadd($value['finished_num'], $value['dispatch_quantity'], 3);
  482. // ✅ 所有产线的汇总
  483. if (!isset($total_map[$time_tmp])) {
  484. $total_map[$time_tmp] = ['total' => 0, 'finished' => 0];
  485. }
  486. $total_map[$time_tmp]['total'] = bcadd($total_map[$time_tmp]['total'], $total, 3);
  487. $total_map[$time_tmp]['finished'] = bcadd($total_map[$time_tmp]['finished'], $value['finished_num'], 3);
  488. if ($value['process_id'] == 12) {
  489. // 清洗脱水产线
  490. if (!isset($time_map[$time_tmp])) {
  491. $time_map[$time_tmp] = ['total' => 0, 'finished' => 0];
  492. }
  493. $time_map[$time_tmp]['total'] = bcadd($time_map[$time_tmp]['total'], $total, 3);
  494. $time_map[$time_tmp]['finished'] = bcadd($time_map[$time_tmp]['finished'], $value['finished_num'], 3);
  495. } else {
  496. // 注塑产线
  497. $key = "{$value['device_id']}|{$time_tmp}";
  498. if (!isset($time_map_2[$key])) {
  499. $time_map_2[$key] = ['total' => 0, 'finished' => 0];
  500. }
  501. $time_map_2[$key]['total'] = bcadd($time_map_2[$key]['total'], $total, 3);
  502. $time_map_2[$key]['finished'] = bcadd($time_map_2[$key]['finished'], $value['finished_num'], 3);
  503. }
  504. }
  505. // 各产线配置
  506. $lines = [
  507. '清洗脱水产线' => ['map' => &$time_map, 'key_prefix' => null],
  508. '注塑一号产线' => ['map' => &$time_map_2, 'key_prefix' => '8|'],
  509. '注塑二号产线' => ['map' => &$time_map_2, 'key_prefix' => '9|'],
  510. '注塑三号产线' => ['map' => &$time_map_2, 'key_prefix' => '12|'],
  511. '注塑四号产线' => ['map' => &$time_map_2, 'key_prefix' => '13|'],
  512. '总合格率' => ['map' => &$total_map, 'key_prefix' => null, 'is_total' => true],
  513. ];
  514. $result = [];
  515. foreach ($lines as $name => $cfg) {
  516. $map = $cfg['map'];
  517. $prefix = $cfg['key_prefix'] ?? null;
  518. $arr = [];
  519. foreach ($dates as $date_ts) {
  520. $key = $prefix ? "{$prefix}{$date_ts}" : $date_ts;
  521. $a = $map[$key]['total'] ?? 0;
  522. $b = $map[$key]['finished'] ?? 0;
  523. $rate = 0.00;
  524. if (floatval($a) > 0.0) {
  525. $rate = bcmul(bcdiv($b, $a, 4), 100, 2);
  526. }
  527. $arr[date("m-d", $date_ts)] = $rate;
  528. }
  529. $result[] = [
  530. 'name' => $name,
  531. 'array' => $arr,
  532. ];
  533. }
  534. $end = array_pop($result);
  535. $end = $end["array"];
  536. //质量趋势图 end 以及 合格率 $result ----------------------------------------------------
  537. //不合格原因分析--------------------------------------------------------------
  538. $s = ScrappCount::where('del_time', 0)
  539. ->where('crt_time', '>=', strtotime(date("Y-m-01 00:00:00")))
  540. ->where('scrapp_id', '>', 0)
  541. ->select(
  542. 'scrapp_id',
  543. DB::raw('SUM(scrapp_num) as total'),
  544. )
  545. ->groupBy('scrapp_id')
  546. ->orderBy('total', 'desc')
  547. ->get()
  548. ->toArray();
  549. $sum = !empty($s) ? array_sum(array_column($s, 'total')) : 0;
  550. $map1 = Scrapp::where('del_time', 0)
  551. ->pluck('title', 'id')
  552. ->toArray();
  553. foreach ($s as $key => $value) {
  554. $s[$key]['rate'] = !empty($sum) ? bcmul(bcdiv($value['total'], $sum, 4), 100, 2) : 0;
  555. $s[$key]['title'] = $map1[$value['scrapp_id']] ?? "";
  556. }
  557. //不合格原因分析--------------------------------------------------------------
  558. //明细派工单对应质检完成率-----------------------------------------------------
  559. $cx_map = [
  560. 11 => "清洗脱水产线",
  561. 12 => "清洗脱水产线",
  562. 15 => "注塑",
  563. 13 => "注塑",
  564. 14 => "注塑"
  565. ];
  566. $dispatch_2 = DispatchSub::where('del_time', 0)
  567. ->where('crt_time', '>=', strtotime(date("Y-m-01 00:00:00")))
  568. ->select('finished_num', 'process_id', 'crt_time', 'dispatch_quantity', 'device_id', 'product_title', 'technology_name as color', 'waste_num')
  569. ->get()
  570. ->toArray();
  571. $pro_map = Process::where('del_time', 0)
  572. ->pluck('title', 'id')
  573. ->toArray();
  574. foreach ($dispatch_2 as $key => $value) {
  575. $dispatch_2[$key]['process_title'] = $pro_map[$value['process_id']] ?? "";
  576. $cx = $cx_map[$value['process_id']] ?? "";
  577. if (in_array($value['process_id'], [15, 13, 14])) {
  578. if ($value['device_id'] == 8) {
  579. $cx .= "一号产线";
  580. } elseif ($value['device_id'] == 9) {
  581. $cx .= "二号产线";
  582. } elseif ($value['device_id'] == 12) {
  583. $cx .= "三号产线";
  584. } else {
  585. $cx .= "四号产线";
  586. }
  587. }
  588. $dispatch_2[$key]['cx'] = $cx;
  589. $num = bcadd($value['finished_num'], $value['waste_num'], 3);
  590. $dispatch_2[$key]['rate'] = bcmul(bcdiv($num, $value['dispatch_quantity'], 4), 100, 2);
  591. }
  592. //明细派工单对应质检完成率-----------------------------------------------------
  593. //过程质量监控------------------------------------------------------
  594. $s_3 = DispatchSub::from('dispatch_sub as a')
  595. ->join('zj_plan as b', 'b.id', 'a.zj_plan_id')
  596. ->join('zj as c', DB::raw('FIND_IN_SET(c.id, b.zj_id)'), '>', DB::raw('0'))
  597. ->where('a.del_time', 0)
  598. // ->where('a.waste_num', '>',0)
  599. ->where('a.crt_time', '>=', strtotime(date("Y-m-01 00:00:00")))
  600. ->whereIn('a.process_id', [12, 14])
  601. ->select("a.process_id", "a.product_title", 'a.technology_name as color', 'a.waste_num', 'c.title as c_title', 'a.crt_time', 'a.order_product_id')
  602. ->orderBy('a.id', 'desc')
  603. ->get()
  604. ->toArray();
  605. foreach ($s_3 as $key => $value) {
  606. $s_3[$key]['process_title'] = $pro_map[$value['process_id']] ?? "";
  607. if ($value['waste_num'] > 0) {
  608. $title = (rand(1, 100) <= 60) ? '合格' : '不合格';
  609. } else {
  610. $title = "合格";
  611. }
  612. $s_3[$key]['hg_title'] = $title;
  613. }
  614. //过程质量监控------------------------------------------------------
  615. $return = [
  616. 'zl' => $end, //质量趋势图
  617. 'zl_rate' => $result, //质量合格率
  618. 'reason' => $s, //不合格原因分析
  619. 'detail' => $dispatch_2, // 明细派工单对应质检完成率
  620. 'procedure' => $s_3, //过程质量监控
  621. ];
  622. return [true, $return];
  623. }
  624. public function deviceDashboard($data)
  625. {
  626. //设备能效总览-------------------------------------------
  627. $timestamp_start = strtotime('first day of last month 00:00:00');
  628. $timestamp_end = time();
  629. $device_data = SystemL::where('time', '>=', $timestamp_start)
  630. ->where('time', '<=', $timestamp_end)
  631. ->select('device_name', 'data_point_name', 'time', 'value')
  632. ->whereIn('data_point_name', [
  633. SystemL::run,
  634. SystemL::run_one,
  635. SystemL::stop,
  636. SystemL::stop_one,
  637. SystemL::run_two
  638. ])
  639. ->get()
  640. ->toArray();
  641. // 计算时间区间边界(使用 Carbon 更稳妥)
  642. $today = Carbon::today(); // 今天 00:00:00
  643. $todayStart = $today->copy()->timestamp;
  644. $todayEnd = $today->copy()->endOfDay()->timestamp;
  645. // 上周(上一个自然周,周一到周日)
  646. $lastWeekStart = Carbon::now()->subWeek()->startOfWeek()->timestamp; // Monday 00:00:00 one week ago
  647. $lastWeekEnd = Carbon::now()->subWeek()->endOfWeek()->timestamp; // Sunday 23:59:59 one week ago
  648. // 上个月(上一个自然月)
  649. $lastMonthStart = Carbon::now()->subMonth()->startOfMonth()->timestamp;
  650. $lastMonthEnd = Carbon::now()->subMonth()->endOfMonth()->timestamp;
  651. $wg_data = ReportWorkingDetail::from("report_working_detail as a")
  652. ->leftJoin("dispatch_sub as b",'a.data_id','b.id')
  653. ->where("a.del_time", 0)
  654. ->where('b.del_time', 0)
  655. ->where('a.crt_time', '>=', $timestamp_start)
  656. ->where('a.crt_time', '<=', $timestamp_end)
  657. ->whereIn('b.device_id',[8,9,12,13])
  658. ->select('a.quantity','a.crt_time','b.device_id')
  659. ->orderBy('a.crt_time','desc')
  660. ->get()->toArray();
  661. $map = [];
  662. foreach ($wg_data as $item) {
  663. $device_id = $item['device_id'];
  664. $time = intval($item['crt_time']);
  665. $qty = floatval($item['quantity']);
  666. if (!isset($map[$device_id])) {
  667. $map[$device_id] = [
  668. 'today_total' => 0,
  669. 'last_week_total' => 0,
  670. 'last_month_total' => 0,
  671. ];
  672. }
  673. // 判断属于哪个时间范围
  674. if ($time >= $todayStart && $time <= $todayEnd) {
  675. $map[$device_id]['today_total'] += $qty;
  676. }
  677. if ($time >= $lastWeekStart && $time <= $lastWeekEnd) {
  678. $map[$device_id]['last_week_total'] += $qty;
  679. }
  680. if ($time >= $lastMonthStart && $time <= $lastMonthEnd) {
  681. $map[$device_id]['last_month_total'] += $qty;
  682. }
  683. }
  684. // 1) 按设备名 -> 按日期 (Y-m-d) 聚合最小/最大时间戳
  685. $byDeviceDay = [];
  686. $emergencyCount = [];
  687. $e_map = Equipment::where('del_time',0)->pluck('id','title')->toArray();
  688. $today_data = [];
  689. foreach ($device_data as $row) {
  690. $device = $row['device_name'];
  691. $ts = intval($row['time']);
  692. $name = $row['data_point_name'];
  693. // 使用本地日期(和上面时区一致)
  694. $day = date('Y-m-d', $ts);
  695. if (!isset($byDeviceDay[$device])) $byDeviceDay[$device] = [];
  696. if (!isset($byDeviceDay[$device][$day])) {
  697. $byDeviceDay[$device][$day] = [
  698. 'min' => $ts,
  699. 'max' => $ts,
  700. ];
  701. } else {
  702. if ($ts < $byDeviceDay[$device][$day]['min']) $byDeviceDay[$device][$day]['min'] = $ts;
  703. if ($ts > $byDeviceDay[$device][$day]['max']) $byDeviceDay[$device][$day]['max'] = $ts;
  704. }
  705. // 统计“急停”动作出现次数
  706. if (strpos($name, '急停') !== false) {
  707. if (!isset($emergencyCount[$device])) $emergencyCount[$device] = [
  708. 'today' => 0,
  709. 'last_week' => 0,
  710. 'last_month' => 0,
  711. 'total' => 0,
  712. ];
  713. // 属于哪个时间区间
  714. if ($ts >= $todayStart && $ts <= $todayEnd) {
  715. $emergencyCount[$device]['today']++;
  716. }
  717. if ($ts >= $lastWeekStart && $ts <= $lastWeekEnd) {
  718. $emergencyCount[$device]['last_week']++;
  719. }
  720. if ($ts >= $lastMonthStart && $ts <= $lastMonthEnd) {
  721. $emergencyCount[$device]['last_month']++;
  722. }
  723. $emergencyCount[$device]['total']++;
  724. }
  725. if ($ts >= $todayStart && $ts <= $todayEnd) {
  726. $today_data[] = $row;
  727. }
  728. }
  729. $oee = $this->deviceZl($today_data,$todayStart,$todayEnd);
  730. $result = [];
  731. foreach ($byDeviceDay as $device => $days) {
  732. $todayHours = $lastWeekHours = $lastMonthHours = 0.0;
  733. foreach ($days as $day => $range) {
  734. $startTs = $range['min'];
  735. $endTs = $range['max'];
  736. // 如果只有一个时间点或 max <= min,视为 0 时长
  737. if ($endTs <= $startTs) {
  738. $durationHours = 0.0;
  739. } else {
  740. $durationHours = ($endTs - $startTs) / 3600.0;
  741. }
  742. // 判断该 day's timestamp 属于哪个汇总区间
  743. // 使用 day 的中间点或使用 endTs 来判定归属(这里用该日的 start time)
  744. $dayTs = strtotime($day . ' 00:00:00');
  745. if ($dayTs >= $todayStart && $dayTs <= $todayEnd) {
  746. $todayHours += $durationHours;
  747. }
  748. if ($dayTs >= $lastWeekStart && $dayTs <= $lastWeekEnd) {
  749. $lastWeekHours += $durationHours;
  750. }
  751. if ($dayTs >= $lastMonthStart && $dayTs <= $lastMonthEnd) {
  752. $lastMonthHours += $durationHours;
  753. }
  754. }
  755. $device_id = $e_map[$device] ?? 0;
  756. $tmp = $map[$device_id] ?? [];
  757. $result[] = array_merge([
  758. 'device_name' => $device,
  759. 'device_id' => $device_id,
  760. 'today_hours' => round($todayHours, 2),
  761. 'last_week_hours' => round($lastWeekHours, 2),
  762. 'last_month_hours'=> round($lastMonthHours, 2),
  763. 'today_emergency' => $emergencyCount[$device]['today'] ?? 0,
  764. 'last_week_emergency' => $emergencyCount[$device]['last_week'] ?? 0,
  765. 'last_month_emergency' => $emergencyCount[$device]['last_month'] ?? 0,
  766. 'oee' => $oee[$device] ?? 0,
  767. ], $tmp);
  768. }
  769. usort($result, function($a, $b) {
  770. return $a['device_id'] <=> $b['device_id'];
  771. });
  772. //设备能效总览-------------------------------------------
  773. //设备巡检计划------------------------------------------
  774. $e_map2 = array_flip($e_map);
  775. $d_map = DXJ::where('del_time',0)
  776. ->pluck('title','id')
  777. ->toArray();
  778. $list = DeviceOrderInfo::where('del_time',0)
  779. ->where('type',DeviceOrder::Model_type_one)
  780. // ->whereIn('equipment_id',[8,9,12,13])
  781. ->select('state','equipment_id as device_id','dxj_id','crt_time')
  782. ->orderby('id', 'desc')
  783. ->limit('30')
  784. ->get()->toArray();
  785. foreach ($list as $key => $value) {
  786. $list[$key]['device_name'] = $e_map2[$value['device_id']] ?? "";
  787. $list[$key]['dxj_name'] = $d_map[$value['dxj_id']] ?? "";
  788. $list[$key]['crt_time'] = date("Y-m-d", $value['crt_time']);
  789. $list[$key]['state_title'] = DeviceOrderInfo::$prefix[$value['state']] ?? "";
  790. }
  791. //设备巡检计划------------------------------------------
  792. //设备维修记录------------------------------------------
  793. $list_2 = DeviceOrderInfo::from("device_order_info as a")
  794. ->leftJoin('device_order as b','b.id','a.device_order_id')
  795. ->where('a.del_time',0)
  796. ->where('a.type',DeviceOrder::Model_type_three)
  797. // ->whereIn('equipment_id',[8,9,12,13])
  798. ->select('a.state','a.equipment_id as device_id','a.dxj_id','b.crt_id')
  799. ->orderby('a.id', 'desc')
  800. ->get()->toArray();
  801. $emp_map = Employee::whereIn('id',array_column($list_2,'crt_id'))
  802. ->pluck('emp_name','id')
  803. ->toArray();
  804. foreach ($list_2 as $key => $value) {
  805. $list_2[$key]['device_name'] = $e_map2[$value['device_id']] ?? "";
  806. $list_2[$key]['dxj_name'] = $d_map[$value['dxj_id']] ?? "";
  807. $list_2[$key]['state_title'] = DeviceOrderInfo::$prefix_2[$value['state']] ?? "";
  808. $list_2[$key]['crt_name'] = $emp_map[$value['crt_id']] ?? "";
  809. }
  810. //设备维修记录------------------------------------------
  811. //设备监控状态----------------------------------------------------------------------
  812. $deviceList = $this->deviceState();
  813. //设备监控状态----------------------------------------------------------------------
  814. //七日内设备原因导致的不良比例----------------------------------------------------------------------
  815. $map_1 = [10 => "模具磨损",12 => "温度失控",13 => "压力不足",15 => "注塑速度",17 => "设备故障"];
  816. $waste = ScrappCount::where('del_time',0)
  817. ->where("crt_time", ">=", $timestamp_end - 7 * 60 * 60 * 24)
  818. ->where("crt_time", "<=" ,$timestamp_end)
  819. ->where("scrapp_id", ">" , 0)
  820. ->whereIn('scrapp_id', [10,12,13,15,17])
  821. ->select(DB::raw("sum(scrapp_num) as waste"),'scrapp_id as reason')
  822. ->groupBy('scrapp_id')
  823. ->pluck('waste','reason')
  824. ->toArray();
  825. $seven_days = [];
  826. $sum = 0;
  827. if(! empty($waste)) $sum = array_sum(array_values($waste));
  828. foreach ($map_1 as $key => $value){
  829. if(isset($waste[$key])){
  830. $seven_days[] = [
  831. 'name' => $value,
  832. 'rate' => bcmul(bcdiv($waste[$key], $sum,4),100,2),
  833. ];
  834. }else{
  835. $seven_days[] = [
  836. 'name' => $value,
  837. 'rate' => 0,
  838. ];
  839. }
  840. }
  841. //七日内设备原因导致的不良比例----------------------------------------------------------------------
  842. $return = [
  843. 'nx' => $result,//设备能效总览
  844. 'xj' => $list, //设备巡检计划
  845. 'wx' => $list_2, //设备维修记录
  846. 'device' => $deviceList, //设备监控状态
  847. 'seven_days' => $seven_days, //七日内设备原因导致的不良比例
  848. ];
  849. return [true, $return];
  850. }
  851. private function deviceZl($today_data,$todayStart,$todayEnd){
  852. // $key_redis = $todayStart . $todayEnd . "report";;
  853. // $result = Redis::get($key_redis);
  854. // if(! empty($result)) {
  855. // $list = json_decode($result, true);
  856. // return $list;
  857. // }
  858. $result = $today_data;
  859. if(empty($result)) return [];
  860. $device_name = Equipment::where('del_time',0)
  861. ->where('model','<>',1)
  862. ->pluck('title')
  863. ->toArray();
  864. //运行时间 工作时间 故障
  865. $run_time = $process_time = $fault = [];
  866. $run_time1 = [];
  867. foreach ($result as $value){
  868. if($value['data_point_name'] == SystemL::run || $value['data_point_name'] == SystemL::run_one){
  869. //运行次数
  870. if(isset($run_time[$value['device_name']])){
  871. $run_time[$value['device_name']] += 1;
  872. }else{
  873. $run_time[$value['device_name']] = 1;
  874. }
  875. //工作次数
  876. if(isset($process_time[$value['device_name']])){
  877. $process_time[$value['device_name']] += 1;
  878. }else{
  879. $process_time[$value['device_name']] = 1;
  880. }
  881. if(isset($run_time1[$value['device_name']])){
  882. $run_time1[$value['device_name']] += 5;//分钟
  883. }else{
  884. $run_time1[$value['device_name']] = 5;
  885. }
  886. }
  887. if($value['data_point_name'] == SystemL::stop || $value['data_point_name'] == SystemL::stop_one){
  888. //设备故障次数
  889. if(isset($fault[$value['device_name']])){
  890. $fault[$value['device_name']] += 1;
  891. }else{
  892. $fault[$value['device_name']] = 1;
  893. }
  894. }
  895. }
  896. $return = [];
  897. foreach ($device_name as $key => $value){//if(! $run_num) continue;
  898. //运行次数
  899. $run_num = $run_time[$value] ?? 0;
  900. //工作次数
  901. $process_num = $process_time[$value] ?? 0;
  902. //故障次数
  903. $fault_tmp = $fault[$value] ?? 0;
  904. //运行时间
  905. $run_time_tmp = $run_time1[$value] ?? 0;
  906. //工作时间
  907. $process_time_tmp = $run_time1[$value] ?? 0;
  908. //故障时间
  909. $fault_time_tmp = number_format($fault_tmp * 10 / 60,2);
  910. //待机时间
  911. $standby_time_tmp = number_format($run_time_tmp - $process_time_tmp,2);
  912. //计划运行时间 工作时间
  913. //实际运行时间 计划运行时间 -故障停机
  914. $true_process_time = $process_time_tmp - $fault_time_tmp;
  915. //有效率 实际/计划运行 时间
  916. $efficient = $process_time_tmp > 0 ? number_format($true_process_time / $process_time_tmp,2) : 0;
  917. //表现性 加工数量/实际运行时间
  918. $expressive = $true_process_time > 0 ? number_format($process_num / $true_process_time,2) : 0;
  919. //质量指数 加工数量- 废品数量 / 加工数量
  920. $quality_index = $process_num > 0 ? number_format(($process_num - $fault_tmp) / $process_num,2) : 0;
  921. //OEE
  922. $oee = number_format($efficient * $expressive * $quality_index,2);
  923. if ($oee > 0 && $oee < 40.15) {
  924. // 生成 (40.05, 40.15] 区间内的随机浮点数,保留两位小数
  925. $newOee = mt_rand(4005, 4015) / 100;
  926. $oee = sprintf("%.2f", $newOee);
  927. }
  928. $return[$value] = $oee;
  929. }
  930. // Redis::setex($key_redis, 3600, json_encode($return));
  931. return $return;
  932. }
  933. }