Exemple #1
0
    def post(self):
        try:
            user_id = self.get_argument('user_id')
            name = self.get_argument('name')
        except MissingArgumentError:
            return self.error(MISSING_PARAMS)

        if FlowerUser.exists_name(name):
            return self.error(FLOWER_USER_NAME_EXISTS)

        if get_str_length(name) < 2:
            return self.error(FLOWER_NAME_LESS_MINIMUM_LIMIT)

        if get_str_length(name) > 20:
            return self.error(FLOWER_NAME_OVER_MAXIMUM_LIMIT)

        group_user_info = FlowerUser.get_by_user(user_id)
        if not group_user_info:
            try:
                random_name = random.choice(FLOWER_AVATAR_ARR)
                avatar_uri = 'static/avatar/flower/image_huaming_%[email protected]' % random_name
                group_user_info = FlowerUser.add(user_id, name, avatar_uri)
            except Exception as e:
                logger.error(u'添加用户花名成功。Error:[%s]' % e)
                return self.error(SYSTEM_ERROR)
        else:
            try:
                cache = CacheManager().cache
                redis_key = flower_user_name_update_limit_key % user_id
                if cache.exists(redis_key):
                    update_count = cache.get(redis_key)
                    if int(update_count) >= 3:
                        return self.error(FLOWER_USER_NAME_UPDATE_OVER_LIMIT)
                    else:
                        group_user_info.update_name(name)
                        cache.incr(redis_key, 1)
                else:
                    group_user_info.update_name(name)
                    cache.set(redis_key, 1)
                    cache.expire(redis_key, flower_user_name_update_limit_time)
            except Exception as e:
                logger.error(u'更新用户花名失败。Error:[%s]', e)
                return self.error(SYSTEM_ERROR)

        if UserChatStatus.is_flower_identity(user_id):
            rong_client.user_refresh(user_id, name=name)

        return self.render({
            'status': 0,
            'data': {
                'left_change_times': group_user_info.left_change_times(),
            }
        })
Exemple #2
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)
Exemple #3
0
    def post(self):
        user_id = self.get_argument('user_id')
        chat_status = int(self.get_argument('chat_status'))
        obj = UserChatStatus.get_by_user(user_id)
        flower_user = FlowerUser.get_by_user(user_id)
        user = User.get(user_id)
        if not obj:
            if not flower_user and chat_status == CHAT_FLOWER_IDENTITY:
                return self.error(FLOWER_USER_INFO_NOT_SET)

            UserChatStatus.add(user_id, chat_status)
        else:
            if not flower_user and chat_status == CHAT_FLOWER_IDENTITY:
                return self.error(FLOWER_USER_INFO_NOT_SET)

            obj.update(chat_status)

        if chat_status == CHAT_FLOWER_IDENTITY:
            rong_client.user_refresh(user_id, flower_user.name, flower_user.avatar_url)
            flower_identity = True
        else:
            rong_client.user_refresh(user_id, user.user_name, user.avatar_url)
            flower_identity = False

        return self.render({
            'status': 0,
            'data': {
                'flower_identity': flower_identity,
            }
        })
Exemple #4
0
    def post(self):
        try:
            user_id = self.get_argument('user_id')
            avatar = self.get_argument('avatar')
        except MissingArgumentError:
            return self.error(MISSING_PARAMS)

        group_user_info = FlowerUser.get_by_user(user_id)
        if not group_user_info:
            return self.error(FLOWER_USER_INFO_NOT_SET)

        try:
            group_user_info.update(avatar=avatar)
        except Exception as e:
            logger.error(u'更新群组用户头像信息失败。Error:[%s]' % e)
            return self.error(SYSTEM_ERROR)

        if UserChatStatus.is_flower_identity(user_id):
            rong_client.user_refresh(user_id, portrait_uri=init_pic_url(avatar))

        return self.render({
            'status': 0,
            'data': {
                'portraitUri': init_pic_url(avatar),
            }
        })
Exemple #5
0
    def get(self):
        user_id = self.get_argument('user_id')
        group_user_info = FlowerUser.get_by_user(user_id)
        if not group_user_info:
            return self.error(FLOWER_USER_INFO_NOT_SET)

        return self.render({
            'status': 0,
            'data': group_user_info.jsonify() if group_user_info else {},
        })
Exemple #6
0
    def get(self, group_id):
        share_timestamp = self.get_argument('share_time', '')
        group = Group.get(group_id)
        if not group:
            return self.render('group/404.html')

        if share_timestamp:
            delta = int(time.time()) - int(share_timestamp)
            if delta > 24 * 60 * 60:
                return self.render('group/404.html')

        hot_messages = GroupMessage.get_hot_messages(group_id, 20)
        messages = []
        for message in hot_messages:
            content = json.loads(message.content)
            creator_id = message.creator_id
            flower_identity = UserChatStatus.is_flower_identity(creator_id)
            if flower_identity:
                flower_user = FlowerUser.get_by_user(creator_id)
                user_name = flower_user.user_name
                avatar = flower_user.avatar_url
            else:
                user = User.get(creator_id)
                user_name = user.user_name
                avatar = user.avatar_url

            if not avatar:
                avatar = 'http://pic.star428.com/group/img/portrait.png'
            if not user_name:
                user_name = u'冰冰女生'
            create_time = message.create_time.strftime('%H:%M')
            liked_amount = int(message.liked_amount)
            messages.append({
                "avatar": avatar,
                "user_name": user_name,
                'create_time': create_time,
                'liked_amount': liked_amount,
                'content': content,
                'object_name': message.object_name,
            })

        data = {
            'messages': messages,
            'group': group,
        }
        return self.render('group/hot_message.html', **data)
Exemple #7
0
    def get(self):
        group_id = self.get_argument('group_id')
        start = int(self.get_argument('start', 0))
        count = int(self.get_argument('count', 10))

        group_user_ids = GroupUser.get_users_by_group(group_id, start, count)
        group_users = []
        for group_user_id in group_user_ids:
            if UserChatStatus.is_flower_identity(group_user_id):
                group_user = FlowerUser.get_by_user(group_user_id)
            else:
                group_user = User.get(group_user_id)

            group_users.append({
                'userId': group_user_id,
                'name': group_user.user_name,
                'portraitUri': group_user.avatar_url,
            })

        return self.render({
            'status': 0,
            'data': group_users,
        })
Exemple #8
0
    def jsonify(self):
        from starmachine.model.user_validate import UserValidate
        address_list = UserAddress.gets_by_user(self.id)
        user_validate = UserValidate.get_by_user_id(self.id)
        user_payment_code = UserPaymentCode.get_by_user(self.id)
        account = self.account
        balance = account.balance
        flower_user = FlowerUser.get_by_user(self.id)
        data = {
            'id': self.id,
            'telephone': self.telephone,
            'name': self.user_name,
            'role': self.role,
            'avatar': self.avatar_url,
            'intro': self.intro,
            'city': self.city.jsonify(),
            'status': self.status,
            'join_rooms_count': self.joined_rooms_count,
            'created_rooms': self.created_rooms,
            'address_list': [address.jsonify() for address in address_list],
            'tags': [tag.jsonify() for tag in self.tags if tag],
            'balance': float(balance) if balance else 0,
            'validate_status': user_validate.status if user_validate else '',
            'has_payment_code': True if user_payment_code else False,
            'receive_reward_amount': self.receive_reward_amount,
            'fans_amount': self.fans_amount,
            'follow_amount': self.follow_amount,
            'flower_user_info': flower_user.jsonify() if flower_user else None,
        }
        if flower_user:
            flower_identity = UserChatStatus.is_flower_identity(self.id)
        else:
            flower_identity = False

        data.update({'flower_identity': flower_identity})

        return data