Merge branch 'master' of ssh://47.101.48.251:/data/git/wx.sstbc.com

master
lion 2 weeks ago
commit e8d311a17d

@ -16,7 +16,7 @@ class UpdateCompany extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'update_company {--user_id=} {--address=0}'; protected $signature = 'update_company {--user_id=} {--address=0} {--market=0}';
/** /**
* The console command description. * The console command description.
@ -44,12 +44,17 @@ class UpdateCompany extends Command
{ {
$user_id = $this->option('user_id'); $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); $this->compnay($user_id);
// 更新经纬度信息(可选) // 更新经纬度信息(可选)
if ($updateLocal) { if ($updateLocal) {
$this->local($user_id); $this->local($user_id);
} }
// 更新上市状态(可选)
if ($updateMarket) {
$this->updateMarketStatus();
}
return $this->info('全部更新完成'); return $this->info('全部更新完成');
} }
@ -137,6 +142,8 @@ class UpdateCompany extends Command
// 更新用户关联 // 更新用户关联
$user->company_id = $company->id; $user->company_id = $company->id;
$user->save(); $user->save();
// 更新上市状态
$this->updateMarketStatus($company->id);
$bar->setMessage($result['enterpriseName'] . ' 更新成功', 'status'); $bar->setMessage($result['enterpriseName'] . ' 更新成功', 'status');
$bar->advance(); $bar->advance();
} }
@ -194,4 +201,54 @@ class UpdateCompany extends Command
return $this->info('经纬度信息-全部更新完成'); return $this->info('经纬度信息-全部更新完成');
} }
/**
* 根据 company_tag 更新上市状态
* 判断是否包含上市代码标签,如 688001.SH、000001.SZ、830001.BJ 等
*/
public function updateMarketStatus($companyId = null)
{
$this->info('开始更新上市状态...');
// 获取所有有 company_tag 的公司
if ($companyId) {
$companies = Company::where('id', $companyId)->get();
} else {
$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} 个公司");
}
} }

@ -75,7 +75,21 @@ class CalendarsController extends BaseController
$query->where('start_time', 'like', $year . '%'); $query->where('start_time', 'like', $year . '%');
} }
})->where('is_count_days', 1)->sum('days'); })->where('is_count_days', 1)->sum('days');
return $this->success(compact('list', 'monthDayCalendar', 'yearDayCalendar')); // 本月开课场次
$monthCourseCount = Calendar::where(function ($query) use ($all) {
if (isset($all['month'])) {
$query->where('start_time', 'like', $all['month'] . '%');
}
})->count();
// 本年开课场次
$yearCourseCount = Calendar::where(function ($query) use ($all) {
if (isset($all['month'])) {
// 获取$all['month']的年份部分
$year = date('Y', strtotime($all['month']));
$query->where('start_time', 'like', $year . '%');
}
})->count();
return $this->success(compact('list', 'monthDayCalendar', 'yearDayCalendar', 'monthCourseCount', 'yearCourseCount'));
} }
/** /**

@ -235,7 +235,7 @@ class OtherController extends CommonController
->orWhereBetween('end_time', [$start_date, $end_date]); ->orWhereBetween('end_time', [$start_date, $end_date]);
})->where(function ($query) use ($courses) { })->where(function ($query) use ($courses) {
if (request('course_type_id')) { if (request('course_type_id')) {
$query->whereIn('course_id', $courses->pluck('id')); $query->whereIn('course_type_id', request('course_type_id'));
} }
}); });
$list['course_total'] = (clone $calendar)->count(); $list['course_total'] = (clone $calendar)->count();
@ -732,7 +732,7 @@ class OtherController extends CommonController
$calendars = Calendar::whereBetween('date', [$start_date, $end_date]) $calendars = Calendar::whereBetween('date', [$start_date, $end_date])
->where(function ($query) use ($course_ids) { ->where(function ($query) use ($course_ids) {
if (request('course_type_id')) { if (request('course_type_id')) {
$query->whereIn('course_id', $course_ids); $query->whereIn('course_type_id', request('course_type_id'));
} }
})->where('is_count_days', 1) })->where('is_count_days', 1)
->with('course') ->with('course')

@ -47,5 +47,10 @@ class Calendar extends SoftDeletesModel
return $this->hasMany(HistoryCourse::class, 'calendar_id', 'id'); return $this->hasMany(HistoryCourse::class, 'calendar_id', 'id');
} }
public function courseType()
{
return $this->belongsTo(CourseType::class, 'course_type_id', 'id');
}
} }

@ -214,7 +214,7 @@ class CourseSign extends SoftDeletesModel
$courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids); $courseSignsQuery = self::getStudentList($start_date, $end_date, 1, $course_ids);
// 获取需要统计跟班学员的课程 // 获取需要统计跟班学员的课程
$genbanCourse = Course::whereHas('typeDetail', function ($query) { $genbanCourse = Course::whereHas('typeDetail', function ($query) {
$query->whereIn('is_count_genban', 1); $query->where('is_count_genban', 1);
})->get(); })->get();
$courseSigns = $courseSignsQuery->whereHas('user', function ($query) { $courseSigns = $courseSignsQuery->whereHas('user', function ($query) {

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddCourseTypeIdToCalendarsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('calendars', function (Blueprint $table) {
$table->unsignedBigInteger('course_type_id')->nullable()->after('id')->comment('课程类型ID');
$table->index('course_type_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('calendars', function (Blueprint $table) {
$table->dropIndex(['course_type_id']);
$table->dropColumn('course_type_id');
});
}
}
Loading…
Cancel
Save