Bläddra i källkod

project contact

Andrew 3 veckor sedan
förälder
incheckning
4e8556e367

+ 5
- 5
app/Filament/Resources/ProjectResource.php Visa fil

@@ -175,14 +175,13 @@ class ProjectResource extends Resource
175 175
                     Tab::make('專案資訊')->schema([
176 176
                         Group::make()->schema([
177 177
                             Translate::make()->schema(fn(string $locale) => [
178
-                                //                                TextInput::make('contact_unit')->label('物管單位'),
179
-                                TextInput::make('contact_phone')->label('物管電話'),
180
-                                TextInput::make('inversment_phone')->label('招商電話'),
178
+                                RichEditor::make('contact')->label('聯絡資訊')
179
+                                    ->toolbarButtons(['bold', 'italic', 'underline', 'link', 'redo', 'undo']),
181 180
                             ])
182 181
                                 ->locales(['zh_TW', 'en'])
183 182
                                 ->actions([
184
-                                    app(DeepLService::class)->createTranslationAction('contact', ['contact_unit', 'contact_phone', 'inversment_phone']),
185
-                                ])->columnSpanFull()->columns(3)
183
+                                    app(DeepLService::class)->createTranslationAction('contact', ['contact']),
184
+                                ])->columnSpanFull()->columns(1)
186 185
                                 ->id('contact'),
187 186
                             TextInput::make('offical_link')->label('官網連結'),
188 187
                         ])->columnSpanFull(),
@@ -227,6 +226,7 @@ class ProjectResource extends Resource
227 226
                 ImageColumn::make('first_list_img_url')->label('列表圖')->alignCenter(),
228 227
                 TextColumn::make('region.name')->label('地址')->alignCenter()
229 228
                     ->formatStateUsing(fn($record) => $record->region->getTranslation('name', 'zh_TW') . ' | ' . $record->getTranslation('address', 'zh_TW')),
229
+                TextColumn::make('contact')->label('物管資訊')->alignCenter()->html()->limit(50),
230 230
             ])
231 231
             ->filters([
232 232
                 SelectFilter::make('visible')->label('上/下架')

+ 1
- 3
app/Http/Controllers/Api/ProjectController.php Visa fil

@@ -121,9 +121,7 @@ class ProjectController extends Controller
121 121
             'badge_type' => $project->badge_type,
122 122
             'badges' => $project->getBadgesByType($locale, $project->badge_type),
123 123
             'contact_info' => [
124
-                'unitName' => $project->getTranslation('contact_unit', $locale),
125
-                'unitPhone' => $project->getTranslation('contact_phone', $locale),
126
-                'inversmentPhone' => $project->getTranslation('inversment_phone', $locale),
124
+                'contact' => $project->getTranslation('contact', $locale),
127 125
                 'officalLink' => $project->offical_link,
128 126
             ],
129 127
             'spaceInfo' => $projectSpaceInfo,

+ 1
- 1
app/Models/Project.php Visa fil

@@ -15,7 +15,7 @@ class Project extends Model
15 15
     protected $guarded = ['id'];
16 16
 
17 17
     protected $translatable = ['name', 'sub_name', 'summaries', 'img_alt', 'address', 'floor_plan',
18
-        'building_structure', 'design_unit', 'contact_unit', 'contact_phone', 'inversment_phone', 'district',
18
+        'building_structure', 'design_unit', 'contact', 'district',
19 19
     ];
20 20
 
21 21
     protected $casts = ['img_url' => 'array', 'mobile_img_url' => 'array'];

+ 78
- 0
database/migrations/2026_01_08_092407_merge_contact_and_inversment_phone_columns_in_projects_table.php Visa fil

@@ -0,0 +1,78 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\DB;
6
+use Illuminate\Support\Facades\Schema;
7
+
8
+return new class extends Migration
9
+{
10
+    /**
11
+     * Run the migrations.
12
+     */
13
+    public function up(): void
14
+    {
15
+        Schema::table('projects', function (Blueprint $table) {
16
+            $table->json('contact')->nullable()->after('design_unit');
17
+        });
18
+
19
+        $projects = DB::table('projects')->get();
20
+
21
+        foreach ($projects as $project) {
22
+            $contactUnit = json_decode($project->contact_unit, true);
23
+            $contactPhone = json_decode($project->contact_phone, true);
24
+            $inversmentPhone = json_decode($project->inversment_phone, true);
25
+
26
+            $contact = [];
27
+
28
+            if (is_array($contactUnit)) {
29
+                foreach ($contactUnit as $locale => $value) {
30
+                    $contact[$locale] = $value;
31
+                }
32
+            }
33
+
34
+            if (is_array($contactPhone)) {
35
+                foreach ($contactPhone as $locale => $value) {
36
+                    if (isset($contact[$locale])) {
37
+                        $contact[$locale] .= ' ' . $value;
38
+                    } else {
39
+                        $contact[$locale] = $value;
40
+                    }
41
+                }
42
+            }
43
+            
44
+            if (is_array($inversmentPhone)) {
45
+                foreach ($inversmentPhone as $locale => $value) {
46
+                    if (isset($contact[$locale])) {
47
+                        $contact[$locale] .= ' ' . $value;
48
+                    } else {
49
+                        $contact[$locale] = $value;
50
+                    }
51
+                }
52
+            }
53
+
54
+            DB::table('projects')
55
+                ->where('id', $project->id)
56
+                ->update(['contact' => json_encode($contact)]);
57
+        }
58
+
59
+        Schema::table('projects', function (Blueprint $table) {
60
+            $table->dropColumn('contact_unit');
61
+            $table->dropColumn('contact_phone');
62
+            $table->dropColumn('inversment_phone');
63
+        });
64
+    }
65
+
66
+    /**
67
+     * Reverse the migrations.
68
+     */
69
+    public function down(): void
70
+    {
71
+        Schema::table('projects', function (Blueprint $table) {
72
+            $table->json('contact_unit')->nullable();
73
+            $table->json('contact_phone')->nullable();
74
+            $table->json('inversment_phone')->nullable();
75
+            $table->dropColumn('contact');
76
+        });
77
+    }
78
+};