暫無描述

models.py 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # -*- coding: utf-8 -*-
  2. from django.db import models
  3. from django.utils.translation import ugettext_lazy as _
  4. from django_models_ext import BaseModelMixin, upload_file_url, upload_path
  5. from shortuuidfield import ShortUUIDField
  6. class SalesResponsibilityInfo(BaseModelMixin):
  7. REFUSED = -1
  8. UNVERIFIED = 0
  9. ACTIVATED = 1
  10. DISABLED = 2
  11. DELETED = 3
  12. ASSIGN = 10
  13. USER_STATUS_TUPLE = (
  14. (REFUSED, u'已拒绝'),
  15. (UNVERIFIED, u'未验证'),
  16. (ACTIVATED, u'已激活'),
  17. (DISABLED, u'已禁用'),
  18. (DELETED, u'已删除'),
  19. (ASSIGN, u'已分配'),
  20. )
  21. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  22. brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
  23. sr_id = ShortUUIDField(_(u'sr_id'), max_length=32, blank=True, null=True, help_text=u'销售担当唯一标识', db_index=True, unique=True)
  24. user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True)
  25. unionid = models.CharField(_(u'unionid'), max_length=32, blank=True, null=True, help_text=u'微信 UnionID', db_index=True)
  26. openid = models.CharField(_(u'openid'), max_length=32, blank=True, null=True, help_text=u'微信 OpenID', db_index=True)
  27. name = models.CharField(_(u'name'), max_length=255, blank=True, null=True, help_text=u'销售担当姓名')
  28. phone = models.CharField(_(u'phone'), max_length=11, blank=True, null=True, help_text=u'销售担当联系电话')
  29. avatar = models.CharField(_(u'avatar'), max_length=255, blank=True, null=True, help_text=u'销售担当头像')
  30. user_status = models.IntegerField(_(u'user_status'), choices=USER_STATUS_TUPLE, default=UNVERIFIED, help_text=u'用户状态', db_index=True)
  31. refused_reason = models.TextField(_(u'refused_reason'), blank=True, null=True, help_text=u'审核拒绝原因')
  32. is_auth = models.BooleanField(_(u'is_auth'), default=False, help_text=_(u'是否已授权'), db_index=True)
  33. is_super = models.BooleanField(_(u'is_super'), default=False, help_text=_(u'是否超级销售担当'), db_index=True)
  34. class Meta:
  35. verbose_name = _(u'销售担当信息')
  36. verbose_name_plural = _(u'销售担当信息')
  37. unique_together = (
  38. ('unionid', 'brand_id'),
  39. )
  40. def __unicode__(self):
  41. return u'{}-{}'.format(self.name, self.phone)
  42. @property
  43. def base_data(self):
  44. return {
  45. 'sr_id': self.sr_id,
  46. 'is_sr': True,
  47. 'is_super': self.is_super,
  48. }
  49. @property
  50. def admindata(self):
  51. return {
  52. 'brand_id': self.brand_id,
  53. 'brand_name': self.brand_name,
  54. 'sr_id': self.sr_id,
  55. 'name': self.name,
  56. 'phone': self.phone,
  57. 'status': self.user_status,
  58. 'refused_reason': self.refused_reason,
  59. 'is_auth': self.is_auth,
  60. }
  61. data = admindata
  62. class SalesResponsibilityInfoModelsSaleStatisticInfo(BaseModelMixin):
  63. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  64. # 销售担当,供 SuperSalesResponsibilityInfoModelsSaleStatisticInfo 统计使用
  65. sr_id = models.CharField(_(u'sr_id'), max_length=32, blank=True, null=True, help_text=u'销售担当唯一标识', db_index=True)
  66. # 经销商
  67. distributor_id = models.CharField(_(u'distributor_id'), max_length=32, help_text=u'经销商唯一标识', db_index=True)
  68. distributor_name = models.CharField(_(u'distributor_name'), max_length=255, blank=True, null=True, help_text=u'经销商名称')
  69. # 型号
  70. model_id = models.CharField(_(u'model_id'), max_length=32, help_text=u'型号唯一标识', db_index=True)
  71. model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称', db_index=True)
  72. is_important = models.BooleanField(_(u'is_important'), default=True, help_text=_(u'是否重要型号'), db_index=True)
  73. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
  74. today_num = models.IntegerField(_(u'today_num'), default=0, help_text=u'支数(今日)')
  75. yesterday_num = models.IntegerField(_(u'yesterday_num'), default=0, help_text=u'支数(昨日)')
  76. current_month = models.IntegerField(_(u'current_month'), default=0, help_text=u'支数(本月)')
  77. last_month = models.IntegerField(_(u'last_month'), default=0, help_text=u'支数(上月)')
  78. position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
  79. class Meta:
  80. verbose_name = _(u'[销售担当]型号销量统计')
  81. verbose_name_plural = _(u'[销售担当]型号销量统计')
  82. def __unicode__(self):
  83. return unicode(self.pk)
  84. @property
  85. def data(self):
  86. return {
  87. 'model_id': self.model_id,
  88. 'model_name': self.model_name,
  89. 'is_important': self.is_important,
  90. 'today_num': self.today_num,
  91. 'yesterday_num': self.yesterday_num,
  92. 'current_month': self.current_month,
  93. 'last_month': self.last_month,
  94. }
  95. class SuperSalesResponsibilityInfoModelsSaleStatisticInfo(BaseModelMixin):
  96. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  97. # 销售担当
  98. sr_id = models.CharField(_(u'sr_id'), max_length=32, blank=True, null=True, help_text=u'销售担当唯一标识', db_index=True)
  99. sr_name = models.CharField(_(u'sr_name'), max_length=255, blank=True, null=True, help_text=u'销售担当名称')
  100. sr_avatar = models.CharField(_(u'sr_avatar'), max_length=255, blank=True, null=True, help_text=u'销售担当头像')
  101. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
  102. today_num = models.IntegerField(_(u'today_num'), default=0, help_text=u'支数(今日)')
  103. yesterday_num = models.IntegerField(_(u'yesterday_num'), default=0, help_text=u'支数(昨日)')
  104. current_month = models.IntegerField(_(u'current_month'), default=0, help_text=u'支数(本月)')
  105. last_month = models.IntegerField(_(u'last_month'), default=0, help_text=u'支数(上月)')
  106. position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
  107. class Meta:
  108. verbose_name = _(u'[超级销售担当]销售担当销量统计')
  109. verbose_name_plural = _(u'[超级销售担当]销售担当销量统计')
  110. def __unicode__(self):
  111. return unicode(self.pk)
  112. @property
  113. def data(self):
  114. return {
  115. 'sr_id': self.sr_id,
  116. 'sr_name': self.sr_name,
  117. 'sr_avatar': self.sr_avatar,
  118. 'today_num': self.today_num,
  119. 'yesterday_num': self.yesterday_num,
  120. 'current_month': self.current_month,
  121. 'last_month': self.last_month,
  122. }