Artificer.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Models;
  3. use DateTimeInterface;
  4. use Illuminate\Database\Eloquent\Factories\HasFactory;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Database\Eloquent\SoftDeletes;
  7. class Artificer extends Model
  8. {
  9. use HasFactory,SoftDeletes;
  10. protected $table = 'js';
  11. protected $hidden = [
  12. //
  13. ];
  14. const CREATED_AT = 'create_time';
  15. const UPDATED_AT = 'update_time';
  16. // 自定义软删除字段 默认 deleted_at
  17. const DELETED_AT = 'delete_time';
  18. protected $dateFormat = 'U';
  19. protected $appends = ['is_busy'];
  20. protected function serializeDate(DateTimeInterface $date): string
  21. {
  22. return $date->format('Y-m-d H:i:s');
  23. }
  24. public function getIsBusyAttribute()
  25. {
  26. return Order::where(['jiedan_js_id' => $this->id, 'status' => 6])->count();
  27. }
  28. public function getSiteAttribute()
  29. {
  30. return ArtificerSite::where(['js_id' => $this->id])->first();
  31. }
  32. public function site()
  33. {
  34. return $this->hasOne(ArtificerSite::class, 'js_id', 'id');
  35. }
  36. }