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.

97 lines
3.1 KiB

5 months ago
<?php
namespace App\Console\Commands;
4 months ago
use App\Models\Company;
5 months ago
use App\Models\User;
use App\Repositories\MeetRepository;
4 months ago
use App\Repositories\YuanheRepository;
5 months ago
use Illuminate\Console\Command;
class UpdateCompany extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
4 months ago
protected $signature = 'update_company {--user_id=}';
5 months ago
/**
* 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()
{
4 months ago
$user_id = $this->option('user_id');
$users = User::where(function ($query) use ($user_id) {
if ($user_id) {
$query->where('id', $user_id);
}
})->get();
4 months ago
$YuanheRepository = new YuanheRepository();
foreach ($users as $user) {
$result = $YuanheRepository->companyInfo(['enterpriseName' => $user->company_name]);
4 months ago
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' => $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' => $result['tagList'],
];
$company = Company::updateOrCreate($where, $data);
// 更新用户关联
$user->company_id = $company->id;
$user->save();
$this->info($result['enterpriseName'] . '-更新成功');
4 months ago
}
4 months ago
return $this->info('全部更新完成');
5 months ago
}
}