zilong преди 4 години
родител
ревизия
0d870e4eb4

+ 1 - 1
app/Http/Controllers/Api/V1/OrderController.php

xqd
@@ -428,7 +428,7 @@ class OrderController extends AuthController
             $addPatient['patient_id'] = $req['patient_id'];
             OrderPatient::create($addPatient);
             //保存订单服务包表
-            $addPack = ServicePack::select(['id as service_pack_id', 'name as pack_name', 'intro as pack_intro', 'price as pack_price', 'insurance_policy', 'insurance_img_url', 'team_id', 'phone_minutes', 'chat_num', 'appoint_num', 'vaccine_limit_amount', 'nurses_limit_amount', 'effective_days'])->where('id', $req['service_pack_id'])->first()->getOriginal();
+            $addPack = ServicePack::select(['id as service_pack_id', 'name as pack_name', 'intro as pack_intro', 'price as pack_price', 'insurance_policy', 'insurance_img_url', 'team_id', 'phone_minutes', 'chat_num', 'appoint_num', 'vaccine_limit_amount', 'nurses_limit_amount', 'effective_days', 'label'])->where('id', $req['service_pack_id'])->first()->getOriginal();
             $addPack['user_id'] = $user['id'];
             $addPack['order_id'] = $order['id'];
             $addPack['is_security'] = $req['is_security'];

+ 5 - 1
app/Http/Controllers/Api/V1/ServicePackController.php

xqd xqd
@@ -9,6 +9,7 @@
 namespace App\Http\Controllers\Api\V1;
 
 use App\Models\ServicePack;
+use App\Models\Team;
 
 class ServicePackController extends AuthController
 {
@@ -26,7 +27,10 @@ class ServicePackController extends AuthController
             'service_pack_id' => 'required|integer'
         ]);
 
-        $data = ServicePack::with('team.docter.office', 'team.docter.qualification')->where('id', $req['service_pack_id'])->first();
+        $data = ServicePack::where('id', $req['service_pack_id'])->first()->toArray();
+        if (!empty($data['team_id'])) {
+            $data['team'] = Team::with(['docter.office', 'docter.qualification'])->whereIn('id', $data['team_id'])->get()->toArray();
+        }
 
         return out($data);
     }

+ 20 - 5
app/Models/OrderPack.php

xqd
@@ -10,20 +10,35 @@ namespace App\Models;
 
 class OrderPack extends BaseModel
 {
-    public function team()
-    {
-        return $this->belongsTo(Team::class);
-    }
+    protected $appends = ['label_texts'];
+    protected $casts = [
+        'label' => 'json',
+        'team_id' => 'json'
+    ];
 
     public function order()
     {
         return $this->belongsTo(Order::class);
     }
 
-    public function user(){
+    public function user()
+    {
         return $this->belongsTo(User::class);
     }
 
+    public function getLabelTextsAttribute()
+    {
+        $data = [];
+        if (!empty($this->label)) {
+            $map = config('config.pack_label_map');
+            foreach ($this->label as $k => $v) {
+                $data[$k]['name'] = $map[$v]??'';
+            }
+        }
+
+        return $data;
+    }
+
     public static function checkUserServicePack($order_pack_id, $user_id, $product_type, $payment_amount)
     {
         $data = self::where('id', $order_pack_id)->where('user_id', $user_id)->first();

+ 0 - 4
app/Models/ServicePack.php

xqd
@@ -16,10 +16,6 @@ class ServicePack extends BaseModel
         'label' => 'json',
         'team_id' => 'json'
     ];
-    public function team()
-    {
-        return $this->belongsToMany(Team::class);
-    }
 
     public function getLabelTextsAttribute()
     {