UserLabor.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App;
  3. use Carbon\Carbon;
  4. use Illuminate\Database\Eloquent\Model;
  5. use App\Traits\ModelTimeFormat;
  6. use Illuminate\Support\Facades\Cache;
  7. class UserLabor extends Model
  8. {
  9. use ModelTimeFormat;
  10. protected $primaryKey='user_id';
  11. public $incrementing=false;
  12. public $timestamps=false;
  13. protected $fillable=[
  14. 'user_id','default_hour_price','labor_company_id','present_status','user_workgroup_id'
  15. ];
  16. protected $appends = [
  17. 'is_relieve_facility',
  18. ];
  19. public function userDetail(){
  20. return $this->belongsTo('App\UserDetail','user_id','user_id');
  21. }
  22. public function laborCompany(){
  23. return $this->belongsTo('App\LaborCompany');
  24. }
  25. public function getIsRelieveFacilityAttribute(){
  26. return Cache::has('dutyCheckTokenUser_'.$this['user_id']);
  27. }
  28. public function isOccupiedAt($date,$time):bool{
  29. $processDailyParticipants=ProcessDailyParticipant::query()->select('ended_at')->where('user_id',$this['user_id'])
  30. ->whereHas('processDaily', function ($query) use($date){
  31. $query->where('date',$date);
  32. })->get();
  33. foreach ($processDailyParticipants as $processDailyParticipant){
  34. if (Carbon::parse($processDailyParticipant->ended_at)->lt(Carbon::parse($time))){
  35. return true;
  36. }
  37. }
  38. return false;
  39. }
  40. }