public function deleteTag($accountId, $name) { Account::updateAll(['$pull' => ['tags' => ['name' => $name]]], ['_id' => $accountId]); Member::updateAll(['$pull' => ['tags' => $name]], ['accountId' => $accountId, 'tags' => $name]); Campaign::updateAll(['$pull' => ['tags' => $name]], ['accountId' => $accountId, 'tags' => $name]); $data = ['type' => 'tag_deleted', 'account_id' => $accountId, 'name' => $name]; $this->notifyModules($data); }
public static function renameTag($accountId, $name, $newName) { //add new tag to campaign Campaign::updateAll(['$addToSet' => ['tags' => $newName]], ['accountId' => $accountId, 'tags' => $name]); //remove old tags from campaign Campaign::updateAll(['$pull' => ['tags' => $name]], ['accountId' => $accountId, 'tags' => $name]); }
/** * when user redeem the code.we need operate the participate and limit for per-person * @return array */ public static function recordCampaignLimit($campaign, $member, $accountId, $memberIds) { $limitTimes = empty($campaign->limitTimes) ? Campaign::MAX_COUNT : $campaign->limitTimes; $reAttributes = ['$inc' => ['usedTimes' => 1]]; $reCondition = ['campaignId' => $campaign->_id, 'memberId' => $member->_id, 'usedTimes' => ['$lt' => $limitTimes], 'accountId' => $accountId]; $reUpdateResult = ReMemberCampaign::updateAll($reAttributes, $reCondition); if ($reUpdateResult === 0) { $msg = Yii::t('product', 'campaign_participate_freq_limit'); LogUtil::error(['msg' => $msg, 'memberId' => (string) $member->_id, 'campaignId' => (string) $campaign->_id, 'reAttributes' => $reAttributes, 'reCondition' => $reCondition], self::PROMOTION_LOG); return ['campaign' => [], 'status' => self::CODE_STATUS_EXCEEDED, 'message' => $msg]; } //when the member take part in this campaign how many times,just only to count to 1 if (!in_array($member->_id, $memberIds)) { $participantCount = empty($campaign->participantCount) ? Campaign::MAX_COUNT : $campaign->participantCount; $attributes = ['$inc' => ['usedCount' => 1]]; $conditions = ['_id' => $campaign->_id, 'usedCount' => ['$lt' => $participantCount], 'accountId' => $accountId]; $updateResult = Campaign::updateAll($attributes, $conditions); if ($updateResult === 0) { // rollback the reMemberCampaign remaining times $reAttributes = ['$inc' => ['usedTimes' => -1]]; $reCondition = ['campaignId' => $campaign->_id, 'memberId' => $member->_id, 'accountId' => $accountId]; ReMemberCampaign::updateAll($reAttributes, $reCondition); $msg = Yii::t('product', 'campaign_participate_limit'); LogUtil::error(['msg' => $msg, 'memberId' => (string) $member->_id, 'campaignId' => (string) $campaign->_id, 'reAttributes' => $reAttributes, 'reCondition' => $reCondition], self::PROMOTION_LOG); return ['campaign' => [], 'status' => self::CODE_STATUS_EXCEEDED, 'message' => $msg]; } } return ['campaign' => $campaign]; }