dyjh 6 年之前
父节点
当前提交
3925657aec
共有 1 个文件被更改,包括 153 次插入78 次删除
  1. 153 78
      app/Http/Controllers/Api/V1/AlbumController.php

+ 153 - 78
app/Http/Controllers/Api/V1/AlbumController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -128,7 +128,7 @@ class AlbumController extends Controller
             return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
         }
         $this->wechat_app = AlbumManufacturerModel::where('store_id',$datas['store_id'])->first();
-        if(!$this->wechat_app) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        if(!$this->wechat_app) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '厂家参数未初始化!', $validator->messages());
         $config = [
             'app_id' => $this->wechat_app->xyx_id,
             'secret' => $this->wechat_app->xyx_secret,
@@ -154,56 +154,56 @@ class AlbumController extends Controller
             $check = AlbumUserModel::where('wechat_union_id', $decryptedData['unionId'])->first();
         }
 
-            if(!$check){
-                $add['username'] = preg_replace('/[\xf0-\xf7].{3}/', '', $datas['nickName']);
-                $add['open_id'] = $res['openid'];
-                $add['wechat_union_id'] = isset($decryptedData['unionId'])?$decryptedData['unionId']:'';
-                $add['avatar'] = $datas['avatar'];
-                $add['is_agent'] = 0;
-                $add['model'] = 1;
-                $add['store_id'] = $datas['store_id'];
-                $res = AlbumUserModel::create($add);
-              //  dd($res);
-                if($res){
-                    $check = AlbumUserModel::where([['wechat_union_id',$res->wechat_union_id],['store_id',$datas['store_id']]])->first();
-                    $user = [
-                        'user_id'=>$check['id'],
-                        //'avatar'=>$check['avatar'],
-                       // 'username'=>$check['username'],
-                        'phone'=>$check->phone,
-                        'is_agent'=>0,
-                        'agent_id'=>'',
-                    ];
-                }else{
-                    $user=[
-                        'error'=>1
-                    ];
-                }
-            } else {
-                //print_r($check);die;
-                $save['username'] = preg_replace('/[\xf0-\xf7].{3}/', '', $datas['nickName']);
-                $save['avatar'] = $datas['avatar'];
-               // $save['open_id'] = $res['openid'];
-                $save['model'] = 1;
-                AlbumUserModel::where('open_id',$res['openid'])->update($save);
-                //echo 111;
-                    //print_r($check);die;
-                if($check->is_dealer == 1){
-                    $user_agent = AlbumAgentModel::where([['user_id',$check->id],['status',1]])->first();
-                    $agent_id = $user_agent['id'];
-                } else {
-                    $agent_id = '';
-                }
+        if(!$check){
+            $add['username'] = preg_replace('/[\xf0-\xf7].{3}/', '', $datas['nickName']);
+            $add['open_id'] = $res['openid'];
+            $add['wechat_union_id'] = isset($decryptedData['unionId'])?$decryptedData['unionId']:'';
+            $add['avatar'] = $datas['avatar'];
+            $add['is_agent'] = 0;
+            $add['model'] = 1;
+            $add['store_id'] = $datas['store_id'];
+            $res = AlbumUserModel::create($add);
+            //  dd($res);
+            if($res){
+                $check = AlbumUserModel::where([['wechat_union_id',$res->wechat_union_id],['store_id',$datas['store_id']]])->first();
                 $user = [
-
-                    'user_id'=>$check->id,
+                    'user_id'=>$check['id'],
+                    //'avatar'=>$check['avatar'],
+                    // 'username'=>$check['username'],
                     'phone'=>$check->phone,
-                    'is_agent'=>$check->is_dealer,
-                    'agent_id'=>$agent_id,
-
+                    'is_agent'=>0,
+                    'agent_id'=>'',
+                ];
+            }else{
+                $user=[
+                    'error'=>1
                 ];
             }
-       // echo 111;die;
+        } else {
+            //print_r($check);die;
+            $save['username'] = preg_replace('/[\xf0-\xf7].{3}/', '', $datas['nickName']);
+            $save['avatar'] = $datas['avatar'];
+            // $save['open_id'] = $res['openid'];
+            $save['model'] = 1;
+            AlbumUserModel::where('open_id',$res['openid'])->update($save);
+            //echo 111;
+            //print_r($check);die;
+            if($check->is_dealer == 1){
+                $user_agent = AlbumAgentModel::where([['user_id',$check->id],['status',1]])->first();
+                $agent_id = $user_agent['id'];
+            } else {
+                $agent_id = '';
+            }
+            $user = [
+
+                'user_id'=>$check->id,
+                'phone'=>$check->phone,
+                'is_agent'=>$check->is_dealer,
+                'agent_id'=>$agent_id,
+
+            ];
+        }
+        // echo 111;die;
         if (Auth::loginUsingId($check->id)) {
             $userAuth = Auth::user();
             if($check->is_dealer ==0){
@@ -216,8 +216,8 @@ class AlbumController extends Controller
                 $add_record['store_id'] = $datas['store_id'];
                 $add_record['detail'] = null;
                 AlbumWatchRecord::create($add_record);
-             //   dd($add_record);
-               // print_r($add_record['agent_id']);die;
+                //   dd($add_record);
+                // print_r($add_record['agent_id']);die;
                 $user_agent = AlbumAgentModel::where('id',$add_record['agent_id'])->first();
                 //dd($user_agent);
                 if($user_agent){
@@ -384,6 +384,13 @@ class AlbumController extends Controller
             $goods->where('style',$style);
         }
 
+        if ($userAuth->up_agent_id != 0) {
+            $agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
+            $set_show_price = $agent->is_show_ma_price;
+        } else {
+            $set_show_price = 0;
+        }
+
 
         $goods = $goods->select('id','cover_pic','thumb','name','style','hot_cake','news','price_default')->orderByDesc('sort')->paginate(9);
 
@@ -412,7 +419,7 @@ class AlbumController extends Controller
         }
         $data =AlbumManufacturerModel::where('store_id',$store_id)->first();
         $name = $data['name'];
-        return $this->api(compact('goods','name'));
+        return $this->api(compact('goods','name','set_show_price'));
     }
 
 
@@ -471,7 +478,7 @@ class AlbumController extends Controller
      */
     public function albumGoodsDetail(Request $request)
     {
-      //  $userAuth = AlbumXyxUserModel::find(1);
+        //  $userAuth = AlbumXyxUserModel::find(1);
         $userAuth = Auth('api')->user();
         if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
         $validator = Validator::make($request->all(), [
@@ -759,7 +766,7 @@ class AlbumController extends Controller
             }
 
             $user = AlbumUserModel::where([['open_id',$val->open_id],['store_id',$val->store_id]])->select(['username','avatar','phone'])->first();
-           // dd(111);
+            // dd(111);
             $data_res[] = [
                 'time'=>$val->created_at,
                 'action'=>$action,
@@ -1057,7 +1064,7 @@ class AlbumController extends Controller
         $end= date('Y-m-d H:i:s',$end);
         $start= date('Y-m-d H:i:s',$start);
         if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
-       // if($userAuth->up_agent_id==0) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未选择经销商!', $validator->messages());
+        // if($userAuth->up_agent_id==0) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未选择经销商!', $validator->messages());
         $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
         $count_user = AlbumWatchRecord::where([['agent_id',$user_agent->id],['store_id',$store_id],['updated_at','>=',$start],['updated_at','<=',$end]])->orderBy('id','DESC')->groupBy('open_id')->get();
         $checkAllstart = mktime(0,0,0,date('m'),date('d'),date('Y'));
@@ -1511,22 +1518,22 @@ class AlbumController extends Controller
         $save = array();
         $return_data = array();
 
-            $save['price'] = $data['price'];
-            $check = AlbumProductPriceModel::where([['agent_id',$agent_id],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->first();
-            if(empty($check)){
-                $save['agent_id'] = $agent_id;
-                $save['store_id'] = $data['store_id'];
-                $save['product_id'] = $data['goods_id'];
-                $res = AlbumProductPriceModel::create($save);
-            }else{
-                $res = AlbumProductPriceModel::where([['agent_id',$agent_id],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->update($save);
-            }
-            if($res){
-                $return['msg'] = 'success';
-                $return_data['price'] = $data['price'];
-            } else {
-                $return['msg'] = 'error';
-            }
+        $save['price'] = $data['price'];
+        $check = AlbumProductPriceModel::where([['agent_id',$agent_id],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->first();
+        if(empty($check)){
+            $save['agent_id'] = $agent_id;
+            $save['store_id'] = $data['store_id'];
+            $save['product_id'] = $data['goods_id'];
+            $res = AlbumProductPriceModel::create($save);
+        }else{
+            $res = AlbumProductPriceModel::where([['agent_id',$agent_id],['store_id',$data['store_id']],['product_id',$data['goods_id']]])->update($save);
+        }
+        if($res){
+            $return['msg'] = 'success';
+            $return_data['price'] = $data['price'];
+        } else {
+            $return['msg'] = 'error';
+        }
 
         $return['data'] = $return_data;
         return $this->api($return);
@@ -1679,7 +1686,7 @@ class AlbumController extends Controller
             $add_record['action'] = $data['type'];
             $add_record['store_id'] = $data['store_id'];
             $add_record['detail'] = json_encode($select_info);
-           // dd($add_record);
+            // dd($add_record);
             $res = AlbumWatchRecord::create($add_record);
             $user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
             $agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
@@ -1755,7 +1762,7 @@ class AlbumController extends Controller
         $weChatApp = AlbumManufacturerModel::where('store_id', $storeid)->first();//\Log::info('2221');
 
         $res_account = $this->accountMesage($g_open_id,$weChatApp,$name,$content);
-     //   \Log::info($res_account);
+        //   \Log::info($res_account);
         if($user && $formId && (!$weChatApp->G_app_id || !$weChatApp->G_app_secret)){
             $config_app = [
                 'app_id' => $weChatApp->app_id,
@@ -1774,7 +1781,7 @@ class AlbumController extends Controller
                     'keyword3' => date('Y-m-d H:i'),
                 ],
             ]);
-          //  dd($res);
+            //  dd($res);
             if($res){
                 $formId->delete();
             }
@@ -1795,7 +1802,7 @@ class AlbumController extends Controller
      */
     private function accountMesage($g_open_id,$weChatApp,$name,$content)
     {
-       // Cache::flush();
+        // Cache::flush();
         $value = Cache::get($g_open_id);
         \Log::info($value);\Log::info('2225');
         if ($g_open_id && (!$value || ($value + 60) <= time())) {
@@ -1878,7 +1885,7 @@ class AlbumController extends Controller
             return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
         }
         $data = $request->input();
-        $url = "https://apis.map.qq.com/ws/geocoder/v1/?address=".$data['address']."&key=U5DBZ-X5VCO-6UUWV-SGPU3-PD5X2-NDFXA";
+        $url = "https://apis.map.qq.com/ws/geocoder/v1/?address=".$data['address']."&key=TD5BZ-GP5RD-PTE4M-PXHFN-6Q5RO-MUBFU";
         $local = $this->curl_get($url);
         $res = json_decode($local,true);
         $agent_check = AlbumAgentModel::where([['store_id',$data['store_id']],['user_id',$userAuth->id]])->first();
@@ -2072,7 +2079,7 @@ class AlbumController extends Controller
         $open_id = $request->input('open_id');
 
         if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
-       $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
+        $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
         $customer = CustomerDetailsModel::where([['store_id',$store_id],['open_id',$open_id],['agent_id',$user_agent->id]])->first(['purpose_level','comment','tips','address']);
         if(!empty($customer)){
             $user = AlbumUserModel::where([['store_id',$store_id],['open_id',$open_id]])->first();
@@ -2158,10 +2165,10 @@ class AlbumController extends Controller
         }
         $customer = CustomerDetailsModel::where([['store_id',$store_id],['open_id',$open_id],['agent_id',$user_agent->id]])->first(['purpose_level','comment','tips','address']);
         if($customer){
-           /// $customer->$key = $value;
+            /// $customer->$key = $value;
             $update[$key] = $value;
             CustomerDetailsModel::where([['store_id',$store_id],['open_id',$open_id],['agent_id',$user_agent->id]])->update($update);
-          //  $customer->save();
+            //  $customer->save();
         }else{
             $add['agent_id'] = $user_agent->id;
             $add['open_id'] = $open_id;
@@ -2370,7 +2377,7 @@ class AlbumController extends Controller
             }
 
             $res[$key]['name'] = $goods->name;
-           // dd($res);
+            // dd($res);
             $res[$key]['count'] = AlbumFavoriteModel::whereIn('user_id',$users)->where([['store_id',$store_id],['product_id',$val['product_id']]])->count();
         }
         return $this->api($res,0,'success');
@@ -2584,4 +2591,72 @@ class AlbumController extends Controller
         }
         return $this->api(compact('res'));
     }
+
+
+    /**
+     * @api {post} /api/album/agent_price_set 厂家价格设置(agent_price_set)
+     * @apiDescription 厂家价格设置(agent_price_set)
+     * @apiGroup Album
+     * @apiPermission AUTH
+     * @apiVersion 0.1.0
+     * @apiParam {int}    [store_id]  商户id
+     * @apiParam {int}    [point]  价格设置比例 为0不设置
+     * @apiParam {int}    [is_show_ma_price]  厂家价格是否可见 0 不可见 1 可见
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "status": true,
+     *     "status_code": 0,
+     *     "message": "success",
+     *     "data":[]
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     */
+    public function albumAgentPriceSet(Request $request)
+    {
+        $userAuth = Auth('api')->user();
+        if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
+        $validator = Validator::make($request->all(), [
+            'is_show_ma_price' => 'required',
+            'store_id' => 'required',
+            'point' => 'required',
+        ],[
+            'is_show_ma_price.required'=>'缺少设置参数',
+            'store_id.required' => '缺少store参数',
+            'point.required'=>'缺少比例参数',
+        ]);
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $data = $request->input();
+        if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
+        $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
+        $user_agent->is_show_ma_price = $data['is_show_ma_price'];
+        $user_agent->save();
+        if ($data['point'] != 0) {
+            $product = AlbumProductModel::where('store_id',$data['store_id'])->all('id','price_default');
+            foreach ($product as $key=>$val) {
+                $save['price'] = $val['price_default'] * $data['point']/100;
+                $check = AlbumProductPriceModel::where([['agent_id',$user_agent->id],['store_id',$data['store_id']],['product_id',$val['id']]])->first();
+                if(empty($check)){
+                    $save['agent_id'] = $user_agent->id;
+                    $save['store_id'] = $data['store_id'];
+                    $save['product_id'] = $val['id'];
+                    AlbumProductPriceModel::create($save);
+                }else{
+                    AlbumProductPriceModel::where([['agent_id',$user_agent->id],['store_id',$data['store_id']],['product_id',$val['id']]])->update($save);
+                }
+            }
+        }
+        return $this->api([],0,'success');
+    }
 }