mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-08-03 15:17:03 -04:00
38 lines
1.4 KiB
PHP
38 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\MultiVendor\Entities;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
class PackageWiseSellerCommision extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
public function scopeTotalCommision($query, $type){
|
|
$seller_id = getParentSellerId();
|
|
$year = Carbon::now()->year;
|
|
if ($type == "today") {
|
|
$query->whereBetween('created_at', [Carbon::now()->format('y-m-d')." 00:00:00", Carbon::now()->format('y-m-d')." 23:59:59"]);
|
|
}
|
|
if ($type == "week") {
|
|
$query->whereBetween('created_at', [Carbon::now()->subDays(7)->format('y-m-d')." 00:00:00", Carbon::now()->format('y-m-d')." 23:59:59"]);
|
|
}
|
|
if ($type == "month") {
|
|
$month = Carbon::now()->month;
|
|
$date_1 = Carbon::create($year, $month)->startOfMonth()->format('Y-m-d')." 00:00:00";
|
|
$query->whereBetween('created_at', [$date_1, Carbon::now()->format('y-m-d')." 23:59:59"]);
|
|
}
|
|
if ($type == "year") {
|
|
$date_1 = Carbon::create($year, 1)->startOfMonth()->format('Y-m-d')." 00:00:00";
|
|
$query->whereBetween('created_at', [$date_1, Carbon::now()->format('y-m-d')." 23:59:59"]);
|
|
}
|
|
$total = $query->where('seller_id', $seller_id)->sum('amount');
|
|
return $total;
|
|
}
|
|
|
|
}
|