*
Showing
1 changed file
with
24 additions
and
1 deletions
... | @@ -4,6 +4,7 @@ namespace App\Console\Commands; | ... | @@ -4,6 +4,7 @@ namespace App\Console\Commands; |
4 | 4 | ||
5 | use App\Helper\RedisClient; | 5 | use App\Helper\RedisClient; |
6 | use App\Models\Legal\Company; | 6 | use App\Models\Legal\Company; |
7 | use App\Models\Legal\Song; | ||
7 | use App\Models\Legal\SongsIp; | 8 | use App\Models\Legal\SongsIp; |
8 | use Illuminate\Console\Command; | 9 | use Illuminate\Console\Command; |
9 | use Illuminate\Support\Facades\Redis; | 10 | use Illuminate\Support\Facades\Redis; |
... | @@ -49,6 +50,29 @@ class DealSongIp extends Command | ... | @@ -49,6 +50,29 @@ class DealSongIp extends Command |
49 | $company_ids = Company::query()->pluck('company_id')->toArray(); | 50 | $company_ids = Company::query()->pluck('company_id')->toArray(); |
50 | 51 | ||
51 | foreach ($company_ids as $company_id) { | 52 | foreach ($company_ids as $company_id) { |
53 | |||
54 | SongsIp::query()->select(['id', 'song_id', 'custom_id'])->chunk(5000, function ($res) { | ||
55 | |||
56 | $res = $res->toArray(); | ||
57 | $custom_ids = array_column($res, 'custom_id'); | ||
58 | |||
59 | if (!empty($custom_ids)) { | ||
60 | $songs = Song::query()->whereIn('custom_id', $custom_ids)->select([])->get()->keyBy('custom_id')->toArray(); | ||
61 | |||
62 | foreach ($res as $item) { | ||
63 | if (isset($songs[$item['custom_id']])) { | ||
64 | SongsIp::query()->where(['id'=>$item['id']])->update(['song_id'=>$item['id']]); | ||
65 | } else { | ||
66 | SongsIp::query()->where(['id'=>$item['id']])->update(['song_id'=>0]); | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | }); | ||
71 | } | ||
72 | |||
73 | |||
74 | //2.修复缓存 | ||
75 | foreach ($company_ids as $company_id) { | ||
52 | $key1 = "company:#company_id#:channel:#channel#:month:#month#:songip"; | 76 | $key1 = "company:#company_id#:channel:#channel#:month:#month#:songip"; |
53 | $key2 = "company:#company_id#:channel:#channel#:songip"; | 77 | $key2 = "company:#company_id#:channel:#channel#:songip"; |
54 | 78 | ||
... | @@ -59,7 +83,6 @@ class DealSongIp extends Command | ... | @@ -59,7 +83,6 @@ class DealSongIp extends Command |
59 | $redis->del($key2); | 83 | $redis->del($key2); |
60 | } | 84 | } |
61 | 85 | ||
62 | |||
63 | SongsIp::query()->chunk(5000, function ($res) use ($redis) { | 86 | SongsIp::query()->chunk(5000, function ($res) use ($redis) { |
64 | foreach ($res as $item) { | 87 | foreach ($res as $item) { |
65 | $key = "company:#company_id#:channel:#channel#:songip"; | 88 | $key = "company:#company_id#:channel:#channel#:songip"; | ... | ... |
-
Please register or sign in to post a comment