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

增加当天订单时间缓存

ANG YU 5 лет назад
Родитель
Сommit
af3ba46a3f

+ 2 - 2
app/Services/OrderCountingRecordService.php

@@ -50,7 +50,7 @@ class OrderCountingRecordService
     public function orderCountingRecords($start, $end, $ownerIds = null, $unit = '日', $user = null)
     {
         $key = 'orderCountingRecords_' . $start . '_' . $end . '_' . $unit . '_' . Auth::user()->id;
-        return Cache::remember($key, 1, function () use ($start, $end, $unit, $ownerIds, $user) {
+        return Cache::remember($key, 120, function () use ($start, $end, $unit, $ownerIds, $user) {
             $orders = $this->get($start, $end, null, $unit, null);
             $dataList = collect();
             $orders->groupBy('date_target')->each(function ($items) use (&$dataList, $unit) {
@@ -191,7 +191,7 @@ class OrderCountingRecordService
                 $key = "order_counting_records_{$dateStr}_{$owner_id}_{$unit}";
                 $ttl = 3600 * 24;
                 if ($dateStr == Carbon::now()->toDateString()) {
-                    $ttl = 1;
+                    $ttl = 60;
                 }
                 Cache::put($key, $item, $ttl);
             });

+ 1 - 1
tests/Services/OrderCountingRecordService/OrderCountingRecordServiceGetTest.php

@@ -35,7 +35,7 @@ class OrderCountingRecordServiceGetTest extends TestCase
         $start = Carbon::now()->subDays(2)->format('Y-m-d');
         $end = (new Carbon())->toDateString();
 
-        $this->actingAs(factory(User::class)->create(['name' => 'yang']));
+        $this->actingAs($user = factory(User::class)->create(['name' => 'yang']));
 
         $owner = factory(Owner::class)->create();
         $orders = factory(Order::class)->times(20)->create([