model = new BoxModel(); } /** * 静态化入口 * @return static|null */ public static function make() { if (!self::$instance) { self::$instance = new static(); } return self::$instance; } /** * 获取最新一期福袋信息 * @return BoxModel|array|mixed|\think\Model|null * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getNewInfo() { $info = BoxModel::where(['status' => 1, 'open_status' => 1])->order('id desc')->find(); $info = $info ? $info->toArray() : []; $id = isset($info['id']) ? $info['id'] : 0; if (empty($info) || $id <= 0) { sr_throw('暂未开启'); } $cur_time = time(); $time = sr_getcurtime($cur_time, 'Y-m-d '); $times = explode('|', $info['time_set']); $appoint_status = 1; // 1 还未开始 2 进行中 3已结束 $dis_time = 0; // 当前时间大于 最后一场结束时间 if ($appoint_status != 3) { $end_timesarr = explode('-', $times[count($times) - 1]); $end_randtime = strtotime($time . $end_timesarr[1]); if ($cur_time > $end_randtime) { $appoint_status = 3; } } // 是否拿到最近的一场未开始距离时间 if ($appoint_status != 3) { foreach ($times as $key => $val) { $time_cur = explode('-', $val); $time_randbegin = strtotime($time . $time_cur[0]); $time_randend = strtotime($time . $time_cur[1]); if ($cur_time > $time_randbegin && $cur_time < $time_randend) { // 正在这一场进行中 $appoint_status = 2; } } if ($appoint_status != 2) { $has_get = false; foreach ($times as $key => $val) { $time_cur = explode('-', $val); $time_randbegin = strtotime($time . $time_cur[0]); if ($cur_time < $time_randbegin && !$has_get) { // 正在这一场进行中 $has_get = true; $dis_time = $time_randbegin - $cur_time; } } } } $isOpen = (int)SystemConfigService::make()->getConfigByName('fudai_is_apply', 1, 'fudai'); $info['is_open'] = $isOpen; $info['appoint_status'] = $info['open_status'] == 1 && $isOpen == 1 ? $appoint_status : 4; $info['dis_time'] = $dis_time; return $info; } /** * 最新一期盒子缓存信息 * @return array|mixed|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getCacheInfo() { $cacheKey = "caches:temp:box:new"; $info = RedisCache::get($cacheKey); if (empty($info)) { $info = $this->model->where(['status' => 1, 'open_status' => 1]) ->field('id,time_set') ->order('id desc') ->find(); $info = $info ? $info->toArray() : []; if ($info) { RedisCache::set($cacheKey, $info, rand(5, 10)); } } // 开奖的半个小时 $curTime = time(); $timesymdtring = sr_getcurtime(time(), 'Y-m-d '); $isMidhanle = false; $arr = explode('|', $info['time_set']); foreach ($arr as $key => $val) { $times = explode('-', $val); if ($curTime > strtotime($timesymdtring . $times[0]) && $curTime < strtotime($timesymdtring . $times[1])) { // 正在预约中 $isMidhanle = true; } } if ($isMidhanle) { return false; } return $info; } }