Пример #1
0
def is_register_1():
    """判断普通用户账号是否存在,不存在,则注册"""
    # 获取判断的账号信息
    mobile_phone = config.get('user', 'mobile_phone')
    password = config.get('user', 'password')

    # 连接数据库,查询数据
    db = MySQLHandler()
    sql = "select * from member where mobile_phone=%s;"
    user_info = db.fetchone(sql, [mobile_phone, ])
    db.close()
    # 若获取结果为空,则创建账户
    if not user_info:
        register_url = config.get('api', 'base_url') + config.get('api', 'register_url')
        headers = eval(config.get('api', 'headers'))
        register_data = {"mobile_phone": mobile_phone, "pwd": password, "type": 1}
        register_json = request.get_json(method='post', url=register_url, json=register_data, headers=headers)
        if register_json['code'] == 0:
            config.set('user', 'member_id', str(register_json['data']['id']))           # 回写配置文件,user id
            log.info(f'用户[{mobile_phone}]注册成功!')
            return True
        log.debug(f'注册失败:{register_json}')
        return False
    config.set('user', 'member_id', str(user_info['id']))   # 回写配置文件,user id
    return None
Пример #2
0
def get_user_info(member_id):
    """查询用户信息"""
    db = MySQLHandler()
    sql = "select * from member where id=%s;"
    user_info = db.fetchone(query=sql, args=[member_id, ])
    db.close()
    return user_info
Пример #3
0
def get_leave_amount(member_id):
    """查余额"""
    db = MySQLHandler()
    sql = "select * from member where id=%s"
    user_info = db.fetchone(query=sql, args=[member_id, ])
    db.close()
    return Decimal(user_info['leave_amount']).quantize(Decimal("0.00"))
Пример #4
0
def old_phone():
    """数据库中已存在的电话号码"""
    db = MySQLHandler()
    sql = "select mobile_phone from member"
    res = db.fetchone(sql)
    phone = res['mobile_phone']
    db.close()
    return phone
Пример #5
0
def new_phone():
    """随机生产新号码"""
    db = MySQLHandler()
    while True:
        phone = make_phone_number()
        sql = "select * from member where mobile_phone=%s;"
        res = db.fetchone(query=sql, args=[phone, ])
        if not res:
            break
    db.close()
    return phone
Пример #6
0
def get_loan_info(my=True, status=2, loan_id=None):
    """查询项目信息, 项目状态status=(1, 2, 3, 4, 5), 1:审核中 2:竞标中 3:还款中 4:还款完成 5:审核不通过 """
    member_id = config.get('user', 'member_id')
    db = MySQLHandler()
    if loan_id is not None:
        """根据项目id 查询项目信息"""
        sql = "select * from loan where id=%s;"
        loan_info = db.fetchone(query=sql, args=[loan_id, ])
    elif my:
        """查询测试账号下的项目信息"""
        sql = "select * from loan where member_id=%s and status=%s;"
        loan_info = db.fetchone(query=sql, args=[member_id, status])
    else:
        """查询其他用户的项目信息"""
        sql = "select * from loan where member_id!=%s and status=%s;"
        loan_info = db.fetchone(query=sql, args=[member_id, status])
    db.close()
    return loan_info
Пример #7
0
def get_invest_info(invest_id=None, loan_id=None):
    """查询投资记录"""
    db = MySQLHandler()
    if invest_id is not None:
        """根据投资记录id查询投资信息"""
        sql = 'select * from invest where id=%s;'
        invest_info = db.fetchone(query=sql, args=[invest_id, ])
        db.close()
        return invest_info
    elif loan_id is not None:
        """项目项目id查询 已投金额"""
        sql = 'select amount from invest where loan_id=%s;'
        invested_amount = db.fetchall(query=sql, args=[loan_id, ])
        db.close()
        return invested_amount
    db.close()
    log.error('未传入查询参数!')
    return None
Пример #8
0
 def wloan_5(self):
     db = MySQLHandler()
     sql = 'select id from loan where status=5'
     loan_id = db.fetchone(query=sql)
     db.close()
     return str(loan_id['id'])
Пример #9
0
def change_amount(member_id, amount):
    """修改账户余额"""
    db = MySQLHandler()
    sql = "update member set leave_amount=%s where id=%s;"
    db.execute(query=sql, args=[amount, member_id])
    db.close()