Просмотр исходного кода

即时账单部分BUG,优化缓存

Zhouzhendong 5 лет назад
Родитель
Сommit
f701c44194

+ 0 - 9
app/Http/Controllers/RejectedBillController.php

@@ -2,21 +2,14 @@
 
 namespace App\Http\Controllers;
 
-use App\Events\InformWMSReceivedEvent;
 use App\Http\Controllers\api\thirdPart\flux\ReceiveController;
 use App\Logistic;
 use App\OracleActAllocationDetails;
 use App\OracleBasSKU;
-use App\OracleDOCOrderHeader;
-use App\Order;
 use App\Owner;
 use App\QualityLabel;
-use App\Rejected;
 use App\RejectedBill;
-use App\RejectedBillItem;
 use App\Services\LogService;
-use App\Services\OrderPackageCommoditiesService;
-use App\Services\OrderService;
 use App\Services\RejectedBillItemService;
 use App\Services\RejectedBillService;
 use Illuminate\Contracts\View\Factory;
@@ -26,10 +19,8 @@ use Illuminate\Http\Response;
 use Illuminate\Routing\Redirector;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Gate;
-use Illuminate\Support\Facades\Session;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\View\View;
-use Ramsey\Uuid\Uuid;
 
 class RejectedBillController extends Controller
 {

+ 7 - 16
app/Http/Controllers/TestController.php

@@ -50,22 +50,13 @@ use App\OracleBasSKU;
 use App\OracleDOCASNHeader;
 use App\OracleDOCOrderDetail;
 use App\OracleDOCOrderHeader;
-use App\OracleDocOrderPackingSummary;
-use App\OracleDOCWaveDetails;
-use App\OracleDOCWaveHeader;
-use App\OracleInvLotLocId;
 use App\Order;
 use App\OrderBin;
 use App\OrderCommodity;
-use App\OrderCommodityAssign;
 use App\OrderIssue;
 use App\OrderPackage;
-use App\OrderPackageCommodities;
-use App\OrderPackageCountingRecord;
-use App\OrderTracking;
 use App\Owner;
 use App\OwnerAreaReport;
-use App\OwnerBillReport;
 use App\OwnerFeeDetail;
 use App\OwnerFeeDetailLogistic;
 use App\OwnerMaterial;
@@ -183,16 +174,16 @@ class TestController extends Controller
     public function restoreResetInstantBill()
     {
         ini_set('max_execution_time', 2500);
-        foreach (OwnerFeeDetail::query()->whereBetween("worked_at",["2021-04-01 00:00:00","2021-04-25 00:00:00"])->cursor() as $detail){
+        foreach (OwnerFeeDetail::query()->whereBetween("worked_at",["2021-04-01 00:00:00","2021-04-26 00:00:00"])->cursor() as $detail){
             dispatch(new ResetInstantBill($detail));
         }
     }
     public function restoreResetInstantBillOrder()
     {
         ini_set('max_execution_time', 2500);
-        $orders = Order::query()->where("wms_status","订单完成")->whereBetween("updated_at",["2021-04-01 00:00:00","2021-04-25 00:00:00"])
+        $orders = Order::query()->where("wms_status","订单完成")->whereBetween("updated_at",["2021-04-01 00:00:00","2021-04-26 00:00:00"])
             ->whereNotIn("id",OwnerFeeDetail::query()->select("outer_id")->where("outer_table_name","orders")
-                ->whereBetween("worked_at",["2021-04-01 00:00:00","2021-04-25 00:00:00"]))->get();
+                ->whereBetween("worked_at",["2021-04-01 00:00:00","2021-04-26 00:00:00"]))->get();
         foreach ($orders->chunk(50) as $or){
             dispatch(new OrderCreateInstantBill($or));
         }
@@ -200,11 +191,11 @@ class TestController extends Controller
     public function restoreResetInstantBillStore()
     {
         ini_set('max_execution_time', 2500);
-        $stores = Store::query()->where("status","已入库")->whereBetween("updated_at",["2021-04-01 00:00:00","2021-04-25 00:00:00"])
+        $stores = Store::query()->where("status","已入库")->whereBetween("updated_at",["2021-04-01 00:00:00","2021-04-26 00:00:00"])
             ->whereNotIn("id",OwnerFeeDetail::query()->select("outer_id")->where("outer_table_name","stores")
-                ->whereBetween("worked_at",["2021-04-01 00:00:00","2021-04-25 00:00:00"]))->get();
-        foreach ($stores as $store){
-            dispatch(new StoreCreateInstantBill($store));
+                ->whereBetween("worked_at",["2021-04-01 00:00:00","2021-04-26 00:00:00"]))->get();
+        foreach ($stores->chunk(50) as $st){
+            dispatch(new OrderCreateInstantBill($st));
         }
     }
     public function supplementMarchOwnerReport()

+ 0 - 2
app/Http/Controllers/api/thirdPart/flux/WaybillController.php

@@ -2,10 +2,8 @@
 
 namespace App\Http\Controllers\api\thirdPart\flux;
 
-use App\City;
 use App\Http\Controllers\Controller;
 use App\Jobs\HandleExceptionWaybill;
-use App\Order;
 use App\Owner;
 use App\Services\RegionService;
 use App\Unit;

+ 2 - 4
app/Jobs/OrderCreateInstantBill.php

@@ -2,7 +2,6 @@
 
 namespace App\Jobs;
 
-use App\Order;
 use App\Services\LogService;
 use App\Services\OrderService;
 use Illuminate\Bus\Queueable;
@@ -10,7 +9,6 @@ use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
-use Illuminate\Queue\SerializesModels;
 
 class OrderCreateInstantBill implements ShouldQueue
 {
@@ -41,9 +39,9 @@ class OrderCreateInstantBill implements ShouldQueue
             foreach ($this->orders as $order){
                 try{
                     if (!$service->createInstantBill($order))
-                        LogService::log(__METHOD__,"ERROR-订单生成即时账单",$this->order->toJson());
+                        LogService::log(__METHOD__,"ERROR-订单生成即时账单",$order->toJson());
                 }catch (\Exception $e){
-                    LogService::log(__METHOD__,"ERROR-订单生成即时账单",$this->order->toJson()." | ".$e->getMessage());
+                    LogService::log(__METHOD__,"ERROR-订单生成即时账单",$order->toJson()." | ".$e->getMessage());
                     throw new \Exception($e->getMessage());
                 }
             }

+ 1 - 1
app/Jobs/ResetInstantBill.php

@@ -65,7 +65,7 @@ class ResetInstantBill implements ShouldQueue
                 if (!$order->logistic || $order->logistic->type == "物流")$logistic_fee = null;
 
                 $items = [];
-                $isBunched = $order->logistic->is_bunched=='Y';
+                $isBunched = $order->logistic && $order->logistic->is_bunched=='Y';
                 $weightExceptionMark = false;
                 $provinceId = null;
                 $logisticTaxFee = 0;

+ 13 - 10
app/Jobs/StoreCreateInstantBill.php

@@ -7,25 +7,26 @@ use App\Services\StoreService;
 use App\Store;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Queue\SerializesModels;
 
 class StoreCreateInstantBill implements ShouldQueue
 {
-    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+    use Dispatchable, InteractsWithQueue, Queueable;
 
 
-    protected $store;
+    protected $stores;
     /**
      * Create a new job instance.
      *
-     * @param Store $store
+     * @param Collection $stores
      * @return void
      */
-    public function __construct(Store $store)
+    public function __construct($stores)
     {
-        $this->store = $store;
+        $this->stores = $stores;
     }
 
     /**
@@ -37,11 +38,13 @@ class StoreCreateInstantBill implements ShouldQueue
      */
     public function handle(StoreService $service)
     {
-        try{
-            $service->createInstantBill($this->store);
-        }catch (\Exception $e){
-            LogService::log(__METHOD__,"ERROR-入库生成即时账单",$this->store->toJson()." | ".$e->getMessage());
-            throw new \Exception($e->getMessage());
+        foreach ($this->stores as $store){
+            try{
+                $service->createInstantBill($store);
+            }catch (\Exception $e){
+                LogService::log(__METHOD__,"ERROR-入库生成即时账单",$store->toJson()." | ".$e->getMessage());
+                throw new \Exception($e->getMessage());
+            }
         }
     }
 }

+ 2 - 3
app/Services/OrderService.php

@@ -1089,8 +1089,7 @@ sql
         /** @var \stdClass $order */
         //检查订单对象
         if (!$order || $order->wms_status != "订单完成")return true;
-        if (Cache::has("owner_fee_details_orders_".$order->id))return true;
-        if (OwnerFeeDetail::query()->where("outer_table_name","orders")->where("outer_id",$order->id)->first())return true;
+        if (Cache::has("owner_fee_details:orders_".$order->id))return true;
 
         $order->loadMissing(["logistic","shop","packages.commodities.commodity","batch"]);
 
@@ -1181,7 +1180,7 @@ sql
             foreach ($items as &$item)$item["owner_fee_detail_id"] = $detail->id;
             if (count($items)>1)OwnerFeeDetailLogistic::query()->insert($items);
             $this->setOrderQuantity($order->owner_id,$order->logistic_id);
-            Cache::put("owner_fee_details_orders_".$order->id,1,86400);
+            Cache::put("owner_fee_details:orders_".$order->id,1,86400);
             return true;
        }
        return false;

+ 3 - 4
app/Services/StoreService.php

@@ -245,9 +245,7 @@ class StoreService
 
     public function pushJob($asnHerders){
         $stores = Store::query()->with(["storeItems"])->where('status','已入库')->whereIn('asn_code', data_get($asnHerders,'*.asnno'))->get();
-        $stores->each(function($store){
-            dispatch(new StoreCreateInstantBill($store));
-        });
+        dispatch(new StoreCreateInstantBill($stores));
     }
 
     public function insert($params)
@@ -322,7 +320,7 @@ class StoreService
     {
         /** @var \stdClass $store */
         if (!$store || $store->status != "已入库") return false;
-        if (OwnerFeeDetail::query()->where("outer_table_name","stores")->where("outer_id",$store->id)->first())return false;
+        if (Cache::has("owner_fee_details:stores_".$store->id))return true;
         $store->loadMissing(["storeItems","warehouse"]);
 
         /** @var OwnerPriceOperationService $service */
@@ -346,6 +344,7 @@ class StoreService
             $amount = 0;
             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);
             return true;
         }
         return false;