def task_chain_in_confirm(): """链内转账504,或timeout错误确认""" with db.app.app_context(): orders = Order.chain_in_unconfirm(COIN_NAME, 100) for order in orders: # 定时任务开关 if not consul_clinet.get_task_switch(): logging.warning('链外充值定时任务被手动关闭!') return # 查询链内哈希 stellar_hash = order.order_hash stellar_node = stellar_service.stellar_node(is_full=True) ret = stellar_service.query_hash(stellar_hash, stellar_node=stellar_node) # 请求失败 if not ret: continue relate_order = None if ret.get('hash') is None: order.status = 0 # hash 不存在,链内转账失败 # 当前订单为充值订单 if order.order_type == 1: relate_order = Order.query.filter_by(id=order.relate_id).first() relate_order.relate_order_status = 0 # 待重新生成链内转账订单 else: order.status = 1 # hash 存在,链内转账成功 # 当前订单为提现订单 if order.order_type == 2: relate_order = Order.query.filter_by(id=order.relate_id).first() relate_order.status = -1 # 更新链外提现订单状态为-1(待转账) elif order.order_type == 1: order.done_time = datetime.now() # 链内充值订单完成时间 # 无需更改关联订单状态 if relate_order is None: try: db.session.add(order) db.session.commit() except Exception as e: logging.error('task_chain_in_confirm update db error:{}'.format(str(e))) db.session.rollback() return # 更改关联订单状态 else: try: db.session.add_all([order, relate_order]) db.session.commit() except Exception as e: logging.error('task_chain_in_confirm update db error:{}'.format(str(e))) db.session.rollback() return is_relate = '否' if not relate_order else '是,关联订单id:{}'.format(relate_order.id) print('确认hash订单id:{},是否更改关联订单:{}'.format(order.id,is_relate)) logging.info('确认hash订单id:{},是否更改关联订单:{}'.format(order.id,is_relate))
def task_chain_in_confirm(): """链内转帐确认""" with db.app.app_context(): orders = Order.chain_in_unconfirm(COIN_NAME, 100) for order in orders: # 定时任务开关 if not consul_clinet.get_task_switch(): logging.warning('{}链内转帐确认定时任务被手动关闭!'.format(COIN_NAME)) return order_hash = order.order_hash stellar_node = stellar_service.stellar_node(is_full=True) ret = stellar_service.query_hash(order_hash, stellar_node=stellar_node) if ret is None: return relate_order = None if ret.get("hash") is None: order.status = 3 # 如果为充值订单 if order.order_type == 1: relate_order = Order.query.filter_by( id=order.relate_id).first() relate_order.relate_order_status = 0 # 进入task_chain_in_recharge 重新生成订单 else: order.status = 3 if order.order_type == 1: order.done_time = datetime.now() else: relate_order = Order.query.filter_by( id=order.relate_id).first() # relate_order.status = -1 # 链外待转帐,relate_order进入task_chain_out_withdraw if relate_order is None: try: db.session.add(order) db.session.commit() except Exception as e: logging.error( 'task_chain_in_confirm update db error:{}'.format( str(e))) db.session.rollback() return else: try: db.session.add_all([order, relate_order]) db.session.commit() except Exception as e: logging.error( 'task_chain_in_confirm update db error:{}'.format( str(e))) db.session.rollback() return