feat: 添加接口 获取商品推荐和根据三级分类获取品牌

master
yin5th 2023-09-21 17:02:20 +08:00
parent cca67c9962
commit 7cfbacceef
4 changed files with 36 additions and 3 deletions

View File

@ -18,6 +18,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\api\controller; namespace app\api\controller;
use app\api\logic\GoodsBrandLogic;
use app\common\basics\Api; use app\common\basics\Api;
use app\api\logic\GoodsLogic; use app\api\logic\GoodsLogic;
use app\common\server\JsonServer; use app\common\server\JsonServer;
@ -27,7 +28,7 @@ use think\facade\Validate;
class Goods extends Api class Goods extends Api
{ {
public $like_not_need_login = ['getGoodsDetail', 'getHotList', 'getGoodsList', 'getGoodsListTemplate', public $like_not_need_login = ['getGoodsDetail', 'getHotList', 'getGoodsList', 'getGoodsListTemplate',
'getGoodsListByColumnId', 'getRecommendGoods']; 'getGoodsListByColumnId', 'getRecommendGoods', 'getBrandListByCateId'];
/** /**
* 商品详情 * 商品详情
@ -117,4 +118,19 @@ class Goods extends Api
return JsonServer::error('请求方式错误'); return JsonServer::error('请求方式错误');
} }
} }
public function getBrandListByCateId()
{
if($this->request->isGet()) {
$cateId = input('cate_id/d',0);
if (empty($cateId)) {
return JsonServer::error('参数错误');
}
$data = GoodsBrandLogic::getByCateId($cateId);
return JsonServer::success('获取成功', $data);
}else{
return JsonServer::error('请求方式错误');
}
}
} }

View File

@ -2,6 +2,7 @@
namespace app\api\logic; namespace app\api\logic;
use app\common\basics\Logic; use app\common\basics\Logic;
use app\common\model\goods\Goods;
use app\common\model\goods\GoodsBrand; use app\common\model\goods\GoodsBrand;
class GoodsBrandLogic extends Logic class GoodsBrandLogic extends Logic
@ -49,4 +50,21 @@ class GoodsBrandLogic extends Logic
$newList = array_merge([], $newList); $newList = array_merge([], $newList);
return $newList; return $newList;
} }
// 通过分类ID 获取相关联的品牌列表
// 逻辑: 通过分类ID查询以该分类ID为三级分类的产品有哪些再从产品中获得品牌ID再去重
public static function getByCateId($cateId)
{
$list = Goods::alias('g')
->field('g.brand_id')
->join('goods_brand gb', 'g.brand_id = gb.id')
->where('g.third_cate_id', $cateId)
->where('gb.del',0)
->where('gb.is_show',1)
->group('g.brand_id')
->field('gb.id,gb.name')
->select()->toArray();
return $list;
}
} }

View File

@ -533,7 +533,7 @@ class GoodsLogic extends Logic
$list = Goods::field('id,name,image,market_price,min_price,sales_actual,column_ids,sort_weight,sales_virtual,(sales_actual + sales_virtual) as sales_total') $list = Goods::field('id,name,image,market_price,min_price,sales_actual,column_ids,sort_weight,sales_virtual,(sales_actual + sales_virtual) as sales_total')
->where($onSaleWhere) ->where($onSaleWhere)
->where('id', "<>", $goodsId) ->where('id', "<>", $goodsId)
->whereFindInSet('column_ids', $goodsInfo['third_cate_id']) ->where('third_cate_id', $goodsInfo['third_cate_id'])
->orderRaw('RAND()') ->orderRaw('RAND()')
->limit($limit) ->limit($limit)
->select(); ->select();

View File

@ -1 +0,0 @@
open_basedir=/data/wwwroot/gonglehui/server/:/data/tmp/