From 5b504adad0eb873b4e9d15ac40fce268118eecf3 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Thu, 27 Nov 2025 13:22:04 +0800 Subject: [PATCH 1/4] update --- app/Models/CourseSign.php | 4 +-- app/Models/CourseType.php | 10 +++++++ ..._is_count_genban_to_course_types_table.php | 29 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2025_11_27_100000_add_is_count_genban_to_course_types_table.php diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index eafe558..80e1b9f 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -212,9 +212,9 @@ class CourseSign extends SoftDeletesModel public static function genban($start_date, $end_date, $course_ids = null, $retList = false) { $courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids); - // 获取制定的课程id + // 获取需要统计跟班学员的课程 $genbanCourse = Course::whereHas('typeDetail', function ($query) { - $query->whereIn('id', [1, 3, 14]); + $query->whereIn('is_count_genban', 1); })->get(); $courseSigns = $courseSignsQuery->whereHas('user', function ($query) { diff --git a/app/Models/CourseType.php b/app/Models/CourseType.php index a0ebea1..25aaf67 100755 --- a/app/Models/CourseType.php +++ b/app/Models/CourseType.php @@ -8,6 +8,16 @@ class CourseType extends SoftDeletesModel { const START_DATE = '2020-01-01 00:00:00'; + protected $appends = ['is_count_genban_text']; + + /** + * 是否统计跟班学员数文字 + */ + public function getIsCountGenbanTextAttribute() + { + return ($this->attributes['is_count_genban'] ?? 1) == 1 ? '是' : '否'; + } + public function courses() { return $this->hasMany(Course::class, 'type', 'id'); diff --git a/database/migrations/2025_11_27_100000_add_is_count_genban_to_course_types_table.php b/database/migrations/2025_11_27_100000_add_is_count_genban_to_course_types_table.php new file mode 100644 index 0000000..c87c6e8 --- /dev/null +++ b/database/migrations/2025_11_27_100000_add_is_count_genban_to_course_types_table.php @@ -0,0 +1,29 @@ +tinyInteger('is_count_genban')->default(0)->nullable()->comment('是否统计跟班学员数 0否 1是'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('course_types', function (Blueprint $table) { + $table->dropColumn('is_count_genban'); + }); + } +}; + From 8717fb82293f3b5b34eb2d6b9ee13a936933a6e5 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Thu, 27 Nov 2025 13:35:27 +0800 Subject: [PATCH 2/4] update --- app/Console/Commands/UpdateCompany.php | 55 +++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) 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} 个公司"); + } + } From 2ec2e7ad3bc556c3e2b0d28fb4fcddb07aec2adb Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Thu, 27 Nov 2025 13:57:18 +0800 Subject: [PATCH 3/4] update --- app/Models/CourseSign.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index 80e1b9f..e0543e3 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -214,7 +214,7 @@ class CourseSign extends SoftDeletesModel $courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids); // 获取需要统计跟班学员的课程 $genbanCourse = Course::whereHas('typeDetail', function ($query) { - $query->whereIn('is_count_genban', 1); + $query->where('is_count_genban', 1); })->get(); $courseSigns = $courseSignsQuery->whereHas('user', function ($query) { From 1ce011e08b20e3e9391287bf5e7ceceb7f81b017 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Thu, 27 Nov 2025 14:03:27 +0800 Subject: [PATCH 4/4] update --- app/Console/Commands/UpdateCompany.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/UpdateCompany.php b/app/Console/Commands/UpdateCompany.php index d281d5a..b5ada7d 100755 --- a/app/Console/Commands/UpdateCompany.php +++ b/app/Console/Commands/UpdateCompany.php @@ -43,8 +43,8 @@ class UpdateCompany extends Command public function handle() { $user_id = $this->option('user_id'); - $updateLocal = (int) $this->option('address'); - $updateMarket = (int) $this->option('market'); + $updateLocal = (int)$this->option('address'); + $updateMarket = (int)$this->option('market'); // 更新公司信息 $this->compnay($user_id); // 更新经纬度信息(可选) @@ -142,6 +142,8 @@ class UpdateCompany extends Command // 更新用户关联 $user->company_id = $company->id; $user->save(); + // 更新上市状态 + $this->updateMarketStatus($company->id); $bar->setMessage($result['enterpriseName'] . ' 更新成功', 'status'); $bar->advance(); } @@ -203,14 +205,18 @@ class UpdateCompany extends Command * 根据 company_tag 更新上市状态 * 判断是否包含上市代码标签,如 688001.SH、000001.SZ、830001.BJ 等 */ - public function updateMarketStatus() + public function updateMarketStatus($companyId = null) { $this->info('开始更新上市状态...'); // 获取所有有 company_tag 的公司 - $companies = Company::whereNotNull('company_tag') - ->where('company_tag', '!=', '') - ->get(); + if ($companyId) { + $companies = Company::where('id', $companyId)->get(); + } else { + $companies = Company::whereNotNull('company_tag') + ->where('company_tag', '!=', '') + ->get(); + } $total = $companies->count(); if ($total == 0) {