Example #1
0
    def update(self, userId, gameId, clientId, activityId):
        '''
        未领取 + 有剩余 = 显示可领取
        未领取 + 无剩余 = 显示倒计时
        已领取 + xxx   = 显示倒计时
        {'isOK': True, 'nowTime': 1452161428.0, 'nextTime': 1452218400.0, 'hasGet': False, 'isRemain': True, 'tip': tip}
        '''
        clientconf = self._clientConf
        serverconf = self._serverConf
        dataWrapper = self._dataWrapper

        timelist = Tool.dictGet(clientconf, "config.activate.timeList")
        startdate = serverconf.get("start")
        enddate = serverconf.get("end")

        #检测是否过期
        if not self.checkOperative():
            tip = Tool.dictGet(clientconf, "config.activate.outdateTip")
            return {"isOK": False, "tip": tip}  #活动已经过期

        nowstamp = Tool.datetimeToTimestamp(datetime.now())
        rconf = {"isOK": True, "nowTime": nowstamp}

        # 上次领取的物品
        itemconf = dataWrapper.getLastGetItem(userId)
        if itemconf:
            rconf.update({
                "itemDesc": itemconf.get("itemDesc"),
                "itemCount": itemconf.get("count")
            })

        arrive_timepoint = dataWrapper.getLastestTimePoint(timelist, startdate)
        next_timepoint = dataWrapper.getNextTimePoint(timelist, enddate)

        if next_timepoint:  # 若存在下一个时间点
            rconf["nextTime"] = Tool.datetimeToTimestamp(next_timepoint)

        count = 0
        if arrive_timepoint:  #已经达到至少一个领取时间点
            has_get = dataWrapper.hasGet(userId, arrive_timepoint)  # 是否已经领取
            isvip = (UserInfo.getVipLevel(userId) > 0)
            if isvip:
                count = _redenvelopeWrapper.getCount()  # 剩余红包数量
            else:
                count = _redenvelopeWrapper.getGeneralCount()  # 非VIP只检测普通红包数量
            rconf.update({"hasGet": has_get, "isRemain": (count > 0)})

            # 上次领取时间在昨天?
            today = datetime.now().replace(None, None, None, 0, 0, 0, 0)
            if arrive_timepoint < today:
                rconf.update({"isFirst": True})

        else:  #未达到领取时间
            rconf.update({"hasGet": False, "isRemain": False, "isFirst": True})

        ftlog.debug("TYActivityDdzRedEnvelope.update: userId", userId,
                    "rconf=", rconf, "count=", count)
        return rconf
Example #2
0
    def update(self, userId, gameId, clientId, activityId, bankId):
        '''
        未领取 + 有剩余 = 显示可领取
        未领取 + 无剩余 = 显示倒计时
        已领取 + xxx   = 显示倒计时
        {'isOK': True, 'nowTime': 1452161428.0, 'nextTime': 1452218400.0, 'hasGet': False, 'isRemain': True, 'tip': tip}
        '''
        clientconf = self._clientConf

        #检测是否过期
        if not self.checkOperative():
            tip = Tool.dictGet(clientconf, "config.activate.outdateTip")
            return {"isOK": False, "tip": tip}  #活动已经过期

        nowstamp = Tool.datetimeToTimestamp(datetime.now())
        rconf = {"isOK": True, "nowTime": nowstamp}
        iteminfo = LuckyPacketHelper.getUserGetLastlyHistory(bankId, userId)
        if iteminfo:
            rconf.update({
                "itemDesc": iteminfo.get("itemDesc"),
                "itemCount": iteminfo.get("count")
            })

        timeservices = ConfigDatabase.getTimeServices(bankId)
        next_timepoint = timeservices.getFirstUnreachedDatetime()
        if next_timepoint:
            rconf["nextTime"] = Tool.datetimeToTimestamp(next_timepoint)

        arrive_timepoint = timeservices.getLastlyReachedDatetime()
        if arrive_timepoint:  #已经达到至少一个领取时间点
            current_issue = timeservices.getIssueNumber(arrive_timepoint)
            isget = LuckyPacketHelper.isUserGet(bankId, userId, current_issue)
            isvip = (UserInfo.getVipLevel(userId) > 0)
            if isvip:
                count = PacketRedisInterface.getAllPacketNumber(
                    bankId, current_issue)  # 剩余红包数量
            else:
                count = PacketRedisInterface.getNormalPacketNumber(
                    bankId, current_issue)  # 非VIP只检测普通红包数量
            rconf.update({"hasGet": isget, "isRemain": (count > 0)})

            # 上次领取时间在昨天?
            today = datetime.now().replace(None, None, None, 0, 0, 0, 0)
            if arrive_timepoint < today:
                rconf.update({"isFirst": True})

        else:  #未达到领取时间
            rconf.update({"hasGet": False, "isRemain": False, "isFirst": True})

        ftlog.debug("LuckyPacket.update: userId=", userId, "bankId=", bankId,
                    "rconf=", rconf, "count=", count)
        return rconf
Example #3
0
    def get(self, userId, gameId, clientId, activityId):
        '''
        {'isOK': True, 'nowTime': 1452161428.0, 'nextTime': 1452218400.0, 'hasGet': False, 'isRemain': True, 'tip': tip}
        '''
        clientconf = self._clientConf
        serverconf = self._serverConf
        dataWrapper = self._dataWrapper

        timelist = Tool.dictGet(clientconf, "config.activate.timeList")
        startdate = serverconf.get("start")
        enddate = serverconf.get("end")

        #检测是否过期
        if not self.checkOperative():
            tip = Tool.dictGet(clientconf, "config.activate.outdateTip")
            return {"isOK": False, "tip": tip}  #活动已经过期

        nowstamp = Tool.datetimeToTimestamp(datetime.now())
        rconf = {"isOK": True, "nowTime": nowstamp}

        arrive_timepoint = dataWrapper.getLastestTimePoint(timelist, startdate)
        next_timepoint = dataWrapper.getNextTimePoint(timelist, enddate)

        if next_timepoint:  # 若存在下一个时间点
            rconf["nextTime"] = Tool.datetimeToTimestamp(next_timepoint)

        if not arrive_timepoint:  #未达到领取时间
            tip = Tool.dictGet(clientconf, "config.activate.cannotGetTip")
            rconf.update({"isOK": False, "tip": tip})
            return rconf

        has_get = dataWrapper.hasGet(userId, arrive_timepoint)  # 是否已经领取
        ftlog.debug("TYActivityDdzRedEnvelope.get: userId", userId,
                    " has_get=", has_get)
        if has_get:  # 已经领取了
            tip = Tool.dictGet(clientconf, "config.activate.alreadyGetTip")
            rconf.update({"isOK": False, "tip": tip})
            return rconf

        isvip = (UserInfo.getVipLevel(userId) > 0)
        result = daobase.executeMixLua(_REDIS_LUA_GET_NAME, 2, isvip,
                                       random.randint(1, 10000000))
        ftlog.debug("TYActivityDdzRedEnvelope.get: userId", userId, " result=",
                    result, "isvip=", isvip)

        if not result:
            tip = Tool.dictGet(clientconf, "config.activate.emptyGetTip")
            rconf.update({"isOK": False, "tip": tip})
            return rconf

        # 领取红包的结果
        result_count = result[1]

        # 领取红包项的配置
        itemconf = _redenvelopeWrapper.getItemConfigWithPath(result[0])
        result_name = str(itemconf.get('desc'))

        # 构造邮箱信息
        assetsdict = {"assets": result_name, "count": str(result_count)}
        mail = Tool.dictGet(clientconf, "config.mail")
        mail = strutil.replaceParams(mail, assetsdict)

        # 发送奖励和邮箱信息
        assets = {'itemId': itemconf.get("itemId"), 'count': result_count}
        UserBag.sendAssetsToUser(6, userId, assets, 'DDZ_ACT_REDENVELOPE',
                                 mail)

        # 发送LED的(条件满足)
        ok = self.sendLedIfNeed(userId, itemconf, result_count)
        ftlog.debug("TYActivityDdzRedEnvelope.get: sendLed-> userId=", userId,
                    " ok=", ok)

        # 记录领取物品
        assets.update({"itemDesc": itemconf.get('desc')})
        dataWrapper.markGet(userId, arrive_timepoint, assets)

        # 日志记录领取
        ftlog.debug("TYActivityDdzRedEnvelope:Get, ", "userId", userId,
                    "gettime", str(datetime.now()), "assets",
                    assets.get("itemId"), "count", assets.get("count"), "desc",
                    assets.get("itemDesc"), "detail", assets)

        # 构造协议信息
        itemtip = Tool.dictGet(clientconf, "config.activate.itemGetTip")
        itemtip = strutil.replaceParams(itemtip, assetsdict)
        rconf.update({
            "isOK": True,
            "itemDesc": result_name,
            "itemCount": result_count,
            "tip": itemtip
        })
        ftlog.debug("TYActivityDdzRedEnvelope.get: userId=", userId,
                    " itemconf=", itemconf, "arrive_timepoint=",
                    str(arrive_timepoint), "rconf=", rconf)

        return rconf
Example #4
0
    def get(self, userId, gameId, clientId, activityId, bankId):
        '''
        {'isOK': True, 'nowTime': 1452161428.0, 'nextTime': 1452218400.0, 'hasGet': False, 'isRemain': True, 'tip': tip}
        '''
        clientconf = self._clientConf

        #检测是否过期
        if not self.checkOperative():
            tip = Tool.dictGet(clientconf, "config.activate.outdateTip")
            return {"isOK": False, "tip": tip}  #活动已经过期

        nowstamp = Tool.datetimeToTimestamp(datetime.now())
        rconf = {"isOK": True, "nowTime": nowstamp}

        timeservices = ConfigDatabase.getTimeServices(bankId)
        next_timepoint = timeservices.getFirstUnreachedDatetime()
        if next_timepoint:
            rconf["nextTime"] = Tool.datetimeToTimestamp(next_timepoint)

        arrive_timepoint = timeservices.getLastlyReachedDatetime()
        if not arrive_timepoint:  #未达到领取时间
            tip = Tool.dictGet(clientconf, "config.activate.cannotGetTip")
            rconf.update({"isOK": False, "tip": tip})
            return rconf

        current_issue = timeservices.getIssueNumber(arrive_timepoint)
        isget = LuckyPacketHelper.isUserGet(bankId, userId, current_issue)
        if isget:  # 已经领取了
            tip = Tool.dictGet(clientconf, "config.activate.alreadyGetTip")
            rconf.update({"isOK": False, "tip": tip})
            return rconf

        isvip = (UserInfo.getVipLevel(userId) > 0)
        iteminfo = LuckyPacketHelper.getPacket(bankId, current_issue, isvip)
        ftlog.debug("TYActivityDdzRedEnvelope.get: userId", userId,
                    " iteminfo=", iteminfo, "isvip=", isvip)
        if not iteminfo:
            tip = Tool.dictGet(clientconf, "config.activate.emptyGetTip")
            rconf.update({"isOK": False, "tip": tip})
            return rconf

        itemId = iteminfo.get('itemId')
        itemCount = iteminfo.get('count', 0)
        itemDesc = self.getItemDesc(clientconf, iteminfo)
        iteminfo["itemDesc"] = itemDesc

        # 构造邮箱信息
        assetsdict = {"assets": itemDesc, "count": str(itemCount)}
        mail = Tool.dictGet(clientconf, "config.mail")
        mail = strutil.replaceParams(mail, assetsdict)

        # 发送奖励和邮箱信息
        assets = {'itemId': itemId, 'count': itemCount}
        UserBag.sendAssetsToUser(6, userId, assets, 'DDZ_ACT_REDENVELOPE',
                                 mail)

        # 发送LED的(条件满足)
        itemconf = self.getItemConf(clientconf, iteminfo)
        ok = self.sendLedIfNeed(userId, itemconf, itemCount)
        ftlog.debug("TYActivityDdzRedEnvelope.get: sendLed-> userId=", userId,
                    " ok=", ok)

        # 记录领取物品
        assets.update({"itemDesc": itemconf.get('desc')})
        LuckyPacketHelper.setUserGet(bankId, userId, current_issue, iteminfo)

        # 日志记录领取
        ftlog.debug("TYActivityDdzRedEnvelope:Get, ", "userId", userId,
                    "gettime", str(datetime.now()), "assets",
                    iteminfo.get("itemId"), "count", iteminfo.get("count"),
                    "desc", iteminfo.get("itemDesc"), "detail", iteminfo)

        # 构造协议信息
        itemtip = Tool.dictGet(clientconf, "config.activate.itemGetTip")
        itemtip = strutil.replaceParams(itemtip, assetsdict)
        rconf.update({
            "isOK": True,
            "itemDesc": itemDesc,
            "itemCount": itemCount,
            "tip": itemtip
        })
        ftlog.debug("LuckyPacket.get: userId=", userId,
                    " itemconf=", itemconf, "arrive_timepoint=",
                    str(arrive_timepoint), "rconf=", rconf)

        return rconf