def advert_list(request, format=None): sells = am.Content.objects.all().exclude( user=request.user).order_by('-datetime') pagination = CustomPagination() query = pagination.paginate_queryset(sells, request) return pagination.get_paginated_response( ass.ContentSerializer(query, many=True).data)
def task_request(request, format=None): if request.method == 'POST': now = datetime.now() now_date = request.data.get('date') if now_date != now.strftime("%Y-%m-%d"): return Response('请开始新任务', status=status.HTTP_205_RESET_CONTENT) try: task = nsm.Task.objects.get(user=request.user, date=now.date()) return Response('今日任务已完成', status=status.HTTP_200_OK) except nsm.Task.DoesNotExist: earn_count = mm.machine_earn_count(request.user) task = nsm.Task(user=request.user, earn=earn_count) task.save() csm.record_creation(user=request.user, point=earn_count, key='daily_task', desc='日常任务') return Response(nss.TaskSerializer(task).data, status=status.HTTP_201_CREATED) else: tasks = nsm.Task.objects.filter(user=request.user) pagination = CustomPagination() query = pagination.paginate_queryset(tasks, request) return pagination.get_paginated_response( nss.TaskSerializer(query, many=True).data)
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('请输入正确的号码')
def buy_mine(request, format=None): buys = Buy.objects.filter(status=0).order_by('-date') pagination = CustomPagination() query = pagination.paginate_queryset(buys, request) if query: return pagination.get_paginated_response( BuySerializer(query, many=True).data) return pagination.get_paginated_response([])
def sell_mine(request, format=None): trades = Sell.objects.filter(status=0).order_by('-date') pagination = CustomPagination() query = pagination.paginate_queryset(trades, request) if query: return pagination.get_paginated_response( SellSerializer(query, many=True).data) return pagination.get_paginated_response([])
def sell_list(request, format=None): sells = Sell.objects.filter(status=0).exclude( user=request.user).order_by('-date') pagination = CustomPagination() query = pagination.paginate_queryset(sells, request) if query: return pagination.get_paginated_response( SellSerializer(query, many=True).data) return pagination.get_paginated_response([])
def advert_mine(request, format=None): adverts = am.Content.objects.filter( user=request.user).order_by('-datetime') pagination = CustomPagination() query = pagination.paginate_queryset(adverts, request) return pagination.get_paginated_response( ass.ContentOwnedSerializer(query, many=True, context={ 'request': request }).data)
def user_records(request, format=None): username = request.GET.get('username', request.user.username) # page = request.GET.get('page', '1') # size = request.GET.get('size', '30') user = CoinUser.objects.filter(username=username).first() if user and user.id: ads = am.Content.objects.filter(user=user) p = CustomPagination() query = p.paginate_queryset(ads, request) if query: return p.get_paginated_response(serializers.ContentSummary(query, many=True).data) return p.get_paginated_response([]) return Response(data='不存在的数据', status=status.HTTP_404_NOT_FOUND)
def mine(request, format=None): t = datetime.now() print(request.GET) # 1 可用 2 已过期 0全部 s = int(request.GET.get('status', 0)) print(s) if s == 0: records = models.Record.objects.filter(user=request.user).order_by('-expired') elif s == 2: records = models.Record.objects.filter(expired__lt=t, user=request.user).order_by('-expired') else: records = models.Record.objects.filter(expired__gt=t, user=request.user).order_by('-expired') # records = models.Record.objects.all() pagination = CustomPagination() query = pagination.paginate_queryset(records, request) return pagination.get_paginated_response(serializers.RecordSerializer(query, many=True).data)
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)
def user_team(request, format=None): # 获取我的下面的人员 infos = CoinUser.objects.filter(inviter=request.user.code).order_by('-date_joined') pagination = CustomPagination() query = pagination.paginate_queryset(infos, request) return pagination.get_paginated_response(TeamSerializer(query, many=True).data)