public function actionDelete($id) { $ids = []; $ids[] = new MongoId($id); $membershipDiscount = MembershipDiscount::findByPk($ids); if (empty($membershipDiscount)) { throw new BadRequestHttpException(Yii::t('product', 'membershipDiscount_is_deleted')); } $isDeMembershipDiscount = MembershipDiscount::deleteAll(['_id' => $ids]); if (!$isDeMembershipDiscount) { throw new ServerErrorHttpException(Yii::t('content', 'delete_fail')); } // Update the relate of couponLog collection. $field = ['status' => MembershipDiscount::DELETED, 'operationTime' => new \MongoDate()]; $where = ['_id' => $membershipDiscount->couponLogId]; CouponLog::updateAll($field, $where); }
public function perform() { $args = $this->args; $accountId = new MongoId($args['accountId']); $storeId = new MongoId($args['storeId']); $store = Store::findByPk($storeId); if (!empty($args['location'])) { // create new store location $location = $args['location']; if ($this->_addNewLocation($location, $accountId)) { $storeLocation = new StoreLocation(); $storeLocation->_id = $store->_id; $storeLocation->name = $store->name; $storeLocation->parentName = $location['district']; $storeLocation->level = StoreLocation::LOCATION_LEVEL_STORE; $storeLocation->accountId = $accountId; $storeLocation->save(); } } else { if (!empty($args['oldLocation']) && !empty($args['newLocation'])) { // update store location $oldLocation = $args['oldLocation']; $newLocation = $args['newLocation']; StoreLocation::updateAll(['name' => $store->name, 'parentName' => $newLocation['district']], ['_id' => $store->_id]); $this->_updateLocation($oldLocation, $newLocation, $accountId); } else { if (!empty($args['removeLocation'])) { // delete store location $location = $args['removeLocation']; StoreLocation::deleteAll(['_id' => $storeId]); $this->_removeOldLocation($location, $accountId); } } } //update store name if (!empty($args['newStoreName'])) { //update storeLocation name StoreLocation::updateAll(['name' => $args['newStoreName']], ['_id' => $storeId]); //update couponLog CouponLog::updateAll(['store.name' => $store->name], ['_id' => $storeId]); } //update coupon store name $this->_updateCouponStroeInfo($store); }