parent
1e8bc8a713
commit
1364601791
8 changed files with 175 additions and 55 deletions
@ -0,0 +1,26 @@ |
||||
from dspt_api.util.general.handle_redis import get_data_from_redis |
||||
from dspt_api.util.api.seat_lock import ApiSeatLock |
||||
from dspt_api.util.api.ecard_detail import ApiEcardDetail |
||||
import random |
||||
|
||||
|
||||
class ApiEcardSeatPrice: |
||||
def __init__(self, **kwargs): |
||||
self.member_type = kwargs.get('member_type') |
||||
self.api = kwargs.get('api') |
||||
self.ip = kwargs.get('ip') |
||||
self.kwargs = kwargs |
||||
|
||||
def get_suggestion(self): |
||||
# 获取 play_id seat_idplay_update_time |
||||
params = ApiSeatLock(**self.kwargs).get_suggestion() |
||||
# 获取 ecard_number |
||||
ecard_number = ApiEcardDetail(**self.kwargs).get_suggestion() |
||||
return params + ecard_number |
||||
|
||||
def get_timestamp(self): |
||||
# 获取 play_id seat_idplay_update_time |
||||
params_ts = ApiSeatLock(**self.kwargs).get_timestamp() |
||||
# 获取 ecard_number |
||||
ecard_number_ts = ApiEcardDetail(**self.kwargs).get_timestamp() |
||||
return params_ts if params_ts > ecard_number_ts else ecard_number_ts |
@ -0,0 +1,61 @@ |
||||
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.handle_goods import general_goods_param |
||||
import time |
||||
import random |
||||
import json |
||||
|
||||
|
||||
class ApiOrderBuyGoods: |
||||
def __init__(self, **kwargs): |
||||
self.member_type = kwargs.get('member_type') |
||||
self.api = kwargs.get('api') |
||||
self.ip = kwargs.get('ip') |
||||
|
||||
def get_suggestion(self): |
||||
request_api = {'name': '3.2.1 获取卖品列表', 'path': 'cinema/goods'} |
||||
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}' |
||||
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api) |
||||
if result: |
||||
goods_data = random.choice(redis_data) |
||||
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) |
||||
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': redis_data + request_api["name"], 'is_checked': True, |
||||
'result': True, |
||||
'timestamp': _timestamp}, |
||||
{'param': 'goods', 'value': redis_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): |
||||
return int(time.time()*1000) |
@ -1,6 +1,50 @@ |
||||
import json |
||||
import random |
||||
|
||||
from dspt_api.util.random_params import random_params |
||||
|
||||
|
||||
# 将接口请求的数据中卖品信息整理成列表结构 |
||||
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) |
||||
print('general_goods_param---------params', params) |
||||
return params, total_cash |
||||
|
Loading…
Reference in new issue