Beispiel #1
0
def upload_bill_data():
    """
    上传燃气表、水表接口
    :param house_code:house_id
    :param type:电表或是燃气表
    :param num:度数
    :return:
    """
    ret = {"retCode": "0000", "retMsg": ""}
    args = request.args
    type = args.get("type")
    house_info_id = args.get("house_code")
    num = args.get("num")
    fee = HouseFee.get_last_mon_fee(house_info_id=house_info_id)
    if fee == None:
        fee = HouseFee()
        fee.house_info_id = house_info_id
        time_struct = time.localtime()
        year = time_struct.tm_year
        mon = time_struct.tm_mon - 1
        if mon < 1:
            year -= 1
        fee.year = year
        fee.month = mon

    if type == str(DefaultConfig.WATER):
        fee.water_num = num
    elif type == str(DefaultConfig.GAS):
        fee.gas_num = num

    try:
        fee.save()
    except IntegrityError:
        ret = {"retCode": "3000", "retMsg": "house_code不存在!请确认house_code正确"}
    except Exception, ex:
        ret = {"retCode": "5000", "retMsg": ex.message}