Ejemplo n.º 1
0
    def toggleCardLockStatus(self, cardId, consumerId):
        millis = SSUtil.getMillis()
        cacheService = CacheService()
        statusFlag = 0
        try:
            consumer = Consumer.objects.get(id=consumerId)
            consumerCard = ConsumerCard.objects.get(id=cardId)

            if SSUtil.isIdinList(consumer.blockedCards, cardId):
                consumer.blockedCards = SSUtil.removeIdFromList(
                    consumer.blockedCards, cardId)
                statusFlag = 1
                consumerCard.status = 1
            else:
                consumer.blockedCards = SSUtil.addIdToList(
                    consumer.blockedCards, cardId)
                statusFlag = 0
                consumerCard.status = 0

            consumer.updated = millis
            consumerCard.updated = millis
            consumer.save()
            cacheService.setConsumer(consumer.id)
            consumerCard.save()
            cacheService.setCard(consumerCard.id)
            return statusFlag
        except:
            raise Exception(SSException.PROCESSING_FAILED)
Ejemplo n.º 2
0
    def unlockTxTypeStatus(self, cardId, txType):
        millis = SSUtil.getMillis()
        statusFlag = 1
        cacheService = CacheService()
        try:
            consumerCard = ConsumerCard.objects.get(id=cardId)

            if SSUtil.isIdinList(consumerCard.blockedTxTypes,txType):
                consumerCard.blockedTxTypes = SSUtil.removeIdFromList(consumerCard.blockedTxTypes,txType)
                statusFlag = 1

            consumerCard.updated = millis
            consumerCard.save()
            cacheService.setCard(cardId)
            return statusFlag
        except:
           raise Exception(SSException.PROCESSING_FAILED)
Ejemplo n.º 3
0
    def recalculateAgg(self, consumerId, recentAmount, recentTxn):
        currTimeMillis = SSUtil.getMillis()
        ssConst = SSConst()
        cacheService = CacheService()
        prefs = cacheService.getConsumerPrefs(consumerId)
        name_map = {'total': 'total', 'pk': 'id'}
        periodKeysJson = ssConst.getJson(ssConst.PERIOD_KEYS)
        approvalTypeJson = ssConst.getJson(ssConst.APPROVAL_TYPES)
        if prefs:
            for pref in prefs:
                consumerAgg = ConsumerAgg()

                querySt = "select sum(amtSpentSS) as total, 1 as id from ss_consumer_txn where consumerId =" + str(
                    consumerId)
                querySt += " and ssApproval='" + ssConst.APPROVAL_TYPES[0][
                    0] + "'"
                if pref.periodKey != 'Any':
                    print "period key is " + pref.periodKey
                    print " value is " + periodKeysJson[pref.periodKey]
                    querySt += " and  FROM_UNIXTIME(created/1000) >= DATE_SUB(FROM_UNIXTIME(" + str(
                        currTimeMillis / 1000
                    ) + "), INTERVAL " + periodKeysJson[pref.periodKey] + ")"
                if pref.categoryKey != 'Any':
                    category = TxnCategory.objects.get(name=pref.categoryKey)
                    querySt += " and  category_id = " + str(category.id)
                if pref.txType != 'Any':
                    querySt += " and  txType = '" + pref.txType + "'"
                if pref.cardId != -1:
                    querySt += " and  cardId = " + str(pref.cardId)
                if pref.merchantId != -1:
                    querySt += " and  merchant_id = " + str(pref.merchantId)
                print querySt
                res = ConsumerTxn.objects.raw(querySt, translations=name_map)
                total = 0
                for x in res:
                    total = x.total
                if total == None:
                    total = 0
                print total
                # check if aggregate exists for this pref
                print str(consumerId) + str(
                    pref.cardId
                ) + pref.periodKey + " " + pref.categoryKey + " " + pref.txType + " " + str(
                    pref.merchantId)
                try:
                    consumerAgg = ConsumerAgg.objects.get(
                        consumerId=consumerId,
                        cardId=pref.cardId,
                        periodKey=pref.periodKey,
                        categoryKey=pref.categoryKey,
                        txType=pref.txType,
                        merchantId=pref.merchantId)
                    print "Got consumer agg " + str(total)
                except ConsumerAgg.DoesNotExist:
                    consumerAgg.periodKey = pref.periodKey
                    consumerAgg.categoryKey = pref.categoryKey
                    consumerAgg.txType = pref.txType
                    consumerAgg.cardId = pref.cardId
                    consumerAgg.merchantId = pref.merchantId
                    consumerAgg.consumerId = pref.consumerId
                    consumerAgg.created = currTimeMillis
                consumerAgg.amtSpentSS = total
                consumerAgg.updated = currTimeMillis
                consumerAgg.save()

        cacheService.setConsumerAggs(consumerId)
        #fix balance now
        if not recentTxn is None:
            if recentTxn.ssApproval == ssConst.APPROVAL_TYPES[0][0]:
                card = ConsumerCard.objects.get(id=recentTxn.cardId)
                card.amtSpentSS = card.amtSpentSS + recentAmount
                card.currOS = card.currOS + recentAmount
                card.avaialbleLimit = card.limit - card.currOS
                card.updated = currTimeMillis
                card.save()
                cacheService.setCard(card.id)