拍爱

models.py 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # -*- coding: utf-8 -*-
  2. from django.db import models
  3. from django.utils.translation import ugettext_lazy as _
  4. from shortuuidfield import ShortUUIDField
  5. from TimeConvert import TimeConvert as tc
  6. from group.models import GroupPhotoInfo
  7. from pai2.basemodels import CreateUpdateMixin
  8. class OrderInfo(CreateUpdateMixin):
  9. NOMARK = 0
  10. ORIGIN = 1
  11. PHOTO_TYPE = (
  12. (NOMARK, u'去除水印'),
  13. (ORIGIN, u'获取高清图'),
  14. )
  15. WANTED = 0
  16. FETCHED = 1
  17. DELETED = 2
  18. PHOTO_STATUS = (
  19. (WANTED, u'待上传'),
  20. (FETCHED, u'已上传'),
  21. (DELETED, u'已删除'),
  22. )
  23. """
  24. # Trade State of Wechat Query
  25. SUCCESS ——— 支付成功
  26. REFUND ——— 转入退款
  27. NOTPAY ——— 未支付
  28. CLOSED ——— 已关闭
  29. REVOKED ——— 已撤销(刷卡支付)
  30. USERPAYING ——— 用户支付中
  31. PAYERROR ——— 支付失败(其他原因,如银行返回失败)
  32. """
  33. WAITING_PAY = 0
  34. PAID = 1
  35. FAIL = 2
  36. # DELETED = 9
  37. PAY_STATUS = (
  38. (WAITING_PAY, u'待支付'),
  39. (PAID, u'已支付'),
  40. (FAIL, u'已失败'),
  41. # (DELETED, u'已删除'),
  42. )
  43. order_id = ShortUUIDField(_(u'order_id'), max_length=255, help_text=u'订单唯一标识', db_index=True)
  44. prepay_id = models.CharField(_(u'prepay_id'), max_length=255, blank=True, null=True, help_text=u'预支付交易会话标识')
  45. transaction_id = models.CharField(_(u'transaction_id'), max_length=255, blank=True, null=True, help_text=u'交易单号')
  46. group_id = models.CharField(_(u'group_id'), max_length=255, blank=True, null=True, help_text=u'群组唯一标识', db_index=True)
  47. session_id = models.CharField(_(u'session_id'), max_length=255, blank=True, null=True, help_text=u'照片组唯一标识,同 PhotosInfo 表', db_index=True)
  48. photo_id = models.CharField(_(u'photo_id'), max_length=255, blank=True, null=True, help_text=u'飞图唯一标识', db_index=True)
  49. lensman_photo_id = models.CharField(_(u'lensman_photo_id'), max_length=255, blank=True, null=True, help_text=u'摄影师照片唯一标识,同 PhotosInfo 表', db_index=True)
  50. photo_type = models.IntegerField(_(u'photo_type'), choices=PHOTO_TYPE, default=NOMARK, help_text=u'购买照片类型', db_index=True)
  51. photo_status = models.IntegerField(_(u'photo_status'), choices=PHOTO_STATUS, default=WANTED, help_text=_(u'购买照片状态, 标识用户是否已经获得照片'), db_index=True)
  52. from_uid = models.CharField(_(u'from_uid'), max_length=255, help_text=u'付款用户唯一标识', db_index=True)
  53. to_uid = models.CharField(_(u'to_uid'), max_length=255, blank=True, null=True, help_text=u'收款用户唯一标识', db_index=True)
  54. body = models.CharField(_(u'body'), max_length=255, blank=True, null=True, help_text=u'商品描述')
  55. total_fee = models.IntegerField(_(u'total_fee'), default=0, help_text=u'总金额')
  56. trade_type = models.CharField(_(u'trade_type'), max_length=255, blank=True, null=True, help_text=u'支付方式')
  57. pay_status = models.IntegerField(_(u'pay_status'), choices=PAY_STATUS, default=WAITING_PAY, help_text=u'支付状态', db_index=True)
  58. paid_at = models.DateTimeField(_(u'paid_at'), blank=True, null=True, help_text=_(u'支付时间'))
  59. reback_status = models.BooleanField(_(u'reback_status'), default=False, help_text=u'退款状态', db_index=True)
  60. reback_at = models.DateTimeField(_(u'reback_at'), blank=True, null=True, help_text=_(u'退款时间'))
  61. # 微信统一下单
  62. unifiedorder_result = models.TextField(_(u'unifiedorder_result'), blank=True, null=True, help_text=_(u'统一下单结果'))
  63. # 微信支付回调
  64. notify_msg = models.TextField(_(u'notify_msg'), blank=True, null=True, help_text=u'回调信息')
  65. class Meta:
  66. verbose_name = _(u'orderinfo')
  67. verbose_name_plural = _(u'orderinfo')
  68. def __unicode__(self):
  69. return u'{0.pk}'.format(self)
  70. def data(self, user_id=None):
  71. try:
  72. group_photo = GroupPhotoInfo.objects.get(photo_id=self.photo_id)
  73. except GroupPhotoInfo.DoesNotExist:
  74. group_photo = None
  75. return {
  76. 'order_id': self.order_id,
  77. 'from_uid': self.from_uid,
  78. 'group_id': self.group_id,
  79. 'photo_id': self.photo_id,
  80. 'group_photo_info': group_photo and group_photo.photo_info(user_id),
  81. 'to_uid': self.to_uid,
  82. 'body': self.body,
  83. 'total_fee': self.total_fee,
  84. 'pay_status': self.pay_status,
  85. 'paid_at': tc.remove_microsecond(self.paid_at),
  86. 'created_at': tc.remove_microsecond(self.created_at),
  87. }
  88. @property
  89. def lensdata(self, user_id=None):
  90. try:
  91. group_photo = GroupPhotoInfo.objects.get(photo_id=self.photo_id)
  92. except GroupPhotoInfo.DoesNotExist:
  93. group_photo = None
  94. return {
  95. 'order_id': self.order_id,
  96. 'session_id': self.session_id,
  97. 'photo_id': self.lensman_photo_id,
  98. 'group_photo_info': group_photo and group_photo.photo_info(user_id),
  99. }