/** * @param int[] $ids * * @return Check */ public static function createByProductIds($ids) { $check = new self(); $check->save(); foreach ($ids as $id) { $product = Product::find()->where(['id' => $id])->one(); if ($product === null) { continue; } $check->link('products', $product); } $check->calculate(); $check->save(); return $check; }