SkuSpec.php 856 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace app\common\Service;
  3. use app\common\model\SkuSpec as SkuSpecModel;
  4. class SkuSpec
  5. {
  6. /**
  7. * 获取指定商品的SKU信息
  8. * @param int $goods_id 商品ID
  9. * @return array
  10. */
  11. public static function getGoodsSkuSpec($goods_id)
  12. {
  13. $list = (new SkuSpecModel())
  14. ->field('MIN(`id`) AS `id`, MIN(`goods_id`) AS `goods_id`, `spec_id`')
  15. ->where('goods_id', $goods_id)
  16. ->with([
  17. 'Spec',
  18. 'SkuValue' => function ($query) use ($goods_id) {
  19. $query->where('goods_id', $goods_id)
  20. ->field('id,goods_id,spec_id,spec_value_id')
  21. ->with(['SpecValue']);
  22. }
  23. ])->group('spec_id')->select();
  24. $list = collection($list)->toArray();
  25. return $list;
  26. }
  27. }