| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace bizHd\goods\services;
- use bizHd\base\services\BaseService;
- use bizHd\goods\classes\GoodsCategoryClass;
- use bizHd\goods\classes\GoodsClass;
- class GoodsCategoryService extends BaseService
- {
- public static $baseFile = '\bizHd\goods\classes\GoodsCategoryClass';
- //获取商品所属的分类id ssh 201917
- public static function getGoodsHasCategoryIds($goodsId)
- {
- $categoryIdList = GoodsCategoryClass::getAllByCondition(['gId' => $goodsId], null, 'cId', 'cId');
- if (empty($categoryIdList)) {
- return [];
- }
- $ids = array_keys($categoryIdList);
- return $ids;
- }
- //所有商品
- public static function getGoodsAll($where)
- {
- $list = GoodsCategoryClass::getAllList('*', $where, 'inTurn DESC');
- $ids = array_column($list, 'gId');
- $list = GoodsService::getAllByCondition(['id' => ['in', $ids]], null, '*');
- $data = GoodsClass::groupGoodsBaseInfo($list);
- return $data;
- }
- //获取商家下所有启用的商品分类
- public static function getEnableGoodsCategory($mainId)
- {
- $cat = CategoryService::getEnableList($mainId);
- $where = ['mainId' => $mainId, 'cId' => ['in', array_column($cat, 'id')]];
- $data = self::getAllList('cId as classId,gId', $where);
- return $data;
- }
- //获取常用分类的 goods id lqh 2021.04.09
- public static function getOftenIds($mainId)
- {
- $data = GoodsClass::getLimitList("id", ['mainId' => $mainId], 10, 'actualSold desc');
- if ($data) {
- $data = array_column($data, 'id');
- }
- return $data;
- }
- public static function assembleData($classIds, $goodsCateData, $goodsData)
- {
- $classMapItem = [];
- if ($goodsData) {
- foreach ($goodsCateData as $v) {
- $classMapItem[$v['classId']][] = $v['gId'];
- }
- }
- $classData = [];
- foreach ($classIds as $v) {
- $classId = $v['id'];
- if ($classId > 0) {
- $tmp = [];
- $tmp['classId'] = $classId;
- $tmp['className'] = $v['name'];
- $items = $classMapItem[$classId] ?? [];
- if ($items) {
- if ($goodsData) {
- foreach ($goodsData as $v) {
- if (in_array($v['id'], $items)) {
- $v['classId'] = $classId; //前端要求增加classId 2021.1.31 lqh
- $tmp['child'][] = $v;
- }
- }
- } else {
- $tmp['child'] = [];
- }
- } else {
- $tmp['child'] = [];
- }
- //去除空分类
- if (empty($tmp['child'])) {
- continue;
- }
- $classData[] = $tmp;
- }
- }
- return $classData;
- }
- }
|