Example #1
0
def ali_pay(request, format=None):
    alipay = 'ALI'
    if request.method == 'GET':
        bank_r = pm.Pay.objects.filter(user=request.user, type=alipay)
        pagination = CustomPagination()
        query = pagination.paginate_queryset(bank_r, request)
        return pagination.get_paginated_response(
            ps.PaySerializer(query, many=True).data, )
    else:
        ali_no = request.data.get('number')
        if ali_no is None:
            return Response('请输入银行卡号')
        if pm.payment_count(request.user, alipay) > 0:
            return Response('银行卡已添加')
        if pm.payment_exist(alipay, ali_no):
            return Response('当前支付宝已被添加')
        serializer = ps.PaySerializer(data={
            'number': ali_no,
            'type': alipay,
            'name': '支付宝'
        })
        try:
            serializer.is_valid(raise_exception=True)
            serializer.save(user=request.user)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        except ValidationError as e:
            return Response('请输入正确的号码')
Example #2
0
def pay(request, format=None):
    if request.method == "GET":
        r = pm.Pay.objects.filter(user=request.user)[:2]
        pagination = CustomPagination()
        query = pagination.paginate_queryset(r, request)
        return pagination.get_paginated_response(
            ps.PaySerializer(query, many=True).data, )
    else:
        if pm.payment_count(request.user) >= 2:
            return Response('你当前已经有2条记录了')
        serializer = ps.PaySerializer(data=request.data)
        # 查询是否已经被使用
        try:
            serializer.is_valid(raise_exception=True)
            serializer.save(user=request.user)
        except ValidationError as e:
            return Response(serializer.errors, )
        return Response(serializer.data, status=status.HTTP_201_CREATED)
Example #3
0
 def get_ali(self, obj):
     ali = payment_count(user=obj.user, t='ALI')
     return ali
Example #4
0
 def get_bank(self, obj):
     bank = payment_count(user=obj.user, t='BANK')
     return bank
Example #5
0
def identified(user):
    return payment_count(user=user) > 0 and ident_count(user=user) > 0