No Description

models.py 9.8KB

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