|
|
|
@ -43,13 +43,28 @@ class UpdateCompany extends Command
|
|
|
|
public function handle()
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$user_id = $this->option('user_id');
|
|
|
|
$user_id = $this->option('user_id');
|
|
|
|
$users = User::where(function ($query) use ($user_id) {
|
|
|
|
// 更新公司信息
|
|
|
|
if ($user_id) {
|
|
|
|
$this->compnay($user_id);
|
|
|
|
$query->where('id', $user_id);
|
|
|
|
// 更新经纬度信息
|
|
|
|
}
|
|
|
|
$this->local($user_id);
|
|
|
|
})->get();
|
|
|
|
return $this->info('全部更新完成');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 更新公司信息
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function compnay($user_id = null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if ($user_id) {
|
|
|
|
|
|
|
|
// 强制单个更新
|
|
|
|
|
|
|
|
$users = User::where('id', $user_id)->get();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 批量更新
|
|
|
|
|
|
|
|
$users = User::whereDoesntHave('company')->get();
|
|
|
|
|
|
|
|
}
|
|
|
|
$YuanheRepository = new YuanheRepository();
|
|
|
|
$YuanheRepository = new YuanheRepository();
|
|
|
|
foreach ($users as $user) {
|
|
|
|
foreach ($users as $user) {
|
|
|
|
|
|
|
|
// 获取公司详细信息
|
|
|
|
$result = $YuanheRepository->companyInfo(['enterpriseName' => $user->company_name]);
|
|
|
|
$result = $YuanheRepository->companyInfo(['enterpriseName' => $user->company_name]);
|
|
|
|
if (!$result) {
|
|
|
|
if (!$result) {
|
|
|
|
$this->info($user->company_name . '公司不存在');
|
|
|
|
$this->info($user->company_name . '公司不存在');
|
|
|
|
@ -89,8 +104,41 @@ class UpdateCompany extends Command
|
|
|
|
$user->save();
|
|
|
|
$user->save();
|
|
|
|
$this->info($result['enterpriseName'] . '-更新成功');
|
|
|
|
$this->info($result['enterpriseName'] . '-更新成功');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->info('全部更新完成');
|
|
|
|
return $this->info('公司信息-全部更新完成');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 更新经纬度信息
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function local($user_id = null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if ($user_id) {
|
|
|
|
|
|
|
|
// 强制单个更新
|
|
|
|
|
|
|
|
$user = User::find($user_id);
|
|
|
|
|
|
|
|
if (empty($user->company_id)) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$companys = Company::where('id', $user->company_id)->get();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 批量更新
|
|
|
|
|
|
|
|
$companys = Company::whereNull('company_longitude')
|
|
|
|
|
|
|
|
->whereNotNUll('company_address')
|
|
|
|
|
|
|
|
->where('company_address', '!=', '')
|
|
|
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 每3个数据分一个chunk 。接口限制了一秒只能3次请求
|
|
|
|
|
|
|
|
$companys = $companys->chunk(3);
|
|
|
|
|
|
|
|
foreach ($companys as $company) {
|
|
|
|
|
|
|
|
foreach ($company 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']}-经纬度信息更新成功");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|