|
|
@@ -4,95 +4,12 @@ namespace bizMall\goods\services;
|
|
|
|
|
|
use bizMall\base\services\BaseService;
|
|
|
use bizMall\goods\classes\GoodsCategoryClass;
|
|
|
-use bizMall\goods\classes\GoodsClass;
|
|
|
-
|
|
|
|
|
|
class GoodsCategoryService extends BaseService
|
|
|
{
|
|
|
|
|
|
public static $baseFile = '\bizMall\goods\classes\GoodsCategoryClass';
|
|
|
|
|
|
- /**
|
|
|
- * 查询一个分类下的商品,有分页
|
|
|
- * @param array $where
|
|
|
- * @param array $goodsCondition
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
- public static function getGoodsList($where, $goodsCondition = [])
|
|
|
- {
|
|
|
- $data = GoodsCategoryClass::getList('*', $where, 'inTurn DESC');
|
|
|
- $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
|
|
|
- if (empty($list)) {
|
|
|
- return $data;
|
|
|
- }
|
|
|
- $ids = array_column($list, 'gId');
|
|
|
- $goodsWhere = ['id' => ['in', $ids]];
|
|
|
- if (count($goodsCondition) > 0) {
|
|
|
- $goodsWhere = array_merge($goodsWhere, $goodsCondition);
|
|
|
- }
|
|
|
- $list = GoodsService::getAllByCondition($goodsWhere, null, '*');
|
|
|
- $data['list'] = GoodsClass::groupGoodsBaseInfo($list, $ids);
|
|
|
- return $data;
|
|
|
- }
|
|
|
-
|
|
|
- //查询指定分类下的商品,没有分页,首页使用 ssh 2019.12.2
|
|
|
- public static function getAppointCategoryList($category, $shop)
|
|
|
- {
|
|
|
- $ids = array_column($category, 'id');
|
|
|
-
|
|
|
- //每个分类取的商品数
|
|
|
- $getNum = [6, 2, 4];
|
|
|
- $showRowNum = [2, 1, 2];
|
|
|
-
|
|
|
- $stockModel = $shop->stockModel ?? 0;
|
|
|
- if ($stockModel == 0) {
|
|
|
- //管到扎的,可以查看所有上架的商品
|
|
|
- $where = ['cId' => ['in', $ids], 'status' => 1];
|
|
|
- } else {
|
|
|
- //管到支的,查看所有上架并且花材数量设置好的商品
|
|
|
- $where = ['cId' => ['in', $ids], 'status' => 1, 'setItemNum' => 1];
|
|
|
- }
|
|
|
-
|
|
|
- //取出分类下的商品id
|
|
|
- $list = GoodsCategoryClass::getAllByCondition($where, 'inTurn DESC,addTime DESC', '*');
|
|
|
- if (empty($list)) {
|
|
|
- foreach ($category as $key => $val) {
|
|
|
- $category[$key]['goodsInfoList'] = [];
|
|
|
- $category[$key]['showRow'] = $showRowNum[$key] ?? 2;
|
|
|
- }
|
|
|
- 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', '*', 'id');
|
|
|
- $goodsInfoList = GoodsClass::groupGoodsBaseInfo($goodsInfoList);
|
|
|
-
|
|
|
- foreach ($category as $key => $val) {
|
|
|
- $id = $val['id'];
|
|
|
- //当前分类下有哪些商品id,并组合商品信息
|
|
|
- $categoryGoodsIdList = $categoryGoods[$id] ?? [];
|
|
|
- $info = [];
|
|
|
- if (!empty($categoryGoodsIdList)) {
|
|
|
- $currentGetNum = $getNum[$key] ?? 2;
|
|
|
- $categoryGoodsIdList = array_slice($categoryGoodsIdList, 0, $currentGetNum);
|
|
|
- foreach ($categoryGoodsIdList as $currentGoodsId) {
|
|
|
- if (isset($goodsInfoList[$currentGoodsId])) {
|
|
|
- $info[] = $goodsInfoList[$currentGoodsId];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- $category[$key]['goodsInfoList'] = $info;
|
|
|
- $category[$key]['showRow'] = $showRowNum[$key] ?? 2;
|
|
|
- }
|
|
|
- return $category;
|
|
|
- }
|
|
|
-
|
|
|
//获取商品所属的分类id ssh 201917
|
|
|
public static function getGoodsHasCategoryIds($goodsId)
|
|
|
{
|