from django.db import models
from django.utils.translation import gettext_lazy as _

# Create your models here.
class WxApp(models.Model):
    name=models.CharField(_('小程序名称'),max_length=100,unique=True)
    appid=models.CharField(_('小程序ID'),max_length=100)
    appsecret=models.CharField(_('应用密钥'),max_length=100)
    remark=models.CharField(_('备注说明'),max_length=100,blank=True,null=True)
    
    class Meta:
        verbose_name = _('微信小程序/公众号')
        verbose_name_plural = _('微信小程序/公众号')

    def __str__(self):
        return self.name




class Pay(models.Model): 
    company = models.ForeignKey('company.Company', verbose_name=_('公司'), on_delete=models.CASCADE)
    appid=models.CharField(_('公众号ID'),max_length=100)
    key=models.CharField(_('密钥'),max_length=200)
    key_v3=models.CharField(_('密钥v3'),max_length=100,blank=True,null=True)
    cert_serial_no=models.CharField(_('商户证书序列号'),max_length=100,blank=True,null=True)
    cert_path=models.CharField(_('证书地址'),max_length=200)
    pay_id=models.CharField(_('商户号'),max_length=100)
    
    remark=models.CharField(_('备注'),max_length=200,blank=True,null=True)
    comp_abbr=models.CharField(_('公司缩写'),max_length=100,blank=True,null=True)
    send_hb_method = models.SmallIntegerField(_('发放类型'),blank=True,null=True)
    version=models.CharField(_('支付版本'),max_length=6,blank=True,null=True)

    
    class Meta:
        verbose_name = _('微信商户平台')
        verbose_name_plural = _('微信商户平台')


#2021-06-23
class ChannelPromotionRebate(models.Model):    
    ancestor = models.ForeignKey('company.Company', verbose_name=_('公司'), related_name='channelpromotionrebate_company',on_delete=models.CASCADE)
    company=models.ForeignKey('company.Company', verbose_name=_('返利经销商'),on_delete=models.CASCADE)
    promotion=models.ForeignKey('sales.ChannelPromotions',verbose_name=_('渠道促销活动'),on_delete=models.CASCADE)
    labelscan=models.ForeignKey('sales.LabelScan',verbose_name=_('消费者扫码记录'),on_delete=models.CASCADE)    
    consumer=models.ForeignKey('sales.ConsumerAccount',verbose_name=_('微信消费者帐号'),on_delete=models.CASCADE)
    batch=models.ForeignKey('inventory.Batch',verbose_name=_('物流Batch'),on_delete=models.CASCADE)
    product=models.ForeignKey('product.Product',verbose_name=_('产品名称'),on_delete=models.CASCADE)
    saldivision_id=models.IntegerField(_('战区ID'),blank=True,null=True,db_index=True)
    vtype_id=models.SmallIntegerField(_('单据类型'),blank=True,null=True,db_index=True)
    level_id=models.SmallIntegerField(_('营销层级ID'),blank=True,null=True,db_index=True)    
    label_code=models.CharField(_('标签号码'),max_length=20,db_index=True)
    box_code=models.CharField(_('箱标号码'),max_length=20,db_index=True)   
    val =models.DecimalField(_('返利金额（点值）'), max_digits=12, decimal_places=2)
    dt = models.DateField(_('日期'), auto_now_add=True, db_index=True)
    tm = models.DateTimeField(_('时间'), auto_now_add=True)
    remark = models.CharField(_('备注说明'), max_length=100, blank=True, null=True) 

    class Meta:
        verbose_name = _('消费者扫码层级返利')
        verbose_name_plural = _('消费者扫码层级返利')

class PayLog(models.Model):
    company = models.ForeignKey('company.Company', verbose_name=_('公司'), on_delete=models.CASCADE)
    user_id = models.IntegerField(_('用户ID'), null=True, blank=True)
    consumer_id = models.IntegerField(_('消费者ID'), null=True, blank=True)
    pay_code=models.CharField(_('流水单号'),max_length=30,null=True,blank=True)
    amount = models.DecimalField(_('金额'), max_digits=8, decimal_places=2)
    reason = models.CharField(_('原因'),max_length=500,null=True,blank=True)
    remark = models.CharField(_('备注'),max_length=30,null=True,blank=True)
    tm = models.DateTimeField(_('提交时间'), auto_now_add=True)

    class Meta:
        verbose_name=_('支付日志')
        verbose_name_plural = _('支付日志')
        
class TransferRecord(models.Model):
    company = models.ForeignKey('company.Company', verbose_name=_('公司'), on_delete=models.CASCADE)
    batch_id = models.CharField(_('批次号'),max_length=30,null=True,blank=True)
    amount = models.DecimalField(_('金额'), max_digits=8, decimal_places=2)
    reason = models.CharField(_('原因'),max_length=500,null=True,blank=True)
    remark = models.CharField(_('备注'),max_length=30,null=True,blank=True)
    state = models.SmallIntegerField(_('状态'),choices=(
        (0,_('未完成')),
        (1,_('已完成')),
        (2,_('已取消'))), default=0)
    tm = models.DateTimeField(_('提交时间'), auto_now_add=True)

    class Meta:
        verbose_name=_('支付日志')
        verbose_name_plural = _('支付日志')
    
