public function actionDelete($id) { $idstrList = explode(',', $id); $ids = []; foreach ($idstrList as $perId) { $ids[] = new MongoId($perId); } $where = ['_id' => ['$in' => $ids]]; $goodsWhere = ['productId' => ['$in' => $ids]]; $result = Product::findOne(array_merge($where, ['isBindCode' => true])); if (!empty($result)) { throw new BadRequestHttpException(Yii::t('product', 'can_not_delete_before_promocode')); } if (!empty(Campaign::getByProductIds($ids)) || !empty(Goods::findOne($goodsWhere))) { throw new BadRequestHttpException(Yii::t('product', 'can_not_delete')); } if (Product::deleteAll($where) == false) { throw new ServerErrorHttpException('Failed to delete the object for unknown reason.'); } //delete the product intro ProductInfo::deleteAll($where); //delete goods and storeGoods $this->attachBehavior('ProductBehavior', new ProductBehavior()); $this->delete($ids); Yii::$app->getResponse()->setStatusCode(204); }
/** *get product description */ public function getIntro() { return $this->hasOne(ProductInfo::className(), ['_id' => '_id']); }