Beispiel #1
0
def update_user(**kwargs):
    """
    编辑用户信息
    :param kwargs: 
    :return: 
    """
    records = view_users()
    if not records:
        print('没有找到结果')
        return False
    entry_id = input("请输入用户ID,(b,返回):>>").strip()
    if entry_id.lower() == 'b':
        return False
    credit = input("请重新输入用户额度:>>").strip()
    if not credit.isdigit() and not utils.is_float_num(credit):
        print("请输入数字字符")
        return False
    ret = db_handler.data_api(
        'update', settings.USER_TABLE, **{
            'set': {
                'credit': float(credit)
            },
            'where': [{
                'field': 'id',
                'value': int(entry_id)
            }]
        })
    if ret:
        return {
            'status': ret,
            'logger': kwargs.get('logger'),
            'msg': "管理员修改用户ID: %s 的额度" % entry_id
        }
    return False
Beispiel #2
0
def transfer(user, **kwargs):
    """
    转账
    :param user: 
    :param kwargs: 
    :return: 
    """
    profile(user)
    username = input("请输入对方用户名:>>").strip()
    amount = input("请输入转账金额:>>").strip()
    if username == user['username']:
        print("不能转给自己")
        return False
    if not amount.isdigit() and not utils.is_float_num(amount):
        print("请输入数字字符")
        return False
    amount = float(amount)
    trans_user = load_user(username=username)
    if not trans_user:
        print("用户不存在")
        return False
    if trans_user.get('status') != 0:
        print("用户已被禁用")
        return False
    note = "转账给用户:%s" % username
    ret = transaction.make_transaction(
        load_user(user_id=user['id']), 'transfer', amount, **{
            'transfer': trans_user,
            'logger': kwargs.get('logger'),
            'note': note
        })
    if not ret:
        return False
    new_user = ret.get('user', False)
    if new_user:
        history = [{
            'user_id': user['id'],
            'username': user['username'],
            'transaction': 'transfer',
            'amount': amount,
            'fee': ret.get('fee', 0),
            'balance': new_user['balance'],
            'add_time': time.time(),
            'note': note,
        }, {
            'user_id': trans_user['id'],
            'username': trans_user['username'],
            'transaction': 'transfer',
            'amount': amount,
            'fee': 0,
            'balance': float(ret.get('transfer_balance', 0)) + amount,
            'add_time': time.time(),
            'note': "用户:%s转账" % user['username'],
        }]
        return {
            'status': 0,
            'history': history,
            'msg': '转账成功,余额 %s' % new_user['balance']
        }
    return False
Beispiel #3
0
def add_user(**kwargs):
    """
    添加用户
    :param kwargs: 
    :return: 
    """
    username = input("请输入用户名,(b,返回):>>").strip()
    if username.lower() == 'b':
        return False
    password = input("请输入用户密码:>>").strip()
    credit = input("请输入用户额度:>>").strip()

    if check_exists(settings.USER_TABLE,
                    **{'where': [{
                        'field': 'username',
                        'value': username
                    }]}):
        print("用户已存在")
        return False
    if not credit.isdigit() and not utils.is_float_num(credit):
        print("请输入数字字符")
        return False
    entry = settings.DATABASE['tables'][settings.USER_TABLE]['structure']
    entry.update({
        'id':
        get_increment_id(settings.USER_TABLE),
        'username':
        username,
        'password':
        utils.hash_md5(password),
        'credit':
        float(credit),
        'balance':
        float(credit),
        'enroll_date':
        utils.calculate_date(),
        'expire_date':
        utils.calculate_date(years=settings.USER_EFFECTIVE_YEARS),
    })
    ret = db_handler.data_api('add', settings.USER_TABLE, **{'fields': entry})
    if ret:
        return {
            'status': ret,
            'logger': kwargs.get('logger'),
            'msg': "管理员添加用户 %s" % username
        }
    return False
Beispiel #4
0
    def recharge(user, **kwargs):
        """
        创建班级
        :param user: 
        :param kwargs: 
        :return: 
        """
        amount = input("请输入充值金额,(b,返回):>>").strip()
        if amount.lower() == 'b':
            return False
        if not amount.isdigit() and not utils.is_float_num(amount):
            print("请输入数字字符")
            return False

        entry = LuffyStudent.fetch_one(user.sn)
        entry.add_balance(float(amount))
        entry.add_transaction('%s 充值:%s' % (utils.calculate_date(time_format=True), amount))
        entry.save()
        return {'status': 0, 'logger': kwargs.get('logger'), 'msg': "学生 %s 成功充值 %s " % (entry.username, amount)}
Beispiel #5
0
def add_product(**kwargs):
    """
    添加商品信息
    :param kwargs: 
    :return: 
    """
    title = input("请输入商品名,(b,返回):>>").strip()
    if title.lower() == 'b':
        return False
    price = input("请输入单价:>>").strip()
    number = input("请输入数量:>>").strip()

    if check_exists(settings.PRODUCT_TABLE,
                    **{'where': [{
                        'field': 'title',
                        'value': title
                    }]}):
        print("商品%s已存在" % title)
        return False
    if not price.isdigit() and not utils.is_float_num(price):
        print("请输入数字字符")
        return False
    if not number.isdigit():
        print("请输入数字字符")
        return False
    entry = settings.DATABASE['tables'][settings.PRODUCT_TABLE]['structure']
    entry.update({
        'id': get_increment_id(settings.PRODUCT_TABLE),
        'title': title,
        'price': float(price),
        'number': int(number),
    })
    ret = db_handler.data_api('add', settings.PRODUCT_TABLE,
                              **{'fields': entry})
    if ret:
        return {
            'status': ret,
            'logger': kwargs.get('logger'),
            'msg': "管理员添加商品 %s" % title
        }
    return False
Beispiel #6
0
 def show_students(user, **kwargs):
     """
     显示讲师的学生列表
     :param user: 
     :param kwargs: 
     :return: 
     """
     teacher = LuffyTeacher.fetch_one(user.sn)
     students = teacher.students()
     if not len(students):
         print("没有学生记录")
         return False
     records = []
     for sn in students:
         entry = LuffyStudent.fetch_one(sn)
         if entry:
             records.append(entry)
     if not len(records):
         print("没有学生记录")
         return False
     for i, row in enumerate(records, 1):
         print('# ', i, row)
     option = input("请输入要打分的学生ID(b,返回):>>").strip()
     if option.lower() == 'b':
         return False
     index = int(option) - 1
     if index < 0 or index >= len(records):
         print("错误的选项")
         return False
     score = input("请输入分值:>>").strip()
     if not score.isdigit() and not utils.is_float_num(score):
         print("请输入数字字符")
         return False
     Models.set_score(
         user, **{
             'student': records[index],
             'score': score,
             'logger': kwargs.get('logger')
         })
Beispiel #7
0
def withdraw(user, **kwargs):
    """
    取现
    :param user: 
    :param kwargs: 
    :return: 
    """
    profile(user)
    amount = input("请输入取现金额:>>").strip()
    if not amount.isdigit() and not utils.is_float_num(amount):
        print("请输入数字字符")
        return False
    amount = float(amount)
    ret = transaction.make_transaction(load_user(user_id=user['id']),
                                       'withdraw', amount,
                                       **{'logger': kwargs.get('logger')})
    if not ret:
        return False
    new_user = ret.get('user', False)
    if new_user:
        history = {
            'user_id': user['id'],
            'username': user['username'],
            'transaction': 'withdraw',
            'amount': amount,
            'fee': ret.get('fee', 0),
            'balance': new_user['balance'],
            'add_time': time.time(),
            'note': '',
        }
        return {
            'status': 0,
            'history': history,
            'msg': '取现成功,余额 %s' % new_user['balance']
        }
    return False
Beispiel #8
0
        os.path.abspath(__file__)))))

from conf import settings
from core import db_handler
from core import utils
from admin import models

# db_handler.find_action('users',**{'where': [{'field': 'id', 'value': 'sss'}, {'field': 'id', 'logic': '!=', 'value': 'sssss'}]})
# db_handler.data_api('find','users',**{'where': [{'field': 'id', 'value': 'sss'}, {'field': 'id', 'logic': '!=', 'value': 'sssss'}]})
# db_handler.add_action('users',**{'fields':{'id':'zjx123','password':'******','credit':15000,'balance':'15000'}})
# models.check_exists('users','zjx')
#print(models.get_increment_id('users'))
price = '1231wqewq123.45'
print(price, type(price), price.isnumeric(), price.isdecimal(),
      price.isdigit())
print(utils.is_float_num(price))
# print(db_handler.check_field(settings.USER_TABLE,*('*',)))
# db_handler.update_action('users',**{'set':{'id':'zjx111'},'where': [{'field': 'id', 'value': 'zjx'}]})
if settings.DATABASE['engine'] == 'mysql':
    add_args = {'id': 'zjx', 'password': 15}
    update_args = {
        'set': {
            'id': 'zjx',
            'password': 15
        },
        'where': [{
            'field': 'id',
            'value': 'sss'
        }, {
            'field': 'id',
            'logic': '!=',