コード例 #1
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def addUser(request):
    if request.method == 'POST':
        userIds = request.POST.get('userIds').split(',')  # 字符串转列表
        userType = request.POST.get('userType')
        createUser = request.POST.get('createUser')

        if userIds is None or userType is None:
            return jsonResponse.error('Parameter error!')
        access_token = get_token.is_time()
        try:
            if "error" in access_token:
                return jsonResponse.error(access_token['error'])
        except:
            pass
        try:
            # 用户已存在,修改角色类型
            for item in userIds:
                user = models.UserInfo.objects.get(userId=item)
                user.persona = userType
                user.updateUser = createUser
                user.save()
            return jsonResponse.success(True)
        except:
            # 不存在则新建
            for item in userIds:
                params2 = {
                    'access_token': access_token,
                    'userid': item,
                }
                res = requests.get('https://oapi.dingtalk.com/user/get',
                                   params=params2,
                                   headers={'Connection': 'close'})
                res1 = res.json()
                if 'errcode' in res:
                    return jsonResponse.error('The user could not be found')
                add_data = {
                    'userId': res1['userid'],
                    'name': res1['name'],
                    'persona': userType,
                    'department': ','.join(map(str, res1['department'])),
                    'position': res1['position'] if 'position' in res1 else '',
                    'avatar': res1['avatar'],
                    'jobNumber':
                    res1['jobNumber'] if 'jobNumber' in res1 else '',
                    'createUser': createUser,
                }
                serializer = serializers.UserInfoSerializer(data=add_data)
                if serializer.is_valid():
                    serializer.save()
                else:
                    pass
            return jsonResponse.success(True)
    return jsonResponse.error('page not found')
コード例 #2
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def getUserInfo(request):
    if request.method == 'GET':
        code = request.GET.get('code')
        access_token = get_token.is_time()
        url = 'https://oapi.dingtalk.com/user/getuserinfo'
        payload = {'access_token': access_token, 'code': code}
        res_data = requests.get(url, params=payload)
        res = res_data.json()

        if 'userid' in res:
            try:
                # 已存在的用户直接返回
                users = models.UserInfo.objects.get(userId=res['userid'])
            except:
                # 第一次使用的用户添加到数据库中
                params2 = {
                    'access_token': access_token,
                    'userid': res['userid']
                }
                res = requests.get('https://oapi.dingtalk.com/user/get',
                                   params=params2,
                                   headers={'Connection': 'close'})
                res1 = res.json()
                add_data = {
                    'userId': res1['userid'],
                    'name': res1['name'],
                    'type': 0,
                    'department': ','.join(map(str, res1['department'])),
                    'position': res1['position'] if 'position' in res1 else '',
                    'avatar': res1['avatar'],
                    'jobNumber':
                    res1['jobNumber'] if 'jobNumber' in res1 else '',
                }
                serializer = serializers.UserInfoSerializer(data=add_data)
                serializer.is_valid()
                serializer.save()
                return jsonResponse.success(serializer.data)
            serializer = serializers.UserInfoSerializer(users)
            ser = serializer.data
            # 获取部门名字
            id = ser['department']
            payload = {'access_token': access_token, 'id': id}
            res = requests.get('https://oapi.dingtalk.com/department/get',
                               params=payload)
            res1 = res.json()
            ser['departmentName'] = res1['name']
            return jsonResponse.success(ser)
        else:
            return jsonResponse.error(res['errmsg'])
    return jsonResponse.error('请求方式错误')
コード例 #3
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def getAllAssign(request):
    if request.method == 'POST':
        try:
            pageIndex = int(request.POST.get('pageIndex'))
            pageSize = int(request.POST.get('pageSize'))
        except:
            return jsonResponse.error('参数错误')
        startIndex = (pageIndex * pageSize) - pageSize
        endIndex = pageIndex * pageSize
        try:
            total = models.Assign.objects.all().count()
            assign_all = models.Assign.objects.all()[startIndex:endIndex]
        except models.Assign.DoesNotExist:
            return jsonResponse.error('数据不存在')
        try:
            serializer = serializers.AssignSerializer(assign_all, many=True)
            res = serializer.data
            as_list = []
            for item in res:
                as_list.append(item['id'])
            assign_detail1 = models.AssignDetail1.objects.filter(
                assignId__in=as_list)
            serializer1 = serializers.Detail1Serializer(assign_detail1,
                                                        many=True)
            return jsonResponse.success({
                "data": serializer.data,
                "total": total,
                'detail1': serializer1.data
            })
        except Exception as e:
            return jsonResponse.error(e)
    return jsonResponse.error('请求方式错误')
コード例 #4
0
def driver_data_all(request):
    if request.method == 'POST':
        driver_name = request.POST.get('tableData')
        try:
            pageIndex = int(request.POST.get('pageIndex'))
            pageSize = int(request.POST.get('pageSize'))
        except:
            return jsonResponse.error('参数错误')
        startIndex = (pageIndex * pageSize) - pageSize
        endIndex = pageIndex * pageSize
        try:
            # 司机派车任务数量(明细2)
            total = models.AssignDetail2.objects.filter(
                driverId__driverName=driver_name, type=0).count()
            # 根据创建时间排序 最新的数据显示在最上方
            vehicle_all = models.AssignDetail2.objects.filter(
                driverId__driverName=driver_name,
                type=0).order_by('id')[startIndex:endIndex]
        except models.ReturnOrder.DoesNotExist:
            return jsonResponse.error('数据不存在')
        detail2 = serializers.Detail2Serializer(vehicle_all, many=True)
        detail2_data = detail2.data

        return jsonResponse.success({
            'data': detail2_data,
            'total': total,
        })
    return jsonResponse.error('请求错误')
コード例 #5
0
def show_assign(request):
    if request.method == 'GET':
        try:
            id = request.GET.get('id')
            # 用户一进入使用用户接口获取userid 从用户表中找到名字再去明细2表中查找对应的派车单,结合关联的用车单一起展示单张需要司机填写的回程表首页
            detail2 = models.AssignDetail2.objects.get(id=int(id))
            serializer = serializers.Detail2Serializer(detail2)
            # 明细2数据
            detail2_data = serializer.data
            as_id = detail2_data['assignId']
            assign = models.Assign.objects.get(id=int(as_id))
            assign_data = serializers.AssignSerializer(assign)
            ass = assign_data.data
            detail1 = models.AssignDetail1.objects.filter(assignId=as_id)
            # 明细1数据
            datail1_data = serializers.Detail1Serializer(detail1, many=True)
            datail1_ser = datail1_data.data[0]

            # 整合数据
            dict_data = {}
            for item in ass:
                dict_data[item] = ass[item]
            for item1 in datail1_ser:
                dict_data[item1] = datail1_ser[item1]
            for item2 in detail2_data:
                dict_data[item2] = detail2_data[item2]

            return jsonResponse.success(dict_data)
        except Exception as e:
            return jsonResponse.error(e)
    else:
        return jsonResponse.error('数据不存在')
コード例 #6
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def getAssign(request):
    if request.method == 'GET':
        assign_id = request.GET.get('id')  # 派车单id
        try:
            as_id = models.Assign.objects.get(id=int(assign_id))
            detail1 = models.AssignDetail1.objects.filter(assignId=as_id)
            detail2 = models.AssignDetail2.objects.filter(assignId=as_id)
            serializer = serializers.AssignSerializer(as_id)
            serializer1 = serializers.Detail1Serializer(detail1, many=True)
            serializer2 = serializers.Detail2Serializer(detail2, many=True)
            data = serializer.data
            data = {
                'data': data,
                'detail1': serializer1.data,
                'detail2': serializer2.data
            }
            # return_data = {}
            # for item in data:
            #     return_data[item] = data[item]
            # for item1 in serializer1.data:
            #     return_data[item1] = serializer1.data[item1]
            # for item2 in serializer2.data:
            #     return_data[item2] = serializer2.data[item2]

            return jsonResponse.success(data)
        except models.Assign.DoesNotExist:
            return jsonResponse.error('数据不存在')
    return jsonResponse.error('请求方式错误')
コード例 #7
0
def getVehicleReturn(request):
    if request.method == 'GET':
        try:
            veh_id = request.GET.get('id')
            veh_data = models.ReturnOrder.objects.get(id=int(veh_id))
        except models.ReturnOrder.DoesNotExist:
            return jsonResponse.error('数据不存在')
        serializer = serializers.ReturnOrderSerializer(veh_data)
        veh_ser_data = serializer.data
        detail2_id = veh_ser_data['assignDetail2Id']  # 从回程表中获取明细表2id

        # 序列化明细2表
        detail2 = models.AssignDetail2.objects.get(id=detail2_id)
        detail2_data = serializers.Detail2Serializer(detail2)
        d2 = detail2_data.data
        detail1_id = d2['assignId']  # 获取派车单id

        # 序列化明细1表
        detail1 = models.AssignDetail1.objects.filter(assignId=detail1_id)
        detail1_data = serializers.Detail1Serializer(detail1, many=True)
        d1 = detail1_data.data[0]

        # 整合返回数据
        dict_data = {}
        for item1 in d1:
            dict_data[item1] = d1[item1]
        for item2 in d2:
            dict_data[item2] = d2[item2]
        for item in veh_ser_data:
            dict_data[item] = veh_ser_data[item]
        return jsonResponse.success(dict_data)
    return jsonResponse.error('请求方式错误')
コード例 #8
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def excel_upload(request):
    """
    :param request:
    :return: 上传文件excel表格 ,并进行解析
    """
    if request.method == "POST":
        f = request.FILES['my_file']
        createUser = request.POST.get('createUser')
        type_excel = f.name.split('.')[1]
        if 'xlsx' == type_excel:
            # 开始解析上传的excel表格
            wb = xlrd.open_workbook(filename=None,
                                    file_contents=f.read())  # 关键点在于这里
            table = wb.sheets()[0]
            nrows = table.nrows  # 行数
            # ncole = table.ncols  # 列数
            try:
                with transaction.atomic():
                    for i in range(1, nrows):
                        rowValues = table.row_values(i)  # 一行的数据
                        models.DepartureInfo.objects.create(
                            departure=rowValues[0], createUser=createUser)
            except Exception as e:
                return jsonResponse.error(e, {'msg': '出现错误....'})
            return jsonResponse.success({'msg': 'ok'})
        return jsonResponse.error({'msg': '上传文件格式不是xlsx'})
    return jsonResponse.error({'msg': '不是post请求'})
コード例 #9
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def updateDestFee(request):
    if request.method == 'POST':
        destfee_Id = request.POST.get('id')
        updata_data = {
            'departureInfoId': request.POST.get('departureInfoId'),
            'dest': request.POST.get('dest'),
            'internalFee': request.POST.get('internalFee'),
            'marketFee': request.POST.get('marketFee'),
            'carModelId': request.POST.get('carModelId'),
            'channel': request.POST.get('channel'),
            'otherNote': request.POST.get('otherNote'),
            'updateUser': request.POST.get('updateUser'),
        }
        print('data', updata_data)
        try:
            dest_id = models.DestFee.objects.get(id=int(destfee_Id))
        except models.DestFee.DoesNotExist:
            return jsonResponse.error('数据不存在')
        serializer = DestFeeSerializer(dest_id, data=updata_data)
        if serializer.is_valid():
            serializer.save()
            print('ser_data', serializer.data)
            return jsonResponse.success(True)
        else:
            print('error', serializer.errors)
            return jsonResponse.error(serializer.errors)
    return jsonResponse.error('请求方式错误')
コード例 #10
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def createdateDriver(request):
    if request.method == 'POST':
        name = request.POST.get('driverId')  # 获取添加数据
        phone = request.POST.get('phone')
        factory = request.POST.get('factoryId')
        createUser = request.POST.get('createUser')
        try:
            models.Driver.objects.get(driverName=name)
            # 数据已存在 返回提示
            return jsonResponse.error('司机已存在,请勿重复添加')
        # 数据不存在则进行添加
        except models.Driver.DoesNotExist:
            data = {
                'driverName': name,
                'phone': phone,
                'factoryId': factory,
                'createUser': createUser
            }
            serializer = DriverSerializer(data=data)
            if serializer.is_valid():
                serializer.save()
                return jsonResponse.success(True)
            else:
                return jsonResponse.error('创建失败')
    return jsonResponse.error('请求方式错误')
コード例 #11
0
def updateCarInfo(request):
    if request.method == 'POST':
        car_id = request.POST.get('id')
        try:
            carinfo_id = models.CarInfo.objects.get(id=int(car_id))
        except models.CarInfo.DoesNotExist:
            return jsonResponse.error('数据不存在')
        # 根据参数对数据库进行数据修改
        updata_data = {
            'factoryId': request.POST.get('factoryId'),
            'licensePlate': request.POST.get('licensePlate'),
            'carModelId': request.POST.get('carModelId'),
            'number': request.POST.get('number'),
            'driverId': request.POST.get('driverId'),
            'carFuel': request.POST.get('carFuel'),
            'extraKm': request.POST.get('extraKm'),
            'extraKmPrice': request.POST.get('extraKmPrice'),
            'remark': request.POST.get('remark'),
            'updateUser': request.POST.get('updateUser'),
        }
        serializer = serializers.CarInfoSerializer(carinfo_id,
                                                   data=updata_data)
        if serializer.is_valid():
            serializer.save()
            return jsonResponse.success(True)
        else:
            return jsonResponse.error(serializer.errors)
    return jsonResponse.error('请求方式错误')
コード例 #12
0
def updateVehicleReturn(request):
    if request.method == 'POST':
        try:
            veh_id = request.POST.get('id')
            veh_data = models.ReturnOrder.objects.get(id=int(veh_id))
        except models.ReturnOrder.DoesNotExist:
            return jsonResponse.error('数据不存在')
        updata = {
            'startMileage': request.POST.get('startmileage'),
            'returnMileage': request.POST.get('returnmileage'),
            'oilVolume': request.POST.get('oilvolume'),
            'toll': request.POST.get('toll'),
            'parkingFee': request.POST.get('parkingfee'),
            'expresswayFee': request.POST.get('expresswayfee'),
            'overtime': request.POST.get('overtime'),
            'mealFee': request.POST.get('mealfee'),
            'otherFee': request.POST.get('otherfee'),
            'remark': request.POST.get('remark'),
            'approvalUser': request.POST.get('name'),
            'updateUser': request.POST.get('userid'),
        }
        serializer = serializers.ReturnOrderSerializer(veh_data, data=updata)
        if serializer.is_valid():
            serializer.save()
            return jsonResponse.success('修改成功')
        else:
            return jsonResponse.error(serializer.errors)
    return jsonResponse.error('请求方式错误')
コード例 #13
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def deleteUser(request):
    if request.method == 'GET':
        userId = request.GET.get('userId')
        user = isUser(userId)
        user.delete()
        return jsonResponse.success(True)
    return jsonResponse.error('page not found')
コード例 #14
0
def approval_apply(request):
    if request.method == 'POST':
        apply_id = request.POST.get('id')
        user = request.POST.get('updateUser')
        statu = request.POST.get('status')
        approvalOpinion = request.POST.get('approvalOpinion')
        now_time = datetime.datetime.now().strftime('%Y-%m-%d')
        try:
            ap_id = models.Apply.objects.get(id=int(apply_id))
            orderNo = ap_id.orderNo.orderNo
        except models.Apply.DoesNotExist:
            return jsonResponse.error('数据不存在')
        updata_data = {
            'approvalStatus': statu,
            'approvalOpinion': approvalOpinion,
            'updateUser': user,
            'approvalUserId': user,
            'approvalDate': now_time
        }
        serializer = serializers.ApprovalChange(ap_id, data=updata_data)
        if serializer.is_valid():
            serializer.save()
            user_list = []
            assign_list = []

            if statu == "2":
                # 发送审核不通过通知给申请人
                user_data = models.Apply.objects.get(
                    id=int(apply_id)).serializable_value('userId')
                user_list.append(user_data)
                message_send.approval_veto_send(user_list, orderNo,
                                                approvalOpinion)

            elif statu == "1":
                # 发送审核通过通知给申请人
                user_data = models.Apply.objects.get(
                    id=int(apply_id)).serializable_value('userId')
                name = models.UserInfo.objects.get(
                    userId=user_data).serializable_value('name')
                user_list.append(name)
                message_send.approval_pass_send(user_list, orderNo)

                # 发送通知给派车员分派车辆 找到用户表中所有的派车员
                try:
                    assign_user = models.UserInfo.objects.filter(persona=3)
                except:
                    return jsonResponse.error('无派车员')
                serializer2 = serializers.UserInfoSerializer(assign_user,
                                                             many=True)
                for item in serializer2.data:
                    assign_list.append(item['userId'])
                user_lis = ','.join(assign_list)
                message_send.assign_car(user_lis, name)
            return jsonResponse.success(True)
        else:
            return jsonResponse.error(serializer.errors)
    return jsonResponse.error('请求方式错误')
コード例 #15
0
def deleteApply(request):
    if request.method == 'GET':
        apply_id = request.GET.get('id')
        try:
            ap_id = models.Apply.objects.get(id=int(apply_id))
        except models.Apply.DoesNotExist:
            return jsonResponse.error('数据不存在')
        ap_id.delete()
        return jsonResponse.success('删除成功')
    return jsonResponse.error('请求方式错误')
コード例 #16
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def getCarModel(request):
    if request.method == 'GET':
        id = request.GET.get('id')
        try:
            carModel_id = models.CarModel.objects.get(id=int(id))
        except models.CarModel.DoesNotExist:
            return jsonResponse.error('数据不存在')
        serializer = CarModelDetailSerializer(carModel_id)
        return jsonResponse.success(serializer.data)
    return jsonResponse.error('请求方式错误')
コード例 #17
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def deleteCarModel(request):
    if request.method == 'GET':
        id = request.GET.get('id')
        try:
            name = models.CarModel.objects.get(id=id)
        except models.CarModel.DoesNotExist:
            return jsonResponse.error('数据不存在')
        name.delete()
        return jsonResponse.success(True)
    return jsonResponse.error('请求方式错误')
コード例 #18
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def getDriver(request):
    if request.method == 'GET':
        driver_id = request.GET.get('id')
        try:
            id = models.Driver.objects.get(id=int(driver_id))
        except models.Driver.DoesNotExist:
            return HttpResponse('False', status=204)
        serializer = DriverSerializer(id)
        return jsonResponse.success(serializer.data)
    return jsonResponse.error('请求方式错误')
コード例 #19
0
def deleteCarInfo(request):
    if request.method == 'GET':
        car_id = request.GET.get('id')
        try:
            id = models.CarInfo.objects.get(id=int(car_id))
        except models.CarInfo.DoesNotExist:
            return jsonResponse.error('数据不存在')
        id.delete()
        return jsonResponse.success(True)
    return jsonResponse.error('请求方式错误')
コード例 #20
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def getDestFee(request):
    if request.method == 'GET':
        id = request.GET.get('id')
        try:
            dest_id = models.DestFee.objects.get(id=int(id))
        except models.DestFee.DoesNotExist:
            return jsonResponse.error('数据不存在')
        serializer = DestFeeSerializer(dest_id)
        return jsonResponse.success(serializer.data)
    return jsonResponse.error('请求方式错误')
コード例 #21
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def getFactory(request):
    if request.method == 'GET':
        id = request.GET.get('id')
        try:
            factory_id = models.Factory.objects.get(id=int(id))
        except models.Factory.DoesNotExist:
            return jsonResponse.error('数据不存在')
        serializer = FactoryDetailSerializer(factory_id)
        return jsonResponse.success(serializer.data)
    return jsonResponse.error('请求方式错误')
コード例 #22
0
def getCarInfo(request):
    if request.method == 'GET':
        car_id = request.GET.get('id')
        try:
            id = models.CarInfo.objects.get(id=int(car_id))
        except models.CarInfo.DoesNotExist:
            return jsonResponse.error('数据不存在')
        serializer = serializers.CarInfoSerializer(id)
        return jsonResponse.success(serializer.data)
    return jsonResponse.error('请求方式错误')
コード例 #23
0
def getApply(request):

    if request.method == 'GET':
        apply_id = request.GET.get('id')
        try:
            ap_id = models.Apply.objects.get(id=int(apply_id))
        except models.Apply.DoesNotExist:
            return jsonResponse.error('数据不存在')
        serializer = serializers.applySerializer(ap_id)
        return jsonResponse.success(serializer.data)
    return jsonResponse.error('请求方式错误')
コード例 #24
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def deleteDestFee(request):

    if request.method == 'GET':
        destId = request.GET.get('id')
        try:
            as_id = models.DestFee.objects.get(id=int(destId))
        except models.DestFee.DoesNotExist:
            return jsonResponse.error('数据不存在')
        as_id.delete()
        return jsonResponse.success(True)
    return jsonResponse.error('请求方式错误')
コード例 #25
0
def createOrderNo(request):
    if request.method == 'POST':
        ord_no = request.POST.get('ord_no')
        data = {
            'orderNo': ord_no,
            'createDate': "2018-12-31",
        }
        serializer = serializers.OrderNumberSerializer(data=data)
        serializer.is_valid()
        serializer.save()
        return jsonResponse.success(serializer.data)
コード例 #26
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def deleteDriver(request):
    if request.method == 'GET':
        driver_id = request.GET.get('id')
        try:
            delete_driver = models.Driver.objects.get(id=driver_id)
        # 司机没有数据
        except models.Driver.DoesNotExist:
            return jsonResponse.error('数据不存在')
        # 司机数据存在 执行删除语句
        delete_driver.delete()
        return jsonResponse.success(True)
    return jsonResponse.error('请求方式错误')
コード例 #27
0
def query_history(request):
    if request.method == 'POST':
        applyUser = request.POST.get('applyUser')
        applyDepart = request.POST.get('applyDepart')
        driver_name = request.POST.get('driverName')
        driver_phone = request.POST.get('driver_phone')
        license_plate = request.POST.get('licensePlate')
        dest = request.POST.get('dest')
        # start_time = request.POST.get('startTime')
        # end_time = request.POST.get('endTime')

        # try:
        #     user_id = models.UserInfo.objects.get(name=applyUser).serializable_value('userId')
        #     driver_id = models.UserInfo.objects.get(name=driver_name).serializable_value('userId')
        # except models.UserInfo.DoesNotExist:
        #     return jsonResponse.error('用户不存在')

        kwargs = {}
        apply = {}
        if applyUser != '':
            userId = models.UserInfo.objects.get(
                name=applyUser).serializable_value('userId')
            apply['apply_data'] = userId
        if applyDepart != '':
            # apply_depart = models.Apply.objects.filter(applyDepart=applyDepart)
            apply['applyDepart'] = applyDepart
        if driver_name != '':
            driver_id = models.UserInfo.objects.get(
                name=driver_name).serializable_value('userId')
            driver = models.Driver.objects.filter(driverName=driver_id)
            driver_ser = serializers.DriverSerializer(driver, many=True)
            driver_data = driver_ser.data
            kwargs['driverName'] = driver_data
        if driver_phone != '':
            kwargs['phone'] = driver_phone
        if license_plate != '':
            kwargs['licensePlate'] = license_plate
        if dest != '':
            kwargs['destId'] = dest
        print('kwargs', kwargs)
        # 从回程表中查找
        # quest = models.ReturnOrder.objects.filter(**kwargs, assignDetail2Id__driverId__driverName=)

        # 用车单
        # apply = models.Apply.objects.filter(**kwargs)
        # apply_ser = serializers.ApplySerializer(apply, many=True)
        # print('data', apply_ser.data)

        # 司机表
        # driver = models.Driver.objects.filter(**kwargs)
        # driver_ser = serializers.DriverSerializer(driver, many=True)
        # print('driver_data', driver_ser.data)
        return jsonResponse.success(kwargs)
コード例 #28
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def deleteDeparture(request):
    if request.method == 'GET':
        id = request.GET.get('id')
        try:
            departure = models.DepartureInfo.objects.get(id=int(id))
        # 出发地没有数据
        except models.DepartureInfo.DoesNotExist:
            return jsonResponse.error('数据不存在')
        # 出发地数据存在 执行删除语句
        departure.delete()
        return jsonResponse.success(True)
    return jsonResponse.error('请求方式错误')
コード例 #29
0
ファイル: views.py プロジェクト: erudamoxiu/AssignCar
def deleteFactory(request):
    if request.method == 'GET':
        id = request.GET.get('id')
        print('id', id)
        try:
            factory_id = models.Factory.objects.get(id=int(id))
            print("factory_id", factory_id)
        except models.Factory.DoesNotExist:
            return jsonResponse.error('数据不存在')
        factory_id.delete()
        return jsonResponse.success(True)
    return jsonResponse.error('请求方式错误')
コード例 #30
0
def approval_vchiclereturn(request):
    if request.method == 'POST':
        id = request.POST.get('id')
        user = request.POST.get('approvalUser')  # 审核员
        statu = request.POST.get('status')
        approvalExplanation = request.POST.get('approvalExplanation')
        try:
            ap_id = models.ReturnOrder.objects.get(id=int(id))
        except models.Apply.DoesNotExist:
            return jsonResponse.error('数据不存在')
        updata_data = {
            'approvalStatus': statu,
            'approvalExplanation': approvalExplanation,
            'approvalUser': user,
            'updateUser': user,
        }
        serializer = serializers.ReturnOrderApprovaSerializer(ap_id,
                                                              data=updata_data)
        if serializer.is_valid():
            serializer.save()
            user_list = []

            detail_id = models.ReturnOrder.objects.get(
                id=int(id)).serializable_value('assignDetail2Id')
            # 审核后发送通知 获取司机的userid
            obj = models.AssignDetail2.objects.get(id=int(detail_id))
            ser = serializers.Detail2Serializer(obj)
            orderNo = ser.data['orderNo']
            driver_id = ser.data['driverId']
            driver_name = models.Driver.objects.get(
                id=int(driver_id)).serializable_value('driverName')
            user_list.append(driver_name)  # 司机userid

            if statu == "2":
                # 司机回程单改为未填写让其重新填写
                obj = models.AssignDetail2.objects.get(id=int(detail_id))
                obj.type = "0"
                obj.save()
                # 发送拒审消息和原因,提示司机重新填写回程单
                message_send.approval_veto_send(user_list, orderNo,
                                                approvalExplanation)

                # 将回程单删除-司机重新创建回程单
                models.ReturnOrder.objects.get(id=int(id)).delete()

            elif statu == "1":
                # 审核通过发送通知给司机
                message_send.return_pass(user_list, orderNo)
            return jsonResponse.success(True)
        else:
            return jsonResponse.error(serializer.errors)
    return jsonResponse.error('请求方式错误')