No Description

models.py 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. # -*- coding: utf-8 -*-
  2. from django.conf import settings
  3. from django.db import models
  4. from django.utils.translation import ugettext_lazy as _
  5. from django_models_ext import BaseModelMixin
  6. from jsonfield import JSONField
  7. from utils.rdm_utils import randnum
  8. class RegisterStatisticInfo(BaseModelMixin):
  9. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  10. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d')
  11. num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
  12. class Meta:
  13. verbose_name = _(u'注册用户统计')
  14. verbose_name_plural = _(u'注册用户统计')
  15. def __unicode__(self):
  16. return unicode(self.pk)
  17. @property
  18. def data(self):
  19. return {
  20. 'ymd': self.ymd,
  21. 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
  22. }
  23. # 经销商维度
  24. class SaleStatisticInfo(BaseModelMixin):
  25. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  26. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d')
  27. num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
  28. class Meta:
  29. verbose_name = _(u'[经销商维度]销量统计')
  30. verbose_name_plural = _(u'[经销商维度]销量统计')
  31. def __unicode__(self):
  32. return unicode(self.pk)
  33. @property
  34. def data(self):
  35. return {
  36. 'ymd': self.ymd,
  37. 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
  38. }
  39. class ModelSaleStatisticInfo(BaseModelMixin):
  40. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  41. model_id = models.CharField(_(u'model_id'), max_length=32, help_text=u'型号唯一标识', db_index=True)
  42. model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称')
  43. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
  44. num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
  45. class Meta:
  46. verbose_name = _(u'[经销商维度]型号销量统计')
  47. verbose_name_plural = _(u'[经销商维度]型号销量统计')
  48. def __unicode__(self):
  49. return unicode(self.pk)
  50. @property
  51. def data(self):
  52. return {
  53. 'model_id': self.model_id,
  54. 'model_name': self.model_name,
  55. 'ymd': self.ymd,
  56. 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
  57. }
  58. # TODO: ROI Calc
  59. @property
  60. def roi(self):
  61. return {
  62. 'model_id': self.model_id,
  63. 'model_name': self.model_name,
  64. 'roi': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
  65. }
  66. class DistributorSaleStatisticInfo(BaseModelMixin):
  67. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  68. distributor_id = models.CharField(_(u'distributor_id'), max_length=32, help_text=u'经销商唯一标识', db_index=True)
  69. distributor_name = models.CharField(_(u'distributor_name'), max_length=255, blank=True, null=True, help_text=u'经销商名称')
  70. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
  71. num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
  72. class Meta:
  73. verbose_name = _(u'[经销商维度]经销商销量统计')
  74. verbose_name_plural = _(u'[经销商维度]经销商销量统计')
  75. def __unicode__(self):
  76. return unicode(self.pk)
  77. @property
  78. def data(self):
  79. return {
  80. 'distributor_id': self.distributor_id,
  81. 'distributor_name': self.distributor_name,
  82. 'ymd': self.ymd,
  83. 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
  84. }
  85. class ProvinceSaleStatisticInfo(BaseModelMixin):
  86. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  87. province_code = models.CharField(_(u'province_code'), max_length=6, help_text=u'省份编码', db_index=True)
  88. province_name = models.CharField(_(u'province_name'), max_length=8, blank=True, null=True, help_text=u'省份名称')
  89. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
  90. num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
  91. position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
  92. class Meta:
  93. verbose_name = _(u'[经销商维度]省份销量统计')
  94. verbose_name_plural = _(u'[经销商维度]省份销量统计')
  95. def __unicode__(self):
  96. return unicode(self.pk)
  97. @property
  98. def data(self):
  99. return {
  100. 'province_code': self.province_code,
  101. 'province_name': self.province_name,
  102. # 'ymd': self.ymd,
  103. 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
  104. }
  105. class SaleclerkSaleStatisticInfo(BaseModelMixin):
  106. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  107. distributor_id = models.CharField(_(u'distributor_id'), max_length=32, blank=True, null=True, help_text=u'经销商唯一标识', db_index=True)
  108. distributor_name = models.CharField(_(u'distributor_name'), max_length=32, blank=True, null=True, help_text=u'经销商名称')
  109. distributor_short_name = models.CharField(_(u'distributor_short_name'), max_length=8, blank=True, null=True, help_text=u'经销商简称')
  110. clerk_id = models.CharField(_(u'clerk_id'), max_length=32, blank=True, null=True, help_text=u'店员唯一标识', db_index=True)
  111. clerk_name = models.CharField(_(u'clerk_name'), max_length=32, blank=True, null=True, help_text=u'店员名称')
  112. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
  113. num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
  114. class Meta:
  115. verbose_name = _(u'[经销商维度]销售员销量统计')
  116. verbose_name_plural = _(u'[经销商维度]销售员销量统计')
  117. def __unicode__(self):
  118. return unicode(self.pk)
  119. @property
  120. def data(self):
  121. return {
  122. 'distributor_name': self.distributor_short_name or self.distributor_name or '',
  123. 'salesman_id': self.clerk_id,
  124. 'salesman_name': self.clerk_name,
  125. # 'ymd': self.ymd,
  126. 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
  127. }
  128. # 消费者维度
  129. class ConsumeUserStatisticInfo(BaseModelMixin):
  130. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  131. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d')
  132. users = JSONField(_(u'users'), default=[], help_text=u'用户列表')
  133. num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
  134. class Meta:
  135. verbose_name = _(u'[消费者维度]用户统计')
  136. verbose_name_plural = _(u'[消费者维度]用户统计')
  137. def __unicode__(self):
  138. return unicode(self.pk)
  139. @property
  140. def data(self):
  141. return {
  142. 'ymd': self.ymd,
  143. 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
  144. }
  145. class ConsumeSaleStatisticInfo(BaseModelMixin):
  146. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  147. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d')
  148. num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
  149. class Meta:
  150. verbose_name = _(u'[消费者维度]销量统计')
  151. verbose_name_plural = _(u'[消费者维度]销量统计')
  152. def __unicode__(self):
  153. return unicode(self.pk)
  154. @property
  155. def data(self):
  156. return {
  157. 'ymd': self.ymd,
  158. 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
  159. }
  160. class ConsumeModelSaleStatisticInfo(BaseModelMixin):
  161. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  162. model_id = models.CharField(_(u'model_id'), max_length=32, help_text=u'型号唯一标识', db_index=True)
  163. model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称', db_index=True)
  164. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
  165. num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
  166. class Meta:
  167. verbose_name = _(u'[消费者维度]型号销量统计')
  168. verbose_name_plural = _(u'[消费者维度]型号销量统计')
  169. def __unicode__(self):
  170. return unicode(self.pk)
  171. @property
  172. def data(self):
  173. return {
  174. 'model_id': self.model_id,
  175. 'model_name': self.model_name,
  176. # 'ymd': self.ymd,
  177. 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
  178. }
  179. class ConsumeDistributorSaleStatisticInfo(BaseModelMixin):
  180. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  181. distributor_id = models.CharField(_(u'distributor_id'), max_length=32, help_text=u'经销商唯一标识', db_index=True)
  182. distributor_name = models.CharField(_(u'distributor_name'), max_length=255, blank=True, null=True, help_text=u'经销商名称')
  183. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
  184. num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
  185. class Meta:
  186. verbose_name = _(u'[消费者维度]经销商销量统计')
  187. verbose_name_plural = _(u'[消费者维度]经销商销量统计')
  188. def __unicode__(self):
  189. return unicode(self.pk)
  190. @property
  191. def data(self):
  192. return {
  193. 'distributor_id': self.distributor_id,
  194. 'distributor_name': self.distributor_name,
  195. 'ymd': self.ymd,
  196. 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
  197. }
  198. class ConsumeProvinceSaleStatisticInfo(BaseModelMixin):
  199. brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
  200. province_code = models.CharField(_(u'province_code'), max_length=6, help_text=u'省份编码', db_index=True)
  201. province_name = models.CharField(_(u'province_name'), max_length=8, blank=True, null=True, help_text=u'省份名称')
  202. ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
  203. users = JSONField(_(u'users'), default=[], help_text=u'用户列表')
  204. num = models.IntegerField(_(u'num'), default=0, help_text=u'人数')
  205. num2 = models.IntegerField(_(u'num2'), default=0, help_text=u'支数')
  206. position = models.IntegerField(_(u'position'), default=1, help_text=u'排序')
  207. class Meta:
  208. verbose_name = _(u'[消费者维度]省份销量统计')
  209. verbose_name_plural = _(u'[消费者维度]省份销量统计')
  210. def __unicode__(self):
  211. return unicode(self.pk)
  212. @property
  213. def data(self):
  214. return {
  215. 'province_code': self.province_code,
  216. 'province_name': self.province_name,
  217. 'ymd': self.ymd,
  218. 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,
  219. 'num2': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num2,
  220. }