def get_agency_list(request): '''归属列表''' try: if request.method == 'POST': if request.POST.get('agency_id') is not None: agency = Agency.objects.get(pk=request.POST.get('agency_id')) agency_json = [] agency_json.append({ 'id': agency.id, "name": agency.name, "organization": agency.organization.name, 'rebate_x': agency.rebate_x, 'rebate_y': agency.rebate_y, "rebate_z": agency.rebate_z, "f_agency_id": 0 if agency.f_agency is None else agency.f_agency.id, "f_agency": '无' if agency.f_agency is None else agency.f_agency.name, 'invite_url': request.get_host()+'/register?code='+agency.invite_num, 'invite_num': agency.invite_num, 'is_freeze': agency.is_freeze, 'bank_card': agency.bank_card, 'bank_name': agency.bank_name, 'bank_holder': agency.bank_holder, 'bank_branch': agency.bank_branch, 'allow_business_id': agency.allow_business, 'allow_business': get_multi_text(agency.allow_business) # ','.join([agency.allow_business.choices.__getitem__(value) for value in agency.allow_business]) }) return JsonResponse(agency_json, safe=False) else: return JsonResponse([], safe=False) # return Http404('用户身份有误,请重新登陆') except Exception as ex: print(ex) return JsonResponse([], safe=False)
def get_allow_business(self, obj): if obj.allow_business: # return obj.allow_business.choices.values() return get_multi_text(obj.allow_business) # return ",".join([obj.allow_business.choices.__getitem__(l) for l in obj.allow_business]) else: return '无'
def get_client_list(request): '''客户列表''' try: if request.method == 'POST': page = request.POST.get("page") rows = request.POST.get("rows") client_list = [] if request.POST.get('agency_id') is not None and request.POST.get( 'agency_id') != '0' and request.POST.get('agency_id') != 0: #如果按归属查询归属下客户 client_list.extend( list( Client.objects.filter(agency=Agency.objects.get( pk=request.POST.get('agency_id', None))))) else: #默认查询机构下所有客户 client_list.extend( list( Client.objects.filter( organization=get_org_obj(request)))) client_list.sort(key=date_joined_sort, reverse=True) results, total = page_helper(client_list, rows, page) eaList = [] for client in results.object_list: eaList.append({ 'id': client.id, 'name': client.name, 'mobile_phone': client.mobile_phone, 'mailbox': client.mailbox, 'organization': client.organization.name, 'agency': client.agency.name, 'status': client.get_status_display(), 'is_freeze': '是' if client.is_freeze else '否', 'allow_business_id': client.allow_business, 'allow_business': get_multi_text(client.allow_business), 'identity_card': client.identity_card, 'bank_image': client.bank_image.name, 'bank_card': client.bank_card, 'bank_name': client.bank_name, 'open_city': client.open_city, 'bank_branch': client.bank_branch }) json_data_list = {'total': total, 'rows': eaList} return JsonResponse(json_data_list, safe=False) except Exception as ex: print(ex) return JsonResponse([], safe=False)