cqpCow 2 年之前
父节点
当前提交
4b9d61de7c
共有 1 个文件被更改,包括 328 次插入0 次删除
  1. 328 0
      app/Http/Controllers/Api/ScreenController.php

+ 328 - 0
app/Http/Controllers/Api/ScreenController.php

@@ -0,0 +1,328 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Model\Box;
+use App\Model\BoxDetail;
+use App\Model\DispatchSub;
+use App\Model\OrdersProductProcess;
+use App\Model\Process;
+use App\Model\SaleOrdersProduct;
+use Carbon\Carbon;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+
+class ScreenController extends BaseController
+{
+    //产值数据全览
+    public function output_value(Request $request){
+        $currentYear = Carbon::now()->year;
+        $lastYear = $currentYear - 1;
+        $currentMonth = Carbon::now()->month;
+
+        $totalValueAllTime = SaleOrdersProduct::where('del_time',0)->sum('finished_num');
+        $totalValueLastYear = SaleOrdersProduct::where('del_time',0)->whereRaw("YEAR(FROM_UNIXTIME(crt_time)) = $lastYear")->sum('finished_num');
+        $totalValueCurrentYearMonth = SaleOrdersProduct::where('del_time',0)->whereRaw("YEAR(FROM_UNIXTIME(crt_time)) = $currentYear AND MONTH(FROM_UNIXTIME(crt_time)) = $currentMonth")->sum('finished_num');
+
+        return $this->json_return(200,'',['total_time'=>$totalValueAllTime, 'total_last_year'=>$totalValueLastYear, 'total_current_month'=>$totalValueCurrentYearMonth]);
+    }
+
+    //项目进度
+    public function order_process1(Request $request) {
+        $result = SaleOrdersProduct::where('del_time',0)
+            ->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')
+            ->groupBy('out_order_no')
+            ->get()->toArray();
+        if(! empty($result)){
+            foreach ($result as $key => $value){
+                $result[$key]['rate'] = intval($value['finished_num'] / $value['total']);
+                unset($result[$key]['total']);
+                unset($result[$key]['finished_num']);
+            }
+        }
+
+        return $this->json_return(200,'',$result);
+    }
+
+    //历史项目 在手项目
+    public function project_region(Request $request){
+        $all = SaleOrdersProduct::where('del_time',0)
+            ->whereColumn('order_quantity','=','finished_num')
+            ->select('out_order_no')
+            ->groupBy('out_order_no')
+            ->get()
+            ->toArray();
+        $all = array_column($all,'out_order_no');
+
+        $not_all = SaleOrdersProduct::where('del_time',0)
+            ->whereColumn('order_quantity','<>','finished_num')
+            ->select('out_order_no')
+            ->groupBy('out_order_no')
+            ->get()
+            ->toArray();
+        $not_all = array_column($not_all,'out_order_no');
+        $all = array_diff($all, $not_all);
+
+        $arr = [
+            "all_num" => count($all),
+            "num" => count($not_all),
+        ];
+        return $this->json_return(200,'',$arr);
+    }
+
+    //本月质量
+    public function output_value_month1(Request $request){
+        date_default_timezone_set("PRC");
+        $date = date('Ymd',time());
+
+        $startDate = strtotime(date('Y-m-01 00:00:00', time()));
+        $endDate = strtotime(date('Y-m-t 23:59:59', time()));
+        //工序-----------------------------
+        $model = new OrdersProductProcess(['channel' => $date]);//当前季度的数据
+        $data = $model->where('del_time',0)
+            ->where('status',4)
+            ->select('crt_time')
+            ->where('crt_time','>=',$startDate)
+            ->where('crt_time','<=',$endDate)
+            ->get()->toArray();
+
+        $return = [];
+        if(! empty($data)){
+            foreach ($data as $value){
+                $crt_time = date('Y-m-d',$value['crt_time']);
+                if(isset($return[$crt_time])){
+                    $return[$crt_time]['num'] += 1;
+                }else{
+                    $return[$crt_time] = [
+                        'num' => 1,
+                        'value' => $crt_time
+                    ];
+                }
+            }
+        }
+        $return = array_values($return);
+        return $this->json_return(200,'',$return);
+    }
+
+    //产量趋势图
+    public function output_value_efficiency(Request $request){
+        date_default_timezone_set("PRC");
+        // 获取当前时间戳
+        $currentTimestamp = time();
+        // 输出过去两周的起止时间(包括当前日期)
+        $timestamp = strtotime("-13 days", $currentTimestamp);
+        $startOfDay = strtotime(date('Y-m-d 00:00:00', $timestamp));
+        $endOfDay = strtotime(date('Y-m-d 23:59:59', $currentTimestamp));
+
+        $box = Box::where('del_time',0)
+            ->where('crt_time','>=',$startOfDay)
+            ->where('crt_time','<=',$endOfDay)
+            ->select('crt_time','top_order_no','order_no')
+            ->orderBy('crt_time','desc')
+            ->get()->toArray();
+        $result = [];
+        if(! empty($box)){
+            foreach ($box as $value){
+                $model = new BoxDetail(['channel' => $value['top_order_no']]);
+                $map = $model->where('del_time',0)
+                    ->where('order_no',$value['order_no'])
+                    ->select('order_no',DB::raw('sum(num) as num'))
+                    ->groupBy('order_no')
+                    ->pluck('num','order_no')
+                    ->toArray();
+                $output = $map[$value['order_no']] ?? 0;
+                $times = date('Y-m-d',$value['crt_time']);
+                if(isset($result[$times])){
+                    $result[$times]['output'] += $output;
+                }else{
+                    $result[$times] = [
+                        'crt_time' => $times,
+                        'output' => $output
+                    ];
+                }
+            }
+        }
+        $result = array_values($result);
+        return $this->json_return(200,'',$result);
+    }
+
+    //工序负荷全览
+    public function capacity(Request $request){
+        date_default_timezone_set("PRC");
+        $date = date('Ymd',time());
+
+        //工序-----------------------------
+        $model = new OrdersProductProcess(['channel' => $date]);//当前季度的数据
+        $data = $model->where('del_time',0)
+            ->where('status',2)
+            ->select('finished_time')
+            ->get()->toArray();
+
+        $return = [];
+        if(! empty($data)){
+            foreach ($data as $value){
+                $finished_time = date('Ymd',$value['finished_time']);
+                if(isset($return[$finished_time])){
+                    $return[$finished_time] += 1;
+                }else{
+                    $return[$finished_time] = 1;
+                }
+            }
+        }
+        $maxValue = empty($return) ? 0 : max($return);
+        $today = $return[$date] ?? 0;
+        $rate = $maxValue ? intval($today/$maxValue) : 0;
+        //工序-----------------------------
+
+        //包装-----------------------------
+        $model = new BoxDetail(['channel' => $date]);//当前季度的数据
+        $data = $model->where('del_time',0)
+            ->select('crt_time','num')
+            ->get()->toArray();
+
+        $return = [];
+        if(! empty($data)){
+            foreach ($data as $value){
+                $crt_time = date('Ymd',$value['crt_time']);
+                if(isset($return[$crt_time])){
+                    $return[$crt_time] += $value['num'];
+                }else{
+                    $return[$crt_time] = $value['num'];
+                }
+            }
+        }
+        $maxValue = empty($return) ? 0 : max($return);
+        $today = $return[$date] ?? 0;
+        $rate2 = $maxValue ? intval($today/$maxValue) : 0;
+        //包装-----------------------------
+
+        $arr = [
+            [
+                [
+                    "title"=> "压贴",
+                    "rate"=> $rate
+                ],
+                [
+                    "title"=> "包装",
+                    "rate"=> $rate2
+                ]
+            ],
+        ];
+        return $this->json_return(200,'',['data' => $arr]);
+
+    }
+
+    //设备信息 暂时不做
+    public function product_num(Request $request){
+        $arr = [
+            [
+                "machine_day_num"=> "4903.69",
+                "machine_month_num"=> "139.64",
+                "machine_week_num"=> "47.21",
+                "break_day_num"=> "0",
+                "break_month_num"=> "10",
+                "break_week_num"=> "3",
+                "start_time"=> date("Y-m-d H:i:s",time()),
+                "day_num"=> "766",
+                "week_num"=> "4598",
+                "month_num"=> "14489",
+                "rate"=> "72"
+            ],
+            [
+                "machine_day_num"=> "469591.19",
+                "machine_month_num"=> "107.03",
+                "machine_week_num"=> "35.23",
+                "break_day_num"=> 0,
+                "break_month_num"=> "210",
+                "break_week_num"=> "18",
+                "start_time"=> date("Y-m-d H:i:s",time()),
+                "day_num"=> 0,
+                "week_num"=> "2353",
+                "month_num"=> "6255",
+                "rate"=> 0
+            ],
+            [
+                "machine_day_num"=> "0",
+                "machine_month_num"=> "14.02",
+                "machine_week_num"=> "6.88",
+                "break_day_num"=> "0",
+                "break_month_num"=> "0",
+                "break_week_num"=> "0",
+                "start_time"=> date("Y-m-d H:i:s",time()),
+                "day_num"=> "0",
+                "week_num"=> "494",
+                "month_num"=> "3058",
+                "rate"=> "0"
+            ],
+            [
+                "machine_day_num"=> "4903.77",
+                "machine_month_num"=> "149.14",
+                "machine_week_num"=> "56.72",
+                "break_day_num"=> "0",
+                "break_month_num"=> "0",
+                "break_week_num"=> "0",
+                "start_time"=> date("Y-m-d H:i:s",time()),
+                "day_num"=> "626",
+                "week_num"=> "4460",
+                "month_num"=> "13034",
+                "rate"=> "48"
+            ]
+        ];
+        return $this->json_return(200,'',$arr);
+    }
+
+    //在制工单
+    public function work_order(Request $request){
+        date_default_timezone_set("PRC");
+        // 获取当前时间戳
+        $currentTimestamp = time();
+        $timestamp = strtotime("-3 months", $currentTimestamp);
+        $startOfDay = strtotime(date('Y-m-d 00:00:00', $timestamp));
+        $endOfDay = strtotime(date('Y-m-d 23:59:59', $currentTimestamp));
+
+        $result = DispatchSub::where('del_time',0)
+            ->where('crt_time',">=", $startOfDay)
+            ->where('crt_time',"<=", $endOfDay)
+            ->whereColumn('dispatch_quantity','>','finished_num')
+            ->select('dispatch_no as order_no','process_id','product_title','dispatch_quantity as product_num','finished_num as finish_num')
+            ->get()->toArray();
+        if(! empty($result)){
+            $process_id = array_unique(array_column($result,'process_id'));
+            $processMap = Process::whereIn('id',$process_id)
+                ->pluck('title','id')
+                ->toArray();
+            foreach ($result as $key => $value){
+                $result[$key]['procedure'] = $processMap[$value['process_id']] ?? '';
+            }
+        }
+
+        return $this->json_return(200,'',$result);
+    }
+
+    //待加工
+    public function nu_work_order(Request $request){
+        date_default_timezone_set("PRC");
+
+        $date = date('Ymd',time());
+
+        //工序-----------------------------
+        $model = new OrdersProductProcess(['channel' => $date]);//当前季度的数据
+        $result = $model->where('del_time',0)
+            ->where('status',0)
+            ->select('production_no as order_no','product_title','process_id',DB::raw('count(id) as product_num'))
+            ->groupBy('order_product_id')
+            ->get()->toArray();
+
+        if(! empty($result)){
+            $process_id = array_unique(array_column($result,'process_id'));
+            $processMap = Process::whereIn('id',$process_id)
+                ->pluck('title','id')
+                ->toArray();
+            foreach ($result as $key => $value){
+                $result[$key]['procedure'] = $processMap[$value['process_id']] ?? '';
+            }
+        }
+
+        return $this->json_return(200,'',$result);
+    }
+}