Commit f7031bdf by Aeolus

修改多库存下单逻辑

parent 5904a932
...@@ -37,6 +37,8 @@ class Hatch(Base): ...@@ -37,6 +37,8 @@ class Hatch(Base):
production_id = Column(INTEGER(10), nullable=False, comment='商品id') production_id = Column(INTEGER(10), nullable=False, comment='商品id')
name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称') name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题') title = Column(String(200, 'utf8mb4_unicode_ci'), nullable=False, comment='商品标题')
left_count = Column(TINYINT(3), nullable=False, comment='剩余数量')
total_count = Column(TINYINT(3), nullable=False, comment='总数')
brand_id = Column(INTEGER(10), nullable=False, comment='品牌ID') brand_id = Column(INTEGER(10), nullable=False, comment='品牌ID')
brand_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称') brand_name = Column(String(100, 'utf8mb4_unicode_ci'), nullable=False, comment='商品名称')
cate_id = Column(INTEGER(10), nullable=False, comment='分类ID') cate_id = Column(INTEGER(10), nullable=False, comment='分类ID')
......
...@@ -44,41 +44,37 @@ def create_rent(): ...@@ -44,41 +44,37 @@ def create_rent():
return jsonify(MACHINE_NOT_EXIST_ERROR) return jsonify(MACHINE_NOT_EXIST_ERROR)
total_fee = 0 total_fee = 0
for id, count in productions.items():
# 根据给的仓号去获取商品信息
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) < int(count):
return jsonify(HATCH_COUNT_ERROR)
total_fee += hatch_list[0].price * int(count)
# 生成订单编号
rent_no = RentService.create_order_no()
open_hatchs = [] open_hatchs = []
for id, count in productions.items(): for id, count in productions.items():
count = int(count) count = int(count)
id = int(id) id = int(id)
# 根据给的仓号去获取商品信息 # 根据给的仓号去获取商品信息
hatch_list = Hatch.query.filter(Hatch.machine_no == machine_no, Hatch.production_id == id, hatch_list = Hatch.query.filter(Hatch.machine_no == machine_no, Hatch.production_id == id,
Hatch.status == 1).order_by(func.random()).all() Hatch.left_count >= 1).order_by(func.random()).all()
if not hatch_list: if not hatch_list:
return jsonify(HATCH_NOT_EXIST_ERROR) return jsonify(HATCH_NOT_EXIST_ERROR)
if len(hatch_list) < count: left_count = count
return jsonify(HATCH_NOT_ALL_EXIST_ERROR) for i in hatch_list:
hatch_no_list = [x.hatch_no for x in hatch_list[:count]] if i.left_count <= left_count:
open_hatchs += hatch_no_list left_count = left_count - i.left_count
hatch_no_dict = {i.hatch_no: i.left_count}
else:
hatch_no_dict = {i.hatch_no: left_count}
left_count = 0
open_hatchs.append(hatch_no_dict)
if left_count > 0:
return jsonify(HATCH_COUNT_ERROR)
total_fee += hatch_list[0].price * int(count)
# 配置微信订单数据 # 配置微信订单数据
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])
# 生成订单编号
rent_no = RentService.create_order_no()
pay_data = { pay_data = {
'body': '灰兔智能租借押金', # 商品描述 'body': '灰兔智能租借押金', # 商品描述
'out_trade_no': rent_no, # 商户订单号 'out_trade_no': rent_no, # 商户订单号
...@@ -170,33 +166,30 @@ def wx_pay_callback(): ...@@ -170,33 +166,30 @@ def wx_pay_callback():
total_fee = 0 total_fee = 0
hatchs = Hatch.query.filter(Hatch.machine_no == machine_no, Hatch.hatch_no.in_(open_hatchs), hatchs = Hatch.query.filter(Hatch.machine_no == machine_no, Hatch.hatch_no.in_(open_hatchs.keys())).order_by(
Hatch.status == 1).order_by(func.random()).all() func.random()).all()
for i in hatchs: for i in hatchs:
if i.status == 1: rent_detail = RentDetail()
rent_detail = RentDetail() rent_detail.rent_no = rent_no
rent_detail.rent_no = rent_no rent_detail.user_id = rent.user_id
rent_detail.user_id = rent.user_id rent_detail.machine_no = rent.machine_no
rent_detail.machine_no = rent.machine_no rent_detail.hatch_no = i.hatch_no
rent_detail.hatch_no = i.hatch_no rent_detail.production_id = i.production_id
rent_detail.production_id = i.production_id rent_detail.name = i.name
rent_detail.name = i.name rent_detail.title = i.title
rent_detail.title = i.title rent_detail.brand_id = i.brand_id
rent_detail.brand_id = i.brand_id rent_detail.brand_name = i.brand_name
rent_detail.brand_name = i.brand_name rent_detail.cate_id = i.cate_id
rent_detail.cate_id = i.cate_id rent_detail.cate_name = i.cate_name
rent_detail.cate_name = i.cate_name rent_detail.price = i.price * open_hatchs[i.hatch_no]
rent_detail.price = i.price rent_detail.img = i.img
rent_detail.img = i.img rent_detail.tags = i.tags
rent_detail.tags = i.tags rent_detail.content = i.content
rent_detail.content = i.content rent_detail.summary = i.summary
rent_detail.summary = i.summary db.session.add(rent_detail)
i.status = 2 db.session.add(i)
db.session.add(rent_detail) total_fee += rent_detail.price
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