Example #1
0
 def format(self):
     data = {
         'order_id': self.order_id,
         'create_at': util.datetime2timestamp(self.create_at),
         'name': self.vgc_name,
         'exchange_code': self.gift_code,
         'expire_at': util.datetime2timestamp(self.expire_at)
     }
     return data
Example #2
0
 def format(self):
     data = {
         'exchange_time': util.datetime2timestamp(self.exchange_time),
         'gift_value': self.gift_value,
         'exchange_value': self.exchange_value,
         'action': self.action,
         'desc': util.get_choices_desc(TRADE_ACTION, self.action),
         'create_at': util.datetime2timestamp(self.create_at)
     }
     return data
Example #3
0
    def create(cls, **query):
        inst = super(UserGiftLog, cls).create(**query)
        if inst:
            if inst.gift_from == const.FROM_RECORD:
                key = VIDEO_GIFT_KEY % (inst.from_id)
                try:
                    if Redis.exists(key) and query.get("send_success"):
                        Redis.zadd(key,
                                   util.datetime2timestamp(inst.create_at),
                                   cjson.dumps(inst, 2))
                except exceptions.ResponseError:
                    Redis.delete(key)

            key = TOP_SENDER_KEY % (inst.user_id)
            try:
                if Redis.exists(key) and query.get("send_success"):
                    Redis.zincrby(key, inst.gold_price, inst.from_user)
            except exceptions.ResponseError:
                Redis.delete(key)

            if inst.gift_from == const.FROM_LIVE:
                key = USER_TOTAL_GOLD % ({'uid': inst.user_id})
                Redis.delete(key)

        return inst
Example #4
0
 def format(self):
     data = {
         'gold': self.gold,
         'action': self.action,
         'desc': util.get_choices_desc(TRADE_ACTION, self.action),
         'create_at': util.datetime2timestamp(self.create_at)
     }
     return data
Example #5
0
def gifts_anchor():
    """
    主播兑换信息

    :uri: /gifts/anchor
    :return: {}
    """
    user = request.authed_user
    cfg = GiftExchangeCfg.get_gift_config()

    break_rate = cfg.break_rate  # 折损率
    _gift_value = UserProduct.get_total_money(user)  # 当前用户礼物价值

    gift_value = float(_gift_value) / 100

    _value = gift_value * float(break_rate)
    exchange_value = int(_value) + 1 if _value > int(_value) else int(
        _value)  # 折损后的价值

    is_anchor_wlist = AnchorWlist.is_anchor_wlist(user._id)  # 是否是签约主播
    is_exchange_time = GiftExchangeCfg.is_exchange_time()  # 是否在兑换时间内

    if cfg.exchange_begin and cfg.exchange_end:
        begin = time.strftime(
            "%Y-%m-%d %H:%M:%S",
            time.localtime(util.datetime2timestamp(cfg.exchange_begin)))
        end = time.strftime(
            "%Y-%m-%d %H:%M:%S",
            time.localtime(util.datetime2timestamp(cfg.exchange_end)))
        exchange_word = '本月仅在{0} - {1}日可兑换'.format(begin[8:10], end[8:10])

    else:
        exchange_word = '本月不可兑换'

    return {
        'gifts_config': cfg.format(),
        'gift_value': gift_value,
        'is_anchor_wlist': is_anchor_wlist,
        'is_exchange_time': is_exchange_time,
        'exchange_value': exchange_value,
        'exchange_word': exchange_word,
    }
Example #6
0
    def format(self):

        data = {
            'exchange_thresthold':
            self.exchange_thresthold,
            'break_rate':
            self.break_rate,
            'exchange_begin':
            util.datetime2timestamp(self.exchange_begin)
            if self.exchange_begin else None,
            'exchange_end':
            util.datetime2timestamp(self.exchange_end)
            if self.exchange_end else None,
            'total_exchange_value':
            self.total_exchange_value,
            'exchange_status':
            self.exchange_status,
        }

        return data
Example #7
0
 def format(self):
     product = Product.get_product(self.product_id)
     data = {
         'from_user':
         User.get_one(
             self.from_user).format(exclude_fields=['is_followed']),
         'product':
         product and product.format(),
         'num':
         self.num,
         'create_at':
         util.datetime2timestamp(self.create_at)
     }
     return data
Example #8
0
    def _load_video_gifts(cls, video_id):
        gifts = list(cls.select().where(
            UserGiftLog.gift_from == const.FROM_RECORD,
            UserGiftLog.from_id == video_id,
            UserGiftLog.send_success == 1,
        ))
        ret = list()
        for gift in gifts:
            ret.extend([
                util.datetime2timestamp(gift.create_at),
                cjson.dumps(gift, 2)
            ])

        return tuple(ret)
Example #9
0
 def format_log(self):
     product = Product.get_product(self.product_id)
     uid = self.user_id if 'user_id' in self.__dict__[
         '_data'] else self.from_user
     user = User.get_one(uid)
     data = {
         'user': user and user.format(exclude_fields=['is_followed']),
         'product': product and product.format(),
         'num': self.daily_sum,
         'credit_type': self.credit_type,
         'credit_value': self.credit_value,
         'send_success': self.send_success,
         'create_at': util.datetime2timestamp(self.create_at)
     }
     return data
Example #10
0
 def format(self):
     product = Product.get_product(self.product_id)
     result = json.loads(self.result) if self.result else None
     rid = result['id'] if result and 'id' in result else None
     code = result['giftCode'] if result and 'giftCode' in result else None
     name = result['name'] if result and 'name' in result else None
     data = {
         'order_id': self.order_id,
         'title': self.title,
         'product': product and product.format(),
         'status': self.status,
         'create_at': util.datetime2timestamp(self.create_at),
         'result': {
             'code': code,
             'name': name,
             'rid': rid
         }
     }
     return data
Example #11
0
    def format(self):
        _share_uri = '/page/html/sharelottery.html?store_id=%s' % (
            self.store_id)
        share_url = urljoin(app.config.get('SHARE_URL'), _share_uri)
        share_image = ''
        if self.share_image:
            share_image = urljoin(app.config.get("MEDIA_URL"),
                                  self.share_image)

        data = {
            'store_id': self.store_id,
            'title': self.title,
            'credit_type': self.credit_type,
            'credit_value': self.credit_value,
            'status': self.status,
            'action': self.action,
            'share_url': share_url,
            'share_image': share_image,
            'share_title': self.share_title,
            'expire_at': util.datetime2timestamp(self.expire_at)
        }
        return data