| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Servers;
- use App\Models\GoodsSku;
- use App\Models\GoodsSpec;
- /**
- * 商品规格服务
- */
- class GoodsSpecServer
- {
- static private $server = '';
- private function __construct()
- {
- }
- /**
- * 创建对象
- * @return GoodsSpecServer
- */
- static function creatServer()
- {
- if (empty(self::$server)) {
- self::$server = new GoodsSpecServer();
- }
- return self::$server;
- }
- /**
- * 获取商品规格信息
- * @param $goods_id
- * @return array
- */
- function getGoodsSku($goods_id)
- {
- $sku = GoodsSku::where('goods_id',$goods_id)
- ->where('is_del',0)
- ->select(['id as sku_id','sku_name'])
- ->orderBy('id','asc')
- ->get();
- foreach ($sku as $value){
- $spec_list = GoodsSpec::where('goods_id', $goods_id)
- ->where('is_del',0)
- ->where('sku_id',$value->{'sku_id'})
- ->select(['id as spec_id','spec_name','spec_price'])
- ->orderBy('id','asc')
- ->get();
- $value->{'spec_list'} = $spec_list;
- }
- return $sku;
- }
- }
|