Zhouzhendong hace 4 años
padre
commit
48d755da38

+ 1 - 0
app/Http/Controllers/CustomerController.php

@@ -515,6 +515,7 @@ class CustomerController extends Controller
 
     public function resetInstantBill()
     {
+        $this->error("功能废弃");
         ini_set('max_execution_time', 2500);
         $startData = request("startDate");
         $endDate = request("endDate");

+ 48 - 20
app/Http/Controllers/TestController.php

@@ -9,12 +9,15 @@ use App\Components\ErrorPush;
 use App\ErrorTemp;
 use App\Feature;
 use App\Jobs\CacheShelfTaskJob;
+use App\Jobs\OrderCreateInstantBill;
 use App\Jobs\OrderCreateWaybill;
+use App\Jobs\StoreCreateInstantBill;
 use App\MaterialBox;
 use App\MaterialBoxModel;
 use App\Order;
 use App\Owner;
 use App\OwnerFeeDetail;
+use App\OwnerFeeDetailLogistic;
 use App\OwnerFeeExpress;
 use App\OwnerFeeLogistic;
 use App\OwnerFeeOperation;
@@ -30,6 +33,7 @@ use App\Services\StorageService;
 use App\Station;
 use App\StationTask;
 use App\StationTaskMaterialBox;
+use App\Store;
 use App\TaskTransaction;
 use App\Unit;
 use App\Waybill;
@@ -58,34 +62,58 @@ class TestController extends Controller
     {
         return call_user_func([$this, $method], $request);
     }
-    public function lightUp()
-    {
-        app("CacheShelfService")->lightUp('HAIB1-02-02','3','0');
-    }
-    public function lightOff()
-    {
-        $params = [
-            "areaCode" => "1004",
-            'locCode' => "HAIB1-02-02",
-            'PTLAction' => 0,
-        ];
-        $response = Http::post(config('api.haiq.storage.light'), $params);
-        return json_decode($response->body());
+    public function test1(){
+        ini_set('max_execution_time',-1);
+        $date = date("Y-m-d H:i:s");
+        ErrorTemp::query()->truncate();
+        OwnerFeeStorage::query()->truncate();
+        OwnerFeeExpress::query()->truncate();
+        OwnerFeeLogistic::query()->truncate();
+        OwnerFeeOperation::query()->truncate();
+        OwnerFeeOperationDetail::query()->truncate();
+        foreach (Order::query()->where("wms_edittime",">=","2021-08-16 00:00:00")
+                     ->where("wms_status","订单完成")
+                     ->where("wms_edittime","<",$date)->get() as $order){
+            $fee = OwnerFeeDetail::query()->where("outer_table_name","orders")->where("outer_id",$order->id)->first();
+            if ($fee){
+                OwnerFeeDetailLogistic::query()->where("owner_fee_detail_id",$fee->id)->delete();
+                $fee->delete();
+            }
+            $a = new Collection([$order]);
+            $this->dispatch(new OrderCreateInstantBill($a));
+        }
+        foreach (Store::query()->where("updated_at",">=","2021-08-16 00:00:00")
+                     ->where("status","已入库")
+                     ->where("updated_at","<",$date)->get() as $store){
+            OwnerFeeDetail::query()->where("outer_table_name","stores")->where("outer_id",$store->id)->delete();
+            $a = new Collection([$store]);
+            $this->dispatch(new StoreCreateInstantBill($a));
+        }
     }
 
     public function test()
     {
+        ini_set('max_execution_time',-1);
         $day = (string)\request("day");
         $d = (int)$day+1;
         $d = $d<10 ? '0'.(string)$d : (string)$d;
-        dd($day,$d);
-        OwnerFeeStorage::query()->truncate();
-        OwnerFeeExpress::query()->truncate();
-        OwnerFeeLogistic::query()->truncate();
-        OwnerFeeOperation::query()->truncate();
-        OwnerFeeOperationDetail::query()->truncate();
         foreach (Order::query()->where("wms_edittime",">=","2021-08-{$day} 00:00:00")
                      ->where("wms_status","订单完成")
-                     ->where("wms_edittime","<=",date("Y-m-d H:i:s"))->get() as $order);
+                     ->where("wms_edittime","<","2021-08-{$d} 00:00:00")->get() as $order){
+            $fee = OwnerFeeDetail::query()->where("outer_table_name","orders")->where("outer_id",$order->id)->first();
+            if ($fee){
+                OwnerFeeDetailLogistic::query()->where("owner_fee_detail_id",$fee->id)->delete();
+                $fee->delete();
+            }
+            $a = new Collection([$order]);
+            $this->dispatch(new OrderCreateInstantBill($a));
+        }
+        foreach (Store::query()->where("updated_at",">=","2021-08-{$day} 00:00:00")
+                     ->where("status","已入库")
+                     ->where("updated_at","<","2021-08-{$d} 00:00:00")->get() as $store){
+            OwnerFeeDetail::query()->where("outer_table_name","stores")->where("outer_id",$store->id)->delete();
+            $a = new Collection([$store]);
+            $this->dispatch(new StoreCreateInstantBill($a));
+        }
     }
 }

+ 5 - 4
app/Jobs/OrderCreateInstantBill.php

@@ -2,6 +2,7 @@
 
 namespace App\Jobs;
 
+use App\Components\ErrorPush;
 use App\Services\LogService;
 use App\Services\OrderService;
 use Illuminate\Bus\Queueable;
@@ -13,7 +14,7 @@ use Illuminate\Queue\InteractsWithQueue;
 
 class OrderCreateInstantBill implements ShouldQueue
 {
-    use Dispatchable, InteractsWithQueue, Queueable;
+    use Dispatchable, InteractsWithQueue, Queueable, ErrorPush;
 
 
     protected $orders;
@@ -41,14 +42,14 @@ class OrderCreateInstantBill implements ShouldQueue
             foreach ($this->orders as $order){
                 try{
                     if (!$service->createInstantBill($order))
-                        LogService::log(__METHOD__,"ERROR-订单生成即时账单",$order->toJson());
+                        $this->push(__METHOD__."->".__LINE__,"订单生成即时账单",$order->toJson());
                 }catch(QueryException $qe){
                     if ($qe->getCode()!='23000'){
-                        LogService::log(__METHOD__,"ERROR-订单生成即时账单",$order->toJson()." | ".$qe->getMessage());
+                        $this->push(__METHOD__."->".__LINE__,"订单生成即时账单",$order->toJson()." | ".$qe->getMessage());
                         $errors = ["order_".$order->id.":".$qe->getMessage()];
                     }
                 }catch (\Exception $e){
-                    LogService::log(__METHOD__,"ERROR-订单生成即时账单",$order->toJson()." | ".$e->getMessage());
+                    $this->push(__METHOD__."->".__LINE__,"订单生成即时账单",$order->toJson()." | ".$e->getMessage());
                     $errors = ["order_".$order->id.":".$e->getMessage()];
                 }
             }

+ 6 - 4
app/Jobs/StoreCreateInstantBill.php

@@ -2,6 +2,7 @@
 
 namespace App\Jobs;
 
+use App\Components\ErrorPush;
 use App\Services\LogService;
 use App\Services\StoreService;
 use Illuminate\Bus\Queueable;
@@ -13,7 +14,7 @@ use Illuminate\Queue\InteractsWithQueue;
 
 class StoreCreateInstantBill implements ShouldQueue
 {
-    use Dispatchable, InteractsWithQueue, Queueable;
+    use Dispatchable, InteractsWithQueue, Queueable, ErrorPush;
 
 
     protected $stores;
@@ -41,14 +42,15 @@ class StoreCreateInstantBill implements ShouldQueue
         $errors = [];
         foreach ($this->stores as $store){
             try{
-                $service->createInstantBill($store);
+                if (!$service->createInstantBill($store))
+                    $this->push(__METHOD__."->".__LINE__,"订单生成即时账单",$store->toJson());
             }catch(QueryException $qe){
                 if ($qe->getCode()!='23000'){
-                    LogService::log(__METHOD__,"ERROR-入库生成即时账单",$store->toJson()." | ".$qe->getMessage());
+                    $this->push(__METHOD__."->".__LINE__,"入库生成即时账单",$store->toJson()." | ".$qe->getMessage());
                     $errors = ["store_".$store->id.":".$qe->getMessage()];
                 }
             }catch (\Exception $e){
-                LogService::log(__METHOD__,"ERROR-入库生成即时账单",$store->toJson()." | ".$e->getMessage());
+                $this->push(__METHOD__."->".__LINE__,"入库生成即时账单",$store->toJson()." | ".$e->getMessage());
                 $errors = ["store_".$store->id.":".$e->getMessage()];
             }
         }

+ 29 - 32
app/Services/OrderService.php

@@ -1243,26 +1243,11 @@ sql
         //获取运输费
         $logisticInfo = $this->getLogisticFeeInfo($order);
 
-        //信息仍然不完整
-        if ($logisticInfo["logisticFee"] && $logisticInfo["fee_info"])OwnerFeeExpress::query()->insert($logisticInfo["fee_info"]);
-        //向指定表插入标记
-
         //获取作业费
         /** @var OwnerPriceOperationService $service */
         $service = app("OwnerPriceOperationService");
         $GLOBALS["FEE_INFO"] = [];
         list($id,$money,$workTaxFee) = $service->matching($order,Feature::MAPPING["order"],$order->owner_id);
-        if ($money>0)app("StoreService")->constructFeeInfo([
-            "worked_at" => $order->wms_edittime ?: $order->updated_at,
-            "owner_id" => $order->owner_id,
-            "model_id"  => $id,
-            "source_number"=> $order->client_code,
-            "doc_number"   => $order->code,
-            "commodity_id" => 0,
-            "total_fee"    =>0,
-            "tax_rate"     =>0,
-            "fee_description"=>'',
-        ]);
 
         //数据组装
         $detail = OwnerFeeDetail::query()->create([
@@ -1288,6 +1273,19 @@ sql
             "work_tax_fee"      => $workTaxFee,
             "logistic_tax_fee"  => $logisticInfo["logisticTaxFee"],
         ]);
+        //向指定表插入标记
+        if ($logisticInfo["logisticFee"] && $logisticInfo["fee_info"])OwnerFeeExpress::query()->insert($logisticInfo["fee_info"]);
+        if ($money>0)app("StoreService")->constructFeeInfo([
+            "worked_at" => $order->wms_edittime ?: $order->updated_at,
+            "owner_id" => $order->owner_id,
+            "model_id"  => $id,
+            "source_number"=> $order->client_code,
+            "doc_number"   => $order->code,
+            "commodity_id" => 0,
+            "total_fee"    =>0,
+            "tax_rate"     =>0,
+            "fee_description"=>'',
+        ]);
         //后续处理
         foreach ($logisticInfo["items"] as &$item)$item["owner_fee_detail_id"] = $detail->id;
         if (count($logisticInfo["items"])>1)OwnerFeeDetailLogistic::query()->insert($logisticInfo["items"]);
@@ -1387,15 +1385,24 @@ sql
         if (!$order->packages->count() || !$order->owner)return false;
         //获取运输费
         $logisticInfo = $this->getLogisticFeeInfo($order);
-        //向指定表插入标记
         if (!$logisticInfo["logisticFee"] || !$logisticInfo["fee_info"])return false;
-        OwnerFeeExpress::query()->insert($logisticInfo["fee_info"]);
-        foreach ($logisticInfo["items"] as &$item)$item["owner_fee_detail_id"] = $feeBill->id;
-        if (count($logisticInfo["items"])>1)OwnerFeeDetailLogistic::query()->insert($logisticInfo["items"]);
-
         //获取作业费
         $GLOBALS["FEE_INFO"] = [];
         list($id,$money,$workTaxFee) = app("OwnerPriceOperationService")->matching($order,Feature::MAPPING["order"],$order->owner_id);
+        //数据组装
+        $feeBill->update([
+            "commodity_amount"  => $logisticInfo["amount"],
+            "logistic_bill"     => $logisticInfo["logisticBill"],
+            "volume"            => $logisticInfo["volume"],
+            "weight"            => $logisticInfo["weight"],
+            "logistic_fee"      => $logisticInfo["logisticFee"],
+            "logistic_tax_fee"  => $logisticInfo["logisticTaxFee"],
+            "work_fee"          => $money,
+            "owner_price_operation_id"  => $id,
+            "work_tax_fee"      => $workTaxFee,
+        ]);
+        foreach ($logisticInfo["items"] as &$item)$item["owner_fee_detail_id"] = $feeBill->id;
+        if (count($logisticInfo["items"])>1)OwnerFeeDetailLogistic::query()->insert($logisticInfo["items"]);
         if ($money>0){
             app("StoreService")->clearFeeInfo($order->code);
             app("StoreService")->constructFeeInfo([
@@ -1410,18 +1417,8 @@ sql
                 "fee_description"=>'',
             ]);
         }
-        //数据组装
-        $feeBill->update([
-            "commodity_amount"  => $logisticInfo["amount"],
-            "logistic_bill"     => $logisticInfo["logisticBill"],
-            "volume"            => $logisticInfo["volume"],
-            "weight"            => $logisticInfo["weight"],
-            "logistic_fee"      => $logisticInfo["logisticFee"],
-            "logistic_tax_fee"  => $logisticInfo["logisticTaxFee"],
-            "work_fee"          => $money,
-            "owner_price_operation_id"  => $id,
-            "work_tax_fee"      => $workTaxFee,
-        ]);
+        //向指定表插入标记
+        OwnerFeeExpress::query()->insert($logisticInfo["fee_info"]);
         return true;
     }
 

+ 11 - 11
app/Services/StoreService.php

@@ -329,17 +329,6 @@ class StoreService
 
         $GLOBALS["FEE_INFO"] = [];
         list($id,$money,$taxFee) = $service->matching($store, Feature::MAPPING["store"], $store->owner_id, "入库");
-        if ($money>0)$this->constructFeeInfo([
-                "worked_at" => $store->updated_at,
-                "owner_id" => $store->owner_id,
-                "model_id"  => $id,
-                "source_number"=> null,
-                "doc_number"   => $store->asn_code,
-                "commodity_id" => 0,
-                "total_fee"    =>0,
-                "tax_rate"     =>0,
-                "fee_description"=>'',
-            ]);
 
         if (!app("OwnerFeeDetailService")->create([
             "owner_id" => $store->owner_id,
@@ -358,6 +347,17 @@ class StoreService
         if ($store->storeItems)foreach ($store->storeItems as $item)$amount += $item->amount;
         $this->setStoreAmount($store->owner_id,$amount);
         Cache::put("owner_fee_details:stores_".$store->id,1,86400);
+        if ($money>0)$this->constructFeeInfo([
+            "worked_at" => $store->updated_at,
+            "owner_id" => $store->owner_id,
+            "model_id"  => $id,
+            "source_number"=> null,
+            "doc_number"   => $store->asn_code,
+            "commodity_id" => 0,
+            "total_fee"    =>0,
+            "tax_rate"     =>0,
+            "fee_description"=>'',
+        ]);
         return true;
     }
 

+ 1 - 1
resources/views/finance/instantBill.blade.php

@@ -32,7 +32,7 @@
                 <a class="dropdown-item" @click="billExport(true)" href="javascript:">导出所有页</a>
             </div>
             @include("finance._resetInstantBill")
-            @can("结算管理-即时账单-重置即时账单")<button data-toggle="modal" data-target="#resetInstantBill" class="btn btn-sm btn-outline-primary">重置即时账单</button>@endcan
+            {{--@can("结算管理-即时账单-重置即时账单")<button data-toggle="modal" data-target="#resetInstantBill" class="btn btn-sm btn-outline-primary">重置即时账单</button>@endcan--}}
         </div>
         <div>
             <table class="table table-sm text-nowrap td-min-width-80" id="table">