Commit 1314ae68 by Aeolus

统一下单时返回要开的仓号

parent 3ed4e4f3
...@@ -60,6 +60,22 @@ def create_rent(): ...@@ -60,6 +60,22 @@ def create_rent():
# 生成订单编号 # 生成订单编号
rent_no = RentService.create_order_no() rent_no = RentService.create_order_no()
open_hatchs = []
for id, count in productions.items():
count = int(count)
id = int(id)
# 根据给的仓号去获取商品信息
hatch_list = Hatch.query.filter(Hatch.machine_no == machine_no, Hatch.production_id == id,
Hatch.status == 1).order_by(func.random()).all()
if not hatch_list:
return jsonify(HATCH_NOT_EXIST_ERROR)
if len(hatch_list) < count:
return jsonify(HATCH_NOT_ALL_EXIST_ERROR)
hatch_no_list = [x.hatch_no for x in hatch_list[:count]]
open_hatchs.append(hatch_no_list)
# 配置微信订单数据 # 配置微信订单数据
wechat_service = WeChatPayService(app_id=platform_appid_config_list[user.platform], wechat_service = WeChatPayService(app_id=platform_appid_config_list[user.platform],
config_name=pay_config_list[machine.mch_platform]) config_name=pay_config_list[machine.mch_platform])
...@@ -75,7 +91,8 @@ def create_rent(): ...@@ -75,7 +91,8 @@ def create_rent():
"machine_no": machine_no, "machine_no": machine_no,
"user_id": user.id, "user_id": user.id,
"machine_id": machine.id, "machine_id": machine.id,
"platform": machine.mch_platform "platform": machine.mch_platform,
"open_hatchs": open_hatchs
} }
} }
...@@ -121,6 +138,7 @@ def wx_pay_callback(): ...@@ -121,6 +138,7 @@ def wx_pay_callback():
machine_no = rent_data["machine_no"] machine_no = rent_data["machine_no"]
machine_id = rent_data["machine_id"] machine_id = rent_data["machine_id"]
productions = rent_data["productions"] productions = rent_data["productions"]
open_hatchs = rent_data["open_hatchs"]
user_id = rent_data["user_id"] user_id = rent_data["user_id"]
platform = pay_config_list[platform] platform = pay_config_list[platform]
wechat_service = WeChatPayService(app_id=callback_data["appid"], config_name=platform) wechat_service = WeChatPayService(app_id=callback_data["appid"], config_name=platform)
...@@ -166,43 +184,34 @@ def wx_pay_callback(): ...@@ -166,43 +184,34 @@ def wx_pay_callback():
rent.prepay_id = prepay_id rent.prepay_id = prepay_id
total_fee = 0 total_fee = 0
for id, count in productions.items():
count = int(count) hatchs = Hatch.query.filter(Hatch.machine_no == machine_no, Hatch.hatch_no.in_(open_hatchs),
id = int(id) Hatch.status == 1).order_by(func.random()).all()
# 根据给的仓号去获取商品信息
hatch_list = Hatch.query.filter(Hatch.machine_no == machine_no, Hatch.production_id == id, for i in hatchs:
Hatch.status == 1).order_by(func.random()).all() if i.status == 1:
rent_detail = RentDetail()
if not hatch_list: rent_detail.rent_no = rent_no
return jsonify(HATCH_NOT_EXIST_ERROR) rent_detail.user_id = rent.user_id
rent_detail.machine_no = rent.machine_no
if len(hatch_list) < count: rent_detail.hatch_no = i.hatch_no
return jsonify(HATCH_NOT_ALL_EXIST_ERROR) rent_detail.production_id = i.production_id
hatchs = hatch_list[:count] rent_detail.name = i.name
for i in hatchs: rent_detail.title = i.title
if i.status == 1: rent_detail.brand_id = i.brand_id
rent_detail = RentDetail() rent_detail.brand_name = i.brand_name
rent_detail.rent_no = rent_no rent_detail.cate_id = i.cate_id
rent_detail.user_id = rent.user_id rent_detail.cate_name = i.cate_name
rent_detail.machine_no = rent.machine_no rent_detail.price = i.price
rent_detail.hatch_no = i.hatch_no rent_detail.img = i.img
rent_detail.production_id = i.production_id rent_detail.tags = i.tags
rent_detail.name = i.name rent_detail.content = i.content
rent_detail.title = i.title rent_detail.summary = i.summary
rent_detail.brand_id = i.brand_id i.status = 2
rent_detail.brand_name = i.brand_name db.session.add(rent_detail)
rent_detail.cate_id = i.cate_id db.session.add(i)
rent_detail.cate_name = i.cate_name
rent_detail.price = i.price total_fee += i.price
rent_detail.img = i.img
rent_detail.tags = i.tags
rent_detail.content = i.content
rent_detail.summary = i.summary
i.status = 2
db.session.add(rent_detail)
db.session.add(i)
total_fee += i.price
if total_fee != int(callback_data['total_fee']): if total_fee != int(callback_data['total_fee']):
return xmltodict.unparse({'xml': error_data}, pretty=True), header return xmltodict.unparse({'xml': error_data}, pretty=True), header
......
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