cqpCow 2 năm trước cách đây
mục cha
commit
512f0d7e96

+ 18 - 1
app/Service/DispatchService.php

@@ -6,8 +6,11 @@ use App\Model\Dispatch;
 use App\Model\DispatchSub;
 use App\Model\Employee;
 use App\Model\EmployeeTeamPermission;
+use App\Model\Equipment;
 use App\Model\OrdersProduct;
 use App\Model\OrdersProductProcess;
+use App\Model\Process;
+use App\Model\Team;
 use Illuminate\Support\Facades\DB;
 
 class DispatchService extends Service
@@ -231,7 +234,7 @@ class DispatchService extends Service
 
     public function dispatchOrderList($data){
         $model = DispatchSub::where('del_time',0)
-            ->select('id','order_no','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','production_quantity','production_time','dispatch_no','status','crt_id','process_id','equipment_id','team_id','dispatch_time_start','dispatch_time_end')
+            ->select('id','order_no','table_header_mark','product_no','product_title','product_size','product_unit','dispatch_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','production_quantity','dispatch_no','status','crt_id','process_id','equipment_id','team_id','dispatch_time_start','dispatch_time_end','crt_time')
             ->orderBy('id','desc');
 
         if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
@@ -280,6 +283,17 @@ class DispatchService extends Service
                 }
             }
         }
+
+        $process_map = Process::whereIn('id',array_column($data['data'],'process_id'))
+            ->pluck('title','id')
+            ->toArray();
+        $team_maps = Team::whereIn('id',array_column($data['data'],'team_id'))
+            ->pluck('title','id')
+            ->toArray();
+        $equipment_map = Equipment::whereIn('id',array_column($data['data'],'equipment_id'))
+            ->pluck('title','id')
+            ->toArray();
+
         date_default_timezone_set("PRC");
         foreach ($data['data'] as $key => $value){
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
@@ -288,6 +302,9 @@ class DispatchService extends Service
             $time2 = $value['dispatch_time_end'] ? date('Y-m-d',$value['dispatch_time_end']) : '';
             $data['data'][$key]['dispatch_time'] = $time1 . ' ' . $time2;
             $data['data'][$key]['team_man'] = $team_map[$value['team_id']] ?? '';
+            $data['data'][$key]['process_name'] = $process_map[$value['process_id']] ?? '';
+            $data['data'][$key]['team_name'] = $team_maps[$value['team_id']] ?? '';
+            $data['data'][$key]['equipment_name'] = $equipment_map[$value['equipment_id']] ?? '';
         }
         $data['dispatch_quantity'] = array_sum(array_column($data['data'], 'dispatch_quantity'));
 

+ 1 - 5
app/Service/FyyOrderService.php

@@ -87,7 +87,7 @@ class FyyOrderService extends Service
 
     public function orderList($data){
         $model = SaleOrdersProduct::where('del_time',0)
-            ->select('id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time')
+            ->select('id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time','production_quantity')
             ->orderBy('id','desc');
 
         if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
@@ -136,9 +136,6 @@ class FyyOrderService extends Service
             }
         }
 
-        //已生产数量
-        $production_map = (new ProductionOrderService())->getProductionOrderQuantity(array_column($data['data'],'id'));
-
         date_default_timezone_set("PRC");
         foreach ($data['data'] as $key => $value){
             $keys = $value['product_no'] . $value['technology_name'] . $value['wood_name'];
@@ -146,7 +143,6 @@ class FyyOrderService extends Service
             $data['data'][$key]['out_order_no_time'] = $value['out_order_no_time'] ? date('Y-m-d',$value['out_order_no_time']) : '';
             $data['data'][$key]['out_checker_time'] = $value['out_checker_time'] ? date('Y-m-d',$value['out_checker_time']) : '';
             $data['data'][$key]['product_quantity_on_hand'] = $detailMap[$keys] ?? 0;
-            $data['data'][$key]['production_quantity'] = $production_map[$value['id']] ?? 0;
         }
         $data['order_quantity'] = array_sum(array_column($data['data'], 'order_quantity'));
 

+ 28 - 7
app/Service/ProductionOrderService.php

@@ -75,9 +75,11 @@ class ProductionOrderService extends Service
             }
             OrdersProduct::insert($result);
 
+            //获取上一次插入订单的所有id
             $last_insert_id = OrdersProduct::where('production_no',$production_no)->select('id')->get()->toArray();
             $last_insert_id = array_column($last_insert_id,'id');
 
+            //组织process bom的数据 写入与主表的关联id
             foreach ($result as $key => $value){
                 $quantity_tmp = $data['quantity'][$key];
 
@@ -107,6 +109,9 @@ class ProductionOrderService extends Service
                 }
             }
 
+            //反写已经生产数量
+            $this->writeProductionQuantity($data['id']);
+
             foreach ($boom as $key => $value){
                 $boom_model = new OrdersProductBom(['channel'=> $key]);
                 $boom_model->insert($value);
@@ -172,15 +177,11 @@ class ProductionOrderService extends Service
         if(in_array(false, $data['quantity'], true) || in_array(0, $data['quantity'], true) || in_array('', $data['quantity'], true))return [false,'数量不能为空!'];
 
         $result = SaleOrdersProduct::whereIn('id',$data['id'])
-            ->select('id as sale_orders_product_id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time')->get()->toArray();
-        $map = $this->getProductionOrderQuantity(array_column($result,'sale_orders_product_id'));
+            ->select('id as sale_orders_product_id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time','production_quantity')->get()->toArray();
 
         foreach ($result as $key => $value){
-            if(isset($map[$value['sale_orders_product_id']])){
-                if($map[$value['sale_orders_product_id']] + $data['quantity'][$key] > $value['order_quantity']) return [false,'生产数量不能大于订单数量'];
-            }else{
-                if($data['quantity'][$key] > $value['order_quantity']) return [false,'生产数量不能大于订单数量'];
-            }
+            if($value['production_quantity'] + $data['quantity'][$key] > $value['order_quantity']) return [false,'生产数量不能大于订单数量'];
+            unset($result[$key]['production_quantity']);//删除销售订单的已生产数量
         }
 
         return [true, $result];
@@ -203,6 +204,26 @@ class ProductionOrderService extends Service
         return $data;
     }
 
+    //反写已生产数量
+    public function writeProductionQuantity($sale_orders_product_id){
+        if(empty($sale_orders_product_id)) return;
+
+        $result = OrdersProduct::where('del_time',0)
+            ->whereIn('sale_orders_product_id',$sale_orders_product_id)
+            ->select(DB::raw("sum(production_quantity) as production_quantity"),'sale_orders_product_id')
+            ->groupby('sale_orders_product_id')
+            ->pluck('production_quantity','sale_orders_product_id')
+            ->toArray();
+
+        if(empty($result)) return;
+
+        foreach ($result as $key => $value){
+            SaleOrdersProduct::where('id',$key)->update([
+                'production_quantity' => $value
+            ]);
+        }
+    }
+
     //返回已生产数量
     public function getProductionOrderQuantity($data){
         if(empty($data)) return [];