芝麻web文件管理V1.00
编辑当前文件:/home/sditechnicalteam/public_html/app/Models/ProjectTimeLog.php
belongsTo(User::class, 'user_id')->withoutGlobalScope(ActiveScope::class); } public function editor(): BelongsTo { return $this->belongsTo(User::class, 'edited_by_user')->withoutGlobalScope(ActiveScope::class); } public function project(): BelongsTo { return $this->belongsTo(Project::class, 'project_id')->withTrashed(); } public function task(): BelongsTo { return $this->belongsTo(Task::class, 'task_id')->withTrashed(); } public function breaks(): HasMany { return $this->hasMany(ProjectTimeLogBreak::class, 'project_time_log_id'); } public function activeBreak(): HasOne { return $this->hasOne(ProjectTimeLogBreak::class, 'project_time_log_id')->whereNull('end_time'); } protected $appends = ['hours', 'duration', 'timer']; public function getDurationAttribute() { $finishTime = now(); if (!is_null($this->start_time)) { return $finishTime->diff($this->start_time)->format('%d days %H Hrs %i Mins %s Secs'); } return ''; } public function getHoursAttribute() { $totalMinutes = $this->total_minutes; $totalMinutes = $totalMinutes - $this->breaks->sum('total_minutes'); $timeLog = intdiv($totalMinutes, 60) . ' ' . __('app.hrs') . ' '; if (($totalMinutes % 60) > 0) { $timeLog .= ($totalMinutes % 60) . ' ' . __('app.mins'); } return $timeLog; } public function getTimerAttribute() { $finishTime = now(); $settings = company(); $startTime = Carbon::parse($this->start_time)->timezone($settings->timezone); $days = $finishTime->diff($startTime)->format('%d'); $hours = $finishTime->diff($startTime)->format('%H'); if ($hours < 10) { $hours = '0' . $hours; } $minutes = $finishTime->diff($startTime)->format('%i'); if ($minutes < 10) { $minutes = '0' . $minutes; } $secs = $finishTime->diff($startTime)->format('%s'); if ($secs < 10) { $secs = '0' . $secs; } return ((int)$days * 24) + (int)$hours . ':' . (int)$minutes . ':' . (int)$secs; } public static function dateWiseTimelogs($date, $userID = null) { $timelogs = ProjectTimeLog::with('breaks')->whereDate('start_time', $date); if (!is_null($userID)) { $timelogs = $timelogs->where('user_id', $userID); } return $timelogs = $timelogs->get(); } public static function weekWiseTimelogs($startDate, $endDate, $userID = null) { $timelogs = ProjectTimeLog::whereBetween(DB::raw('DATE(`start_time`)'), [$startDate, $endDate]); if (!is_null($userID)) { $timelogs = $timelogs->where('user_id', $userID); } return $timelogs = $timelogs->sum('total_minutes'); } public static function projectActiveTimers($projectId) { return ProjectTimeLog::with('user')->whereNull('end_time') ->where('project_id', $projectId) ->get(); } public static function taskActiveTimers($taskId) { return ProjectTimeLog::with('user')->whereNull('end_time') ->where('task_id', $taskId) ->get(); } public static function projectTotalHours($projectId) { return ProjectTimeLog::where('project_id', $projectId) ->sum('total_hours'); } public static function projectTotalMinuts($projectId) { return ProjectTimeLog::where('project_id', $projectId) ->sum('total_minutes'); } public static function memberActiveTimer($memberId) { return ProjectTimeLog::with('project')->where('user_id', $memberId) ->whereNull('end_time') ->first(); } }