Browse Source

fix superball_daily locked

laowu 1 ngày trước cách đây
mục cha
commit
475b728f36

+ 1 - 0
app/Http/Controllers/Admin/SuperballController.php

@@ -24,6 +24,7 @@ class SuperballController extends BaseController
     {
         // 不需要日期筛选,直接按日期倒序分页
         $list = DB::table(TableName::agent() . 'superball_daily')
+            ->lock('with(nolock)')
             ->orderBy('pool_date', 'desc')
             ->paginate(30);
 

+ 3 - 3
app/Services/SuperballActivityService.php

@@ -322,11 +322,11 @@ class SuperballActivityService
                 ]);
             }
 
-            // 若用户选择的号码等于当日 lucky_number,则把 superball_daily.lucky_count 累加
+            // 若用户选择的号码等于当日 lucky_number,则把 superball_daily.lucky_count 累加(使用原子自增,避免锁住整行)
             $daily = DB::connection('write')
                 ->table(TableName::agent() . 'superball_daily')
+                ->lock('with(nolock)')
                 ->where('pool_date', $today)
-                ->lockForUpdate()
                 ->first();
 
             if ($daily) {
@@ -342,7 +342,7 @@ class SuperballActivityService
                         ->table(TableName::agent() . 'superball_daily')
                         ->where('pool_date', $today)
                         ->update([
-                            'lucky_count' => (int) $daily->lucky_count + $matched,
+                            'lucky_count' => DB::raw("lucky_count + {$matched}"),
                             'updated_at' => now()->format('Y-m-d H:i:s'),
                         ]);
                 }