public function getDashboard() { $now = Carbon::now(); $date = Carbon::now(); $date->subWeek(); $output = ['aUsers' => User::where('status', true)->count(), 'iUsers' => User::where('status', false)->count(), 'aStores' => MerchantStore::where('status', true)->count(), 'iStores' => MerchantStore::where('status', false)->count(), 'today' => Offers::where('startDate', '<=', $now)->where('endDate', '>=', $now)->count(), 'future' => Offers::where('startDate', '>', $now)->count(), 'past' => Offers::where('endDate', '<', $now)->count(), 'week_aUsers' => User::where('status', true)->where('created_at', '>', $date->toDateTimeString())->count(), 'week_iUsers' => User::where('status', false)->where('created_at', '>', $date->toDateTimeString())->count(), 'week_offers' => Offers::where('startDate', '>', $date->toDateTimeString())->where('endDate', '<=', $now)->count(), 'uber_rides' => '0']; return view('admin.dashboard', $output); }
public function getSuperMerchantEdit($id) { $matchThese = ['id' => $id, 'status' => true, 'is_parent' => true, 'is_child' => false]; $parent = MerchantStore::where($matchThese)->with('Address.Area')->first(); if (empty($parent)) { return 'No Store Exists'; } $matchThese = ['parent_id' => $parent->id, 'status' => true, 'is_parent' => false, 'is_child' => true]; $childs = MerchantStore::where($matchThese)->with('Address.Area')->get(); $matchThese = ['status' => true, 'is_parent' => false, 'is_child' => false]; $excludedStores = MerchantStore::with(['Address.Area'])->where($matchThese)->orderby('id', 'DESC')->get(); // $output = ['parent' => $parent, 'childs' => $childs, 'excludedStores' => $excludedStores]; return view('admin.editSuperMerchant', $output); }
protected function checkUserHasStore($store_id, $checkStatus) { $hasStore = false; $storeId = Auth::user()->stores->id; if ($store_id == $storeId) { $hasStore = true; } if ($checkStatus) { $store = MerchantStore::where('id', $store_id)->first(); if (!$store->status) { $hasStore = false; } } return $hasStore; }
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]); }
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]); }
public function addOffer(request $request) { $rules = array('title' => 'required', 'fineprint' => 'required', 'startDate' => 'required', 'endDate' => 'required'); $validator = $this->customValidator($request->all(), $rules, array()); if ($validator->fails()) { return response()->json(['status' => 'fail', 'message' => $validator->errors()->all()]); } $is_parent = false; $fineprintArr = explode("\n", $request->input('fineprint')); $fineprint = ''; foreach ($fineprintArr as $value) { if ($value != '' || !empty($value)) { $fineprint .= '<li>' . $value . '</li>'; } } if ($request->has('store_token')) { if ($request->input('store_token') == 'all' && Auth::user()->Stores->is_parent) { $store_id = Auth::user()->Stores->id; $is_parent = true; } else { if ($request->input('store_token') == 'all') { return response()->json(['status' => 'fail', 'message' => 'Not Authorized']); } else { $storeId = Crypt::decrypt($request->input('store_token')); if (!$this->checkUserHasStorePermission($storeId)) { return response()->json(['status' => 'fail', 'message' => 'Not Authorized']); } $store_id = $storeId; } } } else { $store_id = Auth::user()->Stores->id; } $offerInput = $request->only('title', 'startDate', 'endDate'); $offerInput['store_id'] = $store_id; $offerInput['fineprint'] = $fineprint; $offer = Offers::create($offerInput); if ($is_parent) { $offer->is_parent = true; $offer->save(); //creating offer for all sub merchants if user selects and if he is super merchant $matchThese = ['is_child' => true, 'parent_id' => $store_id]; $stores = MerchantStore::where($matchThese)->get(); $offerInp = $request->only('title', 'fineprint', 'startDate', 'endDate'); $offerInp['is_child'] = true; $offerInp['parent_id'] = $offer->id; foreach ($stores as $store) { $offerInp['store_id'] = $store->id; Offers::create($offerInp); } } return response()->json(['status' => 'success']); }