@@ -0,0 +1,60 @@ |
||
1 |
+# -*- coding: utf-8 -*- |
|
2 |
+ |
|
3 |
+import logging |
|
4 |
+import os |
|
5 |
+ |
|
6 |
+from django_six import CompatibilityBaseCommand, close_old_connections |
|
7 |
+ |
|
8 |
+from integral.models import SaleclerkSubmitLogInfo |
|
9 |
+from utils.redis.connect import r |
|
10 |
+from utils.redis.rkeys import QINIU_UPLOAD_LIST |
|
11 |
+from utils.qiniucdn import upload_file_path |
|
12 |
+ |
|
13 |
+ |
|
14 |
+logger = logging.getLogger('console') |
|
15 |
+ |
|
16 |
+ |
|
17 |
+class Command(CompatibilityBaseCommand): |
|
18 |
+ def handle(self, *args, **options): |
|
19 |
+ |
|
20 |
+ logger.info('Upload image qiniu is dealing') |
|
21 |
+ |
|
22 |
+ while True: |
|
23 |
+ # r.rpushjson('QINIU_UPLOAD_LIST', { |
|
24 |
+ # 'model': 'SaleclerkSubmitLogInfo', |
|
25 |
+ # 'pk': 'pk', |
|
26 |
+ # }) |
|
27 |
+ k, v = r.blpopjson(QINIU_UPLOAD_LIST, 60) |
|
28 |
+ if not v: |
|
29 |
+ continue |
|
30 |
+ |
|
31 |
+ logger.info(v) |
|
32 |
+ |
|
33 |
+ model, pk = v.get('model', ''), v.get('pk', '') |
|
34 |
+ |
|
35 |
+ close_old_connections() |
|
36 |
+ |
|
37 |
+ if model == 'SaleclerkSubmitLogInfo': |
|
38 |
+ try: |
|
39 |
+ ssli = SaleclerkSubmitLogInfo.objects.get(pk=pk) |
|
40 |
+ except SaleclerkSubmitLogInfo.DoesNotExist: |
|
41 |
+ continue |
|
42 |
+ |
|
43 |
+ if ssli.image: |
|
44 |
+ try: |
|
45 |
+ upload_file_path(ssli.image.path, key=ssli.image.name, bucket='tamron') |
|
46 |
+ os.remove(ssli.image.path) |
|
47 |
+ except: |
|
48 |
+ pass |
|
49 |
+ |
|
50 |
+ if ssli.code_image: |
|
51 |
+ try: |
|
52 |
+ upload_file_path(ssli.code_image.path, key=ssli.code_image.name, bucket='tamron') |
|
53 |
+ os.remove(ssli.code_image.path) |
|
54 |
+ except: |
|
55 |
+ pass |
|
56 |
+ |
|
57 |
+ ssli.is_upload_qiniu = True |
|
58 |
+ ssli.save() |
|
59 |
+ |
|
60 |
+ close_old_connections() |
@@ -15,7 +15,7 @@ class SaleclerkIntegralIncomeExpensesInfoAdmin(ReadOnlyModelAdmin, admin.ModelAd |
||
15 | 15 |
|
16 | 16 |
class SaleclerkSubmitLogInfoAdmin(AdvancedExportExcelModelAdmin, ReadOnlyModelAdmin, admin.ModelAdmin): |
17 | 17 |
list_display = ('clerk_id', 'clerk_name', 'model_name', 'model_uni_name', 'distributor_name', 'code', 'has_scan', 'remark', 'dupload', 'ymd', 'trackingNo', 'is_wxwork', 'is_staff_delete', 'status', 'created_at', 'updated_at') |
18 |
- list_filter = ('brand_pk', 'dupload', 'test_user', 'test_sn', 'has_scan', 'is_wxwork', 'is_staff_delete', 'status', 'created_at', 'remark') |
|
18 |
+ list_filter = ('brand_pk', 'dupload', 'test_user', 'test_sn', 'has_scan', 'is_wxwork', 'is_staff_delete', 'is_upload_qiniu', 'status', 'created_at', 'remark') |
|
19 | 19 |
excel_fields = ('created_at', 'distributor_name', 'clerk_name', 'model_uni_name', 'model_name', 'code', 'has_scan', 'remark') |
20 | 20 |
search_fields = ('code', 'trackingNo', 'distributor_name', 'clerk_name', 'model_name', 'model_uni_name') |
21 | 21 |
|
@@ -0,0 +1,20 @@ |
||
1 |
+# -*- coding: utf-8 -*- |
|
2 |
+# Generated by Django 1.11.29 on 2020-06-08 20:35 |
|
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 |
+ ('integral', '0018_saleclerksubmitloginfo_code_image'), |
|
12 |
+ ] |
|
13 |
+ |
|
14 |
+ operations = [ |
|
15 |
+ migrations.AddField( |
|
16 |
+ model_name='saleclerksubmitloginfo', |
|
17 |
+ name='is_upload_qiniu', |
|
18 |
+ field=models.BooleanField(db_index=True, default=False, help_text='\u662f\u5426\u5df2\u4e0a\u4f20\u4e03\u725b', verbose_name='is_upload_qiniu'), |
|
19 |
+ ), |
|
20 |
+ ] |
@@ -6,6 +6,7 @@ from django_models_ext import BaseModelMixin, upload_path, upload_file_path, upl |
||
6 | 6 |
from TimeConvert import TimeConvert as tc |
7 | 7 |
|
8 | 8 |
from mch.models import ModelInfo |
9 |
+from utils.qiniucdn import qiniu_file_url |
|
9 | 10 |
|
10 | 11 |
|
11 | 12 |
class SaleclerkIntegralIncomeExpensesInfo(BaseModelMixin): |
@@ -120,6 +121,8 @@ class SaleclerkSubmitLogInfo(BaseModelMixin): |
||
120 | 121 |
is_staff_delete = models.BooleanField(_(u'is_staff_delete'), default=False, help_text=_(u'是否管理员删除'), db_index=True) |
121 | 122 |
code_version = models.IntegerField(_(u'code_version'), default=1, help_text=_(u'统览码版本'), db_index=True) |
122 | 123 |
|
124 |
+ is_upload_qiniu = models.BooleanField(_(u'is_upload_qiniu'), default=False, help_text=_(u'是否已上传七牛'), db_index=True) |
|
125 |
+ |
|
123 | 126 |
class Meta: |
124 | 127 |
verbose_name = _(u'销售员扫码出库记录') |
125 | 128 |
verbose_name_plural = _(u'销售员扫码出库记录') |
@@ -133,15 +136,15 @@ class SaleclerkSubmitLogInfo(BaseModelMixin): |
||
133 | 136 |
|
134 | 137 |
@property |
135 | 138 |
def image_url(self): |
136 |
- return upload_file_url(self.image) |
|
139 |
+ return qiniu_file_url(self.image.name, bucket='tamron') if self.is_upload_qiniu else upload_file_url(self.image) |
|
137 | 140 |
|
138 | 141 |
@property |
139 | 142 |
def code_image_path(self): |
140 |
- return upload_file_path(self.image) |
|
143 |
+ return upload_file_path(self.code_image) |
|
141 | 144 |
|
142 | 145 |
@property |
143 | 146 |
def code_image_url(self): |
144 |
- return upload_file_url(self.image) |
|
147 |
+ return qiniu_file_url(self.code_image.name, bucket='tamron') if self.is_upload_qiniu else upload_file_url(self.code_image) |
|
145 | 148 |
|
146 | 149 |
@property |
147 | 150 |
def admindata(self): |
@@ -256,6 +256,7 @@ QINIU = { |
||
256 | 256 |
'thumbnail': 'http://thumbnail.img.pai.ai', |
257 | 257 |
'thumbnail2': 'http://thumbnail2.img.pai.ai', |
258 | 258 |
'watermark': 'http://watermark.img.pai.ai', |
259 |
+ 'tamron': 'http://qbmivthwi.bkt.clouddn.com', |
|
259 | 260 |
} |
260 | 261 |
} |
261 | 262 |
|
@@ -79,3 +79,6 @@ SUBSCRIBE_USERINFO_LIST = 'subscribe:userinfo:%s' |
||
79 | 79 |
MEMBER_SHOT_DATA = 'kodo:member:shot:data' |
80 | 80 |
MEMBER_SEND_COUPON_LIST = 'kodo:member:send:coupon:list' |
81 | 81 |
MEMBER_UPGRADE_INFO = 'kodo:member:upgrade:info:%s:%s' # brand_id, user_id |
82 |
+ |
|
83 |
+# 七牛 |
|
84 |
+QINIU_UPLOAD_LIST = 'kodo:qiniu:upload:list' |