Zhouzhendong 4 tahun lalu
induk
melakukan
58c5576df1
2 mengubah file dengan 21 tambahan dan 14 penghapusan
  1. 16 12
      app/Http/Controllers/TestController.php
  2. 5 2
      app/Services/StoreService.php

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

@@ -179,22 +179,26 @@ class TestController extends Controller
     }
     public function test()
     {
-        $startData = "2021-05-01";
-        $endDate = "2021-05-12";
-        $stores = Store::query()->where("status","已入库")->whereBetween("updated_at",["{$startData} 00:00:00","{$endDate} 23:59:59"])
-            ->whereNotIn("id",OwnerFeeDetail::query()->select("outer_id")->where("outer_table_name","stores")
-                ->whereBetween("worked_at",["{$startData} 00:00:00","{$endDate} 23:59:59"]))->get();
-        foreach ($stores->chunk(50) as $st){
-            dispatch(new StoreCreateInstantBill($st));
-        }
-        dd("OK");
-        $order = Order::query()->where("code","SO210511005663")->first();
+       $owners = Owner::query()->get();
+       foreach ($owners as $owner){
+           if (Cache::has(date("Y-m")."|A|".$owner->id)){
+               $query = DB::raw(<<<sql
+SELECT sum(amount) total FROM `store_items` LEFT JOIN stores ON store_items.store_id=stores.id WHERE stores.owner_id = ? AND (stores.status='已入库' OR stores.status='ASN关闭') AND store_items.updated_at LIKE ?
+sql
+               );
+               $statistics = DB::selectOne($query,[$owner->id,date("Y-m")."%"]);
+               Cache::put(date("Y-m")."|A|".$owner->id,$statistics->total ? $statistics->total : 0,2764800);
+           }
+       }
+       dd("OK");
+        /*$order = Order::query()->where("code","SO210511005663")->first();
         $ser = new OrderService();
         $ser->createInstantBill($order);
-        dd();
-        $store = Store::query()->find(171502);
+        dd();*/
+        $store = Store::query()->find(173382);dd($store->load("storeItems.commodity"));
         $ser = new StoreService();
         $ser->createInstantBill($store);
+        dd($store);
     }
     public function supplementMarchOwnerReport()
     {

+ 5 - 2
app/Services/StoreService.php

@@ -383,9 +383,12 @@ class StoreService
      */
     private function storeAmountCompensationLogic($owner)
     {
-        $query = DB::raw("SELECT sum(amount) total FROM `store_items` WHERE created_at LIKE ?");
+        $query = DB::raw(<<<sql
+SELECT sum(amount) total FROM `store_items` LEFT JOIN stores ON store_items.store_id=stores.id WHERE stores.owner_id = ? AND (stores.status='已入库' OR stores.status='ASN关闭') AND store_items.updated_at LIKE ?
+sql
+        );
         $statistics = DB::selectOne($query,[$owner,date("Y-m")."%"]);
-        Cache::put(date("Y-m")."|A|".$owner,$statistics->total,2764800);
+        Cache::put(date("Y-m")."|A|".$owner,$statistics->total ? $statistics->total : 0,2764800);
     }
 
     /**