add metrics
This commit is contained in:
@@ -3,10 +3,13 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Basket;
|
||||
use App\Traits\Model\Basic;
|
||||
use Darryldecode\Cart\CartCollection;
|
||||
|
||||
class BasketStores
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public function has($key)
|
||||
{
|
||||
return Basket::find($key);
|
||||
@@ -14,30 +17,29 @@ class BasketStores
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
if($this->has($key))
|
||||
{
|
||||
if($this->has($key)) {
|
||||
return new CartCollection(Basket::find($key)->cart_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function put($key, $value)
|
||||
{
|
||||
if($row = Basket::find($key))
|
||||
{
|
||||
if($row = Basket::find($key)) {
|
||||
// update
|
||||
$row->cart_data = $value;
|
||||
$row->save();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Basket::create([
|
||||
'id' => $key,
|
||||
'cart_data' => $value
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return Basket::query();
|
||||
}
|
||||
}
|
||||
|
||||
32
app/Repositories/Shop/CustomerMetrics.php
Normal file
32
app/Repositories/Shop/CustomerMetrics.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Customer;
|
||||
use App\Repositories\Core\DateStats;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class CustomerMetrics
|
||||
{
|
||||
use Basic, DateStats;
|
||||
|
||||
public static function countOfToday()
|
||||
{
|
||||
return Customer::ofToday()->count();
|
||||
}
|
||||
|
||||
public static function countOfLastWeek()
|
||||
{
|
||||
return Customer::ofLastWeek()->count();
|
||||
}
|
||||
|
||||
public static function countOfLastMonth()
|
||||
{
|
||||
return Customer::ofLastMonth()->count();
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return Customer::query();
|
||||
}
|
||||
}
|
||||
@@ -10,12 +10,15 @@ class Dashboards
|
||||
'orders_count' => OrderMetrics::countByPeriod($start, $end),
|
||||
'orders_sum' => OrderMetrics::sumByPeriod($start, $end, 'total_shipped'),
|
||||
'orders_avg' => OrderMetrics::avgByPeriod($start, $end, 'total_shipped'),
|
||||
'offers_count' => Offers::count(),
|
||||
'clients_count' => Customers::count(),
|
||||
'countClients' => CustomerMetrics::countByPeriod($start, $end),
|
||||
'waitingOrders' => OrderMetrics::countWaiting(),
|
||||
'preparationLess24H' => OrderMetrics::countPreparationLess24h(),
|
||||
'preparationLess48H' => OrderMetrics::countPreparationLess48h(),
|
||||
'preparationMore48H' => OrderMetrics::countPreparationMore48h(),
|
||||
'offers_count' => Offers::count(),
|
||||
'stocksWarning' => OfferStocks::countAlerts(),
|
||||
'countCustomers' => Customers::count(),
|
||||
'lastOrders' => Orders::getLast(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,11 @@ class OrderMetrics
|
||||
return self::sumMonthly('total_taxed');
|
||||
}
|
||||
|
||||
public static function countWaiting()
|
||||
{
|
||||
return Order::waiting()->count();
|
||||
}
|
||||
|
||||
public static function countPreparationLess24h()
|
||||
{
|
||||
$date = now()->subHours(24);
|
||||
|
||||
@@ -14,6 +14,11 @@ class Orders
|
||||
{
|
||||
use Basic, DateStats;
|
||||
|
||||
public static function getLast($nb = 10)
|
||||
{
|
||||
return Order::with('customer')->orderBy('id', 'DESC')->take($nb)->get();
|
||||
}
|
||||
|
||||
public static function getPdfByUUID($uuid)
|
||||
{
|
||||
return self::getPdf(self::getIdByUUID($uuid), 'commande-' . $uuid . '.pdf');
|
||||
|
||||
Reference in New Issue
Block a user