def show(request): try: if request.method == "POST": amount = float( request.POST["amount"]) if request.POST["amount"] else 0 else: amount = 0 crypto_util = WalletManager.create_fund_util('CNY') wallet = WalletManager.get_wallet_balance(crypto_util, request.user.username, 'CNY') userpayment = PaymentMethodManager.get_payment_method( request.user.username) if not userpayment: messages.error("请设置付款方式,再充值") return redirect('balance') useraccountInfo = UserAccountInfo(request.user.id, wallet.balance, wallet.locked_balance, wallet.available_balance, wallet.wallet_addr, None, [userpayment]) return render(request, 'walletgui/redeem_investment.html', { 'account': useraccountInfo, 'amount': amount }) except Exception as e: error_msg = '用户主页显示遇到错误: {0}'.format(sys.exc_info()[0]) logger.exception(error_msg) return errorpageview.show_error(request, ERR_CRITICAL_IRRECOVERABLE, '系统遇到问题,请稍后再试。。。{0}'.format(error_msg))
def show(request): try: crypto_util = WalletManager.create_fund_util('CNY') wallet = WalletManager.get_wallet_balance(crypto_util, request.user.username, 'CNY') userpayment = PaymentMethodManager.get_payment_method( request.user.username) if userpayment: logger.info("get user paymentmethod with account {0}".format( userpayment.account_at_provider)) else: logger.info("No user paymentmethod found") useraccountInfo = UserAccountInfo(request.user.id, wallet.balance, wallet.locked_balance, wallet.available_balance, wallet.wallet_addr, None, [userpayment]) return render(request, 'walletgui/balance.html', { 'account': useraccountInfo, 'userpaymentmethod': userpayment }) except Exception as e: error_msg = '用户主页显示遇到错误: {0}'.format(sys.exc_info()[0]) logger.exception(error_msg) return errorpageview.show_error(request, ERR_CRITICAL_IRRECOVERABLE, '系统遇到问题,请稍后再试。。。{0}'.format(error_msg))
def show(request): try: return render(request, 'walletgui/backup_wallet.html') except Exception as e: error_msg = '用户主页显示遇到错误: {0}'.format(sys.exc_info()[0]) logger.exception(error_msg) return errorpageview.show_error(request, ERR_CRITICAL_IRRECOVERABLE, '系统遇到问题,请稍后再试。。。{0}'.format(error_msg))
def delete(request): try: return render(request, 'walletgui/balance.html', { 'account': None, 'userpaymentmethod': None }) except Exception as e: error_msg = '用户主页显示遇到错误: {0}'.format(sys.exc_info()[0]) logger.exception(error_msg) return errorpageview.show_error(request, ERR_CRITICAL_IRRECOVERABLE, '系统遇到问题,请稍后再试。。。{0}'.format(error_msg))
def show(request): try: userpayment = PaymentMethodManager.get_payment_method(request.user.username) if not userpayment: messages.error("请设置付款方式,再充值") return redirect('balance') return render(request, 'walletgui/purchase_investment.html') except Exception as e: error_msg = '用户主页显示遇到错误: {0}'.format(sys.exc_info()[0]) logger.exception(error_msg) return errorpageview.show_error(request, ERR_CRITICAL_IRRECOVERABLE, '系统遇到问题,请稍后再试。。。{0}'.format(error_msg))
def show(request): try: paymentmethods = [] paymentmethods.append( UserPaymentMethodView(1, 1, 'heepay', '汇钱包', '15910978598')) useraccountInfo = UserAccountInfo( 1, 1000.0, 1000.0, 0.0, 'AXjtBn93Y8Yti6LXWQqwkrF1pHcBRGYEDu', None, paymentmethods) return render(request, 'walletgui/transfer_investment.html', {'account': useraccountInfo}) except Exception as e: error_msg = '用户主页显示遇到错误: {0}'.format(sys.exc_info()[0]) logger.exception(error_msg) return errorpageview.show_error(request, ERR_CRITICAL_IRRECOVERABLE, '系统遇到问题,请稍后再试。。。{0}'.format(error_msg))
def purchase(request): try: if request.method == 'POST': amount = float(request.POST["amount"]) if request.POST["amount"] else 0 if math.fabs(amount) < 0.01: messages.error(request, '充值数量不可小于一分钱') return redirect(request, 'show_purchase') try: api_user = APIUserAccount.objects.get(user__username=request.user.username) except APIUserAccount.DoesNotExist: raise ValueError(ERR_USER_NOT_FOUND_BASED_ON_APPID) except APIUserAccount.MultipleObjectsReturned: raise ValueError(ERR_MORE_THAN_ONE_USER_BASED_ON_APPID) try: userpaymentmethod = UserPaymentMethod.objects.get( user__id = api_user.user.id) except UserPaymentMethod.DoesNotExist: raise ValueError(ERR_PAYMENTMETHOD_NOT_FOUND) except UserPaymentMethod.MultipleObjectsReturned: raise ValueError(ERR_MORE_THAN_ONE_PAYMENTMETHOD_FOUND) out_trade_no = str(uuid.uuid4()) request_obj = TradeAPIRequest( API_METHOD_PURCHASE, api_user.apiKey, api_user.secretKey, out_trade_no, # order id None, # trx _id (int)(amount * 100), # total fee settings.TRADE_API_CALL_TIMEOUT_IN_MINUTES, # expire_minute userpaymentmethod.provider.code, userpaymentmethod.account_at_provider, '127.0.0.1', #client ip subject='Staking充值请求 {0}'.format(amount), notify_url=None, return_url=None) url = TRADE_API_PURCHASE_URL_TEMPLATE.format(settings.TRADE_API_HOST) api_client = APIClient(url) resp_json = api_client.send_json_request(request_obj.getJsonPayload()) if resp_json["return_code"] != 'SUCCESS': logger.error('purchase(): get failure api response: {0}'.format(json.dumps(resp_json, ensure_ascii=False))) errmsg = '充值请求遇到问题:{0}'.format(resp_json["return_code"]) if 'result_msg' in resp_json: errmsg = '{0}-{1}'.format(errmsg, resp_json['result_msg']) messages.error(request, errmsg) return redirect('balance') else: qrcode_filename = '{0}_{1}.png'.format( resp_json['out_trade_no'], resp_json['trx_bill_no'] ) qrcode_img_url_path = create_qrcode_image( resp_json['payment_url'], qrcode_filename, settings.MEDIA_ROOT) return render(request, 'walletgui/purchase_qrcode.html', {'qrcode_file': qrcode_img_url_path}) except Exception as e: error_msg = '用户主页显示遇到错误: {0}'.format(sys.exc_info()[0]) logger.exception(error_msg) return errorpageview.show_error(request, ERR_CRITICAL_IRRECOVERABLE, '系统遇到问题,请稍后再试。。。{0}'.format(error_msg))
def redeem(request): try: if request.method == "POST": amount = float( request.POST["amount"]) if request.POST["amount"] else 0 crypto_util = WalletManager.create_fund_util('CNY') if math.fabs(amount) < 0.02: messages.error(request, '提现数量不可两份钱') return redirect(request, 'show_redeem') try: api_user = APIUserAccount.objects.get( user__username=request.user.username) except APIUserAccount.DoesNotExist: raise ValueError(ERR_USER_NOT_FOUND_BASED_ON_APPID) except APIUserAccount.MultipleObjectsReturned: raise ValueError(ERR_MORE_THAN_ONE_USER_BASED_ON_APPID) try: userpaymentmethod = UserPaymentMethod.objects.get( user__id=api_user.user.id) except UserPaymentMethod.DoesNotExist: raise ValueError(ERR_PAYMENTMETHOD_NOT_FOUND) except UserPaymentMethod.MultipleObjectsReturned: raise ValueError(ERR_MORE_THAN_ONE_PAYMENTMETHOD_FOUND) out_trade_no = str(uuid.uuid4()) request_obj = TradeAPIRequest( API_METHOD_REDEEM, api_user.apiKey, api_user.secretKey, out_trade_no, # order id None, # trx _id (int)(amount * 100), # total fee settings.TRADE_API_CALL_TIMEOUT_IN_MINUTES, # expire_minute userpaymentmethod.provider.code, userpaymentmethod.account_at_provider, '127.0.0.1', #client ip subject='Staking提现请求 {0}'.format(amount), notify_url=None, return_url=None) url = TRADE_API_PURCHASE_URL_TEMPLATE.format( settings.TRADE_API_HOST) api_client = APIClient(url) resp_json = api_client.send_json_request( request_obj.getJsonPayload()) if resp_json["return_code"] != 'SUCCESS': logger.error('redeem(): get failure api response: {0}'.format( json.dumps(resp_json, ensure_ascii=False))) errmsg = '提现请求遇到问题:{0}'.format(resp_json["return_code"]) if 'result_msg' in resp_json: errmsg = '{0}-{1}'.format(errmsg, resp_json['result_msg']) messages.error(request, errmsg) return redirect('balance') else: messages.success(request, '提现请求已经成功,请注意收款') return redirect('balance') else: raise ValueError("提现请求必须是POST请求") except Exception as e: error_msg = '用户主页显示遇到错误: {0}'.format(sys.exc_info()[0]) logger.exception(error_msg) return errorpageview.show_error(request, ERR_CRITICAL_IRRECOVERABLE, '系统遇到问题,请稍后再试。。。{0}'.format(error_msg))
from walletgui.controller.global_constants import * from walletgui.views.models.useraccountinfo import * from walletgui.views.models.userpaymentmethod import * from django.contrib.auth.decorators import login_required import logging,json logger = logging.getLogger("site.balance") @login_required def func(request): @login_required def balance(request):paymentmethods = [] paymentmethods.append( UserPaymentMethodView(1, 1, 'heepay', '汇钱包', '15910978598') ) useraccountInfo = UserAccountInfo(1, 1000.0, 1000.0, 0.0, 'AXjtBn93Y8Yti6LXWQqwkrF1pHcBRGYEDu', None, paymentmethods) sitesettings = context_processor.settings(request)['settings'] master_wallet_known = sitesettings.api_cny_master_wallet_addr is not None and len(sitesettings.api_cny_master_wallet_addr) > 0 return render(request, 'walletgui/balance.html', {'account': useraccountInfo, 'master_wallet_known': master_wallet_known}) except Exception as e: error_msg = '用户主页显示遇到错误: {0}'.format(sys.exc_info()[0]) logger.exception(error_msg) return errorpageview.show_error(request, ERR_CRITICAL_IRRECOVERABLE, '系统遇到问题,请稍后再试。。。{0}'.format(error_msg))