|
@@ -747,38 +747,34 @@ class Goods extends Backend
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 获取单个商品信息
|
|
|
|
|
|
+ * 获取多个商品信息
|
|
*/
|
|
*/
|
|
- public function info()
|
|
|
|
|
|
+ public function getGoodsByIds()
|
|
{
|
|
{
|
|
- $id = $this->request->request('id');
|
|
|
|
- if (!$id) {
|
|
|
|
- $this->error('商品ID不能为空');
|
|
|
|
|
|
+ $ids = $this->request->request('ids');
|
|
|
|
+ if (!$ids) {
|
|
|
|
+ $this->error('请选择商品');
|
|
}
|
|
}
|
|
|
|
|
|
- $goods = $this->model
|
|
|
|
- ->with(['Brand'])
|
|
|
|
- ->where('id', $id)
|
|
|
|
- ->find();
|
|
|
|
|
|
+ $ids = explode(',', $ids);
|
|
|
|
+ $list = $this->model
|
|
|
|
+ ->with(['Category'])
|
|
|
|
+ ->where('id', 'in', $ids)
|
|
|
|
+ ->select();
|
|
|
|
|
|
- if (!$goods) {
|
|
|
|
- $this->error('商品不存在');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// 处理图片URL和SKU信息
|
|
// 处理图片URL和SKU信息
|
|
- if ($goods['image']) {
|
|
|
|
- $goods['image'] = cdnurl($goods['image'], true);
|
|
|
|
|
|
+ foreach ($list as &$item) {
|
|
|
|
+ if ($item['image']) {
|
|
|
|
+ $item['image'] = cdnurl($item['image'], true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 获取商品的第一个SKU ID(单规格商品通常只有一个SKU)
|
|
|
|
+ $sku = \app\common\model\Sku::where('goods_id', $item['id'])->find();
|
|
|
|
+ $item['sku_id'] = $sku ? $sku['id'] : 0;
|
|
}
|
|
}
|
|
|
|
|
|
- // 获取商品的第一个SKU ID(单规格商品通常只有一个SKU)
|
|
|
|
- $sku = \app\common\model\Sku::where('goods_id', $goods['id'])->find();
|
|
|
|
- $goods['sku_id'] = $sku ? $sku['id'] : 0;
|
|
|
|
-
|
|
|
|
- // 添加商品类型文本
|
|
|
|
- $goodsTypeMap = GoodsEnum::getGoodsTypeMap();
|
|
|
|
- $goods['type_text'] = isset($goodsTypeMap[$goods['type']]) ? $goodsTypeMap[$goods['type']] : '';
|
|
|
|
|
|
|
|
- $this->success('获取成功', null, $goods);
|
|
|
|
|
|
+ $this->success('获取成功', null, $list);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|