No Description

models.py 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_path, upload_file_url, upload_path
  5. from shortuuidfield import ShortUUIDField
  6. from TimeConvert import TimeConvert as tc
  7. from mch.models import ModelInfo, OperatorInfo
  8. class MchInfoEncryptLogInfo(BaseModelMixin):
  9. plaintext = models.CharField(_(u'plaintext'), max_length=64, blank=True, null=True, help_text=u'待加密字符串', db_index=True, unique=True)
  10. alg = models.CharField(_(u'alg'), max_length=16, blank=True, null=True, help_text=u'加密算法')
  11. ciphertext = models.CharField(_(u'ciphertext'), max_length=64, blank=True, null=True, help_text=u'加密字符串')
  12. brand_pk = models.IntegerField(_(u'brand_pk'), default=0, help_text=u'品牌PK', db_index=True)
  13. model_pk = models.IntegerField(_(u'model_pk'), default=0, help_text=u'型号PK', db_index=True)
  14. distributor_pk = models.IntegerField(_(u'distributor_pk'), default=0, help_text=u'经销商PK', db_index=True)
  15. sn = models.CharField(_(u'sn'), max_length=32, blank=True, null=True, help_text=u'序列号', db_index=True)
  16. # 二维码版本
  17. version = models.IntegerField(_(u'version'), default=2, help_text=u'二维码版本', db_index=True)
  18. # 一物一码
  19. application_id = models.IntegerField(_(u'application_id'), default=0, help_text=u'申请单号', db_index=True)
  20. code = models.CharField(_(u'code'), max_length=16, blank=True, null=True, help_text=u'九位的字符串原始码', db_index=True)
  21. code_url = models.CharField(_(u'code_url'), max_length=128, blank=True, null=True, help_text=u'28位普通码字符 ', db_index=True)
  22. operator_id = models.CharField(_(u'operator_id'), max_length=32, blank=True, null=True, help_text=u'操作员唯一标识', db_index=True)
  23. class Meta:
  24. verbose_name = _(u'mchinfoencryptloginfo')
  25. verbose_name_plural = _(u'mchinfoencryptloginfo')
  26. def __unicode__(self):
  27. return '%d' % self.pk
  28. @property
  29. def admindata(self):
  30. model = ModelInfo.objects.get(pk=self.model_pk, status=True)
  31. try:
  32. operator_name = OperatorInfo.objects.get(operator_id=self.operator_id).name
  33. except OperatorInfo.DoesNotExist:
  34. operator_name = u'深圳捷成'
  35. return {
  36. 'sn': self.sn,
  37. 'model_pk': self.model_pk,
  38. 'model_uni_name': model.model_uni_name,
  39. 'model_name': model.model_name,
  40. 'operator_name': operator_name,
  41. 'created_at': tc.local_string(utc_dt=self.created_at, format='%Y-%m-%d %H:%M:%S')
  42. }
  43. class MchInfoDecryptLogInfo(BaseModelMixin):
  44. ciphertext = models.CharField(_(u'ciphertext'), max_length=64, blank=True, null=True, help_text=u'待解密字符串', db_index=True)
  45. brand_pk = models.IntegerField(_(u'brand_pk'), default=0, help_text=u'品牌PK', db_index=True)
  46. model_pk = models.IntegerField(_(u'model_pk'), default=0, help_text=u'型号PK', db_index=True)
  47. distributor_pk = models.IntegerField(_(u'distributor_pk'), default=0, help_text=u'经销商PK', db_index=True)
  48. sn = models.CharField(_(u'sn'), max_length=32, blank=True, null=True, help_text=u'序列号', db_index=True)
  49. # 一物一码
  50. application_id = models.IntegerField(_(u'application_id'), default=0, help_text=u'申请单号', db_index=True)
  51. code = models.CharField(_(u'code'), max_length=16, blank=True, null=True, help_text=u'九位的字符串原始码', db_index=True)
  52. code_url = models.CharField(_(u'code_url'), max_length=128, blank=True, null=True, help_text=u'28位普通码字符 ', db_index=True)
  53. decrypt_count = models.IntegerField(_(u'decrypt_count'), default=1, help_text=u'解密次数')
  54. class Meta:
  55. verbose_name = _(u'mchinfodecryptloginfo')
  56. verbose_name_plural = _(u'mchinfodecryptloginfo')
  57. def __unicode__(self):
  58. return '%d' % self.pk
  59. class MchLogInfo(BaseModelMixin):
  60. log_id = ShortUUIDField(_(u'log_id'), max_length=32, help_text=u'日志唯一标识', db_index=True)
  61. log_file = models.FileField(_(u'log_file'), upload_to=upload_path, blank=True, null=True, help_text=u'日志文件')
  62. operator_id = models.CharField(_(u'operator_id'), max_length=32, blank=True, null=True, help_text=u'操作员唯一标识', db_index=True)
  63. app_version = models.IntegerField(_(u'app_version'), default=0, help_text=u'APP 版本号', db_index=True)
  64. class Meta:
  65. verbose_name = _(u'mchloginfo')
  66. verbose_name_plural = _(u'mchloginfo')
  67. def __unicode__(self):
  68. return '%d' % self.pk
  69. class MchSearchModelAndCameraLogInfo(BaseModelMixin):
  70. user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True)
  71. log_id = ShortUUIDField(_(u'log_id'), max_length=32, help_text=u'日志唯一标识', db_index=True)
  72. is_search_model = models.IntegerField(_(u'is_search_model'), default=0, help_text=u'搜索镜头型号', db_index=True)
  73. is_selected_model = models.IntegerField(_(u'is_selected_model'), default=0, help_text=u'搜索相机型号', db_index=True)
  74. is_search_camera = models.IntegerField(_(u'is_search_model'), default=0, help_text=u'搜索相机型号', db_index=True)
  75. is_search_model_camera = models.IntegerField(_(u'is_search_model'), default=0, help_text=u'搜索相机型号和镜头型号', db_index=True)
  76. is_search_camera_after_model = models.IntegerField(_(u'is_search_camera_after_model'), default=0, help_text=u'选择镜头后搜索相机型号', db_index=True)
  77. class Meta:
  78. verbose_name = _(u'mchsearchmodelandcameraloginfo')
  79. verbose_name_plural = _(u'mchsearchmodelandcameraloginfo')
  80. def __unicode__(self):
  81. return '%d' % self.pk
  82. class ComplementCodeLogInfo(BaseModelMixin):
  83. AUDIT_TODO = 0
  84. AUDIT_PASS = 1
  85. AUDIT_REFUSED = -1
  86. AUDIT_STATUS_TUPLE = (
  87. (AUDIT_TODO, u'待审核'),
  88. (AUDIT_PASS, u'审核通过'),
  89. (AUDIT_REFUSED, u'审核不通过'),
  90. )
  91. user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True)
  92. log_id = ShortUUIDField(_(u'log_id'), max_length=32, help_text=u'日志唯一标识', db_index=True)
  93. name = models.CharField(_(u'name'), max_length=255, blank=True, null=True, help_text=u'用户姓名')
  94. phone = models.CharField(_(u'phone'), max_length=11, blank=True, null=True, help_text=u'用户电话', db_index=True)
  95. model_id = models.CharField(_(u'model_id'), max_length=32, blank=True, null=True, help_text=u'型号唯一标识', db_index=True)
  96. model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称')
  97. sn = models.CharField(_(u'sn'), max_length=32, blank=True, null=True, help_text=u'序列号', db_index=True)
  98. shot_image = models.ImageField(_(u'shot_image'), upload_to=upload_path, blank=True, null=True, help_text=u'镜头机身照片')
  99. invoice_image = models.ImageField(_(u'invoice_image'), upload_to=upload_path, blank=True, null=True, help_text=u'购买凭证照片')
  100. audit_status = models.IntegerField(_(u'audit_status'), choices=AUDIT_STATUS_TUPLE, default=AUDIT_TODO, help_text=u'审核状态')
  101. ciphertext = models.CharField(_(u'ciphertext'), max_length=64, blank=True, null=True, help_text=u'待解密字符串', db_index=True)
  102. is_contacted = models.BooleanField(_(u'is_contacted'), default=False, help_text=u'是否已联系用户')
  103. class Meta:
  104. verbose_name = _(u'补码记录')
  105. verbose_name_plural = _(u'补码记录')
  106. def __unicode__(self):
  107. return '%d' % self.pk
  108. @property
  109. def shot_image_url(self):
  110. return upload_file_url(self.shot_image)
  111. @property
  112. def shot_image_path(self):
  113. return upload_file_path(self.shot_image)
  114. @property
  115. def invoice_image_url(self):
  116. return upload_file_url(self.invoice_image)
  117. @property
  118. def invoice_image_path(self):
  119. return upload_file_path(self.invoice_image)
  120. @property
  121. def data(self):
  122. model = ModelInfo.objects.get(model_id=self.model_id)
  123. return {
  124. 'user_id': self.user_id,
  125. 'log_id': self.log_id,
  126. 'name': self.name,
  127. 'phone': self.phone,
  128. 'model_id': self.model_id,
  129. 'model_name': model.model_name,
  130. 'sn': self.sn,
  131. 'shot_image': self.shot_image_path,
  132. 'shot_image_url': self.shot_image_url,
  133. 'invoice_image': self.invoice_image_path,
  134. 'invoice_image_url': self.invoice_image_url,
  135. 'audit_status': self.audit_status,
  136. 'is_contacted': self.is_contacted,
  137. 'ciphertext': self.ciphertext,
  138. 'created_at': tc.local_string(utc_dt=self.created_at, format='%Y-%m-%d %H:%M:%S')
  139. }