# # coding=utf-8
# from django.core.management.base import NoArgsCommand
# from django.conf import settings
# from django.db.models import Q
# from api.models import REFUND_STATUS
# from pay.models import WechatOrder
# from api.models import RefundOrder
# from api.models import ORDER_SOURCE
# from pay.models import Wechat
#
#
#
# class Command(NoArgsCommand):
#     def handle(self, *args, **options):
#         # suspicious_refund_orders = RefundOrder.objects.filter(Q(status=REFUND_STATUS.ARBIT_APPROVE) | Q(status=REFUND_STATUS.DOCTOR_APPROVE))
#         suspicious_refund_orders = RefundOrder.objects.all()
#         for s_refund_order in suspicious_refund_orders:
#
#             if s_refund_order.order.source not in [ORDER_SOURCE.IOS, ORDER_SOURCE.ANDROID]:
#                 wechat = Wechat(settings.M_WECHAT_APP_ID, settings.M_WECHAT_PARTNER_ID, settings.M_WECHAT_SECRET)
#                 wechat.set_cert(settings.M_WECHAT_PEM_KEY, settings.M_WECHAT_PEM_CERT)
#
#             else:
#                 wechat = Wechat(settings.CLIENT_WECHAT_APP_ID, settings.CLIENT_WECHAT_PARTNER_ID,
#                                 settings.CLIENT_WECHAT_SECRET)
#                 wechat.set_cert(settings.CLIENT_WECHAT_PEM_KEY, settings.CLIENT_WECHAT_PEM_CERT)
#
#                 # s_order.order
#                 try:
#                     wechat_order = WechatOrder.objects.get(order_no=s_refund_order.order_id)
#                     order_state = wechat.order_query(transaction_id=wechat_order.transaction_id)
#                     trade_status = order_state.get('trade_state')
#                     if  trade_status!= 'SUCCESS':
#                         print s_refund_order.id, trade_status
#                 except WechatOrder.DoesNotExist:
#                     pass
#
