123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace App\Models;
- use DateTimeInterface;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class Artificer extends Model
- {
- use HasFactory,SoftDeletes;
- protected $table = 'js';
- protected $hidden = [
- //
- ];
- const CREATED_AT = 'create_time';
- const UPDATED_AT = 'update_time';
- // 自定义软删除字段 默认 deleted_at
- const DELETED_AT = 'delete_time';
- protected $dateFormat = 'U';
- protected $appends = ['is_busy'];
- protected function serializeDate(DateTimeInterface $date): string
- {
- return $date->format('Y-m-d H:i:s');
- }
- public function getIsBusyAttribute()
- {
- return Order::where(['jiedan_js_id' => $this->id, 'status' => 6])->count();
- }
- public function getSiteAttribute()
- {
- return ArtificerSite::where(['js_id' => $this->id])->first();
- }
- public function site()
- {
- return $this->hasOne(ArtificerSite::class, 'js_id', 'id');
- }
- }
|