Exemplo n.º 1
0
    async def res(page: Dict[str, int] = Depends(paging_query_depend),
                  current_user: User = Depends(
                      create_current_active_user(need_user))):
        if str(default_query):
            query = default_query.offset(
                (page['page_number'] - 1) * page['page_size']).limit(
                    page['page_size'])  # 第一页,每页20条数据。 默认第一页。
        else:
            query = model.__table__.select().offset(
                (page['page_number'] - 1) * page['page_size']).limit(
                    page['page_size'])  # 第一页,每页20条数据。 默认第一页。
        # if filter:
        #     query.where(           and_(           [ for i in ]    users.c.id == addresses.c.user_id,
        #        users.c.name.between('m', 'z'),
        #        or_(
        #           addresses.c.email_address.like('*****@*****.**'),
        #           addresses.c.email_address.like('*****@*****.**')
        #        )
        #    )
        # )

        paginate_obj = await AdminDatabase().database.fetch_all(query)
        for i in paginate_obj:
            print(i)
        query2 = select([func.count(model.__table__.c.id)])
        total_page = await AdminDatabase().database.fetch_val(query2)
        res_obj = {
            "page_count": int(math.ceil(total_page * 1.0 / page['page_size'])),
            "rows_total": total_page,
            "page_number": page['page_number'],
            "page_size": page['page_size'],
            "data": paginate_obj
        }
        print(res_obj)
        return res_obj
Exemplo n.º 2
0
 async def res(post_dict: schema,
               current_user: User = Depends(
                   create_current_active_user(need_user))):
     res_dict = dict(post_dict)
     query = model.__table__.insert().values(res_dict)
     res_dict.update({"id": await AdminDatabase().database.execute(query)})
     return res_dict
Exemplo n.º 3
0
async def user_retrieve(id,
                        current_user: User = Depends(
                            create_current_active_user(True))):
    """获取用户的详细信息"""
    query = select([
        User, AccountBook.money, AccountBook.rate
    ]).where(User.id == id).where(AccountBook.user_id == User.id)
    print(query)
    return await AdminDatabase().database.fetch_one(query)
Exemplo n.º 4
0
 async def res(id,
               update_dict: schema,
               current_user: User = Depends(
                   create_current_active_user(need_user))):
     query = model.__table__.update().values(
         dict(update_dict)).where(model.id == id)
     print(query)
     await AdminDatabase().database.execute(query)
     return update_dict
Exemplo n.º 5
0
async def modify_base_info(new_info: ModifyBaseInfo,
                           current_user: User = Depends(
                               create_current_active_user(True))):
    """
    修改基础信息
    :param current_user:
    :return:
    """
    query = User.__table__.update().values(
        dict(new_info)).where(User.id == new_info.id)
    await AdminDatabase().database.execute(query)
    return new_info
Exemplo n.º 6
0
async def delete_account(user_id: DeleteAccount,
                         current_user: User = Depends(
                             create_current_active_user(True))):
    """
    禁用账户
    :param current_user:
    :return:
    """
    query = User.__table__.update().values({
        "is_delete": True
    }).where(User.id == user_id.id)
    await AdminDatabase().database.execute(query)
    return user_id
Exemplo n.º 7
0
async def modify_password(new_password: ModifyPassword,
                          current_user: User = Depends(
                              create_current_active_user(True))):
    """
    修改密码
    :param current_user:
    :return:
    """
    hash_password = get_password_hash(new_password.new_password)
    query = User.__table__.update().values({
        "password": hash_password
    }).where(User.id == new_password.id)
    res = await AdminDatabase().database.execute(query)
    return {"code": 200, "message": "success"}
Exemplo n.º 8
0
 async def create(instance: RegisterUser = Body(..., ),
                  current_user: User = Depends(
                      create_current_active_user(True))):
     print("instance:", instance)
     if not instance.guid:
         instance.guid = "1" + createGuid(4)
     instance.password = get_password_hash(instance.password)
     query = model.__table__.insert().values(dict(instance))
     try:
         instance.id = await database.execute(query)
         return instance
     except Exception as e:
         print("注意根据不同数据库返回不同异常")
         raise HTTPException(status_code=400, detail=str(e))
Exemplo n.º 9
0
async def order_list(platform: str = Query(None, description="平台订单号"),
                     tenant: str = Query(None, description="商户订单号"),
                     official: str = Query(None, description="官方订单号"),
                     channel_id: str = Query(None, description="通道id"),
                     goods_name: str = Query(None, description="商品名称"),
                     transaction_type: TransactionType = Query(None, description="支付方式"),
                     start_create_time: datetime = Query(None, description="开始时间"),
                     end_create_time: datetime = Query(None, description="截止时间"),
                     status: OrderStatusEnum = Query(None, description="订单状态"),
                     page: Dict[str, int] = Depends(paging_query_depend),
                     current_user: User = Depends(create_current_active_user(True))):
    table = Order.__table__
    query = Order.__table__.select()
    if platform != None:  # 平台订单号
        query = query.where(table.c.platform_id.like('%' + platform + '%'))
    elif tenant != None:
        query = query.where(table.c.bussiness_order_id.like('%' + tenant + '%'))
    elif official != None:
        query = query.where(table.c.offical_order_id.like('%' + official + '%'))
    else:
        if channel_id:
            query = query.where(table.c.channel_id.like('%' + channel_id + '%'))
        if goods_name:
            query = query.where(table.c.goods_name.like('%' + goods_name + '%'))
        if transaction_type:
            query = query.where(table.c.transaction_type == transaction_type)
        if status:
            query = query.where(table.c.status == status)
        if start_create_time:
            query = query.where(table.c.create_time >= start_create_time)
        if end_create_time:
            query = query.where(table.c.create_time <= end_create_time)
        query = query.offset((page['page_number'] - 1) * page['page_size']).limit(
            page['page_size'])  # 第一页,每页20条数据。 默认第一页。

    paginate_obj = await AdminDatabase().database.fetch_all(query)
    query2 = select([func.count(table.c.id)])
    total_page = await AdminDatabase().database.fetch_val(query2)
    res_obj = {
        "page_count": int(math.ceil(total_page * 1.0 / page['page_size'])),
        "rows_total": total_page,
        "page_number": page['page_number'],
        "page_size": page['page_size'],
        "data": paginate_obj
    }
    return res_obj
Exemplo n.º 10
0
 async def res(page: Dict[str, int] = Depends(paging_query_depend),
               current_user: User = Depends(
                   create_current_active_user(need_login))):
     if str(select_query) != 'None':
         query = select_query.offset(
             (page['page_number'] - 1) * page['page_size']).limit(
                 page['page_size'])  # 第一页,每页20条数据。 默认第一页。
     else:
         assert not isinstance(model, list), "model为列表时必须自定义query"
         query = select([model]).offset(
             (page['page_number'] - 1) * page['page_size']).limit(
                 page['page_size'])  # 第一页,每页20条数据。 默认第一页。
     paginate_obj = await AdminDatabase().database.fetch_all(query)
     query2 = select([func.count(model.__table__.c.id)])
     total_page = await AdminDatabase().database.fetch_val(query2)
     return {
         "page_count": int(math.ceil(total_page * 1.0 / page['page_size'])),
         "rows_total": total_page,
         "page_number": page['page_number'],
         "page_size": page['page_size'],
         "data": paginate_obj
     }
Exemplo n.º 11
0
async def order_post(order_info: OrderPostSchema, current_user: User = Depends(create_current_active_user(True))):
    print(order_info)
    res = dict(order_info)
    query = insert(Order).values(res)
    res['id'] = await AdminDatabase().database.execute(query)
    return res
Exemplo n.º 12
0
 async def res(id,current_user: User = Depends(create_current_active_user(need_user))):
     query = model.__table__.delete().where(model.id==id)
     await AdminDatabase().database.fetch_one(query)
     return query