Exemplo n.º 1
0
 /**
  * @param ShopRequest $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function storeShop(ShopRequest $request)
 {
     $attachment = ImageUploadFacade::attachmentUpload($request->file('attachment'), new Attachment(), 'shops');
     $shop = new Shops();
     $shop->capacity = $request->get('capacity');
     $shop->city_id = $request->get('city');
     $shop->paid_at = Carbon::now()->addMonth();
     $shopProfile = new ShopProfile();
     $shopProfile->fill($request->except('attachment'));
     $shopProfile->save();
     $shop->profile()->associate($shopProfile);
     if ($attachment) {
         $shop->attachment()->associate($attachment);
     }
     $page = $request->page;
     $shop->user_id = $request->user_id;
     $shop->save();
     return redirect($page);
 }
Exemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param ShopRequest $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(ShopRequest $request)
 {
     // dd($request->input('category'));
     // 2000 items
     if (\Request::input('capacity') == 2000) {
         // Create transaction
         $payment = new Payment();
         $payment->uid = mt_rand();
         $payment->user_id = Auth::user()->id;
         $payment->description = 'Покупка магазина на 2000 товаров';
         $payment->balance = 1000;
         $payment->operation = '-';
         $payment->save();
         // Check balance
         if (Auth::user()->balance < 1000) {
             \Session::flash('message', 'Недостаточно средств для покупки магазина, пожалуйста пополните баланс.');
             return redirect()->back();
         } else {
             // Create shop
             $attachment = ImageUploadFacade::attachmentUpload($request->file('attachment'), new Attachment(), 'shops');
             $shop = new Shops();
             $shop->capacity = $request->get('capacity');
             $shop->city_id = $request->get('city');
             $shop->category_id = $request->input('category');
             $shop->paid_at = Carbon::now()->addMonth();
             $shopProfile = new ShopProfile();
             $shopProfile->fill($request->except('attachment'));
             $shopProfile->save();
             $shop->profile()->associate($shopProfile);
             if ($attachment) {
                 $shop->attachment()->associate($attachment);
             }
             $shop->user()->associate(Auth::user());
             $shop->save();
             // Update transaction and balance user
             $payment->status = 1;
             $payment->save();
             $modifyBalanceToUser = User::find(\Auth::user()->id);
             $modifyBalanceToUser->balance -= 1000;
             $modifyBalanceToUser->update();
             \Session::flash('message', "Вы купили магазин на 2000 товаров. Спасибо за покупку ;)");
         }
         return redirect()->route('shops.my');
     }
     // 500 items
     if (\Request::input('capacity') == 500) {
         // Create transaction
         $payment = new Payment();
         $payment->uid = mt_rand();
         $payment->user_id = Auth::user()->id;
         $payment->description = 'Покупка магазина на 500 товаров';
         $payment->balance = 500;
         $payment->operation = '-';
         $payment->save();
         // Check balance
         if (Auth::user()->balance < 500) {
             \Session::flash('message', 'Недостаточно средств для покупки магазина, пожалуйста пополните баланс.');
             return redirect()->back();
         } else {
             // Create shop
             $attachment = ImageUploadFacade::attachmentUpload($request->file('attachment'), new Attachment(), 'shops');
             $shop = new Shops();
             $shop->capacity = $request->get('capacity');
             $shop->city_id = $request->get('city');
             $shop->category_id = $request->input('category');
             $shop->paid_at = Carbon::now()->addMonth();
             $shopProfile = new ShopProfile();
             $shopProfile->fill($request->except('attachment'));
             $shopProfile->save();
             $shop->profile()->associate($shopProfile);
             if ($attachment) {
                 $shop->attachment()->associate($attachment);
             }
             $shop->user()->associate(Auth::user());
             $shop->save();
             // Update transaction and balance user
             $payment->status = 1;
             $payment->save();
             $modifyBalanceToUser = User::find(\Auth::user()->id);
             $modifyBalanceToUser->balance -= 500;
             $modifyBalanceToUser->update();
             \Session::flash('message', "Вы купили магазин на 500 товаров. Спасибо за покупку ;)");
         }
         return redirect()->route('shops.my');
     }
 }