Код: Выделить всё
$topProducts = (new Query())
->select('product_id')
->from('cron_top_products')
->orderBy('RAND()')
->limit(20)
->all();
$products = Products::find()
->where(['id' => array_map(function($item) {
return $item['product_id'];
}, $topProducts)])
->limit(10)
->asArray()
->all();