cqpCow 2 年 前
コミット
93b6a8fe2c

+ 1 - 1
app/Jobs/ProcessDataJob.php

@@ -138,7 +138,7 @@ class ProcessDataJob implements ShouldQueue
         $data = $this->data['data'];
 
         //进入队列的数据
-        Box::where('order_no',$data['order_no'])->update([
+        Box::whereIn('order_no',$data['order_no'])->update([
             'state' => 0,
         ]);
     }

+ 22 - 16
app/Service/Box/BoxService.php

@@ -62,10 +62,12 @@ class BoxService extends Service
 //        ];
 
         $ids = [];
+        $sale_ids = [];
         $key_list = [];
         $top_order_no = $data['order_no'];
         foreach ($data as $v) {
-            $ids[] = $v['id'];
+            if($v['id'] < 0)  $sale_ids = -$v['id'];
+            else $ids[] = $v['id'];
             $total = 0;
 
             foreach ($v['params'] as $vv) {
@@ -83,6 +85,7 @@ class BoxService extends Service
             $lock_status = $this->isLock($key);
             if(!$lock_status) return [false,'操作过于频繁'];
             $product_list = OrdersProduct::wherein('id', $ids)->get()->toArray();
+            $sale_product_list = OrdersProduct::wherein('id', $ids)->get()->toArray();
             $box_insert = [];
             foreach ($product_list as $v) {
 
@@ -192,6 +195,7 @@ class BoxService extends Service
             if(!isset($v['box_type'])) {
                 $product_num = isset($product_key_num_list[$v['id']]) ? $product_key_num_list[$v['id']]['product_num'] : 0;
                 $box_num = isset($product_key_num_list[$v['id']]) ? $product_key_num_list[$v['id']]['box_num'] : 0;
+                if(($v['order_quantity'] - $product_num) === 0) continue;
                 $product_key_list[$v['sale_orders_product_id']] = [
                     'out_order_no' => $v['out_order_no'],
                     'production_time' => '未下生产',
@@ -206,22 +210,24 @@ class BoxService extends Service
                     'un_box_num' => $v['order_quantity'] - $v['box_num'] - $product_num,
                     'sale_num' => $v['order_quantity'],
                 ];
+            }else{
+
+                $return[] = [
+                    'id' => $v['id'],
+                    'out_order_no' => $v['out_order_no'],
+                    'production_time' => date('Y-m-d',$v['crt_time']),
+                    'customer_no' => $v['customer_no'],
+                    'customer_name' => $v['customer_name'],
+                    'product_no' => $v['product_no'],
+                    'product_title' => $v['product_title'],
+                    'product_size' => $v['product_size'],
+                    'type' => '1',
+                    'is_box_num' => $v['box_num'],
+                    'un_box_num' => $v['dispatch_complete_quantity'] - $v['box_num'],
+                    'sale_num' => $v['order_quantity'],
+                ];
             }
-            if($v['box_num'] === 0 && ($v['dispatch_complete_quantity'] - $v['box_num']) === 0) continue;
-            $return[] = [
-                'id' => $v['id'],
-                'out_order_no' => $v['out_order_no'],
-                'production_time' => date('Y-m-d',$v['crt_time']),
-                'customer_no' => $v['customer_no'],
-                'customer_name' => $v['customer_name'],
-                'product_no' => $v['product_no'],
-                'product_title' => $v['product_title'],
-                'product_size' => $v['product_size'],
-                'type' => '1',
-                'is_box_num' => $v['box_num'],
-                'un_box_num' => $v['dispatch_complete_quantity'] - $v['box_num'],
-                'sale_num' => $v['order_quantity'],
-            ];
+
         }
         foreach ($product_key_list as $v){
             $return[] = $v;

+ 17 - 29
app/Service/FyyOrderService.php

@@ -223,7 +223,7 @@ class FyyOrderService extends Service
         Redis::hSet('order_failures', md5(json_encode($redis)), 0);
 
         //标记进入队列的数据
-        Box::where('order_no',$data['order_no'])->update([
+        Box::whereIn('order_no',$data['order_no'])->update([
             'state' => 1,
         ]);
 
@@ -235,57 +235,45 @@ class FyyOrderService extends Service
             $sqlServerModel = new FyySqlServerService();
             if($sqlServerModel->error) return [false,$sqlServerModel->error];
 
-            list($status,$msg) = $sqlServerModel->U8Rdrecord32Save($result);
+            list($status,$msg) = $sqlServerModel->U8Rdrecord32Save($data['post']);
             if(! $status) return [false,$msg];
 
             //更新
-            Box::where('order_no',$data['order_no'])->update([
+            DB::beginTransaction();
+            Box::whereIn('order_no',$data['order_no'])->update([
                 'state' => 2,
             ]);
+            foreach ($data['box_data'] as $value){
+                SaleOrdersProduct::where('out_order_no',$data['order_number'])->update([
+                    'top_id' => $value['top_id'],
+                    'shipment_num' => $value['num'],
+                ]);
+            }
+            DB::commit();
         }catch (\Exception $e){
+            DB::rollBack();
             return [false,$e->getFile() . $e->getLine(). $e->getMessage()];
         }
 
         return [true,''];
     }
 
-    public function orderOutRule($data){//todo
+    public function orderOutRule($data){
+        if(empty($data['order_number'])) return [false,'销售订单号不能为空!'];
         if(empty($data['order_no'])) return [false,'包装单号不能为空!'];
+        if(empty($data['post'])) return [false,'发货单数据不能为空!'];
+        if(empty($data['box_data'])) return [false,'包装单数据不能为空!'];
 
         $boxList = Box::whereIn('order_no',$data['order_no'])->get()->toArray();
         if(empty($boxList)) return [false,'包装单不存在!'];
 
-        $box_detail_list = [];
         foreach ($boxList as $value){
             if($value['del_time'] > 0) return [false,'包装单:' . $value['order_no'] . '已删除'];
             if($value['state'] == 1) return [false,'包装单:' . $value['order_no'] . '已操作出库!'];
             if($value['state'] > 1) return [false,'包装单:' . $value['order_no'] . '已出库!'];
-
-            $box_detail = new BoxDetail(['channel' => $value['order_no']]);
-            $box_detail_list = $box_detail->where('del_time',0)
-                ->where('order_no',$data['order_no'])
-                ->select('order_no','out_order_no','top_id as sale_orders_product_id','ext_1 as customer_no','ext_2 as customer_name','ext_3 as product_no','num')
-                ->get()->toArray();
-        }
-
-
-        $box_detail = new BoxDetail(['channel'=>$box['order_no']]);
-        $box_detail_list = $box_detail->where('order_no',$data['order_no'])
-            ->where('del_time',0)
-            ->select('order_no','out_order_no','top_id as sale_orders_product_id','ext_1 as customer_no','ext_2 as customer_name','ext_3 as product_no','num')
-            ->get()->toArray();
-        if(! empty($box_detail_list)){
-            $saleOrder = SaleOrdersProduct::whereIn('id',array_column($box_detail_list,'sale_orders_product_id'))
-                ->select('id','technology_name','wood_name')
-                ->get()->toArray();
-            $saleOrderMap = array_column($saleOrder,null,'id');
-            foreach ($box_detail_list as $key => $value){
-                $box_detail_list[$key]['technology_name'] = $saleOrderMap[$value['sale_orders_product_id']]['technology_name'];
-                $box_detail_list[$key]['wood_name'] = $saleOrderMap[$value['sale_orders_product_id']]['wood_name'];
-            }
         }
 
-        return [true, $box_detail_list];
+        return [true, ''];
     }
 
     public function orderMobileList($data){

+ 13 - 34
app/Service/FyySqlServerService.php

@@ -359,34 +359,13 @@ class FyySqlServerService extends Service
     //销售出库单保存接口给以及审核
     public function U8Rdrecord32Save($data,$bredvouch = 0){
         if(! empty($this->error)) return [false,$this->error];
-        date_default_timezone_set("PRC");
-
-        //通过销售订单号 获取发货单的数据
-        $out_order_no = array_unique(array_column($data,'out_order_no'));
-        $return = $this->getDataFromDispatchList($out_order_no);
-        if(empty($return)) return [false,'没有找到发货单!'];
-
-        //组织发货单的数据
-        $map = [];
-        foreach ($return as $value){
-            $map[$value['cSOCode']][] = $value;
-        }
 
-        $detail = [];
+        $new = [];
         foreach ($data as $value){
-            if(! isset($map[$value['out_order_no']])) return [false,'包装单的销售订单号:' . $value['out_order_no'] .'没有找到发货单!'];
-            $is_flag = 0;
-            foreach ($map[$value['out_order_no']] as $m){
-                if($value['product_no'] == $m['cinvcode'] && $value['technology_name'] == $m['cfree1'] && $value['wood_name'] == $m['cfree2']) {
-                    $is_flag = 1;
-                    $m['iquantity'] = $value['num'];
-                    $detail[$m['cSOCode']][] = $m;
-                }
-            }
-            if(! $is_flag) return [false,'包装单的产品:' . $value['product_no'] . $value['technology_name'] . $value['wood_name'] . '在发货单中不存在!'];
+            $new[$value['id']][] = $value;
         }
 
-        foreach ($detail as $value){
+        foreach ($new as $value){
             $main_tmp = $value[0];
             foreach ($value as $val){
                 $bodys_tmp[] = [
@@ -395,13 +374,13 @@ class FyySqlServerService extends Service
                     "dlrowno"=>"",
                     "cbdlcode"=>"",
                     "cinvcode"=>$val['cinvcode'],
-                    "cposition"=>$val['cposition'],
-                    "cbatch"=>$val['cbatch'],
+                    "cposition"=>$val['cposition'] ?? "",
+                    "cbatch"=>$val['cbatch'] ?? "",
                     "iquantity"=>$val['iquantity'],
-                    "inum"=>$val['iquantity'],
-                    "iinvexchrate"=>$value['iinvexchrate'],
-                    "iunitcost"=>"",
-                    "iprice"=>"",
+                    "inum"=>$val['inum'],
+                    "iinvexchrate"=> $val['iinvexchrate'] ?? 0,
+                    "iunitcost"=>$val['iunitcost'],
+                    "iprice"=>$val['imoney'],
                     "cbmemo"=>"",
                 ];
             }
@@ -423,9 +402,9 @@ class FyySqlServerService extends Service
                     "dnmaketime"=> date("Y-m-d"),
                     "IsExamine"=>true,
                     "bredvouch"=> $bredvouch,
-                    "cwhcode"=>"02",
-                    "cdepcode"=>"06",
-                    "crdcode"=>"102",
+                    "cwhcode"=>$main_tmp['cwhcode'],
+                    "cdepcode"=>$main_tmp['cdepcode'],
+                    "crdcode"=>'',
                     "cmemo"=> '',
                     "cdefine10" => $main_tmp['customer_name'], //客户名称
                     "bodys"=>$bodys_tmp
@@ -544,7 +523,7 @@ class FyySqlServerService extends Service
             ->leftJoin('DispatchLists as b','b.DLID','a.DLID')
             ->where('a.cSOcode',$order_number)
             ->whereColumn('b.iQuantity', '>', 'b.fOutQuantity')
-            ->select('a.cDefine10 as customer_name','a.cSOCode','a.cDepCode','b.iDLsID as idlsid','b.cWhCode as cwhcode','b.cInvCode as cinvcode','b.cInvName as product_title','b.cFree1 as cfree1','b.cFree2 as cfree2','b.cPosition as cposition','b.cBatch as cbatch','b.iQuantity as iquantity','b.iNum as inum','b.iInvExchRate as iinvexchrate','b.fOutQuantity as out_quantity')
+            ->select('a.DLID as id','a.cDefine10 as customer_name','a.cSOCode','a.cDepCode as cdepcode','b.iDLsID as idlsid','b.cWhCode as cwhcode','b.cInvCode as cinvcode','b.cInvName as product_title','b.cFree1 as cfree1','b.cFree2 as cfree2','b.cPosition as cposition','b.cBatch as cbatch','b.iQuantity as iquantity','b.iNum as inum','b.iInvExchRate as iinvexchrate','b.fOutQuantity as out_quantity','b.iUnitPrice as iunitcost','b.iMoney as imoney')
             ->get()->toArray();
         if(! empty($message)){
             foreach ($message as $key => $value){