From 6608249bc214cc039f47600e280c1261a08f57ba Mon Sep 17 00:00:00 2001 From: RogerWork Date: Sun, 26 Jan 2025 10:02:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BC=9A=E5=91=98=E9=94=81?= =?UTF-8?q?=E5=BA=A7=E8=B4=AD=E7=A5=A8=E5=92=8C=E5=8D=96=E5=93=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dspt_api/util/api/seat_lock_buy.py | 9 + dspt_api/util/general/handle_card.py | 55 ++++++ dspt_api/util/general/handle_goods.py | 177 ++++++++++++++++- dspt_api/util/general/handle_redis.py | 4 +- dspt_api/util/general/handle_seat.py | 212 +++++++++++++++++++-- dspt_api/util/general/suggest_params.py | 62 +++++- dspt_api/util/mapi/card_get_goods_price.py | 51 +++++ dspt_api/util/mapi/order_buy_goods.py | 79 ++++++++ dspt_api/util/mapi/play_seat_status.py | 9 +- dspt_api/util/mapi/seat_lock.py | 55 ++++++ dspt_api/util/mapi/seat_lock_buy.py | 117 ++++++++++++ dspt_api/util/mapi/seat_price.py | 49 +++++ dspt_api/views.py | 34 +++- 13 files changed, 885 insertions(+), 28 deletions(-) create mode 100644 dspt_api/util/general/handle_card.py create mode 100644 dspt_api/util/mapi/card_get_goods_price.py create mode 100644 dspt_api/util/mapi/order_buy_goods.py create mode 100644 dspt_api/util/mapi/seat_lock.py create mode 100644 dspt_api/util/mapi/seat_lock_buy.py create mode 100644 dspt_api/util/mapi/seat_price.py diff --git a/dspt_api/util/api/seat_lock_buy.py b/dspt_api/util/api/seat_lock_buy.py index 19dce49..4894b73 100644 --- a/dspt_api/util/api/seat_lock_buy.py +++ b/dspt_api/util/api/seat_lock_buy.py @@ -65,6 +65,15 @@ class ApiSeatLockBuy: self.add_param('play_update_time', '请手动输入参数,或先请求接口:3.1.5 获取放映计划列表', timestamp=_ticket_timestamp) self.add_param('cash', '请手动输入参数,或先请求接口:3.1.5 获取放映计划列表', timestamp=_ticket_timestamp) + if self.pay_type == 'ecard': + self.add_param('ecard_number', '请手动输入参数,检查相关接口返回值:3.4.6 获取座位的联名卡价格', + timestamp=_ticket_timestamp) + if self.pay_type == 'yushouquan': + self.add_param('coupons', '3.6.1添加券接口中选择的券类型为扫码券,与当前设置不符合', + timestamp=_ticket_timestamp) + if self.pay_type == 'equan': + self.add_param('card_coupons', '3.6.1添加券接口中选择的券类型为扫码券,与当前设置不符合', + timestamp=_ticket_timestamp) return False self.add_param('play_id', _play_id, timestamp=_ticket_timestamp) self.add_param('seat', _seat, timestamp=_ticket_timestamp) diff --git a/dspt_api/util/general/handle_card.py b/dspt_api/util/general/handle_card.py new file mode 100644 index 0000000..8e63d1d --- /dev/null +++ b/dspt_api/util/general/handle_card.py @@ -0,0 +1,55 @@ +from django_redis import get_redis_connection +from dspt_api.models import EcChannel, EcEnv +from django.db.models import Q +from dspt_api.util.general.sign import Sign +import requests + + +def get_card(ip, env, pid, cid): + redis_con = get_redis_connection() + redis_key = f"card_{ip}_{env}_{pid}_{cid}" + print('get_card-card_num', redis_key) + if redis_con.exists(redis_key): + card_num = redis_con.get(redis_key) + print('get_card-card_num', card_num) + return str(card_num, encoding='utf-8') + return False + + +def set_card(ip, env, pid, cid, card): + redis_con = get_redis_connection() + redis_key = f"card_{ip}_{env}_{pid}_{cid}" + if redis_con.exists(redis_key): + redis_con.delete(redis_key) + return redis_con.set(redis_key, card) + + +def get_card_type(env, pid, cid, card): + params = { + 'format': 'json', + 'pid': pid, + 'cid': cid, + 'card': card, + } + + try: + base_url = EcEnv.objects.filter(Q(code=env) & Q(type='member')).values('host').first()['host'] + except Exception as e: + return False, e + + request_url = f"{base_url}/card/detail" + + try: + key = EcChannel.objects.filter(Q(pid=pid) & Q(env=env)).values('channel_key').first()['channel_key'] + except Exception as e: + return False, e + + sign = Sign(key) + req_params = sign.add_sig(params) + + response = requests.get(request_url, params=req_params) + + if response.json()['res']['status'] != 1: + return False + else: + return response.json()['res']['data']['cardType'] diff --git a/dspt_api/util/general/handle_goods.py b/dspt_api/util/general/handle_goods.py index 9b55a4c..bf9059e 100644 --- a/dspt_api/util/general/handle_goods.py +++ b/dspt_api/util/general/handle_goods.py @@ -1,6 +1,10 @@ +from functools import reduce + from dspt_api.util.general.handle_redis import get_data_from_redis, get_param_from_redis from dspt_api.util.general.handle_ecard import get_ecard_level, get_ecard +from dspt_api.util.general.handle_card import get_card_type from dspt_api.util.general.handle_float import f2 +import time # 将接口请求的数据中卖品信息整理成列表结构 @@ -89,7 +93,7 @@ def general_goods_params(pay_type, data, ticket_cash=f2(0)): redis_key_api = f'{redis_key_prefix}_{request_api["path"]}' result, _format, goods_data, _timestamp = get_data_from_redis(redis_key_api) if result is False: - return False, None, None, None + return False, None, None, None, None if pay_type == 'cash': goods_field, goods_cash = general_goods_field(goods_data) goods_cash = f2(goods_cash) @@ -108,7 +112,7 @@ def general_goods_params(pay_type, data, ticket_cash=f2(0)): result_yushouquan, _format_yushouquan, cash_from_yushouquan, _timestamp_yushouquan = get_data_from_redis( redis_key_api_yushouquan) if not result_yushouquan: - return False, None, None, None, None, None, None, None + return False, None, None, None, None # 获取券码 req_params = get_param_from_redis(redis_key_api_yushouquan) if pay_type == 'yushouquan': @@ -122,3 +126,172 @@ def general_goods_params(pay_type, data, ticket_cash=f2(0)): else: pass return True, goods_field, str(goods_cash), quan, _timestamp + + +# 将接口获取的卖品数据转化成请求参数格式 +def general_goods_field_member(_goods_data, _data): + # 获取会员价 + redis_key_prefix = f'dspt_api_{_data["ip"]}_{_data["env"]}_{_data["member_type"]}_{_data["pid"]}_{_data["cid"]}' + request_api_get_goods_price = {'name': '3.3.2 获取卖品折扣信息', 'path': 'card/get-goods-price'} + redis_key_api_get_goods_price = f'{redis_key_prefix}_{request_api_get_goods_price["path"]}' + result, _format, _goods_price, _timestamp = get_data_from_redis(redis_key_api_get_goods_price, True) + params = [] + total_cash = 0 + for g in _goods_data: + _num = g.get('buy_num', 1) + price = f2(g['counterPrice'] if g['cardDiscountType'] == "1" else g['onlinePrice']) + if result: + for gp in _goods_price: + if gp['id'] == str(g['id']): + price = f2(gp['discountPrice']) + info = { + 'id': g['id'], + 'type': g['type'], + 'price': price, + 'num': _num + } + if g['type'] == 'package' and g['packageType'] == '2': + add_price = f2(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 += f2(m['addPrice']) + else: + member.append({'id': m['id'], 'num': 1, 'add_price': m['addPrice']}) + member_id.append(m['id']) + add_price += f2(m['addPrice']) + optional_package.append({'index': key, 'members': member}) + info['optional_package'] = optional_package + info['price'] = info['price'] + add_price + total_cash = f2(total_cash) + f2(info['price']) + params.append(info) + + print('general_goods_param---------params', params) + return params, total_cash + + +def general_goods_params_member(data, pay_type, card, ticket_cash=f2(0)): + # 返回值 result, goods_field, goods_card_balance_pay, goods_cash, cash, timestamp + goods_card_balance_pay = 0 + goods_cash = 0 + third_pay = f2(ticket_cash) + quan_num = int(pay_type['goods_quan']['goods_quan_num']) + quan_val = f2(pay_type['goods_quan']['goods_quan_value']) + quan_type = pay_type['goods_quan']['goods_quan_type'] + + # 获取卡类型 + card_type = get_card_type(data["env"], data["pid"], data["cid"], card) + if card_type is False: + return_str = '此会员卡在该影院无法使用,请使用3.1.3 查询会员卡的详细信息接口查看卡信息' + return False, return_str, return_str, return_str, third_pay, int(time.time() * 1000) + + # 券信息 + quan = '' + # redis_key 前缀 + redis_key_prefix = f'dspt_api_{data["ip"]}_{data["env"]}_{data["member_type"]}_{data["pid"]}_{data["cid"]}' + # 获取卖品数据 + request_api = {'name': '3.2.1 获取卖品列表', 'path': 'cinema/goods'} + redis_key_api = f'{redis_key_prefix}_{request_api["path"]}' + result, _format, goods_data, _timestamp = get_data_from_redis(redis_key_api) + if result is False: + return False, None, None, None, third_pay, int(time.time() * 1000) + + goods_field_list, total_goods_val = general_goods_field_member(goods_data, data) + + if pay_type['select_price_type'] == 'cinema_price': + goods_card_balance_pay = str(total_goods_val) + if card_type == '权益卡(积分卡)': + third_pay += total_goods_val + return True, change_goods_price_str(goods_field_list), goods_card_balance_pay, goods_cash, third_pay, _timestamp + if pay_type['select_price_type'] == 'third_price': + if pay_type['goods_quan_check'] is False: + goods_card_balance_pay = str(total_goods_val) + if card_type == '权益卡(积分卡)': + third_pay += total_goods_val + return True, change_goods_price_str( + goods_field_list), goods_card_balance_pay, goods_cash, third_pay, _timestamp + else: + quan_per_goods_list = quan_num_pre_goods(int(pay_type['goods_quan']['goods_quan_num']), + len(goods_field_list)) + if quan_type == '兑换券': + total_goods_pay = 0 + for i, goods in enumerate(goods_field_list): + goods['coupons'] = [] + for n in range(quan_per_goods_list[i]): + goods['coupons'].append( + {'name': 'Rog卖品接口兑换券', 'code': f'rog{str(time.time_ns())}{goods["id"]}', + 'show_price': 0, 'sell_price': 0, 'coupon_type': 1}) + if n == 0: + goods['price'] = f2(pay_type['goods_quan']['goods_quan_value']) + else: + goods['price'] += f2(pay_type['goods_quan']['goods_quan_value']) + total_goods_pay += goods['price'] + goods_card_balance_pay = str(total_goods_pay) + if card_type == '权益卡(积分卡)': + third_pay += total_goods_pay + return True, change_goods_price_str( + goods_field_list), goods_card_balance_pay, goods_cash, third_pay, _timestamp + if quan_type == '代金券': + total_quan_val = quan_val * quan_num + remain_quan_val = total_quan_val + total_goods_pay = 0 + for i, goods in enumerate(goods_field_list): + if i + 1 < len(goods_field_list): + goods_val = f2(f2(goods['price']) - remain_quan_val) + goods['price'] = goods_val if goods_val > 0 else 0 + total_goods_pay += goods['price'] + else: + quan_val = f2((f2(goods['price']) / total_goods_val) * total_quan_val) + remain_quan_val -= quan_val + goods_val = f2(f2(goods['price']) - quan_val) + goods['price'] = goods_val if goods_val > 0 else 0 + total_goods_pay += goods['price'] + goods_card_balance_pay = str(total_goods_pay) + if card_type == '权益卡(积分卡)': + third_pay += total_goods_pay + return True, change_goods_price_str( + goods_field_list), goods_card_balance_pay, goods_cash, third_pay, _timestamp + if quan_type == '抵值兑换券': + total_goods_pay = 0 + total_quan_pay = 0 + for i, goods in enumerate(goods_field_list): + if quan_per_goods_list[i] == 0: + total_goods_pay += f2(goods['price']) + else: + goods['coupons'] = [] + for n in range(quan_per_goods_list[i]): + goods['coupons'].append( + {'name': 'Rog卖品接口抵值兑换券', 'code': f'rog{str(time.time_ns())}{goods["id"]}', + 'show_price': str(quan_val), 'sell_price': str(quan_val), 'coupon_type': 3}) + if n == 0: + goods['price'] = f2(quan_val) + else: + goods['price'] += f2(quan_val) + total_quan_pay += goods['price'] + goods_card_balance_pay = str(total_goods_pay) + goods_cash = str(total_quan_pay) + if card_type == '权益卡(积分卡)': + third_pay += total_goods_pay + return True, change_goods_price_str( + goods_field_list), goods_card_balance_pay, goods_cash, third_pay, _timestamp + return False, None, None, None, third_pay, int(time.time() * 1000) + + +def quan_num_pre_goods(quan_total_num, goods_num): + quan_average_num = int(quan_total_num / goods_num) # 计算个卖品平均用几张券 + result = [quan_average_num] * goods_num # 生成每个卖品的用券数量列表 + for i in range(quan_total_num % goods_num): # 用券与卖品的余数作为范围,为卖品添加券 + result[i] += 1 + return result + + +def change_goods_price_str(goods_list): + for goods in goods_list: + goods['price'] = str(goods['price']) + return goods_list diff --git a/dspt_api/util/general/handle_redis.py b/dspt_api/util/general/handle_redis.py index 5939ac5..d47eb31 100644 --- a/dspt_api/util/general/handle_redis.py +++ b/dspt_api/util/general/handle_redis.py @@ -7,7 +7,7 @@ import xmltodict # 封装方法处理从redis中获取接口数据 -def get_data_from_redis(redis_key): +def get_data_from_redis(redis_key, raw=False): # 初始化redis redis_conn = get_redis_connection() # 如果有用户数据则处理用户数据 @@ -41,6 +41,8 @@ def get_data_from_redis(redis_key): if len(resp_data) == 0: print('get_data_from_redis-3') return False, redis_data['format'], '接口返回数据为空,请手动输入参数:', 0 + if raw is True: + return True, redis_data['format'], resp_data, redis_data['timestamp'] return True, redis_data['format'], random.choice(resp_data), redis_data['timestamp'] return False, 'json', '请手动输入参数,或先请求接口:', 0 diff --git a/dspt_api/util/general/handle_seat.py b/dspt_api/util/general/handle_seat.py index f53ad08..dec74d8 100644 --- a/dspt_api/util/general/handle_seat.py +++ b/dspt_api/util/general/handle_seat.py @@ -1,22 +1,23 @@ -""" -说明: -支持现金、联名卡支付,电子券支付,扫码券支付 -现金支付时,可以走电商渠道定价 -联名卡支付时,价格取联名卡的优惠价,支付方式还是现金 -电子券和扫码券都是走鼎新定价,然后通过券接口获取价格,剩余待支付的金额为现金支付 -券只支持如下几种券: - -先从seat_lock接口获取座位价格 -如果seat_lock没有获取到座位价格就到 - -返回 结果, seat , ticket_cash, play_id, play_update_time, lock_flag, quan, timestamp -""" -import random from dspt_api.util.general.handle_float import f2 from dspt_api.util.general.handle_redis import get_data_from_redis, get_param_from_redis +from dspt_api.util.general.handle_card import get_card_type +import time def general_seat_params(pay_type, data): + """ + 说明: + 支持现金、联名卡支付,电子券支付,扫码券支付 + 现金支付时,可以走电商渠道定价 + 联名卡支付时,价格取联名卡的优惠价,支付方式还是现金 + 电子券和扫码券都是走鼎新定价,然后通过券接口获取价格,剩余待支付的金额为现金支付 + 券只支持如下几种券: + + 先从seat_lock接口获取座位价格 + 如果seat_lock没有获取到座位价格就到 + + 返回 结果, seat , ticket_cash, play_id, play_update_time, lock_flag, quan, timestamp + """ redis_key_prefix = f'dspt_api_{data["ip"]}_{data["env"]}_{data["member_type"]}_{data["pid"]}_{data["cid"]}' # 获取 area_info和partner_price @@ -24,6 +25,7 @@ def general_seat_params(pay_type, data): 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) if not result_lock: + print('result_lock False') return False, None, None, None, None, None, None, None area_info = seat_price_from_lock['areaInfo'] if len(seat_price_from_lock['areaInfo']) > 0 else False lock_flag = seat_price_from_lock['lockFlag'] @@ -34,6 +36,7 @@ def general_seat_params(pay_type, data): 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) if not result_play: + print('result_play False') return False, None, None, None, None, None, None, None market_price = seat_price_from_play['marketPrice'] play_id = seat_price_from_play['id'] @@ -44,6 +47,7 @@ def general_seat_params(pay_type, data): 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) if not result_config: + print('result_config False') return False, None, None, None, None, None, None, None handle_fee = seat_price_from_config['handleFee'] partner_type = seat_price_from_config['partnerSubsidyType'] # 1:电商平台补贴;2:合作商补贴 @@ -53,6 +57,7 @@ def general_seat_params(pay_type, data): 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) if not result_seat: + print('result_seat False') return False, None, None, None, None, None, None, None 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] @@ -147,6 +152,7 @@ def general_seat_params(pay_type, data): result_ecard, _format_ecard, seat_price_from_ecard, _timestamp_ecard = get_data_from_redis( redis_key_api_ecard) if not result_ecard: + print('result_ecard False') return False, None, None, None, None, None, None, None ecard_info = seat_price_from_ecard['seatPrices'] if len(seat_price_from_ecard['seatPrices']) > 0 else False # 错误判断 @@ -195,6 +201,7 @@ def general_seat_params(pay_type, data): result_yushouquan, _format_yushouquan, seat_price_from_yushouquan, _timestamp_yushouquan = get_data_from_redis( redis_key_api_yushouquan) if not result_yushouquan: + print('result_yushouquan False') return False, None, None, None, None, None, None, None # 获取券码 req_params = get_param_from_redis(redis_key_api_yushouquan) @@ -229,3 +236,180 @@ def general_seat_params(pay_type, data): return True, ','.join(seat_list), ticket_cash, play_id, play_update_time, lock_flag, quan, last_timestamp else: pass + + +def general_seat_params_member(pay_type, data, card): + """ + seat_id-handle_fee-price-ticket_type-is_discount-settlement_price-service_fee 组成的字符串,多个值(多个seat)组用半角逗号分隔。 + seat_id: 要购买的座位号 + handle_fee:手续费,如果下单传入了退票订单号,会将handle_fee字段视为改签手续费 + price:(不包含手续费)会员卡支付金额,该字段值是否包含影厅座位服务费取决于字段is_split_service_fee + ticket_type: 影票类型(《会员卡详细信息》接口的业务响应参数desc的值) + is_discount: 0:普通票,1:会员票,2:全局会员票 + settlement_price:座位结算价,用于计算座位补贴(补贴=结算价-支付价),该值不能低于场次最低票价。(只有当参数is_cinema_price=2时,该值才有效,平台请求影院购票接口时会将计算出的补贴金额传给影院,补贴金额会计入影城报表。 + 注:该字段值是否包含影厅座位服务费取决于字段is_split_service_fee) + service_fee:影厅座位服务费(只有当参数is_cinema_price=2时,该值才有效) + + 返回 结果, seat, play_id, play_update_time, lock_flag, seat_coupons, is_cinema_price, is_split_service_fee, cash_pay, timestamp + """ + # 获取卡类型 + card_type = get_card_type(data["env"], data["pid"], data["cid"], card) + if card_type is False: + return_str = '此会员卡在该影院无法使用,请使用3.1.3 查询会员卡的详细信息接口查看卡信息' + return False, return_str, return_str, return_str, return_str, return_str, '2', 'Y', None, int(time.time() * 1000) + + # 获取其他参数 + redis_key_prefix = f'dspt_api_{data["ip"]}_{data["env"]}_{data["member_type"]}_{data["pid"]}_{data["cid"]}' + + seat_list = [] + + # seat_id + request_api_seat = {'name': '3.2.6 获取某场次座位状态', 'path': 'play/seat-status'} + redis_key_api_seat = f'{redis_key_prefix}_{request_api_seat["path"]}' + result_seat, _format_seat, seat_data, _timestamp_seat = get_data_from_redis(redis_key_api_seat) + if not result_seat: + return False, None, None, None, None, None, None, None, None, None + + # 获取play_id 和 play_update_time + request_api_play = {'name': '3.2.3 获取放映计划列表', '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) + if not result_play: + return False, None, None, None, None, None, None, None, None, None + play_id = seat_price_from_play['id'] + play_update_time = seat_price_from_play['cineUpdateTime'] + lowest_price = f2(seat_price_from_play['lowestPrice']) + + # 获取 lock_flag + request_api_lock = {'name': '3.4.3 座位锁定', '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) + if not result_lock: + return False, None, None, None, None, None, None, None, None, None + lock_flag = seat_price_from_lock['lockFlag'] + + # cinema_price + request_api_seat = {'name': '3.4.4 锁定座位后获取票价', 'path': 'seat/price'} + redis_key_api_seat = f'{redis_key_prefix}_{request_api_seat["path"]}' + result_seat_price, _format_seat_price, seat_data_price, _timestamp_seat_price = get_data_from_redis( + redis_key_api_seat) + if not result_seat_price: + return False, None, None, None, None, None, None, None, None, None + + # handle_fee + request_api_config = {'name': '3.2.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) + if not result_config: + return False, None, None, None, None, None, None, None, None, None + handle_fee = f2(seat_price_from_config['handleFee']) + + # 计算最大时间戳 + last_timestamp = max([_timestamp_seat, _timestamp_play, _timestamp_config, _timestamp_lock, _timestamp_seat_price]) + + # 判断获取到了全部接口数据,就继续,否则报错 + if not (result_seat and result_play and result_lock and result_seat_price and result_config): + return_str = '请手动输入参数,检查相关接口返回值:3.2.6 获取某场次座位状态、3.2.3 获取放映计划列表、3.4.3 座位锁定、3.4.4 锁定座位后获取票价、3.2.2 获取单个影院配置信息' + return False, return_str, return_str, return_str, return_str, return_str, '1', None, None, last_timestamp + + # 处理影院定价逻辑 + if pay_type['select_price_type'] == 'cinema_price': + # 11682-1-27.7-会员票-1 + is_cinema_price = '1' + is_split_service_fee = None + seat_coupons = None + + # 计算影票价 + ticket_price = f2(f2(seat_data_price['totalPrice']) / int(seat_data_price['ticketNum'])) + ticket_service = f2(f2(seat_data_price['totalServiceCharge']) / int(seat_data_price['ticketNum'])) + + cash_pay = 0 # 计算需要非卡余额支付的金额 + + # 生成座位字段 + for seat in seat_data: + seat_list.append(f"{seat['cineSeatId']}-{str(handle_fee)}-{str(ticket_price)}-会员票-1") + if card_type == '权益卡(积分卡)': + cash_pay += f2(ticket_price + handle_fee) + else: + cash_pay += 0 + + return True, ','.join( + seat_list), play_id, play_update_time, lock_flag, seat_coupons, is_cinema_price, is_split_service_fee, str(cash_pay), last_timestamp + + # 处理三方定价的逻辑 + if pay_type['select_price_type'] == 'third_price': + # 11664-1-16.5-会员票-1-26.5-1.5 + is_cinema_price = '2' + + # 处理is_split_service_fee字段 + if pay_type['ticket_info']['have_service_fee'] is True: + is_split_service_fee = 'Y' + else: + is_split_service_fee = 'N' + + # 生成券字段 + # 11663-Rog自营兑换券10元@@6777bbcfhirW6VAqkHItn3PZ@@10.00@@0 + quan_list = [] + quan_price_list = [] + quan_price_num = [] + seat_id_quan_list = [] + if pay_type['ticket_quan_check']: + + quan_per_ticket = int(int(pay_type['ticket_quan']['ticket_quan_num'])/len(seat_data)) # 每张票平均分配的券数量 + quan_price_num = [quan_per_ticket] * len(seat_data) # 每张票平均分配的券数量列表 + # 多余的券添加到每张票上 + for i in range(int(pay_type['ticket_quan']['ticket_quan_num'])%len(seat_data)): + quan_price_num[i] += 1 + print('quan_price_num', quan_price_num) + + # 遍历座位券列表,获取座位id,并写入列表 + for index, num in enumerate(quan_price_num): + for i in range(num): + seat_id_quan_list.append(seat_data[index]['cineSeatId']) + print('seat_id_quan_list', seat_id_quan_list) + + # 生成券字段列表 + quan_price = f2(pay_type['ticket_quan']['ticket_quan_value']) + quan_num = int(pay_type['ticket_quan']['ticket_quan_num']) + for i in range(quan_num): + seat_id = seat_id_quan_list[i] + quan_list.append(f"{seat_id}-Rog接口测试券{str(quan_price)}@@rog{str(time.time_ns())}{seat_id}@@{str(quan_price)}@@0") + quan_price_list.append(quan_price) + + seat_coupons = ','.join(quan_list) if len(quan_list) > 0 else None # 生成券字段 + + ticket_price = f2(pay_type['ticket_info']['ticket_price']) + ticket_service = f2(f2(seat_data_price['totalServiceCharge']) / int(seat_data_price['ticketNum'])) + ticket_price_service = f2(ticket_price + ticket_service) + + cash_pay = 0 + for i, seat in enumerate(seat_data): + if i+1 <= len(quan_price_list): + real_pay_tmp = f2(ticket_price_service - (quan_price_list[i] * quan_price_num[i])) # 实付票价减去券核销的价格 + else: + real_pay_tmp = ticket_price_service # 无券核销的实付价格 + + if is_split_service_fee == 'N': + real_pay_tmp -= ticket_service # 如果不包含服务费,则要从实付价格中减去服务费 + real_pay = real_pay_tmp if real_pay_tmp > 0 else 0 # 因为使用了券,实付价格可能低于0,需要修正到0 + + if card_type == '权益卡(积分卡)': + cash_pay += f2(real_pay + handle_fee) # 当使用权益卡支付时,需要将实付票价累加到现金支付字段中 + else: + cash_pay += 0 + + if ticket_price >= lowest_price: + real_ticket_price = ticket_price_service # 计算应付票价,如果用户设定的票价低于最低票价,则按照最低票价计算,否则按照用户定义价计算 + else: + real_ticket_price = f2(lowest_price + ticket_service) + + if is_split_service_fee == 'N': + real_ticket_price -= ticket_service # 如果不包含服务费,则要减去服务费 + if card_type == '权益卡(积分卡)': + cash_pay += ticket_service # 如果是权益卡则单独累加服务费 + + seat_list.append( + f"{seat['cineSeatId']}-{str(handle_fee)}-{str(real_pay)}-会员票-1-{str(real_ticket_price)}-{str(ticket_service)}") + + return True, ','.join( + seat_list), play_id, play_update_time, lock_flag, seat_coupons, is_cinema_price, is_split_service_fee, str(cash_pay), last_timestamp \ No newline at end of file diff --git a/dspt_api/util/general/suggest_params.py b/dspt_api/util/general/suggest_params.py index 955ddde..d494c14 100644 --- a/dspt_api/util/general/suggest_params.py +++ b/dspt_api/util/general/suggest_params.py @@ -26,7 +26,11 @@ from dspt_api.util.api.order_status import ApiOrderStatus from dspt_api.util.api.order_info import ApiOrderInfo from dspt_api.util.api.goods_deduct import ApiGoodsDeduct from dspt_api.util.mapi.play_seat_status import MapiPlaySeatStatus - +from dspt_api.util.mapi.seat_lock import MapiSeatLock +from dspt_api.util.mapi.seat_price import MapiSeatPrice +from dspt_api.util.mapi.seat_lock_buy import MapiSeatLockBuy +from dspt_api.util.mapi.card_get_goods_price import MapiCardGetGoodsPrice +from dspt_api.util.mapi.order_buy_goods import MapiOrderBuyGoods # 通过api来匹配不同的接口文件获取推荐 # 返回推荐参数应该包含参数名,参数值,和是否勾选的状态 @@ -157,7 +161,34 @@ def suggest_params(member_type, api, env, cid, pid, ip, **kwargs): if api == 'play/seat-status' and member_type == 'member': print('play/seat-status') params = MapiPlaySeatStatus(**data).get_suggestion() - + # 3.3.2 获取卖品折扣信息 + if api == 'card/get-goods-price' and member_type == 'member': + print('card/get-goods-price') + params = MapiCardGetGoodsPrice(**data).get_suggestion() + # 3.4.3 座位锁定 + if api == 'seat/lock' and member_type == 'member': + print('seat/lock') + params = MapiSeatLock(**data).get_suggestion() + # 3.4.4 座位锁定后获取票价 + if api == 'seat/price' and member_type == 'member': + print('seat/price') + params = MapiSeatPrice(**data).get_suggestion() + # 3.4.6 混合下单(影票、卖品) + if api == 'seat/lock-buy' and member_type == 'member': + print('seat/lock-buy') + print("kwargs['sale_type']", kwargs['sale_type']) + print("kwargs['pay_type']", kwargs['pay_type']) + data['sale_type'] = kwargs['sale_type'] + data['pay_type'] = kwargs['pay_type'] + params = MapiSeatLockBuy(**data).get_suggestion() + # 3.4.7 单独下单(卖品) + if api == 'order/buy-goods' and member_type == 'member': + print('order/buy-goods') + print("kwargs['sale_type']", kwargs['sale_type']) + print("kwargs['pay_type']", kwargs['pay_type']) + data['sale_type'] = kwargs['sale_type'] + data['pay_type'] = kwargs['pay_type'] + params = MapiOrderBuyGoods(**data).get_suggestion() return params def suggest_params_timestamp(member_type, api, env, cid, pid, ip, **kwargs): @@ -282,7 +313,32 @@ def suggest_params_timestamp(member_type, api, env, cid, pid, ip, **kwargs): if api == 'play/seat-status' and member_type == 'member': print('play/seat-status') _timestamps = MapiPlaySeatStatus(**data).get_timestamp() - + # 3.3.2 获取卖品折扣信息 + if api == 'card/get-goods-price' and member_type == 'member': + print('card/get-goods-price') + _timestamps = MapiCardGetGoodsPrice(**data).get_timestamp() + # 3.4.3 座位锁定 + if api == 'seat/lock' and member_type == 'member': + print('seat/lock') + _timestamps = MapiSeatLock(**data).get_timestamp() + # 3.4.4 座位锁定后获取票价 + if api == 'seat/price' and member_type == 'member': + print('seat/price') + _timestamps = MapiSeatPrice(**data).get_timestamp() + # 3.4.6 混合下单(影票、卖品) + if api == 'seat/lock-buy' and member_type == 'member': + print('seat/lock-buy') + data['sale_type'] = kwargs['sale_type'] + data['pay_type'] = kwargs['pay_type'] + _timestamps = MapiSeatLockBuy(**data).get_timestamp() + # 3.4.7 单独下单(卖品) + if api == 'order/buy-goods' and member_type == 'member': + print('order/buy-goods') + print("kwargs['sale_type']", kwargs['sale_type']) + print("kwargs['pay_type']", kwargs['pay_type']) + data['sale_type'] = kwargs['sale_type'] + data['pay_type'] = kwargs['pay_type'] + _timestamps = MapiOrderBuyGoods(**data).get_timestamp() return _timestamps diff --git a/dspt_api/util/mapi/card_get_goods_price.py b/dspt_api/util/mapi/card_get_goods_price.py new file mode 100644 index 0000000..99a2d2d --- /dev/null +++ b/dspt_api/util/mapi/card_get_goods_price.py @@ -0,0 +1,51 @@ +import json + +from dspt_api.util.general.handle_redis import get_data_from_redis +from dspt_api.util.general.handle_params import add_param +from dspt_api.util.general.handle_card import get_card +from dspt_api.util.general.handle_goods import general_goods_field_member, change_goods_price_str +import time + + +class MapiCardGetGoodsPrice: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + self.env = kwargs.get('env') + self.cid = kwargs.get('cid') + self.pid = kwargs.get('pid') + self.user_data = { + 'ip': self.ip, + 'env': self.env, + 'member_type': self.member_type, + 'pid': self.pid, + 'cid': self.cid, + } + self.return_data = [] + + def get_suggestion(self): + # play_id play_update_time + print('get_suggestion', self.user_data) + self.handle() + return self.return_data + + def get_timestamp(self): + return self.handle() + + def handle(self): + # 获取会员卡号 + card_num = get_card(self.ip, self.env, self.pid, self.cid) + if card_num is False: + add_param(self.return_data, 'card', '请手动输入会员卡号', timestamp=int(time.time() * 1000)) + else: + add_param(self.return_data, 'card', card_num, timestamp=int(time.time() * 1000)) + redis_key_prefix = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}' + request_api_play_seat_status = {'name': '3.3.1 获取卖品列表', 'path': 'cinema/goods'} + redis_key_api_play_seat_status = f'{redis_key_prefix}_{request_api_play_seat_status["path"]}' + result, _format, _goods_data, _timestamp = get_data_from_redis(redis_key_api_play_seat_status) + goods_field_list, total_goods_val = general_goods_field_member(_goods_data, self.user_data) + if not result: + add_param(self.return_data,'goods', '请手动输入参数,或先请求接口:3.3.1 获取卖品列表') + add_param(self.return_data,'goods', json.dumps(change_goods_price_str(goods_field_list))) + return _timestamp if result else 0 \ No newline at end of file diff --git a/dspt_api/util/mapi/order_buy_goods.py b/dspt_api/util/mapi/order_buy_goods.py new file mode 100644 index 0000000..5f8e7d2 --- /dev/null +++ b/dspt_api/util/mapi/order_buy_goods.py @@ -0,0 +1,79 @@ +import json +from dspt_api.util.general.handle_redis import get_data_from_redis +from dspt_api.util.general.handle_seat import general_seat_params_member +from dspt_api.util.general.get_order_num import general_order_num +from dspt_api.util.general.handle_goods import general_goods_params_member +from dspt_api.util.general.handle_card import get_card +from dspt_api.util.general.handle_params import add_param +import time +import random + + +class MapiOrderBuyGoods: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + self.env = kwargs.get('env') + self.cid = kwargs.get('cid') + self.pid = kwargs.get('pid') + self.sale_type = kwargs.get('sale_type') + self.pay_type = kwargs.get('pay_type') + self.user_data = { + 'ip': self.ip, + 'env': self.env, + 'member_type': self.member_type, + 'pid': self.pid, + 'cid': self.cid, + 'sale_type': self.sale_type, + 'pay_type': self.pay_type, + } + self.return_data = [] + + def get_suggestion(self): + print('get_suggestion', self.user_data, self.sale_type, self.pay_type) + # 获取会员卡号 + card_num = get_card(self.ip, self.env, self.pid, self.cid) + if card_num is False: + add_param(self.return_data, 'card', '请手动输入会员卡号', timestamp=int(time.time() * 1000)) + else: + add_param(self.return_data, 'card', card_num, timestamp=int(time.time() * 1000)) + # 通用字段 + add_param(self.return_data, 'mobile', '18688886666', timestamp=1000000000000) + _partner_buy_ticket_id = general_order_num('BUY_T', self.api, self.member_type, self.ip, self.env, self.pid, + self.cid) + add_param(self.return_data, 'partner_buy_ticket_id', _partner_buy_ticket_id) + + self.handle(card_num) + print(__name__, self.return_data) + return self.return_data + + @staticmethod + def get_timestamp(): + return int(time.time() * 1000) + + def handle(self, card_num): + _third_pay = 0 + if self.sale_type == 'goods': + delivery_appoint_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time() + 5 * 60)) + _good_result, _goods_field, _goods_card_balance_pay, _goods_cash, _third_pay, _goods_timestamp = general_goods_params_member( + self.user_data, self.pay_type, card_num, _third_pay) + print('general_goods_params_member', _good_result, _goods_field, _goods_card_balance_pay, _goods_cash, + _third_pay, _goods_timestamp) + if _good_result is False: + add_param(self.return_data, 'goods', '请手动输入参数,或先请求接口:3.3.1 获取卖品列表', + timestamp=_goods_timestamp) + add_param(self.return_data, 'goods_card_balance_pay', '请手动输入参数,或先请求接口:3.3.1 获取卖品列表', + timestamp=_goods_timestamp) + add_param(self.return_data, 'goods_cash', '请手动输入参数,或先请求接口:3.3.1 获取卖品列表', + timestamp=_goods_timestamp) + return False + add_param(self.return_data, 'goods', json.dumps(_goods_field), timestamp=_goods_timestamp) + add_param(self.return_data, 'goods_card_balance_pay', _goods_card_balance_pay, timestamp=_goods_timestamp) + add_param(self.return_data, 'goods_cash', _goods_cash, timestamp=_goods_timestamp) + add_param(self.return_data, 'delivery_type', '2', is_checked=True, timestamp=_goods_timestamp) + add_param(self.return_data, 'delivery_location', '1号厅', is_checked=True, timestamp=_goods_timestamp) + add_param(self.return_data, 'delivery_appoint_time', delivery_appoint_time, is_checked=True, + timestamp=_goods_timestamp) + add_param(self.return_data, 'contact_number', '18688886666', is_checked=True, timestamp=_goods_timestamp) + add_param(self.return_data, 't3d_pay_amount', _third_pay, timestamp=_goods_timestamp) diff --git a/dspt_api/util/mapi/play_seat_status.py b/dspt_api/util/mapi/play_seat_status.py index 036bd88..f2cfaa6 100644 --- a/dspt_api/util/mapi/play_seat_status.py +++ b/dspt_api/util/mapi/play_seat_status.py @@ -27,12 +27,7 @@ class MapiPlaySeatStatus: return self.return_data def get_timestamp(self): - # play_id play_update_time - redis_key_prefix = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}' - request_api_play_seat_status = {'name': '3.2.3 获取放映计划列表', 'path': 'cinema/plays'} - redis_key_api_play_seat_status = f'{redis_key_prefix}_{request_api_play_seat_status["path"]}' - result, _format, play_data, _timestamp = get_data_from_redis(redis_key_api_play_seat_status) - return _timestamp if result else 0 + return self.handle() def handle(self): redis_key_prefix = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}' @@ -44,4 +39,4 @@ class MapiPlaySeatStatus: add_param(self.return_data,'play_update_time', '请手动输入参数,或先请求接口:3.2.3 获取放映计划列表') add_param(self.return_data,'play_id', play_data['id']) add_param(self.return_data,'play_update_time', play_data['cineUpdateTime']) - + return _timestamp if result else 0 diff --git a/dspt_api/util/mapi/seat_lock.py b/dspt_api/util/mapi/seat_lock.py new file mode 100644 index 0000000..1123139 --- /dev/null +++ b/dspt_api/util/mapi/seat_lock.py @@ -0,0 +1,55 @@ +from dspt_api.util.general.handle_redis import get_data_from_redis +from dspt_api.util.general.handle_params import add_param +import random + + +class MapiSeatLock: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + self.env = kwargs.get('env') + self.cid = kwargs.get('cid') + self.pid = kwargs.get('pid') + self.user_data = { + 'ip': self.ip, + 'env': self.env, + 'member_type': self.member_type, + 'pid': self.pid, + 'cid': self.cid, + } + self.return_data = [] + + def get_suggestion(self): + print('get_suggestion', self.user_data) + self.handle() + return self.return_data + + def get_timestamp(self): + return self.handle() + + def handle(self): + redis_key_prefix = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}' + # play_id + 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, play_data, _timestamp_play = get_data_from_redis(redis_key_api_play) + if not result_play: + add_param(self.return_data, 'play_id', '请手动输入参数,或先请求接口:3.2.3 获取放映计划列表') + add_param(self.return_data, 'play_update_time', '请手动输入参数,或先请求接口:3.2.3 获取放映计划列表') + else: + add_param(self.return_data, 'play_id', play_data['id']) + add_param(self.return_data, 'play_update_time', play_data['cineUpdateTime']) + # seat_id + 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_data, _timestamp_seat = get_data_from_redis(redis_key_api_seat) + if not result_seat: + add_param(self.return_data, 'seat_id', '请手动输入参数,或先请求接口:3.2.6 获取场次座位状态') + else: + seat_id = ','.join([seat['cineSeatId'] for seat in seat_data]) + add_param(self.return_data, 'seat_id', seat_id) + # 处理混合结果 + if result_play and result_seat: + return _timestamp_play if _timestamp_play > _timestamp_seat else _timestamp_seat + return 0 \ No newline at end of file diff --git a/dspt_api/util/mapi/seat_lock_buy.py b/dspt_api/util/mapi/seat_lock_buy.py new file mode 100644 index 0000000..5f0aae2 --- /dev/null +++ b/dspt_api/util/mapi/seat_lock_buy.py @@ -0,0 +1,117 @@ +import json +from dspt_api.util.general.handle_redis import get_data_from_redis +from dspt_api.util.general.handle_seat import general_seat_params_member +from dspt_api.util.general.get_order_num import general_order_num +from dspt_api.util.general.handle_goods import general_goods_params_member +from dspt_api.util.general.handle_card import get_card +from dspt_api.util.general.handle_params import add_param +import time +import random + + +class MapiSeatLockBuy: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + self.env = kwargs.get('env') + self.cid = kwargs.get('cid') + self.pid = kwargs.get('pid') + self.sale_type = kwargs.get('sale_type') + self.pay_type = kwargs.get('pay_type') + self.user_data = { + 'ip': self.ip, + 'env': self.env, + 'member_type': self.member_type, + 'pid': self.pid, + 'cid': self.cid, + 'sale_type': self.sale_type, + 'pay_type': self.pay_type, + } + self.return_data = [] + + def get_suggestion(self): + print('get_suggestion', self.user_data, self.sale_type, self.pay_type) + # 获取会员卡号 + card_num = get_card(self.ip, self.env, self.pid, self.cid) + if card_num is False: + add_param(self.return_data, 'card', '请手动输入会员卡号', timestamp=int(time.time() * 1000)) + else: + add_param(self.return_data, 'card', card_num, timestamp=int(time.time() * 1000)) + # 通用字段 + add_param(self.return_data, 'mobile', '18688886666', timestamp=1000000000000) + _partner_buy_ticket_id = general_order_num('BUY_T', self.api, self.member_type, self.ip, self.env, self.pid, + self.cid) + add_param(self.return_data, 'partner_buy_ticket_id', _partner_buy_ticket_id) + + self.handle(card_num) + print('ApiSeatLockBuy-get_suggestion', self.return_data) + return self.return_data + + @staticmethod + def get_timestamp(): + return int(time.time() * 1000) + + def handle(self, card_num): + # 处理影票部分 + _ticket_result, _seat, _play_id, _play_update_time, _lock_flag, _seat_coupons, _is_cinema_price, _is_split_service_fee, _third_pay, _ticket_timestamp = general_seat_params_member( + self.pay_type, self.user_data, card_num) + print('general_seat_params', _ticket_result, _seat, _play_id, _play_update_time, _lock_flag, _seat_coupons, + _is_cinema_price, _is_split_service_fee, _third_pay, _ticket_timestamp) + if _ticket_result is False: + add_param(self.return_data, 'play_id', '请手动输入参数,或先请求接口:3.1.5 获取放映计划列表', + timestamp=_ticket_timestamp) + add_param(self.return_data, 'seat', '请手动输入参数,或先请求接口:3.1.8 获取某场次座位状态', + timestamp=_ticket_timestamp) + add_param(self.return_data, 'lock_flag', '请手动输入参数,或先请求接口:3.3.1 座位锁定', + timestamp=_ticket_timestamp) + add_param(self.return_data, 'play_update_time', '请手动输入参数,或先请求接口:3.1.5 获取放映计划列表', + timestamp=_ticket_timestamp) + add_param(self.return_data, 'seat_coupons', '请手动输入参数,或请求其他前置接口返回结果!', + timestamp=_ticket_timestamp) + add_param(self.return_data, 'is_cinema_price', '请手动输入参数,或请求其他前置接口返回结果!', + timestamp=_ticket_timestamp) + add_param(self.return_data, 'is_split_service_fee', '请手动输入参数,或请求其他前置接口返回结果!', + timestamp=_ticket_timestamp) + add_param(self.return_data, 't3d_pay_amount', '请手动输入参数,或请求其他前置接口返回结果!', + timestamp=_ticket_timestamp) + return False + add_param(self.return_data, 'play_id', _play_id, timestamp=_ticket_timestamp) + add_param(self.return_data, 'seat', _seat, timestamp=_ticket_timestamp) + add_param(self.return_data, 'lock_flag', _lock_flag, timestamp=_ticket_timestamp) + add_param(self.return_data, 'play_update_time', _play_update_time, timestamp=_ticket_timestamp) + add_param(self.return_data, 'is_cinema_price', _is_cinema_price, timestamp=_ticket_timestamp) + if _is_split_service_fee is not None: + add_param(self.return_data, 'is_split_service_fee', _is_split_service_fee, timestamp=_ticket_timestamp) + else: + add_param(self.return_data, 'is_split_service_fee', '', False, True, timestamp=_ticket_timestamp) + if _seat_coupons is not None: + add_param(self.return_data, 'seat_coupons', _seat_coupons, timestamp=_ticket_timestamp) + else: + add_param(self.return_data, 'seat_coupons', '', False, True, timestamp=_ticket_timestamp) + + # 处理卖品部分 + if self.sale_type == 'all': + delivery_appoint_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time() + 5 * 60)) + _good_result, _goods_field, _goods_card_balance_pay, _goods_cash, _third_pay, _goods_timestamp = general_goods_params_member( + self.user_data, self.pay_type, card_num, _third_pay) + print('general_goods_params_member', _good_result, _goods_field, _goods_card_balance_pay, _goods_cash, + _third_pay, _goods_timestamp) + if _good_result is False: + add_param(self.return_data, 'goods', '请手动输入参数,或先请求接口:3.3.1 获取卖品列表', + timestamp=_goods_timestamp) + add_param(self.return_data, 'goods_card_balance_pay', '请手动输入参数,或先请求接口:3.3.1 获取卖品列表', + timestamp=_goods_timestamp) + add_param(self.return_data, 'goods_cash', '请手动输入参数,或先请求接口:3.3.1 获取卖品列表', + timestamp=_goods_timestamp) + return False + add_param(self.return_data, 'goods', json.dumps(_goods_field), timestamp=_goods_timestamp) + add_param(self.return_data, 'goods_card_balance_pay', _goods_card_balance_pay, timestamp=_goods_timestamp) + add_param(self.return_data, 'goods_cash', _goods_cash, timestamp=_goods_timestamp) + add_param(self.return_data, 'delivery_type', '2', is_checked=True, timestamp=_goods_timestamp) + add_param(self.return_data, 'delivery_location', '1号厅', is_checked=True, timestamp=_goods_timestamp) + add_param(self.return_data, 'delivery_appoint_time', delivery_appoint_time, is_checked=True, + timestamp=_goods_timestamp) + add_param(self.return_data, 'contact_number', '18688886666', is_checked=True, timestamp=_goods_timestamp) + + add_param(self.return_data, 't3d_pay_amount', _third_pay, timestamp=_ticket_timestamp) diff --git a/dspt_api/util/mapi/seat_price.py b/dspt_api/util/mapi/seat_price.py new file mode 100644 index 0000000..84660aa --- /dev/null +++ b/dspt_api/util/mapi/seat_price.py @@ -0,0 +1,49 @@ +from dspt_api.util.general.handle_redis import get_data_from_redis +from dspt_api.util.general.handle_params import add_param +from dspt_api.util.general.handle_card import get_card + + +class MapiSeatPrice: + def __init__(self, **kwargs): + self.member_type = kwargs.get('member_type') + self.api = kwargs.get('api') + self.ip = kwargs.get('ip') + self.env = kwargs.get('env') + self.cid = kwargs.get('cid') + self.pid = kwargs.get('pid') + self.user_data = { + 'ip': self.ip, + 'env': self.env, + 'member_type': self.member_type, + 'pid': self.pid, + 'cid': self.cid, + } + self.return_data = [] + + def get_suggestion(self): + print('get_suggestion', self.user_data) + self.handle() + return self.return_data + + def get_timestamp(self): + return self.handle() + + def handle(self): + # card + card = get_card(self.ip, self.env, self.pid, self.cid) + if not card: + add_param(self.return_data, 'card', '请手动输入参数') + add_param(self.return_data, 'card', card) + + redis_key_prefix = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}' + # lock_code + request_api_seat_lock = {'name': '3.4.3 座位锁定', 'path': 'seat/lock'} + redis_key_api_seat_lock = f'{redis_key_prefix}_{request_api_seat_lock["path"]}' + result_seat_lock, _format_seat_lock, seat_lock_data, _timestamp_seat_lock = get_data_from_redis( + redis_key_api_seat_lock) + if not result_seat_lock: + add_param(self.return_data, 'lock_flag', '请手动输入参数,或先请求接口:3.4.3 座位锁定') + else: + add_param(self.return_data, 'lock_flag', seat_lock_data['lockFlag']) + # 处理混合结果 + return _timestamp_seat_lock if result_seat_lock else 0 diff --git a/dspt_api/views.py b/dspt_api/views.py index 374d978..ed3ea0b 100644 --- a/dspt_api/views.py +++ b/dspt_api/views.py @@ -29,6 +29,7 @@ from dspt_api.util.general.handle_xml_resp import HandleXmlResp from dspt_api.util.general.format_xml import format_xml from dspt_api.util.general.get_cinema_quan import GetQuan from dspt_api.util.general.handle_ecard import set_ecard +from dspt_api.util.general.handle_card import set_card # Create your views here. @@ -149,8 +150,36 @@ def get_suggest_params_by_api(request): cid = request.GET.get('cid') pid = request.GET.get('pid') user_ip = request.META.get('REMOTE_ADDR') + print('request.GET', request.GET) sale_type = request.GET.get('options[sale_type]', None) - pay_type = request.GET.get('options[pay_type]', None) + if member_type == 'nonmember': + pay_type = request.GET.get('options[pay_type]', None) + print('pay_type', pay_type) + elif member_type == 'member': + print('pay_type', request.GET.get('options[pay_type]')) + pay_type_dict = json.loads(request.GET.get('options[pay_type]')) + pay_type = { + 'select_price_type': pay_type_dict.get('select_price_type', None), + 'ticket_info': { + 'ticket_price': pay_type_dict.get('ticket_info', None).get('ticket_price', None), + 'have_service_fee': pay_type_dict.get('ticket_info', None).get('have_service_fee', None), + }, + 'ticket_quan_check': pay_type_dict.get('ticket_quan_check', None), + 'ticket_quan': { + 'ticket_quan_num': pay_type_dict.get('ticket_quan', None).get('ticket_quan_num', None), + 'ticket_quan_value': pay_type_dict.get('ticket_quan', None).get('ticket_quan_value', None), + }, + 'goods_quan_check': pay_type_dict.get('goods_quan_check', None), + 'goods_quan': { + 'goods_quan_num': pay_type_dict.get('goods_quan', None).get('goods_quan_num', None), + 'goods_quan_value': pay_type_dict.get('goods_quan', None).get('goods_quan_value', None), + 'goods_quan_type': pay_type_dict.get('goods_quan', None).get('goods_quan_type', None), + } + } + print('pay_type', pay_type) + else: + print('options[pay_type]参数错误') + pay_type = None params = suggest_params(member_type, api, env, cid, pid, user_ip, **{'sale_type': sale_type, 'pay_type': pay_type}) # if sale_type is None: # params = suggest_params(member_type, api, env, cid, pid, user_ip) @@ -227,6 +256,9 @@ def send_request(request): # 存储ecard if ecard_num := params.get('ecard_number', False): set_ecard(user_ip, env, pid, cid, ecard_num) + # 存储card + if card_num := params.get('card', False): + set_card(user_ip, env, pid, cid, card_num) # 发送请求 req, sig = handle_request(request)