dingxin_toolbox
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.

142 lines
8.5 KiB

"""
说明
支持现金联名卡支付电子券支付扫码券支付
现金支付时可以走电商渠道定价
联名卡支付时价格取联名卡的优惠价支付方式还是现金
电子券和扫码券都是走鼎新定价然后通过券接口获取价格剩余待支付的金额为现金支付
券只支持如下几种券
先从seat_lock接口获取座位价格
如果seat_lock没有获取到座位价格就到
返回 结果, seat , ticket_cash, play_id, play_update_time, lock_flag, timestamp
"""
import random
from decimal import Decimal, ROUND_HALF_UP
from dspt_api.util.general.handle_redis import get_data_from_redis
def general_seat_params(pay_type, data):
redis_key_prefix = f'dspt_api_{data["ip"]}_{data["env"]}_{data["member_type"]}_{data["pid"]}_{data["cid"]}'
# 获取 area_info和partner_price
request_api_lock = {'name': '3.3.1 座位锁定', 'path': 'seat/lock'}
redis_key_api_lock = f'{redis_key_prefix}_{request_api_lock["path"]}'
result_lock, _format_lock, seat_price_from_lock, _timestamp_lock = get_data_from_redis(redis_key_api_lock)
area_info = seat_price_from_lock['areaInfo'] if len(seat_price_from_lock['areaInfo']) > 0 else False
lock_flag = seat_price_from_lock['lockFlag']
# partner_price = seat_price_from_lock['partnerPrice'] if seat_price_from_lock['partnerPrice'] is not None else False
# 获取market_price
request_api_play = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'}
redis_key_api_play = f'{redis_key_prefix}_{request_api_play["path"]}'
result_play, _format_play, seat_price_from_play, _timestamp_play = get_data_from_redis(redis_key_api_play)
market_price = seat_price_from_play['marketPrice']
play_id = seat_price_from_play['id']
play_update_time = seat_price_from_play['cineUpdateTime']
# 获取手续费
request_api_config = {'name': '3.1.2 获取单个影院配置信息', 'path': 'cinema/config'}
redis_key_api_config = f'{redis_key_prefix}_{request_api_config["path"]}'
result_config, _format_config, seat_price_from_config, _timestamp_config = get_data_from_redis(redis_key_api_config)
handle_fee = seat_price_from_config['handleFee']
partner_type = seat_price_from_config['partnerSubsidyType'] # 1:电商平台补贴;2:合作商补贴
# 获取座位信息
request_api_seat = {'name': '3.1.8 获取某场次座位状态', 'path': 'play/seat-status'}
redis_key_api_seat = f'{redis_key_prefix}_{request_api_seat["path"]}'
result_seat, _format_seat, seat_price_from_seat, _timestamp_seat = get_data_from_redis(redis_key_api_seat)
print('seat_price_from_seat', seat_price_from_seat)
seat_id_list = [{'seat_id': seat['cineSeatId'], 'ticket_discount': seat.get('ticketDiscount', 0),
'service_discount': seat.get('serviceDiscount', 0)} for seat in seat_price_from_seat]
# 计算最大时间戳
last_timestamp = max([_timestamp_lock, _timestamp_play, _timestamp_config, _timestamp_seat])
# 判断获取到了全部接口数据,就继续,否则报错
if not (result_lock and result_play and result_config and result_seat):
return_str = '请手动输入参数,检查相关接口返回值:3.3.1 座位锁定、3.1.5 获取放映计划列表、3.1.8 获取某场次座位状态、3.1.2 获取单个影院配置信息'
return False, return_str, 0, return_str, return_str, return_str, last_timestamp
if pay_type == 'cash':
"""
-- 当影院合作商是电商平台定价时partner_type = 1
price不包含手续费,含服务费
user_real_pay_price用户真实支付影票金额不含手续费服务费该字段只做记录不参与计算
service_fee影厅座位服务费仅当锁座接口返回的服务费[areaServiceFee]不为零时才传此参数
ticket_discount_price影票优惠金额; service_fee_discount_price服务费优惠金额
如果是鼎新电商平台对合作商价格管控使用以上两个优惠金额字段需要联系请联系鼎新杰盈公司商务打开开关即可使用否则直接回传会产生掉单
-- 当影院合作商是合作商自主定价时partner_type = 2
price真实的票价[不含服务费不含手续费]
user_real_pay_price用户真实支付影票金额[不含手续费服务费] 需要扣减 ticket_discount_price
service_fee真实的服务费
ticket_discount_price影票优惠金额仅做记录
service_fee_discount_price服务费优惠金额仅做记录
测试影院
测试影院3.166 乐影网 电商平台补贴 是否允许传递优惠金额 影票价格控制 卖品价格控制
测试影院3.166 淘票票 电商平台补贴 是否允许传递优惠金额 影票价格控制 卖品价格控制
测试影院3.166 美团猫眼 电商平台补贴 是否允许传递优惠金额 影票价格控制 卖品价格控制
测试影院3.166 合作商补贴 合作商补贴 是否允许传递优惠金额 影票价格控制 卖品价格控制
"""
seat_list = []
ticket_cash = 0 # 统计cash字段用
for seat_info in seat_id_list:
seat = [seat_info["seat_id"], handle_fee]
ticket_discount = seat_info["ticket_discount"]
service_discount = seat_info["service_discount"]
if area_info is not False:
# 查找座位对应的区域价格
for area_seat_info in area_info:
if area_seat_info['seatId'] == int(seat_info['seat_id']):
# 获取price字段值
price = Decimal(area_seat_info["areaPrice"]).quantize(Decimal('0.00'), ROUND_HALF_UP)
seat.append(price)
seat.append('0')
seat.append(area_seat_info["areaServiceFee"])
# if partner_type == '2': # 合作商定价
# price -= Decimal(area_seat_info["areaServiceFee"]).quantize(Decimal('0.00'), ROUND_HALF_UP)
# 计算用户实际支付的值
real_pay = Decimal(area_seat_info["areaPrice"]).quantize(Decimal('0.00'), ROUND_HALF_UP)
real_pay -= Decimal(area_seat_info["areaServiceFee"]).quantize(Decimal('0.00'), ROUND_HALF_UP)
# 处理影票和服务费折扣
if ticket_discount != 0:
real_pay -= Decimal(ticket_discount)
seat.append(str(ticket_discount))
if service_discount != 0:
if partner_type == '2':
real_pay -= Decimal(service_discount)
seat.append(str(service_discount))
else:
seat.append(str(service_discount))
seat[3] = str(real_pay)
# seat = f'{seat_info["seat_id"]}-{handle_fee}-{str(price)}-{str(real_pay)}-{area_seat_info["areaServiceFee"]}{f"-{str(ticket_discount)}" if ticket_discount != 0 else ""}{f"-{str(service_discount)}" if service_discount != 0 else ""}'
seat_list.append('-'.join(seat))
ticket_cash += real_pay
else:
seat.append(market_price)
seat.append('0')
seat.append('0.00')
real_pay = Decimal(market_price).quantize(Decimal('0.00'), ROUND_HALF_UP)
if ticket_discount != 0:
real_pay -= Decimal(ticket_discount)
seat.append(str(ticket_discount))
if service_discount != 0:
real_pay -= Decimal(service_discount)
seat.append(str(service_discount))
seat[3] = str(real_pay)
# seat = f'{seat_info["seat_id"]}-{handle_fee}-{market_price}-{str(real_pay)}-0{f"-{str(ticket_discount)}" if ticket_discount != 0 else ""}{f"-{str(service_discount)}" if service_discount != 0 else ""}'
seat_list.append('-'.join(seat))
ticket_cash += real_pay
return True, ','.join(seat_list), ticket_cash, play_id, play_update_time, lock_flag, last_timestamp
elif pay_type == 'ecard':
pass
elif pay_type == 'yushouquan':
pass
elif pay_type == 'equan':
pass
else:
pass