Пример #1
0
 def get(self,request):
     if not have_phone_register(user=request.user):
         reply = get_reply(17,'not register with phone')
         return Response(reply,HTTP_403_FORBIDDEN)
     user = request.user
     queryset = BorrowItem.objects.filter(user=user,in_return_bar=True,finish_return=False)
     serializer = BorrowItemDetailSerializer(queryset,data=request.data,many=True)
     serializer.is_valid(raise_exception=True)
     for i in serializer.data:
         # 在返回数据中,增加到期时间
         return_time = i['return_time']
         date_list = return_time.split("-")
         year = int(date_list[0])
         month = int(date_list[1])
         day = int(date_list[2])
         return_date = datetime.datetime(year, month, day)
         now_date = datetime.datetime.now()
         due =  (return_date - now_date).days
         i['due'] = due
         if i < 7:
             i['due_in_7'] = True
             if i < 3:
                 i['due_in_3'] = True
         else:
             i['due_in_7'] = False
             i['due_in_3'] = False
     response = Response(serializer.data,HTTP_200_OK)
     return response
Пример #2
0
 def get(self,request,pk):
     if not have_phone_register(user=request.user):
         reply = get_reply(17,'not register with phone')
         return Response(reply,HTTP_403_FORBIDDEN)
     user = request.user
     try:
         borrow_item = BorrowItem.objects.get(user=user,pk=pk)
         serializer = BorrowItemDetailSerializer(borrow_item,data=request.data)
         serializer.is_valid(raise_exception=True)
         for i in serializer.data:
             # 在返回数据中,增加到期时间
             return_time = i['return_time']
             date_list = return_time.split("-")
             year = int(date_list[0])
             month = int(date_list[1])
             day = int(date_list[2])
             return_date = datetime.datetime(year, month, day)
             now_date = datetime.datetime.now()
             due = (return_date - now_date).days
             i['due'] = due
             if i < 7:
                 i['due_in_7'] = True
                 if i < 3:
                     i['due_in_3'] = True
             else:
                 i['due_in_7'] = False
                 i['due_in_3'] = False
         response = Response(serializer.data,HTTP_200_OK)
         return response
     except BorrowItem.DoesNotExist:
         reply = get_reply(20,'item not found')
         response = Response(reply,HTTP_404_NOT_FOUND)
         return response
Пример #3
0
 def post(self,request):
     if not have_phone_register(user=request.user):
         reply = get_reply(17,'not register with phone')
         return Response(reply,HTTP_403_FORBIDDEN)
     serializer = self.serializer_class(data=request.data)
     serializer.is_valid(raise_exception=True)
     id_list = serializer.validated_data['id_list']
     price = get_price(id_list)
     ctime = time.time()
     qrtype = 'borrow'
     borrow_id = ""
     for i in id_list:
         borrow_id += 'b' + str(i)  # 参数最后的样子:id = b1b2b3b56
     # 在这里创建一个pay,得到唯一的pay_id
     pay = PayItem.objects.create(user=request.user,
                                  state=False,
                                  confirm=False,
                                  price = price,
                                  borrow_id=borrow_id,
                                  )
     pay.save()
     pay_id = pay.id
     url = create_qrcode(id_list,ctime,qrtype,pay_id)
     reply = dict()
     reply['url'] = url
     reply['pay_id'] = pay_id
     reply['price'] = pay.price
     return Response(reply,HTTP_200_OK)
Пример #4
0
 def get(self,request):
     if not have_phone_register(user=request.user):
         reply = get_reply(17,'not register with phone')
         return Response(reply,HTTP_403_FORBIDDEN)
     user = request.user
     # 判断借书栏中是否超过2本书籍
     queryset = BorrowItem.objects.filter(user=user,in_return_bar=False,finish_return=False)
     serializer = BorrowItemDetailSerializer(queryset,data=request.data,many=True)
     serializer.is_valid(raise_exception=True)
     response = Response(serializer.data,HTTP_200_OK)
     return response
Пример #5
0
 def get(self,request,pk):
     if not have_phone_register(user=request.user):
         reply = get_reply(17,'not register with phone')
         return Response(reply,HTTP_403_FORBIDDEN)
     borrow_item = BorrowItem.objects.get(pk=pk)
     ctime = time.time()
     qrtype = "borrow"
     create_qrcode(pk,ctime,qrtype,None)
     url = '/media/borrow_qrcode/'+str(pk)+".png"
     borrow_item.qrcode = url
     borrow_item.save()
     content = {'url':url}
     return Response(content,HTTP_200_OK)
Пример #6
0
    def get(self,request,pk):
        if not have_phone_register(user=request.user):
            reply = get_reply(17,'not register with phone')
            return Response(reply,HTTP_403_FORBIDDEN)
        user = request.user
        try:
            borrow_item = BorrowItem.objects.get(user=user, pk=pk)

            serializer = BorrowItemDetailSerializer(borrow_item,data=request.data)
            serializer.is_valid(raise_exception=True)
            response = Response(serializer.data,HTTP_200_OK)
            return response
        except BorrowItem.DoesNotExist:
            reply = get_reply(12,'item not found')
            response = Response(reply,HTTP_404_NOT_FOUND)
            return response
Пример #7
0
    def post(self,request):
        if not have_phone_register(user=request.user):
            reply = get_reply(17,'not register with phone')
            return Response(reply,HTTP_403_FORBIDDEN)
        serializer = BorrowItemCreateSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        isbn13 = serializer.validated_data['isbn13']
        borrow_time = str(time.strftime('%Y-%m-%d',time.localtime(time.time())))
        return_time = str(time.strftime('%Y-%m-%d',time.localtime(time.time()+2419200)))
        book_id = serializer.validated_data['book_id']
        try:
            holding = Holding.objects.get(id=book_id)
            location = holding.location
            l_loaction = ['总馆', '信息馆', '工学馆', '医学馆']
            guide = ['东', '西', '南', '北']
            location_list = location.split("->")
            location = l_loaction[int(location_list[0])] + "借阅区" + str(location_list[1]) + \
                            "楼" + guide[int(location_list[2])]
            find_id = holding.find_id
        except:
            location = find_id = ''
        user = request.user
        try:
            if BorrowItem.objects.get(user=user,book_id=book_id,in_return_bar=False,
                                      finish_return=False):
                reply = get_reply(10,'item existed')
                return Response(reply,HTTP_200_OK)
        except:
            pass
        # 判断购物车中是否超过2本书籍
        borrow_item_list = BorrowItem.objects.filter(user=user,in_return_bar=False,
                                                     finish_return=False)
        if len(borrow_item_list) >= 2:
            reply = get_reply(11,'item over 2')
            return Response(reply,HTTP_200_OK)

        borrow_item = BorrowItem.objects.create(user=user,
                                                isbn13=isbn13,
                                                borrow_time=borrow_time,
                                                return_time=return_time,
                                                find_id =find_id,
                                                book_id= book_id,
                                                location=location)
        borrow_item.save()
        response = Response(serializer.data,HTTP_201_CREATED)
        return response
Пример #8
0
 def post(self,request):
     if not have_phone_register(user=request.user):
         reply = get_reply(17,'not register with phone')
         return Response(reply,HTTP_403_FORBIDDEN)
     serializer = self.serializer_class(data=request.data)
     serializer.is_valid(raise_exception=True)
     id_list = serializer.validated_data['id_list']
     ctime = time.time()
     qrtype = 'return'
     # 创建一个还书item,得到return_id
     return_item = ReturnItem.objects.create(user=request.user,
                                             confirm=False)
     return_item.save()
     return_id = return_item.id
     url = create_return_qrcode(id_list,ctime,qrtype,return_id)
     reply = dict()
     reply['url'] = url
     reply['return_id'] = return_id
     return Response(reply,HTTP_200_OK)
Пример #9
0
 def delete(self,request,pk):
     if not have_phone_register(user=request.user):
         reply = get_reply(17,'not register with phone')
         return Response(reply,HTTP_403_FORBIDDEN)
     user = request.user
     try:
         borrow_item = BorrowItem.objects.get(user=user, pk=pk)
         serializer = BorrowItemDetailSerializer(borrow_item, data=request.data)
         serializer.is_valid(raise_exception=True)
         try:
             borrow_item.delete()
             reply = get_reply(0,'success')
             response = Response(reply,HTTP_200_OK)
             return response
         except:
             content = get_reply(13,'delete fail')
             response = Response(content, HTTP_400_BAD_REQUEST)
             return response
     except BorrowItem.DoesNotExist:
         content = get_reply(12,'item not found')
         response = Response(content, HTTP_404_NOT_FOUND)
         return response