You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
4.7 KiB
145 lines
4.7 KiB
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Company;
|
|
use App\Models\User;
|
|
use App\Repositories\MeetRepository;
|
|
use App\Repositories\YuanheRepository;
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
class UpdateCompany extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'update_company {--user_id=}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '批量公司信息';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$user_id = $this->option('user_id');
|
|
// 更新公司信息
|
|
$this->compnay($user_id);
|
|
// 更新经纬度信息
|
|
$this->local($user_id);
|
|
return $this->info('全部更新完成');
|
|
}
|
|
|
|
/**
|
|
* 更新公司信息
|
|
*/
|
|
public function compnay($user_id = null)
|
|
{
|
|
if ($user_id) {
|
|
// 强制单个更新
|
|
$users = User::where('id', $user_id)->get();
|
|
} else {
|
|
// 批量更新
|
|
$users = User::whereDoesntHave('company')->whereNotNull('company_name')->get();
|
|
}
|
|
$YuanheRepository = new YuanheRepository();
|
|
foreach ($users as $user) {
|
|
// 获取公司详细信息
|
|
$result = $YuanheRepository->companyInfo(['enterpriseName' => $user->company_name]);
|
|
if (!$result) {
|
|
$this->info($user->company_name . '公司不存在');
|
|
continue;
|
|
}
|
|
$where = ['company_name' => $result['enterpriseName']];
|
|
$data = [
|
|
'company_address' => $result['address'],
|
|
'business_scope' => $result['businessScope'],
|
|
'company_city' => $result['city'],
|
|
'contact_mail' => $result['contactMail'],
|
|
'contact_phone' => $result['contactPhone'],
|
|
'company_area' => $result['country'],
|
|
'credit_code' => $result['creditCode'],
|
|
'enterprise_id' => $result['enterpriseId'],
|
|
'company_name' => $result['enterpriseName'],
|
|
'is_abroad' => $result['isAbroad'],
|
|
'company_market' => $result['isOnStock'],
|
|
'is_yh_invested' => $result['isYhInvested'],
|
|
'logo' => $result['logo'],
|
|
'company_legal_representative' => $result['operName'],
|
|
'company_province' => $result['province'],
|
|
'company_industry' => combineKeyValue($result['qccIndustry']),
|
|
'regist_amount' => $result['registAmount'],
|
|
'regist_capi_type' => $result['registCapiType'],
|
|
'company_date' => $result['startDate'],
|
|
'status' => $result['status'],
|
|
'stock_date' => $result['stockDate'],
|
|
'currency_type' => $result['currencyType'],
|
|
'stock_number' => $result['stockNumber'],
|
|
'stock_type' => $result['stockType'],
|
|
'company_tag' => implode(',', $result['tagList']),
|
|
];
|
|
$company = Company::updateOrCreate($where, $data);
|
|
// 更新用户关联
|
|
$user->company_id = $company->id;
|
|
$user->save();
|
|
$this->info($result['enterpriseName'] . '-更新成功');
|
|
}
|
|
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;
|
|
}
|
|
|
|
}
|