Example #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")

        _tableNumber = str(_tableNumber)
        _peopleNumber = int(_peopleNumber)
        table = Table(shop = shop, number = _tableNumber, peopleNumber= _peopleNumber,lockDateTime =
        datetime.datetime.now())
        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")
Example #2
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")