コード例 #1
0
 public function actionDelete($id)
 {
     $params = $this->getParams();
     $accountId = $this->getAccountId();
     $where = ['status' => Goods::STATUS_OFF, 'accountId' => $accountId];
     if (isset($params['all']) && $params['all']) {
         if (Goods::deleteAll($where) === false) {
             throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
         }
     } else {
         $idstrList = explode(',', $id);
         $ids = [];
         foreach ($idstrList as $perId) {
             $ids[] = new \MongoId($perId);
         }
         //check the goods are not  on shelves
         $where['status'] = Goods::STATUS_ON;
         $where = array_merge($where, ['_id' => ['$in' => $ids]]);
         if (!empty($goods = Goods::findAll($where))) {
             throw new ServerErrorHttpException(Yii::t('product', 'delete_on_shelves'));
         }
         unset($where['status']);
         if (Goods::deleteAll($where) == false) {
             throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
         }
     }
     Yii::$app->getResponse()->setStatusCode(204);
 }
コード例 #2
0
 public function delete($productIds)
 {
     Goods::deleteAll(['productId' => ['$in' => $productIds]]);
     StoreGoods::deleteAll(['productId' => ['$in' => $productIds]]);
 }