cqp 2 dagen geleden
bovenliggende
commit
60519c2fc5
4 gewijzigde bestanden met toevoegingen van 291 en 0 verwijderingen
  1. 22 0
      app/Http/Controllers/Api/LargeScreenController.php
  2. 7 0
      app/Model/Equipment.php
  3. 258 0
      app/Service/LargeScreenService.php
  4. 4 0
      routes/api.php

+ 22 - 0
app/Http/Controllers/Api/LargeScreenController.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\LargeScreenService;
+use Illuminate\Http\Request;
+
+class LargeScreenController extends BaseController
+{
+    //综合大屏
+    public function integratedDashboard(Request $request){
+        $service = new LargeScreenService();
+//        $userData = $request->userData->toArray();
+        list($status,$data) = $service->integratedDashboard($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 7 - 0
app/Model/Equipment.php

@@ -10,5 +10,12 @@ class Equipment extends Model
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
+
+    public static $status_title = [
+        1 => "运行中",
+        2 => "待机",
+        3 => "故障停机",
+        4 => "关机",
+    ];
 }
 

+ 258 - 0
app/Service/LargeScreenService.php

@@ -0,0 +1,258 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\DispatchSub;
+use App\Model\Equipment;
+use App\Model\OrdersProduct;
+use App\Model\SaleOrdersProduct;
+use App\Model\ScrappCount;
+use Illuminate\Support\Facades\DB;
+
+class LargeScreenService extends Service
+{
+    public function integratedDashboard($data){
+        //总产值 ------------------------------------------------
+        $total = SaleOrdersProduct::where('del_time',0)
+            ->where('crt_time', ">=", strtotime(date("Y-01-01 00:00:00")))
+            ->select(DB::raw("sum(finished_num) as total"))
+            ->value('total');
+        //总产值 ------------------------------------------------
+
+        //当日产量 当月产量 ---------------------------------------------
+        $data_one = SaleOrdersProduct::where('del_time',0)
+            ->where('crt_time', ">=", strtotime(date("Y-m-01 00:00:00")))
+            ->where('crt_time', "<=", strtotime(date("Y-m-t 23:59:59")))
+            ->select('finished_num','order_quantity','crt_time')
+            ->get()->toArray();
+        //当日产量 当月产量
+        $today_total = $month_total = $order_total = 0;
+        $timeStamp = strtotime(date("Y-m-d 00:00:00"));
+        $timeStampE = strtotime(date("Y-m-d 23:59:59"));
+        foreach ($data_one as $value){
+            $order_total = bcadd($order_total, $value['order_quantity'],3);
+            $month_total = bcadd($month_total, $value['finished_num'],3);
+            if($timeStamp <= $value['crt_time'] && $timeStampE >= $value['crt_time']) $today_total = bcadd($today_total, $value['finished_num'],3);
+        }
+        //当日产量 当月产量 ---------------------------------------------
+
+        //月计划完成率--------------------------------------------------------------------
+        $month_rate = floatval($order_total) > 0 ? bcdiv($month_total, $order_total,4) : 0;
+        $month_rate = bcmul($month_rate,100,2) . "%";
+        //月计划完成率--------------------------------------------------------------------
+
+        //月注塑合格率----------------------------------------------------------------------
+        $data_two = ScrappCount::where('del_time',0)
+            ->where('crt_time', ">=", strtotime(date("Y-m-01 00:00:00")))
+            ->where('crt_time', "<=", strtotime(date("Y-m-t 23:59:59")))
+            ->where('process_id', 14)
+            ->select(DB::raw("sum(quantity) as quantity"), DB::raw("sum(scrapp_num) as waste"))
+            ->get()->toArray();
+        $total_zj = $total_blp = 0;
+        foreach ($data_two as $value){
+            $total_zj = bcadd($total_zj, $value['quantity'],3);
+            $total_zj = bcadd($total_zj, $value['waste'],3);
+            $total_blp = bcadd($total_blp, $value['waste'],3);
+        }
+        $process_14_total = bcadd($total_zj, $total_blp,3);
+        $process_14_rate = floatval($process_14_total) > 0 ? bcdiv($total_zj, $process_14_total,4) : 0;
+        $process_14_rate = bcmul($process_14_rate, 100,2) . "%";
+        //月注塑合格率----------------------------------------------------------------------
+
+        //设备监控状态----------------------------------------------------------------------
+        $deviceList = Equipment::where('del_time',0)
+            ->where('model','<>',1)
+            ->select('id','title','code','status')
+            ->get()->toArray();
+        foreach ($deviceList as $key => $value){
+            $status_title = Equipment::$status_title[$value['status']] ?? "";
+            $deviceList[$key]['status_title'] = $status_title;
+        }
+        //设备监控状态----------------------------------------------------------------------
+
+        //质量管理--------------------------------------------------------------------------
+        $dates = [];
+        for ($i = 7; $i >= 0; $i--) {
+            $timestamp = strtotime("-{$i} days");
+            $date = date('m-d', $timestamp);
+            $dates[] = $date;
+        }
+        $zl_data = [];
+        $data_three = ScrappCount::where('del_time',0)
+            ->where('crt_time', "<=", time())
+            ->where('crt_time', ">=", strtotime(date("Y-m-d 00:00:00",time() - 7 * 24 * 60 * 60)))
+            ->where('process_id', 14)
+            ->select('quantity', "scrapp_num as waste", "crt_time")
+            ->get()->toArray();
+        foreach ($data_three as $value){
+            $day = date("m-d", $value['crt_time']);
+            $tmp = bcadd($value['quantity'], $value['waste'], 3);
+            if(isset($zl_data[$day])){
+                $zl_data[$day]['quantity'] = bcadd($zl_data[$day]['quantity'], $value['quantity'],3);
+                $zl_data[$day]['total'] = bcadd($zl_data[$day]['total'], $tmp,3);
+            }else{
+                $zl_data[$day] = [
+                    'quantity' => $value['quantity'],
+                    'total' => $tmp
+                ];
+            }
+        }
+        $zj_data_final = [];
+        foreach ($dates as $value){
+            $tmp = [
+                "day" => $value,
+                "total" => 0,
+                "rate" => 0,
+            ];
+            if(isset($zl_data[$value])){
+                $tmp['total'] = $zl_data[$value]['total'];
+                $tmp['rate'] = bcmul(bcdiv($zl_data[$value]['quantity'], $zl_data[$value]['total'],4),100,2);
+            }
+            $zj_data_final[] = $tmp;
+        }
+        //质量管理--------------------------------------------------------------------------
+
+        //物料管理--------------------------------------------------------------------------
+        $thing = [
+            ["name" => '物料一', 'rate' => 50],
+            ["name" => '物料二', 'rate' => 60],
+            ["name" => '物料三', 'rate' => 34],
+            ["name" => '物料四', 'rate' => 22],
+            ["name" => '物料五', 'rate' => 11],
+            ["name" => '物料六', 'rate' => 22],
+            ["name" => '物料七', 'rate' => 44],
+            ["name" => '物料八', 'rate' => 32],
+            ["name" => '物料九', 'rate' => 34],
+            ["name" => '物料十', 'rate' => 51],
+        ];
+        //物料管理--------------------------------------------------------------------------
+
+        //销售管理--------------------------------------------------------------------------
+        $xs = SaleOrdersProduct::where('del_time',0)
+            ->where('crt_time', ">=", strtotime(date("Y-01-01 00:00:00")))
+            ->select(DB::raw("sum(finished_num) as total"),'technology_name as color')
+            ->groupBy('technology_name')
+            ->orderBy('total','desc')
+            ->get()->toArray();
+        //销售管理--------------------------------------------------------------------------
+
+        //总装各线体目标/完成量---------------------------------------------------------------
+        $zx_12_dispatch_quantity = $zx_12_finished_num = 0;
+        $zx_14_dispatch_quantity_8 = $zx_14_finished_num_8 = 0;
+        $zx_14_dispatch_quantity_9 = $zx_14_finished_num_9 = 0;
+        $zx_14_dispatch_quantity_12 = $zx_14_finished_num_12 = 0;
+        $zx_14_dispatch_quantity_13 = $zx_14_finished_num_13 = 0;
+        $dispatch = DispatchSub::where('del_time',0)
+            ->where('crt_time', ">=", strtotime(date("Y-01-01 00:00:00")))
+            ->whereIn('process_id',[12,14])
+            ->select('dispatch_quantity', 'finished_num', 'process_id','device_id')
+            ->get()->toArray();
+        foreach ($dispatch as $value){
+            if($value['process_id'] == 12){
+                $zx_12_dispatch_quantity = bcadd($zx_12_dispatch_quantity, $value['dispatch_quantity'],3);
+                $zx_12_finished_num = bcadd($zx_12_finished_num, $value['finished_num'],3);
+            }else{
+                if($value['device_id'] == 8){
+                    $zx_14_dispatch_quantity_8 = bcadd($zx_14_dispatch_quantity_8, $value['dispatch_quantity'],3);
+                    $zx_14_finished_num_8 = bcadd($zx_14_finished_num_8, $value['finished_num'],3);
+                }elseif ($value['device_id'] == 9){
+                    $zx_14_dispatch_quantity_9 = bcadd($zx_14_dispatch_quantity_9, $value['dispatch_quantity'],3);
+                    $zx_14_finished_num_9 = bcadd($zx_14_finished_num_9, $value['finished_num'],3);
+                }elseif ($value['device_id'] == 12){
+                    $zx_14_dispatch_quantity_12 = bcadd($zx_14_dispatch_quantity_12, $value['dispatch_quantity'],3);
+                    $zx_14_finished_num_12 = bcadd($zx_14_finished_num_12, $value['finished_num'],3);
+                }elseif ($value['device_id'] == 13){
+                    $zx_14_dispatch_quantity_13 = bcadd($zx_14_dispatch_quantity_13, $value['dispatch_quantity'],3);
+                    $zx_14_finished_num_13 = bcadd($zx_14_finished_num_13, $value['finished_num'],3);
+                }
+            }
+        }
+        $diff_num = bcsub($zx_12_dispatch_quantity, $zx_12_finished_num,3);
+        $diff_num_8 = bcsub($zx_14_dispatch_quantity_8, $zx_14_finished_num_8,3);
+        $diff_num_9 = bcsub($zx_14_dispatch_quantity_9, $zx_14_finished_num_9,3);
+        $diff_num_12 = bcsub($zx_14_dispatch_quantity_12, $zx_14_finished_num_12,3);
+        $diff_num_13 = bcsub($zx_14_dispatch_quantity_13, $zx_14_finished_num_13,3);
+
+        $xt = [
+            [
+                "name" => "清洗脱水产线", "sj_num" => $zx_12_finished_num, "jh_num" => $zx_12_dispatch_quantity, "diff_num" => $diff_num
+            ],[
+                "name" => "注塑一号产线", "sj_num" => $zx_14_finished_num_8, "jh_num" => $zx_14_dispatch_quantity_8, "diff_num" => $diff_num_8
+            ],[
+                "name" => "注塑二号产线", "sj_num" => $zx_14_finished_num_9, "jh_num" => $zx_14_dispatch_quantity_9, "diff_num" => $diff_num_9
+            ],[
+                "name" => "注塑三号产线", "sj_num" => $zx_14_finished_num_12, "jh_num" => $zx_14_dispatch_quantity_12, "diff_num" => $diff_num_12
+            ],[
+                "name" => "注塑四号产线", "sj_num" => $zx_14_finished_num_13, "jh_num" => $zx_14_dispatch_quantity_13, "diff_num" => $diff_num_13
+            ],
+        ];
+        //总装各线体目标/完成量---------------------------------------------------------------
+
+        //订单完成进度-----------------------------------------------------------------
+        $orderBy = [11 => "破碎分离", 12 => "清洗脱水" ,15 => "混合搅拌",13 => "挤出造粒",14 => "注塑成型"];
+        $order = OrdersProduct::where('del_time',0)
+            ->select('production_no as order_number','id','technology_name as color','production_quantity','dispatch_complete_quantity','finished_num')
+            ->orderBy('id','desc')
+            ->limit(10)
+            ->get()->toArray();
+        $dispatch_num = DispatchSub::where('del_time',0)
+            ->whereIn('order_product_id',array_column($order,'id'))
+            ->select('order_product_id','process_id','finished_num','dispatch_quantity','waste_num')
+            ->get()->toArray();
+        $details = [];
+        foreach ($dispatch_num as $value){
+            $new = $value['order_product_id'] . $value['process_id'];
+            $finished_num = bcadd($value['finished_num'], $value['waste_num'],3);
+            if(isset($details[$new])){
+                $details[$new]['dispatch_quantity'] = bcadd($details[$new]['dispatch_quantity'], $value['dispatch_quantity'],3);
+                $details[$new]['finished_num'] = bcadd($details[$new]['finished_num'], $finished_num,3);
+            }else{
+                $details[$new] = [
+                    "dispatch_quantity" => $value['dispatch_quantity'],
+                    "finished_num" => $finished_num,
+                ];
+            }
+        }
+        foreach ($order as $key => $value){
+            $d_tmp = [];
+            foreach ($orderBy as $k => $v){
+                $new = $value['id'] . $k;
+                $tmpS = $details[$new] ?? [];
+                $rate = 0;
+                if(! empty($tmpS)) {
+                    $rate = bcdiv($tmpS['finished_num'], $tmpS['dispatch_quantity'],4);
+                    $rate = bcmul($rate, 100,2);
+                }
+                $d_tmp[] = [
+                    "name" => $v,
+                    "rate" => $rate
+                ];
+            }
+            $order[$key]['detail'] = $d_tmp;
+            if($value['production_quantity'] <= $value['finished_num']){
+                $state = "已完成";
+            }else{
+                $state = "进行中";
+            }
+            $order[$key]['state_title'] = $state;
+        }
+        //订单完成进度-----------------------------------------------------------------
+//        dd($total, $today_total, $month_total, $month_rate, $process_14_rate, $deviceList, $zj_data_final, $thing, $xs, $xt,$order);
+
+        $return = [
+            'total' => $total, //年总产量
+            'today_total' => $today_total, //当日产量
+            'month_total' => $month_total, //当月产量
+            'month_rate' => $month_rate, // 月计划完成比例
+            'process_14_rate' => $process_14_rate, // 注塑产线合格率
+            'device' => $deviceList, // 设备监控状态
+            'zj_result' => $zj_data_final, //质量管理
+            'thing' => $thing, //物料管理
+            'xs' => $xs, //销售管理
+            'xt' => $xt, //总装各线体目标/完成量
+            'order' => $order, // 订单完成进度
+        ];
+
+        return [true, $return];
+    }
+}

+ 4 - 0
routes/api.php

@@ -44,6 +44,10 @@ Route::any('nu_work_order','Api\ScreenController@nu_work_order');
 Route::any('saleOrdersFromAddress','Api\ScreenController@saleOrdersFromAddress');
 Route::any('production_status','Api\ScreenController@production_status');
 Route::any('deviceProduction','Api\ScreenController@deviceProduction');
+
+//综合大屏
+Route::any('integratedDashboard','Api\LargeScreenController@integratedDashboard');
+
 Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('HeaderSettingsAdd', 'Api\HeaderWordController@add');
     $route->any('HeaderSettingsDetail', 'Api\HeaderWordController@detail');