class spec extends Model { public function specValue(){ return $this->hasMany(specValue::class,'spec_id','id'); } }
class type extends Model { public function attr() { return $this->hasMany(Attribute::class,'type_id','id'); }
}
/**
* 获取商品详情
* @param $id
* @return array
* @throws Exception
*/
public static function getInfo($id){
# 商品基本信息
$goodsInfo = \app\common\model\Goods::with(['category','brand','images','type'])->field('id,goods_name,goods_price,goods_logo,brand_id,cate_id,type_id')->find($id)->toArray();
# type_id已知
$typeInfo = \app\common\model\Type::with(['spec','spec.specValue','attr'])->hidden(['create_time','delete_time','update_time'])->find($goodsInfo['type_id'])->toArray();
$goodsInfo['type_info'] = $typeInfo;
return $goodsInfo;
}