dyjh 6 years ago
parent
commit
7d41ea9b57
1 changed files with 66 additions and 70 deletions
  1. 66 70
      app/Http/Controllers/Api/V1/AlbumController.php

+ 66 - 70
app/Http/Controllers/Api/V1/AlbumController.php

xqd xqd xqd xqd xqd
@@ -299,7 +299,6 @@ class AlbumController extends Controller
      * @apiVersion 0.1.0
      * @apiParam {int}    [cat_id]  分类id
      * @apiParam {string}    [keywords]  关键词.
-     * @apiParam {int}    [status]  状态  1 只选择热销 2 只选择最新上市 3只选择一个风格 4 同时选择热销和最新上市 5同时选择热销和风格 6同时选择最新上市和风格 7全选 0全不选
      * @apiParam {int}    [style]  风格
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
@@ -336,15 +335,15 @@ class AlbumController extends Controller
     public function albumGoods(Request $request)
     {
         $userAuth = Auth('api')->user();
-        if(!$userAuth) return $this->error(ErrorCode::ERROR_POWER, '登陆过期!');
+        if (!$userAuth) {
+            return $this->error(ErrorCode::ERROR_POWER, '登陆过期!');
+        }
         $validator = Validator::make($request->all(), [
             'cat_id' => 'required',
             'store_id' => 'required',
-            'status' => 'required',
-        ],[
-            'cat_id.required'=>'缺少分类参数',
-            'store_id.required'=>'缺少商户参数',
-            'status.required'=>'缺少状态参数',
+        ], [
+            'cat_id.required' => '缺少分类参数',
+            'store_id.required' => '缺少商户参数',
         ]);
         if ($validator->fails()) {
             return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
@@ -353,81 +352,74 @@ class AlbumController extends Controller
         //dd($data);
         $cat_id = request('cat_id');
         $store_id = request('store_id');
-        $status = request('status');
-        $style = request('style');
+        $parent_id = request('parent_id');
+        $style = request('style_id');
 
-        $select_info = ['cat_id'=>$cat_id,'style'=>$style];
-        if($userAuth->up_agent_id!=0&&$cat_id!="undefined"&&$style!="undefined"){
+        $select_info = ['cat_id' => $cat_id, 'style' => $style];
+        if ($userAuth->up_agent_id != 0 && $cat_id != "undefined" && $parent_id != "undefined") {
             $add_record['agent_id'] = $userAuth->up_agent_id;
             $add_record['open_id'] = $userAuth->open_id;
             $add_record['action'] = 2;
             $add_record['store_id'] = $store_id;
             $add_record['detail'] = json_encode($select_info);
             AlbumWatchRecord::create($add_record);
-            $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
-            $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
-            try{
-                $this->sendLogsMessage($store_id,$agent->open_id,2,$userAuth->username,$agent->g_open_id);
-            }catch (\Exception $e){
-
+            $user_agent = AlbumAgentModel::where('id', $userAuth->up_agent_id)->first();
+            $agent = AlbumUserModel::where('id', $user_agent->user_id)->first();
+            try {
+                $this->sendLogsMessage($store_id, $agent->open_id, 2, $userAuth->username, $agent->g_open_id);
+            } catch (\Exception $e) {
+                \Log::info($e);
             }
         }
-        if(isset($data['keywords'])&&!empty($data['keywords'])) {
-            $keywords = '%'.$data['keywords'].'%';
-            $goods = AlbumProductModel::where([['name','like',$keywords],['store_id',$data['store_id']],['cat_id',$cat_id],['store_id',$store_id]]);
+        if (isset($data['keywords']) && !empty($data['keywords'])) {
+            $keywords = '%' . $data['keywords'] . '%';
+            $goods = AlbumProductModel::where([
+                ['name','like',$keywords],['store_id',$data['store_id']],['cat_id',$cat_id],['store_id',$store_id]]);
         } else {
             $goods = AlbumProductModel::where([['cat_id',$cat_id],['store_id',$store_id]]);
         }
-        if($status == 1) {
-            $goods->where([['hot_cake', 1]]);
-        }
-        if($status == 2){
-            $goods->where('news',1);
-        }
-        if($status == 3){
-            $goods->where('style',$style);
-        }
 
         if ($userAuth->up_agent_id != 0) {
-            $agent_in = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
+            $agent_in = AlbumAgentModel::where('id', $userAuth->up_agent_id)->first();
             $set_show_price = $agent_in->is_show_ma_price;
         } else {
             $set_show_price = 0;
         }
 
         if ($userAuth->is_dealer == 1) {
-            $agent_me = AlbumAgentModel::where('user_id',$userAuth->id)->first();
+            $agent_me = AlbumAgentModel::where('user_id', $userAuth->id)->first();
             $set_show_price = $agent_me->is_show_ma_price;
         }
 
-        $goods = $goods->select('id','cover_pic','thumb','name','style','hot_cake','news','price_default','ma_price','ma_price_comment')->orderByDesc('sort')->paginate(9);
+        $goods = $goods->select('id', 'cover_pic', 'thumb', 'name', 'style', 'hot_cake', 'news', 'price_default', 'ma_price', 'ma_price_comment')
+            ->orderByDesc('sort')->paginate(9);
 
-        foreach($goods as $key =>$val){
-            if($userAuth->is_dealer != 1){
-                if($userAuth->up_agent_id==0){
+        foreach ($goods as $key => $val) {
+            if ($userAuth->is_dealer != 1) {
+                if ($userAuth->up_agent_id == 0) {
                     $goods[$key]['price'] = '';
-                }else{
+                } else {
                     $check = AlbumProductPriceModel::where([['agent_id',$userAuth->up_agent_id],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
-                    if($check){
+                    if ($check) {
                         $goods[$key]['price'] = $check->price;
-                    }else{
+                    } else {
                         $goods[$key]['price'] = '';
                     }
                 }
-            }elseif($userAuth->is_dealer == 1){
-                $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
+            } elseif ($userAuth->is_dealer == 1) {
+                $user_agent = AlbumAgentModel::where('user_id', $userAuth->id)->first();
                 $agent_id = $user_agent['id'];
                 $check = AlbumProductPriceModel::where([['agent_id',$agent_id],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
-                if($check){
+                if ($check) {
                     $goods[$key]['price'] = $check->price;
-                }else{
+                } else {
                     $goods[$key]['price'] = '';
                 }
             }
         }
-        $data =AlbumManufacturerModel::where('store_id',$store_id)->first();
+        $data = AlbumManufacturerModel::where('store_id', $store_id)->first();
         $name = $data['name'];
-        return $this->api(compact('goods','name','set_show_price'));
+        return $this->api(compact('goods', 'name', 'set_show_price'));
     }
 
 
@@ -488,21 +480,23 @@ class AlbumController extends Controller
     {
         //  $userAuth = AlbumXyxUserModel::find(1);
         $userAuth = Auth('api')->user();
-        if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
+        if (!$userAuth) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
+        }
         $validator = Validator::make($request->all(), [
             'goods_id' => 'required',
             'store_id' => 'required',
-        ],[
-            'goods_id.required'=>'缺少商品参数',
-            'store_id_id.required'=>'缺少STORE参数',
+        ], [
+            'goods_id.required' => '缺少商品参数',
+            'store_id_id.required' => '缺少STORE参数',
         ]);
         if ($validator->fails()) {
             return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
         }
         $goods_id = request('goods_id');
         $store_id = request('store_id');
-        $select_info = ['goods_id'=>$goods_id];
-        if($userAuth->up_agent_id!=0){
+        $select_info = ['goods_id' => $goods_id];
+        if ($userAuth->up_agent_id != 0) {
             $add_record['agent_id'] = $userAuth->up_agent_id;
             $add_record['open_id'] = $userAuth->open_id;
             $add_record['action'] = 3;
@@ -510,59 +504,61 @@ class AlbumController extends Controller
             $add_record['detail'] = json_encode($select_info);
             AlbumWatchRecord::create($add_record);
 
-            $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
-            $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
-            try{
-                $this->sendLogsMessage($store_id,$agent->open_id,3,$userAuth->username,$agent->g_open_id);
-            }catch (\Exception $e){
-
+            $user_agent = AlbumAgentModel::where('id', $userAuth->up_agent_id)->first();
+            $agent = AlbumUserModel::where('id', $user_agent->user_id)->first();
+            try {
+                $this->sendLogsMessage($store_id, $agent->open_id, 3, $userAuth->username, $agent->g_open_id);
+            } catch (\Exception $e) {
+                \Log::info($e);
             }
         }
-        $ma = AlbumManufacturerModel::where('store_id',$store_id)->first();
+        $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();
+        $address = AlbumAgentModel::where('id', $userAuth->up_agent_id)->first();
         $cat_record['agent_id'] = $userAuth->up_agent_id;
         $cat_record['open_id'] = $userAuth->open_id;
         $cat_record['store_id'] = $store_id;
         $cat_record['style_id'] = $goods->style;
         $cat_record['cat_id'] = $goods->cat_id;
         CustomerCatRecordModel::create($cat_record);
-        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)){
+        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;
-            }else{
+            } else {
                 $goods->price = '';
             }
             $check_favorite = AlbumFavoriteModel::where([['user_id',$userAuth->id],['store_id',$store_id],['product_id',$goods['id']]])->first();
             //dd($check_favorite);
-            if($check_favorite){
+            if ($check_favorite) {
                 $goods->is_favorite = 1;
                 $goods->favorite_id = $check_favorite->id;
-            }else{
+            } else {
                 $goods->is_favorite = 0;
                 $goods->favorite_id = '';
             }
-        }elseif(!empty($goods) && $userAuth->is_dealer == 1){
+        } elseif (!empty($goods) && $userAuth->is_dealer == 1) {
             $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)){
+            if (!empty($price)) {
                 $goods->price = $price->price;
-            }else{
+            } else {
                 $goods->price = '';
             }
 
             $goods->is_favorite = 0;
             $goods->favorite_id = '';
         }
-        if($userAuth->up_agent_id == 0 || !$address){
+        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{
-            $agent = AlbumUserModel::where('id',$address->user_id)->first();
+        } else {
+            $agent = AlbumUserModel::where('id', $address->user_id)->first();
             $goods->mobile = $address->phone;
             $goods->address = $address->address;
             $goods->realname = $address->name;