You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
4.4 KiB
90 lines
4.4 KiB
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 |
|
|
|
|
|
class ApiEcardRenew: |
|
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') |
|
|
|
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.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'], |
|
'is_checked': True, 'result': True, |
|
'timestamp': _timestamp_ec_2} |
|
ecard_number = ecard_number_ec_2 |
|
ecard_number_result = True |
|
if result_ec_1: |
|
ecard_number_ec_1 = {'param': 'ecard_number', 'value': redis_data_ec_1['ecardNumber'], |
|
'is_checked': True, 'result': True, |
|
'timestamp': _timestamp_ec_1} |
|
ecard_number = ecard_number_ec_1 |
|
ecard_number_result = True |
|
if result_ec_1 and result_ec_2: |
|
ecard_number = ecard_number_ec_1 if _timestamp_ec_1 >= _timestamp_ec_2 else ecard_number_ec_2 |
|
|
|
# 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'] |
|
if fee is not None: |
|
renew_fee = {'param': 'renew_fee', 'value': fee, |
|
'is_checked': True, 'result': True, |
|
'timestamp': _now} |
|
result_renew_fee = True |
|
else: |
|
renew_fee = {'param': 'renew_fee', 'value': '此卡级别不能续卡', |
|
'is_checked': True, 'result': True, |
|
'timestamp': _now} |
|
result_renew_fee = True |
|
|
|
# partner_order_no |
|
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} |
|
|
|
if ecard_number_result and result_renew_fee: |
|
return [ecard_number, renew_fee, partner_order_no] |
|
else: |
|
return [{'param': 'ecard_number', 'value': redis_data_ec_1 + request_api_ec_1["name"], 'is_checked': True, |
|
'result': True, |
|
'timestamp': _now}, |
|
{'param': 'renew_fee', 'value': '请手动输入参数!', 'is_checked': True, 'result': True, |
|
'timestamp': _now}, |
|
partner_order_no |
|
] |
|
|
|
def get_timestamp(self): |
|
return int(time.time() * 1000)
|
|
|