12345678910111213141516171819202122232425262728293031 |
- <?php
- namespace app\common\Service;
- use app\common\model\SkuSpec as SkuSpecModel;
- class SkuSpec
- {
- /**
- * 获取指定商品的SKU信息
- * @param int $goods_id 商品ID
- * @return array
- */
- public static function getGoodsSkuSpec($goods_id)
- {
- $list = (new SkuSpecModel())
- ->field('MIN(`id`) AS `id`, MIN(`goods_id`) AS `goods_id`, `spec_id`')
- ->where('goods_id', $goods_id)
- ->with([
- 'Spec',
- 'SkuValue' => function ($query) use ($goods_id) {
- $query->where('goods_id', $goods_id)
- ->field('id,goods_id,spec_id,spec_value_id')
- ->with(['SpecValue']);
- }
- ])->group('spec_id')->select();
- $list = collection($list)->toArray();
- return $list;
- }
- }
|