49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App;
|
||
|
|
||
|
use Illuminate\Database\Eloquent\Model;
|
||
|
use Session, Cart , DB;
|
||
|
|
||
|
class Order extends Model
|
||
|
{
|
||
|
|
||
|
|
||
|
static public function save_new(){
|
||
|
|
||
|
$cartCollection = Cart::getContent();
|
||
|
$cart = $cartCollection->toArray();
|
||
|
$order = new self();
|
||
|
$order ->user_id = Session::get('user_id');
|
||
|
$order ->data = serialize($cart);
|
||
|
$order ->total = Cart::getTotal();
|
||
|
$order->status = 0;
|
||
|
// dd($order);
|
||
|
$order -> save();
|
||
|
Cart::clear();
|
||
|
Session::flash('sm', 'Thanks, you Order Saved!');
|
||
|
}
|
||
|
|
||
|
|
||
|
static public function getUserOrders($user){
|
||
|
$uid = $user[0]->id;
|
||
|
$sql = "SELECT * FROM orders o WHERE o.user_id = ? ORDER BY orderid";
|
||
|
$user_orders = DB::select($sql,[$uid] );
|
||
|
return $user_orders;
|
||
|
}
|
||
|
|
||
|
static public function getOrder($oid){
|
||
|
$sql = "SELECT * FROM orders o WHERE o.orderid = ?";
|
||
|
$user_order = DB::select($sql,[$oid] );
|
||
|
return $user_order;
|
||
|
}
|
||
|
static public function getAllTotalOrders($users){
|
||
|
$allOrders = [];
|
||
|
$sql = "SELECT total FROM orders o JOIN users u ON u.id = ? AND o.user_id = ?";
|
||
|
foreach ($users as $user) {
|
||
|
$allOrders []= DB::select($sql,[$user->id , $user->id]);
|
||
|
}
|
||
|
return $allOrders;
|
||
|
}
|
||
|
}
|