|
|
@@ -28,6 +28,7 @@ class LaborReport extends Model
|
|
|
'sequence',
|
|
|
'amountOfJoined',
|
|
|
];
|
|
|
+ public static $withoutAppends = true;
|
|
|
|
|
|
static function tokenOfBroadcastEnterAndLeave(){
|
|
|
return md5('tokenOfListAll'.Carbon::now()->format('Y-m-d'));
|
|
|
@@ -85,58 +86,69 @@ class LaborReport extends Model
|
|
|
}
|
|
|
//总在线时长
|
|
|
public function getTotalOnlineTimeAttribute(){
|
|
|
- $laborReports=LaborReport::where('enter_number',$this['enter_number'])->get();
|
|
|
- $totalOnlineTime=$laborReports->reduce(function ($value,$laborReport){
|
|
|
- return ($value??0)+$laborReport['thisRecordOnlineTime'];
|
|
|
- });
|
|
|
- return $totalOnlineTime;
|
|
|
+ if(self::$withoutAppends) {
|
|
|
+ $laborReports = LaborReport::where('enter_number', $this['enter_number'])->get();
|
|
|
+ $totalOnlineTime = $laborReports->reduce(function ($value, $laborReport) {
|
|
|
+ return ($value ?? 0) + $laborReport['thisRecordOnlineTime'];
|
|
|
+ });
|
|
|
+ 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;
|
|
|
+ if(self::$withoutAppends) {
|
|
|
+ $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'];
|
|
|
+ if(self::$withoutAppends) {
|
|
|
+ $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'])->get();
|
|
|
- foreach ($laborReports as $laborReport){
|
|
|
- if ($laborReport['exit_at']&&$laborReport['check_out_at'])
|
|
|
- return $laborReport['check_out_at'];
|
|
|
+ if(self::$withoutAppends) {
|
|
|
+ $laborReports = LaborReport::where('enter_number', $this['enter_number'])->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);
|
|
|
+
|
|
|
+ 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']);
|
|
|
- $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(Carbon::now())->diffInSeconds(Carbon::parse($this['check_in_at'])) / 3600, 2);
|
|
|
+ $checkInTime = Carbon::parse($this['check_in_at']);
|
|
|
+ $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);
|
|
|
@@ -150,27 +162,30 @@ class LaborReport extends Model
|
|
|
$checkOutTime=Carbon::parse($this['check_out_at'])->format('H');
|
|
|
return $this->minusLunchTime($checkInTime,$checkOutTime,$workingTime)-$this['relax_time']/60;
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
//本次取整工作时长
|
|
|
public function getThisRoundRecordWorkingTimeAttribute(){
|
|
|
- if ($this['round_check_in_at']&&!$this['round_check_out_at']&&!$this['relax_time']){
|
|
|
- $workingTime=round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['round_check_in_at']))/3600,2);
|
|
|
- $checkInTime=Carbon::parse($this['round_check_in_at']);
|
|
|
- $checkOutTime=Carbon::parse(Carbon::now())->format('H');
|
|
|
- return $this->minusLunchTime($checkInTime,$checkOutTime,$workingTime);
|
|
|
- }
|
|
|
- if ($this['round_check_in_at']&&$this['round_check_out_at']&&!$this['relax_time']){
|
|
|
- $workingTime=round(Carbon::parse($this['round_check_out_at'])->diffInSeconds(Carbon::parse($this['round_check_in_at']))/3600,2);
|
|
|
- $checkInTime=Carbon::parse($this['round_check_in_at']);
|
|
|
- $checkOutTime=Carbon::parse($this['round_check_out_at'])->format('H');
|
|
|
- return $this->minusLunchTime($checkInTime,$checkOutTime,$workingTime);
|
|
|
- }
|
|
|
- if ($this['round_check_in_at']&&$this['round_check_out_at']&&$this['relax_time']){
|
|
|
- $workingTime=round(Carbon::parse($this['round_check_out_at'])->diffInSeconds(Carbon::parse($this['round_check_in_at']))/3600,2);
|
|
|
- $checkInTime=Carbon::parse($this['round_check_in_at']);
|
|
|
- $checkOutTime=Carbon::parse($this['round_check_out_at'])->format('H');
|
|
|
- return $this->minusLunchTime($checkInTime,$checkOutTime,$workingTime)-$this['relax_time']/60;
|
|
|
- }
|
|
|
+
|
|
|
+ if ($this['round_check_in_at'] && !$this['round_check_out_at'] && !$this['relax_time']) {
|
|
|
+ $workingTime = round(Carbon::parse(Carbon::now())->diffInSeconds(Carbon::parse($this['round_check_in_at'])) / 3600, 2);
|
|
|
+ $checkInTime = Carbon::parse($this['round_check_in_at']);
|
|
|
+ $checkOutTime = Carbon::parse(Carbon::now())->format('H');
|
|
|
+ return $this->minusLunchTime($checkInTime, $checkOutTime, $workingTime);
|
|
|
+ }
|
|
|
+ if ($this['round_check_in_at'] && $this['round_check_out_at'] && !$this['relax_time']) {
|
|
|
+ $workingTime = round(Carbon::parse($this['round_check_out_at'])->diffInSeconds(Carbon::parse($this['round_check_in_at'])) / 3600, 2);
|
|
|
+ $checkInTime = Carbon::parse($this['round_check_in_at']);
|
|
|
+ $checkOutTime = Carbon::parse($this['round_check_out_at'])->format('H');
|
|
|
+ return $this->minusLunchTime($checkInTime, $checkOutTime, $workingTime);
|
|
|
+ }
|
|
|
+ if ($this['round_check_in_at'] && $this['round_check_out_at'] && $this['relax_time']) {
|
|
|
+ $workingTime = round(Carbon::parse($this['round_check_out_at'])->diffInSeconds(Carbon::parse($this['round_check_in_at'])) / 3600, 2);
|
|
|
+ $checkInTime = Carbon::parse($this['round_check_in_at']);
|
|
|
+ $checkOutTime = Carbon::parse($this['round_check_out_at'])->format('H');
|
|
|
+ return $this->minusLunchTime($checkInTime, $checkOutTime, $workingTime) - $this['relax_time'] / 60;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//工作时长减午饭休息时间
|
|
|
@@ -184,45 +199,54 @@ class LaborReport extends Model
|
|
|
//转场序号
|
|
|
public function getSequenceAttribute()
|
|
|
{
|
|
|
- if(Arr::has($this->tempFields,'sequence'))return $this->tempFields['sequence'];
|
|
|
- $laborReports=LaborReport::where('enter_number',$this['enter_number'])->orderBy('id','asc')->get();
|
|
|
- foreach($laborReports as $i=>$laborReport){
|
|
|
- if($laborReport['id']==$this['id']){
|
|
|
- $this->tempFields['sequence']=$i+1;
|
|
|
- return $this->tempFields['sequence'];
|
|
|
+ if(self::$withoutAppends) {
|
|
|
+ if (Arr::has($this->tempFields, 'sequence')) return $this->tempFields['sequence'];
|
|
|
+ $laborReports = LaborReport::where('enter_number', $this['enter_number'])->orderBy('id', 'asc')->get();
|
|
|
+ foreach ($laborReports as $i => $laborReport) {
|
|
|
+ if ($laborReport['id'] == $this['id']) {
|
|
|
+ $this->tempFields['sequence'] = $i + 1;
|
|
|
+ return $this->tempFields['sequence'];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
public function getAmountOfJoinedAttribute()
|
|
|
{
|
|
|
- if(Arr::has($this->tempFields,'amountOfJoined'))return $this->tempFields['amountOfJoined'];
|
|
|
- $this->tempFields['amountOfJoined']=LaborReport::where('enter_number',$this['enter_number'])->orderBy('id','asc')->count();
|
|
|
- return $this->tempFields['amountOfJoined'];
|
|
|
+ if(self::$withoutAppends) {
|
|
|
+ if (Arr::has($this->tempFields, 'amountOfJoined')) return $this->tempFields['amountOfJoined'];
|
|
|
+ $this->tempFields['amountOfJoined'] = LaborReport::where('enter_number', $this['enter_number'])->orderBy('id', 'asc')->count();
|
|
|
+ return $this->tempFields['amountOfJoined'];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//进场时间
|
|
|
public function getEnterAtAttribute()
|
|
|
{
|
|
|
- $laborReportStatus=LaborReportStatus::where('labor_report_id',$this['id'])->where('status','未审核')->orderBy('id','desc')->first();
|
|
|
- if (empty($laborReportStatus))return null;
|
|
|
- return Carbon::parse($laborReportStatus['created_at'])->format('Y-m-d H:i:s');
|
|
|
+ if(self::$withoutAppends) {
|
|
|
+ $laborReportStatus = LaborReportStatus::where('labor_report_id', $this['id'])->where('status', '未审核')->orderBy('id', 'desc')->first();
|
|
|
+ if (empty($laborReportStatus)) return null;
|
|
|
+ return Carbon::parse($laborReportStatus['created_at'])->format('Y-m-d H:i:s');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function getEnteringRecordAttribute()
|
|
|
{
|
|
|
- $laborReport=LaborReport::with(['laborReportStatus'=>function($query){
|
|
|
- return $query->whereIn('status',['已入场','未审核']);
|
|
|
- }])->where('user_id',$this['user_id'])->orderBy('id','desc')->first();
|
|
|
- if(empty($laborReport))return null;
|
|
|
- return $laborReport;
|
|
|
-
|
|
|
+ if(self::$withoutAppends) {
|
|
|
+ $laborReport = LaborReport::with(['laborReportStatus' => function ($query) {
|
|
|
+ return $query->whereIn('status', ['已入场', '未审核']);
|
|
|
+ }])->where('user_id', $this['user_id'])->orderBy('id', 'desc')->first();
|
|
|
+ if (empty($laborReport)) return null;
|
|
|
+ return $laborReport;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function getExitAtAttribute()
|
|
|
{
|
|
|
- $laborReportStatus=LaborReportStatus::where('labor_report_id',$this['id'])->where('status','已退场')->orderBy('id','desc')->first();
|
|
|
- if (empty($laborReportStatus))return null;
|
|
|
- return Carbon::parse($laborReportStatus['created_at'])->format('Y-m-d H:i:s');
|
|
|
+ if(self::$withoutAppends) {
|
|
|
+ $laborReportStatus = LaborReportStatus::where('labor_report_id', $this['id'])->where('status', '已退场')->orderBy('id', 'desc')->first();
|
|
|
+ if (empty($laborReportStatus)) return null;
|
|
|
+ return Carbon::parse($laborReportStatus['created_at'])->format('Y-m-d H:i:s');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//创建或获取进场编号
|
|
|
@@ -236,8 +260,10 @@ class LaborReport extends Model
|
|
|
}
|
|
|
|
|
|
public function getIsExportAttribute(){
|
|
|
- $laborReportStatus=$this->laborReportStatus()->where('labor_report_id',$this['id'])->orderBy('id','desc')->first();
|
|
|
- return $laborReportStatus['status']=='已退场'?true:false;
|
|
|
+ if(self::$withoutAppends) {
|
|
|
+ $laborReportStatus = $this->laborReportStatus()->where('labor_report_id', $this['id'])->orderBy('id', 'desc')->first();
|
|
|
+ return $laborReportStatus['status'] == '已退场' ? true : false;
|
|
|
+ }
|
|
|
}
|
|
|
//出场更新临时工报表信息
|
|
|
static function exitAndChangeLaborReport($laborReport,$userDutyCheck){
|