购票部分先提交一版

main
RogerWork 3 months ago
parent b873d44561
commit f8d2fd236d
  1. 4
      dspt_api/util/api/ecard_detail.py
  2. 1
      dspt_api/util/api/ecard_refund.py
  3. 29
      dspt_api/util/api/ecard_renew.py
  4. 93
      dspt_api/util/api/order_buy_goods.py
  5. 24
      dspt_api/util/api/seat_check_coupon.py
  6. 96
      dspt_api/util/api/seat_lock_buy.py
  7. 2
      dspt_api/util/general/get_cinema_quan.py
  8. 47
      dspt_api/util/general/handle_ecard.py
  9. 4
      dspt_api/util/general/handle_float.py
  10. 90
      dspt_api/util/general/handle_goods.py
  11. 9
      dspt_api/util/general/handle_redis.py
  12. 130
      dspt_api/util/general/handle_seat.py
  13. 4
      dspt_api/util/general/handle_ticket.py
  14. 2
      dspt_api/util/general/suggest_params.py
  15. 6
      dspt_api/views.py
  16. 16998
      logs/dingxin.log
  17. 6
      update/utils/client_util.py

@ -1,5 +1,6 @@
import time
from dspt_api.util.general.handle_redis import get_data_from_redis
from dspt_api.util.general.handle_ecard import get_ecard
class ApiEcardDetail:
@ -13,6 +14,9 @@ class ApiEcardDetail:
def get_suggestion(self):
_now = int(time.time() * 1000)
# 获取本地记录的联名卡
if ecard_num := get_ecard(self.ip, self.env, self.pid, self.cid):
return [{'param': 'ecard_number', 'value': ecard_num,'is_checked': True, 'result': True,'timestamp': _now}]
# ecard_number
request_api_ec_1 = {'name': '3.4.4 获取联名卡详情', 'path': 'ecard/detail'}
redis_key_api_ec_1 = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api_ec_1["path"]}'

@ -3,6 +3,7 @@ from django_redis import get_redis_connection
from dspt_api.util.general.get_order_num import general_order_num
from dspt_api.util.general.handle_redis import get_data_from_redis
from dspt_api.util.api.ecard_order_detail import ApiEcardOrderDetail
from dspt_api.util.general.handle_ecard import get_ecard
class ApiEcardRefund:

@ -1,11 +1,8 @@
import random
import time
import pymysql
from pymysql.cursors import DictCursor
from dingxin_toolbox_drf.settings import CONFIG
from env import ENV
from dspt_api.util.general.get_order_num import general_order_num
from dspt_api.util.general.handle_redis import get_data_from_redis
from dspt_api.util.general.handle_ecard import get_ecard, get_ecard_renew_fee
class ApiEcardRenew:
@ -20,14 +17,21 @@ class ApiEcardRenew:
def get_suggestion(self):
_now = int(time.time() * 1000)
# ecard_number
# 获取本地记录的联名卡
ecard_number_result = False
ecard_number = False
if ecard_num := get_ecard(self.ip, self.env, self.pid, self.cid):
ecard_number = {'param': 'ecard_number', 'value': ecard_num, 'is_checked': True, 'result': True,
'timestamp': _now}
ecard_number_result = True
else:
request_api_ec_1 = {'name': '3.4.4 获取联名卡详情', 'path': 'ecard/detail'}
redis_key_api_ec_1 = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api_ec_1["path"]}'
request_api_ec_2 = {'name': '3.4.2 联名卡开卡', 'path': 'ecard/regist'}
redis_key_api_ec_2 = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api_ec_2["path"]}'
result_ec_1, _format_ec_1, redis_data_ec_1, _timestamp_ec_1 = get_data_from_redis(redis_key_api_ec_1)
result_ec_2, _format_ec_2, redis_data_ec_2, _timestamp_ec_2 = get_data_from_redis(redis_key_api_ec_2)
ecard_number_result = False
ecard_number = False
if result_ec_2:
print('redis_data_ec_2', redis_data_ec_2)
ecard_number_ec_2 = {'param': 'ecard_number', 'value': redis_data_ec_2['ecardNumber'],
@ -47,18 +51,7 @@ class ApiEcardRenew:
# renew_fee
result_renew_fee = False
if ecard_number is not False:
ecard_server = {
'host': CONFIG[ENV]['ECARD_DB']['HOST'],
'user': CONFIG[ENV]['ECARD_DB']['USER'],
'password': CONFIG[ENV]['ECARD_DB']['PASSWORD'],
'port': CONFIG[ENV]['ECARD_DB']['PORT'],
'database': CONFIG[ENV]['ECARD_DB']['NAME'],
}
ecard_conn = pymysql.Connect(**ecard_server)
ecard_cursor = ecard_conn.cursor(DictCursor)
sql = 'SELECT renew_fee FROM fws_dgp_card_db.card_level WHERE card_level_no = (SELECT card_level_no FROM fws_dgp_card_db.card WHERE card_num = %s);'
ecard_cursor.execute(sql, (ecard_number['value'],))
fee = ecard_cursor.fetchone()['renew_fee']
fee = get_ecard_renew_fee(ecard_number['value'])
if fee is not None:
renew_fee = {'param': 'renew_fee', 'value': fee,
'is_checked': True, 'result': True,

@ -1,6 +1,7 @@
from dspt_api.util.general.handle_redis import get_data_from_redis
from dspt_api.util.general.get_order_num import general_order_num
from dspt_api.util.general.handle_goods import general_goods_param
from dspt_api.util.general.handle_goods import general_goods_params
from dspt_api.util.general.handle_ecard import get_ecard
import time
import random
import json
@ -14,50 +15,52 @@ class ApiOrderBuyGoods:
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,
}
self.return_data = []
def get_suggestion(self):
request_api = {'name': '3.2.1 获取卖品列表', 'path': 'cinema/goods'}
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, goods_data, _timestamp = get_data_from_redis(redis_key_api)
if result:
goods_info, cash = general_goods_param(goods_data)
print('ApiOrderBuyGoods', goods_info)
order_num = general_order_num('GS', self.api, self.member_type, self.ip, self.env, self.pid, self.cid)
delivery_appoint_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time() + 5 * 60))
return [
{'param': 'partner_buy_ticket_id', 'value': order_num, 'is_checked': True, 'result': True,
'timestamp': _timestamp},
{'param': 'goods', 'value': json.dumps(goods_info), 'is_checked': True, 'result': True, 'timestamp': _timestamp},
{'param': 'cash', 'value': cash, 'is_checked': True, 'result': True, 'timestamp': _timestamp},
{'param': 'mobile', 'value': '18688886666', 'is_checked': True, 'result': True,
'timestamp': _timestamp},
{'param': 'delivery_type', 'value': '2', 'is_checked': False, 'result': True, 'timestamp': _timestamp},
{'param': 'delivery_location', 'value': '1号厅', 'is_checked': False, 'result': True,
'timestamp': _timestamp},
{'param': 'delivery_appoint_time', 'value': delivery_appoint_time, 'is_checked': False, 'result': True,
'timestamp': _timestamp},
{'param': 'contact_number', 'value': '18688886666', 'is_checked': False, 'result': True,
'timestamp': _timestamp}]
else:
# 返回推荐参数应该包含参数名,参数值,和是否勾选的状态
# redis_data + request_api["name"]
return [
{'param': 'partner_buy_ticket_id', 'value': goods_data + request_api["name"], 'is_checked': True,
'result': True,
'timestamp': _timestamp},
{'param': 'goods', 'value': goods_data + request_api["name"], 'is_checked': True, 'result': True,
'timestamp': _timestamp},
{'param': 'cash', 'value': '0', 'is_checked': True, 'result': True, 'timestamp': _timestamp},
{'param': 'mobile', 'value': '18688886666', 'is_checked': True, 'result': True,
'timestamp': _timestamp},
{'param': 'delivery_type', 'value': '2', 'is_checked': False, 'result': True, 'timestamp': _timestamp},
{'param': 'delivery_location', 'value': '1号厅', 'is_checked': False, 'result': True,
'timestamp': _timestamp},
{'param': 'delivery_appoint_time', 'value': '0000-00-00 00:00:00', 'is_checked': False, 'result': True,
'timestamp': _timestamp},
{'param': 'contact_number', 'value': '18688886666', 'is_checked': False, 'result': True,
'timestamp': _timestamp}
]
def get_timestamp(self):
# 通用字段
self.add_param('mobile', '18688886666', timestamp=1000000000000)
_partner_buy_ticket_id = general_order_num('BUY_G', self.api, self.member_type, self.ip, self.env, self.pid,
self.cid)
self.add_param('partner_buy_ticket_id', _partner_buy_ticket_id)
# 联名卡卡号
ecard_num = None
if self.pay_type == 'ecard':
ecard_num = get_ecard(self.ip, self.env, self.pid, self.cid)
self.add_param('ecard_number', ecard_num, timestamp=1000000000000)
self.goods()
return self.return_data
@staticmethod
def get_timestamp():
return int(time.time() * 1000)
def goods(self):
delivery_appoint_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time() + 5 * 60))
_good_result, _goods_field, _goods_cash, _quan, _goods_timestamp = general_goods_params(self.pay_type,
self.user_data)
if _good_result is False:
self.add_param('goods', '请手动输入参数,或先请求接口:3.2.1 获取卖品列表', timestamp=_goods_timestamp)
self.add_param('cash', '请手动输入参数,或先请求接口:3.2.1 获取卖品列表', timestamp=_goods_timestamp)
return False
self.add_param('goods', json.dumps(_goods_field), timestamp=_goods_timestamp)
self.add_param('cash', _goods_cash, timestamp=_goods_timestamp)
self.add_param('delivery_type', '2', is_checked=False, timestamp=_goods_timestamp)
self.add_param('delivery_location', '1号厅', is_checked=False, timestamp=_goods_timestamp)
self.add_param('delivery_appoint_time', delivery_appoint_time, is_checked=False, timestamp=_goods_timestamp)
self.add_param('contact_number', '18688886666', is_checked=False, timestamp=_goods_timestamp)
def add_param(self, field, value, is_checked=True, result=True, timestamp=int(time.time() * 1000)):
self.return_data.append(
{'param': field, 'value': value, 'is_checked': is_checked, 'result': result, 'timestamp': timestamp})

@ -1,6 +1,6 @@
from dspt_api.util.general.handle_redis import get_data_from_redis
from dspt_api.util.general.get_order_num import general_order_num
from dspt_api.util.general.handle_goods import general_goods_param
from dspt_api.util.general.handle_goods import general_goods_field
from dspt_api.util.general.handle_ticket import get_ticket_price
import time
import random
@ -27,30 +27,36 @@ class ApiSeatCheckCoupon:
return self.get_play() + self.get_goods()
def get_play(self):
redis_key_prefix = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_'
# play_id
print('get_play')
request_api_play = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'}
redis_key_api_play = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api_play["path"]}'
request_api_play = {'name': '3.1.8 获取某场次座位状态', 'path': 'cinema/plays'}
redis_key_api_play = f'{redis_key_prefix}{request_api_play["path"]}'
result_play, _format_play, redis_data_play, _timestamp_play = get_data_from_redis(redis_key_api_play)
print('redis_data_play', redis_data_play)
# seat_num
request_api_seat = {'name': '3.1.5 获取放映计划列表', 'path': 'play/seat-status'}
redis_key_api_seat = f'{redis_key_prefix}{request_api_seat["path"]}'
result_seat, _format_seat, redis_data_seat, _timestamp_seat = get_data_from_redis(redis_key_api_seat)
print('redis_data_seat', redis_data_seat)
seat_num = len(redis_data_seat) if result_seat else 1
if result_play:
play_data = random.choice(redis_data_play)
ticket_price, service_fee = get_ticket_price(play_data)
return [{'param': 'play_id', 'value': play_data['id'], 'is_checked': True, 'result': True},
ticket_price, service_fee = get_ticket_price(redis_data_play,None,None,True)
return [{'param': 'play_id', 'value': redis_data_play['id'], 'is_checked': True, 'result': True},
{'param': 'price', 'value': ticket_price, 'is_checked': True, 'result': True},
{'param': 'seat_num', 'value': '1', 'is_checked': True, 'result': True}]
{'param': 'seat_num', 'value': seat_num, 'is_checked': True, 'result': True}]
else:
return [{'param': 'play_id', 'value': redis_data_play + request_api_play["name"], 'is_checked': True,
'result': True},
{'param': 'price', 'value': '0.00', 'is_checked': True, 'result': True},
{'param': 'seat_num', 'value': '1', 'is_checked': True, 'result': True}]
{'param': 'seat_num', 'value': seat_num, 'is_checked': True, 'result': True}]
def get_goods(self):
request_api = {'name': '3.2.1 获取卖品列表', 'path': 'cinema/goods'}
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, goods_data, _timestamp = get_data_from_redis(redis_key_api)
if result:
goods_info, cash = general_goods_param(goods_data)
goods_info, cash = general_goods_field(goods_data)
print('ApiSeatCheckCoupon', goods_info)
coupon_goods = [self.format_goods(goods) for goods in goods_info]
return [

@ -1,6 +1,13 @@
import json
from twisted.mail.alias import handle
from dspt_api.util.general.handle_redis import get_data_from_redis
from dspt_api.util.general.handle_seat import general_seat_params
from dspt_api.util.general.get_order_num import general_order_num
from dspt_api.util.general.handle_goods import general_goods_params
from dspt_api.util.general.handle_ecard import get_ecard
import time
import random
@ -21,34 +28,73 @@ class ApiSeatLockBuy:
'pid': self.pid,
'cid': self.cid,
}
self.return_data = []
def get_suggestion(self):
return_data = [{'param': 'mobile', 'value': '18688886666', 'is_checked': True, 'result': True}]
# _ticket_result, _goods_result = False, False
if self.sale_type in ['ticket', 'all']:
_ticket_result, _seat, _ticket_cash, _play_id, _play_update_time, _lock_flag, _ticket_timestamp = general_seat_params(
self.pay_type, self.user_data)
print('general_seat_params', _ticket_result, _seat, _ticket_cash, _play_id, _play_update_time, _lock_flag, _ticket_timestamp)
_partner_buy_ticket_id = general_order_num('BUY', self.api, self.member_type, self.ip, self.env, self.pid,
print('get_suggestion', self.user_data, self.sale_type, self.pay_type)
# 通用字段
self.add_param('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)
return_data.append({'param': 'play_id', 'value': _play_id, 'is_checked': True, 'result': True})
return_data.append({'param': 'seat', 'value': _seat, 'is_checked': True, 'result': True})
return_data.append({'param': 'lock_flag', 'value': _lock_flag, 'is_checked': True, 'result': True})
return_data.append(
{'param': 'play_update_time', 'value': _play_update_time, 'is_checked': True, 'result': True})
return_data.append(
{'param': 'partner_buy_ticket_id', 'value': _partner_buy_ticket_id, 'is_checked': True, 'result': True})
return_data.append({'param': 'cash', 'value': _ticket_cash, 'is_checked': True, 'result': True})
elif self.sale_type in ['goods', 'all']:
pass
else:
pass
return return_data
self.add_param('partner_buy_ticket_id', _partner_buy_ticket_id)
def get_timestamp(self):
_ticket_result, _seat, _ticket_cash, _play_id, _play_update_time, _lock_flag, _ticket_timestamp = general_seat_params(
# 联名卡卡号
ecard_num = None
if self.pay_type == 'ecard':
ecard_num = get_ecard(self.ip, self.env, self.pid, self.cid)
self.add_param('ecard_number', ecard_num, timestamp=1000000000000)
self.handle()
print('ApiSeatLockBuy-get_suggestion', self.return_data)
return self.return_data
@staticmethod
def get_timestamp():
return int(time.time() * 1000)
def handle(self):
# 处理影票部分
_ticket_result, _seat, _ticket_cash, _play_id, _play_update_time, _lock_flag, _quan, _ticket_timestamp = general_seat_params(
self.pay_type, self.user_data)
print('general_seat_params', _ticket_result, _seat, _ticket_cash, _play_id, _play_update_time, _lock_flag,
_quan, _ticket_timestamp)
if _ticket_result is False:
self.add_param('play_id', '请手动输入参数,或先请求接口:3.1.5 获取放映计划列表', timestamp=_ticket_timestamp)
self.add_param('seat', '请手动输入参数,或先请求接口:3.1.8 获取某场次座位状态', timestamp=_ticket_timestamp)
self.add_param('lock_flag', '请手动输入参数,或先请求接口:3.3.1 座位锁定', timestamp=_ticket_timestamp)
self.add_param('play_update_time', '请手动输入参数,或先请求接口:3.1.5 获取放映计划列表',
timestamp=_ticket_timestamp)
self.add_param('cash', '请手动输入参数,或先请求接口:3.1.5 获取放映计划列表', timestamp=_ticket_timestamp)
return False
self.add_param('play_id', _play_id, timestamp=_ticket_timestamp)
self.add_param('seat', _seat, timestamp=_ticket_timestamp)
self.add_param('lock_flag', _lock_flag, timestamp=_ticket_timestamp)
self.add_param('play_update_time', _play_update_time, 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_cash, _quan, _goods_timestamp = general_goods_params(self.pay_type,
self.user_data,
_ticket_cash)
print('_goods_field', _goods_field)
if _good_result is False:
self.add_param('goods', '请手动输入参数,或先请求接口:3.2.1 获取卖品列表', timestamp=_goods_timestamp)
self.add_param('cash', '请手动输入参数,或先请求接口:3.2.1 获取卖品列表', timestamp=_goods_timestamp)
return False
self.add_param('goods', json.dumps(_goods_field), timestamp=_goods_timestamp)
self.add_param('cash', _goods_cash, timestamp=_goods_timestamp)
self.add_param('delivery_type', '2', is_checked=False, timestamp=_goods_timestamp)
self.add_param('delivery_location', '1号厅', is_checked=False, timestamp=_goods_timestamp)
self.add_param('delivery_appoint_time', delivery_appoint_time, is_checked=False, timestamp=_goods_timestamp)
self.add_param('contact_number', '18688886666', is_checked=False, timestamp=_goods_timestamp)
else:
self.add_param('cash', _ticket_cash, timestamp=_ticket_timestamp)
# 处理券码部分
if self.pay_type == 'yushouquan':
self.add_param('coupons', _quan, timestamp=_ticket_timestamp)
if self.pay_type == 'equan':
self.add_param('card_coupons', _quan, timestamp=_ticket_timestamp)
return _ticket_timestamp
def add_param(self, field, value, is_checked=True, result=True, timestamp=int(time.time() * 1000)):
self.return_data.append(
{'param': field, 'value': value, 'is_checked': is_checked, 'result': result, 'timestamp': timestamp})

@ -21,7 +21,7 @@ QUAN_SQL = sql = """
AND cqi.card_quan_channel = '2'
GROUP BY m2.`cinema_yushouquan_book_order`,m2.cinema_yushouquan_encrypt_barcode
HAVING COUNT(*)<10
ORDER BY m1.cinema_yushouquan_book_order;
ORDER BY m1.cinema_yushouquan_book_order, m1.cinema_yushouquan_encrypt_barcode;
"""
CARD_QUAN_SQL = "SELECT cqo.card_quan_order_id, cqi.cinema_quan_name, cqo.cinema_quan_id, cqo.quan_remain_nums, cqo.cinema_dead_time FROM cine.card_quan_order cqo LEFT JOIN cine.cinema_quan_info cqi ON cqo.cinema_quan_id = cqi.cinema_quan_id WHERE cqi.card_quan_channel = '2' AND cqo.quan_remain_nums > 0 AND cqo.cinema_dead_time >= NOW() AND cqo.cinema_card_num = %s;"

@ -0,0 +1,47 @@
from django_redis import get_redis_connection
import pymysql
from pymysql.cursors import DictCursor
from dingxin_toolbox_drf.settings import CONFIG
from env import ENV
def get_ecard(ip, env, pid, cid):
redis_con = get_redis_connection()
redis_key = f"ecard_{ip}_{env}_{pid}_{cid}"
print('get_ecard-ecard_num', redis_key)
if redis_con.exists(redis_key):
ecard_num = redis_con.get(redis_key)
print('get_ecard-ecard_num', ecard_num)
return str(ecard_num, encoding='utf-8')
return False
def set_ecard(ip, env, pid, cid, ecard):
redis_con = get_redis_connection()
redis_key = f"ecard_{ip}_{env}_{pid}_{cid}"
if redis_con.exists(redis_key):
redis_con.delete(redis_key)
return redis_con.set(redis_key, ecard)
def get_ecard_renew_fee(ecard_number):
return get_ecard_info('renew_fee', ecard_number)
def get_ecard_level(ecard_number):
return get_ecard_info('card_level_no', ecard_number)
def get_ecard_info(filed, ecard_number):
ecard_server = {
'host': CONFIG[ENV]['ECARD_DB']['HOST'],
'user': CONFIG[ENV]['ECARD_DB']['USER'],
'password': CONFIG[ENV]['ECARD_DB']['PASSWORD'],
'port': CONFIG[ENV]['ECARD_DB']['PORT'],
'database': CONFIG[ENV]['ECARD_DB']['NAME'],
}
ecard_conn = pymysql.Connect(**ecard_server)
ecard_cursor = ecard_conn.cursor(DictCursor)
sql = f'SELECT {filed} FROM fws_dgp_card_db.card_level WHERE card_level_no = (SELECT card_level_no FROM fws_dgp_card_db.card WHERE card_num = %s);'
ecard_cursor.execute(sql, (ecard_number,))
result = ecard_cursor.fetchone()[filed]
return result

@ -0,0 +1,4 @@
from decimal import Decimal, ROUND_HALF_UP
def f2(val):
return Decimal(str(val)).quantize(Decimal('0.00'), rounding=ROUND_HALF_UP)

@ -1,3 +1,8 @@
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_float import f2
# 将接口请求的数据中卖品信息整理成列表结构
def format_goods(_data):
goods_list = []
@ -8,7 +13,7 @@ def format_goods(_data):
# 将接口获取的卖品数据转化成请求参数格式
def general_goods_param(_data):
def general_goods_field(_data, ecard_level=None):
params = []
total_cash = 0
for g in _data:
@ -16,11 +21,11 @@ def general_goods_param(_data):
info = {
'id': g['id'],
'type': g['type'],
'price': round(float(g.get('partnerPrice', g['onlinePrice'])) * _num, 2),
'price': str(get_goods_price(g, _num, ecard_level=ecard_level)),
'num': _num
}
if g['type'] == 'package' and g['packageType'] == '2':
add_price = 0
add_price = f2(0)
optional_package = []
for key, val in g['user_select'].items():
member = []
@ -30,31 +35,90 @@ def general_goods_param(_data):
for item in member:
if item['id'] == m['id']:
item['num'] = item['num'] + 1
add_price += round(float(m['addPrice']), 2)
add_price += f2(m['addPrice'])
else:
member.append({'id': m['id'], 'num': 1, 'add_price': m['addPrice']})
member_id.append(m['id'])
add_price += round(float(m['addPrice']), 2)
add_price += f2(m['addPrice'])
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)
info['price'] = str(f2(info['price']) + add_price)
total_cash = f2(total_cash) + f2(info['price'])
params.append(info)
if g.get('discount1', False):
total_discount = 0
total_discount = f2(0)
discount_list = []
if g['discount1'] > 0:
total_discount = round(total_discount + g['discount1'], 2)
total_discount += f2(g['discount1'])
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)
total_discount += f2(g['discount2'])
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_price'] = str(total_discount)
info['discount_detail'] = discount_list
total_cash = round(total_cash - total_discount, 2)
total_cash -= total_discount
print('general_goods_param---------params', params)
return params, total_cash
return params, str(total_cash)
def get_goods_price(goods, num, ecard_level=None):
price = goods.get('partnerPrice', goods['onlinePrice']) if ecard_level is None else get_ecard_price(goods,
ecard_level)
return f2(price)
def get_ecard_price(goods, ecard_level):
if ecard_price_list := goods.get('ecardPrices', False):
for ecard_price_item in ecard_price_list:
if ecard_price_item['ecardLevelNo'] == ecard_level:
return ecard_price_item['ecardLevelPrice']
return False
def general_goods_params(pay_type, data, ticket_cash=f2(0)):
# 券信息
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
if pay_type == 'cash':
goods_field, goods_cash = general_goods_field(goods_data)
goods_cash = f2(goods_cash)
goods_cash += ticket_cash
elif pay_type == 'ecard':
ecard_num = get_ecard(data['ip'], data["env"], data["pid"], data["cid"])
ecard_level = get_ecard_level(ecard_num)
goods_field, goods_cash = general_goods_field(goods_data, ecard_level)
goods_cash = f2(goods_cash)
goods_cash += ticket_cash
elif pay_type in ['yushouquan', 'equan']:
goods_field, goods_cash = general_goods_field(goods_data)
# 获取券价格
request_api_yushouquan = {'name': '3.6.1 添加券', 'path': 'seat/check-coupon'}
redis_key_api_yushouquan = f'{redis_key_prefix}_{request_api_yushouquan["path"]}'
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
# 获取券码
req_params = get_param_from_redis(redis_key_api_yushouquan)
if pay_type == 'yushouquan':
quan = req_params['coupons'] if req_params.get('coupons', False) else '3.6.1添加券接口中选择的券类型为会员卡赠券,与当前设置不符合'
elif pay_type == 'equan':
quan = req_params['card_coupons'] if req_params.get('equan', False) else '3.6.1添加券接口中选择的券类型为扫码券,与当前设置不符合'
else:
quan = '请检查3.6.1添加券接口'
goods_cash = cash_from_yushouquan['balance']
return True, goods_field, goods_cash, quan, _timestamp_yushouquan
else:
pass
return True, goods_field, str(goods_cash), quan, _timestamp

@ -37,3 +37,12 @@ def get_data_from_redis(redis_key):
return False, redis_data['format'], '接口返回数据为空,请手动输入参数:', 0
return True, redis_data['format'], random.choice(resp_data), redis_data['timestamp']
return False, 'json', '请手动输入参数,或先请求接口:', 0
def get_param_from_redis(redis_key):
# 初始话redis
redis_conn = get_redis_connection()
if redis_conn.exists(redis_key):
redis_data = json.loads(redis_conn.get(redis_key))
request_params = redis_data['params']
return request_params
return False

@ -9,11 +9,11 @@
先从seat_lock接口获取座位价格
如果seat_lock没有获取到座位价格就到
返回 结果, seat , ticket_cash, play_id, play_update_time, lock_flag, timestamp
返回 结果, seat , ticket_cash, play_id, play_update_time, lock_flag, quan, timestamp
"""
import random
from decimal import Decimal, ROUND_HALF_UP
from dspt_api.util.general.handle_redis import get_data_from_redis
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
def general_seat_params(pay_type, data):
@ -23,6 +23,8 @@ def general_seat_params(pay_type, data):
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)
if not result_lock:
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']
# partner_price = seat_price_from_lock['partnerPrice'] if seat_price_from_lock['partnerPrice'] is not None else False
@ -31,6 +33,8 @@ def general_seat_params(pay_type, data):
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)
if not result_play:
return False, None, None, None, None, None, None, None
market_price = seat_price_from_play['marketPrice']
play_id = seat_price_from_play['id']
play_update_time = seat_price_from_play['cineUpdateTime']
@ -39,6 +43,8 @@ def general_seat_params(pay_type, data):
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)
if not result_config:
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:合作商补贴
@ -46,7 +52,8 @@ def general_seat_params(pay_type, data):
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)
if not result_seat:
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]
@ -56,7 +63,7 @@ def general_seat_params(pay_type, data):
# 判断获取到了全部接口数据,就继续,否则报错
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
return False, return_str, 0, return_str, return_str, return_str, return_str, last_timestamp
if pay_type == 'cash':
"""
@ -80,6 +87,7 @@ def general_seat_params(pay_type, data):
测试影院3.166 合作商补贴 合作商补贴 是否允许传递优惠金额 影票价格控制 卖品价格控制
"""
quan = ''
seat_list = []
ticket_cash = 0 # 统计cash字段用
for seat_info in seat_id_list:
@ -89,24 +97,24 @@ def general_seat_params(pay_type, data):
if area_info is not False:
# 查找座位对应的区域价格
for area_seat_info in area_info:
if area_seat_info['seatId'] == int(seat_info['seat_id']):
if int(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)
price = f2(area_seat_info["areaPrice"])
seat.append(str(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)
real_pay = f2(area_seat_info["areaPrice"])
real_pay -= f2(area_seat_info["areaServiceFee"])
# 处理影票和服务费折扣
if ticket_discount != 0:
real_pay -= Decimal(ticket_discount)
real_pay -= f2(ticket_discount)
seat.append(str(ticket_discount))
if service_discount != 0:
if partner_type == '2':
real_pay -= Decimal(service_discount)
real_pay -= f2(service_discount)
seat.append(str(service_discount))
else:
seat.append(str(service_discount))
@ -118,24 +126,106 @@ def general_seat_params(pay_type, data):
seat.append(market_price)
seat.append('0')
seat.append('0.00')
real_pay = Decimal(market_price).quantize(Decimal('0.00'), ROUND_HALF_UP)
real_pay = f2(market_price)
if ticket_discount != 0:
real_pay -= Decimal(ticket_discount)
real_pay -= f2(ticket_discount)
seat.append(str(ticket_discount))
if service_discount != 0:
real_pay -= Decimal(service_discount)
real_pay -= f2(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
return True, ','.join(seat_list), ticket_cash, play_id, play_update_time, lock_flag, quan, last_timestamp
elif pay_type == 'ecard':
pass
elif pay_type == 'yushouquan':
pass
quan = ''
# 获取联名卡价格
request_api_ecard = {'name': '3.4.6 获取座位的联名卡价格', 'path': 'ecard/seat-price'}
redis_key_api_ecard = f'{redis_key_prefix}_{request_api_ecard["path"]}'
result_ecard, _format_ecard, seat_price_from_ecard, _timestamp_ecard = get_data_from_redis(
redis_key_api_ecard)
if not result_ecard:
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
# 错误判断
if ecard_info is False:
return_str = '请手动输入参数,检查相关接口返回值:3.4.6 获取座位的联名卡价格'
return False, return_str, 0, return_str, return_str, return_str, last_timestamp
# 处理价格
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"]
for ecard_seat_info in ecard_info:
if int(ecard_seat_info['seatId']) == int(seat_info['seat_id']):
# 获取price字段值
price = f2(ecard_seat_info["price"])
seat.append(str(price))
seat.append('0')
seat.append(ecard_seat_info["serviceFee"])
# if partner_type == '2': # 合作商定价
# price -= Decimal(area_seat_info["areaServiceFee"]).quantize(Decimal('0.00'), ROUND_HALF_UP)
# 计算用户实际支付的值
real_pay = f2(ecard_seat_info["price"])
real_pay -= f2(ecard_seat_info["serviceFee"])
# 处理影票和服务费折扣
if ticket_discount != 0:
real_pay -= f2(ticket_discount)
seat.append(str(ticket_discount))
if service_discount != 0:
if partner_type == '2':
real_pay -= f2(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
return True, ','.join(seat_list), ticket_cash, play_id, play_update_time, lock_flag, quan, last_timestamp
elif pay_type in ['yushouquan', 'equan']:
# 获取券价格
request_api_yushouquan = {'name': '3.6.1 添加券', 'path': 'seat/check-coupon'}
redis_key_api_yushouquan = f'{redis_key_prefix}_{request_api_yushouquan["path"]}'
result_yushouquan, _format_yushouquan, seat_price_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
# 获取券码
req_params = get_param_from_redis(redis_key_api_yushouquan)
if pay_type == 'yushouquan':
quan = req_params['coupons'] if req_params.get('coupons', False) else '3.6.1添加券接口中选择的券类型为会员卡赠券,与当前设置不符合'
elif pay_type == 'equan':
pass
quan = req_params['card_coupons'] if req_params.get('equan', False) else '3.6.1添加券接口中选择的券类型为扫码券,与当前设置不符合'
else:
quan = '请检查3.6.1添加券接口'
# 获取座位参数
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"]
seat.append(market_price)
seat.append('0')
seat.append('0.00')
real_pay = f2(market_price)
if ticket_discount != 0:
real_pay -= f2(ticket_discount)
seat.append(str(ticket_discount))
if service_discount != 0:
real_pay -= f2(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
ticket_cash = seat_price_from_yushouquan['balance']
return True, ','.join(seat_list), ticket_cash, play_id, play_update_time, lock_flag, quan, last_timestamp
else:
pass

@ -1,5 +1,7 @@
def get_ticket_price(data, seat=None, ecard=None):
def get_ticket_price(data, seat=None, ecard=None, quan=False):
print('get_ticket_price-data', data)
if quan is True:
return data.get('marketPrice'), None
if data.get('areaInfo') is None:
if data.get('partnerPrice') is None:
return data.get('marketPrice'), None

@ -49,6 +49,8 @@ def suggest_params(member_type, api, env, cid, pid, ip, **kwargs):
params = ApiSeatLock(**data).get_suggestion()
if api == 'order/buy-goods' and member_type == 'nonmember':
print('order/buy-goods')
data['sale_type'] = kwargs['sale_type']
data['pay_type'] = kwargs['pay_type']
params = ApiOrderBuyGoods(**data).get_suggestion()
if api == 'ecard/regist' and member_type == 'nonmember':
print('ecard/regist')

@ -28,6 +28,7 @@ from dspt_api.util.general.suggest_params import suggest_params, suggest_params_
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
# Create your views here.
@ -223,6 +224,10 @@ def send_request(request):
api = web_req.get('api')
redis_key_api = f'dspt_api_{user_ip}_{env}_{member_type}_{pid}_{cid}_{api}'
# 存储ecard
if ecard_num := params.get('ecard_number', False):
set_ecard(user_ip, env, pid, cid, ecard_num)
# 发送请求
req, sig = handle_request(request)
failed_resp_data = {'url': '请检查foramt、pid参数', 'sig': ''}
@ -371,6 +376,7 @@ def get_quan(request):
'port': 3306,
'database': 'cine'
}
print('get_quan', card_num)
quan = GetQuan(cinema_db)
quan_data = {
'quan': quan.get_quan(),

File diff suppressed because it is too large Load Diff

@ -114,6 +114,9 @@ class ClientUtil:
def get_client_version(self, cinema_ip, short_version):
client_version = self.get_client_info_from_deploy_db(short_version)
# 新版本还没有对应的包
if client_version is None:
client_version = self.get_client_version_from_cine(cinema_ip)
test_client_list = self.get_all_smb_file_list()
# 客户端打包服务器上有,smb上没有
is_exist = False
@ -123,9 +126,6 @@ class ClientUtil:
if is_exist is False:
client = ClientRelease.objects.filter(ver_id=int(short_version[7:])).order_by('-sub_ver').first()
client_version = client.client_ver
# 新版本还没有对应的包
if client_version is None:
client_version = self.get_client_version_from_cine(cinema_ip)
return client_version
def get_client(self, cinema_ip, short_version):

Loading…
Cancel
Save