作者 何书鹏

商城首页

... ... @@ -122,19 +122,25 @@ trait ActivityCache
if ($status != 'all') {
$starttime = $redis->HGET($hashKey, 'starttime');
$endtime = $redis->HGET($hashKey, 'endtime');
$tomorrow_start = strtotime(date('Y-m-d',strtotime('+1 day'))); //明日开始时间
$tomorrow_end = strtotime(date('Y-m-d',strtotime('+1 day'))) + 86400; //明日结束时间
if ($status == 'ing') {
if (time() < $starttime || time() > $endtime) {
continue;
}
} else if ($status == 'nostart') {
if (time() > $starttime) {
if (time() > $starttime || $tomorrow_start < $endtime) {
continue;
}
} else if ($status == 'ended') {
if (time() < $endtime) {
continue;
}
} else if ($status == 'tomorrow') {
if ($tomorrow_start > $starttime || $tomorrow_end < $endtime) {
continue;
}
}
}
... ...
... ... @@ -177,6 +177,98 @@ class Goods extends Model
}
// 首页秒杀列表
public static function indexSeckillGoodsList() {
$current_endtime = [ // 距本场结束时间
'hour' => 0,
'minute' => 0,
'second' => 0,
];
$soon_starttime = 0; // 即将开抢时间
$tomorrow_start = strtotime(date('Y-m-d',strtotime('+1 day'))); //明日开始时间
$tomorrow_end = strtotime(date('Y-m-d',strtotime('+1 day'))) + 86400; //明日结束时间
$where['type'] = 'seckill';
$where['starttime'] = ['<', time()];
$where['endtime'] = ['>', time()];
$activity = Activity::where($where)->order('starttime')->find();
if($activity){ //本场
$type = '1';
// 本场倒计时
$lefttime = $activity['endtime'] - time();
$current_endtime = [
'hour' => date('H', $lefttime) - 1,// 倒计时剩余的小时数
'minute' => date('i', $lefttime) - 1,// 倒计时剩余的分钟数
'second' => date('s', $lefttime) - 1,// 倒计时剩余的秒数
];
}else{ //下一场
$where['starttime'] = ['>', time()];
$where['endtime'] = ['<', $tomorrow_start];
$activity = Activity::where($where)->order('starttime')->find();
if($activity){
$type = '2';
$soon_starttime = date('H:i',$activity['starttime']);
}else{ //明日预告
$where['starttime'] = ['>', $tomorrow_start];
$where['endtime'] = ['<', $tomorrow_end];
$activity = Activity::where($where)->order('starttime')->find();
$type = '3';
}
}
$goodsList = [];
if($activity && $activity['goods_ids']){
$goodsList = self::getGoodsListByIds($activity['goods_ids']);
$goodsList = array_slice(collection($goodsList)->toArray()['data'],0,4);
}
return empty($goodsList) ? [] : compact('type','current_endtime','soon_starttime','goodsList');
}
// 首页拼团列表
public static function indexGrouponGoodsList() {
$current_endtime = [ // 距本场结束时间
'hour' => 0,
'minute' => 0,
'second' => 0,
];
$soon_starttime = 0; // 即将开抢时间
$tomorrow_start = strtotime(date('Y-m-d',strtotime('+1 day'))); //明日开始时间
$tomorrow_end = strtotime(date('Y-m-d',strtotime('+1 day'))) + 86400; //明日结束时间
$where['type'] = 'groupon';
$where['starttime'] = ['<', time()];
$where['endtime'] = ['>', time()];
$activity = Activity::where($where)->order('starttime')->find();
if($activity){ //本场
$type = 'ing';
// 本场倒计时
$lefttime = $activity['endtime'] - time();
$current_endtime = [
'hour' => date('H', $lefttime) - 1,// 倒计时剩余的小时数
'minute' => date('i', $lefttime) - 1,// 倒计时剩余的分钟数
'second' => date('s', $lefttime) - 1,// 倒计时剩余的秒数
];
}else{ //下一场
$where['starttime'] = ['>', time()];
$where['endtime'] = ['<', $tomorrow_start];
$activity = Activity::where($where)->order('starttime')->find();
if($activity){
$type = 'nostart';
$soon_starttime = date('H:i',$activity['starttime']);
}else{ //明日预告
$where['starttime'] = ['>', $tomorrow_start];
$where['endtime'] = ['<', $tomorrow_end];
$activity = Activity::where($where)->order('starttime')->find();
$type = 'tomorrow';
}
}
$goodsList = [];
if($activity && $activity['goods_ids']){
$goodsList = self::getGoodsListByIds($activity['goods_ids']);
$goodsList = array_slice(collection($goodsList)->toArray()['data'],0,4);
}
return empty($goodsList) ? [] : compact('type','current_endtime','soon_starttime','goodsList');
}
// 获取秒杀商品列表
public static function getSeckillGoodsList($params) {
... ... @@ -190,13 +282,20 @@ class Goods extends Model
$where = [
'type' => 'seckill'
];
$tomorrow_start = strtotime(date('Y-m-d',strtotime('+1 day'))); //明日开始时间
$tomorrow_end = strtotime(date('Y-m-d',strtotime('+1 day'))) + 86400; //明日结束时间
if ($type == 'ing') {
$where['starttime'] = ['<', time()];
$where['endtime'] = ['>', time()];
} else if ($type == 'nostart') {
$where['starttime'] = ['>', time()];
$where['endtime'] = ['<', $tomorrow_start];
} else if ($type == 'ended') {
$where['endtime'] = ['<', time()];
} else if ($type == 'tomorrow') {
$where['starttime'] = ['>', $tomorrow_start];
$where['endtime'] = ['<', $tomorrow_end];
}
$activityList = Activity::where($where)->select();
... ... @@ -221,7 +320,7 @@ class Goods extends Model
// 获取拼团商品列表
public static function getGrouponGoodsList($params) {
extract($params);
$type = 'ing';
$type = $type ?? 'all';
if ((new self)->hasRedis()) {
// 如果有redis,读取 redis
... ... @@ -230,9 +329,19 @@ class Goods extends Model
$where = [
'type' => 'groupon'
];
$tomorrow_start = strtotime(date('Y-m-d',strtotime('+1 day'))); //明日开始时间
$tomorrow_end = strtotime(date('Y-m-d',strtotime('+1 day'))) + 86400; //明日结束时间
if ($type == 'ing') {
$where['starttime'] = ['<', time()];
$where['endtime'] = ['>', time()];
} else if ($type == 'nostart') {
$where['starttime'] = ['>', time()];
$where['endtime'] = ['<', $tomorrow_start];
} else if ($type == 'ended') {
$where['endtime'] = ['<', time()];
} else if ($type == 'tomorrow') {
$where['starttime'] = ['>', $tomorrow_start];
$where['endtime'] = ['<', $tomorrow_end];
}
$activityList = Activity::where($where)->select();
... ...
... ... @@ -13,6 +13,10 @@ class Goods extends Base
protected $noNeedLogin = ['index', 'detail', 'lists', 'activity', 'seckillList', 'grouponList', 'store'];
protected $noNeedRight = ['*'];
/**
* @ApiInternal
* 测试
*/
public function index()
{
// 测试,下面代码可删除
... ... @@ -304,7 +308,7 @@ class Goods extends Base
* @ApiMethod (GET)
*
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=type, type=string, required=false, description="类型:all=全部,ing=进行中,nostart=未开始,ended=已结束")
* @ApiParams (name=type, type=string, required=false, description="类型:all=全部,ing=进行中,nostart=未开始,ended=已结束,tomorrow=明日预告")
*
* @ApiReturn({
"code": 1,
... ... @@ -334,15 +338,15 @@ class Goods extends Base
"dispatch_ids": "1",
"deletetime": null,
"activity": {
"id": 7,
"title": "秒杀测试",
"type": "seckill",
"id": 7, //活动ID
"title": "秒杀测试", //活动标题
"type": "seckill", //活动类型:seckill=秒杀,groupon=拼团
"richtext_id": 0,
"richtext_title": "",
"starttime": 1607616000,
"endtime": 1607702400,
"rules": {
"limit_buy": "1",
"limit_buy": "1", //每人限购件数
"order_auto_close": "",
"activity_auto_close": ""
}
... ... @@ -398,9 +402,94 @@ class Goods extends Base
* @ApiMethod (GET)
*
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=type, type=string, required=false, description="类型:all=全部,ing=进行中,nostart=未开始,ended=已结束")
* @ApiParams (name=type, type=string, required=false, description="类型:all=全部,ing=进行中,nostart=未开始,ended=已结束,tomorrow=明日预告")
*
* @ApiReturn()
* @ApiReturn({
"code": 1,
"msg": "拼团商品列表",
"time": "1608039147",
"data": {
"total": 1, //数据总数
"per_page": 10,
"current_page": 1,
"last_page": 1,
"data": [{
"id": 2, //商品ID
"type": "normal",
"title": "测试商品2", //商品标题
"subtitle": "测试啊啊", //商品副标题
"weigh": 0,
"category_ids": "3",
"image": "http://www.ant.top/uploads/20201211/8894d62100f2f920ffb2f38063b63f2d.jpg", //商品主图
"price": "0.02", //现价
"original_price": "1000.00", //原价
"is_sku": 0, //是否多规格:0=否,1=是
"likes": 0,
"views": 1,
"sales": 0,
"show_sales": 0, //显示销量
"dispatch_type": "express",
"dispatch_ids": "1",
"deletetime": null,
"activity": {
"id": 9, //活动ID
"title": "拼团测试", //活动标题
"type": "groupon", //活动类型:seckill=秒杀,groupon=拼团
"richtext_id": 0,
"richtext_title": "",
"starttime": 1607616000,
"endtime": 1607702400,
"rules": { //活动规则
"limit_buy": "1", //每人限购件数
"order_auto_close": "",
"activity_auto_close": "",
"team_num": "2", //成团人数
"is_alone": "0", //是否允许单独购买
"is_fictitious": "0",
"fictitious_num": "",
"valid_time": "",
"team_card": "0"
}
},
"activity_type": "groupon",
"groupon_price": "0.01",
"sku_price": [{
"id": 2,
"goods_sku_ids": null,
"goods_id": 2,
"weigh": 0,
"image": null,
"stock": 10,
"sales": 0,
"sn": "",
"weight": 0,
"price": "0.02",
"goods_sku_text": null,
"status": "up",
"groupon_price": "0.01",
"activity_type": "groupon",
"activity_id": 9,
"item_goods_sku_price": {
"id": 5,
"activity_id": 9,
"sku_price_id": 2,
"goods_id": 2,
"stock": 10,
"sales": 0,
"price": "0.01",
"status": "up"
},
"goods_sku_id_arr": [
""
]
}],
"stock": 10,
"dispatch_type_arr": [
"express"
]
}]
}
})
*/
public function grouponList() {
$params = $this->request->get();
... ...
... ... @@ -56,16 +56,186 @@ class Index extends Base
"status_code": 1610640000, //状态码:no_use=未使用,used=已使用,expired=已过期
"status_name": "未使用" //状态名称
}]
}{
"code": 1,
"msg": "首页",
"time": "1608036399",
"data": {
"banner_list": [{ //轮播图
"id": 3, //轮播图ID
"image": "http://www.ant.top/uploads/20201214/b655ea4dc4779222ab7a4e2b95feb3a4.png" //图片地址
}],
"category_list": [{ //一级分类
"id": 1, //分类ID
"name": "商品分类" //分类名称
}],
"seckill_list": {
"type": "1",
"current_endtime": {
"hour": 10,
"minute": 12,
"second": 19
},
"soon_starttime": 0,
"goodsList": [{
"id": 1, //商品ID
"type": "normal",
"title": "测试商品", //标题
"subtitle": "测试啊", //副标题
"weigh": 0,
"category_ids": "3", //所属分类ID
"image": "http://www.ant.top/assets/img/qrcode.png", //商品主图
"price": "0.01", //商品价格
"original_price": "10000.00", //原价
"is_sku": 0,
"likes": 0,
"views": 3,
"sales": 0, //销量
"show_sales": 0, //显示销量
"dispatch_type": "express",
"dispatch_ids": "1",
"deletetime": null,
"activity": {
"id": 7,
"title": "秒杀测试",
"type": "seckill",
"richtext_id": 0,
"richtext_title": "",
"starttime": 1607616000,
"endtime": 1607702400,
"rules": {
"limit_buy": "1",
"order_auto_close": "",
"activity_auto_close": ""
}
},
"activity_type": "seckill",
"sku_price": [{
"id": 1,
"goods_sku_ids": null,
"goods_id": 1,
"weigh": 0,
"image": null,
"stock": 20,
"sales": 0,
"sn": "",
"weight": 0,
"price": "0.01",
"goods_sku_text": null,
"status": "up",
"activity_type": "seckill",
"activity_id": 7,
"item_goods_sku_price": {
"id": 4,
"activity_id": 7,
"sku_price_id": 1,
"goods_id": 1,
"stock": 20,
"sales": 0,
"price": "0.01",
"status": "up"
},
"goods_sku_id_arr": [
""
]
}],
"stock": 20,
"dispatch_type_arr": [
"express"
]
}]
},
"groupon_list": [{
"id": 2, //商品ID
"type": "normal",
"title": "测试商品2", //商品标题
"subtitle": "测试啊啊", //商品副标题
"weigh": 0,
"category_ids": "3",
"image": "http://www.ant.top/uploads/20201211/8894d62100f2f920ffb2f38063b63f2d.jpg", //商品主图
"price": "0.02", //现价
"original_price": "1000.00", //原价
"is_sku": 0, //是否多规格:0=否,1=是
"likes": 0,
"views": 1,
"sales": 0,
"show_sales": 0, //显示销量
"dispatch_type": "express",
"dispatch_ids": "1",
"deletetime": null,
"activity": {
"id": 9, //活动ID
"title": "拼团测试", //活动标题
"type": "groupon", //活动类型:seckill=秒杀,groupon=拼团
"richtext_id": 0,
"richtext_title": "",
"starttime": 1607616000,
"endtime": 1607702400,
"rules": { //活动规则
"limit_buy": "1", //每人限购件数
"order_auto_close": "",
"activity_auto_close": "",
"team_num": "2", //成团人数
"is_alone": "0", //是否允许单独购买
"is_fictitious": "0",
"fictitious_num": "",
"valid_time": "",
"team_card": "0"
}
},
"activity_type": "groupon",
"groupon_price": "0.01",
"sku_price": [{
"id": 2,
"goods_sku_ids": null,
"goods_id": 2,
"weigh": 0,
"image": null,
"stock": 10,
"sales": 0,
"sn": "",
"weight": 0,
"price": "0.02",
"goods_sku_text": null,
"status": "up",
"groupon_price": "0.01",
"activity_type": "groupon",
"activity_id": 9,
"item_goods_sku_price": {
"id": 5,
"activity_id": 9,
"sku_price_id": 2,
"goods_id": 2,
"stock": 10,
"sales": 0,
"price": "0.01",
"status": "up"
},
"goods_sku_id_arr": [
""
]
}],
"stock": 10,
"dispatch_type_arr": [
"express"
]
}]
}
})
*/
public function index()
{
$banner_list = Banner::field('id,image')->select();
$category_list = Category::where('pid',0)->field('id,name')->select();
$this->success('初始化数据', compact('banner_list','category_list'));
$category_list = Category::where('pid',0)->field('id,name')->limit(9)->select();
$seckill_list = \addons\shopro\model\Goods::indexSeckillGoodsList();
$groupon_list = \addons\shopro\model\Goods::indexGrouponGoodsList();
$this->success('首页', compact('banner_list','category_list','seckill_list','groupon_list'));
}
//初始化商城数据
/**
* @ApiInternal
* 初始化商城数据
*/
public function init()
{
$params = $this->request->get();
... ... @@ -109,7 +279,10 @@ class Index extends Base
}
//商城模板数据
/**
* @ApiInternal
* 商城模板数据
*/
public function template()
{
$get = $this->request->get();
... ... @@ -122,7 +295,10 @@ class Index extends Base
$this->success('模板数据', $template);
}
//自定义页面
/**
* @ApiInternal
* 自定义页面
*/
public function custom()
{
$get = $this->request->get();
... ... @@ -134,7 +310,10 @@ class Index extends Base
$this->success('自定义模板数据', $decorate);
}
//富文本详情
/**
* @ApiInternal
* 富文本详情
*/
public function richtext()
{
$id = $this->request->get('id');
... ... @@ -142,7 +321,10 @@ class Index extends Base
$this->success($data->title, $data);
}
//同步前端所有页面链接
/**
* @ApiInternal
* 同步前端所有页面链接
*/
public function asyncLink()
{
$post = $this->request->post();
... ... @@ -169,8 +351,11 @@ class Index extends Base
}
}
//前端获取轮播图平均色
//1.0.7以后此接口作废
/**
* @ApiInternal
* 前端获取轮播图平均色
* 1.0.7以后此接口作废
*/
public function asyncBannerBgColor()
{
$params = $this->request->post();
... ... @@ -178,7 +363,10 @@ class Index extends Base
$data['template'] = \addons\shopro\model\Decorate::asyncBannerBgColor($platform, $params);
}
//店铺装修 截图商城首页
/**
* @ApiInternal
* 店铺装修 截图商城首页
*/
public function asyncDecorateScreenShot()
{
$params = $this->request->post();
... ... @@ -375,6 +563,10 @@ class Index extends Base
}
}
/**
* @ApiInternal
* 写调试日志
*/
public function debugLog()
{
$params = $this->request->post();
... ...
此 diff 太大无法显示。