|
|
@@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Model;
|
|
|
use App\Traits\ModelTimeFormat;
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
use Illuminate\Support\Arr;
|
|
|
+use Illuminate\Support\Collection;
|
|
|
+use function Matrix\add;
|
|
|
|
|
|
class LaborReport extends Model
|
|
|
{
|
|
|
@@ -15,10 +17,11 @@ class LaborReport extends Model
|
|
|
protected $fillable=[
|
|
|
'id','enter_number','user_workgroup_id','user_id','name','mobile_phone','identity_number','labor_company',
|
|
|
'check_in_at','verify_at','group_user_id','check_out_at','online_duration','working_duration','created_at','updated_at',
|
|
|
- 'user_duty_check_id','status'
|
|
|
+ 'user_duty_check_id','relax_time'
|
|
|
];
|
|
|
protected $appends = [
|
|
|
- 'is_exportGroup','is_export', 'exit_at','enter_at','sequence', 'amountOfJoined','remark',
|
|
|
+ 'is_exportGroup','is_export', 'exit_at','enter_at','sequence', 'amountOfJoined','remark','thisRecordOnlineTime','thisRecordWorkingTime',
|
|
|
+ 'totalOnlineTime',
|
|
|
];
|
|
|
protected $tempFields = [
|
|
|
'temEnteringRecord',
|
|
|
@@ -46,10 +49,86 @@ class LaborReport extends Model
|
|
|
Sign::updateOrCreate(['signable_type'=>'labor_reports','signable_id'=>$id,'field'=>'remark'],['mark'=>$remark]);
|
|
|
|
|
|
}
|
|
|
-
|
|
|
public function getIsExportGroupAttribute(){
|
|
|
return $this['check_out_at']? true:false;
|
|
|
}
|
|
|
+ //总在线时长
|
|
|
+ public function getTotalOnlineTimeAttribute(){
|
|
|
+ $laborReports=LaborReport::where('enter_number',$this['enter_number'])->get();
|
|
|
+ $totalOnlineTime=$laborReports->reduce(function ($value,$laborReport){
|
|
|
+ return $value+$laborReport['thisRecordOnlineTime'];
|
|
|
+ },0);
|
|
|
+ return $totalOnlineTime;
|
|
|
+ }
|
|
|
+ //总工作时长
|
|
|
+ public function getTotalWorkingTimeAttribute(){
|
|
|
+ $laborReports=LaborReport::where('enter_number',$this['enter_number'])->orderBy('id','asc')->get();
|
|
|
+ $totalWorkingTime=$laborReports->reduce(function ($value,$laborReport){
|
|
|
+ return ($value??0)+$laborReport['thisRecordWorkingTime'];
|
|
|
+ });
|
|
|
+ return $totalWorkingTime;
|
|
|
+ }
|
|
|
+ //本轮工作起始时间
|
|
|
+ public function getThisRoundOnlineStartTimeAttribute(){
|
|
|
+ $laborReports=LaborReport::where('enter_number',$this['enter_number'])->orderBy('id','asc')->get();
|
|
|
+ foreach ($laborReports as $laborReport){
|
|
|
+ if ($laborReport['enter_at']&&$laborReport['check_in_at'])
|
|
|
+ return $laborReport['check_in_at'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //本轮工作结束时间
|
|
|
+ public function getThisRoundOnlineEndTimeAttribute(){
|
|
|
+ $laborReports=LaborReport::where('enter_number',$this['enter_number'])->orderBy('id','asc')->get();
|
|
|
+ foreach ($laborReports as $laborReport){
|
|
|
+ if ($laborReport['exit_at']&&$laborReport['check_out_at'])
|
|
|
+ return $laborReport['check_out_at'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //本次在线时长
|
|
|
+ public function getThisRecordOnlineTimeAttribute(){
|
|
|
+ if($this['enter_at']&&!$this['check_out_at']&&!$this['exit_at'])
|
|
|
+ return round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['enter_at']))/3600,2);
|
|
|
+ if ($this['enter_at']&&$this['check_out_at']&&!$this['exit_at'])
|
|
|
+ return round(Carbon::parse($this['check_out_at'])->diffInSeconds(Carbon::parse($this['enter_at']))/3600,2);
|
|
|
+ if ($this['enter_at']&&$this['exit_at'])
|
|
|
+ return round(Carbon::parse($this['exit_at'])->diffInSeconds(Carbon::parse($this['enter_at']))/3600,2);
|
|
|
+ if ($this['check_in_at']&&!$this['enter_at']&&!$this['check_out_at']&&!$this['exit_at'])
|
|
|
+ return round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['check_in_at']))/3600,2);
|
|
|
+ if ($this['check_in_at']&&!$this['enter_at']&&$this['check_out_at']&&!$this['exit_at'])
|
|
|
+ return round(Carbon::parse($this['check_out_at'])->diffInSeconds(Carbon::parse($this['check_in_at']))/3600,2);
|
|
|
+ if ($this['check_in_at']&&!$this['enter_at']&&$this['exit_at'])
|
|
|
+ return round(Carbon::parse($this['exit_at'])->diffInSeconds(Carbon::parse($this['check_in_at']))/3600,2);
|
|
|
+ }
|
|
|
+ //本次工作时长
|
|
|
+ public function getThisRecordWorkingTimeAttribute(){
|
|
|
+ if ($this['check_in_at']&&!$this['check_out_at']&&!$this['relax_time']){
|
|
|
+ $workingTime=round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['check_in_at']))/3600,2);
|
|
|
+ $checkInTime=Carbon::parse($this['check_in_at'])->format('H');
|
|
|
+ $checkOutTime=Carbon::parse(Carbon::now())->format('H');
|
|
|
+ return $this->minusLunchTime($checkInTime,$checkOutTime,$workingTime);
|
|
|
+ }
|
|
|
+ if ($this['check_in_at']&&$this['check_out_at']&&!$this['relax_time']){
|
|
|
+ $workingTime=round(Carbon::parse($this['check_out_at'])->diffInSeconds(Carbon::parse($this['check_in_at']))/3600,2);
|
|
|
+ $checkInTime=Carbon::parse($this['check_in_at'])->format('H');
|
|
|
+ $checkOutTime=Carbon::parse($this['check_out_at'])->format('H');
|
|
|
+ return $this->minusLunchTime($checkInTime,$checkOutTime,$workingTime);
|
|
|
+ }
|
|
|
+ if ($this['check_in_at']&&$this['check_out_at']&&$this['relax_time']){
|
|
|
+ $workingTime=round(Carbon::parse($this['check_out_at'])->diffInSeconds(Carbon::parse($this['check_in_at']))/3600,2);
|
|
|
+ $checkInTime=Carbon::parse($this['check_in_at'])->format('H');
|
|
|
+ $checkOutTime=Carbon::parse($this['check_out_at'])->format('H');
|
|
|
+ return $this->minusLunchTime($checkInTime,$checkOutTime,$workingTime)-$this['relax_time']/60;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //工作时长减午饭休息时间
|
|
|
+ public function minusLunchTime($checkInTime,$checkOutTime,$hour){
|
|
|
+ if ((int)$checkInTime<=12&&(int)$checkOutTime>=13){
|
|
|
+ $hour=$hour-1;
|
|
|
+ }
|
|
|
+ return $hour;
|
|
|
+ }
|
|
|
+
|
|
|
//转场序号
|
|
|
public function getSequenceAttribute()
|
|
|
{
|
|
|
@@ -105,8 +184,8 @@ class LaborReport extends Model
|
|
|
// return $laborReport;
|
|
|
// }
|
|
|
$laborReport=LaborReport::with(['laborReportStatus'=>function($query){
|
|
|
- return $query->whereIn('status',['已入场','未审核']);
|
|
|
- }])->where('user_id',$this['user_id'])->orderBy('id','desc')->first();
|
|
|
+ return $query->whereIn('status',['已入场','未审核']);
|
|
|
+ }])->where('user_id',$this['user_id'])->orderBy('id','desc')->first();
|
|
|
if(empty($laborReport))return null;
|
|
|
return $laborReport;
|
|
|
|