def histories(user, fields=''): """ 查看个人信息 :param user: 指定字段 :param fields: 指定字段 :return: """ if not len(fields): fields = ('username', 'transaction', 'amount', 'fee', 'balance', 'add_time', 'note') trans_logs = db_handler.data_api( 'find', settings.HISTORY_TABLE, **{ 'fields': fields, 'where': [{ 'field': 'user_id', 'value': user['id'] }] }) if isinstance(trans_logs, int) or not len(trans_logs): print('没有交易记录') return False result = [] for item in trans_logs: info = {} for i in fields: info[i] = item[i] if i == 'add_time': info[i] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(item['add_time'] // 1)) if i == 'transaction': info[i] = utils.format_transaction(item['transaction']) result.append(info) utils.format_table(fields, result) return True
def profile(user, fields=''): """ 查看个人信息 :param user: 指定字段 :param fields: 指定字段 :return: """ if not len(fields): fields = ('username', 'balance', 'credit', 'expire_date', 'enroll_date', 'status') info = {} new_user = load_user(user_id=user['id']) for i in fields: info[i] = new_user[i] if i == 'status': info[i] = utils.format_status(new_user['status']) utils.format_table(fields, [info]) return False
def view_products(user, **kwargs): """ 查看商品列表 :param user: :param kwargs: :return: """ fields = kwargs.get('fields', ()) if not len(fields): fields = ('id', 'title', 'price', 'number', 'status') ret = db_handler.data_api( 'find', settings.PRODUCT_TABLE, **{ 'fields': fields, 'where': [{ 'field': 'status', 'logic': '!=', 'value': 1 }] }) if isinstance(ret, int): return ret if not len(ret): print('没有商品') return False result = [] for i in ret: if 'status' in i: i.update({'status': utils.format_status(i['status'])}) result.append(i) utils.format_table(fields, result) option = input("请输入要购买的商品ID,(0,注销;b,返回):>>").strip() if option.isdigit(): if option == '0': logout(user, **kwargs) else: consume( user, **{ 'product_id': int(option), 'logger': kwargs.get('logger') }) elif option.lower() == 'b': return True
def view_products(fields=''): """ 查看商品列表 :param fields: :return: """ if not len(fields): fields = ('id', 'title', 'price', 'number', 'status') ret = db_handler.data_api('find', settings.PRODUCT_TABLE, **{'fields': fields}) if isinstance(ret, int): return ret if not len(ret): return False result = [] for i in ret: if 'status' in i: i.update({'status': utils.format_status(i['status'])}) result.append(i) utils.format_table(fields, result) return ret
def view_cart(user, fields=''): """ 查看购物车 :param user: :param fields: :return: """ if not fields: fields = ('title', 'amount', 'created_at') if 'cart' not in user or not len(user['cart']): print('没有购买记录') return False result = [] for item in user['cart']: tmp = {} for field in fields: tmp[field] = item[field] result.append(tmp) utils.format_table(fields, result) return False
def view_users(fields=''): """ 查看用户列表 :param fields: 指定字段 :return: """ if not len(fields): fields = ('id', 'username', 'balance', 'credit', 'expire_date', 'enroll_date', 'status') ret = db_handler.data_api('find', settings.USER_TABLE, **{'fields': fields}) if isinstance(ret, int): return ret if not len(ret): print('没有结果') return False result = [] for i in ret: if 'status' in i: i.update({'status': utils.format_status(i['status'])}) result.append(i) utils.format_table(fields, result) return ret