def get_month_bill_status(): """ 获取当前年的有无费用 :return: """ args = request.args house_info_id = args.get("house_code") current_time = time.localtime() current_year = current_time.tm_year current_mon = current_time.tm_mon monthList = [str(current_year) + "%02d" % mon + "0" for mon in range(1, 13)] fees = HouseFee.get_year_fees(house_info_id=house_info_id) for fee in fees: index = fee.month - 1 monthList[index] = str(current_year) + "%02d" % fee.month + "1" ret = { "retCode": "0000", "retMst": "", "monthList": monthList, "currentMon": str(current_year) + "%02d" % current_mon, } return jsonify(ret)
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}
def get_bill(): args = request.args house_info_id = args.get("house_code") year_mon = args.get("year_mon") ret = {"retCode": "0000", "retMsg": "", "billList": [], "lastMonth": "", "nextMonth": ""} year = None mon = None last_year = None last_mon = None next_year = None next_mon = None def get_last_mon(year, mon): last_mon = None last_year = None if mon == 1: last_year = year - 1 last_mon = 12 elif mon == 12: last_year = year last_mon -= 1 else: last_year = year last_mon = mon - 1 return (last_year, last_mon) def get_next_mon(year, mon): next_year = None next_mon = None if mon == 1: next_year = year next_mon += 1 elif mon == 12: next_year = year + 1 next_mon = 1 else: next_year = year next_mon = mon + 1 return (next_year, next_mon) try: year = int(year_mon[:4]) mon = int(year_mon[4:]) last_year, last_mon = get_last_mon(year, mon) next_year, next_mon = get_last_mon(year, mon) except ValueError as ex: ret = {"retCode": "3000", "retMsg": "年月格式错误,请按照201509的格式传递", "billList": [], "lastMonth": "", "nextMonth": ""} mon_list = [{"year": year, "mon": mon}, {"year": last_year, "mon": last_mon}, {"year": next_year, "mon": next_mon}] fees = HouseFee.get_house_fees(house_info_id=house_info_id, monList=mon_list) fees_dict = {} if fees: for fee in fees: fees_dict[fee.month] = fee target_fee = None total_fee = 0 try: target_fee = fees_dict[mon] total_fee = target_fee.water_fee + target_fee.gas_fee + target_fee.electricity_fee ret["total"] = total_fee last_mon_fee = None if fees_dict.has_key(last_mon): ret["lastMonth"] = str(last_year) + "%02d" % last_mon last_mon_fee = fees_dict[last_mon] ret["billList"] = [ { "FeeID": target_fee.id, "fee": target_fee.water_fee, "name": "水费", "status": target_fee.water_fee_status, "detailList": {"thisMon": target_fee.water_num, "lastMon": last_mon_fee.water_num}, }, { "FeeID": target_fee.id, "fee": target_fee.gas_fee, "name": "燃气费", "status": target_fee.gas_fee_status, "detailList": {"thisMon": target_fee.gas_num, "lastMon": last_mon_fee.gas_num}, }, { "FeeID": target_fee.id, "fee": target_fee.electricity_fee, "name": "电费", "status": target_fee.electricity_fee_status, "detailList": {"thisMon": target_fee.electricity_num, "lastMon": last_mon_fee.electricity_num}, }, ] else: ret["billList"] = [ { "FeeID": target_fee.id, "fee": target_fee.water_fee, "name": "水费", "status": target_fee.water_fee_status, "detailList": {"thisMon": target_fee.water_num, "lastMon": 0}, }, { "FeeID": target_fee.id, "fee": target_fee.gas_fee, "name": "燃气费", "status": target_fee.gas_fee_status, "detailList": {"thisMon": target_fee.gas_num, "lastMon": 0}, }, { "FeeID": target_fee.id, "fee": target_fee.electricity_fee, "name": "电费", "status": target_fee.electricity_fee_status, "detailList": {"thisMon": target_fee.electricity_num, "lastMon": 0}, }, ] except IndexError as ex: if fees_dict.has_key(last_mon): ret["lastMonth"] = str(last_year) + "%02d" % last_mon if fees_dict.has_key(next_mon): ret["nextMonth"] = str(next_year) + "%02d" % next_mon else: pass return jsonify(ret)