Răsfoiți Sursa

修改 工序位置

cqp 3 luni în urmă
părinte
comite
45821ed960
1 a modificat fișierele cu 26 adăugiri și 0 ștergeri
  1. 26 0
      app/Service/DispatchService.php

+ 26 - 0
app/Service/DispatchService.php

@@ -13,6 +13,7 @@ use App\Model\OrdersProduct;
 use App\Model\OrdersProductProcess;
 use App\Model\Process;
 use App\Model\Team;
+use App\Model\Technology;
 use Illuminate\Support\Facades\DB;
 
 class DispatchService extends Service
@@ -461,9 +462,13 @@ class DispatchService extends Service
             ->pluck('emp_name','id')
             ->toArray();
 
+        $tech = Technology::where('id',9)->first();
+        $process_id_str = "";
+        if(! empty($tech)) $process_id_str = $tech->process_id;
         $process_map = $this->getProcess($data['data']);
         foreach ($data['data'] as $key => $value){
             $tmp = $process_map[$value['id']] ?? [];
+            if(! empty($process_id_str)) $tmp = $this->forSort($process_id_str, $tmp);
             foreach ($tmp as $t => $v) {
                 $q = $map[$value['id'] . $v['process_id']] ?? 0;
                 $tmp[$t]['dispatch_quantity'] = $q;
@@ -493,6 +498,27 @@ class DispatchService extends Service
         return $data;
     }
 
+    private function forSort($order, $array){
+        $order = explode(',',$order);
+
+        // 构建一个值到索引的映射,用于比较函数
+        $priority = array_flip($order);
+
+        // 使用 usort 自定义排序
+        usort($array, function($a, $b) use ($priority) {
+            $aKey = $a['process_id'];
+            $bKey = $b['process_id'];
+
+            // 如果某个 process_id 不在优先级列表中,可以放在最后
+            $aPos = isset($priority[$aKey]) ? $priority[$aKey] : count($priority);
+            $bPos = isset($priority[$bKey]) ? $priority[$bKey] : count($priority);
+
+            return $aPos <=> $bPos;
+        });
+
+        return $array;
+    }
+
     //返回已派工数量
     public function getDispatchQuantity($order_product_id = []){
         if(empty($order_product_id)) return [];