Skip to content

Commit bd55039

Browse files
committed
修复控制器获取 app_id 失败
修复导入用户只获取到前100个的问题
1 parent 508e082 commit bd55039

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/Http/Controllers/Admin/BaseController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ public function index(Content $content)
2424

2525
if ($appId = request('app_id')) {
2626
Cache::forever(config('admin.extensions.wechat.admin_current_key', 'wechat.admin.current'), $appId);
27-
28-
$this->appId = $appId;
2927
}
3028

3129
$current = ConfigService::getCurrent();
@@ -37,6 +35,7 @@ public function index(Content $content)
3735
}
3836

3937
$this->config = $current;
38+
$this->appId = $current->app_id;
4039

4140
Admin::navbar(function (\Encore\Admin\Widgets\Navbar $navbar) use ($current) {
4241
$configs = WechatConfig::query()->get(['app_id', 'name']);

src/Jobs/ImportUsers.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,25 @@ public function handle()
4949
return;
5050
}
5151

52-
$result = $app->user->select($list['data']['openid']);
52+
$chunk = array_chunk($list['data']['openid'], 100);
5353

54-
foreach ($result['user_info_list'] as $user) {
55-
config('admin.extensions.wechat.wechat_user', WechatUser::class)::query()->updateOrCreate([
56-
'app_id' => $this->appId,
57-
'openid' => $user['openid'],
58-
], [
59-
'nickname' => $user['nickname'] ?? null,
60-
'avatar' => $user['headimgurl'] ?? null,
61-
'gender' => $user['sex'] ?? null,
62-
'country' => $user['country'] ?? null,
63-
'province' => $user['province'] ?? null,
64-
'city' => $user['city'] ?? null,
65-
'subscribed_at' => $user['subscribe'] ? Carbon::parse($user['subscribe_time'])->toDateTimeString() : null,
66-
]);
54+
foreach ($chunk as $openids) {
55+
$result = $app->user->select($openids);
56+
57+
foreach ($result['user_info_list'] as $user) {
58+
config('admin.extensions.wechat.wechat_user', WechatUser::class)::query()->updateOrCreate([
59+
'app_id' => $this->appId,
60+
'openid' => $user['openid'],
61+
], [
62+
'nickname' => $user['nickname'] ?? null,
63+
'avatar' => $user['headimgurl'] ?? null,
64+
'gender' => $user['sex'] ?? null,
65+
'country' => $user['country'] ?? null,
66+
'province' => $user['province'] ?? null,
67+
'city' => $user['city'] ?? null,
68+
'subscribed_at' => $user['subscribe'] ? Carbon::parse($user['subscribe_time'])->toDateTimeString() : null,
69+
]);
70+
}
6771
}
6872
}
6973
}

0 commit comments

Comments
 (0)