# Path: openunipay/models.py
# class OrderItem(models.Model):
#     orderno = models.CharField(verbose_name=u'订单号', max_length=50, primary_key=True, editable=False)
#     user = models.CharField(verbose_name=u'用户标识', max_length=50, null=True, blank=True)
#     product_desc = models.CharField(verbose_name=u'商品描述', max_length=128, null=False, blank=False)
#     product_detail = models.TextField(verbose_name=u'商品详情', max_length=1000, null=False, blank=False)
#     fee = models.DecimalField(verbose_name=u'金额(单位:分)', max_digits=6, decimal_places=0, null=False, blank=False)
#     attach = models.CharField(verbose_name=u'附加数据', max_length=127, null=True, blank=True)
#     dt_start = models.DateTimeField(verbose_name=u'交易开始时间', null=False, blank=False, editable=False)
#     dt_end = models.DateTimeField(verbose_name=u'交易失效时间', null=False, blank=False, editable=False)
#     dt_pay = models.DateTimeField(verbose_name=u'付款时间', null=True, blank=True, editable=False)
#     paied = models.BooleanField(verbose_name=u'已收款', null=False, blank=False, default=False, editable=False)
#     lapsed = models.BooleanField(verbose_name=u'已失效', null=False, blank=False, default=False, editable=False)
#     payway = models.CharField(verbose_name=u'支付方式', max_length=10, null=False, blank=False, choices=PAY_WAY, default=PAY_WAY[0][0])
#     date_create = models.DateTimeField(verbose_name=u'创建时间', auto_now_add=True)
#     date_update = models.DateTimeField(verbose_name=u'修改时间', auto_now=True)
# 
#     class Meta:
#         verbose_name = '付款单'
#         verbose_name_plural = '付款单'
# 
#     def __str__(self):
#         return self.orderno
# 
#     def _set_expire_time(self, expire):
#         self.dt_start = datetime.local_now()
#         self.dt_end = self.dt_start + timedelta(minutes=expire)
# 
#     def initial_orlder(self, expire):
#         self._set_expire_time(expire)
# 
# class Product(models.Model):
#     productid = models.CharField(verbose_name=u'商品ID', max_length=50, primary_key=True)
#     product_desc = models.CharField(verbose_name=u'商品描述', max_length=128, null=False, blank=False)
#     product_detail = models.TextField(verbose_name=u'商品详情', max_length=1000, null=False, blank=False)
#     fee = models.DecimalField(verbose_name=u'金额(单位:分)', max_digits=6, decimal_places=0, null=False, blank=False)
#     weinxin_qrurl = models.CharField(verbose_name=u'微信扫码支付URL', max_length=500, null=True, blank=True)
#     date_create = models.DateTimeField(verbose_name=u'创建时间', auto_now_add=True)
#     date_update = models.DateTimeField(verbose_name=u'修改时间', auto_now=True)
# 
#     class Meta:
#         verbose_name = '商品'
#         verbose_name_plural = '商品'
# 
# PAY_WAY_WEIXIN = 'WEIXIN'
# 
# Path: openunipay/paygateway/unipay.py
# _PAY_GATEWAY = {PAY_WAY_WEIXIN: weixin.WeiXinPayGateway(),
#                 PAY_WAY_ALI: alipay.AliPayGateway(), }
# def create_order(orderno, payway, clientIp, product_desc, product_detail, fee, user=None, attach=None, expire=1440, **kwargs):
# def query_order(orderno):
# def process_notify(payway, requestContent):
# def is_supportted_payway(payway):
# def _update_order_pay_result(payResult):
# def generate_qr_pay_url(payway, productid):
# def process_qr_pay_notify(payway, requestContent):


from django.contrib import admin
from .ali_pay.admin import *
from .weixin_pay.admin import *
from .models import OrderItem, Product, PAY_WAY_WEIXIN
from openunipay.paygateway import unipay

# -*- coding: utf-8 -*-



class OrderItemResource(resources.ModelResource):
    class Meta:
        model = OrderItem
        import_id_fields = ('orderno', )


class OrderItemAdmin(ImportExportModelAdmin):
    resource_class = OrderItemResource
    # list page
    list_display = ('orderno', 'user', 'product_desc', 'payway', 'fee', 'dt_start', 'dt_end', 'dt_pay', 'paied')
    ordering = ('-dt_start', )
    search_fields = ['=orderno',
                     '=user', ]
    list_filter = ('payway',
                   'paied',
                   'product_desc', )

    def save_model(self, request, obj, form, change):
        if not obj.orderno:
            obj.initial_orlder()
        admin.ModelAdmin.save_model(self, request, obj, form, change)


########################### product #########################
class ProductResource(resources.ModelResource):
    class Meta:

# Path: openunipay/models.py
# class OrderItem(models.Model):
#     orderno = models.CharField(verbose_name=u'订单号', max_length=50, primary_key=True, editable=False)
#     user = models.CharField(verbose_name=u'用户标识', max_length=50, null=True, blank=True)
#     product_desc = models.CharField(verbose_name=u'商品描述', max_length=128, null=False, blank=False)
#     product_detail = models.TextField(verbose_name=u'商品详情', max_length=1000, null=False, blank=False)
#     fee = models.DecimalField(verbose_name=u'金额(单位:分)', max_digits=6, decimal_places=0, null=False, blank=False)
#     attach = models.CharField(verbose_name=u'附加数据', max_length=127, null=True, blank=True)
#     dt_start = models.DateTimeField(verbose_name=u'交易开始时间', null=False, blank=False, editable=False)
#     dt_end = models.DateTimeField(verbose_name=u'交易失效时间', null=False, blank=False, editable=False)
#     dt_pay = models.DateTimeField(verbose_name=u'付款时间', null=True, blank=True, editable=False)
#     paied = models.BooleanField(verbose_name=u'已收款', null=False, blank=False, default=False, editable=False)
#     lapsed = models.BooleanField(verbose_name=u'已失效', null=False, blank=False, default=False, editable=False)
#     payway = models.CharField(verbose_name=u'支付方式', max_length=10, null=False, blank=False, choices=PAY_WAY, default=PAY_WAY[0][0])
#     date_create = models.DateTimeField(verbose_name=u'创建时间', auto_now_add=True)
#     date_update = models.DateTimeField(verbose_name=u'修改时间', auto_now=True)
# 
#     class Meta:
#         verbose_name = '付款单'
#         verbose_name_plural = '付款单'
# 
#     def __str__(self):
#         return self.orderno
# 
#     def _set_expire_time(self, expire):
#         self.dt_start = datetime.local_now()
#         self.dt_end = self.dt_start + timedelta(minutes=expire)
# 
#     def initial_orlder(self, expire):
#         self._set_expire_time(expire)
# 
# class Product(models.Model):
#     productid = models.CharField(verbose_name=u'商品ID', max_length=50, primary_key=True)
#     product_desc = models.CharField(verbose_name=u'商品描述', max_length=128, null=False, blank=False)
#     product_detail = models.TextField(verbose_name=u'商品详情', max_length=1000, null=False, blank=False)
#     fee = models.DecimalField(verbose_name=u'金额(单位:分)', max_digits=6, decimal_places=0, null=False, blank=False)
#     weinxin_qrurl = models.CharField(verbose_name=u'微信扫码支付URL', max_length=500, null=True, blank=True)
#     date_create = models.DateTimeField(verbose_name=u'创建时间', auto_now_add=True)
#     date_update = models.DateTimeField(verbose_name=u'修改时间', auto_now=True)
# 
#     class Meta:
#         verbose_name = '商品'
#         verbose_name_plural = '商品'
# 
# PAY_WAY_WEIXIN = 'WEIXIN'
# 
# Path: openunipay/paygateway/unipay.py
# _PAY_GATEWAY = {PAY_WAY_WEIXIN: weixin.WeiXinPayGateway(),
#                 PAY_WAY_ALI: alipay.AliPayGateway(), }
# def create_order(orderno, payway, clientIp, product_desc, product_detail, fee, user=None, attach=None, expire=1440, **kwargs):
# def query_order(orderno):
# def process_notify(payway, requestContent):
# def is_supportted_payway(payway):
# def _update_order_pay_result(payResult):
# def generate_qr_pay_url(payway, productid):
# def process_qr_pay_notify(payway, requestContent):


# Path: openunipay/admin.py
from django.contrib import admin
from .ali_pay.admin import *
from .weixin_pay.admin import *
from .models import OrderItem, Product, PAY_WAY_WEIXIN
from openunipay.paygateway import unipay

# -*- coding: utf-8 -*-



class OrderItemResource(resources.ModelResource):
    class Meta:
        model = OrderItem
        import_id_fields = ('orderno', )


class OrderItemAdmin(ImportExportModelAdmin):
    resource_class = OrderItemResource
    # list page
    list_display = ('orderno', 'user', 'product_desc', 'payway', 'fee', 'dt_start', 'dt_end', 'dt_pay', 'paied')
    ordering = ('-dt_start', )
    search_fields = ['=orderno',
                     '=user', ]
    list_filter = ('payway',
                   'paied',
                   'product_desc', )

    def save_model(self, request, obj, form, change):
        if not obj.orderno:
            obj.initial_orlder()
        admin.ModelAdmin.save_model(self, request, obj, form, change)


########################### product #########################
class ProductResource(resources.ModelResource):
    class Meta:

        model = OrderItem
