public function create(Request $request, Offer $offer) { if ($request->user()->cannot('edit-offer', [$offer])) { abort(403); } $this->validate($request, ['offer' => 'required|integer', 'num' => 'required|integer|min:1', 'title' => 'required|min:3', 'description' => 'required|min:3', 'real_amount' => 'required|integer', 'pay_amount' => 'required|integer']); $user = Auth::user(); $input = $request->all(); //check if the service is valid or not $service = CouponGallery::where('id', $input['offer'])->firstOrFail(); if ($service->expired_at < Carbon::now()) { abort(403); } $coupon = $user->coupons()->create(['offer_id' => $offer->id, 'coupon_gallery_id' => $input['offer'], 'title' => $input['title'], 'description' => $input['description'], 'real_amount' => $input['real_amount'], 'pay_amount' => $input['pay_amount'], 'num' => $input['num']]); return ['hasCallback' => '1', 'callback' => 'service_coupon', 'hasMsg' => 0, 'msg' => '', 'returns' => $offer->coupons()->with('coupon_gallery')->get()]; }
/** * Show the application welcome screen to the user. * * @return Response */ public function index() { $offers = Offer::where('status', '=', 1)->take(5)->get(); $this->data['offers'] = $offers; $products = Product::where('status', '=', 1)->get(); foreach ($products as $product) { $rank = $product->rank()->first(); if (count($rank)) { array_set($product, 'rank', $rank->rank); } $image = $product->images()->first(); array_set($product, 'image', $image['file']); } $this->data['products'] = $products; $brochures = Brochure::where('status', '=', 1)->get(); $count = 0; foreach ($brochures as $brochure) { $rank = $brochure->rank()->first(); if (count($rank)) { array_set($brochure, 'rank', $rank->rank); $count++; } if ($count == 4) { break; } } $this->data['brochures'] = $brochures; $data = $this->data; return view('index', $data); }
public function store(Requests\SaveCommentRequest $request, $offer_id) { $offer = Offer::findOrFail($offer_id); if (Gate::denies('add-comment', $offer)) { abort(403); } $comment = new Comment(); $comment->fill($request->input()); $comment->user_id = Auth::user()->id; $comment->offer_id = $offer_id; $comment->save(); $violation = $offer->violation; // Send email $user_type = Auth::user()->getOriginal('user_type'); if ($user_type == 'cus') { $to = $offer->author->username; $email = $offer->author->email; } else { $to = $violation->author->username; $email = $violation->author->email; } $poster_name = Auth::user()->username; $address = $violation_name = $violation->address1 . ', ' . $violation->city . ' (' . $violation->getOriginal('state') . ') ' . $violation->zip; $data = compact('user_type', 'to', 'poster_name', 'address', 'offer_id'); Mail::send('emails.newcomment', $data, function ($message) use($email) { $message->subject('New Comment Posted'); $message->to($email); }); // Flash message Session::flash('message', 'Your comment has been posted to the offer.'); Session::flash('message-type', 'success'); // Redirect return redirect(url('/offer/' . $offer_id . '#comment_' . $comment->id)); }
public function store($offer_id, Request $request) { $offer = Offer::findOrFail($offer_id); if (Gate::denies('close-offer', $offer)) { abort(403); } $rate = new Rate(); $rate->fill($request->input()); $rate->pro_id = Auth::user()->id; $rate->offer_id = $offer_id; $rate->save(); $offer->status = 6; $offer->save(); // Send email $violation = $offer->violation; $violation->status = 6; $violation->save(); $email = $offer->author->email; $to = $offer->author->username; $customer_name = $offer->violation->author->username; $address = $violation_name = $violation->address1 . ', ' . $violation->city . ' (' . $violation->getOriginal('state') . ') ' . $violation->zip; $offer_id = $offer->id; $data = compact('to', 'customer_name', 'address', 'offer_id'); Mail::send('emails.offerclosed', $data, function ($message) use($email) { $message->subject('You have been reviewed!'); $message->to($email); }); // Flash message Session::flash('message', 'You have submitted a review and closed this offer.'); Session::flash('message-type', 'success'); // Redirect return redirect()->action('OfferController@show', [$offer_id]); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $offer = new Offer(); $image = ''; $filename = str_random(25) . '.' . $request->file('image')->getClientOriginalExtension(); // dd($request); if ($request->hasFile('image')) { $request->file('image')->move(public_path() . '/uploads/offers/', $filename); $image = '/uploads/offers/' . $filename; } $offer->title = $request->get('title'); $offer->image = $image; $offer->description = $request->get('description'); $offer->content = $request->get('content'); $offer->url = $request->get('url'); $offer->code = $request->get('code'); $offer->save(); alert()->success('The new offer was successfully created', 'Alright!'); return redirect()->intended('backend/offers'); }
public function deny($id) { $offer = Offer::find($id); $poster = User::findOrFail($offer->post_creator); $user = User::findOrFail($offer->user_id); Mail::send('emails.offerDenied', ['user' => $user, 'offer' => $offer, 'poster' => $poster], function ($m) use($user) { $m->to($user->email, $user->name)->subject('Offer Denied'); }); $offer->delete(); return Redirect('/admin/dashboard')->with('message', 'Post created'); }
/** * Bind data to the view. * * @param View $view * @return void */ public function compose(View $view) { if (Auth::check()) { $offers = Offer::where('post_creator', Auth::user()->id)->whereHas('post', function ($q) { $q->where('sold', NULL); })->orderBy('created_at', 'desc')->count(); } else { $offers = ""; } $categories = Category::all(); $view->with(['categories' => $categories, 'offers' => $offers]); }
/** * Show the application dashboard to the user. * * @return Response */ public function dashboard() { $user = User::find(Auth::user()->id); $communitys = Community::all()->lists('name', 'id'); $feedbacksGiven = Feedback::where('giver_id', Auth::user()->id)->get(); $feedbacks = Feedback::where('receiver_id', Auth::user()->id)->get(); $activePosts = Post::where('user_id', Auth::user()->id)->where('sold', null)->get(); $offers = Offer::where('post_creator', Auth::user()->id)->whereHas('post', function ($q) { $q->where('sold', NULL); })->orderBy('created_at', 'desc')->get(); return view('pages.dashboard', ['user' => $user, 'communities' => $communitys, 'offers' => $offers, 'feedbacks' => $feedbacks, 'activePosts' => $activePosts, 'feedbacksGiven' => $feedbacksGiven]); }
public function postDelete(Request $request, $id) { $offer = Offer::where('id', $id)->first(); if ($offer != null) { $offer->delete(); $msg = "Предложение \"" . $offer->title . "\" удалено."; return redirect('admin/offer')->with('msg', $msg); } else { $msg = "Предложения с id = " . $id . " не существует."; return redirect('admin/offer')->with('msg', $msg); } }
public function getOffers(Request $request) { if ($request->input('id') == null) { $offers = Offer::all(); return view('home.offers')->with('offers', $offers); } else { $offer = Offer::where('id', $request->input('id'))->first(); if ($offer == null) { return redirect('offers'); } return view('home.offer')->with('offer', $offer); } }
public function getTakeorder(Request $request, $shop_id, $offer_id, $product_amount) { $user = $request->user(); $business = Business::apiFind($shop_id); $offer = Offer::apiFind($shop_id, $offer_id); $coupon_id = $request->input('coupon_id'); $item = Order::item($offer_id, $product_amount); $check = Offer::apiCheck($item, $shop_id, $coupon_id); $mobile = $request->input('mobile'); $touch = $request->input('touch'); $sex = $request->input('sex'); $url = '/business/takeorder/' . $shop_id . '/' . $offer_id . '/' . $product_amount . '?mobile=' . $mobile . '&touch=' . $touch . '&sex=' . $sex; session(['url' => $url]); return view('auth.business.takeorder', ['TITLE' => '下单', 'META_KEYWORDS' => META_KEYWORDS, 'META_DESC' => META_DESC, 'PAGE_CODE' => 'auth.business.takeorder', 'user' => $user, 'business' => $business, 'offer' => $offer, 'check' => $check, 'product_amount' => $product_amount, 'mobile' => $mobile, 'touch' => $touch, 'sex' => $sex, 'coupon_id' => $coupon_id, 'url' => $url]); }
/** * Bind data to the view. * * @param View $view * @return void */ public function compose(View $view) { $categories = Category::with('children', 'products')->where('parent_id', '=', 0)->orderBy('did')->get(); $hotpros_id = Salesstats::groupBy('product_id')->take(16)->get(); $hotpros_id = $hotpros_id->lists('product_id'); $hotpros = Product::with('images')->has('images')->has('prices')->wherein('id', $hotpros_id)->take(16)->get(); $globals = DB::table('globalsettings')->get(); $dts = DB::table('deliverytimes')->where('active', true)->get(); foreach ($dts as $dt) { $dt->start = Carbon::parse($dt->start)->format('h:ia'); $dt->stop = Carbon::parse($dt->stop)->format('h:ia'); } $settings = []; foreach ($globals as $global) { $name = $global->name; $value = $global->value; $settings[$name] = $value; } $offers = Offer::with(['categories', 'categories.products' => function ($q) { $q->has('images'); }, 'brands', 'brands.products' => function ($q) { $q->has('images'); }, 'products' => function ($q) { $q->has('images'); }, 'products.images', 'products.prices'])->where('active', true)->where('start', '<=', Carbon::today()->toDateString())->where('end', '>=', Carbon::today()->toDateString())->take(16)->get(); //dd($offers); $feedbacks = Feedback::with('user')->take(8)->get(); if ($user = Sentinel::check()) { $user = User::findorfail($user->id); $flashes = Flashtext::where('active', '1')->get(); $areas = Area::where('deliverable', '1')->get(); $viewpros_id = Viewstats::where('user_id', $user->id)->take(16)->get(); //dd($viewpros_id); $viewpros_id = $viewpros_id->lists('product_id'); $viewpros = Product::with('images')->has('images')->has('prices')->wherein('id', $viewpros_id)->take(16)->get(); $view->with(['user' => $user, 'flashes' => $flashes, 'areas' => $areas, 'hotpros' => $hotpros, 'viewpros' => $viewpros, 'offers' => $offers, 'settings' => $settings, 'dts' => $dts, 'feedbacks' => $feedbacks, 'categories' => $categories]); } else { $flashes = Flashtext::where('active', '1')->get(); $areas = Area::where('deliverable', '1')->get(); $viewpros_id = Viewstats::where('user_id', 0)->take(16)->get(); $viewpros_id = $viewpros_id->lists('product_id'); $viewpros = Product::with('images')->has('images')->has('prices')->wherein('id', $viewpros_id)->take(16)->get(); $view->with(['flashes' => $flashes, 'areas' => $areas, 'hotpros' => $hotpros, 'viewpros' => $viewpros, 'offers' => $offers, 'settings' => $settings, 'dts' => $dts, 'feedbacks' => $feedbacks, 'categories' => $categories]); } }
public function store($offer_id, Requests\SaveConditionRequest $request) { // Find offer to make sure it exists $offer = Offer::findOrFail($offer_id); if (Gate::denies('add-condition', $offer)) { abort(403); } // Create new condition and save $condition = new Condition(); $condition->fill($request->input()); $condition->offer_id = $offer_id; $condition->pro_id = Auth::user()->id; $condition->save(); // Flash message Session::flash('message', 'You have added a new condition to the offer.'); Session::flash('message-type', 'success'); // Redirect return redirect(url('/offer/' . $offer_id . '#conditions')); }
public function postAddoffer(request $request) { $user = $request->user(); $offer_id = $request->input('offer_id'); $product_amount = $request->input('product_amount'); $item = Order::item($offer_id, $product_amount); $shop_id = $request->input('shop_id'); $coupon_id = $request->input('coupon_id'); $mobile = $request->input('mobile'); $touch = $request->input('touch'); $sex = $request->input('sex'); $url = $request->input('url'); $response = Offer::apiCheck($item, $shop_id, $coupon_id); if ($response) { $params = ['item_id' => $shop_id, 'item' => $item, 'mobile' => $mobile, 'touch' => $touch, 'sex' => $sex]; if ($coupon_id) { $params['coupon_id'] = $coupon_id; } $order = Order::apiCreateZd($params); if (is_object($order)) { $business = new Business(env('WECHAT_APPID'), env('WECHAT_APPSECRET'), env('WECHAT_MCHID'), env('WECHAT_KEY')); $wxorder = new WxOrder(); $wxorder->body = $order->odrno; $wxorder->out_trade_no = $order->odrno; $wxorder->total_fee = $order->final * 100; // 单位为 “分”, 字符串类型 $wxorder->openid = $user->user_open_id; $wxorder->notify_url = API_PAY_CALLBACK_URL; $unifiedOrder = new UnifiedOrder($business, $wxorder); $payment = new Payment($unifiedOrder); $res = redirect('/pay')->with(['payment' => $payment, 'order' => $order, 'wxorder' => $wxorder, 'url' => $url, 'type' => 'ZD']); } else { $res = redirect()->back()->with('msgError', $order); } } else { $res = redirect()->back()->with('msgError', '订单信息错误'); } return $res; }
/** * Display the specified resource. * * @param $slug * @return Response */ public function show($slug) { $offer = Offer::where('slug', $slug)->first(); return view('account.offers.show', compact('offer')); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // Offer::destroy($id); return back(); }
public function adminServiceIndex(User $user, Offer $offer) { $services = $offer->coupon_gallery()->paginate(20); return view('admin.offer.service.index', compact('user', 'offer', 'services'))->with(['title' => 'Offer Service Management']); }
public function showOffer($id) { $offer = Offer::findOrFail($id); return view('home.show_offer', compact('offer')); }
/** * log the buy * * @param $user \App\User * @param $offer \App\Offer * @return Response the image download */ public function logBuy(User $user, Offer $offer) { if ($user->toArray() == [] || $offer->toArray() == []) { \App::abort(404, 'The API doesn\'t exist'); } $userRepo = new UserRepository($user); $userRepo->logBuy($offer); return json_encode(["points" => $userRepo->getUserPoints(), "level" => $userRepo->getUserLevel()->id]); }
/** * Test deletion of an offer. */ public function test_it_delete_offer_with_no_subscriptions() { // Generate new offer $offer = factory(App\Offer::class)->create(); // Make sure offer was inserted $this->seeInDatabase('offers', ['id' => $offer->id]); // Delete offer from database Offer::find($offer->id)->delete(); // Check if offer was deleted $this->notSeeInDatabase('offers', ['id' => $offer->id]); }
/** * Delete the given Offer. * * @param int $id * @return Redirect */ public function getDelete($id = null) { $offer = Offer::destroy($id); // Redirect to the group management page return redirect('admin/offers')->with('success', Lang::get('message.success.delete')); }
public function offerShow($offer) { if (Agent::isMobile()) { $offer = Offer::active()->identifier($offer)->whereHas('websites', function ($q) { $q->where('id', $this->website_id); })->with(['contents' => function ($query) { $query->where('lang_id', '=', $this->langId); }])->orderBy('priority', 'desc')->first(); } else { $offer = Offer::active()->identifier($offer)->whereHas('websites', function ($q) { $q->where('id', $this->website_id); })->with(['contents' => function ($query) { $query->where('lang_id', '=', $this->langId); }])->where('mobile_only', 0)->first(); } if ($offer) { $resorts = Resort::active()->whereHas('offers', function ($q) use($offer) { $q->where('id', $offer->id); })->with(['contents' => function ($query) { $query->where('lang_id', '=', $this->langId); }])->get(); $all_offers = Offer::active()->range()->whereHas('resorts', function ($q) use($resorts) { $q->where('id', $resorts[0]->id); })->whereHas('websites', function ($q) { $q->where('id', $this->website_id); })->with(['contents' => function ($query) { $query->where('lang_id', '=', $this->langId); }])->where('mobile_only', 0)->orderBy('priority', 'desc')->get()->take(3); return View('pages.offer ', compact('offer', 'all_offers')); } else { abort(404); } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $offer = Offer::findOrFail($id)->isOwnedOrFail(); foreach ($offer->pictures as $picture) { unlink(storage_path('app/pictures/pic_' . $picture->id)); $picture->delete(); } $offer->delete(); flash()->success('Gelöscht.'); return redirect('host/offers'); }
public function buenFinGRM() { /* consulto las promos vigentes del hotel para mostrarlas como opciones si la promo está no vigente */ $offer = Offer::active()->range()->whereHas('resorts', function ($q) { $q->whereIn('id', [6]); })->with(['websites' => function ($q) { $q->where('id', '7'); }])->with(['contents' => function ($query) { $query->where('lang_id', '=', '1'); }])->where('mobile_only', 0)->where('main', 1)->orderBy('priority', 'desc')->first(); return View("pages.offer-buenfin16-grm", compact('offer')); }
public function offerShow($offer) { if (Agent::isMobile()) { $offer = Offer::active()->identifier($offer)->whereHas('websites', function ($q) { $q->where('id', $this->website_id); })->with(['contents' => function ($query) { $query->where('lang_id', '=', $this->langId); }])->orderBy('priority', 'desc')->first(); } else { $offer = Offer::active()->identifier($offer)->whereHas('websites', function ($q) { $q->where('id', $this->website_id); })->with(['contents' => function ($query) { $query->where('lang_id', '=', $this->langId); }])->where('mobile_only', 0)->orderBy('priority', 'desc')->first(); } if ($offer) { $travel_window = App\OfferTravelWindow::where('offer_id', $offer->id)->orderBy('start_date', 'asc')->get(); $resorts = Resort::active()->whereHas('offers', function ($q) use($offer) { $q->where('id', $offer->id); })->with(['contents' => function ($query) { $query->where('lang_id', '=', $this->langId); }])->get(); $offer_resort = App\OfferResort::where('offer_id', $offer->id)->get(); $i = 0; foreach ($resorts as $key => $value) { //offer_resort2 almacena los datos necesarios en un solo vector para llevar al formulario. for ($k = 0; $k < count($offer_resort); $k++) { if ($value->id == $offer_resort[$k]['resort_id']) { $offer_resort2[$i]['ihotelier_rate_id'] = $offer_resort[$k]['ihotelier_rate_id']; $offer_resort2[$i]['minimum'] = $offer_resort[$k]['minimum']; $offer_resort2[$i]['id'] = $value->id; $offer_resort2[$i]['name'] = $value->name; $offer_resort2[$i]['ihotelier_id'] = $value->ihotelier_id; $offer_resort2[$i]['area'] = $value->area; } } $i++; } $all_offers = Offer::active()->range()->whereHas('resorts', function ($q) use($resorts) { $q->where('id', $resorts[0]->id); })->whereHas('websites', function ($q) { $q->where('id', $this->website_id); })->with(['contents' => function ($query) { $query->where('lang_id', '=', $this->langId); }])->where('mobile_only', 0)->orderBy('priority', 'desc')->get()->take(3); return View('pages.offer ', compact('offer', 'resorts', 'all_offers', 'offer_resort2', 'travel_window')); } else { abort(404); } }
public function report_completed($offer_id) { $offer = Offer::findOrFail($offer_id); if (Gate::denies('complete-offer', $offer)) { abort(403); } // Update offer $offer->status = 5; $offer->save(); // Update violation $violation = $offer->violation; $violation->status = 5; $violation->save(); // Send email to the pro $email = $offer->violation->author->email; $to = $offer->violation->author->username; $pro_name = $offer->author->username; $address = $violation_name = $violation->address1 . ', ' . $violation->city . ' (' . $violation->getOriginal('state') . ') ' . $violation->zip; $offer_id = $offer->id; $data = compact('to', 'pro_name', 'address', 'offer_id'); Mail::send('emails.offercompleted', $data, function ($message) use($email) { $message->subject('Offer Completed!'); $message->to($email); }); // Flash message Session::flash('message', 'You have reported that you have completed solving this violation. The customer <b>' . $violation->author->username . '</b> needs to review before it can be closed.'); Session::flash('message-type', 'success'); // Redirect return redirect()->action('OfferController@show', [$offer_id]); }
public function index() { return Offer::all(); }
public function deactivate($id) { $offer = Offer::find($id); $offer->status = 0; $offer->save(); return redirect('home/offers'); }
/** * Register any application authentication / authorization services. * * @param \Illuminate\Contracts\Auth\Access\Gate $gate * @return void */ public function boot(GateContract $gate) { $this->registerPolicies($gate); // USERS $gate->define('see-email', function ($user, $profile) { if ($user->id == $profile->id or $user->id == 1) { return true; } else { return false; } }); // VIOLATIONS // Create (only Customers) $gate->define('create-violation', function ($user) { return $user->getOriginal('user_type') == 'cus'; }); // Edit (only Author) $gate->define('edit-violation', function ($user, $violation) { return $violation->user_id == $user->id; }); // Delete (only Author) $gate->define('delete-violation', function ($user, $violation) { return $violation->user_id == $user->id; }); // OFFERS $gate->define('see-offers', function ($user) { return $user->getOriginal('user_type') == 'pro'; }); // Create (only Pros) $gate->define('create-offer', function ($user) { return $user->getOriginal('user_type') == 'pro'; }); // Edit (only Author) $gate->define('edit-offer', function ($user, $offer) { if ($offer->author->id == $user->id and $offer->getOriginal('status') < 1) { return true; } else { return false; } }); // Delete (only Author) $gate->define('delete-offer', function ($user, $offer) { if ($offer->author->id == $user->id and $offer->getOriginal('status') < 1) { return true; } return false; }); // Full view (only author of Violation and author of Offer) $gate->define('full-view-offer', function ($user, $offer) { if ($offer->author->id == $user->id or $offer->violation->author->id == $user->id) { return true; } else { return false; } }); // Send offer (only Pros) $gate->define('send-offer', function ($user, $violation) { $offers = \App\Offer::where(['violation_id' => $violation->id, 'pro_id' => $user->id])->get(); if (count($offers)) { return false; } else { return true; } }); // Award Offer (only Customers) $gate->define('award-offer', function ($user, $offer) { if ($offer->violation->user_id == $user->id and $offer->getOriginal('status') == 0 and $offer->violation->getOriginal('status') == 0) { return true; } else { return false; } }); // Remove Award offer (only customer) $gate->define('remove-award', function ($user, $offer) { if ($offer->violation->author->id == $user->id and $offer->getOriginal('status') > 0 and $offer->getOriginal('status') < 3) { return true; } else { return false; } }); // Submit comments $gate->define('add-comment', function ($user, $offer) { if ($user->id == $offer->violation->user_id or $user->id == $offer->author->id) { return true; } else { return false; } }); // Submit conditions $gate->define('submit-conditions', function ($user, $offer) { if ($user->id == $offer->author->id and count($offer->conditions) > 0 and $offer->getOriginal('status') > 0 and $offer->getOriginal('status') < 2) { return true; } else { return false; } }); // Add new condition $gate->define('add-condition', function ($user, $offer) { if ($user->id == $offer->author->id and $offer->getOriginal('status') > 0 and $offer->getOriginal('status') < 3) { return true; } else { return false; } }); // Delete condition $gate->define('delete-condition', function ($user, $condition) { $offer = $condition->offer; if ($user->id == $offer->author->id and $user->id == $condition->author->id and $offer->getOriginal('status') > 0 and $offer->getOriginal('status') < 3) { return true; } else { return false; } }); // Accept Offer Conditions $gate->define('accept-conditions', function ($user, $offer) { if ($user->id == $offer->violation->author->id and $offer->getOriginal('status') == 2) { return true; } else { return false; } }); // Pay Offer $gate->define('pay-offer', function ($user, $offer) { if ($user->id == $offer->violation->author->id and $offer->getOriginal('status') == 3 and !$offer->paid) { return true; } else { return false; } }); // Can compelte order $gate->define('complete-offer', function ($user, $offer) { if ($user->id == $offer->author->id and $offer->getOriginal('status') == 4) { return true; } else { return false; } }); // Can close the offer $gate->define('close-offer', function ($user, $offer) { if ($user->id == $offer->violation->author->id and $offer->getOriginal('status') == 5) { return true; } else { return false; } }); }
/** * Delete offer. * * @param DeleteOfferRequest $request * @return mixed */ public function deleteOffer(DeleteOfferRequest $request) { // Find offer $offer = Offer::find($request->get('offer_id')); // Delete all subscriptions that belongs to this offer Subscription::where('offer_id', $offer->id)->delete(); // Delete offer $offer->delete(); // Return success response $response = new AjaxResponse(); $response->setSuccessMessage(trans('offers.offer_deleted')); return response($response->get())->header('Content-Type', 'application/json'); }