query_pay_list = HydeeERPModel().query_pay_list() card_id_list = [x.card_id for x in query_pay_list] if len(card_id_list) != 0: card_id_list = list(set(card_id_list)) card_query = MemberCard.objects.filter(card_id__in=card_id_list) user_list = [{ 'card_id': card.card_id, 'name': card.name, 'avatar': card.user.useravatar.avatar.url if card.user and hasattr(card.user, 'UserAvatar') else '', 'settlement_list': [{ 'id': x.id, 'type': x.type, 'date': x.date.to_datetime_string(), 'gift': x.gift, 'branch': get_branch(x.branch), 'status': '待付款', 'amount': x.amount, 'before_price': f'{x.before_price:.2f}', 'discount': f'{x.discount:.2f}', 'after_price': f'{x.after_price:.2f}', 'detail': [{ 'name': y.name, 'spec': y.spec, 'amount': y.amount, 'unit': y.unit, 'unit_price': y.unit_price, 'price': y.price } for y in x.detail], } for x in list(filter(lambda m: m.card_id == card.card_id, query_pay_list))] } for card in card_query] return json_resp(user_list) else: return json_resp({}, "", '数据为空', status.HTTP_200_OK)