YS : 秒杀

es
wmc 7 months ago
parent b370246dee
commit 4b172f54ac
  1. 16
      app/api/model/sharp/Active.php
  2. 54
      app/api/service/sharp/Active.php

@ -44,31 +44,31 @@ class Active extends ActiveModel
$todayTime = strtotime(date('Y-m-d')); $todayTime = strtotime(date('Y-m-d'));
return $this->getActiveByDate($todayTime, '='); return $this->getActiveByDate($todayTime, '=');
} }
/** /**
* 获取天的活动 * 获取天的活动
* @return Active|array|null * @return Active|array|null
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function getTmowActive() public function getNextActive()
{ {
$todayTime = strtotime(date('Y-m-d',strtotime("+1 day"))); $todayTime = strtotime(date('Y-m-d'));
return $this->getActiveByDate($todayTime, '='); return $this->getActiveByDate($todayTime, '>');
} }
/** /**
* 获取天的活动 * 获取天的活动
* @return Active|array|null * @return Active|array|null
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function getNextActive() public function gettmoActive()
{ {
$todayTime = strtotime(date('Y-m-d')); $todayTime = strtotime('+1 day');
return $this->getActiveByDate($todayTime, '>'); return $this->getActiveByDate($todayTime, '>');
} }
/** /**
* 根据日期获取活动 * 根据日期获取活动
* @param $date * @param $date

@ -306,14 +306,13 @@ class Active extends BaseService
// 获取即将开始的活动 // 获取即将开始的活动
$data = array_merge($data, $this->getSoonActive($todyActive)); $data = array_merge($data, $this->getSoonActive($todyActive));
} }
//获取明天活动 $tmoActive = $this->ActiveModel->gettmoActive();
$tmowActive = $this->ActiveModel->getNowActive(); if (!empty($tmoActive)) {
if (!empty($tmowActive)) {
// 获取即将开始的活动 // 获取即将开始的活动
$data = array_merge($data, $this->getSoonActive($todyActive)); $data = array_merge($data, $this->getmingActive($tmoActive));
} }
// 获取预告的活动 // 获取预告的活动
$data[] = $this->getNoticeActive(); // $data[] = $this->getNoticeActive();
return array_values(array_filter($data)); return array_values(array_filter($data));
} }
@ -365,7 +364,6 @@ class Active extends BaseService
foreach ($list as $item) { foreach ($list as $item) {
$startTime = $todyActive['active_date'] + ($item->getData('active_time') * 60 * 60); $startTime = $todyActive['active_date'] + ($item->getData('active_time') * 60 * 60);
$endTime = $startTime + (1 * 60 * 60); $endTime = $startTime + (1 * 60 * 60);
if(strtotime(date('Y-m-d',$startTime))>strtotime(date("y-m-d",time()))){
$data[] = [ $data[] = [
'active_id' => $todyActive['active_id'], 'active_id' => $todyActive['active_id'],
'active_time_id' => $item['active_time_id'], 'active_time_id' => $item['active_time_id'],
@ -373,12 +371,32 @@ class Active extends BaseService
'start_time' => $this->onFormatTime($startTime), 'start_time' => $this->onFormatTime($startTime),
'end_time' => $this->onFormatTime($endTime), 'end_time' => $this->onFormatTime($endTime),
'count_down_time' => $this->onFormatTime($startTime), 'count_down_time' => $this->onFormatTime($startTime),
'status' => ActiveStatusEnum::STATE_NOTICE, 'status' => ActiveStatusEnum::STATE_SOON,
'status_text' => '明日预告', 'status_text' => '即将开抢',
'status_text2' => $this->onFormatTime($startTime) . ' 开始', 'status_text2' => '即将开抢',
'sharp_modular_text' => $this->onFormatTime($startTime) . ' 开始', 'sharp_modular_text' => "{$item['active_time']} 场预告",
]; ];
}else{ }
return $data;
}
/**
* 获取即将开始的活动
* @param $todyActive
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getmingActive($todyActive): array
{
// 当前的时间点
$list = $this->ActiveTimeModel->getNextActiveTimes($todyActive['active_id']);
if (empty($list) || $list->isEmpty()) return [];
// 整理数据
$data = [];
foreach ($list as $item) {
$startTime = $todyActive['active_date'] + ($item->getData('active_time') * 60 * 60);
$endTime = $startTime + (1 * 60 * 60);
$data[] = [ $data[] = [
'active_id' => $todyActive['active_id'], 'active_id' => $todyActive['active_id'],
'active_time_id' => $item['active_time_id'], 'active_time_id' => $item['active_time_id'],
@ -386,18 +404,14 @@ class Active extends BaseService
'start_time' => $this->onFormatTime($startTime), 'start_time' => $this->onFormatTime($startTime),
'end_time' => $this->onFormatTime($endTime), 'end_time' => $this->onFormatTime($endTime),
'count_down_time' => $this->onFormatTime($startTime), 'count_down_time' => $this->onFormatTime($startTime),
'status' => ActiveStatusEnum::STATE_SOON, 'status' => ActiveStatusEnum::STATE_NOTICE,
'status_text' => '即将开抢', 'status_text' => '明日预告',
'status_text2' => '即将开抢', 'status_text2' => $this->onFormatTime($startTime) . ' 开始',
'sharp_modular_text' => "{$item['active_time']} 场预告", 'sharp_modular_text' => $this->onFormatTime($startTime) . ' 开始',
]; ];
} }
}
return $data; return $data;
} }
/** /**
* 获取预告的活动 * 获取预告的活动
* @return array * @return array
@ -424,7 +438,7 @@ class Active extends BaseService
'end_time' => $this->onFormatTime($endTime), 'end_time' => $this->onFormatTime($endTime),
'count_down_time' => $this->onFormatTime($startTime), 'count_down_time' => $this->onFormatTime($startTime),
'status' => ActiveStatusEnum::STATE_NOTICE, 'status' => ActiveStatusEnum::STATE_NOTICE,
'status_text' => '明日预告', 'status_text' => '预告',
'status_text2' => $this->onFormatTime($startTime) . ' 开始', 'status_text2' => $this->onFormatTime($startTime) . ' 开始',
'sharp_modular_text' => $this->onFormatTime($startTime) . ' 开始', 'sharp_modular_text' => $this->onFormatTime($startTime) . ' 开始',
]; ];

Loading…
Cancel
Save