37 lines
845 B
PHP
37 lines
845 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models\Stats;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
class StatSalesMonthly extends Model
|
||
|
|
{
|
||
|
|
protected $connection = 'sam_stat';
|
||
|
|
|
||
|
|
protected $table = 'stat_sales_monthly';
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'stat_year' => 'integer',
|
||
|
|
'stat_month' => 'integer',
|
||
|
|
'order_count' => 'integer',
|
||
|
|
'order_amount' => 'decimal:2',
|
||
|
|
'sales_count' => 'integer',
|
||
|
|
'sales_amount' => 'decimal:2',
|
||
|
|
'avg_order_amount' => 'decimal:2',
|
||
|
|
];
|
||
|
|
|
||
|
|
public function scopeForTenant($query, ?int $tenantId)
|
||
|
|
{
|
||
|
|
if ($tenantId) {
|
||
|
|
return $query->where('tenant_id', $tenantId);
|
||
|
|
}
|
||
|
|
|
||
|
|
return $query;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function scopeForMonth($query, int $year, int $month)
|
||
|
|
{
|
||
|
|
return $query->where('stat_year', $year)->where('stat_month', $month);
|
||
|
|
}
|
||
|
|
}
|