diff --git a/app/Console/Commands/UpdateCompany.php b/app/Console/Commands/UpdateCompany.php index 8581313..d281d5a 100755 --- a/app/Console/Commands/UpdateCompany.php +++ b/app/Console/Commands/UpdateCompany.php @@ -16,7 +16,7 @@ class UpdateCompany extends Command * * @var string */ - protected $signature = 'update_company {--user_id=} {--address=0}'; + protected $signature = 'update_company {--user_id=} {--address=0} {--market=0}'; /** * The console command description. @@ -43,13 +43,18 @@ class UpdateCompany extends Command public function handle() { $user_id = $this->option('user_id'); - $updateLocal = (int)$this->option('address'); + $updateLocal = (int) $this->option('address'); + $updateMarket = (int) $this->option('market'); // 更新公司信息 $this->compnay($user_id); // 更新经纬度信息(可选) if ($updateLocal) { $this->local($user_id); } + // 更新上市状态(可选) + if ($updateMarket) { + $this->updateMarketStatus(); + } return $this->info('全部更新完成'); } @@ -194,4 +199,50 @@ class UpdateCompany extends Command return $this->info('经纬度信息-全部更新完成'); } + /** + * 根据 company_tag 更新上市状态 + * 判断是否包含上市代码标签,如 688001.SH、000001.SZ、830001.BJ 等 + */ + public function updateMarketStatus() + { + $this->info('开始更新上市状态...'); + + // 获取所有有 company_tag 的公司 + $companies = Company::whereNotNull('company_tag') + ->where('company_tag', '!=', '') + ->get(); + + $total = $companies->count(); + if ($total == 0) { + return $this->info('没有需要更新上市状态的公司'); + } + + $bar = $this->output->createProgressBar($total); + $bar->start(); + + // 上市代码正则:数字.SH 或 数字.SZ 或 数字.BJ + $stockCodePattern = '/\d{6}\.(SH|SZ|BJ)/i'; + + $updatedCount = 0; + foreach ($companies as $company) { + $hasStockCode = preg_match($stockCodePattern, $company->company_tag); + $newMarketStatus = $hasStockCode ? 1 : 0; + + // 只有状态变化才更新 + if ($company->company_market != $newMarketStatus) { + $company->company_market = $newMarketStatus; + $company->save(); + $updatedCount++; + $statusText = $newMarketStatus ? '上市' : '非上市'; + $bar->setMessage("{$company->company_name} => {$statusText}", 'status'); + } + + $bar->advance(); + } + + $bar->finish(); + $this->newLine(); + return $this->info("上市状态更新完成,共更新 {$updatedCount} 个公司"); + } + }