You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.6 KiB
60 lines
2.6 KiB
# 将接口请求的数据中卖品信息整理成列表结构 |
|
def format_goods(_data): |
|
goods_list = [] |
|
for cate in _data['res']['data']: |
|
for g in cate['goods']: |
|
goods_list.append(g) |
|
return {'res': {'status': _data['res']['status'], 'data': goods_list}} |
|
|
|
|
|
# 将接口获取的卖品数据转化成请求参数格式 |
|
def general_goods_param(_data): |
|
params = [] |
|
total_cash = 0 |
|
for g in _data: |
|
_num = g.get('buy_num', 1) |
|
info = { |
|
'id': g['id'], |
|
'type': g['type'], |
|
'price': round(float(g.get('partnerPrice', g['onlinePrice'])) * _num, 2), |
|
'num': _num |
|
} |
|
if g['type'] == 'package' and g['packageType'] == '2': |
|
add_price = 0 |
|
optional_package = [] |
|
for key, val in g['user_select'].items(): |
|
member = [] |
|
member_id = [] |
|
for m in val['data']: |
|
if m['id'] in member_id: |
|
for item in member: |
|
if item['id'] == m['id']: |
|
item['num'] = item['num'] + 1 |
|
add_price += round(float(m['addPrice']), 2) |
|
else: |
|
member.append({'id': m['id'], 'num': 1, 'add_price': m['addPrice']}) |
|
member_id.append(m['id']) |
|
add_price += round(float(m['addPrice']), 2) |
|
optional_package.append({'index': key, 'members': member}) |
|
info['optional_package'] = optional_package |
|
info['price'] = round(info['price'] + add_price, 2) |
|
total_cash = round(total_cash + info['price'] * _num, 2) |
|
params.append(info) |
|
if g.get('discount1', False): |
|
total_discount = 0 |
|
discount_list = [] |
|
if g['discount1'] > 0: |
|
total_discount = round(total_discount + g['discount1'], 2) |
|
discount_list.append( |
|
{"discount_price": g['discount1'], "discount_name": f"现金优惠券{str(g['discount1'])}元"}) |
|
if g['discount2'] > 0: |
|
total_discount = round(total_discount + g['discount2'], 2) |
|
discount_list.append( |
|
{"discount_price": g['discount2'], "discount_name": f"现金优惠券{str(g['discount2'])}元"}) |
|
if len(discount_list) > 0: |
|
info['discount_price'] = total_discount |
|
info['discount_detail'] = discount_list |
|
total_cash = round(total_cash - total_discount, 2) |
|
|
|
print('general_goods_param---------params', params) |
|
return params, total_cash
|
|
|