public function run() { $faker = Faker::create(); $users = Address::get(); $status_list = array_keys(trans('globals.order_status')); for ($i = 0; $i < 20; $i++) { $user = $users->random(1); $products = Product::get(); $type = $faker->randomElement(['cart', 'wishlist', 'order']); $status = 'open'; switch ($type) { case 'order': $status = $faker->randomElement($status_list); break; } $stock = $faker->numberBetween(1, 20); $order = Order::create(['user_id' => $user->user_id, 'seller_id' => '3', 'address_id' => $user->id, 'status' => $status, 'type' => $type, 'description' => $type == 'wishlist' ? $faker->companySuffix : '', 'end_date' => $status == 'closed' || $status == 'cancelled' ? $faker->dateTime() : null]); $num = $faker->numberBetween(2, 5); $list = []; if ($num > 1 && count($products) - 1 < $num) { $num = count($products) - 1; } for ($j = 0; $j < $num; $j++) { do { $a = true; $product = $products->random(1); if (in_array($product->id, $list)) { $a = false; } else { $list[] = $product->id; } } while ($a == false); if ($status == 'closed') { $delivery = $faker->dateTime(); } else { $delivery = $faker->numberBetween(0, 1) ? $faker->dateTime() : null; } OrderDetail::create(['order_id' => $order->id, 'product_id' => $product->id, 'price' => $product->price, 'quantity' => $stock, 'delivery_date' => $delivery]); } $order->sendNotice(); } }
public function edit($booking_id) { $booking = Booking::with('comment.comment_type', 'comment.role.user', 'comment.role.role_type', 'change.change_type', 'change.user', 'car_type', 'role.user', 'role.role_type', 'income.income_type', 'outcome.outcome_type', 'route_point.location', 'route_point.sub_location', 'route_point.address')->with(array('route_point' => function ($query) { $query->orderBy('order', 'ASC'); }))->findOrFail($booking_id); $car_types = Car_type::get(); $role_types = Role_type::get(); $income_types = Income_type::get(); $outcome_types = Outcome_type::get(); $locations = Location::get(); $sub_locations = Sub_location::get(); $addresses = Address::get(); JavaScript::put(['addresses' => $addresses, 'booking' => $booking, 'car_types' => $car_types, 'income_types' => $income_types, 'locations' => $locations, 'outcome_types' => $outcome_types, 'role_types' => $role_types, 'sub_locations' => $sub_locations, 'csrf_token' => csrf_token()]); return view('booking.edit'); }
public function run() { $faker = Faker::create(); $users = Address::get(); $status_list = array_keys(trans('globals.order_status')); for ($i = 0; $i < 40; $i++) { $user = $users->random(1); $products = Product::where('id', '!=', $user->user_id)->where('type', '!=', 'freeproduct')->get(); $type = 'freeproduct'; $status = 'paid'; $order = Order::create(['user_id' => $user->user_id, 'seller_id' => '3', 'address_id' => $user->address_id, 'status' => 'paid', 'type' => $type, 'description' => '', 'end_date' => null]); //Productos a insertar a la orden. Se haran copias de los productos que esten en las ordenes y se le asignara el tipo freeproduct $num = $faker->numberBetween(2, 5); $list = []; if ($num > 1 && count($products) - 1 < $num) { $num = count($products) - 1; } for ($j = 0; $j < $num; $j++) { do { $a = true; $product = $products->random(1); $quantity = $faker->numberBetween(1, 5); if (in_array($product->id, $list)) { $a = false; } else { //duplico el producto $productactual = $product->toArray(); unset($productactual['id']); unset($productactual['num_of_reviews']); $productactual['user_id'] = '3'; //$user->user_id; $productactual['type'] = 'freeproduct'; $productactual['parent_id'] = $product->id; $newproduct = Product::create($productactual); $list[] = $product->id; } } while ($a == false); //el nuevo producto lo asocio al detalle de la orden OrderDetail::create(['order_id' => $order->id, 'product_id' => $newproduct->id, 'price' => $product->price, 'quantity' => $quantity, 'delivery_date' => null]); //Actualizo el stock $product->stock = $product->stock - $quantity; $product->save(); } $order->sendNotice(); } $orders = Order::where('type', '=', 'freeproduct')->get(); $users = User::where('type', 'trusted')->get(); $list_orders = []; for ($i = 0; $i < 15; $i++) { //Se crea el free product y se asocia las ordenes $user = $users->random(1); $end_date = \Carbon\Carbon::now()->addDays($faker->numberBetween(5, 30)); $freeproduct = FreeProduct::create(['user_id' => '3', 'description' => $faker->unique()->catchPhrase, 'start_date' => \Carbon\Carbon::now(), 'end_date' => $end_date, 'participation_cost' => $faker->numberBetween(10000, 50000), 'min_participants' => $min_participants = $faker->numberBetween(1, 15), 'max_participants' => $faker->numberBetween($min_participants, $min_participants * 2), 'max_participations_per_user' => $faker->numberBetween(1, 5), 'draw_number' => $faker->numberBetween(1, 3), 'draw_date' => $end_date->addDays($faker->numberBetween(1, 5)), 'status' => $faker->randomElement([0, 1])]); //asocio una o mas ordenes a un free product $num = $faker->numberBetween(1, 3); if ($num > 1 && count($orders) - 1 < $num) { $num = count($orders) - 1; } for ($j = 0; $j < $num; $j++) { do { $a = true; $order = $orders->random(1); if (in_array($order->id, $list_orders)) { $a = false; } else { $list_orders[] = $order->id; } } while ($a == false); FreeProductOrder::create(['order_id' => $order->id, 'freeproduct_id' => $freeproduct->id]); } } }