UserLabor.php 1.4 KB

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