Пример #1
0
def add_user_integral(user_id, source, integral, redis_key=None, extra=None):
    db = DbManager().db
    create_time = datetime.now()
    date = create_time.date()
    try:
        db.execute('begin;')
        sql = 'update {table} set integral=integral+%s where user_id=%s'.format(table=UserIntegral.table)
        db.execute(sql, integral, user_id)
        sql = 'select integral from {table} where user_id=%s'.format(table=UserIntegral.table)
        amount = db.get(sql, user_id).get('integral')
        sql = 'insert into {table} (user_id, source, amount, integral, date, create_time, extra) values ' \
        '(%s, %s, %s, %s, %s, %s)'.format(table=UserIntegralRecord.table)
        db.execute(sql, user_id, source, amount, integral, date, create_time, extra)
        db.execute('commit;')
        if redis_key:
            cache.set(redis_key, 1)
    except:
        db.execute('rollback;')
        raise

    level = handle_integral_level_point(integral)
    if level:
        if level == 3:
            text = u'恭喜您有%s积分,升级至LV3啦,赶紧去创建房间和聊天组吧!' % integral
            Notify.add(user_id, user_id, NOTIFY_ACTION_LEVEL_UP_THREE, None, extra_info=text)
        else:
            text = u'恭喜您有%s积分,升级至LV%s啦,查看积分攻略更快升级!' % (integral, level)
            Notify.add(user_id, user_id, NOTIFY_ACTION_LEVEL_UP, None, extra_info=text)
Пример #2
0
def welfare_robed_notify(user, welfare):
    text = u'呼啦啦,恭喜神枪手,已顺利抢到福利!小事儿会在抢福利结束后1-3个工作日确认福利订单!'
    Notify.add(welfare.creator_id,
               user.id,
               NOTIFY_ACTION_WELFARE_ROBED,
               welfare.id,
               extra_info=text)
Пример #3
0
def notify_content_like(user, content):
    user_name = user.name
    if not isinstance(user_name, unicode):
        user_name = user_name.decode('utf-8')

    text = u'%s对你的内容进行了点赞' % user_name
    Notify.add(user.id, content.creator_id, NOTIFY_ACTION_CONTENT_LIKED, content.id, NOTIFY_TYPE_LIKED, extra_info=text)
    push_client.notify_content_like(content)
Пример #4
0
def notify_content_reward(user, content, reward_order):
    user_name = user.name
    if not isinstance(user_name, unicode):
        user_name = user_name.decode('utf-8')

    text = u'哇,%s给你打赏了:¥%s' % (user_name, float(reward_order.amount))
    Notify.add(user.id, content.creator_id, NOTIFY_ACTION_CONTENT_REWARD, content.id, NOTIFY_TYPE_REWARD, reward_order.id, text)
    push_client.notify_reward(content)
Пример #5
0
def notify_change_password(user_id, change_time):
    change_time = '%s日%s时%s分' % (change_time.date().strftime('%Y-%m-%d'),
                                 change_time.hour, change_time.minute)
    text = u'您于%s修改了登陆密码,如是本人修改无须理会。' % change_time
    Notify.add(user_id,
               user_id,
               NOTIFY_ACTION_CHANGE_PASSWORD,
               None,
               extra_info=text)
Пример #6
0
def notify_change_payment_code(user_id, change_time):
    change_time = '%s日%s时%s分' % (change_time.date().strftime('%Y-%m-%d'),
                                 change_time.hour, change_time.minute)
    text = u'您于%s修改了支付密码,如是本人修改无须理会。' % change_time
    Notify.add(user_id,
               user_id,
               NOTIFY_ACTION_CHANGE_PAYMENT_CODE,
               None,
               extra_info=text)
Пример #7
0
def room_silent_user_notify(operator, operator_status, room, silent_user):
    operator_name = operator.name
    if not isinstance(operator_name, unicode):
        operator_name = operator_name.decode('utf-8')

    if operator_status == ROOM_USER_CREATOR:
        text = u'对不起,您已经被房主%s操作禁言,禁言24H后方可发布内容。' % operator_name
    else:
        text = u'对不起,您已经被房管%s操作禁言,禁言24H后方可发布内容。' % operator_name

    Notify.add(operator.id, silent_user.id, NOTIFY_ACTION_ROOM_SILENT, room.id, extra_info=text)
Пример #8
0
def notify_comment_reply(user, receiver, content, comment):
    user_name = user.name
    if not isinstance(user_name, unicode):
        user_name = user_name.decode('utf-8')

    comment_text = comment.text
    if not isinstance(comment_text, unicode):
        comment_text = comment_text.decode('utf-8')

    text = u'%s回复了你:%s' % (user_name, comment_text)
    Notify.add(user.id, receiver.id, NOTIFY_ACTION_COMMENT_REPLY, content.id, NOTIFY_TYPE_COMMENT, comment.id, text)
    push_client.notify_comment(receiver, content)
Пример #9
0
def notify_be_followed(user_id, follow_id):
    user = User.get(user_id)
    user_name = user.name
    if not isinstance(user_name, unicode):
        user_name = user_name.decode('utf-8')

    text = u'%s关注了您' % user_name
    Notify.add(user_id,
               follow_id,
               NOTIFY_ACTION_BE_FOLLOWED,
               None,
               extra_info=text)
Пример #10
0
def notify_content_comment(user, content, comment):
    user_name = user.name
    comment_text = comment.text
    if not isinstance(user_name, unicode):
        user_name = user_name.decode('utf-8')

    if not isinstance(comment_text, unicode):
        comment_text = comment_text.decode('utf-8')

    text = u'%s评论了你:%s' % (user_name, comment_text)
    Notify.add(user.id, content.creator_id, NOTIFY_ACTION_CONTENT_COMMENT, content.id, NOTIFY_TYPE_COMMENT, comment.id, text)
    push_client.notify_comment(content.creator, content)
Пример #11
0
    def get(self):
        user_id = self.get_argument('user_id')
        user = User.get(user_id)
        if not user:
            return self.error(USER_NOT_FOUND)

        system_latest_notify = Notify.get_user_latest_notify_by_type(user_id, NOTIFY_TYPE_SYSTEM)
        liked_latest_notify = Notify.get_user_latest_notify_by_type(user_id, NOTIFY_TYPE_LIKED)
        comment_latest_notify = Notify.get_user_latest_notify_by_type(user_id, NOTIFY_TYPE_COMMENT)
        reward_latest_notify = Notify.get_user_latest_notify_by_type(user_id, NOTIFY_TYPE_REWARD)

        return self.render({
            'status': 0,
            'data': {
                'user_id': user_id,
                'notify': {
                    NOTIFY_TYPE_SYSTEM: {
                        'count': Notify.get_user_unread_notify_count_by_type(user_id, NOTIFY_TYPE_SYSTEM),
                        'latest_notify': system_latest_notify.jsonify() if system_latest_notify else None,
                    },
                    NOTIFY_TYPE_LIKED: {
                        'count': Notify.get_user_unread_notify_count_by_type(user_id, NOTIFY_TYPE_LIKED),
                        'latest_notify': liked_latest_notify.jsonify() if liked_latest_notify else None,
                    },
                    NOTIFY_TYPE_COMMENT: {
                        'count': Notify.get_user_unread_notify_count_by_type(user_id, NOTIFY_TYPE_COMMENT),
                        'latest_notify': comment_latest_notify.jsonify() if comment_latest_notify else None,
                    },
                    NOTIFY_TYPE_REWARD: {
                        'count': Notify.get_user_unread_notify_count_by_type(user_id, NOTIFY_TYPE_REWARD),
                        'latest_notify': reward_latest_notify.jsonify() if reward_latest_notify else None,
                    }
                },
            }
        })
Пример #12
0
def welfare_confirm_notify(welfare, user):
    welfare_name = welfare.name
    if not isinstance(welfare_name, unicode):
        welfare_name = welfare_name.decode('utf-8')

    if len(welfare_name) > 10:
        welfare_name = welfare_name[:10] + u'……'

    text = u'"%s"已收货完成,小事儿祝您下次继续抢到单哦。' % welfare_name
    Notify.add(welfare.creator_id,
               user.id,
               NOTIFY_ACTION_WELFARE_CONFIRMED,
               welfare.id,
               extra_info=text)
Пример #13
0
def room_remove_user_notify(operator, operator_status, room, remove_user):
    room_name = room.name
    operator_name = operator.name
    if not isinstance(room_name, unicode):
        room_name = room_name.decode('utf-8')

    if not isinstance(operator_name, unicode):
        operator_name = operator_name.decode('utf-8')

    if operator_status == ROOM_USER_CREATOR:
        text = u'对不起,您已经被房主%s移除出房间%s,不能再加入该房间了。' % (operator_name, room_name)
    else:
        text = u'对不起,您已经被房管%s移除出房间%s,不能再加入该房间了。' % (operator_name, room_name)

    Notify.add(operator.id, remove_user.id, NOTIFY_ACTION_ROOM_REMOVED, room.id, extra_info=text)
Пример #14
0
def welfare_end_notify(welfare):
    welfare.welfare_robed_end()
    robed_users = WelfareOrder.get_robed_users_by_welfare(welfare.id)
    welfare_name = welfare.name
    if not isinstance(welfare_name, unicode):
        welfare_name = welfare_name.decode('utf-8')

    if len(welfare_name) > 10:
        welfare_name = welfare_name[:10] + u'……'

    text = u'"%s"抢福利已结束,小事儿在吭哧吭哧确认订单中!' % welfare_name
    for user in robed_users:
        Notify.add(welfare.creator_id,
                   user.id,
                   NOTIFY_ACTION_WELFARE_END,
                   welfare.id,
                   extra_info=text)
Пример #15
0
def welfare_ordered_notify(welfare,
                           welfare_order,
                           platform=None,
                           order_num=None):
    # welfare_orders = WelfareOrder.gets_by_welfare(welfare.id)
    # robed_users = WelfareOrder.get_robed_users_by_welfare(welfare.id)
    welfare_name = welfare.name
    if len(welfare_name) > 10:
        welfare_name = welfare_name[:10] + u'……'

    if not isinstance(welfare_name, unicode):
        welfare_name = welfare_name.decode('utf-8')

    text = u'"%s"已经下单啦' % (welfare_name)
    Notify.add(welfare.creator_id,
               welfare_order.user_id,
               NOTIFY_ACTION_WELFARE_ORDERED,
               welfare.id,
               extra_info=text)
Пример #16
0
def welfare_created_notify(room, welfare):
    user_ids = RoomUser.get_user_ids_by_room(room.id)
    welfare_name = welfare.name
    if not isinstance(welfare_name, unicode):
        welfare_name = welfare_name.decode('utf-8')

    if len(welfare_name) > 10:
        welfare_name = welfare_name[:10] + u'……'

    room_name = room.name
    if not isinstance(room_name, unicode):
        room_name = room_name.decode('utf-8')

    text = u'%s房间发福利啦:"%s"' % (room_name, welfare_name)
    for user_id in user_ids:
        Notify.add(welfare.creator_id,
                   user_id,
                   NOTIFY_ACTION_WELFARE_CREATED,
                   welfare.id,
                   extra_info=text)
Пример #17
0
    def get(self):
        user_id = self.get_argument('user_id')
        notify_type = self.get_argument('notify_type', NOTIFY_TYPE_SYSTEM)
        start = int(self.get_argument('start', 0))
        count = int(self.get_argument('count', 10))
        user = User.get(user_id)
        if not user:
            return self.error(USER_NOT_FOUND)

        notifies = Notify.get_notifies_by_type(user_id, notify_type, start, count)
        return self.render({
            'status': 0,
            'data': [notify.jsonify() for notify in notifies if notify],
        })
Пример #18
0
def chat_user_reward(receiver, helper, group_id, message_id, liked_count):
    if not GroupReward.has_get_reward(group_id, message_id, liked_count):
        rewards = [CHAT_RED_ENVELOPE, CHAT_MELON_SEEDS]
        probability = [0.1, 0.9]
        reward = random_pick(rewards, probability)
        GroupReward.add(receiver.id, group_id, message_id, liked_count, reward)
        if UserChatStatus.is_flower_identity(receiver.id):
            receiver_name = FlowerUser.get_by_user(receiver.id).name
        else:
            receiver_name = receiver.user_name
        if not isinstance(receiver_name, unicode):
            receiver_name = receiver_name.decode('utf-8')

        if UserChatStatus.is_flower_identity(helper.id):
            helper_name = FlowerUser.get_by_user(helper.id).name
        else:
            helper_name = helper.user_name
        if not isinstance(helper_name, unicode):
            helper_name = helper_name.decode('utf-8')

        if reward == CHAT_RED_ENVELOPE:
            amount = random.randint(1, 10) / 100.0
            envelope = GroupEnvelope.add(receiver.id, group_id, message_id, liked_count, amount)
            reward_id = envelope.id
            if int(helper.id) == int(receiver.id):
                Notify.add(helper.id, receiver.id, NOTIFY_ACTION_CHAT_ENVELOPE_REWARD, envelope.id, extra_info=u'呦!您集齐%s个赞召唤出1个红包' % liked_count)
            else:
                Notify.add(helper.id, receiver.id, NOTIFY_ACTION_CHAT_ENVELOPE_REWARD, envelope.id, extra_info=u'呦!您集齐%s个赞召唤出1个红包' % liked_count)
                Notify.add(receiver.id, helper.id, NOTIFY_ACTION_CHAT_ENVELOPE_AST, envelope.id, extra_info=u'牛!助攻成功,您帮%s集齐%s个赞召唤出了1个红包' % (receiver_name, liked_count))
        else:
            amount = 1
            seeds = GroupSeeds.add(receiver.id, group_id, message_id, liked_count, amount)
            reward_id = seeds.id
            if int(helper.id) == int(receiver.id):
                Notify.add(helper.id, receiver.id, NOTIFY_ACTION_CHAT_SEEDS_REWARD, seeds.id, extra_info=u'呦!您集齐了%s个赞召唤出了1枚炒瓜子' % liked_count)
            else:
                Notify.add(helper.id, receiver.id, NOTIFY_ACTION_CHAT_SEEDS_REWARD, seeds.id, extra_info=u'呦!您集齐了%s个赞召唤出了1枚炒瓜子' % liked_count)
                Notify.add(receiver.id, helper.id, NOTIFY_ACTION_CHAT_SEEDS_AST, seeds.id, extra_info=u'牛!助攻成功!您帮%s集齐%s个赞召唤除了八卦必备神器“一枚炒瓜子”' % (receiver_name, liked_count))

        receiver_obj = {
            'id': receiver.id,
            'name': receiver_name,
        }
        helper_obj = {
            'id': helper.id,
            'name': helper_name,
        }
        push_client.notify_chat_reward(receiver_obj, helper_obj, reward, reward_id, amount, liked_count)
Пример #19
0
# coding: utf-8

from starmachine.model.user import User
from starmachine.model.notify import Notify
from starmachine.model.consts import NOTIFY_UNREAD, NOTIFY_READ, NOTIFY_ACTION_CONTENT_COMMENT, \
    NOTIFY_ACTION_CONTENT_REWARD, NOTIFY_ACTION_CONTENT_LIKED, NOTIFY_ACTION_COMMENT_REPLY, NOTIFY_TYPE_COMMENT, \
    NOTIFY_TYPE_REWARD, NOTIFY_TYPE_SYSTEM, NOTIFY_TYPE_LIKED

notifies = Notify.gets_all()
for notify in notifies:
    notify_action = int(notify.action)
    if notify_action == NOTIFY_ACTION_CONTENT_LIKED:
        user = User.get(notify.sender_id)
        user_name = user.name
        if not isinstance(user_name, unicode):
            user_name = user_name.decode('utf-8')

        text = u'%s对你的内容进行了点赞' % user_name
        notify.update(extra_info=text, notify_type=NOTIFY_TYPE_LIKED)
    elif notify_action == NOTIFY_ACTION_CONTENT_REWARD:
        user = User.get(notify.sender_id)
        amount = float(notify.extra_info)
        user_name = user.name
        if not isinstance(user_name, unicode):
            user_name = user_name.decode('utf-8')

        text = u'哇,%s给你打赏了:¥%s' % (user_name, amount)
        notify.update(extra_info=text, notify_type=NOTIFY_TYPE_REWARD)
    elif notify_action == NOTIFY_ACTION_CONTENT_COMMENT:
        user = User.get(notify.sender_id)
        user_name = user.name