$query = new Query();
$query->select('gs.*, g.goods_images, sa.attr_name, sa.is_default, sa.alias_sort')->from(GoodsSpec::tableName() . ' gs');
$query->leftJoin(SpecAlias::tableName() . ' sa', 'gs.attr_id = sa.attr_id and gs.goods_id = sa.goods_id');
// $query->leftJoin(CatSpec::tableName() . ' c', 'gs.attr_id = c.attr_id and gs.cat_id = c.cat_id');
$query->leftJoin(AttrValue::tableName() . ' av', 'gs.attr_vid = av.attr_vid');
$query->leftJoin(Goods::tableName() . ' g', 'g.goods_id = gs.goods_id');
$query->andWhere('gs.goods_id in ('.$goods_ids.')');
// $query->groupBy(['gs.goods_id']);

$query->orderBy([
'sa.is_default' => SORT_DESC,
'gs.spec_sort' => SORT_ASC,
'av.attr_vsort' => SORT_ASC
]);
$sql = clone $query;
var_dump($sql->createCommand()->getRawSql());

05-11 21:50