store-manage/app/Models/TaskPerformance.php

46 lines
1.0 KiB
PHP

<?php
namespace App\Models;
use App\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphOne;
class TaskPerformance extends Model
{
use HasFactory, HasDateTimeFormatter;
protected $fillable = [
'month',
'store_id',
'store_master_id',
'expected_performance',
'actual_performance',
];
public function task(): MorphOne
{
return $this->morphOne(Task::class, 'taskable');
}
public function store(): BelongsTo
{
return $this->belongsTo(Store::class);
}
public function storeMaster(): BelongsTo
{
return $this->belongsTo(Employee::class, 'store_master_id');
}
/**
* 此业绩指标是否已完成
*/
public function isCompleted(): bool
{
return bccomp($this->actual_performance, $this->expected_performance, 2) >= 0;
}
}