|
|
@@ -12,7 +12,7 @@ class GoodsCategoryService extends BaseService
|
|
|
|
|
|
public static $baseFile = '\biz\goods\classes\GoodsCategoryClass';
|
|
|
|
|
|
- //分类下的商品 shish 2019.12.2
|
|
|
+ //查询一个分类下的商品,有分页 shish 2019.12.2
|
|
|
public static function getGoodsList($where)
|
|
|
{
|
|
|
$data = GoodsCategoryClass::getList('*', $where, 'inTurn DESC');
|
|
|
@@ -26,4 +26,46 @@ class GoodsCategoryService extends BaseService
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
+ //查询指定分类下的商品,没有分页,首页使用 shish 2019.12.2
|
|
|
+ public static function getAppointCategoryList($category)
|
|
|
+ {
|
|
|
+ $ids = array_column($category, 'id');
|
|
|
+ //取出分类下的商品id
|
|
|
+ $list = GoodsCategoryClass::getAllByCondition(['cId' => ['in', $ids]], null, '*');
|
|
|
+ if (empty($list)) {
|
|
|
+ return $category;
|
|
|
+ }
|
|
|
+ $goodsList = [];
|
|
|
+ $categoryGoods = [];
|
|
|
+ foreach ($list as $val) {
|
|
|
+ $goodsList[] = $val['gId'];
|
|
|
+ $cId = $val['cId'];
|
|
|
+ $categoryGoods[$cId][] = $val['gId'];
|
|
|
+ }
|
|
|
+ //查出商品信息
|
|
|
+ $goodsInfoList = GoodsService::getAllByCondition(['id' => ['in', $goodsList]], 'inTurn DESC', 'goodsName,shopImg,price,sold,id', 'id');
|
|
|
+ $goodsInfoList = GoodsCategoryClass::groupGoodsBaseInfo($goodsInfoList);
|
|
|
+
|
|
|
+ //每个分类取的商品数
|
|
|
+ $getNum = [6, 2, 4];
|
|
|
+
|
|
|
+ foreach ($category as $key => $val) {
|
|
|
+ $id = $val['id'];
|
|
|
+ //当前分类下有哪些商品id,并组合商品信息
|
|
|
+ $categoryGoodsIdList = isset($categoryGoods[$id]) ? $categoryGoods[$id] : [];
|
|
|
+ $info = [];
|
|
|
+ if (!empty($categoryGoodsIdList)) {
|
|
|
+ $currentGetNum = isset($getNum[$key]) ? $getNum[$key] : 2;
|
|
|
+ $categoryGoodsIdList = array_slice($categoryGoodsIdList, 0, $currentGetNum);
|
|
|
+ foreach ($categoryGoodsIdList as $currentGoodsId) {
|
|
|
+ if (isset($goodsInfoList[$currentGoodsId])) {
|
|
|
+ $info[] = $goodsInfoList[$currentGoodsId];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $category[$key]['goodsInfoList'] = $info;
|
|
|
+ }
|
|
|
+ return $category;
|
|
|
+ }
|
|
|
+
|
|
|
}
|