...
|
...
|
@@ -11,12 +11,14 @@ use think\Config; |
|
|
class Goods extends Api
|
|
|
{
|
|
|
protected $goodsModel;
|
|
|
protected $categoryModel;
|
|
|
protected $keywordLogModel;
|
|
|
|
|
|
public function _initialize()
|
|
|
{
|
|
|
parent::_initialize();
|
|
|
$this->goodsModel = new \app\api\model\Goods;
|
|
|
$this->categoryModel = new \app\api\model\Category;
|
|
|
$this->keywordLogModel = new \app\api\model\KeywordLog;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -50,12 +52,10 @@ class Goods extends Api |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (商品列表)
|
|
|
* @ApiSummary (商品列表)
|
|
|
* @ApiTitle (推荐商品列表)
|
|
|
* @ApiSummary (推荐商品列表)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/goods/getGoodsList)
|
|
|
* @ApiParams (name=keyword, type=string, required=false, description="关键字搜索")
|
|
|
* @ApiParams (name=page, type=string, required=false, description="页数")
|
|
|
* @ApiRoute (/api/goods/getRecommendGoods)
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
...
|
...
|
@@ -66,9 +66,7 @@ class Goods extends Api |
|
|
"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", 会员售价
|
|
|
"goods_price": "0.00", 售价
|
|
|
"country_ch_name": "意大利", 原产地中文
|
|
|
"country_en_name": "Ltaly", 原产地英文
|
|
|
"is_vip_price": "2", 会员特价:1=开启,2=关闭
|
...
|
...
|
@@ -77,29 +75,21 @@ class Goods extends Api |
|
|
]
|
|
|
})
|
|
|
*/
|
|
|
public function getGoodsList()
|
|
|
public function getRecommendGoods()
|
|
|
{
|
|
|
$page = $this->request->param('page');
|
|
|
$limit = Config::get('paginate.index_rows');
|
|
|
$where = [];
|
|
|
$where['g.is_recommend'] = 1;
|
|
|
|
|
|
$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->selectData($where, 10);
|
|
|
|
|
|
$data = $this->goodsModel->selectPageData($where,$page,$limit);
|
|
|
$this->success('请求成功', $data);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (团购商品列表)
|
|
|
* @ApiSummary (团购商品列表)
|
|
|
* @ApiTitle (团购商品列表(首页))
|
|
|
* @ApiSummary (团购商品列表(首页))
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/goods/getGroupGoodsList)
|
|
|
* @ApiParams (name=page, type=string, required=false, description="页数")
|
|
|
* @ApiRoute (/api/goods/getGroupGoodsIndex)
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
...
|
...
|
@@ -121,19 +111,21 @@ class Goods extends Api |
|
|
]
|
|
|
})
|
|
|
*/
|
|
|
public function getGroupGoodsList()
|
|
|
public function getGroupGoodsIndex()
|
|
|
{
|
|
|
$page = $this->request->param('page');
|
|
|
$limit = Config::get('paginate.index_rows');
|
|
|
$where['g.is_group'] = 1;
|
|
|
$data = $this->goodsModel->selectPageData($where,$page,$limit);
|
|
|
|
|
|
$data = $this->goodsModel->selectData($where, 5);
|
|
|
|
|
|
$this->success('请求成功', $data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (推荐商品列表)
|
|
|
* @ApiSummary (推荐商品列表)
|
|
|
* @ApiTitle (团购商品列表)
|
|
|
* @ApiSummary (团购商品列表)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/goods/getRecommendGoods)
|
|
|
* @ApiRoute (/api/goods/getGroupGoodsList)
|
|
|
* @ApiParams (name=page, type=string, required=false, description="页数")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
...
|
...
|
@@ -144,7 +136,9 @@ class Goods extends Api |
|
|
"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", 售价
|
|
|
"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=关闭
|
...
|
...
|
@@ -153,21 +147,21 @@ class Goods extends Api |
|
|
]
|
|
|
})
|
|
|
*/
|
|
|
public function getRecommendGoods()
|
|
|
public function getGroupGoodsList()
|
|
|
{
|
|
|
$where['g.is_recommend'] = 1;
|
|
|
|
|
|
$data = $this->goodsModel->selectData($where, 10);
|
|
|
|
|
|
$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 (团购商品列表(首页))
|
|
|
* @ApiTitle (商品列表)
|
|
|
* @ApiSummary (商品列表)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/goods/getGroupGoodsIndex)
|
|
|
* @ApiRoute (/api/goods/getGoodsList)
|
|
|
* @ApiParams (name=page, type=string, required=false, description="页数")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
...
|
...
|
@@ -189,22 +183,216 @@ class Goods extends Api |
|
|
]
|
|
|
})
|
|
|
*/
|
|
|
public function getGroupGoodsIndex()
|
|
|
public function getGoodsList()
|
|
|
{
|
|
|
$where['g.is_group'] = 1;
|
|
|
$page = $this->request->param('page');
|
|
|
$limit = Config::get('paginate.index_rows');
|
|
|
$where = [];
|
|
|
|
|
|
$data = $this->goodsModel->selectData($where, 5);
|
|
|
$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/getCategoryGoodsList)
|
|
|
* @ApiParams (name=category_two_id, type=string, required=true, description="二级分类id")
|
|
|
* @ApiParams (name=category_three_id, type=string, required=false, description="三级分类id")
|
|
|
* @ApiParams (name=category_group_id, type=string, required=false, description="分组id")
|
|
|
* @ApiParams (name=country_id, type=string, required=false, description="国家id")
|
|
|
* @ApiParams (name=brand_id, type=string, required=false, description="品牌id")
|
|
|
* @ApiParams (name=level_id, type=string, required=false, description="等级id")
|
|
|
* @ApiParams (name=part_id, type=string, required=false, description="部位id")
|
|
|
* @ApiParams (name=category2_id, type=string, required=false, description="品类id")
|
|
|
* @ApiParams (name=page, type=string, required=false, description="页数")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
|
|
"time": "1587539236",
|
|
|
"data": {
|
|
|
"country": { 国家
|
|
|
"1": {
|
|
|
"id": 1, 国家id
|
|
|
"ch_name": "意大利", 中文名称
|
|
|
"en_name": "Ltaly" 英文名称
|
|
|
}
|
|
|
},
|
|
|
"brand": { 品牌
|
|
|
"1": {
|
|
|
"id": 1, 品牌id
|
|
|
"ch_name": "HAR", 中文名称
|
|
|
"en_name": "HAR" 英文名称
|
|
|
}
|
|
|
},
|
|
|
"level": { 等级
|
|
|
"1": {
|
|
|
"id": 1, 等级id
|
|
|
"ch_name": "草饲", 中文名称
|
|
|
"en_name": "Forage fed" 英文名称
|
|
|
}
|
|
|
},
|
|
|
"part": { 部位
|
|
|
"1": { 部位id
|
|
|
"id": 1,
|
|
|
"ch_name": "战斧", 中文名称
|
|
|
"en_name": "Tomahawk" 英文名称
|
|
|
}
|
|
|
},
|
|
|
"category2": [], 品类
|
|
|
"list": {
|
|
|
"total": 1, 总条数
|
|
|
"list": [
|
|
|
{
|
|
|
"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", 价格
|
|
|
"ch_country_name": "意大利", 中文名称
|
|
|
"en_country_name": "Ltaly", 英文名称
|
|
|
"is_vip_price": "2", 会员特价:1=开启,2=关闭
|
|
|
"is_group": "2", 团购:1=开启,2=关闭
|
|
|
"group_price": null, 拼团售价 拼团售价优先级最高
|
|
|
"vip_price": "0.00", 会员售价
|
|
|
"stock_num": 55 库存
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function getCategoryGoodsList()
|
|
|
{
|
|
|
$params = $this->request->param();
|
|
|
if (empty($params['category_two_id'])) $this->error('缺少参数 category_two_id!');
|
|
|
$page = $params['page'];
|
|
|
$limit = Config::get('paginate.index_rows');
|
|
|
$where['category_two_id'] = $params['category_two_id'];
|
|
|
if (!empty($params['category_three_id'])) $where['category_three_id'] = $params['category_three_id'];
|
|
|
if (!empty($params['category_group_id'])) $where['category_group_ids'] = ['like','%,'.$params['category_group_id'].',%'];
|
|
|
if (!empty($params['country_id'])) $where['country_id'] = $params['country_id'];
|
|
|
if (!empty($params['brand_id'])) $where['brand_id'] = $params['brand_id'];
|
|
|
if (!empty($params['level_id'])) $where['level_id'] = $params['level_id'];
|
|
|
if (!empty($params['part_id'])) $where['part_id'] = $params['part_id'];
|
|
|
if (!empty($params['category2_id'])) $where['category2_id'] = $params['category2_id'];
|
|
|
|
|
|
//获取筛选标签,国家,品牌,等级,部位,品类
|
|
|
$data = $this->categoryModel->getExtend($where);
|
|
|
//获取三级分类
|
|
|
$data['category_three'] = $this->categoryModel->selectData(['pid'=>$params['category_two_id']]);
|
|
|
//获取列表数据
|
|
|
$data['list'] = $this->goodsModel->selectPageData($where,$page,$limit);
|
|
|
|
|
|
$this->success('请求成功', $data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (搜索商品列表)
|
|
|
* @ApiSummary (搜索商品列表)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/goods/getSearchGoodsList)
|
|
|
* @ApiParams (name=keyword, type=string, required=false, description="关键字搜索")
|
|
|
* @ApiParams (name=country_id, type=string, required=false, description="国家id")
|
|
|
* @ApiParams (name=brand_id, type=string, required=false, description="品牌id")
|
|
|
* @ApiParams (name=level_id, type=string, required=false, description="等级id")
|
|
|
* @ApiParams (name=part_id, type=string, required=false, description="部位id")
|
|
|
* @ApiParams (name=category2_id, type=string, required=false, description="品类id")
|
|
|
* @ApiParams (name=page, type=string, required=false, description="页数")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
|
|
"time": "1587539236",
|
|
|
"data": {
|
|
|
"country": { 国家
|
|
|
"1": {
|
|
|
"id": 1, 国家id
|
|
|
"ch_name": "意大利", 中文名称
|
|
|
"en_name": "Ltaly" 英文名称
|
|
|
}
|
|
|
},
|
|
|
"brand": { 品牌
|
|
|
"1": {
|
|
|
"id": 1, 品牌id
|
|
|
"ch_name": "HAR", 中文名称
|
|
|
"en_name": "HAR" 英文名称
|
|
|
}
|
|
|
},
|
|
|
"level": { 等级
|
|
|
"1": {
|
|
|
"id": 1, 等级id
|
|
|
"ch_name": "草饲", 中文名称
|
|
|
"en_name": "Forage fed" 英文名称
|
|
|
}
|
|
|
},
|
|
|
"part": { 部位
|
|
|
"1": { 部位id
|
|
|
"id": 1,
|
|
|
"ch_name": "战斧", 中文名称
|
|
|
"en_name": "Tomahawk" 英文名称
|
|
|
}
|
|
|
},
|
|
|
"category2": [], 品类
|
|
|
"list": {
|
|
|
"total": 1, 总条数
|
|
|
"list": [
|
|
|
{
|
|
|
"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", 价格
|
|
|
"ch_country_name": "意大利", 中文名称
|
|
|
"en_country_name": "Ltaly", 英文名称
|
|
|
"is_vip_price": "2", 会员特价:1=开启,2=关闭
|
|
|
"is_group": "2", 团购:1=开启,2=关闭
|
|
|
"group_price": null, 拼团售价 拼团售价优先级最高
|
|
|
"vip_price": "0.00", 会员售价
|
|
|
"stock_num": 55 库存
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function getSearchGoodsList()
|
|
|
{
|
|
|
$params = $this->request->param();
|
|
|
if (empty($params['keyword'])) $this->error('缺少参数 keyword!');
|
|
|
$page = $params['page'];
|
|
|
$limit = Config::get('paginate.index_rows');
|
|
|
$where = [];
|
|
|
if (!empty($params['country_id'])) $where['country_id'] = $params['country_id'];
|
|
|
if (!empty($params['brand_id'])) $where['brand_id'] = $params['brand_id'];
|
|
|
if (!empty($params['level_id'])) $where['level_id'] = $params['level_id'];
|
|
|
if (!empty($params['part_id'])) $where['part_id'] = $params['part_id'];
|
|
|
if (!empty($params['category2_id'])) $where['category2_id'] = $params['category2_id'];
|
|
|
$goodsWhere = $where;
|
|
|
$where['ch_name|en_name|ch_content|en_content'] = ['like','%'.$params['keyword'].'%'];
|
|
|
$goodsWhere['g.ch_name|g.en_name|g.ch_content|g.en_content'] = ['like','%'.$params['keyword'].'%'];
|
|
|
|
|
|
//获取筛选标签,国家,品牌,等级,部位,品类
|
|
|
$data = $this->categoryModel->getExtend($where);
|
|
|
//获取列表数据
|
|
|
$data['list'] = $this->goodsModel->selectPageData($goodsWhere,$page,$limit);
|
|
|
|
|
|
$this->success('请求成功', $data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (商品详情)
|
|
|
* @ApiSummary (商品详情)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/goods/getGoodsInfo)
|
|
|
* @ApiParams (name=goods_id, type=string, required=false, description="商品id")
|
|
|
* @ApiParams (name=goods_id, type=string, required=true, description="商品id")
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "请求成功",
|
...
|
...
|
@@ -240,6 +428,7 @@ class Goods extends Api |
|
|
"is_group": "2", 团购:1=开启,2=关闭
|
|
|
"ch_country_name": "意大利",
|
|
|
"en_country_name": "Ltaly"
|
|
|
"is_car": 0 购物车:1=加入,2=未加入
|
|
|
}
|
|
|
}
|
|
|
]
|
...
|
...
|
@@ -251,7 +440,14 @@ class Goods extends Api |
|
|
if (!$goods_id) $this->error('缺少参数 goods_id!');
|
|
|
$where = ['g.id'=>$goods_id];
|
|
|
$data = $this->goodsModel->getInfo($where);
|
|
|
// if ($data['status'] == 2) $this->error('商品已下架');
|
|
|
|
|
|
if ($data['status'] == 2) $this->error('商品已下架');
|
|
|
$userId = $this->userId;
|
|
|
if ($userId){
|
|
|
$carModel = new \app\api\model\Car;
|
|
|
$data['is_car'] = $carModel->where(['user_id'=>$userId,'goods_id'=>$data['goods_id']])->count();
|
|
|
}
|
|
|
|
|
|
$this->success('请求成功', $data);
|
|
|
}
|
|
|
} |
...
|
...
|
|