本文整理汇总了PHP中app\models\Order::All方法的典型用法代码示例。如果您正苦于以下问题:PHP Order::All方法的具体用法?PHP Order::All怎么用?PHP Order::All使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Order
的用法示例。
在下文中一共展示了Order::All方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: viewAll
public function viewAll()
{
$connectedUser = Auth::user();
$error = \Session::get('error');
$messages = \Session::get('messages');
if ($connectedUser->rank == Constants::RANK_ADMIN) {
// recuperation de la liste des commandes et les totaux
$orders = Order::where('status', '!=', Constants::ORDER_VALIDATE)->get();
$today = (new \DateTime())->setTime(0, 0);
// nombre de commandes total
$totalOrders = Order::All()->count();
// nombre de commandes validées
$totalValidated = Order::where('status', '=', Constants::ORDER_VALIDATE)->count();
// nombre de commandes en attente
$totalWaiting = Order::where('status', '=', Constants::ORDER_WAITING)->count();
// nombre de commandes en cours de traitement
$totalAssigned = Order::where('status', '=', Constants::ORDER_IN_PROGRESS)->count();
// nombre de commandes validées aujourd'hui
$todayOrders = Order::where('date_validation', '>', $today)->count();
// récuperation de la liste des utilisateurs avec leurs stats
$users = User::where('active', Constants::ACTIVE)->where('rank', Constants::RANK_USER)->get();
$detailsUsers = [];
foreach ($users as $user) {
$totalRatio = 0;
$todayRatio = 0;
// nombre de commandes traités par l'utilisateur (au total)
$total = Order::where('user_id', '=', $user->id)->where('status', '=', Constants::ORDER_VALIDATE)->count();
if ($totalValidated != 0) {
$totalRatio = round($total / $totalValidated * 100);
}
// nombre de commandes traitées par l'utilisateur aujourd'hui
$today = Order::where('user_id', '=', $user->id)->where('status', '=', Constants::ORDER_VALIDATE)->count();
if ($todayOrders != 0) {
$todayRatio = round($today / $todayOrders * 100);
}
$detailsUsers[] = array($user, $total, $totalRatio, $today, $todayRatio);
}
return view('manager.orderList', ['orders' => $orders, 'error' => $error, 'messages' => $messages, 'total' => $totalOrders, 'totalValidated' => $totalValidated, 'today' => $todayOrders, 'waiting' => $totalWaiting, 'assigned' => $totalAssigned, 'detailsUsers' => $detailsUsers]);
} else {
// on recherche si on a déjà une commande attribuée
$order = Order::where('user_id', $connectedUser->id)->Where('status', Constants::ORDER_IN_PROGRESS)->first();
// sinon on prend la première libre et on l'assigne
if ($order == null) {
$order = Order::where('status', '=', Constants::ORDER_WAITING)->first();
$order->user_id = $connectedUser->id;
$order->status = Constants::ORDER_IN_PROGRESS;
$order->save();
}
return view('users.order', ['order' => $order, 'error' => $error, 'messages' => $messages]);
}
}