guard()->user(); $time = $request->filled('time') ? Carbon::createFromFormat('Y-m', $request->input('time')) : now(); $list = EmployeeSign::where('employee_id', $user->id)->filter(['month' => $time->format('Y-m')])->get(); $data = []; $start = $time->copy()->startOfMonth(); $end = $time->copy()->endOfMonth(); do { $info = $list->where(fn($item) => $item->date->format('Y-m-d') == $start->format('Y-m-d'))->first(); array_push($data, [ 'date' => $start->format('Y-m-d'), 'sign_status' => $info ? $info->sign_status : null, 'first_time' => $info?->first_time->format('H:i'), 'last_time' => $info?->last_time->format('H:i'), ]); $start->addDay(); } while(!$end->isSameDay($start)); return $data; } public function info(Request $request, EmployeeSignService $service) { $user = $this->guard()->user(); $date = now(); // 上午: 上班打卡, 下午: 下班打卡 $time = $date->format('H') <= 12 ? SignTime::Morning : SignTime::Afternoon; // 根据定位的距离判断, 是否外勤 $type = SignType::Normal; // 当前位置不在考勤范围内,请选择外勤打卡 $description = '已进入考勤范围xx店'; return compact('time', 'type', 'description'); } public function store(Request $request, EmployeeSignService $service) { $request->validate([ 'type' => ['required'], 'time' => ['required'], ]); $user = $this->guard()->user(); $time = SignTime::from($request->input('time')); try { DB::beginTransaction(); if (!$service->signDay($user, $time, now(), $request->only(['remarks', 'position', 'type']))) { throw new RuntimeException($service->getError()); } DB::commit(); return response('', Response::HTTP_OK); } catch (\Exception $e) { DB::rollBack(); throw new RuntimeException($e->getMessage()); } } }