YS : 秒杀

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

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

@ -306,14 +306,13 @@ class Active extends BaseService
// 获取即将开始的活动
$data = array_merge($data, $this->getSoonActive($todyActive));
}
//获取明天活动
$tmowActive = $this->ActiveModel->getNowActive();
if (!empty($tmowActive)) {
$tmoActive = $this->ActiveModel->gettmoActive();
if (!empty($tmoActive)) {
// 获取即将开始的活动
$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));
}
@ -365,39 +364,54 @@ class Active extends BaseService
foreach ($list as $item) {
$startTime = $todyActive['active_date'] + ($item->getData('active_time') * 60 * 60);
$endTime = $startTime + (1 * 60 * 60);
if(strtotime(date('Y-m-d',$startTime))>strtotime(date("y-m-d",time()))){
$data[] = [
'active_id' => $todyActive['active_id'],
'active_time_id' => $item['active_time_id'],
'active_time' => $item['active_time'],
'start_time' => $this->onFormatTime($startTime),
'end_time' => $this->onFormatTime($endTime),
'count_down_time' => $this->onFormatTime($startTime),
'status' => ActiveStatusEnum::STATE_NOTICE,
'status_text' => '明日预告',
'status_text2' => $this->onFormatTime($startTime) . ' 开始',
'sharp_modular_text' => $this->onFormatTime($startTime) . ' 开始',
];
}else{
$data[] = [
'active_id' => $todyActive['active_id'],
'active_time_id' => $item['active_time_id'],
'active_time' => $item['active_time'],
'start_time' => $this->onFormatTime($startTime),
'end_time' => $this->onFormatTime($endTime),
'count_down_time' => $this->onFormatTime($startTime),
'status' => ActiveStatusEnum::STATE_SOON,
'status_text' => '即将开抢',
'status_text2' => '即将开抢',
'sharp_modular_text' => "{$item['active_time']} 场预告",
];
}
$data[] = [
'active_id' => $todyActive['active_id'],
'active_time_id' => $item['active_time_id'],
'active_time' => $item['active_time'],
'start_time' => $this->onFormatTime($startTime),
'end_time' => $this->onFormatTime($endTime),
'count_down_time' => $this->onFormatTime($startTime),
'status' => ActiveStatusEnum::STATE_SOON,
'status_text' => '即将开抢',
'status_text2' => '即将开抢',
'sharp_modular_text' => "{$item['active_time']} 场预告",
];
}
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[] = [
'active_id' => $todyActive['active_id'],
'active_time_id' => $item['active_time_id'],
'active_time' => $item['active_time'],
'start_time' => $this->onFormatTime($startTime),
'end_time' => $this->onFormatTime($endTime),
'count_down_time' => $this->onFormatTime($startTime),
'status' => ActiveStatusEnum::STATE_NOTICE,
'status_text' => '明日预告',
'status_text2' => $this->onFormatTime($startTime) . ' 开始',
'sharp_modular_text' => $this->onFormatTime($startTime) . ' 开始',
];
}
return $data;
}
/**
* 获取预告的活动
* @return array
@ -424,7 +438,7 @@ class Active extends BaseService
'end_time' => $this->onFormatTime($endTime),
'count_down_time' => $this->onFormatTime($startTime),
'status' => ActiveStatusEnum::STATE_NOTICE,
'status_text' => '明日预告',
'status_text' => '预告',
'status_text2' => $this->onFormatTime($startTime) . ' 开始',
'sharp_modular_text' => $this->onFormatTime($startTime) . ' 开始',
];

Loading…
Cancel
Save