Nenhuma Descrição

models.py 12KB

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