|
|
@@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
|
use App\Traits\ModelLogChanging;
|
|
|
+use Tightenco\Collect\Support\Collection;
|
|
|
|
|
|
class LaborReport extends Model
|
|
|
{
|
|
|
@@ -24,8 +25,8 @@ class LaborReport extends Model
|
|
|
'user_duty_check_id','relax_time','remark'
|
|
|
];
|
|
|
protected $appends = [
|
|
|
- 'is_exportGroup','is_export', 'exit_at','enter_at','sequence', 'amountOfJoined','thisRecordOnlineTime','thisRecordWorkingTime','thisRoundRecordWorkingTime',
|
|
|
- 'totalOnlineTime','verifyPerson','userDutyCheckVerifyUserId','isAdult','round_check_in_at','round_check_out_at','has_group_verify_right',
|
|
|
+ 'is_exportGroup',/*'sequence',*//*'amountOfJoined',*/'thisRecordOnlineTime','thisRecordWorkingTime','thisRoundRecordWorkingTime',
|
|
|
+ /*'totalOnlineTime',*/'verifyPerson','userDutyCheckVerifyUserId','isAdult','round_check_in_at','round_check_out_at','has_group_verify_right',
|
|
|
];
|
|
|
protected $tempFields = [
|
|
|
'temEnteringRecord',
|
|
|
@@ -52,7 +53,9 @@ class LaborReport extends Model
|
|
|
public function laborReportStatus(){
|
|
|
return $this->hasMany('App\LaborReportStatus','labor_report_id','id');
|
|
|
}
|
|
|
-
|
|
|
+ public function laborReports(){
|
|
|
+ return $this->hasMany(get_class($this),'enter_number','enter_number');
|
|
|
+ }
|
|
|
|
|
|
public function getRoundCheckInAtAttribute(){
|
|
|
if (!$this['check_in_at'])return null;
|
|
|
@@ -68,7 +71,7 @@ class LaborReport extends Model
|
|
|
if ($round_check_out_at>=25&&$round_check_out_at<=55) return Carbon::parse($this['check_out_at'])->clone()->setMinutes(30)->setSeconds(00)->format('Y-m-d H:i:s');
|
|
|
if ($round_check_out_at>55&&$round_check_out_at<=59) return Carbon::parse($this['check_out_at'])->clone()->addHour()->setMinutes(00)->setSeconds(00)->format('Y-m-d H:i:s');
|
|
|
}
|
|
|
- //has_group_verify_right'
|
|
|
+
|
|
|
public function getHasGroupVerifyRightAttribute(){
|
|
|
if (!Gate::allows('人事管理-临时工报表')){return null; }
|
|
|
if (Gate::allows('人事管理-临时工报表-管理全部组')){return true;}
|
|
|
@@ -77,6 +80,16 @@ class LaborReport extends Model
|
|
|
if (count($userWorkgroupIds)!=0) return in_array($this['user_workgroup_id'],$userWorkgroupIds);
|
|
|
|
|
|
}
|
|
|
+ public function getEnteringRecordAttribute()
|
|
|
+ {
|
|
|
+ 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 getIsExportGroupAttribute(){
|
|
|
return $this['check_out_at']? true:false;
|
|
|
@@ -89,20 +102,18 @@ class LaborReport extends Model
|
|
|
return $this['userDutyCheck']['verify_user_id']?$this['userDutyCheck']['verify_user_id']:'';
|
|
|
}
|
|
|
//总在线时长
|
|
|
- public function getTotalOnlineTimeAttribute(){
|
|
|
- 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 getTotalOnlineTimeAttribute(){
|
|
|
+// if(self::$withoutAppends) {
|
|
|
+// $totalOnlineTime = $this->laborReports->reduce(function ($value, $laborReport) {
|
|
|
+// return ($value ?? 0) + $laborReport['thisRecordOnlineTime'];
|
|
|
+// });
|
|
|
+// return $totalOnlineTime;
|
|
|
+// }
|
|
|
+// }
|
|
|
//总工作时长
|
|
|
public function getTotalWorkingTimeAttribute(){
|
|
|
if(self::$withoutAppends) {
|
|
|
- $laborReports = LaborReport::where('enter_number', $this['enter_number'])->orderBy('id', 'asc')->get();
|
|
|
- $totalWorkingTime = $laborReports->reduce(function ($value, $laborReport) {
|
|
|
+ $totalWorkingTime = $this->laborReports->reduce(function ($value, $laborReport) {
|
|
|
return ($value ?? 0) + $laborReport['thisRecordWorkingTime'];
|
|
|
});
|
|
|
return $totalWorkingTime;
|
|
|
@@ -111,8 +122,7 @@ class LaborReport extends Model
|
|
|
//本轮工作起始时间
|
|
|
public function getThisRoundOnlineStartTimeAttribute(){
|
|
|
if(self::$withoutAppends) {
|
|
|
- $laborReports = LaborReport::where('enter_number', $this['enter_number'])->orderBy('id', 'asc')->get();
|
|
|
- foreach ($laborReports as $laborReport) {
|
|
|
+ foreach ($this->laborReports as $laborReport) {
|
|
|
if ($laborReport['enter_at'] && $laborReport['check_in_at'])
|
|
|
return $laborReport['check_in_at'];
|
|
|
}
|
|
|
@@ -121,8 +131,7 @@ class LaborReport extends Model
|
|
|
//本轮工作结束时间
|
|
|
public function getThisRoundOnlineEndTimeAttribute(){
|
|
|
if(self::$withoutAppends) {
|
|
|
- $laborReports = LaborReport::where('enter_number', $this['enter_number'])->get();
|
|
|
- foreach ($laborReports as $laborReport) {
|
|
|
+ foreach ($this->laborReports as $laborReport) {
|
|
|
if ($laborReport['exit_at'] && $laborReport['check_out_at'])
|
|
|
return $laborReport['check_out_at'];
|
|
|
}
|
|
|
@@ -201,55 +210,74 @@ class LaborReport extends Model
|
|
|
}
|
|
|
|
|
|
//转场序号
|
|
|
- public function getSequenceAttribute()
|
|
|
+// public function getSequenceAttribute()
|
|
|
+// {
|
|
|
+// if(self::$withoutAppends) {
|
|
|
+// if (Arr::has($this->tempFields, 'sequence')) return $this->tempFields['sequence'];
|
|
|
+// foreach ($this->laborReports as $i => $laborReport) {
|
|
|
+// if ($laborReport['id'] == $this['id']) {
|
|
|
+// $this->tempFields['sequence'] = $i + 1;
|
|
|
+// return $this->tempFields['sequence'];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// public function getAmountOfJoinedAttribute()
|
|
|
+// {
|
|
|
+// if(self::$withoutAppends) {
|
|
|
+// if (Arr::has($this->tempFields, 'amountOfJoined')) return $this->tempFields['amountOfJoined'];
|
|
|
+// $this->tempFields['amountOfJoined'] = count($this->laborReports);
|
|
|
+// return $this->tempFields['amountOfJoined'];
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ private function checkExitStatus()
|
|
|
{
|
|
|
- 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'];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ $status = $this->laborReportStatus->sortByDesc('id')->first();
|
|
|
+ $this->is_export = $status['status'] == '已退场' ? true : false;
|
|
|
+ if ($status['status'] == '已退场')$this->exit_at=Carbon::parse($status['created_at'])->format('Y-m-d H:i:s');
|
|
|
}
|
|
|
- public function getAmountOfJoinedAttribute()
|
|
|
- {
|
|
|
- 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'];
|
|
|
- }
|
|
|
+ private function checkEnterStatus(){
|
|
|
+ $status = $this->laborReportStatus->sortBy('id')->first();
|
|
|
+ if ($status['status'] == '未审核')$this->enter_at=Carbon::parse($status['created_at'])->format('Y-m-d H:i:s');
|
|
|
}
|
|
|
-
|
|
|
- //进场时间
|
|
|
- public function getEnterAtAttribute()
|
|
|
- {
|
|
|
- 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');
|
|
|
+ private function checkAmountOfJoined(){
|
|
|
+ if ($this->amountOfJoined!=count($this->laborReports))$this->amountOfJoined=count($this->laborReports);
|
|
|
+ }
|
|
|
+ private function checkSequence(){
|
|
|
+ if (!$this->sequence) foreach ($this->laborReports as $i => $laborReport) {
|
|
|
+ if ($laborReport['id'] == $this['id']) {
|
|
|
+ $this->sequence = $i + 1;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ private function checkTotalOnlineTime(){
|
|
|
+ if (!$this->totalOnlineTime) $this->totalOnlineTime = $this->laborReports->reduce(function ($value, $laborReport) {
|
|
|
+ return ($value ?? 0) + $laborReport['thisRecordOnlineTime'];
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- public function getEnteringRecordAttribute()
|
|
|
+ public static function processing($laborReports)
|
|
|
{
|
|
|
- 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;
|
|
|
+ foreach ($laborReports as $laborReport){
|
|
|
+ /** @var LaborReport $laborReport */
|
|
|
+ $laborReport->checkEnterStatus(); //校验进场并赋值
|
|
|
+ $laborReport->checkAmountOfJoined();
|
|
|
+ $laborReport->checkSequence();
|
|
|
+ $laborReport->checkTotalOnlineTime();
|
|
|
+ $laborReport->checkExitStatus(); //校验出场并赋值
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public function getExitAtAttribute()
|
|
|
+ public static function enter($laborReports)
|
|
|
{
|
|
|
- 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');
|
|
|
+ foreach ($laborReports as $laborReport){
|
|
|
+ /** @var LaborReport $laborReport */
|
|
|
+ $laborReport->checkEnterStatus(); //校验进场并赋值
|
|
|
+ $laborReport->checkAmountOfJoined();
|
|
|
+ $laborReport->checkSequence();
|
|
|
+ $laborReport->checkTotalOnlineTime();
|
|
|
+ $laborReport->checkExitStatus(); //校验出场并赋值
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -262,13 +290,6 @@ class LaborReport extends Model
|
|
|
$this['enter_number']=$enteringNumber;
|
|
|
return $enteringNumber;
|
|
|
}
|
|
|
-
|
|
|
- public function getIsExportAttribute(){
|
|
|
- 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){
|
|
|
$laborReportStatus=new LaborReportStatus([
|
|
|
@@ -287,7 +308,7 @@ class LaborReport extends Model
|
|
|
$laborReport->online_duration=$online_duration;
|
|
|
}
|
|
|
$laborReport->update();
|
|
|
- $laborReport->is_export=$laborReport->getIsExportAttribute();
|
|
|
+ $laborReport->is_export=$laborReport->checkExitStatus();
|
|
|
return $laborReport;
|
|
|
}
|
|
|
|