Beispiel #1
0
async def invite_by(qq_id, invite_by):
    """
    更新用户的邀请者
    :param qq_id:
    :param invite_by:
    :return:
    """
    session = DBSession()
    user_invite = session.query(User_invite).filter(
        User_invite.qq_id == qq_id).first()
    if not user_invite:
        session.close()
        await init_user_invite(qq_id=qq_id,
                               nickname=await get_qq_user_info(qq_id))
        invite_by(qq_id, invite_by)
    else:
        if not user_invite.invite_by:
            user_invite.invite_by = invite_by
        else:
            raise RuntimeError
        session.merge(user_invite)
        session.commit()
        # 判断是否邀请到足够人数
        invite_user_num = session.query(User_invite).filter(
            User_invite.invite_by == invite_by).count()
        if invite_user_num == 3:
            await invite.get_sell_card(invite_by)

        session.close()
        return True
Beispiel #2
0
async def add_group_info(group_id,
                         group_name,
                         last_weather_notify=None,
                         is_morningcall_on=False,
                         is_curriculumschedule_on=True,
                         is_weather_notify_on=False,
                         is_homework_daily_on=False):
    session = DBSession()
    group = session.query(GroupInfo).filter(
        GroupInfo.group_id == group_id).first()
    if group:
        group.group_id = group_id
        group.group_name = group_name
        session.merge(group)
        session.commit()
        session.close()
        return 1
    else:
        group = GroupInfo(group_id=group_id,
                          group_name=group_name,
                          last_weather_notify=last_weather_notify,
                          is_morningcall_on=is_morningcall_on,
                          is_curriculumschedule_on=is_curriculumschedule_on,
                          is_weather_notify_on=is_weather_notify_on,
                          is_homework_daily_on=is_homework_daily_on)
        session.add(group)
        session.commit()
        session.close()
        return 0
Beispiel #3
0
async def add_QQUser(qq_id,
                     nickname,
                     group_id=None,
                     group_card=None,
                     sex=None,
                     group_role=None,
                     **kw):
    session = DBSession()
    qqUser = session.query(QQUser).filter(QQUser.qq_id == qq_id).first()
    if qqUser:
        qqUser.nickname = nickname
        if (group_id):
            qqUser.group_id = group_id
        qqUser.group_role = group_role
        qqUser.sex = sex
        session.merge(qqUser)
        session.commit()
        session.close()
        return 1
    else:
        qqUser = QQUser(qq_id=qq_id,
                        group_id=group_id,
                        nickname=nickname,
                        group_card=group_card,
                        sex=sex,
                        group_role=group_role,
                        join_time=datetime.now())
        session.add(qqUser)
        session.commit()
        session.close()
        return 0
Beispiel #4
0
async def del_item(id):
    session = DBSession()
    item = session.query(SellItem).filter(SellItem.id == id).first()
    item.is_onsell = not item.is_onsell
    session.merge(item)
    session.commit()
    session.close()
Beispiel #5
0
async def make_cp(user1, user2):
    session = DBSession()
    user1.is_paired = True
    user1.paired_to = user2.id
    user2.is_paired = True
    user2.paired_to = user1.id
    session.merge(user1)
    session.merge(user2)
    session.commit()
    session.close()
Beispiel #6
0
async def update_last_weather_notify(group_id, last_weather_notify):
    session = DBSession()
    try:
        group = session.query(GroupInfo).filter(
            GroupInfo.group_id == group_id).first()
        group.last_weather_notify = last_weather_notify
        session.merge(group)
        session.commit()
    except Exception:
        session.rollback()
    session.close()
Beispiel #7
0
async def update_item(id, item_name=None, item_info=None):
    session = DBSession()
    item = session.query(SellItem).filter(SellItem.id == id).first()
    if item_name:
        item.item_name = item_name
    if item_info:
        item.item_info = item_info
    item.add_time = datetime.now()
    session.merge(item)
    session.commit()
    session.close()
Beispiel #8
0
async def get_do_you_know():

    session = DBSession()
    dyn = session.query(DoYouKnow).order_by(func.rand()).first()
    dyn.times += 1
    try:
        session.merge(dyn)
    except Exception:
        session.rollback()
    session.close()
    result = {}
    result['text'] = dyn.text
    result['info'] = dyn.times
    return result