cqpCow 2 年之前
父节点
当前提交
fe4ed01a18
共有 2 个文件被更改,包括 97 次插入32 次删除
  1. 42 16
      app/Service/FyyOrderService.php
  2. 55 16
      app/Service/FyySqlServerService.php

+ 42 - 16
app/Service/FyyOrderService.php

@@ -25,7 +25,7 @@ class FyyOrderService extends Service
         list($status,$return,$return_stock_detail) = $sqlServerModel->getDataFromSqlServer($data);
         if(! $status) return [false, $return];
 
-        //数据校验以及填充
+        //数据校验
         list($status,$msg) = $this->orderRule($return);
         if(!$status) return [$status,$msg];
 
@@ -35,7 +35,7 @@ class FyyOrderService extends Service
             $keys = array_unique(array_column($return,'out_order_no'));
             $map = array_fill_keys($keys, 0);
 
-            $orders = $return_stock_detail_map = [];
+            $orders = [];
             foreach ($return as $key => $value){
                 if(! empty($map[$value['out_order_no']])){
                     $order_no = $map[$value['out_order_no']];
@@ -52,14 +52,6 @@ class FyyOrderService extends Service
                 $return[$key]['order_no'] = $order_no;
                 $return[$key]['crt_id'] = $user['id'];
                 $return[$key]['crt_time'] = time();
-
-                $keys = ($value['technology_name'] ?? '' ) . ($value['wood_name'] ?? '' ) . $value['product_no'];
-                $return_stock_detail_map[$keys] = $order_no;
-            }
-
-            foreach ($return_stock_detail as $key => $value){
-                $keys = ($value['technology_name'] ?? '' ) . ($value['wood_name'] ?? '' ) . $value['product_no'];
-                $return_stock_detail[$key]['order_no'] = $return_stock_detail_map[$keys] ?? '';
             }
 
             Orders::insert($orders);
@@ -124,23 +116,33 @@ class FyyOrderService extends Service
     public function fillData($data){
         if(empty($data['data'])) return $data;
 
-        $order_no = array_filter(array_column($data['data'],'order_no'));
+        $product_no = array_filter(array_column($data['data'],'product_no'));
         $detail = SaleOrdersProductStockDetail::where('del_time',0)
-            ->whereIn('order_no',$order_no)
-            ->select('order_no','product_no','product_quantity_on_hand','technology_name','wood_name','warehouse_name')
+            ->whereIn('product_no',$product_no)
+            ->select('product_no','product_quantity_on_hand','technology_name','wood_name','warehouse_name')
             ->get()->toArray();
-        $detail_map = [];
+        $detailMap = $detail_map = [];
         foreach ($detail as $value){
-            $keys = $value['order_no'] . $value['product_no'];
+            $keys = $value['product_no'] . $value['technology_name'] . $value['wood_name'];
             $detail_map[$keys][] = [
                 'warehouse_name' => $value['warehouse_name'],
                 'product_quantity_on_hand' => $value['product_quantity_on_hand']
             ];
+
+            if(isset($detailMap[$keys])){
+                $detailMap[$keys] += $value['product_quantity_on_hand'];
+            }else{
+                $detailMap[$keys] = $value['product_quantity_on_hand'];
+            }
         }
 
+        date_default_timezone_set("PRC");
         foreach ($data['data'] as $key => $value){
-            $keys = $value['order_no'] . $value['product_no'];
+            $keys = $value['product_no'] . $value['technology_name'] . $value['wood_name'];
             $data['data'][$key]['sub'] = $detail_map[$keys] ?? [];
+            $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;
         }
 
         return $data;
@@ -157,6 +159,30 @@ class FyyOrderService extends Service
     }
 
     public function fyyRefreshOnHandQuantity($data){
+        //获取数据
+        $sqlServerModel = new FyySqlServerService();
+        list($status,$return,$return_product) = $sqlServerModel->getDataFromSqlServerForOnHand($data);
+        if(! $status) return [false, $return];
+
+        DB::beginTransaction();
+        try {
+            $args = '';
+            foreach ($return_product as $value){
+                $args .= "(product_no = '{$value['product_no']}' and technology_name = '{$value['technology_name']}' and wood_name = '{$value['wood_name']}') OR ";
+            }
+            $args = rtrim($args,'OR ');
+            SaleOrdersProductStockDetail::where('del_time',0)
+                ->whereRaw("($args)")
+                ->update(['del_time' => time()]);
+
+            SaleOrdersProductStockDetail::insert($return);
+
+            DB::commit();
+        }catch (\Throwable $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
         return [true,''];
     }
 }

+ 55 - 16
app/Service/FyySqlServerService.php

@@ -2,6 +2,7 @@
 
 namespace App\Service;
 
+use App\Model\SaleOrdersProduct;
 use Illuminate\Support\Facades\DB;
 
 class FyySqlServerService extends Service
@@ -83,20 +84,33 @@ class FyySqlServerService extends Service
         return $return;
     }
 
-    //获取数据
+    //获取数据(点击引入)
     public function getDataFromSqlServer($data){
-        if(empty($data['out_order_no_time'][0]) || empty($data['out_order_no_time'][1])) return [false,'制单日期不能为空!'];
+        if(empty($data['out_order_no_time'][0]) || empty($data['out_order_no_time'][1])) return [false,'制单日期不能为空!',''];
 
         //查询产品主表副表数据
         date_default_timezone_set("PRC");
         $start = date('Y-m-d H:i:s.000',$data['out_order_no_time'][0]);
         $end = date('Y-m-d H:i:s.000',$data['out_order_no_time'][1]);
-        $result = $this->db->table('SO_SOMain as a')
+        $model = $this->db->table('SO_SOMain as a')
             ->leftJoin('SO_SODetails as b','b.cSOCode','a.cSOCode')
             ->whereBetween('a.dDate',[$start, $end])
-            ->select('a.cSOCode as out_order_no','a.dDate as out_order_no_time','a.cCusCode as customer_no','a.cCusName as customer_name','a.cMemo as table_header_mark','a.cMaker as out_crt_man','a.cVerifier as out_checker_man','a.dverifydate as out_checker_time','b.cInvCode as product_no','b.iQuantity as product_quantity','b.cDefine28 as technology_material','b.cFree1 as technology_name','b.cFree2 as wood_name','b.cDefine30 as process_mark','b.cMemo as table_body_mark')
-            ->get()->toArray();
-        if(empty($result)) return [false,'暂无数据,更新结束!'];
+            ->select('a.cSOCode as out_order_no','a.dDate as out_order_no_time','a.cCusCode as customer_no','a.cCusName as customer_name','a.cMemo as table_header_mark','a.cMaker as out_crt_man','a.cVerifier as out_checker_man','a.dverifydate as out_checker_time','b.cInvCode as product_no','b.iQuantity as product_quantity','b.cDefine28 as technology_material','b.cFree1 as technology_name','b.cFree2 as wood_name','b.cDefine30 as process_mark','b.cMemo as table_body_mark');
+
+        if(! empty($data['out_order_no'])) $model->where('a.cSOCode', 'LIKE', '%'.$data['out_order_no'].'%');
+        if(! empty($data['customer_no'])) $model->where('a.cCusCode', 'LIKE', '%'.$data['customer_no'].'%');
+        if(! empty($data['customer_name'])) $model->where('a.cCusName', 'LIKE', '%'.$data['customer_name'].'%');
+        if(! empty($data['table_header_mark'])) $model->where('a.cMemo', 'LIKE', '%'.$data['table_header_mark'].'%');
+        if(! empty($data['out_crt_man'])) $model->where('a.cMaker', 'LIKE', '%'.$data['out_crt_man'].'%');
+        if(! empty($data['out_checker_man'])) $model->where('a.cVerifier', 'LIKE', '%'.$data['out_checker_man'].'%');
+        if(! empty($data['out_checker_time'][0]) && ! empty($data['out_checker_time'][1])) {
+            $start1 = date('Y-m-d H:i:s.000',$data['out_checker_time'][0]);
+            $end1 = date('Y-m-d H:i:s.000',$data['out_checker_time'][1]);
+            $model->whereBetween('a.dverifydate',[$start1, $end1]);
+        }
+
+        $result = $model->get()->toArray();
+        if(empty($result)) return [false,'暂无数据,更新结束!',''];
 
         //查询附带的一些信息(比较少)
         $product_no = array_column($result,'product_no');
@@ -110,7 +124,7 @@ class FyySqlServerService extends Service
             ->get()->toArray();
         $messageMap = array_column($messageOne,null,'product_no');
 
-        //组织查询条件
+        //现存量查询开始 ---组织查询条件
         $args = '';
         foreach ($result as $value){
             $product = $value->product_no;
@@ -127,30 +141,55 @@ class FyySqlServerService extends Service
             ->select('a.iQuantity as product_quantity_on_hand','a.cInvCode as product_no','a.cFree1 as technology_name','a.cFree2 as wood_name','b.cWhName as warehouse_name')
             ->get()->toArray();
 
-        $messageTwoTotal = [];
         if(! empty($messageTwo)){
             foreach ($messageTwo as $key => $value){
-                $keys = $value->product_no . $value->technology_name . $value->wood_name;
-                if(isset($messageTwoTotal[$keys])){
-                    $messageTwoTotal[$keys] += $value->product_quantity_on_hand;
-                }else{
-                    $messageTwoTotal[$keys] = $value->product_quantity_on_hand;
-                }
-
                 $messageTwo[$key] = (array)$value;
             }
         }
+        //现存量查询结束
 
         foreach ($result as $key => $value){
             $keys = $value->product_no . $value->technology_name . $value->wood_name;
             $result[$key]->out_order_no_time = $value->out_order_no_time ? strtotime($value->out_order_no_time) : 0;
+            $result[$key]->out_checker_time = $value->out_checker_time ? strtotime($value->out_checker_time) : 0;
             $result[$key]->product_title = $messageMap[$value->product_no]->product_title ?? '';
             $result[$key]->product_size = $messageMap[$value->product_no]->product_size ?? '';
             $result[$key]->product_unit = $messageMap[$value->product_no]->product_unit ?? '';
-            $result[$key]->product_quantity_on_hand = $messageTwoTotal[$keys] ?? 0;
             $result[$key] = (array)$value;
         }
 
         return [true,$result,$messageTwo];
     }
+
+    //获取数据(刷新现存量)
+    public function getDataFromSqlServerForOnHand($data){
+        if(empty($data['id'])) return [false,'数据不能为空!',''];
+
+        $product = SaleOrdersProduct::whereIn('id',$data['id'])
+            ->select('product_no','technology_name','wood_name')
+            ->get()->toArray();
+
+        //现存量查询开始 ---组织查询条件
+        $args = '';
+        foreach ($product as $value){
+            $args .= "(a.cInvCode = '{$value['product_no']}' and a.cFree1 = '{$value['technology_name']}' and a.cFree2 = '{$value['wood_name']}') OR ";
+        }
+        $args = rtrim($args,'OR ');
+
+        $message = $this->db->table('CurrentStock as a')
+            ->leftJoin('Warehouse as b','b.cWhCode','a.cWhCode')
+            ->whereRaw("($args)")
+            ->where('a.iQuantity','>',0)
+            ->select('a.iQuantity as product_quantity_on_hand','a.cInvCode as product_no','a.cFree1 as technology_name','a.cFree2 as wood_name','b.cWhName as warehouse_name')
+            ->get()->toArray();
+
+        if(! empty($message)){
+            foreach ($message as $key => $value){
+                $message[$key] = (array)$value;
+            }
+        }
+        //现存量查询结束
+
+        return [true,$message,$product];
+    }
 }