【增加】判断当前时间是否在秒杀开启时间,并区分有无钻石用户

This commit is contained in:
liqianjin 2023-02-28 18:06:36 +08:00
parent 6d14f5d6fa
commit 76c2256794
2 changed files with 82 additions and 47 deletions

View File

@ -14,11 +14,7 @@ class Futures extends BaseApi{
$token = $this->checkToken();
if ($token['code'] < 0) return $this->response($token);
$fenxiao = model('fenxiao')->getInfo([['member_id', '=', $this->member_id]]);
// $is_read = FALSE;
// if(empty($fenxiao) || $fenxiao['diamond'] < 0){
// $is_read =
// }//TODO 判断当前时间是否在秒杀开启时间,并区分有无钻石用户
//判断当前时间是否在秒杀开启时间,并区分有无钻石用户
$status = input('status', 'miaosha');
@ -29,15 +25,38 @@ class Futures extends BaseApi{
switch($status){
case 'miaosha':
$condition[] = ['a.status', '=', '2'];
$startTimeKey = 'miaosha_start_time';
$endTimeKey = 'miaosha_end_time';
$fenxiao = model('fenxiao')->getInfo([['member_id', '=', $this->member_id]]);
if(!empty($fenxiao) && $fenxiao['diamond'] > 0){
$startTimeKey = 'miaosha_early_start_time';
}
break;
case 'jianlou':
$condition[] = ['a.status', '=', '7'];
$startTimeKey = 'jianlou_start_time';
$endTimeKey = 'jianlou_end_time';
break;
default:
$condition[] = ['a.status', '=', '2'];
return $this->response($this->error('','参数不合法'));
break;
}
$nowTime = time() - strtotime("today");
$is_read = FALSE;
$futuresModel = new FuturesModel;
$basics = $futuresModel->getBasicsConfig($this->site_id)['data']['value'];
foreach($basics['times'] as $times){
if($times[$startTimeKey] <= $nowTime && $times[$endTimeKey] >= $nowTime){
$is_read = TRUE;
break;
}
}
if(!$is_read){
return $this->response($this->error('','未到秒杀时间'));
}
// 获取内容
$field = [
@ -62,7 +81,7 @@ class Futures extends BaseApi{
['goods g', 'g.goods_id = a.goods_id', 'left'],// 获取商品信息
];
$futuresModel = new FuturesModel;
$page = input('page', 1);
$page_size = input('page_size', PAGE_LIST_ROWS);
$list = $futuresModel->getPageList($condition, $page, $page_size, 'a.created_time desc,a.id desc', $field, 'a', $join);

View File

@ -16,17 +16,15 @@
<span class="card-title">秒杀时间设置</span>
</div>
<div class="layui-card-body">
<div class="layui-form-item time-view">
<div class="layui-inline">
<label class="layui-form-label">秒杀日期:</label>
<div class="layui-input-inline">
<input type="radio" name="time_type" value="0" title="每天" lay-filter="time_type" {if
!isset($info.time_type) || $info.time_type== 0}checked{/if}/>
<input type="radio" name="time_type" value="1" title="自定义" lay-filter="time_type" {if
!isset($info.time_type) || $info.time_type== 1 }checked{/if}/>
</div>
</div>
</div>
<!-- <div class="layui-form-item time-view">-->
<!-- <div class="layui-inline">-->
<!-- <label class="layui-form-label">秒杀日期:</label>-->
<!-- <div class="layui-input-inline">-->
<!-- <input type="radio" name="time_type" value="0" title="每天" lay-filter="time_type" {//if !isset($info.time_type) || $info.time_type== 0}checked{/if}/>-->
<!-- <input type="radio" name="time_type" value="1" title="自定义" lay-filter="time_type" {//if !isset($info.time_type) || $info.time_type== 1 }checked{/if}/>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<div class="time-view">
<div class="layui-form-item time-type-view" lay-verify="time_week">
@ -70,19 +68,21 @@
<div class="layui-form">
<table class="layui-table">
<colgroup>
<col width="22%" />
<col width="22%" />
<col width="22%" />
<col width="22%" />
<!-- <col width="12%" />-->
<col width="18%" />
<col width="18%" />
<col width="18%" />
<col width="18%" />
<col width="18%" />
<col width="10%" />
</colgroup>
<thead>
<tr>
<th><span class="required">*</span>秒杀提前开始时间</th>
<th><span class="required">*</span>秒杀开始时间</th>
<th><span class="required">*</span>秒杀结束时间</th>
<th><span class="required">*</span>捡漏开始时间</th>
<th><span class="required">*</span>捡漏结束时间</th>
<!-- <th>操作</th>-->
<th>操作</th>
</tr>
</thead>
<tbody class="attr-new">
@ -92,13 +92,13 @@
</tbody>
</table>
</div>
<!-- <button class="layui-btn layui-btn-primary"-->
<!-- onclick="addNewAttr({-->
<!-- miaosha_start_time: 0,-->
<!-- miaosha_end_time: 0,-->
<!-- jianlou_start_time: 0,-->
<!-- jianlou_end_time: 0,-->
<!-- })">添加商品参数</button>-->
<button class="layui-btn layui-btn-primary"
onclick="addNewAttr({
miaosha_start_time: 0,
miaosha_end_time: 0,
jianlou_start_time: 0,
jianlou_end_time: 0,
})">添加时间段</button>
</div>
</div>
@ -131,7 +131,7 @@
function isNullTable() {
var len = $(".attr-new .goods-attr-tr").length;
if (len == 0) {
$(".attr-new").html('<tr class="null-data"><td colspan="5" align="center">无数据</td></tr>');
$(".attr-new").html('<tr class="null-data"><td colspan="6" align="center">无数据</td></tr>');
} else {
$(".attr-new .null-data").remove();
}
@ -154,8 +154,18 @@
form.render();
addNewAttr = function (times){
addNewAttr = function (times = {
miaosha_early_start_time: 0,
miaosha_start_time: 0,
miaosha_end_time: 0,
jianlou_start_time: 0,
jianlou_end_time: 0,
}){
var html = '<tr class="goods-attr-tr goods-new-attr-tr">' +
'<td>' +
'<input type="text" class="layui-input" id="miaoshaEarlyStartTime' + $('.goods-attr-tr').length + '" placeholder="秒杀提前开始时间" value="" readonly >' +
'<input type="hidden" class="layui-input" id="miaoshaEarlyStartTimeInput' + $('.goods-attr-tr').length + '" name="times[' + $('.goods-attr-tr').length + '][miaosha_early_start_time]" placeholder="秒杀提前开始时间" value="' + times.miaosha_early_start_time + '">' +
'</td>' +
'<td>' +
'<input type="text" class="layui-input" id="miaoshaStartTime' + $('.goods-attr-tr').length + '" placeholder="秒杀开始时间" value="" readonly >' +
'<input type="hidden" class="layui-input" id="miaoshaStartTimeInput' + $('.goods-attr-tr').length + '" name="times[' + $('.goods-attr-tr').length + '][miaosha_start_time]" placeholder="秒杀开始时间" value="' + times.miaosha_start_time + '">' +
@ -172,30 +182,40 @@
'<input type="text" class="layui-input" id="jianlouEndTime' + $('.goods-attr-tr').length + '" placeholder="捡漏结束时间" value="" readonly >' +
'<input type="hidden" class="layui-input" id="jianlouEndTimeInput' + $('.goods-attr-tr').length + '" name="times[' + $('.goods-attr-tr').length + '][jianlou_end_time]" placeholder="捡漏结束时间" value="' + times.jianlou_end_time + '">' +
'</td>' +
// '<td>' +
// '<div class="table-btn"><a class="layui-btn" onclick="delAttr(this)">删除</a></div>' +
// '</td>' +
'<td>' +
'<div class="table-btn"><a class="layui-btn" onclick="delAttr(this)">删除</a></div>' +
'</td>' +
'</tr>';
$(".attr-new").append(html);
isNullTable();
console.log(times.miaosha_start_time,getData(times.miaosha_start_time))
laydate.render({
elem: '#miaoshaEarlyStartTime' + ($('.goods-attr-tr').length - 1)
, type: 'time'
,value: getData(times.miaosha_early_start_time)
,done: function(value, date, endDate){
var time = date.hours * 3600 + date.minutes * 60 + date.seconds;
$('#miaoshaEarlyStartTimeInput' + this.elem.selector.substr(-1)).val(time);
}
});
console.log($('.goods-attr-tr').length)
laydate.render({
elem: '#miaoshaStartTime' + ($('.goods-attr-tr').length - 1)
, type: 'time'
,value: getData(times.miaosha_start_time)
,done: function(value, date, endDate){
var time = date.hours * 3600 + date.minutes * 60 + date.seconds;
$('#miaoshaStartTimeInput' + ($('.goods-attr-tr').length - 1)).val(time);
$('#miaoshaStartTimeInput' + this.elem.selector.substr(-1)).val(time);
}
});
console.log($('.goods-attr-tr').length)
laydate.render({
elem: '#miaoshaEndTime' + ($('.goods-attr-tr').length - 1)
, type: 'time'
,value: getData(times.miaosha_end_time)
,done: function(value, date, endDate){
var time = date.hours * 3600 + date.minutes * 60 + date.seconds;
$('#miaoshaEndTimeInput' + ($('.goods-attr-tr').length - 1)).val(time);
$('#miaoshaEndTimeInput' + this.elem.selector.substr(-1)).val(time);
}
});
laydate.render({
@ -204,7 +224,7 @@
,value: getData(times.jianlou_start_time)
,done: function(value, date, endDate){
var time = date.hours * 3600 + date.minutes * 60 + date.seconds;
$('#jianlouStartTimeInput' + ($('.goods-attr-tr').length - 1)).val(time);
$('#jianlouStartTimeInput' + this.elem.selector.substr(-1)).val(time);
}
});
laydate.render({
@ -213,7 +233,7 @@
,value: getData(times.jianlou_end_time)
,done: function(value, date, endDate){
var time = date.hours * 3600 + date.minutes * 60 + date.seconds;
$('#jianlouEndTimeInput' + ($('.goods-attr-tr').length - 1)).val(time);
$('#jianlouEndTimeInput' + this.elem.selector.substr(-1)).val(time);
}
});
@ -221,6 +241,7 @@
<?php if (isset($info['times'])){ ?>
{foreach name="info.times" item="vo"}
addNewAttr({
miaosha_early_start_time: {$vo['miaosha_early_start_time']},
miaosha_start_time: {$vo['miaosha_start_time']},
miaosha_end_time: {$vo['miaosha_end_time']},
jianlou_start_time: {$vo['jianlou_start_time']},
@ -228,12 +249,7 @@
})
{/foreach}
<?php }else{ ?>
addNewAttr({
miaosha_start_time: 0,
miaosha_end_time: 0,
jianlou_start_time: 0,
jianlou_end_time: 0,
})
addNewAttr()
<?php } ?>
form.verify({
start_time: function(value, item){ //value表单的值、item表单的DOM对象