dyjh %!s(int64=6) %!d(string=hai) anos
pai
achega
76c4792bf9
Modificáronse 1 ficheiros con 16 adicións e 18 borrados
  1. 16 18
      app/Http/Controllers/Api/V1/AlbumController.php

+ 16 - 18
app/Http/Controllers/Api/V1/AlbumController.php

xqd xqd
@@ -563,23 +563,15 @@ class AlbumController extends Controller
 
             }
         }
+        $ma = AlbumManufacturerModel::where('store_id',$store_id)->first();
         $goods = AlbumProductModel::where([['id',$goods_id],['store_id',$store_id]])->first();
+        $address = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
         if(!empty($goods) && $userAuth->is_dealer != 1){
             $price = DB::table('album_product_price')->where([['agent_id',$userAuth->up_agent_id],['store_id',$store_id],['product_id',$goods['id']]])->first();
             if(!empty($price)){
                 $goods->price = $price->price;
-                $goods->mobile = $price->mobile;
-                $address = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
-                $goods->address = $address->address;
-                $goods->realname = $address->realname;
-                $goods->avatar = $address->avatar;
             }else{
-                $ma = AlbumManufacturerModel::where('store_id',$store_id)->first();
                 $goods->price = '';
-                $goods->mobile = $ma->phone;
-                $goods->address = $ma->address;
-                $goods->realname = $ma->name;
-                $goods->avatar = $ma->avatar;
             }
             $check_favorite = AlbumFavoriteModel::where([['user_id',$userAuth->id],['store_id',$store_id],['product_id',$goods['id']]])->first();
             //dd($check_favorite);
@@ -591,23 +583,29 @@ class AlbumController extends Controller
                 $goods->favorite_id = '';
             }
         }elseif(!empty($goods) && $userAuth->is_dealer == 1){
-            $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
-            $agent_id = $user_agent['id'];
+            $agent_id = $address['id'];
             $price = DB::table('album_product_price')->where([['agent_id',$agent_id],['store_id',$store_id],['product_id',$goods['id']]])->first();
             if(!empty($price)){
                 $goods->price = $price->price;
-                $goods->mobile = $price->mobile;
             }else{
                 $goods->price = '';
-                $goods->mobile = '';
             }
-            $address = AlbumAgentModel::where('id',$agent_id)->first();
-            $goods->address = $address->address;
-            $goods->realname = $address->realname;
+
             $goods->is_favorite = 0;
             $goods->favorite_id = '';
         }
-
+        if($userAuth->up_agent_id == 0 || !$address){
+            $goods->price = '';
+            $goods->mobile = $ma->phone;
+            $goods->address = $ma->address;
+            $goods->realname = $ma->name;
+            $goods->avatar = $ma->avatar;
+        }else{
+            $goods->mobile = $address->phone;
+            $goods->address = $address->address;
+            $goods->realname = $address->name;
+            $goods->avatar = $address->avatar;
+        }
         return $this->api($goods);
     }