refreshm

Brightcells 6 years ago
parent
commit
d12cffef3f
4 changed files with 40 additions and 9 deletions
  1. 4 6
      api/mch_views.py
  2. 34 0
      pre/views.py
  3. 1 1
      statistic/models.py
  4. 1 2
      statistic/views.py

+ 4 - 6
api/mch_views.py

@@ -325,28 +325,25 @@ def consumer_info_api(request):
325 325
             # 日型号销量统计
326 326
             mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(
327 327
                 brand_id=brand.brand_id,
328
-                model_id=model.model_id,
328
+                model_name=model.model_uni_name,
329 329
                 ymd=ymd,
330 330
             )
331
-            mssi.model_name = model.model_name
332 331
             mssi.num += 1
333 332
             mssi.save()
334 333
             # 月型号销量统计
335 334
             mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(
336 335
                 brand_id=brand.brand_id,
337
-                model_id=model.model_id,
336
+                model_name=model.model_uni_name,
338 337
                 ymd=ymd[:6],
339 338
             )
340
-            mssi.model_name = model.model_name
341 339
             mssi.num += 1
342 340
             mssi.save()
343 341
             # 年型号销量统计
344 342
             mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(
345 343
                 brand_id=brand.brand_id,
346
-                model_id=model.model_id,
344
+                model_name=model.model_uni_name,
347 345
                 ymd=ymd[:4],
348 346
             )
349
-            mssi.model_name = model.model_name
350 347
             mssi.num += 1
351 348
             mssi.save()
352 349
 
@@ -419,6 +416,7 @@ def consumer_snlist_api(request):
419 416
         return response(UserStatusCode.USER_NOT_FOUND)
420 417
 
421 418
     # 用户信息提交列表
419
+    # TODO: 按照序列号去重
422 420
     logs = ConsumeInfoSubmitLogInfo.objects.filter(user_id=user_id, status=True)
423 421
     logs = [log.data for log in logs]
424 422
 

+ 34 - 0
pre/views.py

@@ -210,3 +210,37 @@ def refreshp():
210 210
             'lon': log.lon,
211 211
             'ymd': tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d'),
212 212
         })
213
+
214
+
215
+def refreshm():
216
+    logs = ConsumeInfoSubmitLogInfo.objects.filter(test_user=False)
217
+    for log in logs:
218
+        try:
219
+            mdl = ModelInfo.objects.get(brand_id=log.brand_id)
220
+        except ModelInfo.DoesNotExist:
221
+            continue
222
+        ymd = tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d')
223
+        # 日型号销量统计
224
+        mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(
225
+            brand_id=mdl.brand_id,
226
+            model_name=mdl.model_uni_name,
227
+            ymd=ymd,
228
+        )
229
+        mssi.num += 1
230
+        mssi.save()
231
+        # 月型号销量统计
232
+        mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(
233
+            brand_id=mdl.brand_id,
234
+            model_name=mdl.model_uni_name,
235
+            ymd=ymd[:6],
236
+        )
237
+        mssi.num += 1
238
+        mssi.save()
239
+        # 年型号销量统计
240
+        mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(
241
+            brand_id=mdl.brand_id,
242
+            model_name=mdl.model_uni_name,
243
+            ymd=ymd[:4],
244
+        )
245
+        mssi.num += 1
246
+        mssi.save()

+ 1 - 1
statistic/models.py

@@ -187,7 +187,7 @@ class ConsumeSaleStatisticInfo(BaseModelMixin):
187 187
 class ConsumeModelSaleStatisticInfo(BaseModelMixin):
188 188
     brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
189 189
     model_id = models.CharField(_(u'model_id'), max_length=32, help_text=u'型号唯一标识', db_index=True)
190
-    model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称')
190
+    model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称', db_index=True)
191 191
     ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True)  # 例:20171208, tc.local_string(format='%Y%m%d'), 0 为全部
192 192
     num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')
193 193
 

+ 1 - 2
statistic/views.py

@@ -164,10 +164,9 @@ def __tj_generate(ymd=None):
164 164
 
165 165
             cmssi, created = ConsumeModelSaleStatisticInfo.objects.get_or_create(
166 166
                 brand_id=brand.brand_id,
167
-                model_id=mdl.model_id,
167
+                model_name=mdl.model_uni_name,
168 168
                 ymd=ymd,
169 169
             )
170
-            cmssi.model_name = mdl.model_name
171 170
             cmssi.save()
172 171
 
173 172
         distributors = DistributorInfo.objects.filter(brand_id=brand.brand_id, status=True)