完善redis缓存逻辑,区分不同环境

main
RogerWork 1 month ago
parent b2b7b5f65c
commit c1cfc46a8b
  1. 7
      dspt_api/util/api/cinema_goods_pic.py
  2. 7
      dspt_api/util/api/cinema_hall_seats.py
  3. 7
      dspt_api/util/api/cinema_plays_increment.py
  4. 7
      dspt_api/util/api/ecard_detail.py
  5. 11
      dspt_api/util/api/ecard_order_detail.py
  6. 5
      dspt_api/util/api/ecard_refund.py
  7. 7
      dspt_api/util/api/ecard_regist.py
  8. 9
      dspt_api/util/api/ecard_renew.py
  9. 3
      dspt_api/util/api/ecard_seat_price.py
  10. 7
      dspt_api/util/api/order_buy_goods.py
  11. 7
      dspt_api/util/api/play_info.py
  12. 7
      dspt_api/util/api/play_period_changed_seats.py
  13. 7
      dspt_api/util/api/play_seat_overview.py
  14. 7
      dspt_api/util/api/play_seat_status.py
  15. 7
      dspt_api/util/api/seat_check_coupon.py
  16. 11
      dspt_api/util/api/seat_lock.py
  17. 4
      dspt_api/util/general/get_order_num.py
  18. 2
      dspt_api/util/general/random_params.py
  19. 8
      dspt_api/util/general/suggest_params.py
  20. 26
      dspt_api/views.py
  21. 51535
      logs/dingxin.log

@ -8,11 +8,14 @@ class ApiCinemaGoodsPic(object):
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')
def get_suggestion(self):
# play_id play_update_time
request_api = {'name': '3.2.1 获取卖品列表', 'path': 'cinema/goods'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
if result:
goods_list = get_goods_list(redis_data, _format)
@ -33,6 +36,6 @@ class ApiCinemaGoodsPic(object):
def get_timestamp(self):
# play_id play_update_time
request_api = {'name': '3.2.1 获取卖品列表', 'path': 'cinema/goods'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
return _timestamp if result else 0

@ -7,11 +7,14 @@ class ApiCinemaHallSeats:
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')
def get_suggestion(self):
# hall_id
request_api = {'name': '3.1.3 获取影厅列表', 'path': 'cinema/halls'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
if result:
hall_data = random.choice(redis_data)
@ -26,6 +29,6 @@ class ApiCinemaHallSeats:
def get_timestamp(self):
# hall_id
request_api = {'name': '3.1.3 获取影厅列表', 'path': 'cinema/halls'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
return _timestamp if result else 0

@ -7,11 +7,14 @@ class ApiCinemaPlaysIncrement:
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')
def get_suggestion(self):
# start
request_api = {'name': '3.1.6 获取放映计划列表(增量)', 'path': 'cinema/plays-increment'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
# 生成默认值
start = redis_data['nextSyncStartTime'] if result else datetime.datetime.strftime(datetime.datetime.now(),
@ -21,6 +24,6 @@ class ApiCinemaPlaysIncrement:
def get_timestamp(self):
# start
request_api = {'name': '3.1.6 获取放映计划列表(增量)', 'path': 'cinema/plays-increment'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
return _timestamp if result else 0

@ -7,14 +7,17 @@ class ApiEcardDetail:
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')
def get_suggestion(self):
_now = int(time.time() * 1000)
# ecard_number
request_api_ec_1 = {'name': '3.4.4 获取联名卡详情', 'path': 'ecard/detail'}
redis_key_api_ec_1 = f'dspt_api_{self.ip}_{self.member_type}_{request_api_ec_1["path"]}'
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.member_type}_{request_api_ec_2["path"]}'
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

@ -8,17 +8,20 @@ class ApiEcardOrderDetail:
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')
def get_suggestion(self):
_now = int(time.time() * 1000)
# partner_order_no
request_renew = {'name': '3.4.3 联名卡续卡', 'path': 'ecard/renew'}
redis_key_renew_order_num = f'dspt_api_{self.ip}_{self.member_type}_{request_renew["path"]}_order_num'
redis_key_renew = f'dspt_api_{self.ip}_{self.member_type}_{request_renew["path"]}'
redis_key_renew_order_num = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_renew["path"]}_order_num'
redis_key_renew = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_renew["path"]}'
request_regist = {'name': '3.4.2 联名卡开卡', 'path': 'ecard/regist'}
redis_key_regist_order_num = f'dspt_api_{self.ip}_{self.member_type}_{request_regist["path"]}_order_num'
redis_key_regist = f'dspt_api_{self.ip}_{self.member_type}_{request_regist["path"]}'
redis_key_regist_order_num = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_regist["path"]}_order_num'
redis_key_regist = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_regist["path"]}'
result_renew, _format__renew, redis_data_renew, _timestamp_renew = get_data_from_redis(redis_key_renew)
result_regist, _format_regist, redis_data_regist, _timestamp_regist = get_data_from_redis(redis_key_regist)

@ -10,13 +10,16 @@ class ApiEcardRefund:
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.kwargs = kwargs
def get_suggestion(self):
# source_order_no
source_order_no = ApiEcardOrderDetail(**self.kwargs).get_suggestion()[0]
# partner_order_no
order_num = general_order_num('REF', self.api, self.member_type, self.ip)
order_num = general_order_num('REF', self.api, self.member_type, self.ip, self.env, self.pid, self.cid)
return [{'param': 'source_order_no', 'value': source_order_no['value'], 'is_checked': True, 'result': True,
'timestamp': int(time.time() * 1000)},
{'param': 'partner_order_no', 'value': order_num, 'is_checked': True, 'result': True,

@ -9,16 +9,19 @@ class ApiEcardRegist:
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')
def get_suggestion(self):
request_api = {'name': '3.4.1 获取联名卡等级', 'path': 'ecard/ecard-levels'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
if result:
level_data = random.choice(redis_data)
level_no = level_data['ecardLevelNo']
fee = level_data['registerFee']
order_num = general_order_num('REG', self.api, self.member_type, self.ip)
order_num = general_order_num('REG', self.api, self.member_type, self.ip, self.env, self.pid, self.cid)
return [
{'param': 'mobile', 'value': 18688886666, 'is_checked': True, 'result': True, 'timestamp': _timestamp},
{'param': 'register_fee', 'value': fee, 'is_checked': True, 'result': True, 'timestamp': _timestamp},

@ -13,14 +13,17 @@ class ApiEcardRenew:
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')
def get_suggestion(self):
_now = int(time.time() * 1000)
# ecard_number
request_api_ec_1 = {'name': '3.4.4 获取联名卡详情', 'path': 'ecard/detail'}
redis_key_api_ec_1 = f'dspt_api_{self.ip}_{self.member_type}_{request_api_ec_1["path"]}'
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.member_type}_{request_api_ec_2["path"]}'
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
@ -68,7 +71,7 @@ class ApiEcardRenew:
result_renew_fee = True
# partner_order_no
order_num = general_order_num('REN', self.api, self.member_type, self.ip)
order_num = general_order_num('REN', self.api, self.member_type, self.ip, self.env, self.pid, self.cid)
partner_order_no = {'param': 'partner_order_no', 'value': order_num, 'is_checked': True, 'result': True,
'timestamp': _now}

@ -9,6 +9,9 @@ class ApiEcardSeatPrice:
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.kwargs = kwargs
def get_suggestion(self):

@ -11,16 +11,19 @@ class ApiOrderBuyGoods:
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')
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"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{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)
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,

@ -8,11 +8,14 @@ class ApiPlayInfo:
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')
def get_suggestion(self):
# play_id
request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
if result:
play_data = random.choice(redis_data)
@ -27,6 +30,6 @@ class ApiPlayInfo:
def get_timestamp(self):
# play_id
request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
return _timestamp if result else 0

@ -8,11 +8,14 @@ class ApiPlayPeriodChangedSeats:
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')
def get_suggestion(self):
# play_id play_update_time
request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
if result:
play_data = random.choice(redis_data)
@ -31,6 +34,6 @@ class ApiPlayPeriodChangedSeats:
def get_timestamp(self):
# play_id play_update_time
request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
return _timestamp if result else 0

@ -7,11 +7,14 @@ class ApiPlaySeatOverview:
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')
def get_suggestion(self):
# play_id play_update_time
request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
if result:
play_data = random.choice(redis_data)
@ -26,6 +29,6 @@ class ApiPlaySeatOverview:
def get_timestamp(self):
# play_id play_update_time
request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
return _timestamp if result else 0

@ -7,11 +7,14 @@ class ApiPlaySeatStatus:
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')
def get_suggestion(self):
# play_id play_update_time
request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
if result:
play_data = random.choice(redis_data)
@ -31,6 +34,6 @@ class ApiPlaySeatStatus:
def get_timestamp(self):
# play_id play_update_time
request_api = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
return _timestamp if result else 0

@ -12,6 +12,9 @@ class ApiSeatCheckCoupon:
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')
def get_suggestion(self):
@ -27,7 +30,7 @@ class ApiSeatCheckCoupon:
# 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.member_type}_{request_api_play["path"]}'
redis_key_api_play = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{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)
if result_play:
@ -44,7 +47,7 @@ class ApiSeatCheckCoupon:
def get_goods(self):
request_api = {'name': '3.2.1 获取卖品列表', 'path': 'cinema/goods'}
redis_key_api = f'dspt_api_{self.ip}_{self.member_type}_{request_api["path"]}'
redis_key_api = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api["path"]}'
result, _format, redis_data, _timestamp = get_data_from_redis(redis_key_api)
if result:
goods_data = random.choice(redis_data)

@ -7,15 +7,18 @@ class ApiSeatLock:
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')
def get_suggestion(self):
# play_id
request_api_play = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'}
redis_key_api_play = f'dspt_api_{self.ip}_{self.member_type}_{request_api_play["path"]}'
redis_key_api_play = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api_play["path"]}'
result_play, _format_play, redis_data_play, _timestamp_play = get_data_from_redis(redis_key_api_play)
# seat_id
request_api_seat = {'name': '3.1.8 获取某场次座位状态', 'path': 'play/seat-status'}
redis_key_api_seat = f'dspt_api_{self.ip}_{self.member_type}_{request_api_seat["path"]}'
redis_key_api_seat = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api_seat["path"]}'
result_seat, _format_seat, redis_data_seat, _timestamp_seat = get_data_from_redis(redis_key_api_seat)
if result_play and result_seat:
play_data = random.choice(redis_data_play)
@ -39,11 +42,11 @@ class ApiSeatLock:
def get_timestamp(self):
# play_id
request_api_play = {'name': '3.1.5 获取放映计划列表', 'path': 'cinema/plays'}
redis_key_api_play = f'dspt_api_{self.ip}_{self.member_type}_{request_api_play["path"]}'
redis_key_api_play = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api_play["path"]}'
result_play, _format_play, redis_data_play, _timestamp_play = get_data_from_redis(redis_key_api_play)
# seat_id
request_api_seat = {'name': '3.1.8 获取某场次座位状态', 'path': 'play/seat-status'}
redis_key_api_seat = f'dspt_api_{self.ip}_{self.member_type}_{request_api_seat["path"]}'
redis_key_api_seat = f'dspt_api_{self.ip}_{self.env}_{self.member_type}_{self.pid}_{self.cid}_{request_api_seat["path"]}'
result_seat, _format_seat, redis_data_seat, _timestamp_seat = get_data_from_redis(redis_key_api_seat)
# 处理混合结果
if result_play and result_seat:

@ -3,14 +3,14 @@ import random
from django_redis import get_redis_connection
def general_order_num(prefix, api, api_type, ip):
def general_order_num(prefix, api, api_type, ip, env, pid, cid):
# 生成新的order_num
_now = str(int(time.time() * 1000))
_rand = str(random.randint(100, 999))
order_num = prefix + _now + _rand
# 注册redis写入order_num
redis_conn = get_redis_connection()
redis_key = f'dspt_api_{ip}_{api_type}_{api}_order_num'
redis_key = f'dspt_api_{ip}_{env}_{api_type}_{pid}_{cid}_{api}_order_num'
if redis_conn.get(redis_key):
redis_conn.delete(redis_key)
redis_conn.set(redis_key, order_num, 10 * 60 * 60)

@ -10,7 +10,7 @@ def random_params(_user_info, _handle_data):
if _user_info["api"] in RANDOM_DATA_API_LIST:
if str(_handle_data['res']['status']) == '0':
return False
redis_key_api = f'dspt_api_{_user_info["user_ip"]}_{_user_info["member_type"]}_{_user_info["api"]}_random'
redis_key_api = f'dspt_api_{_user_info["user_ip"]}_{_user_info["env"]}_{_user_info["member_type"]}_{_user_info["pid"]}_{_user_info["cid"]}_{_user_info["api"]}_random'
redis_conn = get_redis_connection()
if redis_conn.get(redis_key_api):
redis_conn.delete(redis_key_api)

@ -18,8 +18,8 @@ from dspt_api.util.api.seat_check_coupon import ApiSeatCheckCoupon
# 通过api来匹配不同的接口文件获取推荐
# 返回推荐参数应该包含参数名,参数值,和是否勾选的状态
def suggest_params(member_type, api, ip, **kwargs):
data = {'member_type': member_type, 'api': api, 'ip': ip}
def suggest_params(member_type, api, env, cid, pid, ip, **kwargs):
data = {'member_type': member_type, 'api': api, 'env': env, 'cid': cid, 'pid':pid, 'ip': ip}
params = []
# 非会员
if api == 'cinema/hall-seats' and member_type == 'nonmember':
@ -74,8 +74,8 @@ def suggest_params(member_type, api, ip, **kwargs):
params = ApiSeatCheckCoupon(**data).get_suggestion()
return params
def suggest_params_timestamp(member_type, api, ip):
data = {'member_type': member_type, 'api': api, 'ip': ip}
def suggest_params_timestamp(member_type, api, env, cid, pid, ip, **kwargs):
data = {'member_type': member_type, 'api': api, 'env': env, 'cid': cid, 'pid':pid, 'ip': ip}
_timestamps = 0
# 非会员
if api == 'cinema/hall-seats' and member_type == 'nonmember':

@ -144,14 +144,16 @@ def get_suggest_params_by_api(request):
# 获取基础数据
member_type = request.GET.get('member_type')
api = request.GET.get('api')
env = request.GET.get('env')
cid = request.GET.get('cid')
pid = request.GET.get('pid')
user_ip = request.META.get('REMOTE_ADDR')
sale_type = request.GET.get('options[sale_type]', None)
print()
print('sale_type', sale_type)
if sale_type is None:
params = suggest_params(member_type, api, user_ip)
params = suggest_params(member_type, api, env, cid, pid, user_ip)
else:
params = suggest_params(member_type, api, user_ip, **{'sale_type': sale_type})
params = suggest_params(member_type, api, env, cid, pid, user_ip, **{'sale_type': sale_type})
return JsonResponse(params, safe=False)
@ -160,8 +162,11 @@ def get_suggest_params_timestamp_by_api(request):
# 获取基础数据
member_type = request.GET.get('member_type')
api = request.GET.get('api')
env = request.GET.get('env')
cid = request.GET.get('cid')
pid = request.GET.get('pid')
user_ip = request.META.get('REMOTE_ADDR')
_ts = suggest_params_timestamp(member_type, api, user_ip)
_ts = suggest_params_timestamp(member_type, api, env, cid, pid, user_ip)
print('timestamp', _ts)
return JsonResponse({'timestamp': _ts})
@ -204,12 +209,15 @@ def send_request(request):
print('request_params', params)
resp_format = params['format']
member_type = req.get('member_type')
env = req.get('env')
pid = req.get('pid')
cid = req.get('cid')
# 初始化redis
redis_conn = get_redis_connection()
user_ip = request.META.get('REMOTE_ADDR')
web_req = json.loads(request.body)
api = web_req.get('api')
redis_key_api = f'dspt_api_{user_ip}_{member_type}_{api}'
redis_key_api = f'dspt_api_{user_ip}_{env}_{member_type}_{pid}_{cid}_{api}'
# 发送请求
req, sig = handle_request(request)
@ -266,6 +274,9 @@ def send_request(request):
'member_type': member_type,
'api': api,
'format': resp_format,
'env': env,
'cid': cid,
'pid': pid,
}
random_params(user_data, handled_data)
@ -289,9 +300,12 @@ def set_user_select_data(request):
resp_format = 'xml' if req.get('format') == 'html' else req.get('format')
user_data = req.get('user_data')
user_ip = request.META.get('REMOTE_ADDR')
env = req.get('env')
pid = req.get('pid')
cid = req.get('cid')
# 初始化redis
redis_conn = get_redis_connection()
redis_key_user_data = f'dspt_api_{user_ip}_{member_type}_{api}_user_data'
redis_key_user_data = f'dspt_api_{user_ip}_{env}_{member_type}_{pid}_{cid}_{api}_user_data'
print('user_data', user_data)
# 记录用户选择
data = {

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save