|
|
@@ -10,9 +10,9 @@ use linslin\yii2\curl;
|
|
|
|
|
|
class GoodsCategoryService extends BaseService
|
|
|
{
|
|
|
-
|
|
|
+ const OFTEN_CLASS_ID = '-2'; //常用分类
|
|
|
public static $baseFile = '\bizHd\goods\classes\GoodsCategoryClass';
|
|
|
-
|
|
|
+
|
|
|
//查询一个分类下的商品,有分页 ssh 2019.12.2
|
|
|
public static function getGoodsList($where)
|
|
|
{
|
|
|
@@ -26,7 +26,7 @@ class GoodsCategoryService extends BaseService
|
|
|
$data['list'] = GoodsClass::groupGoodsBaseInfo($list);
|
|
|
return $data;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//查询指定分类下的商品,没有分页,首页使用 ssh 2019.12.2
|
|
|
public static function getAppointCategoryList($category)
|
|
|
{
|
|
|
@@ -49,11 +49,11 @@ class GoodsCategoryService extends BaseService
|
|
|
//查出商品信息
|
|
|
$goodsInfoList = GoodsService::getAllByCondition(['id' => ['in', $goodsList]], 'inTurn DESC', '*', 'id');
|
|
|
$goodsInfoList = GoodsClass::groupGoodsBaseInfo($goodsInfoList);
|
|
|
-
|
|
|
+
|
|
|
//每个分类取的商品数
|
|
|
$getNum = [6, 2, 4];
|
|
|
$showRowNum = [2, 1, 2];
|
|
|
-
|
|
|
+
|
|
|
foreach ($category as $key => $val) {
|
|
|
$id = $val['id'];
|
|
|
//当前分类下有哪些商品id,并组合商品信息
|
|
|
@@ -73,7 +73,7 @@ class GoodsCategoryService extends BaseService
|
|
|
}
|
|
|
return $category;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//获取商品所属的分类id ssh 201917
|
|
|
public static function getGoodsHasCategoryIdList($goodsId)
|
|
|
{
|
|
|
@@ -85,4 +85,104 @@ class GoodsCategoryService extends BaseService
|
|
|
return $ids;
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+ //所有商品
|
|
|
+ public static function getGoodsAll($where)
|
|
|
+ {
|
|
|
+ $list = GoodsCategoryClass::getAllList('*', $where, 'inTurn DESC');
|
|
|
+
|
|
|
+ $ids = array_column($list, 'gId');
|
|
|
+ $list = GoodsService::getAllByCondition(['id' => ['in', $ids]], 'inTurn DESC', '*');
|
|
|
+ $data = GoodsClass::groupGoodsBaseInfo($list);
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取商家下 所有商品的分类
|
|
|
+ public static function getGoodsCategory($sjId)
|
|
|
+ {
|
|
|
+ $where = [
|
|
|
+ 'merchantId' => $sjId
|
|
|
+ ];
|
|
|
+ $data = self::getAllList('cId as classId,gId', $where);
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取常用分类的 goods id linqh 2021.04.09
|
|
|
+ public static function getOftenIds($sjId)
|
|
|
+ {
|
|
|
+ $data = GoodsClass::getLimitList("id", ['merchantId' => $sjId], 10,'actualSold desc');
|
|
|
+ if ($data) {
|
|
|
+ $data = array_column($data, 'id');
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ public static function assembleData($classIds,$goodsCateData,$goodsData, $oftenIds)
|
|
|
+ {
|
|
|
+ $oftenItemInfoData = [];
|
|
|
+ if($goodsData){
|
|
|
+ foreach ($goodsData as $v){
|
|
|
+ if(in_array($v['id'],$oftenIds)){
|
|
|
+ $v['classId'] = self::OFTEN_CLASS_ID;
|
|
|
+ $oftenItemInfoData[] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //classId=>itemId
|
|
|
+ $classMapItem = [];
|
|
|
+ if($goodsData){
|
|
|
+ foreach ($goodsCateData as $v){
|
|
|
+ $classMapItem[$v['classId']][] = $v['gId'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //常用
|
|
|
+ $oftenData = [
|
|
|
+ [
|
|
|
+ 'classId'=> self::OFTEN_CLASS_ID,
|
|
|
+ 'className'=>'常用',
|
|
|
+ 'child'=>$oftenItemInfoData,
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+
|
|
|
+ $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 linqh
|
|
|
+ $tmp['child'][] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $tmp['child'] = [];
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $tmp['child'] = [];
|
|
|
+ }
|
|
|
+ //去除空分类
|
|
|
+ if(empty($tmp['child'])){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $classData[] = $tmp;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //$data = array_merge($oftenData,$allData,$classData);
|
|
|
+ //去除全部
|
|
|
+ $data = array_merge($oftenData,$classData);
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+}
|