/** * 分段更新本地用户资料. * * @param int $total * @param FanModel $fanModel * @param Account $accountId */ public function performUpdateUserDetail($total, $fanModel, $account) { $this->info("\n开始更新用户资料..."); $this->output->progressStart($total); $userService = new User($account->app_id, $account->app_secret); $fanService = new FanService(); $accountId = $account->id; $fanModel->where('account_id', $accountId)->orderBy('id', 'desc')->chunk(100, function ($fans) use($userService, $accountId, $fanModel, $fanService) { $fans = $userService->batchGet($fans->lists('openid')->toArray()); foreach ($fans as $fan) { $fan = $fanService->formatFromWeChat($fan); $fanModel->where('openid', $fan['openid'])->update($fan); $this->output->progressAdvance(); } }); $this->output->progressFinish(); $this->info("\n同步完成。"); }
/** * 更新备注并保存到本地数据库. * * @param Request $request * @param $id * * @return \Illuminate\Http\JsonResponse */ public function postEditRemark(Request $request, $id) { try { $this->fanService->edirRemark($id, $request->input('remark')); return success('修改成功!'); } catch (\Exception $e) { return error('修改失败!' . $e->getMessage()); } }
/** * Execute the console command. * * @return mixed */ public function handle() { $accountId = $this->argument('account_id'); $openId = $this->argument('openid'); /* * 1 获取Account */ $account = $this->getAccount($accountId); $fanModel = new FanModel(); $FanService = new FanService(); /* * 2 初始化 SDK Config, 构建 SDK 对象 */ $userService = new User($account->app_id, $account->app_secret); $fan = $userService->get($openId); if (isset($fan['subscribe']) && $fan['subscribe']) { //subscribe=1 关注了公众号 $updateInput = $FanService->formatFromWeChat($fan); /* * 存入本地 */ $fanModel->where('account_id', $accountId)->where('openid', $openId)->update($updateInput); } }