hasMany('StoreGoodsItem','goods_id','id')->where(['is_deleted'=>0,'status'=>1]); } /** * 获取商品规格详情 * @param $goods_id 商品id * @param $spec_id 规格id * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function getGoodsSpec($goods_id,$spec_id){ $goods_info = self::with(['itemList'=>function($query)use($spec_id){ return $query->where('id',$spec_id)->where('is_deleted',0); }])->where('id',$goods_id)->where('is_deleted',0)->where('status',1)->find(); return $goods_info ? $goods_info->toArray() : []; } }