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

Merge branch 'yang' of ssh://was.baoshi56.com:10022/var/git/bswas

 Conflicts:
	yarn.lock
LD 5 лет назад
Родитель
Сommit
fb2bcdb13d

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

@@ -1512,4 +1512,20 @@ TEXT;
         $logistic_number = $request->logistic_number;
         \App\Jobs\LogisticZopSync::dispatchNow($logistic_number);
     }
+
+    public function laborReportsCountingRecordsCacheClear()
+    {
+        $dayClears = now()->subYear()->daysUntil(now());
+        $monthClears = now()->subYear()->monthsUntil(now());
+        foreach ($dayClears as $day) {
+            $key = 'laborReportsCountingRecords_' . $day->toDateString() . '_日';
+            Cache::forget($key);
+        }
+        foreach ($monthClears as $month) {
+            $key = 'laborReportsCountingRecords_' . $month->format('Y-m') . '_月';
+            Cache::forget($key);
+        }
+        Cache::forget('laborReportsCountingRecords_2020_年');
+        Cache::forget('laborReportsCountingRecords_2021_年');
+    }
 }

+ 11 - 9
app/Services/LaborReportsCountingRecordService.php

@@ -6,25 +6,27 @@ namespace App\Services;
 
 use App\LaborReport;
 use Carbon\Carbon;
-use DateTime;
-use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Str;
-use Ramsey\Uuid\Type\Integer;
 use App\Traits\ServiceAppAop;
 
 
 class LaborReportsCountingRecordService
 {
     use ServiceAppAop;
-    protected $modelClass=LaborReportsCountingRecord::class;
+
+    private $ttl;
+
     public function __construct(LaborReport $laborReport)
     {
+        $this->ttl = config('cache.expirations.commonFrequent');
         $laborReport::$withoutAppends = false;
     }
+
     public function userGroupsCount($start, $end)
     {
-        $resultByCache = Cache::remember('userGroupsCount_' . $start . '_' . $end, 600, function () use ($start, $end) {
+
+        $resultByCache = Cache::remember('userGroupsCount_' . $start . '_' . $end, $this->ttl, function () use ($start, $end) {
             return LaborReport::query()->selectRaw('user_workgroup_id,count(user_workgroup_id) amount')
                 ->with('userWorkgroup', 'laborReportStatus')
                 ->whereDate('created_at', '>=', $start)
@@ -103,7 +105,7 @@ class LaborReportsCountingRecordService
                 break;
             case '年';
                 foreach (Carbon::parse($start)->yearsUntil($end, 1)->toArray() as $item) {
-                    $dataArray[] = $item->year.'';
+                    $dataArray[] = $item->year . '';
                 }
                 break;
             default:
@@ -127,7 +129,7 @@ class LaborReportsCountingRecordService
                 $dataList->each(function ($item) use ($unit) {
                     $date = $item->date_target;
                     $key = 'laborReportsCountingRecords_' . $date . '_' . $unit;
-                    Cache::put($key, $item);
+                    Cache::put($key, $item, $this->ttl);
                 });
                 break;
             case '月':
@@ -143,7 +145,7 @@ class LaborReportsCountingRecordService
                 $dataList->each(function ($item) use ($unit) {
                     $date = $item->date_target;
                     $key = 'laborReportsCountingRecords_' . $date . '_' . $unit;
-                    Cache::put($key, $item);
+                    Cache::put($key, $item, $this->ttl);
                 });
                 break;
             case '年':
@@ -158,7 +160,7 @@ class LaborReportsCountingRecordService
                 $dataList->each(function ($item) use ($unit) {
                     $date = $item->date_target;
                     $key = 'laborReportsCountingRecords_' . $date . '_' . $unit;
-                    Cache::put($key, $item);
+                    Cache::put($key, $item, $this->ttl);
                 });
                 break;
             default:

+ 1 - 1
app/Services/LogisticZopService.php

@@ -30,7 +30,7 @@ class LogisticZopService implements LogisticRouteInterface
 
     public function format($nativeResponse)
     {
-        if (is_null($nativeResponse)||isEmpty($nativeResponse->result)) {//返回的结果为空,或者路由为[] 直接返回就好
+        if (is_null($nativeResponse)||empty($nativeResponse->result)) {//返回的结果为空,或者路由为[] 直接返回就好
             return [];
         }
         $nativeRoutes = $nativeResponse->result;

+ 1 - 1
tests/Feature/LogisticZopSyncTest.php

@@ -39,7 +39,7 @@ class LogisticZopSyncTest extends TestCase
 
     public function test_get()
     {
-        LogisticZopSync::dispatch('75600256515921');
+        LogisticZopSync::dispatch('75600296655116');
     }