ScreenController.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Model\ApplyOrder;
  4. use App\Model\ApplyOrderDetail;
  5. use App\Model\Box;
  6. use App\Model\BoxDetail;
  7. use App\Model\DispatchEmpSub;
  8. use App\Model\DispatchSub;
  9. use App\Model\EmployeeTeamPermission;
  10. use App\Model\Equipment;
  11. use App\Model\ForDeviceData;
  12. use App\Model\OrdersProduct;
  13. use App\Model\OrdersProductProcess;
  14. use App\Model\Process;
  15. use App\Model\SaleOrdersProduct;
  16. use App\Model\SalesFrom;
  17. use App\Model\ScrappCount;
  18. use App\Model\SystemL;
  19. use App\Model\Team;
  20. use App\Service\EquipmentService;
  21. use App\Service\FyySqlServerService;
  22. use App\Service\ReportFormsService;
  23. use Carbon\Carbon;
  24. use Illuminate\Http\Request;
  25. use Illuminate\Support\Facades\Cache;
  26. use Illuminate\Support\Facades\DB;
  27. use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
  28. /**
  29. * 大屏数据展示
  30. * Class ScreenController
  31. * @package App\Http\Controllers\Api
  32. */
  33. class ScreenController extends BaseController
  34. {
  35. /**
  36. * 产值数据全览
  37. * @param Request $request
  38. * @return array
  39. */
  40. public function output_value(Request $request){
  41. $currentYear = Carbon::now()->year;
  42. $lastYear = $currentYear - 1;
  43. $currentMonth = Carbon::now()->month;
  44. $totalValueAllTime = SaleOrdersProduct::where('del_time',0)
  45. ->sum('finished_num');
  46. $totalValueAllTime = $totalValueAllTime . "(吨)";
  47. $totalValueLastYear = SaleOrdersProduct::where('del_time',0)
  48. ->whereRaw("YEAR(FROM_UNIXTIME(crt_time)) = $lastYear")
  49. ->sum('finished_num');
  50. $totalValueLastYear = $totalValueLastYear . "(吨)";
  51. $totalValueCurrentYearMonth = SaleOrdersProduct::where('del_time',0)
  52. ->whereRaw("YEAR(FROM_UNIXTIME(crt_time)) = $currentYear AND MONTH(FROM_UNIXTIME(crt_time)) = $currentMonth")
  53. ->sum('finished_num');
  54. $totalValueCurrentYearMonth = $totalValueCurrentYearMonth . "(吨)";
  55. return $this->json_return(200,'',['total_time'=>$totalValueAllTime, 'total_last_year'=>$totalValueLastYear, 'total_current_month'=>$totalValueCurrentYearMonth]);
  56. }
  57. /**
  58. * 项目进度
  59. * @param Request $request
  60. * @return array
  61. */
  62. public function order_process1(Request $request) {
  63. $firstDayOfMonth = strtotime(date('Y-m-01 00:00:00'));
  64. $result = SaleOrdersProduct::where('del_time',0)
  65. ->where('out_order_no_time', '>=',$firstDayOfMonth)
  66. ->select(DB::raw('sum(order_quantity) as total'), DB::raw('sum(finished_num) as finished_num'),'out_order_no as Code','customer_name as CustomerName','pre_shipment_time')
  67. ->groupBy('out_order_no')
  68. ->orderBy('id', 'desc') // 添加这一行以按创建时间降序排序
  69. ->get()->toArray();
  70. if(! empty($result)){
  71. foreach ($result as $key => $value){
  72. $rate = bcmul(bcdiv($value['finished_num'], $value['total'],2),100,2);
  73. if($rate > 100) $rate = "100.00";
  74. $result[$key]['rate'] = $rate;
  75. if($result[$key]['rate'] >= 100){
  76. $result[$key]['is_over'] = '否';
  77. }else{
  78. $t = $value['pre_shipment_time'];
  79. if(time() > $t) $result[$key]['is_over'] = '是';
  80. else $result[$key]['is_over'] = '否';
  81. }
  82. unset($result[$key]['total']);
  83. unset($result[$key]['finished_num']);
  84. }
  85. $rate = array_column($result, 'rate'); // 提取列作为排序依据
  86. array_multisort($rate, SORT_DESC,$result);
  87. }
  88. return $this->json_return(200,'',$result);
  89. }
  90. /**
  91. * 历史项目 在手项目
  92. * @param Request $request
  93. * @return array
  94. */
  95. public function project_region(Request $request){
  96. $all = SaleOrdersProduct::where('del_time',0)
  97. ->whereColumn('order_quantity','=','finished_num')
  98. ->select('out_order_no')
  99. ->groupBy('out_order_no')
  100. ->get()
  101. ->toArray();
  102. $all = array_column($all,'out_order_no');
  103. $not_all = SaleOrdersProduct::where('del_time',0)
  104. ->whereColumn('order_quantity','<>','finished_num')
  105. ->select('out_order_no')
  106. ->groupBy('out_order_no')
  107. ->get()
  108. ->toArray();
  109. $not_all = array_column($not_all,'out_order_no');
  110. $all = array_diff($all, $not_all);
  111. $arr = [
  112. "all_num" => count($all) + 8000,
  113. "num" => count($not_all),
  114. ];
  115. return $this->json_return(200,'',$arr);
  116. }
  117. /**
  118. * 本月质量
  119. * @param Request $request
  120. * @return array
  121. */
  122. public function output_value_month1(Request $request){
  123. $date = date('Ymd',time());
  124. $startDate = strtotime(date('Y-m-01 00:00:00', time()));
  125. $endDate = strtotime(date('Y-m-t 23:59:59', time()));
  126. $return = $this->getDayInMonth();
  127. //获取数据
  128. $data = ScrappCount::where('crt_time','>=',$startDate)
  129. ->where('crt_time','<',$endDate)
  130. ->where('del_time',0)
  131. ->select('crt_time as time','scrapp_num as value')
  132. ->get()->toArray();
  133. if(! empty($data)){
  134. foreach ($data as $value){
  135. $crt_time = date('Y-m-d',$value['time']);
  136. if(isset($return[$crt_time])){
  137. $return[$crt_time]['value'] += 1;
  138. }
  139. }
  140. ksort($return);
  141. }
  142. $return = array_values($return);
  143. return $this->json_return(200,'',$return);
  144. }
  145. function getDayInMonth(){
  146. $startDate = strtotime(date('Y-m-01 00:00:00', time()));
  147. // 获取当前日期
  148. $currentDate = time();
  149. $dates = array();
  150. while ($currentDate >= $startDate) {
  151. $t = date('Y-m-d', $currentDate);
  152. $dates[$t] = [
  153. 'value' => $t,
  154. 'num' => 0
  155. ];
  156. $currentDate = strtotime('-1 day', $currentDate);
  157. }
  158. return $dates;
  159. }
  160. /**
  161. * 本月质量
  162. * @param Request $request
  163. * @return array
  164. */
  165. // public function output_value_month11(Request $request){
  166. // $date = date('Ymd',time());
  167. //
  168. // $startDate = strtotime(date('Y-m-01 00:00:00', time()));
  169. // $endDate = strtotime(date('Y-m-t 23:59:59', time()));
  170. // //工序-----------------------------
  171. // $model = new OrdersProductProcess(['channel' => $date]);//当前季度的数据
  172. // $data = $model->where('del_time',0)
  173. // ->where('status',4)
  174. // ->select('crt_time')
  175. // ->where('crt_time','>=',$startDate)
  176. // ->where('crt_time','<=',$endDate)
  177. // ->get()->toArray();
  178. //
  179. // $return = [];
  180. // if(! empty($data)){
  181. // foreach ($data as $value){
  182. // $crt_time = date('Y-m-d',$value['crt_time']);
  183. // if(isset($return[$crt_time])){
  184. // $return[$crt_time]['num'] += 1;
  185. // }else{
  186. // $return[$crt_time] = [
  187. // 'num' => 1,
  188. // 'value' => $crt_time
  189. // ];
  190. // }
  191. // }
  192. // }
  193. // $return = array_values($return);
  194. // return $this->json_return(200,'',$return);
  195. // }
  196. /**
  197. * 产量趋势图
  198. * @param Request $request
  199. * @return array
  200. */
  201. public function output_value_efficiency1(Request $request){
  202. // 获取当前时间戳
  203. $currentTimestamp = time();
  204. // 输出过去两周的起止时间(包括当前日期)
  205. $timestamp = strtotime("-13 days", $currentTimestamp);
  206. $startOfDay = strtotime(date('Y-m-d 00:00:00', $timestamp));
  207. $endOfDay = strtotime(date('Y-m-d 23:59:59', $currentTimestamp));
  208. $box = Box::where('del_time',0)
  209. ->where('crt_time','>=',$startOfDay)
  210. ->where('crt_time','<=',$endOfDay)
  211. ->select('crt_time','top_order_no','order_no')
  212. ->orderBy('crt_time','desc')
  213. ->get()->toArray();
  214. $result = [];
  215. if(! empty($box)){
  216. foreach ($box as $value){
  217. $model = new BoxDetail(['channel' => $value['top_order_no']]);
  218. $map = $model->where('del_time',0)
  219. ->where('order_no',$value['order_no'])
  220. ->select('order_no',DB::raw('sum(num) as num'))
  221. ->groupBy('order_no')
  222. ->pluck('num','order_no')
  223. ->toArray();
  224. $output = $map[$value['order_no']] ?? 0;
  225. $times = date('Y-m-d',$value['crt_time']);
  226. if(isset($result[$times])){
  227. $result[$times]['output'] += $output;
  228. }else{
  229. $result[$times] = [
  230. 'time' => $times,
  231. 'output' => $output
  232. ];
  233. }
  234. }
  235. }
  236. $result = array_values($result);
  237. return $this->json_return(200,'',$result);
  238. }
  239. //产量趋势图(完工)
  240. public function output_value_efficiency11(Request $request){
  241. $list = DispatchSub::where('del_time',0)
  242. ->where('finished_num','>=',0)
  243. ->select('crt_time','finished_num')
  244. ->orderBy('id','desc')
  245. ->limit(20)
  246. ->get()->toArray();
  247. $return = [];
  248. foreach ($list as $value){
  249. $date = date("Y-m-d",$value['crt_time']);
  250. if(isset($return[$date])){
  251. $num = bcadd($value['finished_num'], $return[$date]['output'],3);
  252. $return[$date]['output'] = $num;
  253. }else{
  254. $return[$date] = [
  255. 'output' => $value['finished_num'],
  256. 'time' => $date,
  257. ];
  258. }
  259. }
  260. ksort($return);
  261. $result = array_values($return);
  262. return $this->json_return(200,'',$result);
  263. }
  264. //产量趋势图
  265. public function output_value_efficiency(Request $request){
  266. $time = strtotime('-2 month');
  267. $return = [];
  268. $data = ApplyOrderDetail::where('del_time',0)
  269. ->where('type',ApplyOrder::type_two)
  270. ->where('crt_time','>=',$time)
  271. ->select('quantity','crt_time','data_id')
  272. ->get()->toArray();
  273. $dispatch = DispatchSub::whereIn('id',array_column($data,'data_id'))
  274. ->pluck('sale_orders_product_id','id')
  275. ->toArray();
  276. $sale_order_map = [];
  277. $sale_order = SaleOrdersProduct::whereIn('id', array_unique(array_values($dispatch)))
  278. ->select('order_quantity','id','crt_time')
  279. ->get()
  280. ->toArray();
  281. foreach ($sale_order as $value){
  282. $sale_order_map[$value['id']] = $value;
  283. }
  284. $plan = $plan_2 = [];
  285. foreach ($data as $value) {
  286. $date = date("Y-m-d", $value['crt_time']);
  287. if (isset($return[$date])) {
  288. $quantity = bcadd($return[$date], $value['quantity'], 3);
  289. $return[$date] = $quantity;
  290. } else {
  291. $return[$date] = $value['quantity'];
  292. }
  293. $sale_id = $dispatch[$value['data_id']] ?? 0;
  294. $n = $sale_order_map[$sale_id] ?? [];
  295. if(! empty($n)){
  296. $date_2 = date("Y-m-d", $n['crt_time']);
  297. if(isset($plan_2[$date_2]) && in_array($sale_id, $plan_2[$date_2])) continue;
  298. if (isset($plan[$date_2])) {
  299. $quantity = bcadd($plan[$date_2], $n['order_quantity'], 3);
  300. $plan[$date_2] = $quantity;
  301. } else {
  302. $plan[$date_2] = $n['order_quantity'];
  303. }
  304. $plan_2[$date_2][] = $sale_id;
  305. }
  306. }unset($plan_2);
  307. ksort($return);
  308. $result = [];
  309. foreach ($return as $key => $value){
  310. $tmp = [
  311. 'time' => $key,
  312. 'output' => $value,
  313. 'plan' => $plan[$key] ?? $value,
  314. ];
  315. $result[] = $tmp;
  316. }
  317. return $this->json_return(200,'',$result);
  318. }
  319. function getDay(){
  320. // 获取当前季度的开始日期
  321. $month = date('m');
  322. if ($month >= 1 && $month <= 3) {
  323. $quarter = 1;
  324. } elseif ($month >= 4 && $month <= 6) {
  325. $quarter = 2;
  326. } elseif ($month >= 7 && $month <= 9) {
  327. $quarter = 3;
  328. } else {
  329. $quarter = 4;
  330. }
  331. $year = date('Y'); // 获取当前年份
  332. if ($quarter == 1) {
  333. $startDate = strtotime("$year-01-01"); // 第一季度的开始日期
  334. } elseif ($quarter == 2) {
  335. $startDate = strtotime("$year-04-01"); // 第二季度的开始日期
  336. } elseif ($quarter == 3) {
  337. $startDate = strtotime("$year-07-01"); // 第三季度的开始日期
  338. } else {
  339. $startDate = strtotime("$year-10-01"); // 第四季度的开始日期
  340. }
  341. // 获取当前日期
  342. $currentDate = time();
  343. // 生成当前季度到今天为止的所有日期
  344. $dates = array();
  345. while ($currentDate >= $startDate) {
  346. $t = date('Y-m-d', $currentDate);
  347. $dates[$t] = [
  348. 'time' => $t,
  349. 'output' => 0
  350. ];
  351. $currentDate = strtotime('-1 day', $currentDate);
  352. }
  353. return $dates;
  354. }
  355. /**
  356. * 工序负荷全览
  357. * @param Request $request
  358. * @return array
  359. */
  360. public function capacity(Request $request){
  361. $process = Process::where('del_time',0)->get()->toArray();
  362. $list = DispatchSub::where('del_time',0)
  363. ->where('dispatch_quantity','>=',0)
  364. ->select('crt_time','dispatch_quantity')
  365. ->orderBy('id','desc')
  366. ->limit(20)
  367. ->get()->toArray();
  368. $return = [];
  369. foreach ($list as $value){
  370. $date = date("Ymd",$value['crt_time']);
  371. if(isset($return[$date])){
  372. $num = bcadd($value['dispatch_quantity'], $return[$date],3);
  373. $return[$date] = $num;
  374. }else{
  375. $return[$date] = $value['dispatch_quantity'];
  376. }
  377. }
  378. $maxValue = empty($return) ? 0 : max($return);
  379. $today = $return[date("Ymd")] ?? 0;
  380. $rate = $maxValue ? intval($today/$maxValue * 100) : 0;
  381. $array = [];
  382. foreach ($process as $value){
  383. $array[] = [
  384. [
  385. 'title' => $value['title'],
  386. 'rate' => $rate
  387. ]
  388. ];
  389. }
  390. //工序-----------------------------
  391. return $this->json_return(200,'',['data' => $array]);
  392. }
  393. public function systemDataList(Request $request){
  394. $data = $request->all();
  395. $model = SystemL::select('*')
  396. ->where('time','<=', time())
  397. ->orderBy('time','desc');
  398. if(! empty($data['device_name'])) $model->where('device_name', 'LIKE', '%'.$data['device_name'].'%');
  399. if(! empty($data['device_no'])) $model->where('device_no', 'LIKE', '%'.$data['device_no'].'%');
  400. if(! empty($data['data_point_name'])) $model->where('data_point_name', 'LIKE', '%'.$data['data_point_name'].'%');
  401. if(! empty($data['time'][0]) && ! empty($data['time'][1])) {
  402. $model->where('time','>=',$data['time'][0]);
  403. $model->where('time','<=',$data['time'][1]);
  404. }
  405. $list = $this->limitC($model,'',$data);
  406. foreach ($list['data'] as $key => $value){
  407. $list['data'][$key]['time'] = $value['time'] ? date('Y-m-d H:i:s', $value['time']) : '';
  408. }
  409. return $this->json_return(200,'',$list);
  410. }
  411. //分页共用
  412. public function limitC($db, $columns, $request)
  413. {
  414. $per_page = $request['page_size'] ?? 20;
  415. $page = $request['page_index'] ?? 1;
  416. $return = $db->paginate($per_page, $columns, 'page', $page)->toArray();
  417. $data['total'] = $return['total'];
  418. $data['data'] = $return['data'];
  419. return $data;
  420. }
  421. /**
  422. * 设备信息
  423. * @param Request $request
  424. * @return array
  425. */
  426. public function product_num(Request $request){
  427. //数据模型
  428. $models = [];
  429. $device = (new EquipmentService())->getDeviceList();
  430. foreach ($device as $k => $v){
  431. $models[$k] = [
  432. "machine_day_num"=> 0,
  433. "machine_month_num"=> 0,
  434. "machine_week_num"=> 0,
  435. "break_day_num"=> 0,
  436. "break_month_num"=> 0,
  437. "break_week_num"=> 0,
  438. "start_time"=> '',
  439. "day_num"=> 0,
  440. "week_num"=> 0,
  441. "month_num"=> 0,
  442. "rate"=> 0
  443. ];
  444. }
  445. //当天的开始与结束时间戳
  446. $timestamp_today_start = strtotime(date("Y-m-d 00:00:00",time()));
  447. $timestamp_today_end = strtotime(date("Y-m-d 23:59:59",time()));
  448. //查询当日
  449. $today = SystemL::where('time','>=',$timestamp_today_start)
  450. ->where('time','<=',$timestamp_today_end)
  451. ->select('device_name','data_point_name','time','value')
  452. ->whereIn('data_point_name',[SystemL::run,SystemL::run_one,SystemL::stop,SystemL::stop_one,SystemL::run_two])
  453. ->get()->toArray();
  454. //组织当日数据
  455. $this->fillData($today,1,$models,$device);
  456. //上周时间
  457. $previousWeekStartDate = Carbon::now()->subWeek()->startOfWeek();
  458. $previousWeekEndDate = Carbon::now()->subWeek()->endOfWeek();
  459. //上周开始结束日期
  460. $start_week = $previousWeekStartDate->toDateString();
  461. $end_week = $previousWeekEndDate->toDateString();
  462. $last_week_key = $start_week . $end_week;
  463. list($status, $return_last_week) = $this->getRedisData($last_week_key);
  464. if(! $status){
  465. $previousWeekStartTimeStamp = $previousWeekStartDate->timestamp;
  466. $previousWeekEndTimeStamp = $previousWeekEndDate->timestamp;
  467. //获取上周数据
  468. $list_week = SystemL::where('time','>=',$previousWeekStartTimeStamp)
  469. ->where('time','<=',$previousWeekEndTimeStamp)
  470. ->select('device_name','data_point_name','value')
  471. ->whereIn('data_point_name',[SystemL::run,SystemL::run_one,SystemL::stop,SystemL::stop_one,SystemL::run_two])
  472. ->get()->toArray();
  473. //组织上周数据
  474. $this->fillData($list_week,2,$models,$device);
  475. //缓存
  476. // Cache::put($last_week_key,json_encode($list_week),86400);
  477. }else{
  478. //有缓存 填充数据 组织上周数据
  479. $this->fillData($return_last_week,2,$models,$device);
  480. }
  481. //上月时间
  482. $previousMonthStartDate = Carbon::now()->subMonth()->startOfMonth();
  483. $previousMonthEndDate = Carbon::now()->subMonth()->endOfMonth();
  484. //上月开始结束日期
  485. $start_month = $previousMonthStartDate->toDateString();
  486. $end_month = $previousMonthEndDate->toDateString();
  487. $last_month_key = $start_month . $end_month;
  488. list($status, $return_last_month) = $this->getRedisData($last_month_key);
  489. if(! $status){
  490. $previousMonthStartTimeStamp = $previousMonthStartDate->timestamp;
  491. $previousMonthEndTimeStamp = $previousMonthEndDate->timestamp;
  492. //获取上月数据
  493. $list_month = SystemL::where('time','>=',$previousMonthStartTimeStamp)
  494. ->where('time','<=',$previousMonthEndTimeStamp)
  495. ->select('device_name','data_point_name','value')
  496. ->whereIn('data_point_name',[SystemL::run,SystemL::run_one,SystemL::stop,SystemL::stop_one,SystemL::run_two])
  497. ->get()->toArray();
  498. //组织上月数据
  499. $this->fillData($list_month,3,$models,$device);
  500. //缓存
  501. // Cache::put($last_month_key,json_encode($list_month),86400);
  502. }else{
  503. //有缓存 填充数据 组织上周数据
  504. $this->fillData($return_last_month,3,$models,$device);
  505. }
  506. $return = [];
  507. foreach ($models as $key => $value){
  508. $value['device_name'] = $key;
  509. $return[] = $value;
  510. }
  511. return $this->json_return(200,'',$return);
  512. }
  513. //在制工单
  514. public function work_order(Request $request){
  515. // 获取当前时间戳
  516. $currentTimestamp = time();
  517. $startOfDay = strtotime(date('Y-m-1 00:00:00', $currentTimestamp));
  518. $endOfDay = strtotime(date('Y-m-d 23:59:59', $currentTimestamp));
  519. $result = DispatchSub::where('del_time',0)
  520. ->where('crt_time',">=", $startOfDay)
  521. ->where('crt_time',"<=", $endOfDay)
  522. ->whereColumn('dispatch_quantity','>','finished_num')
  523. ->select('dispatch_no','process_id','product_title','technology_name','dispatch_quantity as product_num','finished_num as finish_num','sale_orders_product_id')
  524. ->get()->toArray();
  525. $map = SaleOrdersProduct::whereIn('id',array_unique(array_column($result, 'sale_orders_product_id')))
  526. ->pluck('out_order_no','id')
  527. ->toArray();
  528. if(! empty($result)){
  529. $process_id = array_unique(array_column($result,'process_id'));
  530. $processMap = Process::whereIn('id',$process_id)
  531. ->pluck('title','id')
  532. ->toArray();
  533. foreach ($result as $key => $value){
  534. $result[$key]['procedure'] = $processMap[$value['process_id']] ?? '';
  535. $result[$key]['product_title'] = $value['product_title'] . "(". $value['technology_name'] .")";
  536. $result[$key]['order_no'] = $map[$value['sale_orders_product_id']] ?? "";
  537. }
  538. }
  539. return $this->json_return(200,'',$result);
  540. }
  541. /**
  542. * 待加工
  543. * @param Request $request
  544. * @return array
  545. */
  546. public function nu_work_order(Request $request){
  547. $startOfDay = strtotime(date('Y-m-1 00:00:00'));
  548. $result = DispatchSub::where('del_time',0)
  549. ->where('crt_time',">=", $startOfDay)
  550. ->where('finished_num',0)
  551. ->select('dispatch_no','product_title','technology_name','dispatch_quantity as product_num','process_id','sale_orders_product_id')
  552. ->orderBy('id','desc')
  553. ->limit(20)
  554. ->get()->toArray();
  555. $map = SaleOrdersProduct::whereIn('id',array_unique(array_column($result, 'sale_orders_product_id')))
  556. ->pluck('out_order_no','id')
  557. ->toArray();
  558. if(! empty($result)){
  559. $process_id = array_unique(array_column($result,'process_id'));
  560. $processMap = Process::whereIn('id',$process_id)
  561. ->pluck('title','id')
  562. ->toArray();
  563. foreach ($result as $key => $value){
  564. $result[$key]['procedure'] = $processMap[$value['process_id']] ?? '';
  565. $result[$key]['product_title'] = $value['product_title'] . "(". $value['technology_name'] .")";
  566. $result[$key]['order_no'] = $map[$value['sale_orders_product_id']] ?? "";
  567. }
  568. }
  569. return $this->json_return(200,'',$result);
  570. }
  571. //获取缓存
  572. public function getRedisData($cacheKey){
  573. if(Cache::has($cacheKey)){
  574. return [true,json_decode(Cache::get($cacheKey),true)];
  575. }
  576. return [false, []];
  577. }
  578. /**
  579. * 数据填充
  580. * @param $list
  581. * @param $type
  582. * @param $models
  583. */
  584. public function fillData($list,$type,&$models,$device){
  585. if(empty($list)) return;
  586. $run_time = $run_time1 = $process_time = $finished_num = $fault = $start_time = [];
  587. foreach ($list as $value){
  588. if($type == 1 && ! isset($start_time[$value['device_name']])){
  589. $start_time_tmp = date("Y-m-d H:i:s", $value['time']);
  590. $start_time[$value['device_name']] = $start_time_tmp;
  591. }
  592. if($value['data_point_name'] == SystemL::run || $value['data_point_name'] == SystemL::run_one){
  593. //运行次数
  594. if(isset($run_time[$value['device_name']])){
  595. $run_time[$value['device_name']] += 1;
  596. }else{
  597. $run_time[$value['device_name']] = 1;
  598. }
  599. //工作次数
  600. if(isset($process_time[$value['device_name']])){
  601. $process_time[$value['device_name']] += 1;
  602. }else{
  603. $process_time[$value['device_name']] = 1;
  604. }
  605. if(isset($run_time1[$value['device_name']])){
  606. $run_time1[$value['device_name']] += 5;//分钟
  607. }else{
  608. $run_time1[$value['device_name']] = 5;
  609. }
  610. }
  611. if($value['data_point_name'] == SystemL::run_two){
  612. if(isset($finished_num[$value['device_name']])){
  613. $tmp = bcadd($finished_num[$value['device_name']], $value['value'],2);
  614. $finished_num[$value['device_name']] = $tmp;
  615. }else{
  616. $finished_num[$value['device_name']] = $value['value'];
  617. }
  618. }
  619. if($value['data_point_name'] == SystemL::stop || $value['data_point_name'] == SystemL::stop_one){
  620. //故障次数
  621. if(isset($fault[$value['device_name']])){
  622. $fault[$value['device_name']] += 1;
  623. }else{
  624. $fault[$value['device_name']] = 1;
  625. }
  626. }
  627. }
  628. foreach ($device as $key => $value){
  629. $finished = $finished_num[$key] ?? 0;
  630. //运行次数
  631. $run_num = $run_time[$key] ?? 0;
  632. //工作次数
  633. $process_num = $process_time[$key] ?? 0;
  634. //故障次数
  635. $fault_tmp = $fault[$key] ?? 0;
  636. //运行时间
  637. $run_time_tmp = $run_time1[$key] ?? 0;
  638. $run_time_tmp = $run_time_tmp;
  639. //工作时间
  640. $process_time_tmp = $run_time1[$key] ?? 0;
  641. //故障时间
  642. $fault_time_tmp = number_format($fault_tmp * 10 / 60,2);
  643. //计划运行时间 工作时间
  644. //实际运行时间 计划运行时间 -故障停机
  645. $true_process_time = $process_time_tmp - $fault_time_tmp;
  646. //有效率 实际/计划运行 时间
  647. $efficient = $process_time_tmp > 0 ? number_format($true_process_time / $process_time_tmp,2) : 0;
  648. //表现性 加工数量/实际运行时间
  649. $expressive = $true_process_time > 0 ? number_format($process_num / $true_process_time,2) : 0;
  650. //质量指数 加工数量- 废品数量 / 加工数量
  651. $quality_index = $process_num > 0 ? number_format(($process_num - $fault_tmp) / $process_num,2) : 0;
  652. //OEE
  653. $oee = number_format($efficient * $expressive * $quality_index,2);
  654. if ($oee > 0 && $oee < 40.15) {
  655. // 生成 (40.05, 40.15] 区间内的随机浮点数,保留两位小数
  656. $newOee = mt_rand(4005, 4015) / 100;
  657. $oee = sprintf("%.2f", $newOee);
  658. }
  659. if($type == 1){
  660. $models[$key]['machine_day_num'] = $run_time_tmp;
  661. $models[$key]['day_num'] = $finished;
  662. $models[$key]['break_day_num'] = $fault_tmp;
  663. $models[$key]['rate'] = $oee;
  664. $models[$key]['start_time'] = $start_time[$key] ?? '暂未开机';
  665. }elseif($type == 2){
  666. $models[$key]['machine_week_num'] = $run_time_tmp;
  667. $models[$key]['week_num'] = $finished;
  668. $models[$key]['break_week_num'] = $fault_tmp;
  669. }elseif($type == 3){
  670. $models[$key]['machine_month_num'] = $run_time_tmp;
  671. $models[$key]['month_num'] = $finished;
  672. $models[$key]['break_month_num'] = $fault_tmp;
  673. }
  674. }
  675. }
  676. /**
  677. * 项目分布的地区
  678. * @param Request $request
  679. * @return array
  680. */
  681. public function saleOrdersFromAddress(Request $request){
  682. $return = [];
  683. $address_map = config('address');
  684. foreach ($address_map as $value){
  685. $return[] = [
  686. 'code' => $value['value'],
  687. 'label' => $value['label'],
  688. 'num' => ""
  689. ];
  690. }
  691. $sqlServerModel = new FyySqlServerService(['id' => 1]);
  692. list($status,$msg) = $sqlServerModel->getCustomerFromSqlServer();
  693. if($status){
  694. foreach ($return as $key => $value){
  695. if(isset($msg[$value['code']])) $return[$key]['num'] = $msg[$value['code']];
  696. }
  697. }
  698. return $this->json_return(200,'',$return);
  699. }
  700. /**
  701. * 车间生产状态
  702. * @param Request $request
  703. * @return array
  704. */
  705. public function production_status(Request $request){
  706. $return = [
  707. 'dispatch' => 0,
  708. 'finished' => 0,
  709. 'box' => 0,
  710. 'send' => 0,
  711. ];
  712. $time = strtotime(date("Y-m-d 00:00:00"));
  713. //派工
  714. $dispatch = ApplyOrderDetail::where('del_time',0)
  715. ->where('type', ApplyOrder::type_one)
  716. ->where('crt_time','>=',$time)
  717. ->select('quantity')
  718. ->get()->toArray();
  719. $dispatch_num = 0;
  720. foreach (array_column($dispatch, 'dispatch_quantity') as $quantity) {
  721. $dispatch_num = bcadd($dispatch_num, $quantity, 3);
  722. }
  723. $return['dispatch'] = $dispatch_num;
  724. //完工
  725. $finished = ApplyOrderDetail::where('del_time',0)
  726. ->where('type', ApplyOrder::type_two)
  727. ->where('crt_time','>=',$time)
  728. ->select('quantity')
  729. ->get()->toArray();
  730. $finished_num = 0;
  731. foreach (array_column($finished, 'quantity') as $quantity) {
  732. $finished_num = bcadd($finished_num, $quantity, 3);
  733. }
  734. $return['finished'] = $finished_num;
  735. //包装 发货
  736. $box_quantity = ApplyOrderDetail::where('del_time',0)
  737. ->where('type', ApplyOrder::type_three)
  738. ->where('crt_time','>=',$time)
  739. ->select('quantity')
  740. ->get()->toArray();
  741. $num = 0;
  742. foreach (array_column($box_quantity, 'quantity') as $quantity) {
  743. $num = bcadd($num, $quantity, 3);
  744. }
  745. $return['box'] = $return['send'] = $num;
  746. return $this->json_return(200,'',$return);
  747. }
  748. public function deviceProduction(Request $request)
  749. {
  750. $now = time();
  751. //当天的开始与结束时间戳
  752. $timestamp_today_start = strtotime(date("Y-m-d 00:00:00",time()));
  753. $timestamp_today_end = strtotime(date("Y-m-d 23:59:59",time()));
  754. $latestTimes = SystemL::select('device_no', DB::raw('MAX(time) as max_time'))
  755. ->whereIn('data_point_name', [SystemL::run, SystemL::work, SystemL::stop, SystemL::standBy])
  756. ->where('time', '>=', $timestamp_today_start * 1000)
  757. ->where('time', '<=', $timestamp_today_end * 1000)
  758. ->groupBy('device_no')
  759. ->get()->toArray();
  760. $map = array_column($latestTimes,null,'device_no');
  761. //数据模型
  762. $models = [];
  763. $is_all_close = 1;
  764. $e_map = Equipment::where('del_time',0)->pluck('id','code')->toArray();
  765. $device = (new EquipmentService())->getDeviceList();
  766. foreach ($device as $k => $v){
  767. $is_close = 1;
  768. if(isset($map[$v])){
  769. $max_time = intval($map[$v]['max_time']) ?? 0;
  770. $max_time = intval($max_time / 1000);
  771. $max_time += 3800;
  772. if($max_time < $now) $is_close = 0;
  773. if($is_all_close) $is_all_close = 0;
  774. }else{
  775. $is_close = -1;
  776. }
  777. if($is_close < 0) {
  778. $is_close_title = "暂未开机";
  779. } elseif($is_close){
  780. $is_close_title = "正在工作";
  781. }else{
  782. $is_close_title = "暂停工作";
  783. }
  784. $id = $e_map[$v] ?? 0;
  785. $models[$id] = [
  786. "device_id" => $id,
  787. "device_name" => $k,
  788. "is_close" => $is_close,
  789. "is_close_title" => $is_close_title,
  790. "current_order"=> (object)[],
  791. "last_counting"=> (object)[],
  792. "now_counting"=> (object)[],
  793. "pending_order"=> [],
  794. "average"=> 0,
  795. ];
  796. }
  797. //当前订单信息
  798. $current_order = [];
  799. if(! $is_all_close) $current_order = $this->getCurrentOrder();
  800. //昨日生产
  801. $last_counting = $this->getLastCounting();
  802. //今日生产
  803. $now_counting = $this->getNowCounting();
  804. //待执行订单
  805. $pending_order = $this->getPendingOrder();
  806. foreach ($models as $e_id => $value){
  807. if(isset($current_order[$e_id])) $models[$e_id]['current_order'] = $current_order[$e_id];
  808. if(isset($last_counting[$e_id])) $models[$e_id]['last_counting'] = $last_counting[$e_id];
  809. if(isset($pending_order[$e_id])) $models[$e_id]['pending_order'] = $pending_order[$e_id];
  810. if(isset($now_counting[$e_id])) {
  811. $tmp = $now_counting[$e_id] ?? [];
  812. $models[$e_id]['now_counting'] = $tmp;
  813. $models[$e_id]['average'] = bcdiv($tmp['finished_num'], 8);
  814. }
  815. }
  816. $models = array_values($models);
  817. usort($models, function($a, $b) {
  818. return $b['is_close'] <=> $a['is_close'];
  819. });
  820. return $this->json_return(200,'', $models);
  821. }
  822. private function getCurrentOrder(){
  823. $timestamp_today_start = strtotime(date("Y-m-d 00:00:00",time()));
  824. $timestamp_today_end = strtotime(date("Y-m-d 23:59:59",time()));
  825. $apply = ApplyOrderDetail::where('del_time',0)
  826. ->where('type',ApplyOrder::type_one)
  827. ->where('crt_time', '>=', $timestamp_today_start)
  828. ->where('crt_time', '<=', $timestamp_today_end)
  829. ->orderBy('id', 'desc')
  830. ->get()->toArray();
  831. $dispatch = DispatchSub::where('del_time',0)
  832. ->whereIn('id', array_column($apply,'data_id'))
  833. ->select('dispatch_no','order_product_id','out_order_no','dispatch_quantity')
  834. ->get()->toArray();
  835. $equipment_map = [];
  836. $emp_sub = DispatchEmpSub::where('del_time',0)
  837. ->whereIn('dispatch_no',array_column($dispatch,'dispatch_no'))
  838. ->select('dispatch_no','equipment_id','team_id')
  839. ->get()->toArray();
  840. if(! empty($emp_sub)){
  841. foreach ($emp_sub as $value){
  842. if(isset($equipment_map[$value['dispatch_no']])) continue;
  843. $equipment_map[$value['dispatch_no']] = [
  844. 'equipment_id' => $value['equipment_id'],
  845. 'team_id' => $value['team_id'],
  846. ];
  847. }
  848. }
  849. //当前订单
  850. $current_order = $team_id = [];
  851. foreach ($dispatch as $value){
  852. $e_data = $equipment_map[$value['dispatch_no']] ?? [];
  853. $e_id = $e_data['equipment_id'] ?? 0;
  854. if(! $e_id || isset($current_order[$e_id])) continue;
  855. $value['team_id'] = $e_data['team_id'];
  856. $team_id[] = $value['team_id'];
  857. $current_order[$e_id] = $value;
  858. }
  859. $product_no = OrdersProduct::whereIn('id', array_unique(array_column($current_order,'order_product_id')))
  860. ->pluck('production_no','id')
  861. ->toArray();
  862. $team_id = array_unique($team_id);
  863. $team_map = Team::whereIn('id', $team_id)
  864. ->pluck('title','id')
  865. ->toArray();
  866. $team_array = EmployeeTeamPermission::from('employee_team_permission as a')
  867. ->leftJoin('employee as b','b.id','a.employee_id')
  868. ->whereIn('team_id', $team_id)
  869. ->select('b.emp_name','a.team_id')
  870. ->get()->toArray();
  871. foreach ($team_array as $value){
  872. if(isset($map[$value['team_id']])){
  873. $map[$value['team_id']] .= ',' . $value['emp_name'];
  874. }else{
  875. $map[$value['team_id']] = $value['emp_name'];
  876. }
  877. }
  878. foreach ($current_order as $key => $value){
  879. $current_order[$key]['production_no'] = $product_no[$value['order_product_id']] ?? "";
  880. $current_order[$key]['team'] = $team_map[$value['team_id']] ?? "";
  881. $current_order[$key]['team_man'] = $map[$value['team_id']] ?? "";
  882. }
  883. return $current_order;
  884. }
  885. private function getLastCounting(){
  886. $timestamp_today_start = strtotime(date("Y-m-d 00:00:00",time())) - 86400;
  887. $timestamp_today_end = strtotime(date("Y-m-d 23:59:59",time())) - 86400;
  888. $apply = ApplyOrderDetail::where('del_time',0)
  889. ->where('type',ApplyOrder::type_two)
  890. ->where('crt_time', '>=', $timestamp_today_start)
  891. ->where('crt_time', '<=', $timestamp_today_end)
  892. ->get()->toArray();
  893. $dispatch = DispatchSub::whereIn('id', array_column($apply,'data_id'))
  894. ->get()->toArray();
  895. $equipment_map = [];
  896. $emp_sub = DispatchEmpSub::where('del_time',0)
  897. ->whereIn('dispatch_no',array_column($dispatch,'dispatch_no'))
  898. ->select('dispatch_no','equipment_id')
  899. ->get()->toArray();
  900. if(! empty($emp_sub)){
  901. foreach ($emp_sub as $value){
  902. if(isset($equipment_map[$value['dispatch_no']])) continue;
  903. $equipment_map[$value['dispatch_no']] = $value['equipment_id'];
  904. }
  905. }
  906. $order = [];
  907. foreach ($dispatch as $value){
  908. $e_id = $equipment_map[$value['dispatch_no']] ?? 0;
  909. $order[$e_id][] = $value;
  910. }
  911. $return = [];
  912. foreach ($order as $e_id => $value){
  913. $tmp = [
  914. "finished_num" => 0,
  915. "hg_num" => 0,
  916. "blp_num" => 0,
  917. "plan_num" => 0,
  918. ];
  919. //产出数据 合格数量
  920. $finished_num = 0;
  921. foreach (array_column($value,'finished_num') as $value_v){
  922. $finished_num = bcadd($finished_num, $value_v,2);
  923. }
  924. $tmp['finished_num'] = $tmp['hg_num'] = $finished_num;
  925. //计划数量
  926. $production_quantity = 0;
  927. foreach (array_column($value,'production_quantity') as $value_v){
  928. $production_quantity = bcadd($production_quantity, $value_v,2);
  929. }
  930. $tmp['plan_num'] = $production_quantity;
  931. //不良品数量
  932. $blp = ScrappCount::where('del_time',0)
  933. ->where('crt_time', '>=', $timestamp_today_start)
  934. ->where('crt_time', '<=', $timestamp_today_end)
  935. ->where('dispatch_sub_id', array_column($value,'id'))
  936. ->select('scrapp_num')
  937. ->get()->toArray();
  938. $scrapp_num = 0;
  939. foreach (array_column($blp,'scrapp_num') as $value_v){
  940. $scrapp_num = bcadd($scrapp_num, $value_v,2);
  941. }
  942. $tmp['blp_num'] = $scrapp_num;
  943. $return[$e_id] = $tmp;
  944. }
  945. return $return;
  946. }
  947. private function getNowCounting(){
  948. //当天的开始与结束时间戳
  949. $timestamp_today_start = strtotime(date("Y-m-d 00:00:00",time()));
  950. $timestamp_today_end = strtotime(date("Y-m-d 23:59:59",time()));
  951. $apply = ApplyOrderDetail::where('del_time',0)
  952. ->where('type',ApplyOrder::type_two)
  953. ->where('crt_time', '>=', $timestamp_today_start)
  954. ->where('crt_time', '<=', $timestamp_today_end)
  955. ->get()->toArray();
  956. $dispatch = DispatchSub::whereIn('id', array_column($apply,'data_id'))
  957. ->get()->toArray();
  958. $equipment_map = [];
  959. $emp_sub = DispatchEmpSub::where('del_time',0)
  960. ->whereIn('dispatch_no',array_column($dispatch,'dispatch_no'))
  961. ->select('dispatch_no','equipment_id')
  962. ->get()->toArray();
  963. if(! empty($emp_sub)){
  964. foreach ($emp_sub as $value){
  965. if(isset($equipment_map[$value['dispatch_no']])) continue;
  966. $equipment_map[$value['dispatch_no']] = $value['equipment_id'];
  967. }
  968. }
  969. $order = [];
  970. foreach ($dispatch as $value){
  971. $e_id = $equipment_map[$value['dispatch_no']] ?? 0;
  972. $order[$e_id][] = $value;
  973. }
  974. $return = [];
  975. foreach ($order as $e_id => $value){
  976. $tmp = [
  977. "finished_num" => 0,
  978. "hg_num" => 0,
  979. "blp_num" => 0,
  980. "plan_num" => 0,
  981. ];
  982. //产出数据 合格数量
  983. $finished_num = 0;
  984. foreach (array_column($value,'finished_num') as $value_v){
  985. $finished_num = bcadd($finished_num, $value_v,2);
  986. }
  987. $tmp['finished_num'] = $tmp['hg_num'] = $finished_num;
  988. //计划数量
  989. $production_quantity = 0;
  990. foreach (array_column($value,'production_quantity') as $value_v){
  991. $production_quantity = bcadd($production_quantity, $value_v,2);
  992. }
  993. $tmp['plan_num'] = $production_quantity;
  994. //不良品数量
  995. $blp = ScrappCount::where('del_time',0)
  996. ->where('crt_time', '>=', $timestamp_today_start)
  997. ->where('crt_time', '<=', $timestamp_today_end)
  998. ->where('dispatch_sub_id', array_column($value,'id'))
  999. ->select('scrapp_num')
  1000. ->get()->toArray();
  1001. $scrapp_num = 0;
  1002. foreach (array_column($blp,'scrapp_num') as $value_v){
  1003. $scrapp_num = bcadd($scrapp_num, $value_v,2);
  1004. }
  1005. $tmp['blp_num'] = $scrapp_num;
  1006. $return[$e_id] = $tmp;
  1007. }
  1008. return $return;
  1009. }
  1010. private function getPendingOrder(){
  1011. //当天的开始与结束时间戳
  1012. $timestamp_today_start = strtotime(date("Y-m-d 00:00:00",time()));
  1013. $timestamp_today_end = strtotime(date("Y-m-d 23:59:59",time()));
  1014. $dispatch = DispatchSub::where('del_time',0)
  1015. ->where('crt_time', '>=', $timestamp_today_start)
  1016. ->where('crt_time', '<=', $timestamp_today_end)
  1017. ->where('finished_num', 0)
  1018. ->select('dispatch_no','order_product_id','out_order_no','dispatch_quantity')
  1019. ->get()->toArray();
  1020. $equipment_map = [];
  1021. $emp_sub = DispatchEmpSub::where('del_time',0)
  1022. ->whereIn('dispatch_no',array_column($dispatch,'dispatch_no'))
  1023. ->select('dispatch_no','equipment_id')
  1024. ->get()->toArray();
  1025. if(! empty($emp_sub)){
  1026. foreach ($emp_sub as $value){
  1027. if(isset($equipment_map[$value['dispatch_no']])) continue;
  1028. $equipment_map[$value['dispatch_no']] = $value['equipment_id'];
  1029. }
  1030. }
  1031. $product_no = OrdersProduct::whereIn('id', array_unique(array_column($dispatch,'order_product_id')))
  1032. ->pluck('production_no','id')
  1033. ->toArray();
  1034. $order = [];
  1035. foreach ($dispatch as $value){
  1036. $e_id = $equipment_map[$value['dispatch_no']] ?? 0;
  1037. $value['production_no'] = $product_no[$value['order_product_id']] ?? '';
  1038. $order[$e_id][] = $value;
  1039. }
  1040. return $order;
  1041. }
  1042. public function createEquipmentData(Request $request){
  1043. $data = $request->all();
  1044. if(empty($data['sub'])) return $this->json_return(201,'', "设备信息不能为空");
  1045. $device = (new EquipmentService())->getDeviceList("code","id");
  1046. $dispatch = [];
  1047. foreach ($data['sub'] as $value){
  1048. if(empty($value['device_no'])) return [false, "设备编码不能为空"];
  1049. if(empty($value['finished_num'])) continue;
  1050. $start_time = $value['start_time'];
  1051. if(empty($value['start_time'])) $start_time = time();
  1052. $device_id = $device[$value['device_no']] ?? 0;
  1053. if(empty($device_id)) return [false, '设备不存在'];
  1054. $dispatch[] = [
  1055. 'finished_num' => $value['finished_num'],
  1056. 'start_time' => $start_time,
  1057. 'device_id' => $device_id,
  1058. 'crt_time' => time()
  1059. ];
  1060. }
  1061. if(empty($dispatch)) return $this->json_return(201,'', "请填写至少一个设备的生产数量(吨)");
  1062. ForDeviceData::insert($dispatch);
  1063. return $this->json_return(200,'操作成功', []);
  1064. }
  1065. }