Commit 7074b38a by Aeolus

增加machine_price接口

parent ef263373
......@@ -629,3 +629,56 @@ def rent_money_liuyuan():
return jsonify(BASE_RESPONSE().to_dict())
else:
return jsonify(BASE_RESPONSE(error_code=-1, error_message='refund failed').to_dict())
@route_rent.route('/machine_price', methods=['POST'])
def get_machine_price():
json_data = request.get_json()
mac_no = json_data.get("mac_no", None)
if not mac_no:
return jsonify(PARAMETER_ERROR)
# 验证机柜是否存在
machine = Machine.query.filter_by(mac_no=mac_no).first()
if not machine:
return jsonify(MACHINE_NOT_EXIST_ERROR)
data = {
"price_type": machine.price_type,
"one_day_price": machine.one_day_price,
"desposit": machine.deposit,
"time_price": []
}
if machine.price_type == 1:
# 免费时间
data["time_price"].append([str(0) + '天', 0])
max_days = machine.deposit // machine.one_day_price + 1
i = 1
while i < max_days:
data["time_price"].append([str(i) + '天', machine.one_day_price * i])
i += 1
data["time_price"].append([str(max_days) + '天', machine.deposit])
elif machine.price_type == 2:
data["price_type"] = 2
fee_minutes = FeeMinuteModel.query.filter_by(machine_id=machine.id, status=1).order_by(
FeeMinuteModel.index.asc()).all()
data["time_price"].append(['0分钟', '0分钟', 0])
max_hours = len(fee_minutes)
n = 0
while n < max_hours - 1:
data["time_price"].append(
[str(fee_minutes[n].minute) + "分钟", str(fee_minutes[n + 1].minute) + "分钟", fee_minutes[n].price])
n += 1
data["time_price"].append(
[str(fee_minutes[n].minute) + "分钟", "1天", fee_minutes[n].price])
max_days = machine.deposit // machine.one_day_price + 1
i = 2
while i < max_days:
data["time_price"].append([str(i) + '天', machine.one_day_price * i])
i += 1
data["time_price"].append([str(max_days) + '天', machine.deposit])
else:
pass
return jsonify(BASE_RESPONSE(data=data).to_dict())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment