|
@@ -90,7 +90,7 @@ class GoodsService extends Service
|
|
|
}
|
|
|
$cates[$id]['ids'] = array_reverse($cates[$id]['ids']);
|
|
|
$cates[$id]['names'] = array_reverse($cates[$id]['names']);
|
|
|
- if ($simple && count($cates[$id]['names']) !== $this->getCateLevel()) {
|
|
|
+ if ($simple && count($cates[$id]['names']) !== $this->getCateMax()) {
|
|
|
unset($cates[$key]);
|
|
|
}
|
|
|
}
|
|
@@ -109,6 +109,15 @@ class GoodsService extends Service
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 最大分类级别
|
|
|
+ * @return integer
|
|
|
+ */
|
|
|
+ public function getCateMax(): int
|
|
|
+ {
|
|
|
+ return 3;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 商品数据绑定
|
|
|
* @param array $data 商品主数据
|
|
|
* @param boolean $simple 简化数据
|
|
@@ -117,29 +126,19 @@ class GoodsService extends Service
|
|
|
* @throws \think\db\exception\DbException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
*/
|
|
|
- public function buildItemData(array &$data = [], $simple = true): array
|
|
|
+ public function buildData(array &$data = [], $simple = true): array
|
|
|
{
|
|
|
- $cates = $this->getCateData();
|
|
|
- $codes = array_unique(array_column($data, 'code'));
|
|
|
+ [$cates, $codes] = [$this->getCateData(), array_unique(array_column($data, 'code'))];
|
|
|
$marks = $this->app->db->name('ShopGoodsMark')->where(['status' => 1])->column('name');
|
|
|
$items = $this->app->db->name('ShopGoodsItem')->whereIn('goods_code', $codes)->where(['status' => 1])->select()->toArray();
|
|
|
foreach ($data as &$vo) {
|
|
|
[$vo['marks'], $vo['cateids'], $vo['cateinfo']] = [str2arr($vo['marks'], ',', $marks), str2arr($vo['cateids']), []];
|
|
|
- foreach ($cates as $cate) if (in_array($cate['id'], $vo['cateids'])) $vo['cateinfo'] = $cate;
|
|
|
[$vo['slider'], $vo['specs'], $vo['items']] = [str2arr($vo['slider'], '|'), json_decode($vo['data_specs'], true), []];
|
|
|
+ foreach ($cates as $cate) if (in_array($cate['id'], $vo['cateids'])) $vo['cateinfo'] = $cate;
|
|
|
foreach ($items as $item) if ($item['goods_code'] === $vo['code']) $vo['items'][] = $item;
|
|
|
if ($simple) unset($vo['marks'], $vo['sort'], $vo['status'], $vo['deleted'], $vo['data_items'], $vo['data_specs'], $vo['cateinfo']['parent']);
|
|
|
}
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 最大分类级别
|
|
|
- * @return integer
|
|
|
- */
|
|
|
- public function getCateLevel(): int
|
|
|
- {
|
|
|
- return 3;
|
|
|
- }
|
|
|
-
|
|
|
}
|