Esempio n. 1
0
 def get(self, request, uid):
     """
     发起与uid的聊天/创建于uid的聊天室
     :param request:
     :param uid: 对方账户的id
     :return: 返回聊天室id
     """
     to_user = UserInfo.objects.get(id=uid)
     myself = getUser(request.session.get('login'))
     chatRoom = ChatRoom.objects.filter(
         ((Q(user1=to_user) & Q(user2=myself)) |
          (Q(user1=myself) & Q(user2=to_user)))
         & Q(is_cancel=False))  # 检查是否已经有该房间
     if chatRoom.exists():
         return JsonResponse({
             'status': True,
             'chat_room_id': chatRoom[0].chatRoomID
         })
     chatRoom = ChatRoom.objects.create(chatRoomID=generateChatRoomID(),
                                        user1=myself,
                                        user2=to_user)
     return JsonResponse({
         'status': False,
         'chat_room_id': chatRoom.chatRoomID
     })
Esempio n. 2
0
    def put(self, requests, tid):
        '''
        用户为发起单添加图片
        :param requests:
        :param tid:
        :return:
        '''
        try:
            tr = TailwindRequest.objects.filter(requestID=tid)
            if not tr.exists:
                return JsonResponse({
                    'status': False,
                    'errMsg': '请求单不存在'
                },
                                    status=404)
            tr = tr[0]
            user = getUser(requests.session.get('login'))
            if tr.initiator != user:
                return JsonResponse({
                    'status': False,
                    'errMsg': '你没有权限操作'
                },
                                    status=401)
            get_img = requests.FILES.get("img")
            tr.img = get_img
            tr.save()
            return JsonResponse({'status': True, 'id': tr.requestID})

        except Exception as ex:
            return JsonResponse({
                'status': False,
                'errMsg': '错误信息:' + str(ex)
            },
                                status=403)
Esempio n. 3
0
 def delete(self, requests, tid):
     """
     用户删除发起单
     :param request:
     :param tid:
     :return:
     """
     try:
         tr = TailwindRequest.objects.filter(requestID=tid)
         if not tr.exists:
             return JsonResponse({
                 'status': False,
                 'errMsg': '请求单不存在'
             },
                                 status=404)
         tr = tr[0]
         user = getUser(requests.session.get('login'))
         if tr.initiator != user:
             return JsonResponse({
                 'status': False,
                 'errMsg': '你没有权限操作'
             },
                                 status=401)
         if tr.status == 'paid':
             # 退款
             pass
         elif tr.status == 'orderT':
             # 告知接单者,同意后退款
             pass
     except Exception as ex:
         return JsonResponse({'status': False, 'errMsg': '错误信息:' + str(ex)})
Esempio n. 4
0
 def get(self, request):
     """
     获取用户的所有接收单
     :param request:
     :return:
     """
     try:
         user = getUser(request.session.get('login'))
         ago = request.GET.get('ago')
         page = request.GET.get('page')
         three_month_ago = get_three_month_ago()
         if ago:
             tailwindTake = TailwindTakeOrder.objects.filter(
                 Q(mandatory=user)
                 & Q(create_time__lte=three_month_ago)  # 小于等于这个时间
             )
         else:
             tailwindTake = TailwindTakeOrder.objects.filter(
                 Q(mandatory=user)
                 & Q(create_time__gte=three_month_ago)  # 大于等于这个时间
             )
         takeList = paginator(tailwindTake, page)
         tailwindTakeOrder = [model_to_dict(tl, exclude='end_time') for tl in takeList]
         return JsonResponse({
             'status': True,
             'takeOrder': tailwindTakeOrder,
             'has_next': takeList.has_next(),
             'has_previous': takeList.has_previous()
         })
     except Exception as ex:
         return JsonResponse({
             'status': False,
             'errMsg': '错误信息:' + str(ex)
         }, status=403)
Esempio n. 5
0
def priority_list(requestOrder, request):
    """
    排序请求单列表,使之更符合目标用户
    版本号 1.0
    :return:
    """
    import json
    from time import localtime, time, strftime
    config = UserConfig.objects.get(relateUser=getUser(
        email=request.session.get('login')))
    # dormitory = config.dormitory  # 宿舍
    common_buildings = json.loads(config.commonAcademicBuilding)
    todayWeek = strftime('%a', localtime(time()))
    building_list = common_buildings[todayWeek]
    if len(building_list) == 0:
        return requestOrder
    else:
        for building in reversed(building_list):  # 使用倒序遍历,表示优先级
            # 将requestOrder里面的有beginPlace放前面
            for requests in requestOrder:
                if requests['beginPlace'] == building:
                    print(requests['requestID'])
                    tmp = requests
                    requestOrder.remove(requests)
                    requestOrder.insert(0, tmp)
        return requestOrder
    pass
Esempio n. 6
0
 def delete(self, request):
     '''
     登出账户
     :param request:
     :return:
     '''
     user = getUser(request.session.get('login'))
     # 删除服务器session
     request.session['login'] = None
     return JsonResponse({'status': True, 'id': user.id})
Esempio n. 7
0
    def get(self, request):
        '''
        获取当前用户的单子计数器,身份验证情况
        :param request:
        :return:
        '''
        user = getUser(request.session.get('login'))
        '''
        请求单
        未支付(unpaid) --》 支付后等待接单(paid) --》 接单后等待完成(orderT) --》 完成后变成待评价(waitR) --》评价后就完成了(accomplish)
        '''
        # 统计订单情况
        # 统计未支付的订单数量
        unpaid_number = TailwindRequest.objects.filter(
            Q(initiator=user) & Q(status='unpaid')).count()
        # 统计等待接单订单数量
        waiting_number = TailwindRequest.objects.filter(
            Q(initiator=user) & Q(status='paid')).count()
        # 统计(已接单)待完成订单数量
        waiting_for_finish_number = TailwindRequest.objects.filter(
            Q(initiator=user) & Q(status='orderT')).count()
        # 统计未评价订单数量
        unrated_number = TailwindRequest.objects.filter(
            Q(initiator=user) & Q(status='waitR')).count()
        # 统计自己正在进行中的接收单
        inProcess_number = TailwindTakeOrder.objects.filter(
            Q(mandatory=user) & Q(status='unaccomplished')).count()

        tailwind_number = {
            'unpaid_number': str(unpaid_number),
            'waiting_number': str(waiting_number),
            'waiting_for_finish_number': str(waiting_for_finish_number),
            'unrated_number': str(unrated_number),
            'inProcess_number': str(inProcess_number)
        }

        userAuthentication = {}

        if user.user_role == '5':
            userAuthentication['email_active'] = False
        else:
            userAuthentication['email_active'] = True
        if user.student_id != 0:
            userAuthentication['es_check'] = True
        else:
            userAuthentication['es_check'] = False

        return JsonResponse({
            'status': True,
            'userAuthentication': userAuthentication,
            'tailwind_number': tailwind_number
        })
Esempio n. 8
0
 def get(self, request):
     """
     获得用户发起的订单
     :param request:
     :return:
     """
     try:
         user = getUser(email=request.session.get('login'))
         page = request.GET.get('page')
         ago = request.GET.get('ago')
         types = request.GET.get('type')
         three_month_ago = get_three_month_ago()
         type_list = [
             'unpaid', 'paid', 'orderT', 'waitR', 'accomplish', 'cancel'
         ]
         if not types:  # 没有对应的url参数,查询全部类型的
             types = type_list
         elif types not in type_list:  # 参数不合法
             types = ['unpaid']
         else:  # 参数合法,查询对应类型
             types = [types]
         if ago:
             # 获取三个月前的订单
             tailwindObj = TailwindRequest.objects.filter(
                 Q(initiator=user)
                 & Q(beginTime__lte=three_month_ago)
                 & Q(status__in=types))
         else:
             # 获取三个月内的
             tailwindObj = TailwindRequest.objects.filter(
                 Q(initiator=user)
                 & Q(beginTime__gte=three_month_ago)
                 & Q(status__in=types))
         tailwindList = paginator(tailwindObj, page)
         tailwind = [
             model_to_dict(t, fields=self.COMMON_FIELDS)
             for t in tailwindList
         ]
         return JsonResponse({
             'status': True,
             'tailwind': tailwind,
             'has_next': tailwindList.has_next(),
             'has_previous': tailwindList.has_previous()
         })
     except Exception as ex:
         return JsonResponse({
             'status': False,
             'errMsg': '错误信息:' + str(ex)
         },
                             status=403)
Esempio n. 9
0
 def get(self, request):
     '''
     用于检查是否登录
     :param request:
     :return:
     '''
     if request.session.get('login', None):
         return JsonResponse({
             'status': True,
             'id': getUser(request.session.get('login')).id
         })
     else:
         return JsonResponse({
             'status': False,
             'errMsg': '你还未登录'
         },
                             status=401)
Esempio n. 10
0
 def put(self, request, rid):
     """
     用户接单
     :param request:
     :param rid: request id
     :return:
     """
     try:
         user = getUser(request.session.get('login'))  # 接单人对象
         tailwindRequest = getRequest(rid)
         if not tailwindRequest:
             return JsonResponse({
                 'status': False,
                 'errMsg': '请求单不存在或已经被接单啦'
             }, status=401)
         newID = generateNewTakeID(tailwindRequest.requestID)
         if int(str(newID)[-2:]) >= 11:
             '''怀疑恶意接单'''
             tailwindRequest.status = 'cancel'
             tailwindRequest.save()
             return JsonResponse({
                 'status': False,
                 'errMsg': "订单已被取消"
             }, status=401)
         newTakeOrder = TailwindTakeOrder.objects.create(
             takeID=newID,
             mandatory=user,
             tailwindRequest=tailwindRequest
         )
         # 修改request单的状态
         tailwindRequest.status = 'orderT'
         tailwindRequest.save()
         # 新建实时位置数据库对象
         realLocation = TakeOrderUserRealtimeLocation.objects.create(relateTakeOrder=newTakeOrder)
         return JsonResponse({
             'status': True,
             'newTakeID': newTakeOrder.takeID,
             'real_location': realLocation.id
         })
     except Exception as ex:
         return JsonResponse({
             'status': False,
             'errMsg': '错误信息:' + str(ex)
         }, status=403)
Esempio n. 11
0
 def post(self, request):
     '''
     新增/更换头像
     :param request:
     :return:
     '''
     try:
         user = getUser(email=request.session.get('login'))
         head_portrait = request.FILES.get('img')
         user.head_portrait = head_portrait
         user.save()
         return JsonResponse({
             'status': False,
             'id': user.id
         })
     except Exception as ex:
         return JsonResponse({
             'status': False,
             'errMsg': '错误信息:' + str(ex)
         })
Esempio n. 12
0
    def post(self, request):
        """
        用户发起订单
        :param request:
        :return:
        """
        try:
            user = getUser(email=request.session.get('login'))
            jsonParam = json.loads((request.body).decode('utf-8'))

            taskContent = jsonParam.get('taskContent')
            serviceType = jsonParam.get('type')
            beginPlace = jsonParam.get('begin_place')
            endPlace = jsonParam.get('end_place')
            money = float(jsonParam.get('money'))
            endTime = datetime.datetime.strptime(jsonParam.get('end_time'),
                                                 '%Y-%m-%d %H:%M:%S')

            newTailwindRequest = TailwindRequest.objects.create(
                requestID=generateRequestID(),
                taskContent=taskContent,
                serviceType=serviceType,
                beginPlace=beginPlace,
                endPlace=endPlace,
                money=money,
                endTime=endTime,
                beginTime=now(),
                initiator=user)

            return JsonResponse({
                'status': True,
                'id': newTailwindRequest.requestID,
            })

        except Exception as ex:
            return JsonResponse({
                'status': False,
                'errMsg': '错误信息:' + str(ex)
            },
                                status=403)
Esempio n. 13
0
    def post(self, request):
        """
        学生认证接口
        :param request:
        :return:
        """
        try:
            user = getUser(request.session.get('login'))
            if user.student_id != 0:
                return JsonResponse({
                    'status': False,
                    'errMsg': '账号已经认证过了'
                },
                                    status=401)
            jsonParams = json.loads((request.body).decode('utf-8'))
            stuID = jsonParams.get('username')
            password = jsonParams.get('password')
            check_result = BNUZ_es_check(stuID, password)
            if check_result:
                user.RealName = check_result['name']
                user.student_id = stuID
                user.save()
                return JsonResponse({
                    'status': True,
                    'student_id': stuID,
                    'real_name': user.RealName
                })
            else:
                return JsonResponse({
                    'status': False,
                    'errMsg': '验证失败'
                },
                                    status=401)

        except Exception as ex:
            return JsonResponse({
                'status': False,
                'errMsg': '错误信息:' + str(ex)
            },
                                status=403)
Esempio n. 14
0
 def get(self, request, uid=0):
     '''
     用户主页(用户详细信息)
     :param request:
     :param uid:
     :return:
     '''
     if uid == 0:
         # 查看自己的信息
         user = getUser(request.session.get('login'))
         MYSELF_FIELDS = [
             'RealName', 'age', 'joined_date', 'TimesOfTake', 'TimesOfRequest'
         ]
         self.INCLUDE_FIELDS += MYSELF_FIELDS
     else:
         # 查看他人的信息(同时获取发起订单的列表)
         user = UserInfo.objects.filter(id=uid)
         if not user.exists():
             return JsonResponse({
                 'status': False,
                 'errMsg': '用户不存在'
             }, status=404)
         user = user[0]
     userInformation = model_to_dict(user, fields=self.INCLUDE_FIELDS)
     for i in user.roles:
         if i[0] == user.user_role:
             userInformation['role'] = i[1]
             break
     if user.head_portrait:
         userInformation['head_portrait'] = 'https://freetime-oss.oss-cn-shenzhen.aliyuncs.com/media/' + str(
             user.head_portrait)
     else:
         userInformation['head_portrait'] = False
     return JsonResponse({
         'status': True,
         'information': userInformation
     })