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

master
lion 3 months ago
commit b95d700fd5

@ -75,7 +75,7 @@ class AutoSchoolmate extends Command
->orWhereNull('is_schoolmate');
})
//->where('is_black',0)
->update(['is_schoolmate' => 1]);
->update(['is_schoolmate' => 1, 'schoolmate_time' => now()]);
$totalUpdated += $updated;
}

@ -0,0 +1,233 @@
<?php
namespace App\Console\Commands;
use App\Models\Course;
use App\Models\CourseType;
use App\Models\CourseTypeDataOverviewConfig;
use App\Models\HistoryCourse;
use App\Models\CourseSign;
use Illuminate\Console\Command;
/**
* 对比 home-v2 的 yearConfigs 与 courses-home 的 courseTypesSum
* 在 2024-01-01 2027-01-01 时间段内,找出课程数量、去重培养人数差异的原因
*/
class DiffHomeV2CoursesHome extends Command
{
protected $signature = 'diff:home-v2-courses-home {--start=2024-01-01} {--end=2027-01-01}';
protected $description = '对比 home-v2 yearConfigs 与 courses-home courseTypesSum 在指定时间段内的期数、去重培养人数差异';
public function handle()
{
$start = $this->option('start');
$end = $this->option('end');
$this->info("=== 对比时间段: {$start} {$end} ===\n");
// 1. 找到覆盖该时间段的 yearConfig或使用该时间段模拟
$config = CourseTypeDataOverviewConfig::where('status', true)
->where('start_date', '<=', $start)
->where(function ($q) use ($end) {
$q->where('end_date', '>=', $end)->orWhereNull('end_date');
})
->orderBy('sort')
->first();
if (!$config) {
$config = CourseTypeDataOverviewConfig::where('status', true)
->whereBetween('start_date', [$start, $end])
->orWhereBetween('end_date', [$start, $end])
->orderBy('sort')
->first();
}
$configStart = $config ? $config->start_date : $start;
$configEnd = $config && $config->end_date ? $config->end_date : $end;
$this->info("yearConfig: " . ($config ? "id={$config->id} [{$configStart} {$configEnd}]" : "无覆盖配置,使用 {$configStart} {$configEnd}"));
// 2. 按 home-v2 逻辑统计(仅用 2024-01-012027-01-01 做筛选,与 config 自身范围不一致时以 2024-2027 为准则需单独算)
// 为与 courses-home 可比,我们在这里用 startend 作为统一日期范围
$homeV2 = $this->computeHomeV2Style($start, $end);
$this->info("\n【home-v2 逻辑】期数: {$homeV2['course_periods_total']}, 去重培养人数: {$homeV2['course_signs_unique_total']}");
// 3. 按 courses-home 逻辑统计
$coursesHome = $this->computeCoursesHomeStyle($start, $end);
$this->info("【courses-home 逻辑】课程数量(行数): {$coursesHome['course_count']}, 去重培养人数: {$coursesHome['course_signs_unique_total']}");
// 4. 差异
$diffCount = $coursesHome['course_count'] - $homeV2['course_periods_total'];
$this->info("\n--- 差异: 课程数量 courses-home 多 " . $diffCount . " ---");
// 5. 定位多出来的课程来源
$this->findExtraSources($start, $end, $homeV2, $coursesHome);
return 0;
}
/**
* home-v2 风格is_chart=1 且 is_history=0 的 CourseType + 按 name like 的 HistoryCourse + 其他
*/
protected function computeHomeV2Style(string $start, string $end): array
{
$allCourseTypes = CourseType::where('is_chart', 1)->where('is_history', 0)->orderBy('sort')->get();
$coursePeriodsTotal = 0;
$courseSignsUniqueTotal = 0;
$dateFilter = function ($q) use ($start, $end) {
$q->whereBetween('start_date', [$start, $end])->orWhereBetween('end_date', [$start, $end]);
};
$historyDateFilter = function ($q) use ($start, $end) {
$q->whereBetween('start_time', [$start, $end])->orWhereBetween('end_time', [$start, $end]);
};
foreach ($allCourseTypes as $ct) {
$historyCourse = HistoryCourse::whereHas('typeDetail', fn($q) => $q->where('name', 'like', '%' . $ct->name . '%'))
->where($historyDateFilter)->get();
$courses = Course::where('type', $ct->id)->where('is_chart', 1)->where($dateFilter)->get();
$coursePeriodsTotal += $historyCourse->count() + $courses->count();
$courseSignsUniqueTotal += $historyCourse->sum('course_type_signs_pass_unique')
+ (int)CourseSign::courseSignsTotalByUnique($start, $end, 1, $courses->pluck('id'), false, false);
}
$other = CourseType::getOtherStatistics($start, $end);
$coursePeriodsTotal += $other->course_periods_total;
$courseSignsUniqueTotal += $other->course_signs_total;
return ['course_periods_total' => $coursePeriodsTotal, 'course_signs_unique_total' => $courseSignsUniqueTotal];
}
/**
* courses-home 风格:全部 CourseType含 is_history=1的 Course(is_chart=1) + is_history=1 的 HistoryCourse(calendar.is_count_people=1)
*/
protected function computeCoursesHomeStyle(string $start, string $end): array
{
$course_type_id = CourseType::pluck('id')->toArray();
$courseTypesSum = [];
$allCourseIdsForUnique = [];
$dateFilter = function ($q) use ($start, $end) {
if ($start && $end) {
$q->whereBetween('start_date', [$start, $end])->orWhereBetween('end_date', [$start, $end]);
}
};
// 第一循环:所有 CourseType含 is_history=1
$courseTypes = CourseType::whereIn('id', $course_type_id)->get();
foreach ($courseTypes as $ct) {
$courses2 = Course::where('type', $ct->id)->where($dateFilter)->where('is_chart', 1)->orderBy('start_date')->get();
foreach ($courses2 as $c) {
$courseTypesSum[] = ['source' => 'Course', 'course_type_id' => $ct->id, 'course_type_name' => $ct->name, 'is_history' => $ct->is_history ?? 0, 'course_id' => $c->id, 'course_name' => $c->name];
$allCourseIdsForUnique[] = $c->id;
}
}
// 第二循环is_history=1 的 HistoryCourse与 home-v2 一致:仅 typeDetail.name 能匹配某个 is_chart=1 且 is_history=0 的 name
$chartHistoryTypeNames = CourseType::where('is_chart', 1)->where('is_history', 0)->pluck('name')->toArray();
$courseTypesHistory = CourseType::where('is_history', 1)->whereIn('id', $course_type_id)->get();
$historySignsTotal = 0;
foreach ($courseTypesHistory as $hc) {
$historyQ = HistoryCourse::whereHas('calendar', fn($q) => $q->where('is_count_people', 1))
->where(fn($q) => $q->whereBetween('start_time', [$start, $end])->orWhereBetween('end_time', [$start, $end]))
->where('type', $hc->id);
if (!empty($chartHistoryTypeNames)) {
$historyQ->whereHas('typeDetail', function ($query) use ($chartHistoryTypeNames) {
$query->where(function ($q2) use ($chartHistoryTypeNames) {
foreach ($chartHistoryTypeNames as $n) {
$q2->orWhere('name', 'like', '%' . $n . '%');
}
});
});
} else {
$historyQ->whereHas('typeDetail', fn($query) => $query->whereRaw('1=0'));
}
$courses3 = $historyQ->get();
foreach ($courses3 as $c) {
$courseTypesSum[] = ['source' => 'HistoryCourse', 'course_type_id' => $hc->id, 'course_type_name' => $hc->name, 'is_history' => 1, 'history_course_id' => $c->id, 'course_name' => $c->course_name];
$historySignsTotal += (int)($c->course_type_signs_pass_unique ?? 0);
}
}
$courseSignsUniqueTotal = (int)CourseSign::courseSignsTotalByUnique($start, $end, 1, $allCourseIdsForUnique ?: [], false, false) + $historySignsTotal;
return [
'course_count' => count($courseTypesSum),
'course_signs_unique_total' => $courseSignsUniqueTotal,
'rows' => $courseTypesSum,
];
}
/**
* 找出 courses-home 多出来的课程来源
*/
protected function findExtraSources(string $start, string $end, array $homeV2, array $coursesHome): void
{
$allCourseTypes = CourseType::where('is_chart', 1)->where('is_history', 0)->pluck('id')->toArray();
$historyDateFilter = function ($q) use ($start, $end) {
$q->whereBetween('start_time', [$start, $end])->orWhereBetween('end_time', [$start, $end]);
};
$dateFilter = function ($q) use ($start, $end) {
$q->whereBetween('start_date', [$start, $end])->orWhereBetween('end_date', [$start, $end]);
};
// home-v2 会计入的1) Course: type in is_history=0, is_chart=1, 日期 2) HistoryCourse: typeDetail.name like (is_history=0 的 name), 日期 3) 其他
$homeV2CourseIds = [];
foreach (CourseType::where('is_chart', 1)->where('is_history', 0)->get() as $ct) {
$ids = Course::where('type', $ct->id)->where('is_chart', 1)->where($dateFilter)->pluck('id')->toArray();
$homeV2CourseIds = array_merge($homeV2CourseIds, $ids);
}
$otherCourseIds = Course::whereIn('type', CourseType::where('is_chart', 0)->where('is_history', 0)->pluck('id'))
->where('is_chart', 1)->where($dateFilter)->pluck('id')->toArray();
$homeV2CourseIds = array_unique(array_merge($homeV2CourseIds, $otherCourseIds));
$homeV2HistoryIds = [];
foreach (CourseType::where('is_chart', 1)->where('is_history', 0)->get() as $ct) {
$ids = HistoryCourse::whereHas('typeDetail', fn($q) => $q->where('name', 'like', '%' . $ct->name . '%'))
->where($historyDateFilter)->pluck('id')->toArray();
$homeV2HistoryIds = array_merge($homeV2HistoryIds, $ids);
}
$otherHistory = HistoryCourse::whereIn('type', CourseType::where('is_chart', 0)->where('is_history', 0)->pluck('id'))
->where($historyDateFilter)->pluck('id')->toArray();
$homeV2HistoryIds = array_unique(array_merge($homeV2HistoryIds, $otherHistory));
// courses-home 多出的:在 rows 里但不在 home-v2 的
$extras = [];
foreach ($coursesHome['rows'] as $r) {
if ($r['source'] === 'Course') {
if (!in_array($r['course_id'], $homeV2CourseIds)) {
$extras[] = $r;
}
} else {
if (!in_array($r['history_course_id'], $homeV2HistoryIds)) {
$extras[] = $r;
}
}
}
$this->info("\n【多出的课程/期courses-home 有、home-v2 无)】共 " . count($extras) . " 条:");
foreach ($extras as $e) {
$this->line(sprintf(
" - %s | type_id=%s is_history=%s | %s | %s",
$e['source'],
$e['course_type_id'],
$e['is_history'],
$e['course_name'] ?? '-',
isset($e['course_id']) ? "course_id={$e['course_id']}" : "history_id={$e['history_course_id']}"
));
}
// 单独列出type 属于 is_history=1 的 Coursehome-v2 不统计此类)
$isHistory1TypeIds = CourseType::where('is_history', 1)->pluck('id')->toArray();
$courseFromHistory1Type = Course::whereIn('type', $isHistory1TypeIds)
->where('is_chart', 1)
->where($dateFilter)
->get();
if ($courseFromHistory1Type->isNotEmpty()) {
$this->info("\n【属于 is_history=1 课程类型的 Coursehome-v2 不统计)】共 " . $courseFromHistory1Type->count() . " 条:");
foreach ($courseFromHistory1Type as $c) {
$ct = CourseType::find($c->type);
$this->line(" - course_id={$c->id} type={$c->type} ({$ct->name}) | {$c->name} | {$c->start_date}{$c->end_date}");
}
}
}
}

@ -0,0 +1,194 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class MergeDuplicateUsersByMobile extends Command
{
protected $signature = 'merge_duplicate_users_by_mobile
{--dry-run : 只打印将执行的操作,不实际更新或删除}';
protected $description = '将手机号重复的用户合并:保留 id 最大的用户,把旧用户的关联数据转移到新用户后软删除旧用户(仅处理有报名审核通过的重复手机号)';
/**
* 需要把 user_id 从旧用户改成新用户的表
*/
protected array $tablesWithUserId = [
'course_signs',
'course_keeps',
'appointments',
'supply_demands',
'supply_demand_keeps',
'course_content_evaluation_forms',
'course_content_checks',
'course_appointment_totals',
'score_logs',
'third_appointment_logs',
];
/**
* 表里既有 user_id 又有 to_user_id都需要把旧用户 id 替换为新用户 id
*/
protected array $tablesWithToUserId = [
'dialogues',
'messages',
];
public function handle()
{
$dryRun = $this->option('dry-run');
if ($dryRun) {
$this->warn('【预检模式】不会修改数据库');
}
$duplicateGroups = $this->getDuplicateMobileUsers();
if ($duplicateGroups->isEmpty()) {
$this->info('没有需要合并的重复手机号。');
return 0;
}
$this->info('共 ' . $duplicateGroups->count() . ' 组重复手机号待处理。');
$merged = 0;
$failed = 0;
foreach ($duplicateGroups as $mobile => $users) {
// 按 id 升序id 最大为“新”,保留;其余为“旧”,合并后软删
$sorted = $users->sortBy('id')->values();
$newUser = $sorted->last();
$oldUsers = $sorted->slice(0, -1);
$newId = (int) $newUser->id;
$oldIds = $oldUsers->pluck('id')->map(fn($v) => (int) $v)->toArray();
$this->line('');
$this->line("手机号: {$mobile} | 保留用户 id={$newId} ({$newUser->name}), 合并并删除: " . implode(', ', $oldIds));
if ($dryRun) {
$this->listTransfers($newId, $oldIds);
$merged++;
continue;
}
try {
DB::transaction(function () use ($newId, $oldIds) {
foreach ($oldIds as $oldId) {
$this->transferRelations($oldId, $newId);
}
User::whereIn('id', $oldIds)->delete(); // 软删除
});
$this->info(" 已合并并软删除旧用户: " . implode(', ', $oldIds));
$merged++;
} catch (\Throwable $e) {
$this->error(" 失败: " . $e->getMessage());
$failed++;
}
}
$this->line('');
$this->info("完成: 成功 {$merged} 组" . ($failed > 0 ? ", 失败 {$failed} 组" : '') . ($dryRun ? '(未写入)' : ''));
return $failed > 0 ? 1 : 0;
}
/**
* 查询:有报名审核通过且手机号重复的用户,按手机号分组
*/
protected function getDuplicateMobileUsers()
{
$sql = "
SELECT u.id, u.name, u.mobile
FROM users u
WHERE u.deleted_at IS NULL
AND u.mobile IS NOT NULL AND TRIM(u.mobile) != ''
AND EXISTS (
SELECT 1 FROM course_signs cs
WHERE cs.user_id = u.id AND cs.status = 1 AND cs.deleted_at IS NULL
)
AND u.mobile IN (
SELECT u2.mobile
FROM users u2
INNER JOIN course_signs cs2 ON cs2.user_id = u2.id AND cs2.status = 1 AND cs2.deleted_at IS NULL
WHERE u2.deleted_at IS NULL
AND u2.mobile IS NOT NULL AND TRIM(u2.mobile) != ''
GROUP BY u2.mobile
HAVING COUNT(DISTINCT u2.id) > 1
)
ORDER BY u.mobile, u.id
";
$rows = DB::select($sql);
return collect($rows)->groupBy('mobile');
}
/**
* 把 oldUserId 的关联全部改为 newUserId
*/
protected function transferRelations(int $oldUserId, int $newUserId): void
{
foreach ($this->tablesWithUserId as $table) {
if (!Schema::hasTable($table) || !Schema::hasColumn($table, 'user_id')) {
continue;
}
$n = DB::table($table)->where('user_id', $oldUserId)->update(['user_id' => $newUserId]);
if ($n > 0) {
$this->line(" {$table}.user_id: {$oldUserId} -> {$newUserId}, 更新 {$n} 行");
}
}
foreach ($this->tablesWithToUserId as $table) {
if (!Schema::hasTable($table)) {
continue;
}
if (Schema::hasColumn($table, 'user_id')) {
$n = DB::table($table)->where('user_id', $oldUserId)->update(['user_id' => $newUserId]);
if ($n > 0) {
$this->line(" {$table}.user_id: {$oldUserId} -> {$newUserId}, 更新 {$n} 行");
}
}
if (Schema::hasColumn($table, 'to_user_id')) {
$n = DB::table($table)->where('to_user_id', $oldUserId)->update(['to_user_id' => $newUserId]);
if ($n > 0) {
$this->line(" {$table}.to_user_id: {$oldUserId} -> {$newUserId}, 更新 {$n} 行");
}
}
}
}
/**
* dry-run只统计并打印每个表将更新的行数
*/
protected function listTransfers(int $newUserId, array $oldIds): void
{
foreach ($oldIds as $oldId) {
foreach ($this->tablesWithUserId as $table) {
if (!Schema::hasTable($table) || !Schema::hasColumn($table, 'user_id')) {
continue;
}
$n = DB::table($table)->where('user_id', $oldId)->count();
if ($n > 0) {
$this->line(" [拟] {$table}.user_id: {$oldId} -> {$newUserId}, 约 {$n} 行");
}
}
foreach ($this->tablesWithToUserId as $table) {
if (!Schema::hasTable($table)) {
continue;
}
if (Schema::hasColumn($table, 'user_id')) {
$n = DB::table($table)->where('user_id', $oldId)->count();
if ($n > 0) {
$this->line(" [拟] {$table}.user_id: {$oldId} -> {$newUserId}, 约 {$n} 行");
}
}
if (Schema::hasColumn($table, 'to_user_id')) {
$n = DB::table($table)->where('to_user_id', $oldId)->count();
if ($n > 0) {
$this->line(" [拟] {$table}.to_user_id: {$oldId} -> {$newUserId}, 约 {$n} 行");
}
}
}
}
}
}

@ -284,9 +284,11 @@ class CompanyController extends BaseController
$statistics = [
'course_signs_invested' => 0,
'company_invested_after_enrollment_total' => 0,
'company_invested_after_enrollment_current_total' => 0,
'company_invested_year_total' => 0,
'course_signs_invested_companies' => [],
'company_invested_after_enrollment_companies' => [],
'company_invested_after_enrollment_current_companies' => [],
'company_invested_year_companies' => [],
];
$start_date = $start_year ? $start_year . '-01-01' : date('Y-01-01');
@ -324,6 +326,16 @@ class CompanyController extends BaseController
$statistics['company_invested_year_companies'] = $yearInvestedCompaniesCollection->pluck('company_name')->filter()->unique()->values()->toArray();
}
// 当前入学后被投企业数(与 courses-home 的 company_invested_after_enrollment_total 口径一致:被投时间在 yearStart-yearEnd 内且入学≤被投)
// companyInvestedAfterEnrollment 需传日期yearStart/yearEnd 为空时用 CourseType::START_DATE 与 end_date 表示全周期
$currentAfterStart = $yearStart ?? CourseType::START_DATE;
$currentAfterEnd = $yearEnd ?? $end_date;
$currentAfterEnrollmentCompanies = CourseSign::companyInvestedAfterEnrollment($currentAfterStart, $currentAfterEnd, $course_ids, true);
if ($currentAfterEnrollmentCompanies) {
$statistics['company_invested_after_enrollment_current_total'] = count($currentAfterEnrollmentCompanies);
$statistics['company_invested_after_enrollment_current_companies'] = collect($currentAfterEnrollmentCompanies)->pluck('company.company_name')->filter()->unique()->values()->toArray();
}
// 入学后被投企业数量(与 courses-home 的 company_invested_after_enrollment_total_cumulative 口径一致)
$afterEnrollmentCompanies = CourseSign::companyInvestedAfterEnrollment(CourseType::START_DATE, $end_date, $course_ids, true);
if ($afterEnrollmentCompanies) {

@ -285,6 +285,7 @@ class EmployeeParticipationController extends BaseController
$list[$key]['company_name'] = $value['公司名称'] ?? null;
$list[$key]['name'] = $value['姓名'] ?? null;
$list[$key]['department'] = $value['部门'] ?? null;
$list[$key]['total'] = $value['数量'] ?? 1;
// 根据课程信息填充其他字段
if ($course) {

@ -263,18 +263,8 @@ class OtherController extends CommonController
$config->courseTypes = $courseTypes;
// 总期数(包含"其他"
$config->course_periods_total = $courseTypes->sum('course_periods_total');
// 总去重人数(包含"其他"
$coursesAll = Course::whereIn('type', $allCourseTypes->pluck('id'))
->where('is_chart', 1)
->where(function ($query) use ($configStartDate, $configEndDate) {
$query->whereBetween('start_date', [$configStartDate, $configEndDate])
->orWhereBetween('end_date', [$configStartDate, $configEndDate]);
})->get();
// 获取"其他"课程类型的课程ID列表
$otherCourseIds = CourseType::getOtherCourseIds($configStartDate, $configEndDate);
$config->course_signs_unique_total = $courseTypes->sum('history_course_signs_total') + CourseSign::courseSignsTotalByUnique($configStartDate, $configEndDate, 1, $coursesAll->pluck('id')->merge($otherCourseIds), false, false);
// 总去重人数(包含"其他"),与 courseTypes 各项 course_signs_total 之和保持一致
$config->course_signs_unique_total = $courseTypes->sum('course_signs_total');
}
return $this->success(compact('list', 'suzhou', 'country', 'monthCourses', 'time_axis', 'article', 'yearConfigs'));
@ -387,11 +377,22 @@ class OtherController extends CommonController
];
}
}
// 附加历史课程数据
// 附加历史课程数据(与 home-v2 yearConfigs 口径一致:仅统计 typeDetail.name 能匹配某个 is_chart=1 且 is_history=0 的 CourseType 的 HistoryCourse
$chartHistoryTypeNames = CourseType::where('is_chart', 1)->where('is_history', 0)->pluck('name')->toArray();
$courseTypesHistory = CourseType::where('is_history', 1)->whereIn('id', $course_type_id)->get();
foreach ($courseTypesHistory as $historyCourse) {
$courses3 = HistoryCourse::whereHas('calendar', function ($query) {
$query->where('is_count_people', 1);
})->whereHas('typeDetail', function ($query) use ($chartHistoryTypeNames) {
if (empty($chartHistoryTypeNames)) {
$query->whereRaw('1=0');
return;
}
$query->where(function ($q) use ($chartHistoryTypeNames) {
foreach ($chartHistoryTypeNames as $n) {
$q->orWhere('name', 'like', '%' . $n . '%');
}
});
})->where(function ($query) use ($start_date, $end_date) {
// 开始结束日期的筛选。or查询
$query->whereBetween('start_time', [$start_date, $end_date])
@ -873,11 +874,22 @@ class OtherController extends CommonController
];
}
}
// 附加历史课程数据
// 附加历史课程数据(与 home-v2 yearConfigs 口径一致:仅统计 typeDetail.name 能匹配某个 is_chart=1 且 is_history=0 的 CourseType 的 HistoryCourse
$chartHistoryTypeNames = CourseType::where('is_chart', 1)->where('is_history', 0)->pluck('name')->toArray();
$courseTypesHistory = CourseType::where('is_history', 1)->whereIn('id', $course_type_id)->get();
foreach ($courseTypesHistory as $historyCourse) {
$courses3 = HistoryCourse::whereHas('calendar', function ($query) {
$query->where('is_count_people', 1);
})->whereHas('typeDetail', function ($query) use ($chartHistoryTypeNames) {
if (empty($chartHistoryTypeNames)) {
$query->whereRaw('1=0');
return;
}
$query->where(function ($q) use ($chartHistoryTypeNames) {
foreach ($chartHistoryTypeNames as $n) {
$q->orWhere('name', 'like', '%' . $n . '%');
}
});
})->where(function ($query) use ($start_date, $end_date) {
// 开始结束日期的筛选。or查询
$query->whereBetween('start_time', [$start_date, $end_date])

@ -190,6 +190,7 @@ class UserController extends BaseController
* @OA\Parameter(name="is_company_market", in="query", @OA\Schema(type="string"), required=false, description="是否上市公司0否1是"),
* @OA\Parameter(name="company_tag", in="query", @OA\Schema(type="string"), required=false, description="企业标签"),
* @OA\Parameter(name="talent_tags", in="query", @OA\Schema(type="string"), required=false, description="人才标签,多个英文逗号分隔"),
* @OA\Parameter(name="address", in="query", @OA\Schema(type="string"), required=false, description="公司地址,模糊匹配关联 company 的 company_address 或 company_city"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
@ -369,6 +370,13 @@ class UserController extends BaseController
$company_area = explode(',', $all['company_area']);
$query->whereIn('company_area', $company_area);
}
// 公司地址:模糊匹配关联 company 的 company_address 或 company_city
if (isset($all['address']) && $all['address'] !== '') {
$query->whereHas('company', function ($c) use ($all) {
$c->where('company_address', 'like', '%' . $all['address'] . '%')
->orWhere('company_city', 'like', '%' . $all['address'] . '%');
});
}
if (isset($all['company_industry'])) {
$company_industry = explode(',', $all['company_industry']);
$query->where(function ($q) use ($company_industry) {
@ -742,6 +750,7 @@ class UserController extends BaseController
$data = [];
if (isset($all['is_schoolmate'])) {
$data['is_schoolmate'] = $all['is_schoolmate'];
$data['schoolmate_time'] = ($all['is_schoolmate'] == 1) ? now() : null;
}
$this->model->whereIn('id', $idsArray)->update($data);
return $this->success('批量更新成功');
@ -794,6 +803,10 @@ class UserController extends BaseController
return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, '没有可更新的有效字段']);
}
if (array_key_exists('is_schoolmate', $data)) {
$data['schoolmate_time'] = ($data['is_schoolmate'] == 1) ? now() : null;
}
// 解析用户ID
$idsArray = explode(',', $all['ids']);
$idsArray = array_filter(array_map('trim', $idsArray));

@ -806,7 +806,7 @@ class CourseSign extends SoftDeletesModel
// 条件2user.type 包含「人才」的用户
$courseSigns2 = $courseSignsQuery->whereHas('user', function ($q) {
$q->where('type', 'like', '%人才%');
$q->where('type', 'like', '%人才%')->orWhere('talent_tags', 'like', '%人才%');
})->with(['user.company'])->get();
// 合并两个条件的结果(或关系),并去重 user_id

@ -125,29 +125,6 @@ class User extends Authenticatable implements Auditable
'is_schoolmate' => ['否', '是'],
];
/**
* Boot 方法 - 处理模型事件
*/
protected static function boot()
{
parent::boot();
static::saving(function ($user) {
// 当 is_schoolmate 被设置为 1 时,自动设置成为校友时间
if ($user->isDirty('is_schoolmate')) {
if ($user->is_schoolmate == 1) {
// 如果是从非校友变成校友,设置成为校友时间为当前时间
if ($user->getOriginal('is_schoolmate') != 1) {
$user->schoolmate_time = now();
}
} elseif ($user->is_schoolmate == 0 || $user->is_schoolmate === null) {
// 如果设置为 0 或 null清空成为校友时间
$user->schoolmate_time = null;
}
}
});
}
public function getMobileAttribute($value)
{
// 如果url中包含admin字符串则所有的手机号显示中间4位星号代替

@ -19,7 +19,7 @@ return new class extends Migration {
$table->string('name')->nullable()->comment('名字');
$table->date('start_date')->nullable()->comment('开始日期');
$table->date('end_date')->nullable()->comment('结束日期');
$table->integer('total')->default(0)->comment('加减数据(正数表示加,负数表示减)');
$table->unsignedInteger('total')->default(1)->comment('数量必须为正数默认1');
$table->text('remark')->nullable()->comment('备注');
$table->timestamps();
$table->softDeletes();

Loading…
Cancel
Save