mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-08-02 21:16:12 -04:00
46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Modules\Review\Entities;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Carbon\Carbon;
|
|
|
|
class SellerReview extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
public function customer(){
|
|
return $this->belongsTo(User::class,'customer_id','id');
|
|
}
|
|
|
|
public function seller(){
|
|
return $this->belongsTo(User::class, 'seller_id', 'id');
|
|
}
|
|
|
|
public function scopeTotalReview($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"]);
|
|
}
|
|
return $query->where('seller_id', $seller_id)->where('status', 1)->get()->count();
|
|
}
|
|
}
|