Browse Source

feat: 添加获取评价标签列表功能

在OrderController中新增commentTags方法,允许用户获取所有可用的评价标签列表。相应地,在OrderService中实现getCommentTags方法以查询有效的评价标签。同时,更新了验证规则中的标签字段,确保其引用正确的数据库表。此更改提升了用户在评价时的选择性和系统的功能性。
刘学玺 2 months ago
parent
commit
652a487c14

+ 30 - 1
app/Http/Controllers/Client/OrderController.php

@@ -438,7 +438,7 @@ class OrderController extends Controller
             'attitude_score' => 'nullable|numeric|min:1|max:5',
             'professional_score' => 'nullable|numeric|min:1|max:5',
             'tags' => 'nullable|array',
-            'tags.*' => 'integer|exists:comment_tags,id',
+            'tags.*' => 'integer|exists:order_comment_tags,id',
             'content' => 'nullable|string|max:1000',
             'images' => 'nullable|array',
             'images.*' => 'string'
@@ -448,6 +448,35 @@ class OrderController extends Controller
         return $this->success(null, '评价成功');
     }
 
+    /**
+     * [订单]获取评价标签列表
+     *
+     * 获取所有可用的评价标签列表,用于用户评价时选择
+     *
+     * @authenticated
+     *
+     * @response {
+     *   "data": [
+     *     {
+     *       "id": 1,
+     *       "tag_name": "打扫干净"
+     *     },
+     *     {
+     *       "id": 2,
+     *       "tag_name": "工装规范"
+     *     },
+     *     {
+     *       "id": 3,
+     *       "tag_name": "态度端正"
+     *     }
+     *   ]
+     * }
+     */
+    public function commentTags()
+    {
+        return $this->success($this->service->getCommentTags());
+    }
+
     /**
      * [订单]删除订单
      *

+ 24 - 0
app/Models/OrderCommentTag.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class OrderCommentTag extends Model
+{
+    use SoftDeletes;
+
+    protected $table = 'order_comment_tags';
+
+    protected $fillable = [
+        'tag_name',
+        'type',
+        'state'
+    ];
+
+    protected $casts = [
+        'type' => 'integer',
+        'state' => 'integer'
+    ];
+}

+ 14 - 0
app/Services/Client/OrderService.php

@@ -42,6 +42,7 @@ use App\Models\OrderRefundRecord;
 use App\Enums\PaymentType;
 use App\Enums\TransactionStatus;
 use App\Enums\TechnicianWorkStatus;
+use App\Models\OrderCommentTag;
 
 readonly class OrderService
 {
@@ -3166,4 +3167,17 @@ readonly class OrderService
             ];
         });
     }
+
+    /**
+     * 获取评价标签列表
+     *
+     * @return array
+     */
+    public function getCommentTags(): array
+    {
+        return OrderCommentTag::query()
+            ->where('state', 1)
+            ->get(['id', 'tag_name'])
+            ->toArray();
+    }
 }

+ 2 - 0
routes/api.php

@@ -149,6 +149,8 @@ Route::prefix('client')->group(function () {
 
             // 用户删除订单
             Route::delete('{id}', [OrderController::class, 'delete'])->name('client.order.delete');
+
+            Route::get('comment-tags', [OrderController::class, 'commentTags']);
         });
 
         // 团队管理路由