@@ -7,7 +7,7 @@ import random  | 
            ||
| 7 | 7 | 
                from django_logit import logit  | 
            
| 8 | 8 | 
                from django_response import response  | 
            
| 9 | 9 | 
                 | 
            
| 10 | 
                -from logs.models import MchInfoEncryptLogInfo  | 
            |
| 10 | 
                +from logs.models import MchInfoDecryptLogInfo, MchInfoEncryptLogInfo  | 
            |
| 11 | 11 | 
                from mch.models import BrandInfo, ModelInfo  | 
            
| 12 | 12 | 
                from utils.algorithm.b64 import b64_decrypt, b64_encrypt  | 
            
| 13 | 13 | 
                from utils.algorithm.caesar import caesar_decrypt, caesar_encrypt  | 
            
                @@ -96,6 +96,18 @@ def decrypt(request):  | 
            ||
| 96 | 96 | 
                except ModelInfo.DoesNotExist:  | 
            
| 97 | 97 | 
                model = None  | 
            
| 98 | 98 | 
                 | 
            
| 99 | 
                +    mdli, created_at = MchInfoDecryptLogInfo.objects.get_or_create(ciphertext=ciphertext, defaults={
               | 
            |
| 100 | 
                + 'brand_pk': brand_pk,  | 
            |
| 101 | 
                + 'model_pk': model_pk,  | 
            |
| 102 | 
                + 'distributor_pk': distributor_pk,  | 
            |
| 103 | 
                + 'sn': sn,  | 
            |
| 104 | 
                + 'decrypt_count': 1,  | 
            |
| 105 | 
                + })  | 
            |
| 106 | 
                +  | 
            |
| 107 | 
                + if not created_at:  | 
            |
| 108 | 
                + mdli.decrypt_count += 1  | 
            |
| 109 | 
                + mdli.save()  | 
            |
| 110 | 
                +  | 
            |
| 99 | 111 | 
                     return response(200, data={
               | 
            
| 100 | 112 | 
                'plaintext': plaintext,  | 
            
| 101 | 113 | 
                'logo_url': brand.brand_logo_url if brand else '',  | 
            
                @@ -0,0 +1,34 @@  | 
            ||
| 1 | 
                +# -*- coding: utf-8 -*-  | 
            |
| 2 | 
                +# Generated by Django 1.11.15 on 2018-09-17 04:14  | 
            |
| 3 | 
                +from __future__ import unicode_literals  | 
            |
| 4 | 
                +  | 
            |
| 5 | 
                +from django.db import migrations, models  | 
            |
| 6 | 
                +  | 
            |
| 7 | 
                +  | 
            |
| 8 | 
                +class Migration(migrations.Migration):  | 
            |
| 9 | 
                +  | 
            |
| 10 | 
                + dependencies = [  | 
            |
| 11 | 
                +        ('logs', '0004_mchinfoencryptloginfo_distributor_pk'),
               | 
            |
| 12 | 
                + ]  | 
            |
| 13 | 
                +  | 
            |
| 14 | 
                + operations = [  | 
            |
| 15 | 
                + migrations.CreateModel(  | 
            |
| 16 | 
                + name='MchInfoDecryptLogInfo',  | 
            |
| 17 | 
                + fields=[  | 
            |
| 18 | 
                +                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
               | 
            |
| 19 | 
                +                ('status', models.BooleanField(db_index=True, default=True, help_text='Status', verbose_name='status')),
               | 
            |
| 20 | 
                +                ('created_at', models.DateTimeField(auto_now_add=True, help_text='Create Time', verbose_name='created_at')),
               | 
            |
| 21 | 
                +                ('updated_at', models.DateTimeField(auto_now=True, help_text='Update Time', verbose_name='updated_at')),
               | 
            |
| 22 | 
                +                ('ciphertext', models.CharField(blank=True, db_index=True, help_text='\u5f85\u89e3\u5bc6\u5b57\u7b26\u4e32', max_length=64, null=True, verbose_name='ciphertext')),
               | 
            |
| 23 | 
                +                ('brand_pk', models.IntegerField(db_index=True, default=0, help_text='\u54c1\u724cPK', verbose_name='brand_pk')),
               | 
            |
| 24 | 
                +                ('model_pk', models.IntegerField(db_index=True, default=0, help_text='\u578b\u53f7PK', verbose_name='model_pk')),
               | 
            |
| 25 | 
                +                ('distributor_pk', models.IntegerField(db_index=True, default=0, help_text='\u7ecf\u9500\u5546PK', verbose_name='distributor_pk')),
               | 
            |
| 26 | 
                +                ('sn', models.CharField(blank=True, db_index=True, help_text='\u5e8f\u5217\u53f7', max_length=32, null=True, verbose_name='sn')),
               | 
            |
| 27 | 
                +                ('decrypt_count', models.IntegerField(default=1, help_text='\u89e3\u5bc6\u6b21\u6570', verbose_name='decrypt_count')),
               | 
            |
| 28 | 
                + ],  | 
            |
| 29 | 
                +            options={
               | 
            |
| 30 | 
                + 'verbose_name': 'mchinfodecryptloginfo',  | 
            |
| 31 | 
                + 'verbose_name_plural': 'mchinfodecryptloginfo',  | 
            |
| 32 | 
                + },  | 
            |
| 33 | 
                + ),  | 
            |
| 34 | 
                + ]  | 
            
                @@ -28,6 +28,25 @@ class MchInfoEncryptLogInfo(BaseModelMixin):  | 
            ||
| 28 | 28 | 
                return unicode(self.pk)  | 
            
| 29 | 29 | 
                 | 
            
| 30 | 30 | 
                 | 
            
| 31 | 
                +class MchInfoDecryptLogInfo(BaseModelMixin):  | 
            |
| 32 | 
                + ciphertext = models.CharField(_(u'ciphertext'), max_length=64, blank=True, null=True, help_text=u'待解密字符串', db_index=True)  | 
            |
| 33 | 
                +  | 
            |
| 34 | 
                + brand_pk = models.IntegerField(_(u'brand_pk'), default=0, help_text=u'品牌PK', db_index=True)  | 
            |
| 35 | 
                + model_pk = models.IntegerField(_(u'model_pk'), default=0, help_text=u'型号PK', db_index=True)  | 
            |
| 36 | 
                + distributor_pk = models.IntegerField(_(u'distributor_pk'), default=0, help_text=u'经销商PK', db_index=True)  | 
            |
| 37 | 
                +  | 
            |
| 38 | 
                + sn = models.CharField(_(u'sn'), max_length=32, blank=True, null=True, help_text=u'序列号', db_index=True)  | 
            |
| 39 | 
                +  | 
            |
| 40 | 
                + decrypt_count = models.IntegerField(_(u'decrypt_count'), default=1, help_text=u'解密次数')  | 
            |
| 41 | 
                +  | 
            |
| 42 | 
                + class Meta:  | 
            |
| 43 | 
                + verbose_name = _(u'mchinfodecryptloginfo')  | 
            |
| 44 | 
                + verbose_name_plural = _(u'mchinfodecryptloginfo')  | 
            |
| 45 | 
                +  | 
            |
| 46 | 
                + def __unicode__(self):  | 
            |
| 47 | 
                + return unicode(self.pk)  | 
            |
| 48 | 
                +  | 
            |
| 49 | 
                +  | 
            |
| 31 | 50 | 
                class MchLogInfo(BaseModelMixin):  | 
            
| 32 | 51 | 
                log_id = ShortUUIDField(_(u'log_id'), max_length=32, help_text=u'日志唯一标识', db_index=True)  | 
            
| 33 | 52 | 
                log_file = models.FileField(_(u'log_file'), upload_to=upload_path, blank=True, null=True, help_text=u'日志文件')  |