拍爱

models.py 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. group_id = models.CharField(_(u'group_id'), max_length=255, blank=True, null=True, help_text=u'群组唯一标识', db_index=True)
  45. session_id = models.CharField(_(u'session_id'), max_length=255, blank=True, null=True, help_text=u'照片组唯一标识,同 PhotosInfo 表', db_index=True)
  46. photo_id = models.CharField(_(u'photo_id'), max_length=255, blank=True, null=True, help_text=u'飞图唯一标识', db_index=True)
  47. lensman_photo_id = models.CharField(_(u'lensman_photo_id'), max_length=255, blank=True, null=True, help_text=u'摄影师照片唯一标识,同 PhotosInfo 表', db_index=True)
  48. photo_type = models.IntegerField(_('photo_type'), choices=PHOTO_TYPE, default=NOMARK, help_text=u'购买照片类型', db_index=True)
  49. photo_status = models.IntegerField(_(u'photo_status'), choices=PHOTO_STATUS, default=WANTED, help_text=_(u'购买照片状态, 标识用户是否已经获得照片'), db_index=True)
  50. from_uid = models.CharField(_(u'from_uid'), max_length=255, help_text=u'付款用户唯一标识', db_index=True)
  51. to_uid = models.CharField(_(u'to_uid'), max_length=255, blank=True, null=True, help_text=u'收款用户唯一标识', db_index=True)
  52. body = models.CharField(_(u'body'), max_length=255, blank=True, null=True, help_text=u'商品描述')
  53. total_fee = models.IntegerField(_(u'total_fee'), default=0, help_text=u'总金额')
  54. trade_type = models.CharField(_('trade_type'), max_length=255, blank=True, null=True, help_text=u'支付方式')
  55. pay_status = models.IntegerField(_(u'pay_status'), choices=PAY_STATUS, default=WAITING_PAY, help_text=u'支付状态', db_index=True)
  56. paid_at = models.DateTimeField(_(u'paid_at'), blank=True, null=True, help_text=_(u'支付时间'))
  57. reback_status = models.BooleanField(_(u'reback_status'), default=False, help_text=u'退款状态', db_index=True)
  58. reback_at = models.DateTimeField(_(u'reback_at'), blank=True, null=True, help_text=_(u'退款时间'))
  59. class Meta:
  60. verbose_name = _('orderinfo')
  61. verbose_name_plural = _('orderinfo')
  62. def __unicode__(self):
  63. return u'{0.pk}'.format(self)
  64. def data(self, user_id=None):
  65. try:
  66. group_photo = GroupPhotoInfo.objects.get(photo_id=self.photo_id)
  67. except GroupPhotoInfo.DoesNotExist:
  68. group_photo = None
  69. return {
  70. 'order_id': self.order_id,
  71. 'from_uid': self.from_uid,
  72. 'group_id': self.group_id,
  73. 'photo_id': self.photo_id,
  74. 'group_photo_info': group_photo and group_photo.photo_info(user_id),
  75. 'to_uid': self.to_uid,
  76. 'body': self.body,
  77. 'total_fee': self.total_fee,
  78. 'pay_status': self.pay_status,
  79. 'paid_at': tc.remove_microsecond(self.paid_at),
  80. 'created_at': tc.remove_microsecond(self.created_at),
  81. }
  82. @property
  83. def lensdata(self, user_id=None):
  84. try:
  85. group_photo = GroupPhotoInfo.objects.get(photo_id=self.photo_id)
  86. except GroupPhotoInfo.DoesNotExist:
  87. group_photo = None
  88. return {
  89. 'order_id': self.order_id,
  90. 'session_id': self.session_id,
  91. 'photo_id': self.lensman_photo_id,
  92. 'group_photo_info': group_photo and group_photo.photo_info(user_id),
  93. }