def changeCreditLine(request, *args, **kwargs): ''' 修改信用额度 ''' if request.GET.has_key('account_id') and request.GET.has_key( 'credit_line'): account_id = request.GET['account_id'] credit_line = request.GET['credit_line'] response = billing_req('account/detail/%s' % account_id) result = None if response['account']['type'] == 'normal': result = billing_req('account/change2credit/%s?credit_line=%s' % (account_id, credit_line)) else: result = billing_req('account/changecreditline/%s?credit_line=%s' % (account_id, credit_line)) if result['success'] == 'success': return HttpResponse(json.dumps({'success': 'success'})) else: return HttpResponse( json.dumps({ 'success': 'error', 'msg': '修改信用额度失败' })) else: return HttpResponse(json.dumps({'success': 'error', 'msg': '参数不对'}))
def get_data(self): account_id = self.request.session.get("account")["account_id"] # account_id="3fcf0bba-1c52-4dc8-9b59-2f78b3691943" account_info = {} for key, value in billing_req("/account/detail/" + account_id)["account"].items(): if key == "cash_balance" or key == "credit_line" or key == "gift_balance": account_info[key] = string.atof(value) account_info[ "available"] = account_info["credit_line"] if account_info[ "cash_balance"] > 0 else account_info[ "cash_balance"] + account_info["credit_line"] account_info["account_id"] = account_id title_list = [{"name": "账户详情", "url": "/center/bill_details"}] parentUser = billing_req( '/account/getparentuserbyid/' + self.request.session.get("account")["user_id"])['parentUser'] isSubAccount = False if parentUser and parentUser['name'] not in ('admin', 'register'): isSubAccount = True return { "account_info": account_info, 'amount': account_info['cash_balance'] + account_info['gift_balance'], "title_list": title_list, 'isSubAccount': isSubAccount }
def get_data(self): account_id = self.request.session.get("account")["account_id"] #account_id="asdasdadasfftgerr" return_info = {} temp = billing_req("/account/getsubaccountsum/" + account_id)["subAccountSum"] return_info["credit_child_num"] = temp["credit_sum"] return_info["general_child_num"] = temp["sum"] - temp["credit_sum"] return_info["account_info"] = billing_req("/account/detail/" + account_id)["account"] title_list = [{"name": "子帐号账户管理", "url": "/center/account_manage"}] return_info["title_list"] = [] return return_info
def child_account(request): account_id = request.session.get("account")["account_id"] #account_id="asdasdadasfftgerr" pageSize = int(request.GET['limit']) pageNo = int(request.GET['offset']) / pageSize + 1 url = "/account/subaccountlist/%s?pageNo=%s&pageSize=%s" % ( account_id, pageNo, pageSize) if request.GET.has_key('name'): url += '&name=' + request.GET['name'] if request.GET.has_key('type'): url += '&type=' + request.GET['type'] if request.GET.has_key('max_cash'): url += '&max_cash=' + request.GET['max_cash'] if request.GET.has_key('min_cash'): url += '&min_cash=' + request.GET['min_cash'] if request.GET.has_key('max_gift'): url += '&max_gift=' + request.GET['max_gift'] if request.GET.has_key('min_gift'): url += '&min_gift=' + request.GET['min_gift'] if request.GET.has_key('max_credit'): url += '&max_credit=' + request.GET['max_credit'] if request.GET.has_key('min_credit'): url += '&min_credit=' + request.GET['min_credit'] result = billing_req(url) data = { 'total': result['subAccountList']['total'], 'rows': result['subAccountList']['accounts'] } return HttpResponse(json.dumps(data))
def get_data(self): resource_type_list = ( ('instance', '实例'), ('ip', '浮动IP'), ('router', '路由'), ('disk', '云硬盘'), ('bandwidth', '带宽'), ('snapshot', '快照'), ('vpn', 'VPN'), ) account_id = self.request.session.get("account")["account_id"] #account_id="5689sfshfhsdhiojfdsjofi" title_list = [{"name": "近期消费记录", "url": "/center/recent_cost"}] return_info = billing_req("/consumption/getamountsummary/" + account_id)["amountsummary"] return_info["title_list"] = title_list return_info["region_list"] = billing_req( "/common/getregionlist")["regionList"] return_info["resource_type_list"] = resource_type_list return return_info
def insteadRecharge(request): ''' 近期消费记录 ''' recharge_data = json.loads(request.POST["recharge"]) recharge_data["recharge"]["amount"] = float( recharge_data["recharge"]["amount"]) request_url = "/recharge/insteadrecharge" response = billing_req(request_url, data=json.dumps(recharge_data), method="POST") if response['success'] == "success": return_data = "success" else: return_data = "fail" return HttpResponse(return_data)
def get_data(self): account_id = self.request.GET['account_id'] response = billing_req('account/detail/%s' % account_id) if response['success'] == "success": type = { 'key': 'normal', 'value': '普通账户' } if response['account']['type'] == 'normal' else { 'key': 'credit', 'value': '信用账户' } return { 'account_id': account_id, 'type': type, 'credit_line': response['account']['credit_line'] } return {}
def giftRecharge(request, *args, **kwargs): ''' 一般赠送 ''' account_id = kwargs["account_id"] recharge_data = json.loads(request.POST["recharge"]) recharge_data["gift"]["amount"] = float(recharge_data["gift"]["amount"]) request_url = "/gift/giftamount/" + account_id if recharge_data["gift"]["amount"] > 0: response = billing_req(request_url, data=json.dumps(recharge_data), method="POST") if response['success'] == "success": return_data = "success" else: return_data = "fail" else: return_data = "fail" return HttpResponse(return_data)
def firstGift(request, *args, **kwargs): ''' 首次赠送 ''' account_id = kwargs["account_id"] recharge_data = json.loads(request.POST["recharge"]) recharge_data["gift"]["amount"] = float(recharge_data["gift"]["amount"]) request_url = "/gift/firstamount/" + account_id if recharge_data["gift"]["amount"] > 0 and recharge_data["gift"][ "amount"] <= settings.GIFT_VALUE: response = billing_req(request_url, data=json.dumps(recharge_data), method="POST") if response['success'] == "success": return_data = "success" else: return_data = "fail1" else: return_data = "fail2" return HttpResponse(return_data)
def consumption_data(request): account_id = request.session.get("account")["account_id"] #account_id="5689sfshfhsdhiojfdsjofi" pageSize = int(request.GET['limit']) pageNo = int((float(request.GET['offset']) + 1) / float(request.GET['limit']) + 1) product_type = request.GET['product_type'] region = request.GET['region'] period = request.GET['period'] import datetime import calendar as cal current_year = datetime.date.today().year current_month = datetime.date.today().month current_range = ("%s-%s-01" % (current_year, current_month), "%s-%s-01" % (month_add(current_year, current_month, 1))) last_range = ("%s-%s-01" % (month_add(current_year, current_month, -1)), "%s-%s-01" % (current_year, current_month)) forelast_range = ("%s-%s-01" % (month_add(current_year, current_month, -2)), "%s-%s-01" % (month_add(current_year, current_month, -1))) if period == "current": started_at, ended_at = current_range elif period == "last": started_at, ended_at = last_range else: #period=="forelast": started_at, ended_at = forelast_range request_url = "/consumption/list/%s?pageNo=%s&pageSize=%s&started_at=%s&ended_at=%s" % ( account_id, pageNo, pageSize, started_at, ended_at) if product_type != "all": request_url += "&resource_type=%s" % product_type if region != "all": request_url += "®ion_id=%s" % region result = billing_req(request_url)['consumptionList'] #result = billing_req("/consumption/list/%s"%account_id,data={"pageNo":pageNo,"pageSize":pageSize}) return_data = {} return_data["rows"] = result.pop('consumptions') #return_data["rows"]=filter(lambda x:if_true(product_type,region,period,x),result.pop('consumptions')) return_data["total"] = result.pop('total') return HttpResponse(json.dumps(return_data))
def data_def_map(request): ''' 数据展示用于定义格式 :param request: :return: ''' return_info = {} resource_type_list = ( ('instance', '实例'), ('ip', '浮动IP'), ('router', '路由'), ('disk', '云硬盘'), ('bandwidth', '带宽'), ('snapshotdisk', '快照'), ('vpn', 'VPN'), ) return_info["region_list"] = { item["region_id"]: item["region_desc"] for item in billing_req("/common/getregionlist")["regionList"] } return_info["resource_type_list"] = resource_type_list return HttpResponse(json.dumps(return_info))
def cost_forecast(request): account_id = request.session.get("account")["account_id"] #account_id="5689sfshfhsdhiojfdsjofi" return_list = billing_req("/consumption/forecast/" + account_id)["forecast"] return HttpResponse(json.dumps(return_list))