Пример #1
0
 public function getStoreOffers(request $request, $id, $period)
 {
     $now = Carbon::now();
     if ($period == 'today') {
         $offers = Offers::with('store', 'favouriteCount', 'votesCount')->where('store_id', $id)->where('startDate', '<=', $now)->where('endDate', '>=', $now)->orderby('created_at', 'desc')->paginate(20);
     } elseif ($period == 'future') {
         $offers = Offers::with('store', 'favouriteCount', 'votesCount')->where('store_id', $id)->where('startDate', '>', $now)->orderby('created_at', 'desc')->paginate(20);
     } elseif ($period == 'past') {
         $offers = Offers::with('store', 'favouriteCount', 'votesCount')->where('store_id', $id)->where('endDate', '<', $now)->orderby('created_at', 'desc')->get();
     } else {
         $offers = Offers::with('store', 'favouriteCount', 'votesCount')->where('store_id', $id)->orderby('created_at', 'desc')->paginate(20);
     }
     $store = MerchantStore::with(['Address', 'tags', 'Merchant'])->where('id', $id)->first();
     $output = ['offers' => $offers, 'store' => $store];
     //return $output;
     return view('admin.storeOffers', $output);
 }
Пример #2
0
 public function getAllStoresOffers()
 {
     if (!Auth::User()->Stores->is_parent) {
         return response()->json(['response_code' => 'ERR_IR', 'messages' => 'invalid request'], 400);
     }
     $matchThese = ['status' => true, 'is_child' => true, 'parent_id' => Auth::User()->Stores->id];
     $stores = MerchantStore::where($matchThese)->get();
     $storesArr = [];
     foreach ($stores as $key => $store) {
         $storesArr[$key] = $store->id;
     }
     $offers = Offers::with('Store', 'votesCount')->whereIn('store_id', $storesArr)->orderby('created_at', 'desc')->paginate(15);
     return response()->json(['response_code' => 'RES_OFF', 'messages' => 'Offers', 'data' => $offers]);
 }
Пример #3
0
 protected function login($user, $type)
 {
     $key = Config::get('custom.JWTkey');
     $token = array("sub" => $user->id, "iss" => "http://homestead.app", "iat" => 1356999524, "name" => $user->name, "type" => $type);
     $jwt = JWT::encode($token, $key);
     if ($type == 'merchant') {
         $store = MerchantStore::where('user_id', $user->id)->first();
         if (count($store)) {
             $is_parent = $store->is_parent;
         } else {
             $is_parent = false;
         }
     } else {
         $is_parent = false;
     }
     return response()->json(['response_code' => 'TOKEN', 'data' => $jwt, 'user' => $user, 'is_parent' => $is_parent]);
 }
Пример #4
0
 public function getStoreDetails(request $request)
 {
     $user_id = Auth::user()->id;
     $store = MerchantStore::with('Merchant', 'Address', 'Tags')->where('user_id', $user_id)->first();
     $user = User::where('id', '=', $user_id)->first();
     if ($store == '' || empty($store)) {
         return response()->json(['response_code' => 'RES_SE', 'messages' => 'Store Empty', 'data' => ['user' => $user]]);
     }
     return response()->json(['response_code' => 'RES_SD', 'messages' => 'Store Details', 'data' => ['store' => $store, 'user' => $user]]);
 }
Пример #5
0
 public function editStore(request $request)
 {
     $validator = Validator::make($request->all(), ['store_name' => 'required|max:255', 'landline' => 'required', 'cost_two' => 'required', 'veg' => 'required', 'status' => 'required', 'street' => 'required|max:200', 'area_id' => 'required', 'city_id' => 'required', 'state_id' => 'required', 'country_id' => 'required', 'pincode' => 'required', 'latitude' => 'required', 'longitude' => 'required']);
     $input = $request->only('store_id');
     if ($validator->fails()) {
         return redirect('merchant/store/edit')->withErrors($validator);
     }
     $store_id = Auth::user()->Stores->id;
     $store = MerchantStore::find($store_id);
     foreach ($request->only('store_name', 'veg', 'cost_two', 'landline', 'status', 'description') as $key => $value) {
         $store->{$key} = $value;
     }
     if ($request->hasFile('logo')) {
         $image = $request->file('logo');
         $imageName = strtotime(Carbon::now()) . md5($store_id) . '.' . $image->getClientOriginalExtension();
         $path = public_path('assets/img/stores/' . $imageName);
         Image::make($image->getRealPath())->resize(280, null, function ($constraint) {
             $constraint->aspectRatio();
         })->save($path);
         $store->logoUrl = $imageName;
     }
     $store->save();
     $store->tags()->detach();
     $store->tags()->attach([$request->input('tag_id')]);
     $matchThese = ['store_id' => $store_id];
     $address = MerchantStoreAddress::where($matchThese)->first();
     foreach ($request->only('street', 'area_id', 'city_id', 'state_id', 'country_id', 'pincode', 'latitude', 'longitude') as $key => $value) {
         $address->{$key} = $value;
     }
     $address->save();
     return redirect('merchant/store');
 }