コード例 #1
0
def start_lottery_queuing(self, member_cid, race_cid, rule: RedPacketRule, checkpoint_cid):
    """

    :param self:
    :param member_cid:
    :param race_cid:
    :param rule:
    :param checkpoint_cid:
    :return:
    """
    logger.info('START(%s): lottery queuing, race_cid=%s, checkpoint_cid=%s, member_id=%s ' % (
        self.request.id, race_cid, checkpoint_cid, member_cid))
    try:
        if not (member_cid and race_cid and rule):
            raise Exception('There is not member_cid or race_cid or rule')

        top_limit, fail_msg = None, None
        if rule.category == CATEGORY_REDPACKET_RULE_DIRECT:
            conf = RedPacketConf.sync_find_one({'rule_cid': rule.cid})
            top_limit = conf.top_limit
            fail_msg = conf.over_msg

        if rule.category == CATEGORY_REDPACKET_RULE_LOTTERY:
            conf = RedPacketBasicSetting.sync_find_one({'rule_cid': rule.cid})
            top_limit = conf.top_limit
            fail_msg = conf.fail_msg

        has_sent_count = RedPacketBox.sync_count({'rule_cid': rule.cid, 'draw_dt': {
            '$gte': datetime.now().replace(hour=0, minute=0, second=0),
            '$lte': datetime.now().replace(hour=23, minute=59, second=59)}, 'record_flag': 1},
                                                 read_preference=ReadPreference.PRIMARY)

        msg = None
        if has_sent_count >= top_limit:
            msg = conf.over_msg
            redpkt_box = RedPacketBox()
            result = RESULT_RACE_LOTTERY_LOSE_LATE
        else:
            redpkt_box = RedPacketBox.sync_find_one({'rule_cid': rule.cid, 'draw_dt': None, 'record_flag': 1})
            if not redpkt_box:
                msg = fail_msg
                redpkt_box = RedPacketBox()
                result = RESULT_RACE_LOTTERY_LOSE
            else:
                # 拿到了红包
                if not redpkt_box.award_msg:
                    item_setting = RedPacketItemSetting.sync_find_one({'rule_cid': rule.cid})
                    msg = item_setting.message
                    logger.error('item_msg: %s' % msg)

                if not redpkt_box.award_cid:
                    result = RESULT_RACE_LOTTERY_LOSE

        redpkt_box.race_cid = race_cid
        redpkt_box.rule_cid = rule.cid
        redpkt_box.checkpoint_cid = checkpoint_cid
        redpkt_box.member_cid = member_cid
        redpkt_box.draw_dt = datetime.now()

        if msg:
            redpkt_box.award_msg = msg
        redpkt_box.sync_save()

        win = bool(redpkt_box.award_cid)
        if win:
            result = RESULT_RACE_LOTTERY_WIN
            add_notice(member_cid, race_cid, checkpoint_cid, msg_type=TYPE_MSG_DRAW, redpkt_box=redpkt_box)

        RedisCache.hset(KEY_RACE_LOTTERY_RESULT.format(checkpoint_cid), member_cid, result)
        logger.info(' END (%s): lottery end , checkpoint_cid=%s, member_id=%s, result=%s ' % (
            self.request.id, checkpoint_cid, member_cid, result))
    except Exception:
        logger.error(traceback.format_exc())
        logger.error(
            'ERROR(%s): lottery error, checkpoint_cid=%s, member_id=%s, rule_cid=%s' % (
                self.request.id, checkpoint_cid, member_cid, rule.cid))
コード例 #2
0
ファイル: convert.py プロジェクト: yaochangfei/stars_new
    item = setting_map[entry.award_cid]
    box = RedPacketBox()
    box.race_cid = race.cid
    box.rule_cid = rule.cid
    box.award_cid = entry.award_cid
    box.award_msg = item.message
    box.award_amount = item.amount

    if entry.open_id:
        member = Member.sync_find_one({'open_id': entry.open_id})
        box.member_cid = member.cid

    hist = RedPacketAwardHistory.sync_find_one({'race_cid': race.cid, 'award_cid': entry.cid, 'issue_status': {'$ne': 1}})
    if hist:
        box.draw_status = STATUS_REDPACKET_AWARDED
        box.draw_dt = hist.request_dt
        box.error_msg = hist.error_msg
        box.request_dt = hist.request_dt
        box.checkpoint_cid = last_ck.cid
    else:
        box.draw_status = STATUS_REDPACKET_AWARD_FAILED

    box.sync_save()

# 抽奖记录
for history in RedPacketLotteryHistory.sync_find({'race_cid': race.cid}):
    history.rule_cid = rule.cid
    history.checkpoint_cid = last_ck.cid
    history.sync_save()