public function postBuy(Request $request)
 {
     $user = \App\User::find(1);
     $user->charge($request->get('price'), ['source' => $request->get('stripeToken'), 'receipt_email' => $user->email]);
     $services = new \App\Services();
     $services->Username = $request->get('account');
     $services->Attribute = "MD5-Password";
     $services->op = ":=";
     $services->Value = md5($request->get('password'));
     $services->save();
     $purchesed = new \App\Purchesed();
     $purchesed->Username = $request->get('account');
     $purchesed->PassWord = $request->get('password');
     $purchesed->user_id = $user->id;
     // 3000 半年套餐 - Half Year $30 USD
     // 5000 一年套餐 - One Year $50 USD (半年后可换海龟套餐)
     // 9000 两年套餐 - Two Year $90 USD (可随时切换海龟套餐)
     // 8800 一年双套餐 - One Year With Project Beijing $88 USD (推荐)
     if ($request->get('price') == 3000) {
         $serviceNameSet = "云端套餐 30 USD 半年套餐";
     }
     if ($request->get('price') == 5000) {
         $serviceNameSet = "云端套餐 50 USD 一年套餐";
     }
     if ($request->get('price') == 9000) {
         $serviceNameSet = "云端套餐 90 USD 两年套餐";
     }
     if ($request->get('price') == 8800) {
         $serviceNameSet = "云端海龟套餐 88 USD 一年套餐";
     }
     $purchesed->ServiceName = $serviceNameSet;
     $purchesed->save();
     return redirect($this->homePath());
 }
예제 #2
0
파일: Product.php 프로젝트: KingSloff/POS
 /**
  * Reorder point
  */
 public function getReorderPointAttribute()
 {
     $result = $this->average_daily_demand * $this->average_lead_time + Services::normSInv(0.95) * sqrt($this->average_lead_time * pow($this->sd_daily_demand, 2) + pow($this->average_daily_demand, 2) * pow($this->sd_lead_time, 2));
     return ceil($result);
 }
예제 #3
0
 /**
  * Checkout event
  *
  * @param CheckoutRequest $request
  * @param Cart $cart
  * @return \Illuminate\Http\RedirectResponse
  */
 public function checkout(CheckoutRequest $request, Cart $cart)
 {
     foreach ($cart->cart_items as $cartItem) {
         $numberToDeduct = $cartItem->amount;
         $product = $cartItem->product;
         if ($product->in_stock < $numberToDeduct) {
             return redirect()->route('checkout.index')->withErrors('Not enough of product: ' . $product->name);
         }
     }
     $cash = $request->has('cash');
     $total = $cart->total();
     $change = 0;
     if ($cash) {
         $amountGiven = $request->amountGiven;
         if ($amountGiven < $total) {
             return redirect()->route('checkout.index')->withErrors('Not enough money given');
         } else {
             $change = $amountGiven - $total;
         }
     }
     DB::transaction(function () use($request, $cart, $cash, $total) {
         if (!$cash) {
             $user = User::findOrFail($request->user_id);
         }
         foreach ($cart->cart_items as $cartItem) {
             $numberToDeduct = $cartItem->amount;
             $product = $cartItem->product;
             if (!$cash) {
                 $user->balance -= $product->price * $numberToDeduct;
             }
             $stocks = $product->stocks()->hasStock()->get();
             foreach ($stocks as $stock) {
                 if ($stock->in_stock == 0) {
                     continue;
                 }
                 if ($stock->in_stock - $numberToDeduct >= 0) {
                     $stock->in_stock -= $numberToDeduct;
                     $stock->save();
                     if (!$cash) {
                         $product->sales()->create(['price' => $product->price, 'amount' => $numberToDeduct, 'cpu' => $stock->cpu, 'user_id' => $request->user_id]);
                     } else {
                         $product->sales()->create(['price' => $product->price, 'amount' => $numberToDeduct, 'cpu' => $stock->cpu]);
                     }
                     break;
                 } else {
                     if (!$cash) {
                         $product->sales()->create(['price' => $product->price, 'amount' => $stock->in_stock, 'cpu' => $stock->cpu, 'user_id' => $request->user_id]);
                     } else {
                         $product->sales()->create(['price' => $product->price, 'amount' => $stock->in_stock, 'cpu' => $stock->cpu]);
                     }
                     $numberToDeduct -= $stock->in_stock;
                     $stock->in_stock = 0;
                     $stock->save();
                 }
             }
             $product->updateStock();
             $cartItem->delete();
         }
         if (!$cash) {
             $user->save();
             $services = new Services();
             $user->logs()->create(['title' => 'Goods Purchased', 'description' => $services->displayCurrency($total) . ' worth of items have been purchased.', 'details' => "Balance\t=>\t" . $services->displayCurrency($user->balance)]);
         }
     });
     if ($change == 0) {
         return redirect()->route('checkout.index')->with('success', 'Purchase made');
     } else {
         $service = new Services();
         return redirect()->route('checkout.index')->with('success', 'Purchase made. Change: ' . $service->displayCurrency($change));
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     Services::create($input);
     return Redirect::route('services.index')->with('message', 'Service created');
 }
예제 #5
0
 /**
  * Loan an amount
  *
  * @param LoanUserRequest $request
  * @param  User $user
  * @return \Illuminate\Http\Response
  */
 public function loan(LoanUserRequest $request, User $user)
 {
     DB::transaction(function () use($request, $user) {
         $user->balance -= $request->amountToLoan;
         $user->save();
         $services = new Services();
         $user->payments()->create(['amount' => -$request->amountToLoan]);
         $user->logs()->create(['title' => 'Amount Loaned', 'description' => $services->displayCurrency($request->amountToLoan) . ' has been loaned.', 'details' => "Balance\t=>\t" . $services->displayCurrency($user->balance)]);
     });
     return redirect()->route('user.show', $user)->with('success', 'Amount Loaned');
 }
예제 #6
0
 public static function init()
 {
     Services::registerServices();
 }