generated from liutk/owl-admin-base
72 lines
1.7 KiB
PHP
72 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\PromotionStatus;
|
|
use App\Traits\HasCheckable;
|
|
use App\Traits\HasDateTimeFormatter;
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* 员工升职申请
|
|
*/
|
|
class EmployeePromotion extends Model
|
|
{
|
|
use Filterable, HasCheckable, HasDateTimeFormatter;
|
|
|
|
protected $fillable = ['store_id', 'employee_id', 'invitor_id', 'job_id', 'promotion_status', 'employee_data', 'remarks'];
|
|
|
|
protected $casts = [
|
|
'promotion_status' => PromotionStatus::class,
|
|
'employee_data' => 'json',
|
|
];
|
|
|
|
public function modelFilter()
|
|
{
|
|
return \App\Admin\Filters\EmployeePromotionFilter::class;
|
|
}
|
|
|
|
public function checkSuccess()
|
|
{
|
|
$this->update(['promotion_status' => PromotionStatus::Success]);
|
|
// 添加职位
|
|
$this->employee->jobs()->attach($this->job_id);
|
|
}
|
|
|
|
public function checkFail()
|
|
{
|
|
$this->update(['promotion_status' => PromotionStatus::Fail]);
|
|
}
|
|
|
|
public function checkCancel()
|
|
{
|
|
$this->update(['promotion_status' => PromotionStatus::Employee]);
|
|
}
|
|
|
|
public function canUpdate(): bool
|
|
{
|
|
return in_array($this->promotion_status, [PromotionStatus::Employee, PromotionStatus::Invitor, PromotionStatus::Fail]);
|
|
}
|
|
|
|
public function store()
|
|
{
|
|
return $this->belongsTo(Store::class, 'store_id');
|
|
}
|
|
|
|
public function employee()
|
|
{
|
|
return $this->belongsTo(Employee::class, 'employee_id');
|
|
}
|
|
|
|
public function invitor()
|
|
{
|
|
return $this->belongsTo(Employee::class, 'invitor_id');
|
|
}
|
|
|
|
public function job()
|
|
{
|
|
return $this->belongsTo(Keyword::class, 'job_id', 'key');
|
|
}
|
|
}
|