protected function pushEmails($count) { $qqUsers = CrawQqUser::whereIn('status', [0, 3])->take($count)->get(); $mails = []; foreach ($qqUsers as $user) { $user->status = 1; $user->save(); $email = $user->qq . '@qq.com'; $mails[] = $email; } if (empty($mails)) { return; } $this->info('Push to: ' . implode("\t", $mails)); SendCloud::sendTemplate('ruogu_invite_to_register', [], function (SendCloudMessage $message) use($mails) { $message->to($mails)->subject('若古社区诚邀您入驻'); })->success(function ($response) use($qqUsers) { foreach ($qqUsers as $user) { $user->status = 2; $user->count++; $user->save(); } })->failure(function ($response, $error) use($qqUsers) { foreach ($qqUsers as $user) { $user->status = 3; $user->save(); } $this->error($error->message); }); }
/** * Execute the console command. * * @return mixed */ public function handle() { $clear = $this->option('clear'); $response = $this->api->bounces('2015-09-01', Carbon::now()->toDateString(), 200); if (property_exists($response, 'message') && property_exists($response, 'bounces') && $response->message === 'success') { $bounces = $response->bounces; foreach ($bounces as $bounce) { $qq = explode('@', $bounce->email)[0]; $user = CrawQqUser::where('qq', $qq)->first(); $this->info('Email: ' . $bounce->email); if (!is_null($user)) { $this->info('找到无效用户并删除:' . $qq); $user->delete(); } // 如果 --clear 则清除远程记录 if ($clear) { $this->api->deleteBounce($bounce->email); $this->info('清除无效用户:' . $bounce->email); } } } }
function saveUser($uin, $gid, $qq, $name) { return QQUser::create(compact('uin', 'gid', 'qq', 'name')); }