Phase 8 and 9 marketplace matching

This commit is contained in:
Codex
2026-07-10 14:27:51 -05:00
parent 5009269907
commit 24f73084fa
21 changed files with 778 additions and 50 deletions
+43 -2
View File
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Models\JobPost;
use App\Models\TaxonomyTerm;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
@@ -11,7 +12,8 @@ class JobPostController extends Controller
{
public function index(Request $request): View
{
$jobs = JobPost::with('buyer.buyerProfile', 'attachments', 'ratings.user');
$jobs = JobPost::with('buyer.buyerProfile', 'workCategory', 'workSpecialty', 'attachments', 'ratings.user')
->withCount('quotes');
if ($search = $request->string('q')->toString()) {
$jobs->where(fn ($query) => $query
@@ -26,8 +28,35 @@ class JobPostController extends Controller
$jobs->where('status', $status);
}
if ($category = $request->integer('work_category_id')) {
$jobs->where('work_category_id', $category);
}
if ($level = $request->integer('technician_level')) {
$jobs->where('required_technician_level', '<=', $level);
}
if ($scope = $request->string('scope_clarity')->toString()) {
$jobs->where('scope_clarity_status', $scope);
}
if ($request->boolean('support_certified')) {
$jobs->where('contact_certified', true);
}
if ($request->boolean('remote_only')) {
$jobs->where(fn ($query) => $query->where('remote_eligible', true)->orWhere('work_mode', 'remote'));
}
if ($request->boolean('hide_risky')) {
$jobs->where(fn ($query) => $query->whereNull('risk_flags')->orWhereJsonLength('risk_flags', 0));
}
return view('jobs.index', [
'jobs' => $jobs->latest()->paginate(20)->withQueryString(),
'categories' => TaxonomyTerm::where('type', 'work_category')->where('is_active', true)->orderBy('sort_order')->orderBy('name')->get(),
'technicianLevels' => config('technician-levels'),
'filters' => $request->only(['q', 'status', 'work_category_id', 'technician_level', 'scope_clarity', 'support_certified', 'remote_only', 'hide_risky']),
]);
}
@@ -35,7 +64,11 @@ class JobPostController extends Controller
{
abort_unless($request->user()->hasRole('buyer'), 403);
return view('jobs.create');
return view('jobs.create', [
'categories' => TaxonomyTerm::where('type', 'work_category')->where('is_active', true)->orderBy('sort_order')->orderBy('name')->get(),
'specialties' => TaxonomyTerm::where('type', 'work_specialty')->where('is_active', true)->orderBy('sort_order')->orderBy('name')->get(),
'technicianLevels' => config('technician-levels'),
]);
}
public function store(Request $request): RedirectResponse
@@ -45,6 +78,12 @@ class JobPostController extends Controller
$data = $request->validate([
'title' => ['required', 'string', 'max:255'],
'service_category' => ['nullable', 'string', 'max:255'],
'work_category_id' => ['nullable', 'integer', 'exists:taxonomy_terms,id'],
'work_specialty_id' => ['nullable', 'integer', 'exists:taxonomy_terms,id'],
'required_technician_level' => ['required', 'integer', 'min:1', 'max:5'],
'work_mode' => ['required', 'string', 'in:onsite,remote,hybrid'],
'pay_type' => ['nullable', 'string', 'in:fixed,hourly,blended,not_listed'],
'posted_terms_summary' => ['nullable', 'string', 'max:255'],
'location' => ['required', 'string', 'max:255'],
'starts_at' => ['nullable', 'date'],
'time_window' => ['nullable', 'string', 'max:255'],
@@ -110,6 +149,8 @@ class JobPostController extends Controller
return view('jobs.show', [
'job' => $job->load(
'buyer.buyerProfile',
'workCategory',
'workSpecialty',
'quotes.provider.providerProfile',
'quotes.revisions.user',
'workOrder',
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Models\ProviderProfile;
use App\Models\TaxonomyTerm;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
@@ -11,7 +12,7 @@ class ProviderProfileController extends Controller
{
public function index(Request $request): View
{
$profiles = ProviderProfile::with('user', 'externalImports', 'attachments', 'ratings.user')
$profiles = ProviderProfile::with('user', 'externalImports', 'taxonomyTerms', 'attachments', 'ratings.user')
->withAvg(['ratings as average_stars' => fn ($query) => $query->whereNotNull('stars')], 'stars')
->withCount('ratings');
@@ -32,6 +33,14 @@ class ProviderProfileController extends Controller
$profiles->where('skills', 'like', "%{$skill}%");
}
if ($level = $request->integer('technician_level')) {
$profiles->where('max_technician_level', '>=', $level);
}
if ($tag = $request->integer('taxonomy_term_id')) {
$profiles->whereHas('taxonomyTerms', fn ($query) => $query->whereKey($tag));
}
if ($insurance = $request->string('insurance')->toString()) {
$profiles->where('insurance_status', 'like', "%{$insurance}%");
}
@@ -48,7 +57,14 @@ class ProviderProfileController extends Controller
return view('providers.index', [
'profiles' => $profiles->paginate(20)->withQueryString(),
'filters' => $request->only(['q', 'service_area', 'skill', 'insurance', 'public_contact', 'sort']),
'filters' => $request->only(['q', 'service_area', 'skill', 'technician_level', 'taxonomy_term_id', 'insurance', 'public_contact', 'sort']),
'technicianLevels' => config('technician-levels'),
'taxonomyTerms' => TaxonomyTerm::whereIn('type', ['work_category', 'work_specialty', 'skill', 'tool', 'certification'])
->where('is_active', true)
->orderBy('type')
->orderBy('sort_order')
->orderBy('name')
->get(),
]);
}
@@ -57,7 +73,14 @@ class ProviderProfileController extends Controller
abort_unless($request->user()->hasRole('provider'), 403);
return view('providers.edit', [
'profile' => $request->user()->providerProfile?->load('attachments', 'externalImports.attachments'),
'profile' => $request->user()->providerProfile?->load('attachments', 'externalImports.attachments', 'taxonomyTerms'),
'technicianLevels' => config('technician-levels'),
'taxonomyTerms' => TaxonomyTerm::whereIn('type', ['work_category', 'work_specialty', 'skill', 'tool', 'certification'])
->where('is_active', true)
->orderBy('type')
->orderBy('sort_order')
->orderBy('name')
->get(),
]);
}
@@ -70,7 +93,10 @@ class ProviderProfileController extends Controller
'headline' => ['nullable', 'string', 'max:255'],
'bio' => ['nullable', 'string'],
'service_area' => ['nullable', 'string', 'max:255'],
'max_technician_level' => ['required', 'integer', 'min:1', 'max:5'],
'skills' => ['nullable', 'string'],
'taxonomy_terms' => ['nullable', 'array'],
'taxonomy_terms.*' => ['integer', 'exists:taxonomy_terms,id'],
'services_text' => ['nullable', 'string'],
'tools' => ['nullable', 'string'],
'tool_inventory_text' => ['nullable', 'string'],
@@ -97,18 +123,23 @@ class ProviderProfileController extends Controller
]);
unset($data['services_text'], $data['tool_inventory_text'], $data['certification_records_text']);
$request->user()->providerProfile()->updateOrCreate(
$profile = $request->user()->providerProfile()->updateOrCreate(
['user_id' => $request->user()->id],
$data
);
$sync = collect($data['taxonomy_terms'] ?? [])
->mapWithKeys(fn ($termId): array => [(int) $termId => ['evidence_source' => 'self_declared']])
->all();
$profile->taxonomyTerms()->sync($sync);
return redirect()->route('providers.edit')->with('status', 'Provider profile saved.');
}
public function show(ProviderProfile $provider): View
{
return view('providers.show', [
'profile' => $provider->load('user', 'externalImports.attachments', 'attachments', 'ratings.user'),
'profile' => $provider->load('user', 'externalImports.attachments', 'taxonomyTerms', 'attachments', 'ratings.user'),
]);
}
+26 -1
View File
@@ -11,7 +11,8 @@ use Illuminate\Database\Eloquent\Model;
#[Fillable([
'buyer_id', 'title', 'status', 'service_category', 'location', 'starts_at',
'time_window', 'schedule_type', 'remote_eligible', 'scope', 'primary_objective',
'work_category_id', 'work_specialty_id', 'required_technician_level', 'work_mode',
'pay_type', 'posted_terms_summary', 'time_window', 'schedule_type', 'remote_eligible', 'scope', 'primary_objective',
'included_work', 'excluded_work', 'maximum_onsite_expectations', 'expected_duration',
'required_skills', 'required_tools', 'required_certifications', 'required_safety_gear',
'deliverables', 'closeout_conditions', 'buyer_provided_equipment',
@@ -38,6 +39,7 @@ class JobPost extends Model
{
return [
'starts_at' => 'datetime',
'required_technician_level' => 'integer',
'remote_eligible' => 'boolean',
'risk_flags' => 'array',
'contact_certified' => 'boolean',
@@ -50,6 +52,16 @@ class JobPost extends Model
return $this->belongsTo(User::class, 'buyer_id');
}
public function workCategory(): BelongsTo
{
return $this->belongsTo(TaxonomyTerm::class, 'work_category_id');
}
public function workSpecialty(): BelongsTo
{
return $this->belongsTo(TaxonomyTerm::class, 'work_specialty_id');
}
public function quotes(): HasMany
{
return $this->hasMany(Quote::class);
@@ -95,6 +107,10 @@ class JobPost extends Model
'parking_access_notes' => $this->parking_access_notes,
'onsite_restrictions' => $this->onsite_restrictions,
'supplemental_instructions' => $this->supplemental_instructions,
'required_technician_level' => $this->required_technician_level,
'technician_level' => $this->technicianLevel()['name'],
'work_category' => $this->workCategory?->name,
'work_specialty' => $this->workSpecialty?->name,
];
}
@@ -152,6 +168,10 @@ class JobPost extends Model
$flags[] = 'compressed_schedule';
}
if ((int) $this->required_technician_level <= 1 && ($this->required_certifications || str_contains(strtolower((string) $this->primary_objective.' '.$this->included_work), 'troubleshoot'))) {
$flags[] = 'level_scope_mismatch';
}
return array_values(array_unique($flags));
}
@@ -173,4 +193,9 @@ class JobPost extends Model
return 'clear';
}
public function technicianLevel(): array
{
return config('technician-levels')[(int) $this->required_technician_level] ?? config('technician-levels')[1];
}
}
+15 -1
View File
@@ -4,13 +4,14 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Model;
#[Fillable([
'user_id', 'business_name', 'headline', 'bio', 'service_area', 'skills',
'services', 'tools', 'tool_inventory', 'certifications', 'certification_records',
'max_technician_level', 'services', 'tools', 'tool_inventory', 'certifications', 'certification_records',
'insurance_status', 'rate_card', 'travel_policy', 'availability_notes',
'website_url', 'phone', 'public_contact', 'profile_visibility', 'private_notes',
])]
@@ -24,6 +25,7 @@ class ProviderProfile extends Model
'certification_records' => 'array',
'profile_visibility' => 'array',
'public_contact' => 'boolean',
'max_technician_level' => 'integer',
];
}
@@ -47,6 +49,18 @@ class ProviderProfile extends Model
return $this->morphMany(Rating::class, 'rateable');
}
public function taxonomyTerms(): BelongsToMany
{
return $this->belongsToMany(TaxonomyTerm::class)
->withPivot('evidence_source')
->withTimestamps();
}
public function technicianLevel(): array
{
return config('technician-levels')[(int) $this->max_technician_level] ?? config('technician-levels')[1];
}
public function visible(string $field): bool
{
$visibility = $this->profile_visibility ?? [];
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
#[Fillable(['parent_id', 'type', 'name', 'slug', 'description', 'sort_order', 'is_active'])]
class TaxonomyTerm extends Model
{
public const TYPES = [
'work_category',
'work_specialty',
'skill',
'tool',
'certification',
];
protected function casts(): array
{
return [
'is_active' => 'boolean',
];
}
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
}
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id');
}
public function providerProfiles(): BelongsToMany
{
return $this->belongsToMany(ProviderProfile::class)
->withPivot('evidence_source')
->withTimestamps();
}
}
+7
View File
@@ -198,4 +198,11 @@ class WorkOrder extends Model
->whereIn('event_type', ['contact_failed', 'support_unavailable', 'site_contact_unavailable'])
->count();
}
public function technicianLevel(): array
{
$level = $this->scopeSnapshotValue('required_technician_level') ?? $this->jobPost?->required_technician_level ?? 1;
return config('technician-levels')[(int) $level] ?? config('technician-levels')[1];
}
}