public function formatExpect($expect, $opentime) { //休市日数 $restDay = 0; $openY = date('Y', $opentime); foreach (\Lottery\Fetch\Rest::getRestTimeInfo($this->getName()) as $key => $item) { if ($openY == $key && $opentime >= strtotime($item['end'])) { $startDatetime = new \DateTime($item['start']); $endDatetime = new \DateTime($item['end']); $datetimeDiff = $startDatetime->diff($endDatetime); $restDay += intval($datetimeDiff->format('%a')); } } return $openY . str_pad(date('z', $opentime) + 1 - $restDay, 3, '0', STR_PAD_LEFT); }
public function getCurrentSaleExpectInfo($deadline = 30) { //获取开始统计日期到现在时间的天数 $startCountDatetime = new \DateTime(self::START_COUNT_DATE); $nowDatetime = new \DateTime(date('Y-m-d', $this->nowTimestamp)); $datetimeDiff = $startCountDatetime->diff($nowDatetime); $diffDay = intval($datetimeDiff->format('%a')); //今天第一期期号 $expect = self::START_COUNT_EXPECT + $diffDay * self::DAILY_OPEN_EXPECT_NUM - 1; $opentime = 0; $awardTimeInfo = $this->getAwardTimeInfo(); $restTimeInfo = \Lottery\Fetch\Rest::getRestTimeInfo($this->getName()); $isRest = false; foreach ($restTimeInfo as $item) { if ($this->nowTimestamp >= strtotime($item['start']) && $this->nowTimestamp < strtotime($item['end'])) { $isRest = true; break; } } $countTimestamp = $this->nowTimestamp + $deadline; foreach ($awardTimeInfo as $item) { $start = strtotime($item['start'], $this->nowTimestamp); $end = strtotime($item['end'], $this->nowTimestamp); for ($i = $start; $i <= $end; $i += $item['interval']) { if (!$isRest) { $expect++; } if ($countTimestamp < $i) { $opentime = $i; break 2; } } } if (!$opentime) { //当日最后一期后当前销售期号为次日第一期 $expect++; $opentime = strtotime(date('Y-m-d', strtotime('+1 day', $this->nowTimestamp)) . ' ' . $awardTimeInfo[0]['start']); } //休市判断 $restDay = 0; foreach ($restTimeInfo as $item) { if ($opentime >= strtotime($item['start']) && $opentime < strtotime($item['end'])) { //在休市时间内,当前销售期号为休市结束后第一期 $opentime = strtotime(date('Y-m-d', strtotime($item['end'])) . ' ' . $awardTimeInfo[0]['start']); } elseif ($opentime >= strtotime($item['end'])) { $startDatetime = new \DateTime($item['start']); $endDatetime = new \DateTime($item['end']); $datetimeDiff = $startDatetime->diff($endDatetime); $restDay += intval($datetimeDiff->format('%a')); } } $expect -= $restDay * self::DAILY_OPEN_EXPECT_NUM; return array('status' => 1, 'expect' => $this->formatExpect($expect, $opentime), 'opentime' => $opentime); }
/** * 获取当前销售期号信息 * @param int $deadline 截止时间 * * @return array( 'status' => 1, //1 成功 0 失败 'expect' => '141106036', 'opentime' => 1402143035 ) */ public function getCurrentSaleExpectInfo($deadline = 30) { $countTimestamp = $this->nowTimestamp; if ($this->getName() == 'xjssc') { $nowTimeHis = date('H:i:s', $this->nowTimestamp); if ($nowTimeHis >= '00:00:00' && $nowTimeHis < '02:00:00') { $countTimestamp += 3600 * 24; } } $countTimestamp += $deadline; $expect = $opentime = $sales_second = 0; $awardTimeInfo = $this->getAwardTimeInfo(); foreach ($awardTimeInfo as $item) { $start = strtotime($item['start'], $this->nowTimestamp); $end = strtotime($item['end'], $this->nowTimestamp); if ($item['start'] == '00:00:00') { $start += 3600 * 24; $end += 3600 * 24; } for ($i = $start; $i <= $end; $i += $item['interval']) { $expect++; if ($countTimestamp < $i) { $opentime = $i; $sales_second = $item['interval']; break 2; } } } if (!$opentime) { if (!isset($awardTimeInfo[0]['start'])) { return array('status' => 0); } //当日最后一期后当前销售期号为次日第一期 $expect = 1; $opentime = strtotime(date('Y-m-d', strtotime('+1 day', $this->nowTimestamp)) . ' ' . $awardTimeInfo[0]['start']); $sales_second = $awardTimeInfo[0]['interval']; } //上一期信息 $prev_expect = $expect - 1; if ($prev_expect == 0) { $prev_expect = static::DAILY_OPEN_EXPECT_NUM; } $prev_expect = $this->formatExpect($prev_expect, $opentime - $sales_second); //休市判断 if ($this->getName() == 'xjssc' && $expect >= 84) { $opentime -= 3600 * 24; } foreach (\Lottery\Fetch\Rest::getRestTimeInfo($this->getName()) as $item) { if ($opentime >= strtotime($item['start']) && $opentime < strtotime($item['end'])) { if (!isset($awardTimeInfo[0]['start'])) { return array('status' => 0); } //在休市时间内,当前销售期号为休市结束后第一期 $expect = 1; $opentime = strtotime(date('Y-m-d', strtotime($item['end'])) . ' ' . $awardTimeInfo[0]['start']); $sales_second = $awardTimeInfo[0]['interval']; $prev_expect = static::DAILY_OPEN_EXPECT_NUM; $prev_expect = $this->formatExpect($prev_expect, strtotime($item['start']) - 1); } } return array('status' => 1, 'expect' => $this->formatExpect($expect, $opentime), 'prev_expect' => $prev_expect, 'sales_second' => $sales_second, 'opentime' => $opentime); }