buildSpecsJson($data); $data['specs_json'] = $specs; $data['intake_source'] = $source; $data['visibility'] = $data['visibility'] ?? 'portal'; $listing = $this->listingService->create($business, $data, $user); if ($request && method_exists($request, 'hasFile')) { $this->mediaService->uploadForListing($business, $listing, $request, $user); } $listing = $this->listingService->submit($business, $listing->fresh(['media']), $user); try { $this->catalogMatchService->discoverMatches($business, $listing->fresh(), true); } catch (\Throwable) { } try { $this->crmBridge->createLeadFromListing($business, $listing->fresh()); } catch (\Throwable) { } $settings = $this->aexUtil->getAexSettings($business->id); if ($settings['auto_start_research_on_intake'] ?? true) { try { $this->researchCaseService->openCase($business, $listing->fresh(), [ 'title' => 'تحقیق اولیه — '.$listing->title, 'spawn_templates' => true, 'lead_researcher_id' => $listing->assigned_broker_user_id, ], $user); } catch (\Throwable) { } } $this->pipelineService->logEvent( $business, Listing::class, $listing->id, 'portal_intake_received', 'دریافت عرضه از پورتال با مشخصات و رسانه', $user, ['source' => $source, 'media_count' => $listing->media()->count()] ); return $listing->fresh(['media', 'seller']); }); } protected function buildSpecsJson(array $data): array { $keys = [ 'power_kw', 'voltage', 'dimensions', 'weight_kg', 'capacity', 'control_system', 'automation_level', 'included_accessories', 'known_defects', 'maintenance_history', 'operating_hours_note', 'custom_fields', ]; $specs = []; foreach ($keys as $key) { if (! empty($data[$key])) { $specs[$key] = $data[$key]; } } if (! empty($data['specs_json']) && is_array($data['specs_json'])) { $specs = array_merge($specs, $data['specs_json']); } return $specs; } }