Browse Source

Merge remote-tracking branch 'origin/fyy' into fyy

root 2 năm trước cách đây
mục cha
commit
e0af917a9c
2 tập tin đã thay đổi với 84 bổ sung13 xóa
  1. 83 13
      app/Service/FinishedOrderService.php
  2. 1 0
      app/Service/FyyOrderService.php

+ 83 - 13
app/Service/FinishedOrderService.php

@@ -10,6 +10,7 @@ use App\Model\Equipment;
 use App\Model\FinishedOrder;
 use App\Model\FinishedOrderScrapp;
 use App\Model\FinishedOrderSub;
+use App\Model\OrdersProduct;
 use App\Model\OrdersProductProcess;
 use App\Model\Process;
 use App\Model\SaleOrdersProduct;
@@ -58,11 +59,8 @@ class FinishedOrderService extends Service
             'result' => $msg,
             'data' => $data,
         ];
-        file_put_contents('1.txt','start:'.microtime(true).PHP_EOL,8);
-        $job = ProcessDataJob::dispatch($redis,$user,1)->onQueue('finished_operation');
-        file_put_contents('1.txt','end:'.microtime(true).PHP_EOL,8);
-        $job =true;
 
+        $job = ProcessDataJob::dispatch($redis,$user,1)->onQueue('finished_operation');
         if(! $job){
             return [false,'任务没有进入队列!'];
         }
@@ -170,6 +168,15 @@ class FinishedOrderService extends Service
                     ]);
 
                 if(! empty($insert_waste)) $process_model->insert($insert_waste);
+
+                //生产订单数量
+                if(! empty($waste[$key])){
+                    $num = $waste[$key];
+                    OrdersProduct::where('id',$value['order_product_id'])->update([
+                        'production_quantity' => DB::raw("production_quantity + {$num}"),
+                        'scrapp_num' => DB::raw("scrapp_num + {$num}"),
+                    ]);
+                }
             }
 
             //反写数量
@@ -235,6 +242,9 @@ class FinishedOrderService extends Service
     public function orderRule($data){
         if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
         if($this->isEmpty($data,'quantity')) return [false,'请填写完工数量!'];
+        foreach ($data['quantity'] as $value){
+            if(! is_numeric($value) && $value < 0) return [false,'请填写正确的完工数量!'];
+        }
         if($this->isEmpty($data,'finish_id') && $this->isEmpty($data,'team_id')) return [false,'人员和班组不能都为空!'];
 
         $bool = DispatchSub::whereIn('id',$data['id'])->where('job_status',1)->exists();
@@ -245,8 +255,13 @@ class FinishedOrderService extends Service
             ->orderBy('id','desc')
             ->get()->toArray();
 
+        $waste = [];
+        foreach ($data['waste'] as $key => $value){
+            $waste[$key] = array_sum(array_column($value,'num'));
+        }
         foreach ($result as $key => $value){
-            if(($data['quantity'][$key] + $value['finished_num']) > $value['dispatch_quantity']) return [false,'完工数量不能大于派工数量'];
+            $tmp = $waste[$key] ?? 0;
+            if(($data['quantity'][$key] + $value['finished_num'] + $tmp) > $value['dispatch_quantity']) return [false,'完工数量加上损耗数量不能大于派工数量'];
         }
 
         return [true, $result];
@@ -391,9 +406,7 @@ class FinishedOrderService extends Service
             'data' => $data,
             'quantity_count' => $count_arr,
         ];
-        file_put_contents('1.txt','start:'.time().PHP_EOL,8);
-        $job =  ProcessDataJob::dispatch($redis,$user,3)->onQueue(ProcessDataJob::job_one);
-        file_put_contents('1.txt','end:'.time().PHP_EOL,8);
+        $job = ProcessDataJob::dispatch($redis,$user,3)->onQueue(ProcessDataJob::job_one);
         if(! $job) return [false,'任务没有进入队列!'];
 
         //错误计数
@@ -444,15 +457,39 @@ class FinishedOrderService extends Service
             //本地数据写入-----------
             DB::beginTransaction();
 
+            $waste = $waste2 = [];
+            foreach ($data as $value){
+                if(! empty($value['waste'])){
+                    foreach ($value['waste'] as $v){
+                        if(isset($waste[$value['id']])){
+                            $waste[$value['id']] += $v['num'];
+                            $waste2[$value['order_product_id']] += $v['num'];
+                        }else{
+                            $waste[$value['id']] = $v['num'];
+                            $waste2[$value['order_product_id']] = $v['num'];
+                        }
+                    }
+                }
+            }
             $time = time();
-            foreach ($result as $key => $value){
+            foreach ($result as $value){
                 $finished_num = $value['quantity'] + $value['finished_num'];
                 DispatchSub::where('id',$value['id'])
                     ->update([
                         'finished_num' => $finished_num,
+                        'waste_num' => $waste[$value['id']] ?? 0,
                         'job_status' => 0
                     ]);
-
+                //生产订单数量
+                if(! empty($waste2[$value['order_product_id']])){
+                    $num = $waste2[$value['order_product_id']];
+                    OrdersProduct::where('id',$value['order_product_id'])->update([
+                        'production_quantity' => DB::raw("production_quantity + {$num}"),
+                        'scrapp_num' => DB::raw("scrapp_num + {$num}"),
+                    ]);
+                }
+                //损耗
+                $insert_waste = [];
                 //工序
                 $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
                 foreach ($data as $d){
@@ -468,8 +505,30 @@ class FinishedOrderService extends Service
                                 'team_id' => $d['team_id'],
                                 'equipment_id' => $d['equipment_id']
                             ]);
+
+                        if(! empty($d['waste'])){
+                            foreach ($d['waste'] as $v){
+                                for($i = 0 ;$i < $v['num']; $i++){
+                                    $insert_waste[] = [
+                                        'order_product_id' => $value['order_product_id'],
+                                        'order_no' => $value['order_no'],
+                                        'product_no' => $value['product_no'],
+                                        'product_title' => $value['product_title'],
+                                        'process_id' => $value['process_id'],
+                                        'crt_time' => $time,
+                                        'dispatch_no' => $value['dispatch_no'],
+                                        'status' => 4,
+                                        'team_id' => $d['team_id'],
+                                        'finished_id' => $d['finished_id'],
+                                        'equipment_id' => $d['equipment_id'],
+                                        'scrapp_id' => $v['scrapp_id']
+                                    ];
+                                }
+                            }
+                        }
                     }
                 }
+                if(! empty($insert_waste)) $process_model->insert($insert_waste);
             }
 
             //反写数量
@@ -492,15 +551,25 @@ class FinishedOrderService extends Service
         $bool = DispatchSub::whereIn('id',$dispatch_id)->where('job_status',1)->exists();
         if($bool) return [false,'正在队列中,请不要重复操作!',''];
 
-        $post = [];
+        $post = $waste = [];
         foreach ($data as $value){
-            if(empty($value['quantity'])) return [false,'数量必须填写!',''];
+            if(! is_numeric($value['quantity']) && $value['quantity'] < 0) return [false,'请填写正确的完工数量!'];
             if(empty($value['finished_id']) && empty($value['team_id'])) return [false,'人员和班组必须填写一项!',''];
             if(isset($post[$value['id']])){
                 $post[$value['id']] += $value['quantity'];
             }else{
                 $post[$value['id']] = $value['quantity'];
             }
+
+            if(! empty($value['waste'])){
+                foreach ($value['waste'] as $v){
+                    if(isset($waste[$value['id']])){
+                        $waste[$value['id']] += $v['num'];
+                    }else{
+                        $waste[$value['id']] = $v['num'];
+                    }
+                }
+            }
         }
 
         $result = DispatchSub::whereIn('id',$dispatch_id)
@@ -509,7 +578,8 @@ class FinishedOrderService extends Service
             ->get()->toArray();
 
         foreach ($result as $key => $value){
-            if(($post[$value['id']] + $value['finished_num']) > $value['dispatch_quantity']) return [false,"{$value['dispatch_no']}单号的完工数量不能大于派工数量",''];
+            $tmp = $waste[$value['id']] ?? 0;
+            if(($post[$value['id']] + $value['finished_num'] + $tmp) > $value['dispatch_quantity']) return [false,"完工数量加上损耗数量不能大于派工数量",''];
         }
 
         return [true, $result, $post];

+ 1 - 0
app/Service/FyyOrderService.php

@@ -108,6 +108,7 @@ class FyyOrderService extends Service
         if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
         if(! empty($data['out_order_no'])) $model->where('out_order_no', 'LIKE', '%'.$data['out_order_no'].'%');
         if(! empty($data['customer_name'])) $model->where('customer_name', 'LIKE', '%'.$data['customer_name'].'%');
+        if(! empty($data['product_no'])) $model->where('product_no', 'LIKE', '%'.$data['product_no'].'%');
         if(! empty($data['product_title'])) $model->where('product_title', 'LIKE', '%'.$data['product_title'].'%');
         if(! empty($data['product_size'])) $model->where('product_size', 'LIKE', '%'.$data['product_size'].'%');
         if(! empty($data['technology_material'])) $model->where('technology_material', 'LIKE', '%'.$data['technology_material'].'%');