GoodsSpecServer.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Servers;
  3. use App\Models\GoodsSku;
  4. use App\Models\GoodsSpec;
  5. /**
  6. * 商品规格服务
  7. */
  8. class GoodsSpecServer
  9. {
  10. static private $server = '';
  11. private function __construct()
  12. {
  13. }
  14. /**
  15. * 创建对象
  16. * @return GoodsSpecServer
  17. */
  18. static function creatServer()
  19. {
  20. if (empty(self::$server)) {
  21. self::$server = new GoodsSpecServer();
  22. }
  23. return self::$server;
  24. }
  25. /**
  26. * 获取商品规格信息
  27. * @param $goods_id
  28. * @return array
  29. */
  30. function getGoodsSku($goods_id)
  31. {
  32. $sku = GoodsSku::where('goods_id',$goods_id)
  33. ->where('is_del',0)
  34. ->select(['id as sku_id','sku_name'])
  35. ->orderBy('id','asc')
  36. ->get();
  37. foreach ($sku as $value){
  38. $spec_list = GoodsSpec::where('goods_id', $goods_id)
  39. ->where('is_del',0)
  40. ->where('sku_id',$value->{'sku_id'})
  41. ->select(['id as spec_id','spec_name','spec_price'])
  42. ->orderBy('id','asc')
  43. ->get();
  44. $value->{'spec_list'} = $spec_list;
  45. }
  46. return $sku;
  47. }
  48. }