本文整理汇总了PHP中app\Address::auth方法的典型用法代码示例。如果您正苦于以下问题:PHP Address::auth方法的具体用法?PHP Address::auth怎么用?PHP Address::auth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Address
的用法示例。
在下文中一共展示了Address::auth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: placeOrders
/**
* Start the checkout process for any type of order.
*
* @param int $type_order Type of order to be processed
*
* @return Response
*/
public static function placeOrders($type_order)
{
$cart = self::ofType($type_order)->auth()->whereStatus('open')->orderBy('id', 'desc')->first();
$show_order_route = $type_order == 'freeproduct' ? 'freeproducts.show' : 'orders.show_cart';
$cartDetail = OrderDetail::where('order_id', $cart->id)->get();
$address_id = 0;
//When address is invalid, it is because it comes from the creation of a free product. You must have a user direction (Default)
if (is_null($cart->address_id)) {
$useraddress = Address::auth()->orderBy('default', 'DESC')->first();
if ($useraddress) {
$address_id = $useraddress->address_id;
} else {
return trans('address.no_registered');
}
} else {
$address_id = $cart->address_id;
}
$address = Address::where('id', $address_id)->first();
//Checks if the user has points for the cart price and the store has stock
//and set the order prices to the current ones if different
//Creates the lists or sellers to send mail to
$total_points = 0;
$seller_email = [];
foreach ($cartDetail as $orderDetail) {
$product = Product::find($orderDetail->product_id);
$seller = User::find($product->user_id);
if (!in_array($seller->email, $seller_email)) {
$seller_email[] = $seller->email;
}
$total_points += $orderDetail->quantity * $product->price;
if ($orderDetail->price != $product->price) {
$orderDetail->price = $product->price;
$orderDetail->save();
}
if ($product->type != 'item') {
$virtual = VirtualProduct::where('product_id', $orderDetail->product_id)->get();
$first = $virtual->first();
//$first=null;
//foreach ($virtual as $row){
//$first=$row;
//break;
//}
switch ($product->type) {
case 'key':
case 'software_key':
$virtualOrder = VirtualProductOrder::where('virtual_product_id', $first->id)->where('order_id', $orderDetail->order_id)->where('status', 1)->get();
if (count($virtual) - 1 < count($virtualOrder)) {
return trans('store.insufficientStock');
}
break;
default:
break;
}
} elseif ($product->stock < $orderDetail->quantity) {
return trans('store.insufficientStock');
}
}
//Checks if the user has points for the cart price
$user = \Auth::user();
if ($user->current_points < $total_points && config('app.payment_method') == 'Points') {
return trans('store.cart_view.insufficient_funds');
}
if (config('app.payment_method') == 'Points') {
$negativeTotal = -1 * $total_points;
//7 is the action type id for order checkout
$pointsModified = $user->modifyPoints($negativeTotal, 7, $cart->id);
} else {
$pointsModified = true;
}
if ($pointsModified) {
//Separate the order for each seller
//Looks for all the different sellers in the cart
$sellers = [];
foreach ($cartDetail as $orderDetail) {
if (!in_array($orderDetail->product->user_id, $sellers)) {
$sellers[] = $orderDetail->product->user_id;
}
}
foreach ($sellers as $seller) {
//Creates a new order and address for each seller
$newOrder = new self();
$newOrder->user_id = $user->id;
$newOrder->address_id = $address->id;
$newOrder->status = $type_order == 'freeproduct' ? 'paid' : 'open';
$newOrder->type = $type_order == 'freeproduct' ? 'freeproduct' : 'order';
$newOrder->seller_id = $seller;
$newOrder->save();
$newOrder->sendNotice();
//moves the details to the new orders
foreach ($cartDetail as $orderDetail) {
if ($orderDetail->product->user_id == $seller) {
$orderDetail->order_id = $newOrder->id;
$orderDetail->save();
//.........这里部分代码省略.........