示例#1
0
def tableInfo(request):
    response = {}
    response['data'] = {}
    response['errorMsg'] = ""
    _shopId = request.session.get('shopId')
    if not _shopId:
        response['code'] = 1
        response['errorMsg'] = '请先登录'
        return HttpResponse(json.dumps(response),content_type="application/json")
    ##################JUDGE############
    _lastLoginTime = request.session.get('lastLoginTime')
    if not _lastLoginTime:
        response['code'] = 1
        response['errorMsg'] = '请先登录'
        return HttpResponse(json.dumps(response),content_type="application/json")
    try:
        shop = Shop.objects.get(id = _shopId)
    except ObjectDoesNotExist:
        response['code'] = 1
        response['errorMsg'] = '请先登录'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if _lastLoginTime != shop.lastLoginTime:
        response['code'] = 1
        response['errorMsg'] = '上次登录失效,请重新登录'
        return HttpResponse(json.dumps(response),content_type="application/json")
    ####################END#################

    _method = request.REQUEST.get('method')
    if _method == None or _method == '':
        response['code'] = -1
        response['errorMsg'] = '获取method失败'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    _method = str(_method)

    #if method = 0 , add;  method = 2 , queryOne; method = 3, delete
    if _method == '0':
        _tableNumber = request.REQUEST.get('tableNumber')
        if _tableNumber == None or _tableNumber == '':
            response['code'] = -1
            response['errorMsg'] = '请输入餐桌号'
            return HttpResponse(json.dumps(response),content_type="application/json")
        _peopleNumber = request.REQUEST.get('tablePeopleNumber')
        if _peopleNumber == None or _peopleNumber == '':
            response['code'] = -1
            response['errorMsg'] = '请输入最大容纳人数'
            return HttpResponse(json.dumps(response),content_type="application/json")
        _tableCategoryList = request.REQUEST.get('tableCategoryList')
        if _tableCategoryList == None or _tableCategoryList == '':
            response['code'] = -1
            response['errorMsg'] = '请输入对应关系'
            return HttpResponse(json.dumps(response),content_type="application/json")
        __tableCategoryList = json.loads(_tableCategoryList)
        __categoryList = []
        for _tableCategory in __tableCategoryList:
            _categoryId = _tableCategory['categoryId']
            _waiterOrderId = _tableCategory['waiterOrderId']
            _cookId = _tableCategory['cookId']
            _waiterServeId = _tableCategory['waiterServeId']
            if _categoryId == None or _categoryId == '':
                response['code'] = -1
                response['errorMsg'] = '获取categoryId失败'
                return HttpResponse(json.dumps(response),content_type="application/json")
            if _waiterOrderId == None or _waiterOrderId == '':
                response['code'] = -1
                response['errorMsg'] = '获取categoryId失败'
                return HttpResponse(json.dumps(response),content_type="application/json")
            if _cookId == None or _cookId == '':
                response['code'] = -1
                response['errorMsg'] = '获取categoryId失败'
                return HttpResponse(json.dumps(response),content_type="application/json")
            if _waiterServeId == None or _waiterServeId == '':
                response['code'] = -1
                response['errorMsg'] = '获取categoryId失败'
                return HttpResponse(json.dumps(response),content_type="application/json")
            try:
                category = Category.objects.get(id = _categoryId)
            except ObjectDoesNotExist:
                response['code'] = -1
                response['errorMsg'] = '查找category失败'
                return HttpResponse(json.dumps(response),content_type="application/json")
            __categoryList.append(category)

        _tableNumber = str(_tableNumber)
        _peopleNumber = int(_peopleNumber)
        table = Table(shop = shop, number = _tableNumber, peopleNumber= _peopleNumber)
        index = 0
        for _tableCategory in __tableCategoryList:
            _waiterOrderId = _tableCategory['waiterOrderId']
            _cookId = _tableCategory['cookId']
            _waiterServeId = _tableCategory['waiterServeId']
            try:
                waiterOrder = WaiterOrder.objects.get(id = str(_waiterOrderId))
            except ObjectDoesNotExist:
                response['code'] = -1
                response['errorMsg'] = '查找厨师失败'
                return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
            try:
                cook = Cook.objects.get(id = str(_cookId))
            except ObjectDoesNotExist:
                response['code'] = -1
                response['errorMsg'] = '查找厨师失败'
                return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")

            try:
                waiterServe = WaiterServe.objects.get(id = str(_waiterServeId))
            except ObjectDoesNotExist:
                response['code'] = -1
                response['errorMsg'] = '查找厨师失败'
                return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")

            category = __categoryList[index]
            index = index + 1
            tableCategory = TableCategory(category = category, waiterOrder = waiterOrder, cook = cook,
                                          waiterServe = waiterServe)
            tableCategory.save()

        table.save()
        response['code'] = 0
        response_data = {}
        response_data['tableNumber'] = table.number
        response_data['tablePeopleNumber'] = table.peopleNumber
        response_data['tableStatus'] = table.status
        response_data['tableId'] = table.id
        response['data'] = response_data
        return HttpResponse(json.dumps(response),content_type="application/json")

    elif _method == '2':
        _tableId = request.REQUEST.get('tableId')
        if _tableId == None or _tableId == '':
            response['code'] = -1
            response['errorMsg'] = '请输入tableid'
            return HttpResponse(json.dumps(response),content_type="application/json")

        try:
            table = Table.objects.get(id = _tableId)
        except ObjectDoesNotExist:
            response['code'] = -1
            response['errorMsg'] = 'table查询失败'
            return HttpResponse(json.dumps(response),content_type="application/json")

        response['code'] = 0
        response_data = {}
        response_data['tableNumber'] = table.number
        response_data['tablePeopleNumber'] = table.peopleNumber
        response_data['tableStatus'] = table.status
        response_data['tableId'] = table.id
        response['data'] = response_data
        return HttpResponse(json.dumps(response),content_type="application/json")

    elif _method == '3':
        _tableId = request.REQUEST.get('tableId')
        if _tableId == None or _tableId == '':
            response['code'] = -1
            response['errorMsg'] = '请输入tableid'
            return HttpResponse(json.dumps(response),content_type="application/json")
        try:
            table = Table.objects.get(id = _tableId)
        except ObjectDoesNotExist:
            response['code'] = -1
            response['errorMsg'] = 'table查询失败'
            return HttpResponse(json.dumps(response),content_type="application/json")

        table.isValid = False
        table.save()
        response['code'] = 0
        response['data'] = {}
        return HttpResponse(json.dumps(response),content_type="application/json")
示例#2
0
def addTableCategory(request):
    response = {}
    response['data'] = {}
    response['errorMsg'] = ""
    _shopId = request.session.get('shopId')
    if not _shopId:
        response['code'] = 1
        response['errorMsg'] = '请先登录'
        return HttpResponse(json.dumps(response),content_type="application/json")
    ##################JUDGE############
    _lastLoginTime = request.session.get('lastLoginTime')
    if not _lastLoginTime:
        response['code'] = 1
        response['errorMsg'] = '请先登录'
        return HttpResponse(json.dumps(response),content_type="application/json")
    try:
        shop = Shop.objects.get(id = _shopId)
    except ObjectDoesNotExist:
        response['code'] = 1
        response['errorMsg'] = '请先登录'
        return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
    if _lastLoginTime != shop.lastLoginTime:
        response['code'] = 1
        response['errorMsg'] = '上次登录失效,请重新登录'
        return HttpResponse(json.dumps(response),content_type="application/json")
    ####################END#################
    _tableId = request.REQUEST.get('tableId')
    _categoryId = request.REQUEST.get('categoryId')
    _waiterOrderId = request.REQUEST.get('waiterOrderId')
    _cookId = request.REQUEST.get('cookId')
    _waiterServeId = request.REQUEST.get('waiterServeId')

    if _tableId == None or _tableId == '':
        response['code'] = -1
        response['errorMsg'] = '请输入tableId'
        return HttpResponse(json.dumps(response),content_type="application/json")
    if _categoryId == None or _categoryId == '':
        response['code'] = -1
        response['errorMsg'] = '请输入tableCategoryId'
        return HttpResponse(json.dumps(response),content_type="application/json")
    if _waiterOrderId == None or _waiterOrderId == '':
        response['code'] = -1
        response['errorMsg'] = '请输入waiterOrderId'
        return HttpResponse(json.dumps(response),content_type="application/json")
    if _cookId == None or _cookId == '':
        response['code'] = -1
        response['errorMsg'] = '请输入cookId'
        return HttpResponse(json.dumps(response),content_type="application/json")
    if _waiterServeId == None or _waiterServeId == '':
        response['code'] = -1
        response['errorMsg'] = '请输入waiterServeId'
        return HttpResponse(json.dumps(response),content_type="application/json")

    _tableId = str(_tableId)
    _waiterOrderId = str(_waiterOrderId)
    _cookId = str(_cookId)
    _waiterServeId = str(_waiterServeId)
    tableCategoryQuery = TableCategory.objects.filter(table__id = _tableId).filter(category__id = _categoryId).filter(waiterOrder__id = _waiterOrderId).filter(cook__id = _cookId).filter(waiterServe__id = _waiterServeId)
    if tableCategoryQuery.exists():
        response['code'] = -1
        response['errorMsg'] = '已经绑定过'
        return HttpResponse(json.dumps(response),content_type="application/json")
    else:
        try:
            table = Table.objects.get(id = _tableId)
        except ObjectDoesNotExist:
            response['code'] = -1
            response['errorMsg'] = '查找厨师失败'
            return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
        try:
            category = Category.objects.get(id = _categoryId)
        except ObjectDoesNotExist:
            response['code'] = -1
            response['errorMsg'] = '查找厨师失败'
            return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")

        try:
            waiterOrder = WaiterOrder.objects.get(id = _waiterOrderId)
        except ObjectDoesNotExist:
            response['code'] = -1
            response['errorMsg'] = '查找厨师失败'
            return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")
        try:
            cook = Cook.objects.get(id = _cookId)
        except ObjectDoesNotExist:
            response['code'] = -1
            response['errorMsg'] = '查找厨师失败'
            return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")

        try:
            waiterServe = WaiterServe.objects.get(id = _waiterServeId)
        except ObjectDoesNotExist:
            response['code'] = -1
            response['errorMsg'] = '查找厨师失败'
            return HttpResponse(json.dumps(response,ensure_ascii=False),content_type="application/json")

        tableCategory = TableCategory(table = table,mcategory = category, waiterOrder = waiterOrder, cook = cook,
                                          waiterServe = waiterServe)
        tableCategory.save()
        response_data_waiter_order = {}
        response_data_waiter_order['waiterOrderId'] = waiterOrder.id
        response_data_waiter_order['waiterOrderName'] = waiterOrder.name
        response_data_waiter_order['waiterOrderTelephone'] = waiterOrder.telephone
        response['data'] = response_data_waiter_order
        return HttpResponse(json.dumps(response),content_type="application/json")