disableQueryLog(); $this->time = $this->argument('time_line') ? $this->argument('time_line') : date('Y-m-d', strtotime('-1 days')); $this->info(date('m-d H:i:s') . ' 开始整理'); $this->getData($this->time); } public function getData($date) { try { $page = 1; do { // 获取公众号信息 $accountList = Account::accountList(ZZYService::PLATFORM_ID, $page, $this->limit); $count = count($accountList); $this->info(date('m-d H:i:s') . ' 此次共有' . $count . '个账号待处理'); $this->info(date('m-d H:i:s') . ' 页码数' . $page . '页'); $insertData = []; foreach ($accountList as $item) { // 判断是否存在 $isSave = FansData::where('app_id', $item->app_id)->where('ref_date', $date)->exists(); if (!$isSave) { // 获取数据 $data = FansDataService::fansDataCube( $item->app_id, $date, $date, $item->channel_id ); if (empty($data) || !isset($data[0]) || empty($data[0])) { Log::logError('微信未返回粉丝数据,时间:' . $date . ',公众号Id:' . $item->app_id, (array)$data, 'FansDataCube'); continue; } array_push($insertData, $data[0]); $this->info(date('m-d H:i:s') . $item->app_id . ' 的粉丝数据获取完毕'); } } // 存储数据 if (!empty($insertData)) { $result = FansData::insert($insertData); if (!$result) { Log::logError('粉丝数据写入失败', $insertData, 'FansDataCube'); } } $page++; # 返回此次同步数量 $this->info(date('H:i:s') . ' 已同步 ' . $count . ' 条粉丝信息,占用内存' . round(memory_get_usage() / 1024 / 1024) . 'M'); } while ($count == $this->limit); } catch (\Exception $e) { Log::logError('粉丝数据获取失败'.$e->getMessage(), [], 'AccountData'); } } }