public function store(Request $request) { ///validate data if it is in databse or not $data_to_val = $request->only('product_codes'); $rule = AuctionController::getRule($request); $user = JWTAuth::parseToken()->authenticate(); ///if login $validate = Validator::make($data_to_val, $rule); if ($user->role != 1) { return response()->json(['message', 'invalid Role']); } if ($validate->fails()) { return response()->json($validate->errors()->all()); } ///open new auction $auction = new Auction(); ////add finished time this is added by 1 hr $auction->finished_at = time() + 3600; $auction->buyer()->associate($user); $auction->save(); $products = []; $product_codes = $request->get('product_codes'); foreach ($product_codes as $key => $val) { $product = Product::where(['product_code' => $val])->get()->first(); $products[$key] = $product; } $auction->products()->saveMany($products); if ($auction->products->count() >= 1) { /////Generating Defualt Bid foreach ($product_codes as $val) { $product = Product::where(['product_code' => $val])->get()->first(); $product_descriptions = $product->product_descriptions; $lowest_price_description = ProductController::findLowestPriceProductDescription($product_descriptions); $bid = new Bid(['price' => $lowest_price_description->price]); $bid->seller()->associate($lowest_price_description->seller); $bid->auction()->associate($auction); $bid->save(); $bid->products()->saveMany([$product]); } //// if ($auction->bids->count() >= 1) { $auction->status = 0; //opening $auction->save(); return response()->json(['message', 'success']); } } return response()->json(['message', 'error occurred']); }
public function getProductInfo($code) { ///validate data if it is in databse or not $data_to_validate = ['product_code' => $code]; $rule = ['product_code' => 'required|exists:products,product_code']; try { $user = JWTAuth::parseToken()->authenticate(); if ($user) { $validate = Validator::make($data_to_validate, $rule); if ($validate->fails()) { return response()->json(['message', 'product not existed']); } $product = Product::where($data_to_validate)->get()->first(); $product_des = ProductController::findLowestPriceProductDescription($product->product_descriptions); $data = ['id' => $product_des->id, 'product_code' => $product->product_code, 'name' => $product_des->name, 'price' => $product_des->price]; return response()->json($data); } } catch (JWTException $e) { } return response()->json(['message', 'login please jeeez']); //return json_encode(ProductDescription::findOrFail($id)); }
public function getMenuThree($name, $name1, $name2) { $info = InfoController::getInfo(); $menu = MenuController::getMenu(); $convert = new convertString(); $categorys = CategoryController::getCategory(); $ID = 0; $Name = array("name" => "", "name1" => "", "name2" => ""); $tag = TagController::getTag(); foreach ($menu as $values) { if ($convert->convertString($values->name) == $name) { //$ID = $values->id; $Name["name"] = $values->name; } if ($convert->convertString($values->name) == $name1) { //$ID = $values->id; $Name["name1"] = $values->name; } if ($convert->convertString($values->name) == $name2) { $ID = $values->id; $Name["name2"] = $values->name; } } $header = array("title" => $Name["name2"] . " - Phụ kiện thời trang", "keyword" => $Name["name2"], "description" => $Name["name2"]); $product = ProductController::getAllProductWhereMenuID($ID); if (count($menu) > 0) { $menu = $this->ConvertMenuToArray($menu); } if (count($product) > 0) { return View::make("product.menuproductThree", array('menu' => $menu, "categorys" => $categorys, "convert" => $convert, "info" => $info, "header" => $header, "product" => $product, "tag" => $tag, "Name" => $Name)); } else { return View::make("errors.404"); } }