|
|
<?php
|
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
use think\Config;
|
|
|
|
|
|
/**
|
|
|
* 商品接口
|
|
|
*/
|
|
|
class Goods extends Api
|
|
|
{
|
|
|
protected $goodsModel;
|
|
|
protected $keywordLogModel;
|
|
|
|
|
|
public function _initialize()
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
$this->goodsModel = new \app\api\model\Goods;
|
|
|
$this->keywordLogModel = new \app\api\model\KeywordLog;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (本店热榜)
|
|
|
* @ApiSummary (本店热榜)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/goods/getHotGoods)
|
|
|
* @ApiParams (name=limit, type=string, required=false, description="显示条数 默认10条")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
|
|
"time": "1587463117",
|
|
|
"data": [
|
|
|
{
|
|
|
"goods_id": 1, 商品id
|
|
|
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
|
|
|
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
|
|
|
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
|
|
|
"sales_actual": "100", 实际销量
|
|
|
}
|
|
|
]
|
|
|
})
|
|
|
*/
|
|
|
public function getHotGoods()
|
|
|
{
|
|
|
$limit = $this->request->param('limit')?$this->request->param('limit'):10;
|
|
|
$where = [];
|
|
|
$data = $this->goodsModel->selectHotData($where, $limit);
|
|
|
$this->success('请求成功', $data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (商品列表)
|
|
|
* @ApiSummary (商品列表)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/goods/getGoodsList)
|
|
|
* @ApiParams (name=keyword, type=string, required=false, description="关键字搜索")
|
|
|
* @ApiParams (name=page, type=string, required=false, description="页数")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
|
|
"time": "1587463117",
|
|
|
"data": [
|
|
|
{
|
|
|
"goods_id": 1, 商品id
|
|
|
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
|
|
|
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
|
|
|
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
|
|
|
"goods_price": "0.00", 普通售价
|
|
|
"group_price": "0.00", 拼团售价 拼团售价优先级最高
|
|
|
"vip_price": "0.00", 会员售价
|
|
|
"country_ch_name": "意大利", 原产地中文
|
|
|
"country_en_name": "Ltaly", 原产地英文
|
|
|
"is_vip_price": "2", 会员特价:1=开启,2=关闭
|
|
|
"stock_num": 55 库存
|
|
|
}
|
|
|
]
|
|
|
})
|
|
|
*/
|
|
|
public function getGoodsList()
|
|
|
{
|
|
|
$page = $this->request->param('page');
|
|
|
$limit = Config::get('paginate.index_rows');
|
|
|
$where = [];
|
|
|
|
|
|
$keyword = $this->request->param('keyword');
|
|
|
if ($keyword){
|
|
|
$where['g.ch_name|g.en_name|g.ch_content|g.en_content'] = ['like','%'.$keyword.'%'];
|
|
|
//添加搜索记录
|
|
|
if ($this->userId) $this->keywordLogModel->save(['user_id'=>$this->userId,'content'=>$keyword,'createtime'=>time()]);
|
|
|
}
|
|
|
|
|
|
$data = $this->goodsModel->selectPageData($where,$page,$limit);
|
|
|
$this->success('请求成功', $data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (团购商品列表)
|
|
|
* @ApiSummary (团购商品列表)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/goods/getGroupGoodsList)
|
|
|
* @ApiParams (name=page, type=string, required=false, description="页数")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
|
|
"time": "1587463117",
|
|
|
"data": [
|
|
|
{
|
|
|
"goods_id": 1, 商品id
|
|
|
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
|
|
|
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
|
|
|
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
|
|
|
"goods_price": "0.00", 普通售价
|
|
|
"group_price": "0.00", 拼团售价 拼团售价优先级最高
|
|
|
"vip_price": "0.00", 会员售价
|
|
|
"country_ch_name": "意大利", 原产地中文
|
|
|
"country_en_name": "Ltaly", 原产地英文
|
|
|
"is_vip_price": "2", 会员特价:1=开启,2=关闭
|
|
|
"stock_num": 55 库存
|
|
|
}
|
|
|
]
|
|
|
})
|
|
|
*/
|
|
|
public function getGroupGoodsList()
|
|
|
{
|
|
|
$page = $this->request->param('page');
|
|
|
$limit = Config::get('paginate.index_rows');
|
|
|
$where['g.is_group'] = 1;
|
|
|
$data = $this->goodsModel->selectPageData($where,$page,$limit);
|
|
|
$this->success('请求成功', $data);
|
|
|
}
|
|
|
/**
|
|
|
* @ApiTitle (推荐商品列表)
|
|
|
* @ApiSummary (推荐商品列表)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/goods/getRecommendGoods)
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
|
|
"time": "1587463117",
|
|
|
"data": [
|
|
|
{
|
|
|
"goods_id": 1, 商品id
|
|
|
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
|
|
|
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
|
|
|
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
|
|
|
"goods_price": "0.00", 售价
|
|
|
"country_ch_name": "意大利", 原产地中文
|
|
|
"country_en_name": "Ltaly", 原产地英文
|
|
|
"is_vip_price": "2", 会员特价:1=开启,2=关闭
|
|
|
"stock_num": 55 库存
|
|
|
}
|
|
|
]
|
|
|
})
|
|
|
*/
|
|
|
public function getRecommendGoods()
|
|
|
{
|
|
|
$where['g.is_recommend'] = 1;
|
|
|
|
|
|
$data = $this->goodsModel->selectData($where, 10);
|
|
|
|
|
|
$this->success('请求成功', $data);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (团购商品列表(首页))
|
|
|
* @ApiSummary (团购商品列表(首页))
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/goods/getGroupGoodsIndex)
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
|
|
"time": "1587463117",
|
|
|
"data": [
|
|
|
{
|
|
|
"goods_id": 1, 商品id
|
|
|
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
|
|
|
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
|
|
|
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
|
|
|
"goods_price": "0.00", 普通售价
|
|
|
"group_price": "0.00", 拼团售价 拼团售价优先级最高
|
|
|
"vip_price": "0.00", 会员售价
|
|
|
"country_ch_name": "意大利", 原产地中文
|
|
|
"country_en_name": "Ltaly", 原产地英文
|
|
|
"is_vip_price": "2", 会员特价:1=开启,2=关闭
|
|
|
"stock_num": 55 库存
|
|
|
}
|
|
|
]
|
|
|
})
|
|
|
*/
|
|
|
public function getGroupGoodsIndex()
|
|
|
{
|
|
|
$where['g.is_group'] = 1;
|
|
|
|
|
|
$data = $this->goodsModel->selectData($where, 5);
|
|
|
|
|
|
$this->success('请求成功', $data);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (商品详情)
|
|
|
* @ApiSummary (商品详情)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/goods/getGoodsInfo)
|
|
|
* @ApiParams (name=goods_id, type=string, required=false, description="商品id")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
|
|
"time": "1587463117",
|
|
|
"data": [
|
|
|
{
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
|
|
"time": "1587471193",
|
|
|
"data": {
|
|
|
"goods_id": 1, 商品id
|
|
|
"ch_name": "EMP精选 澳洲白肉油桃 500~540g 4只装", 中文名称
|
|
|
"en_name": "EMP selected Australian white meat nectarines Australian meat nectarines", 英文名称
|
|
|
"image": "http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png", 缩略图
|
|
|
"goods_price": "123.00", 普通价格
|
|
|
"images": [
|
|
|
"http://q7s0a1rb4.bkt.clouddn.com/uploads/20200420/26f5e51b8ac7fbd6f1c649cc45a18265.png"
|
|
|
], 轮播图
|
|
|
"goods_no": "", 商品编码
|
|
|
"ch_specification": "", 中文包装规格
|
|
|
"en_specification": "", 英文包装规格
|
|
|
"ch_save_where": "", 中文保存条件
|
|
|
"en_save_where": "", 英文保存条件
|
|
|
"ch_period": "", 中文有效期
|
|
|
"en_period": "", 英文有效期
|
|
|
"ch_content": "", 中文详情
|
|
|
"en_content": "", 英文详情
|
|
|
"stock_num": 55, 库存
|
|
|
"sales_actual": 3, 实际销量
|
|
|
"group_price": null, 拼团价格
|
|
|
"vip_price": "0.00", 会员特价
|
|
|
"is_vip_price": "2", 会员特价:1=开启,2=关闭
|
|
|
"is_group": "2", 团购:1=开启,2=关闭
|
|
|
"ch_country_name": "意大利",
|
|
|
"en_country_name": "Ltaly"
|
|
|
}
|
|
|
}
|
|
|
]
|
|
|
})
|
|
|
*/
|
|
|
public function getGoodsInfo()
|
|
|
{
|
|
|
$goods_id = $this->request->param('goods_id');
|
|
|
if (!$goods_id) $this->error('缺少参数 goods_id!');
|
|
|
$where = ['g.id'=>$goods_id];
|
|
|
$data = $this->goodsModel->getInfo($where);
|
|
|
// if ($data['status'] == 2) $this->error('商品已下架');
|
|
|
$this->success('请求成功', $data);
|
|
|
}
|
|
|
} |
...
|
...
|
|