zoukankan      html  css  js  c++  java
  • 代码学习总结

            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)); // 当月最后一天的函数

  • 相关阅读:
    Linux学习路径 -- 1、文件目录操作命令
    第一次认识Postman
    接口测试的基础理论
    浅浅记录一哈HTTP接口
    Linux 的安装和使用
    QTP11 安装笔记:win10
    fiddler的下载安装与配置
    adb 下载安装
    maven 下载 安装 环境配置
    idea 2018.3.4安装破解
  • 原文地址:https://www.cnblogs.com/cjjjj/p/10186346.html
Copyright © 2011-2022 走看看