return $this->wrapTransaction(function () use ($request) { $periods = $request->input('periods', []); $teacherId = $request->input('teacher_id', 0); $action = $request->input('action', 'camp-on'); $role = $request->input('role', 'user'); ScheduleModule::getDomainService()->bookSchedules( $teacherId, $periods, $action, $role ); return ''; }, 'bookSchedule');
protected function wrapTransaction($callable, $funcKey) { try { DB::beginTransaction(); $result = $callable(); DB::commit(); return $this->response($result); } catch (\Exception $ex) { DB::rollback(); \Log::error($funcKey); $code = $ex->getCode(); \Log::error($code . ' ' . $ex->getMessage() . ' ' . $ex->getTraceAsString()); if (empty($code)) { $code = -1; } return $this->response(null, $code, $ex->getMessage()); } }
$schedules = $schedules->filter(function ($item) { // 如果某天零点时间大于time()时间,那么就选取某天的零点时间 if (strtotime($item->dateFrom) > time()) { $time = strtotime($item->dateFrom); // 获取开始时间 } else { // 否则就获取当天日期加现在的时间点的时间戳 $time = strtotime(explode(' ', $item->dateFrom)[0] . ' ' . date('H:i:s')); } // 获取开始时间 $timeLimit = self::filterStartTime($time); return $item->timeFrom >= $timeLimit; }); //按日期分组 $schedules = $schedules->mapToGroups(function ($item) { $key = explode(' ', $item->dateFrom)[0]; return [$key => [ 'date' => $key, 'time_from' => $item->timeFrom, 'time_to' => $item->timeTo, 'is_free' => $item->isFree, ] ]; })->toArray();
$start = date('Y-m-d H:i:s', max(time(), strtotime($month))); $end = date('Y-m-t 23:59:59', strtotime($month)); // 当月最后一天的函数