master
cody 4 weeks ago
parent cd2140e96d
commit fb49707d54

@ -43,7 +43,7 @@ class UpdateCompany extends Command
public function handle()
{
$user_id = $this->option('user_id');
$updateLocal = (int)$this->option('address');
$updateLocal = (int) $this->option('address');
// 更新公司信息
$this->compnay($user_id);
// 更新经纬度信息(可选)
@ -65,17 +65,29 @@ class UpdateCompany extends Command
// 批量更新
$users = User::whereNotNull('company_name')->get();
}
$total = $users->count();
if ($total == 0) {
return $this->info('没有需要更新的用户');
}
$this->info("开始更新公司信息,共 {$total} 个用户");
$bar = $this->output->createProgressBar($total);
$bar->start();
$YuanheRepository = new YuanheRepository();
foreach ($users as $user) {
// 获取公司详细信息
$result = $YuanheRepository->companyInfo(['enterpriseName' => $user->company_name]);
if (!$result) {
$this->info($user->company_name . '公司不存在');
$bar->setMessage($user->company_name . ' 公司不存在', 'status');
$bar->advance();
continue;
}
// 如果$result['enterpriseName']存在数字,跳过
if (preg_match('/\d/', $result['enterpriseName'])) {
$this->info($user->company_name . '公司名称包含数字,跳过');
$bar->setMessage($user->company_name . ' 公司名称包含数字,跳过', 'status');
$bar->advance();
continue;
}
$where = ['company_name' => $result['enterpriseName']];
@ -106,7 +118,7 @@ class UpdateCompany extends Command
'stock_type' => $result['stockType'],
'company_tag' => implode(',', $result['tagList']),
// 更新日期
'update_date' => $result['updatedDate']??null,
'update_date' => $result['updatedDate'] ?? null,
// 管理平台
'project_users' => $result['projectUsers'] ?? null,
];
@ -114,8 +126,12 @@ class UpdateCompany extends Command
// 更新用户关联
$user->company_id = $company->id;
$user->save();
$this->info($result['enterpriseName'] . '-更新成功');
$bar->setMessage($result['enterpriseName'] . ' 更新成功', 'status');
$bar->advance();
}
$bar->finish();
$this->newLine();
return $this->info('公司信息-全部更新完成');
}
@ -128,7 +144,7 @@ class UpdateCompany extends Command
// 强制单个更新
$user = User::find($user_id);
if (empty($user->company_id)) {
return false;
return $this->error('用户没有关联公司');
}
$companys = Company::where('id', $user->company_id)->get();
} else {
@ -138,19 +154,33 @@ class UpdateCompany extends Command
->where('company_address', '!=', '')
->get();
}
$total = $companys->count();
if ($total == 0) {
return $this->info('没有需要更新经纬度的公司');
}
$this->info("开始更新经纬度信息,共 {$total} 个公司");
$bar = $this->output->createProgressBar($total);
$bar->start();
// 每3个数据分一个chunk 。接口限制了一秒只能3次请求
$companys = $companys->chunk(3);
foreach ($companys as $company) {
foreach ($company as $item) {
$companysChunk = $companys->chunk(3);
foreach ($companysChunk as $companyChunk) {
foreach ($companyChunk as $item) {
$local = Company::addressTolocation($item->company_address);
$item->company_longitude = $local['lng'];
$item->company_latitude = $local['lat'];
$item->save();
$this->info($item->company_name . "-{$local['lng']}-{$local['lat']}-经纬度信息更新成功");
$bar->setMessage($item->company_name . " 经纬度({$local['lng']}, {$local['lat']})更新成功", 'status');
$bar->advance();
}
sleep(1);
}
return true;
$bar->finish();
$this->newLine();
return $this->info('经纬度信息-全部更新完成');
}
}

Loading…
Cancel
Save