public static function getDetailItem($cart) { $items = []; foreach ($cart as $item) { $tmp = []; $model = new Cd(); $dataModel = $model->where('id', $item['id'])->with('singer')->with('format')->with('composer')->first(); // dd($dataModel); $tmp['singer'] = $dataModel->singer->name; $tmp['format'] = $dataModel->format->name; $tmp['portal'] = $dataModel->portal; $items[] = $tmp; } return $items; }
/** * Run the database seeds. * * @return void */ public function run() { $avt = ['1437634539.jpg', '1437106469.jpg', '1437106714.jpg', '1437106796.jpg', '1437106868.jpg', '1437622106.jpg', '1437808833.jpg', '1437809400.jpg']; $faker = Faker\Factory::create(); for ($i = 0, $j = 32; $i < 15; $i++, $j++) { \App\Cd::create(['name' => $faker->realText(15), 'singer_id' => $faker->numberBetween(32, 46), 'composer_id' => $j, 'format_id' => $faker->numberBetween(1, 4), 'type_id' => $faker->numberBetween(1, 4), 'description' => $faker->text(200), 'quantity' => $faker->numberBetween(20, 50), 'buy_time' => $faker->numberBetween(0, 100), 'status' => 1, 'portal' => $faker->randomElement($avt), 'root_price' => $faker->numberBetween(8, 20), 'price' => $faker->numberBetween(8, 20), 'sale_off' => $faker->numberBetween(0, 10), 'public_date' => \Carbon\Carbon::today(), 'created_at' => \Carbon\Carbon::today()]); } }
public function changeStatus(ChangeStatusOrderRequest $request) { $idOrder = $request->input('id'); //get current status $currentStatus = Order::find($idOrder)->status; $newStatus = $request->input('status'); if ($currentStatus == $this::CANCEL) { return redirect_errors('Order canceled cannot changer status!'); } if ($currentStatus == $this::PENDING && $newStatus > $this::DELIVERING) { return redirect_errors('Order is Pending can only changer Cancel or Delivering status!'); } if ($currentStatus == $this::DELIVERING && $newStatus > $this::DELIVERED && $newStatus < $this::DELIVERING && $newStatus != $this::CANCEL) { return redirect_errors('Order is Delivering can only changer Cancel or Delivered status!'); } if ($currentStatus == $this::DELIVERED && $newStatus < $this::DELIVERED && $newStatus != $this::CANCEL) { return redirect_errors('Order is Delivered can only changer Cancel or Charged status!'); } if ($currentStatus == $this::CHARGED) { return redirect_errors('Order charged cannot changer status!'); } $model = new Order(); DB::beginTransaction(); try { $order = $model->find(intval($idOrder)); $order->status = intval($newStatus); $order->save(); //if cancel then qty return if ($newStatus == $this::CANCEL) { $model = new Order(); $order = $model->viewOrder($idOrder); $details = $order['order']['detail']; foreach ($details as $detail) { $qtyReturn = $detail['quantity']; $currentQty = Cd::find($detail['product_id'])->quantity; $currentBuyTime = Cd::find($detail['product_id'])->buy_time; Cd::find($detail['product_id'])->update(['quantity' => $currentQty + $qtyReturn, 'buy_time' => $currentBuyTime + $qtyReturn]); } // $customer=User::find('user_id'); // if(is_null($customer)){ // // } // Mail::send('auth.message_order', ['name' => 'you'], // function ($message) use ($data) { // $message // ->to($data['email'], $data['name']) // ->from('*****@*****.**') // ->subject('Your order canceled!'); // }); } DB::commit(); return redirect()->back()->with('success', 'Updated status'); } catch (\Exception $e) { DB::rollback(); return redirect_errors('Updated Fails!'); } }
public function index() { View::share(['sideBar' => NavigatorHelper::getSideBarBE()]); $status = Status_orders::all(['name', 'id'])->toArray(); $newProduct = Cd::whereIn('public_date', [Carbon::today(), Carbon::today()->subDay(3)])->count(); $newArtist = Artist::whereIn('created_at', [Carbon::today(), Carbon::today()->subDay(3)])->count(); $newOrder = Order::where('status', Order::PENDING)->count(); $newCustomer = Customer::whereIn('created_at', [Carbon::today(), Carbon::today()->subDay(3)])->count(); return view('backend.index')->with(['status' => $status, 'newProduct' => $newProduct, 'newArtist' => $newArtist, 'newOrder' => $newOrder, 'newCustomer' => $newCustomer]); }
public function changeQuantityItem(ChangeQtyItemRequest $request) { $dataRequest = $request->all(); //check exist if (is_object(Cart::get(Input::get('idrow')))) { if (Cd::find($dataRequest['id'])->quantity - $dataRequest['qty'] >= 0) { Cart::update($dataRequest['idrow'], ['qty' => $dataRequest['qty']]); return redirect()->back()->with('success', 'Updated item!'); } else { return redirect_errors("Sorry we aren't Cd for You"); } } else { return redirect_errors('You haven"t this Item!'); } }
public function order() { //get Session option $option = Session::get('option'); //get Cart $cart = Cart::content(); //get type order $type = $option['type']; //payment method $payMethod = Session::get('pay_med'); if ($option['type'] == 'logged') { $order = new Order(); DB::beginTransaction(); try { $idUser = array_get(session('user'), 'id'); $order->user_id = $idUser; $order->delivery_detail_id = 0; $order->comment = $payMethod['comment']; $order->save(); $idOrder = Order::where('user_id', $idUser)->orderBy('id', 'desc')->first()->id; //add order detail and sub amount of product foreach ($cart as $item) { $root_price = Cd::find($item['id'])->root_price; $modelOrderDetail = new OrderDetail(); $modelOrderDetail->order_id = $idOrder; $modelOrderDetail->product_id = $item['id']; $modelOrderDetail->quantity = $item['qty']; $modelOrderDetail->root_price = $root_price; $modelOrderDetail->price = $item->price; $modelOrderDetail->save(); //sub qty product $cd = Cd::find($item['id']); if ($cd->quantity - $item['qty'] <= 0) { throw new QtyCDException(); } $cd->quantity = $cd->quantity - $item['qty']; $cd->buy_time = $cd->buy_time + $item['qty']; $cd->save(); } DB::commit(); $this->clear(); return redirect_success('FrontendController@index', 'Ordered, Check your email to check detail'); } catch (QtyCDException $e) { DB::rollback(); return redirect_errors($e->notify()); } catch (\Exception $e) { DB::rollback(); return redirect_errors("Sorry cannot to this deal!"); } } else { $deliveryDetail = Session::get('shi_add'); $order = new Order(); $modelDeliverDetail = new DeliveryDetail(); $modelDeliverDetail = autoAssignDataToProperty($modelDeliverDetail, $deliveryDetail); // dd($modelDeliverDetail); DB::beginTransaction(); try { $orderHuman = $modelDeliverDetail; $modelDeliverDetail->save(); $newDeliverDetail = new DeliveryDetail(); $delivery = $newDeliverDetail->getDeliveryDetail($deliveryDetail); $order->user_id = 0; $order->delivery_detail_id = $delivery->id; $order->comment = $payMethod['comment']; $order->save(); $idOrder = Order::where('delivery_detail_id', $delivery->id)->first()->id; //add order detail and sub amount of product foreach ($cart as $item) { $modelOrderDetail = new OrderDetail(); $modelOrderDetail->order_id = $idOrder; $modelOrderDetail->product_id = $item['id']; $modelOrderDetail->quantity = $item['qty']; $modelOrderDetail->price = $item['price']; $modelOrderDetail->save(); // $cd = Cd::find($item['id']); if ($cd->quantity - $item['qty'] <= 0) { throw new QtyCDException(); } else { $cd->quantity = $cd->quantity - $item['qty']; } } DB::commit(); $this->clear(); //send // Mail::send('auth.mail_welcome', ['last_name' => $orderHuman->lastname, 'key' => $key_active, 'password' => $pass], function ($message) use ($data) { // $message // ->to($data['email'], $data['name']) // ->from('*****@*****.**') // ->subject('Thank you for your buying!'); // }); return redirect_success('FrontendController@index', 'Ordered, Check your email to check detail'); } catch (QtyCDException $e) { DB::rollback(); return redirect_errors($e->notify()); } catch (\Exception $e) { DB::rollback(); return redirect_errors("Sorry cannot to this deal!"); } } }
public function destroy(DestroyProductRequest $request) { $id = Input::get('id'); //check delete if (Cd::find($id)->update(['status' => Cd::IN_ACTIVE])) { return redirect()->back()->with('success', 'Deleted'); } else { return redirect_errors('Have error,Cannot delete'); } //end check delete }
public function index() { $model = new Cd(); return view('frontend.home.index')->with(['latest' => $model->getNewProduct()]); }