cqp 6 ay önce
ebeveyn
işleme
dc7acf825b
1 değiştirilmiş dosya ile 122 ekleme ve 0 silme
  1. 122 0
      app/Service/FinishedOrderService.php

+ 122 - 0
app/Service/FinishedOrderService.php

@@ -29,6 +29,128 @@ class FinishedOrderService extends Service
 {
     public function edit($data){}
 
+    public function getZj($data, $user){
+        if(empty($data['id'])) return [false, '完工单ID不能为空'];
+        if(empty($data['process_id'])) return [false, '工序ID不能为空'];
+
+        $old = ScrappCount::where('del_time',0)
+            ->where('dispatch_sub_id', $data['id'])
+            ->where('process_id', $data['process_id'])
+            ->select('scrapp_id','scrapp_num as num','process_id')
+            ->get()->toArray();
+        $return = [];
+        foreach ($old as $value){
+            $key = $value['scrapp_id'] . $value['process_id'];
+            if(isset($return[$key])){
+                $return[$key]['num'] += $value['num'];
+            }else{
+                $return[$key] = [
+                    'scrapp_id' => $value['scrapp_id'],
+                    'num' => $value['num'],
+                    'process_id' => $value['process_id'],
+                ];
+            }
+        }
+
+        return [true, ['save' => array_values($return)]];
+    }
+
+    public function editZj($data, $user){
+        list($status, $msg) = $this->editZjRule($data);
+        if(! $status) return [false, $msg];
+
+        $order = $msg;
+        try{
+            DB::beginTransaction();
+            $time = time();
+
+            //更新次品数量
+            $num = 0;
+            if(! empty($data['waste'])){
+                foreach ($data['waste'] as $value){
+                    $num += $value['num'];
+                }
+            }
+            DispatchSub::where('id',$order['id'])->update([
+                'waste_num' => $num,
+            ]);
+
+            $insert = [];
+            foreach ($data['waste'] as $value){
+                $insert[] = [
+                    'sale_orders_product_id' => $order['sale_orders_product_id'],
+                    'order_product_id' => $order['order_product_id'],
+                    'dispatch_sub_id' => $order['id'],
+                    'out_order_no' => $order['out_order_no'],
+                    'order_no' => $order['order_no'],
+                    'customer_no' => $order['customer_no'],
+                    'customer_name' => $order['customer_name'],
+                    'product_no' => $order['product_no'],
+                    'product_title' => $order['product_title'],
+                    'product_size' => $order['product_size'],
+                    'product_unit' => $order['product_unit'],
+                    'technology_material' => $order['technology_material'],
+                    'technology_name' => $order['technology_name'],
+                    'wood_name' => $order['wood_name'],
+                    'price' => $order['price'],
+                    'process_mark' => $order['process_mark'],
+                    'table_body_mark' => $order['table_body_mark'],
+                    'table_header_mark' => $order['table_header_mark'],
+                    'crt_id' => $user['id'],
+                    'crt_time' => $time,
+                    'scrapp_num' => $value['num'],
+                    'scrapp_id' => $value['scrapp_id'],
+                    'team_id' => $data['team_id'],
+                    'finished_id' => 0,
+                    'equipment_id' => $data['equipment_id'],
+                    'order_number' => $order['id'] . $time . $order['process_id'],
+                    'process_id' => $order['process_id'],
+                    'quantity' => $order['finished_num'],
+                ];
+            }
+
+            //质检单 不良品单
+            ScrappCount::where('del_time',0)
+                ->where('dispatch_sub_id', $order['id'])
+                ->where('process_id',$order['process_id'])
+                ->update(['del_time' => $time]);
+            if(! empty($insert)) ScrappCount::insert($insert);
+
+            DB::commit();
+        }catch (\Throwable $exception){
+            DB::rollBack();
+            return [false, $exception->getMessage()];
+
+        }
+
+        return [true, ''];
+    }
+
+    public function editZjRule($data){
+        if(empty($data['id'])) return [false, '完工ID不能为空'];
+        $order = DispatchSub::where('del_time',0)
+            ->where('id',$data['id'])
+            ->first();
+        if(empty($order)) return [false, '完工单不存在或已被删除'];
+        $order = $order->toArray();
+        if(empty($data['team_id'])) return [false, '质检班组不能为空'];
+//            if(empty($value['finished_id'])) return [false, '质检人员不能为空'];
+        if(empty($data['equipment_id'])) return [false, '设备不能为空'];
+//        if(empty($data['waste'])) return [false, '质检信息不能为空'];
+//        if(! empty($data['waste'])){
+//            $num = 0;
+//            foreach ($data['waste'] as $value){
+//                if(empty($value['num'])) return [false, '质检损耗数量不能为空'];
+//                if(empty($value['scrapp_id'])) return [false, '质检损耗原因不能为空'];
+//                $num += $value['num'];
+//            }
+//
+//            if($num > $order['finished_num']) return [false, '质检总数不能超过完工数量'];
+//        }
+
+        return [true, $order];
+    }
+
     public function setOrderNO(){
         $str = date('Ymd',time());