cqp 2 bulan lalu
induk
melakukan
ece4c0eba6

+ 106 - 0
app/Http/Controllers/Api/TestController.php

@@ -4,11 +4,19 @@ namespace App\Http\Controllers\Api;
 
 
 use App\Model\BoxDetail;
+use App\Model\Depart;
+use App\Model\InOutRecord;
+use App\Model\Inventory;
+use App\Model\Product;
+use App\Model\ProductInventory;
+use App\Model\ProductPriceDetail;
+use App\Model\PurchaseOrderInfoForOutBound;
 use App\Service\Box\BoxHookService;
 use App\Service\EmployeeService;
 use App\Service\MeasureService;
 use App\Service\OaService;
 use App\Service\OperationLogService;
+use App\Service\OrderNoService;
 use App\Service\SalesOrderService;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Hash;
@@ -111,5 +119,103 @@ die;
 
 
 
+    public function clear(){
+        $in_record = InOutRecord::select('top_depart_id')
+            ->groupBy('top_depart_id')
+            ->get()->toArray();
+        $in_record = array_column($in_record,'top_depart_id');
 
+        $depart = Depart::whereIn('id',$in_record)
+            ->pluck('basic_type_id', 'id')
+            ->toArray();
+
+        $product_inventory = ProductInventory::whereIn('top_depart_id',$in_record)
+            ->select('id','product_id','storehouse_id','number','lock_number','top_depart_id')
+            ->get()->toArray();
+        $product_inventory_map = [];
+        foreach ($product_inventory as $value){
+            $key = $value['top_depart_id'] . $value['product_id'];
+            $product_inventory_map[$key] = 111;
+        }
+
+        $record_list = InOutRecord::where('del_time',0)
+            ->whereIn('top_depart_id',$in_record)
+            ->get()->toArray();
+        $list = [];$error1 = [];
+        foreach ($record_list as $value){
+            $key = $value['top_depart_id'] . $value['product_id'];
+            if(! isset($product_inventory_map[$key])){
+                $error1[] = $value;
+            }else{
+                if(isset($list[$key])){
+                    $number = bcadd($value['number'],$list[$key],2);
+                    $list[$key] = $number;
+                }else{
+                    $list[$key] = $value['number'];
+                }
+            }
+        }
+        if(! empty($error1)){
+            foreach ($error1 as $value){
+                InOutRecord::where('id', $value['id'])->update(['del_time' => 1233]);
+            }dd(1);
+        }
+
+        $error = [];
+        foreach ($product_inventory as $value){
+            $key = $value['top_depart_id'] . $value['product_id'];
+            if(isset($list[$key])){
+                $tmp = $list[$key];
+                if($tmp != $value['number']){
+                    $numbers = bcsub($value['number'],$tmp,2);
+                    $error[] = [
+                        'product_id' => $value['product_id'],
+                        'top_depart_id' => $value['top_depart_id'],
+                        'depart_id' => $value['top_depart_id'],
+                        'storehouse_id' => $value['storehouse_id'],
+                        'number' => $numbers,
+                    ];
+                }
+            }else{
+                $error[] = [
+                    'product_id' => $value['product_id'],
+                    'top_depart_id' => $value['top_depart_id'],
+                    'depart_id' => $value['top_depart_id'],
+                    'storehouse_id' => $value['storehouse_id'],
+                    'number' => $value['number'],
+                ];
+            }
+        }
+
+        if(empty($error)) dd('no data');
+dd($error);
+        $price_detail_map = [];
+        $price_detail = ProductPriceDetail::whereIn('product_id',array_unique(array_column($error,'product_id')))
+            ->select('product_id','price','basic_type_id')
+            ->get()->toArray();
+        foreach ($price_detail as $value){
+            $price_detail_map[$value['product_id'] . $value['basic_type_id']] = $value['price'];
+        }
+
+        $price_2 = Product::whereIn('id',array_unique(array_column($error,'product_id')))
+            ->pluck('retail_price','id')
+            ->toArray();
+
+        foreach ($error as $e => $value){
+            $basic_type_id = $depart[$value['top_depart_id']] ?? 0;
+            $key = $value['product_id'] . $basic_type_id;
+            $price = $price_detail_map[$key] ?? 0;
+            if(! $price) $price = $price_2[$value['product_id']] ?? 0;
+            if(! $price) dd(1);
+            if(! $value['number'] > 0) dd(2222);
+
+            $error[$e]['price'] = $price;
+            $error[$e]['crt_time'] = 1740758399;
+            $error[$e]['order_type'] = PurchaseOrderInfoForOutBound::prefix2;
+            $error[$e]['order_number'] = (new OrderNoService())->createOrderNumber(PurchaseOrderInfoForOutBound::prefix2);
+        }
+
+        InOutRecord::insert($error);
+        dd(count($error),$error);
+    }
 }

+ 1 - 0
app/Model/PurchaseOrderInfoForOutBound.php

@@ -14,6 +14,7 @@ class PurchaseOrderInfoForOutBound extends Model
     const is_use = 1;
     const type_one = 1;
     const prefix = 'CGCk';
+    const prefix2 = 'SJZL';
 
     const from_type_zero = 0; // 采购单
     const from_type_one = 1;  // 盘点单

+ 4 - 2
app/Service/ProductInventoryService.php

@@ -190,9 +190,10 @@ class ProductInventoryService extends Service
         if(isset($data['is_stock'])){
             if($data['is_stock'] == 0){
                 $model->where('a.number','>',0);
-            }else{
-                $model->where('a.number','<=',0);
             }
+//            else{
+//                $model->where('a.number','<=',0);
+//            }
         }else{
             $model->where('a.number','>',0);
         }
@@ -363,6 +364,7 @@ class ProductInventoryService extends Service
         $array[Inventory::prefix] = '盘点单';
         $array[OutBoundOrder::prefix] = '出库单';
         $array[PurchaseOrderInfoForOutBound::prefix] = '平出库流水记录';
+        $array[PurchaseOrderInfoForOutBound::prefix2] = '平库存流水记录';
         $array[ProductAdjustment::prefix] = '产品金额调整单';
 
         return $array;