@@ -14,11 +14,9 @@ from TimeConvert import TimeConvert as tc  | 
            ||
| 14 | 14 | 
                from account.models import UserInfo  | 
            
| 15 | 15 | 
                from mch.models import (AdministratorInfo, BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, LatestAppInfo,  | 
            
| 16 | 16 | 
                LatestAppScreenInfo, ModelInfo, OperatorInfo)  | 
            
| 17 | 
                -from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo,  | 
            |
| 18 | 
                - ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo)  | 
            |
| 17 | 
                +from statistic.models import ConsumeModelSaleStatisticInfo, ConsumeSaleStatisticInfo, ConsumeUserStatisticInfo  | 
            |
| 19 | 18 | 
                from utils.error.errno_utils import (AdministratorStatusCode, OperatorStatusCode, ProductBrandStatusCode,  | 
            
| 20 | 
                - ProductDistributorStatusCode, ProductModelStatusCode, SaleclerkStatusCode,  | 
            |
| 21 | 
                - UserStatusCode)  | 
            |
| 19 | 
                + ProductModelStatusCode, UserStatusCode)  | 
            |
| 22 | 20 | 
                from utils.redis.connect import r  | 
            
| 23 | 21 | 
                from utils.redis.rkeys import MINI_PROGRAM_GIS_LIST  | 
            
| 24 | 22 | 
                 | 
            
                @@ -266,6 +264,16 @@ def consumer_info_api(request):  | 
            ||
| 266 | 264 | 
                # except ValueError:  | 
            
| 267 | 265 | 
                # return response(ProductDistributorStatusCode.DISTRIBUTOR_NOT_FOUND)  | 
            
| 268 | 266 | 
                 | 
            
| 267 | 
                + dupload = ConsumeInfoSubmitLogInfo.objects.filter(  | 
            |
| 268 | 
                + brand_id=brand.brand_id,  | 
            |
| 269 | 
                + model_id=model.model_id,  | 
            |
| 270 | 
                + # distributor_id=distributor.distributor_id,  | 
            |
| 271 | 
                + distributor_id='',  | 
            |
| 272 | 
                + serialNo=serialNo,  | 
            |
| 273 | 
                + verifyResult=1,  | 
            |
| 274 | 
                + test_user=False,  | 
            |
| 275 | 
                + ).exists()  | 
            |
| 276 | 
                +  | 
            |
| 269 | 277 | 
                # 记录用户信息提交记录  | 
            
| 270 | 278 | 
                log = ConsumeInfoSubmitLogInfo.objects.create(  | 
            
| 271 | 279 | 
                user_id=user_id,  | 
            
                @@ -284,122 +292,89 @@ def consumer_info_api(request):  | 
            ||
| 284 | 292 | 
                distributor_name='',  | 
            
| 285 | 293 | 
                serialNo=serialNo,  | 
            
| 286 | 294 | 
                verifyResult=verifyResult,  | 
            
| 295 | 
                + dupload=dupload,  | 
            |
| 287 | 296 | 
                test_user=user.test_user,  | 
            
| 288 | 297 | 
                )  | 
            
| 289 | 298 | 
                 | 
            
| 290 | 
                - if not user.test_user:  | 
            |
| 299 | 
                + if not user.test_user and not dupload:  | 
            |
| 291 | 300 | 
                # TODO: Make statistic async  | 
            
| 292 | 
                - if ConsumeInfoSubmitLogInfo.objects.filter(  | 
            |
| 301 | 
                + ymd = tc.local_string(format='%Y%m%d')  | 
            |
| 302 | 
                +  | 
            |
| 303 | 
                + cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create(  | 
            |
| 304 | 
                + brand_id=brand.brand_id,  | 
            |
| 305 | 
                + ymd=ymd,  | 
            |
| 306 | 
                + )  | 
            |
| 307 | 
                + cusi.users = list(set(cusi.users + [log.user_id]))  | 
            |
| 308 | 
                + cusi.num = len(cusi.users)  | 
            |
| 309 | 
                + cusi.save()  | 
            |
| 310 | 
                + cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create(  | 
            |
| 311 | 
                + brand_id=brand.brand_id,  | 
            |
| 312 | 
                + ymd=ymd[:6],  | 
            |
| 313 | 
                + )  | 
            |
| 314 | 
                + cusi.users = list(set(cusi.users + [log.user_id]))  | 
            |
| 315 | 
                + cusi.num = len(cusi.users)  | 
            |
| 316 | 
                + cusi.save()  | 
            |
| 317 | 
                + cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create(  | 
            |
| 318 | 
                + brand_id=brand.brand_id,  | 
            |
| 319 | 
                + ymd=ymd[:4],  | 
            |
| 320 | 
                + )  | 
            |
| 321 | 
                + cusi.users = list(set(cusi.users + [log.user_id]))  | 
            |
| 322 | 
                + cusi.num = len(cusi.users)  | 
            |
| 323 | 
                + cusi.save()  | 
            |
| 324 | 
                +  | 
            |
| 325 | 
                + # 日销量统计  | 
            |
| 326 | 
                + cssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 327 | 
                + brand_id=brand.brand_id,  | 
            |
| 328 | 
                + ymd=ymd,  | 
            |
| 329 | 
                + )  | 
            |
| 330 | 
                + cssi.num += 1  | 
            |
| 331 | 
                + cssi.save()  | 
            |
| 332 | 
                + # 月销量统计  | 
            |
| 333 | 
                + cssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 334 | 
                + brand_id=brand.brand_id,  | 
            |
| 335 | 
                + ymd=ymd[:6],  | 
            |
| 336 | 
                + )  | 
            |
| 337 | 
                + cssi.num += 1  | 
            |
| 338 | 
                + cssi.save()  | 
            |
| 339 | 
                + # 年销量统计  | 
            |
| 340 | 
                + cssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 341 | 
                + brand_id=brand.brand_id,  | 
            |
| 342 | 
                + ymd=ymd[:4],  | 
            |
| 343 | 
                + )  | 
            |
| 344 | 
                + cssi.num += 1  | 
            |
| 345 | 
                + cssi.save()  | 
            |
| 346 | 
                +  | 
            |
| 347 | 
                + # 日型号销量统计  | 
            |
| 348 | 
                + cmssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 349 | 
                + brand_id=brand.brand_id,  | 
            |
| 350 | 
                + model_name=model.model_uni_name,  | 
            |
| 351 | 
                + ymd=ymd,  | 
            |
| 352 | 
                + )  | 
            |
| 353 | 
                + cmssi.num += 1  | 
            |
| 354 | 
                + cmssi.save()  | 
            |
| 355 | 
                + # 月型号销量统计  | 
            |
| 356 | 
                + cmssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 357 | 
                + brand_id=brand.brand_id,  | 
            |
| 358 | 
                + model_name=model.model_uni_name,  | 
            |
| 359 | 
                + ymd=ymd[:6],  | 
            |
| 360 | 
                + )  | 
            |
| 361 | 
                + cmssi.num += 1  | 
            |
| 362 | 
                + cmssi.save()  | 
            |
| 363 | 
                + # 年型号销量统计  | 
            |
| 364 | 
                + cmssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 293 | 365 | 
                brand_id=brand.brand_id,  | 
            
| 294 | 
                - model_id=model.model_id,  | 
            |
| 295 | 
                - # distributor_id=distributor.distributor_id,  | 
            |
| 296 | 
                - distributor_id='',  | 
            |
| 297 | 
                - serialNo=serialNo,  | 
            |
| 298 | 
                - verifyResult=1,  | 
            |
| 299 | 
                - test_user=False,  | 
            |
| 300 | 
                - ).count() == 1:  | 
            |
| 301 | 
                - ymd = tc.local_string(format='%Y%m%d')  | 
            |
| 302 | 
                -  | 
            |
| 303 | 
                - # 日销量统计  | 
            |
| 304 | 
                - ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 305 | 
                - brand_id=brand.brand_id,  | 
            |
| 306 | 
                - ymd=ymd,  | 
            |
| 307 | 
                - )  | 
            |
| 308 | 
                - ssi.num += 1  | 
            |
| 309 | 
                - ssi.save()  | 
            |
| 310 | 
                - # 月销量统计  | 
            |
| 311 | 
                - ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 312 | 
                - brand_id=brand.brand_id,  | 
            |
| 313 | 
                - ymd=ymd[:6],  | 
            |
| 314 | 
                - )  | 
            |
| 315 | 
                - ssi.num += 1  | 
            |
| 316 | 
                - ssi.save()  | 
            |
| 317 | 
                - # 年销量统计  | 
            |
| 318 | 
                - ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 319 | 
                - brand_id=brand.brand_id,  | 
            |
| 320 | 
                - ymd=ymd[:4],  | 
            |
| 321 | 
                - )  | 
            |
| 322 | 
                - ssi.num += 1  | 
            |
| 323 | 
                - ssi.save()  | 
            |
| 324 | 
                -  | 
            |
| 325 | 
                - # 日型号销量统计  | 
            |
| 326 | 
                - mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 327 | 
                - brand_id=brand.brand_id,  | 
            |
| 328 | 
                - model_name=model.model_uni_name,  | 
            |
| 329 | 
                - ymd=ymd,  | 
            |
| 330 | 
                - )  | 
            |
| 331 | 
                - mssi.num += 1  | 
            |
| 332 | 
                - mssi.save()  | 
            |
| 333 | 
                - # 月型号销量统计  | 
            |
| 334 | 
                - mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 335 | 
                - brand_id=brand.brand_id,  | 
            |
| 336 | 
                - model_name=model.model_uni_name,  | 
            |
| 337 | 
                - ymd=ymd[:6],  | 
            |
| 338 | 
                - )  | 
            |
| 339 | 
                - mssi.num += 1  | 
            |
| 340 | 
                - mssi.save()  | 
            |
| 341 | 
                - # 年型号销量统计  | 
            |
| 342 | 
                - mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 343 | 
                - brand_id=brand.brand_id,  | 
            |
| 344 | 
                - model_name=model.model_uni_name,  | 
            |
| 345 | 
                - ymd=ymd[:4],  | 
            |
| 346 | 
                - )  | 
            |
| 347 | 
                - mssi.num += 1  | 
            |
| 348 | 
                - mssi.save()  | 
            |
| 349 | 
                -  | 
            |
| 350 | 
                -            r.rpushjson(MINI_PROGRAM_GIS_LIST, {
               | 
            |
| 351 | 
                - 'brand_id': log.brand_id,  | 
            |
| 352 | 
                - 'lat': log.lat,  | 
            |
| 353 | 
                - 'lon': log.lon,  | 
            |
| 354 | 
                - 'ymd': ymd,  | 
            |
| 355 | 
                - })  | 
            |
| 356 | 
                -  | 
            |
| 357 | 
                - # mssi2, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 358 | 
                - # brand_id=brand.brand_id,  | 
            |
| 359 | 
                - # model_id=model.model_id,  | 
            |
| 360 | 
                - # ymd=0,  | 
            |
| 361 | 
                - # )  | 
            |
| 362 | 
                - # mssi2.model_name = model.model_name  | 
            |
| 363 | 
                - # mssi2.num += 1  | 
            |
| 364 | 
                - # mssi2.save()  | 
            |
| 365 | 
                -  | 
            |
| 366 | 
                - # # 经销商销量统计  | 
            |
| 367 | 
                - # dssi, _ = ConsumeDistributorSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 368 | 
                - # brand_id=brand.brand_id,  | 
            |
| 369 | 
                - # distributor_id=distributor.distributor_id,  | 
            |
| 370 | 
                - # ymd=ymd,  | 
            |
| 371 | 
                - # )  | 
            |
| 372 | 
                - # dssi.distributor_name = distributor.distributor_name  | 
            |
| 373 | 
                - # dssi.num += 1  | 
            |
| 374 | 
                - # dssi.save()  | 
            |
| 375 | 
                - #  | 
            |
| 376 | 
                - # dssi2, _ = ConsumeDistributorSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 377 | 
                - # brand_id=brand.brand_id,  | 
            |
| 378 | 
                - # distributor_id=distributor.distributor_id,  | 
            |
| 379 | 
                - # ymd=0,  | 
            |
| 380 | 
                - # )  | 
            |
| 381 | 
                - # dssi2.distributor_name = distributor.distributor_name  | 
            |
| 382 | 
                - # dssi2.num += 1  | 
            |
| 383 | 
                - # dssi2.save()  | 
            |
| 384 | 
                - #  | 
            |
| 385 | 
                - # # 省份销量统计  | 
            |
| 386 | 
                - # pssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 387 | 
                - # brand_id=brand.brand_id,  | 
            |
| 388 | 
                - # province_code=distributor.distributor_province_code,  | 
            |
| 389 | 
                - # ymd=ymd,  | 
            |
| 390 | 
                - # )  | 
            |
| 391 | 
                - # pssi.province_name = distributor.distributor_province_name  | 
            |
| 392 | 
                - # pssi.num += 1  | 
            |
| 393 | 
                - # pssi.save()  | 
            |
| 394 | 
                - #  | 
            |
| 395 | 
                - # pssi2, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create(  | 
            |
| 396 | 
                - # brand_id=brand.brand_id,  | 
            |
| 397 | 
                - # province_code=distributor.distributor_province_code,  | 
            |
| 398 | 
                - # ymd=0,  | 
            |
| 399 | 
                - # )  | 
            |
| 400 | 
                - # pssi2.province_name = distributor.distributor_province_name  | 
            |
| 401 | 
                - # pssi2.num += 1  | 
            |
| 402 | 
                - # pssi2.save()  | 
            |
| 366 | 
                + model_name=model.model_uni_name,  | 
            |
| 367 | 
                + ymd=ymd[:4],  | 
            |
| 368 | 
                + )  | 
            |
| 369 | 
                + cmssi.num += 1  | 
            |
| 370 | 
                + cmssi.save()  | 
            |
| 371 | 
                +  | 
            |
| 372 | 
                +        r.rpushjson(MINI_PROGRAM_GIS_LIST, {
               | 
            |
| 373 | 
                + 'brand_id': log.brand_id,  | 
            |
| 374 | 
                + 'lat': log.lat,  | 
            |
| 375 | 
                + 'lon': log.lon,  | 
            |
| 376 | 
                + 'ymd': ymd,  | 
            |
| 377 | 
                + })  | 
            |
| 403 | 378 | 
                 | 
            
| 404 | 379 | 
                return response(200, 'Submit Consumer Info Success', u'提交消费者信息成功')  | 
            
| 405 | 380 | 
                 | 
            
                @@ -416,9 +391,10 @@ def consumer_snlist_api(request):  | 
            ||
| 416 | 391 | 
                return response(UserStatusCode.USER_NOT_FOUND)  | 
            
| 417 | 392 | 
                 | 
            
| 418 | 393 | 
                # 用户信息提交列表  | 
            
| 419 | 
                - # TODO: 按照序列号去重  | 
            |
| 420 | 
                - logs = ConsumeInfoSubmitLogInfo.objects.filter(user_id=user_id, status=True)  | 
            |
| 421 | 
                - logs = [log.data for log in logs]  | 
            |
| 394 | 
                + logs = ConsumeInfoSubmitLogInfo.objects.filter(user_id=user_id, status=True).distinct()  | 
            |
| 395 | 
                + seen = set()  | 
            |
| 396 | 
                + seen_add = seen.add  | 
            |
| 397 | 
                + logs = [log.data for log in logs if not (log.serialNo in seen or seen_add(log.serialNo))]  | 
            |
| 422 | 398 | 
                 | 
            
| 423 | 399 | 
                     return response(200, 'Get Consumer Submit List Success', u'获取消费者提交列表成功', {
               | 
            
| 424 | 400 | 
                'logs': logs,  | 
            
                @@ -473,6 +473,8 @@ class ConsumeInfoSubmitLogInfo(BaseModelMixin):  | 
            ||
| 473 | 473 | 
                 | 
            
| 474 | 474 | 
                verifyResult = models.IntegerField(_(u'verifyResult'), default=0, help_text=u'验证结果', db_index=True)  | 
            
| 475 | 475 | 
                 | 
            
| 476 | 
                + dupload = models.BooleanField(_(u'dupload'), default=False, help_text=_(u'是否为重复提交'), db_index=True)  | 
            |
| 477 | 
                +  | 
            |
| 476 | 478 | 
                test_user = models.BooleanField(_(u'test_user'), default=False, help_text=_(u'是否为测试用户'), db_index=True)  | 
            
| 477 | 479 | 
                 | 
            
| 478 | 480 | 
                class Meta:  | 
            
                @@ -9,8 +9,9 @@ from TimeConvert import TimeConvert as tc  | 
            ||
| 9 | 9 | 
                 | 
            
| 10 | 10 | 
                from mch.models import BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, ModelInfo  | 
            
| 11 | 11 | 
                from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo,  | 
            
| 12 | 
                - ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, DistributorSaleStatisticInfo,  | 
            |
| 13 | 
                - ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, SaleStatisticInfo)  | 
            |
| 12 | 
                + ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, ConsumeUserStatisticInfo,  | 
            |
| 13 | 
                + DistributorSaleStatisticInfo, ModelSaleStatisticInfo, ProvinceSaleStatisticInfo,  | 
            |
| 14 | 
                + SaleStatisticInfo)  | 
            |
| 14 | 15 | 
                from utils.redis.connect import r  | 
            
| 15 | 16 | 
                from utils.redis.rkeys import MINI_PROGRAM_GIS_LIST  | 
            
| 16 | 17 | 
                 | 
            
                @@ -201,48 +202,91 @@ def fill_ym():  | 
            ||
| 201 | 202 | 
                ssi.save()  | 
            
| 202 | 203 | 
                 | 
            
| 203 | 204 | 
                 | 
            
| 204 | 
                -def refreshp():  | 
            |
| 205 | 
                +def refreshs():  | 
            |
| 206 | 
                + ConsumeUserStatisticInfo.objects.all().delete()  | 
            |
| 207 | 
                + ConsumeSaleStatisticInfo.objects.all().delete()  | 
            |
| 205 | 208 | 
                ConsumeProvinceSaleStatisticInfo.objects.all().delete()  | 
            
| 206 | 
                - logs = ConsumeInfoSubmitLogInfo.objects.filter(test_user=False)  | 
            |
| 207 | 
                - for log in logs:  | 
            |
| 208 | 
                -        r.rpushjson(MINI_PROGRAM_GIS_LIST, {
               | 
            |
| 209 | 
                - 'brand_id': log.brand_id,  | 
            |
| 210 | 
                - 'lat': log.lat,  | 
            |
| 211 | 
                - 'lon': log.lon,  | 
            |
| 212 | 
                - 'ymd': tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d'),  | 
            |
| 213 | 
                - })  | 
            |
| 209 | 
                + ConsumeModelSaleStatisticInfo.objects.all().delete()  | 
            |
| 214 | 210 | 
                 | 
            
| 211 | 
                + logs = ConsumeInfoSubmitLogInfo.objects.filter(verifyResult=1, dupload=False, test_user=False)  | 
            |
| 215 | 212 | 
                 | 
            
| 216 | 
                -def refreshm():  | 
            |
| 217 | 
                - ConsumeModelSaleStatisticInfo.objects.all().delete()  | 
            |
| 218 | 
                - logs = ConsumeInfoSubmitLogInfo.objects.filter(test_user=False)  | 
            |
| 219 | 213 | 
                for log in logs:  | 
            
| 214 | 
                + ymd = tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d')  | 
            |
| 215 | 
                +  | 
            |
| 220 | 216 | 
                try:  | 
            
| 221 | 217 | 
                mdl = ModelInfo.objects.get(model_id=log.model_id)  | 
            
| 222 | 218 | 
                except ModelInfo.DoesNotExist:  | 
            
| 223 | 219 | 
                continue  | 
            
| 224 | 
                - ymd = tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d')  | 
            |
| 220 | 
                +  | 
            |
| 221 | 
                + cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create(  | 
            |
| 222 | 
                + brand_id=mdl.brand_id,  | 
            |
| 223 | 
                + ymd=ymd,  | 
            |
| 224 | 
                + )  | 
            |
| 225 | 
                + cusi.users = list(set(cusi.users + [log.user_id]))  | 
            |
| 226 | 
                + cusi.num = len(cusi.users)  | 
            |
| 227 | 
                + cusi.save()  | 
            |
| 228 | 
                + cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create(  | 
            |
| 229 | 
                + brand_id=mdl.brand_id,  | 
            |
| 230 | 
                + ymd=ymd[:6],  | 
            |
| 231 | 
                + )  | 
            |
| 232 | 
                + cusi.users = list(set(cusi.users + [log.user_id]))  | 
            |
| 233 | 
                + cusi.num = len(cusi.users)  | 
            |
| 234 | 
                + cusi.save()  | 
            |
| 235 | 
                + cusi, _ = ConsumeUserStatisticInfo.objects.get_or_create(  | 
            |
| 236 | 
                + brand_id=mdl.brand_id,  | 
            |
| 237 | 
                + ymd=ymd[:4],  | 
            |
| 238 | 
                + )  | 
            |
| 239 | 
                + cusi.users = list(set(cusi.users + [log.user_id]))  | 
            |
| 240 | 
                + cusi.num = len(cusi.users)  | 
            |
| 241 | 
                + cusi.save()  | 
            |
| 242 | 
                +  | 
            |
| 243 | 
                + cssi, _ = ConsumeSaleStatisticInfo.objects.get_or_create(  | 
            |
| 244 | 
                + brand_id=mdl.brand_id,  | 
            |
| 245 | 
                + ymd=ymd,  | 
            |
| 246 | 
                + )  | 
            |
| 247 | 
                + cssi.num += 1  | 
            |
| 248 | 
                + cssi.save()  | 
            |
| 249 | 
                + cssi, _ = ConsumeSaleStatisticInfo.objects.get_or_create(  | 
            |
| 250 | 
                + brand_id=mdl.brand_id,  | 
            |
| 251 | 
                + ymd=ymd[:6],  | 
            |
| 252 | 
                + )  | 
            |
| 253 | 
                + cssi.num += 1  | 
            |
| 254 | 
                + cssi.save()  | 
            |
| 255 | 
                + cssi, _ = ConsumeSaleStatisticInfo.objects.get_or_create(  | 
            |
| 256 | 
                + brand_id=mdl.brand_id,  | 
            |
| 257 | 
                + ymd=ymd[:4],  | 
            |
| 258 | 
                + )  | 
            |
| 259 | 
                + cssi.num += 1  | 
            |
| 260 | 
                + cssi.save()  | 
            |
| 261 | 
                +  | 
            |
| 225 | 262 | 
                # 日型号销量统计  | 
            
| 226 | 
                - mssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create(  | 
            |
| 263 | 
                + cmssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create(  | 
            |
| 227 | 264 | 
                brand_id=mdl.brand_id,  | 
            
| 228 | 265 | 
                model_name=mdl.model_uni_name,  | 
            
| 229 | 266 | 
                ymd=ymd,  | 
            
| 230 | 267 | 
                )  | 
            
| 231 | 
                - mssi.num += 1  | 
            |
| 232 | 
                - mssi.save()  | 
            |
| 268 | 
                + cmssi.num += 1  | 
            |
| 269 | 
                + cmssi.save()  | 
            |
| 233 | 270 | 
                # 月型号销量统计  | 
            
| 234 | 
                - mssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create(  | 
            |
| 271 | 
                + cmssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create(  | 
            |
| 235 | 272 | 
                brand_id=mdl.brand_id,  | 
            
| 236 | 273 | 
                model_name=mdl.model_uni_name,  | 
            
| 237 | 274 | 
                ymd=ymd[:6],  | 
            
| 238 | 275 | 
                )  | 
            
| 239 | 
                - mssi.num += 1  | 
            |
| 240 | 
                - mssi.save()  | 
            |
| 276 | 
                + cmssi.num += 1  | 
            |
| 277 | 
                + cmssi.save()  | 
            |
| 241 | 278 | 
                # 年型号销量统计  | 
            
| 242 | 
                - mssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create(  | 
            |
| 279 | 
                + cmssi, _ = ConsumeModelSaleStatisticInfo.objects.get_or_create(  | 
            |
| 243 | 280 | 
                brand_id=mdl.brand_id,  | 
            
| 244 | 281 | 
                model_name=mdl.model_uni_name,  | 
            
| 245 | 282 | 
                ymd=ymd[:4],  | 
            
| 246 | 283 | 
                )  | 
            
| 247 | 
                - mssi.num += 1  | 
            |
| 248 | 
                - mssi.save()  | 
            |
| 284 | 
                + cmssi.num += 1  | 
            |
| 285 | 
                + cmssi.save()  | 
            |
| 286 | 
                +  | 
            |
| 287 | 
                +        r.rpushjson(MINI_PROGRAM_GIS_LIST, {
               | 
            |
| 288 | 
                + 'brand_id': log.brand_id,  | 
            |
| 289 | 
                + 'lat': log.lat,  | 
            |
| 290 | 
                + 'lon': log.lon,  | 
            |
| 291 | 
                + 'ymd': tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d'),  | 
            |
| 292 | 
                + })  | 
            
                @@ -4,9 +4,9 @@ from django.contrib import admin  | 
            ||
| 4 | 4 | 
                from django_admin import ReadOnlyModelAdmin  | 
            
| 5 | 5 | 
                 | 
            
| 6 | 6 | 
                from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo,  | 
            
| 7 | 
                - ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, DistributorSaleStatisticInfo,  | 
            |
| 8 | 
                - ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, RegisterStatisticInfo,  | 
            |
| 9 | 
                - SaleclerkSaleStatisticInfo, SaleStatisticInfo)  | 
            |
| 7 | 
                + ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, ConsumeUserStatisticInfo,  | 
            |
| 8 | 
                + DistributorSaleStatisticInfo, ModelSaleStatisticInfo, ProvinceSaleStatisticInfo,  | 
            |
| 9 | 
                + RegisterStatisticInfo, SaleclerkSaleStatisticInfo, SaleStatisticInfo)  | 
            |
| 10 | 10 | 
                 | 
            
| 11 | 11 | 
                 | 
            
| 12 | 12 | 
                class RegisterStatisticInfoAdmin(admin.ModelAdmin):  | 
            
                @@ -45,6 +45,12 @@ class SaleclerkSaleStatisticInfoAdmin(admin.ModelAdmin):  | 
            ||
| 45 | 45 | 
                     search_fields = ('brand_id', 'distributor_id', 'distributor_name', 'distributor_short_name', 'clerk_id', 'clerk_name', 'ymd')
               | 
            
| 46 | 46 | 
                 | 
            
| 47 | 47 | 
                 | 
            
| 48 | 
                +class ConsumeUserStatisticInfoAdmin(admin.ModelAdmin):  | 
            |
| 49 | 
                +    list_display = ('brand_id', 'ymd', 'users', 'num', 'status', 'created_at', 'updated_at')
               | 
            |
| 50 | 
                +    list_filter = ('brand_id', 'status')
               | 
            |
| 51 | 
                +    search_fields = ('brand_id', 'ymd')
               | 
            |
| 52 | 
                +  | 
            |
| 53 | 
                +  | 
            |
| 48 | 54 | 
                class ConsumeSaleStatisticInfoAdmin(admin.ModelAdmin):  | 
            
| 49 | 55 | 
                     list_display = ('brand_id', 'ymd', 'num', 'status', 'created_at', 'updated_at')
               | 
            
| 50 | 56 | 
                     list_filter = ('brand_id', 'status')
               | 
            
                @@ -77,6 +83,7 @@ admin.site.register(DistributorSaleStatisticInfo, DistributorSaleStatisticInfoAd  | 
            ||
| 77 | 83 | 
                admin.site.register(ProvinceSaleStatisticInfo, ProvinceSaleStatisticInfoAdmin)  | 
            
| 78 | 84 | 
                admin.site.register(SaleclerkSaleStatisticInfo, SaleclerkSaleStatisticInfoAdmin)  | 
            
| 79 | 85 | 
                 | 
            
| 86 | 
                +admin.site.register(ConsumeUserStatisticInfo, ConsumeUserStatisticInfoAdmin)  | 
            |
| 80 | 87 | 
                admin.site.register(ConsumeSaleStatisticInfo, ConsumeSaleStatisticInfoAdmin)  | 
            
| 81 | 88 | 
                admin.site.register(ConsumeModelSaleStatisticInfo, ConsumeModelSaleStatisticInfoAdmin)  | 
            
| 82 | 89 | 
                admin.site.register(ConsumeDistributorSaleStatisticInfo, ConsumeDistributorSaleStatisticInfoAdmin)  | 
            
                @@ -4,6 +4,7 @@ from django.conf import settings  | 
            ||
| 4 | 4 | 
                from django.db import models  | 
            
| 5 | 5 | 
                from django.utils.translation import ugettext_lazy as _  | 
            
| 6 | 6 | 
                from django_models_ext import BaseModelMixin  | 
            
| 7 | 
                +from jsonfield import JSONField  | 
            |
| 7 | 8 | 
                 | 
            
| 8 | 9 | 
                from utils.rdm_utils import randnum  | 
            
| 9 | 10 | 
                 | 
            
                @@ -165,6 +166,27 @@ class SaleclerkSaleStatisticInfo(BaseModelMixin):  | 
            ||
| 165 | 166 | 
                # 消费者维度  | 
            
| 166 | 167 | 
                 | 
            
| 167 | 168 | 
                 | 
            
| 169 | 
                +class ConsumeUserStatisticInfo(BaseModelMixin):  | 
            |
| 170 | 
                + brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)  | 
            |
| 171 | 
                + ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d')  | 
            |
| 172 | 
                + users = JSONField(_(u'users'), default=[], help_text=u'用户列表')  | 
            |
| 173 | 
                + num = models.IntegerField(_(u'num'), default=0, help_text=u'数量')  | 
            |
| 174 | 
                +  | 
            |
| 175 | 
                + class Meta:  | 
            |
| 176 | 
                + verbose_name = _(u'[消费者维度]销量统计')  | 
            |
| 177 | 
                + verbose_name_plural = _(u'[消费者维度]销量统计')  | 
            |
| 178 | 
                +  | 
            |
| 179 | 
                + def __unicode__(self):  | 
            |
| 180 | 
                + return unicode(self.pk)  | 
            |
| 181 | 
                +  | 
            |
| 182 | 
                + @property  | 
            |
| 183 | 
                + def data(self):  | 
            |
| 184 | 
                +        return {
               | 
            |
| 185 | 
                + 'ymd': self.ymd,  | 
            |
| 186 | 
                + 'num': randnum() if settings.DEBUG_STATISTIC_DATA_FLAG else self.num,  | 
            |
| 187 | 
                + }  | 
            |
| 188 | 
                +  | 
            |
| 189 | 
                +  | 
            |
| 168 | 190 | 
                class ConsumeSaleStatisticInfo(BaseModelMixin):  | 
            
| 169 | 191 | 
                brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)  | 
            
| 170 | 192 | 
                ymd = models.IntegerField(_(u'ymd'), default=0, help_text=u'年月日', db_index=True) # 例:20171208, tc.local_string(format='%Y%m%d')  | 
            
                @@ -9,9 +9,9 @@ from TimeConvert import TimeConvert as tc  | 
            ||
| 9 | 9 | 
                 | 
            
| 10 | 10 | 
                from mch.models import BrandInfo, DistributorInfo, ModelInfo  | 
            
| 11 | 11 | 
                from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo,  | 
            
| 12 | 
                - ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, DistributorSaleStatisticInfo,  | 
            |
| 13 | 
                - ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, RegisterStatisticInfo,  | 
            |
| 14 | 
                - SaleclerkSaleStatisticInfo, SaleStatisticInfo)  | 
            |
| 12 | 
                + ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, ConsumeUserStatisticInfo,  | 
            |
| 13 | 
                + DistributorSaleStatisticInfo, ModelSaleStatisticInfo, ProvinceSaleStatisticInfo,  | 
            |
| 14 | 
                + RegisterStatisticInfo, SaleclerkSaleStatisticInfo, SaleStatisticInfo)  | 
            |
| 15 | 15 | 
                from utils.rdm_utils import randnum  | 
            
| 16 | 16 | 
                 | 
            
| 17 | 17 | 
                 | 
            
                @@ -206,15 +206,29 @@ def __tj_generate(ymd=None):  | 
            ||
| 206 | 206 | 
                def ymdtj(brand_id, ymd, lastymd):  | 
            
| 207 | 207 | 
                # [消费者维度] 周期内扫描用户人数  | 
            
| 208 | 208 | 
                try:  | 
            
| 209 | 
                - scan_user_count = ConsumeSaleStatisticInfo.objects.get(brand_id=brand_id, ymd=ymd).num  | 
            |
| 210 | 
                - except ConsumeSaleStatisticInfo.DoesNotExist:  | 
            |
| 209 | 
                + scan_user_count = ConsumeUserStatisticInfo.objects.get(brand_id=brand_id, ymd=ymd).num  | 
            |
| 210 | 
                + except ConsumeUserStatisticInfo.DoesNotExist:  | 
            |
| 211 | 211 | 
                scan_user_count = 0  | 
            
| 212 | 212 | 
                 | 
            
| 213 | 213 | 
                try:  | 
            
| 214 | 
                - last_scan_user_count = ConsumeSaleStatisticInfo.objects.get(brand_id=brand_id, ymd=lastymd).num  | 
            |
| 215 | 
                - except ConsumeSaleStatisticInfo.DoesNotExist:  | 
            |
| 214 | 
                + last_scan_user_count = ConsumeUserStatisticInfo.objects.get(brand_id=brand_id, ymd=lastymd).num  | 
            |
| 215 | 
                + except ConsumeUserStatisticInfo.DoesNotExist:  | 
            |
| 216 | 216 | 
                last_scan_user_count = 0  | 
            
| 217 | 217 | 
                 | 
            
| 218 | 
                + # [消费者维度] 周期内镜头销售支数  | 
            |
| 219 | 
                + try:  | 
            |
| 220 | 
                + sell_volume_count = ConsumeSaleStatisticInfo.objects.get(brand_id=brand_id, ymd=ymd).num  | 
            |
| 221 | 
                + except ConsumeSaleStatisticInfo.DoesNotExist:  | 
            |
| 222 | 
                + sell_volume_count = 0  | 
            |
| 223 | 
                +  | 
            |
| 224 | 
                + try:  | 
            |
| 225 | 
                + last_sell_volume_count = ConsumeSaleStatisticInfo.objects.get(brand_id=brand_id, ymd=lastymd).num  | 
            |
| 226 | 
                + except ConsumeSaleStatisticInfo.DoesNotExist:  | 
            |
| 227 | 
                + last_sell_volume_count = 0  | 
            |
| 228 | 
                +  | 
            |
| 229 | 
                + # 与上个统计周期数据的销售支数比例  | 
            |
| 230 | 
                + volume_count_increase_pct = '%.2f' % (sell_volume_count * 100.0 / last_sell_volume_count) if last_sell_volume_count != 0 else -1  | 
            |
| 231 | 
                +  | 
            |
| 218 | 232 | 
                # 与上个统计周期数据的用户人数比例  | 
            
| 219 | 233 | 
                user_count_increase_pct = '%.2f' % (scan_user_count * 100.0 / last_scan_user_count) if last_scan_user_count != 0 else -1  | 
            
| 220 | 234 | 
                 | 
            
                @@ -222,15 +236,6 @@ def ymdtj(brand_id, ymd, lastymd):  | 
            ||
| 222 | 236 | 
                     current_models = ConsumeModelSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=ymd, status=True).order_by('-num')
               | 
            
| 223 | 237 | 
                models = [m.data for m in current_models[:20]]  | 
            
| 224 | 238 | 
                 | 
            
| 225 | 
                - # [消费者维度] 周期内镜头销售支数  | 
            |
| 226 | 
                - sell_volume_count = sum([m.num for m in current_models])  | 
            |
| 227 | 
                -  | 
            |
| 228 | 
                -    last_models = ConsumeModelSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=lastymd, status=True).order_by('-num')
               | 
            |
| 229 | 
                - last_sell_volume_count = sum([m.num for m in last_models])  | 
            |
| 230 | 
                -  | 
            |
| 231 | 
                - # 与上个统计周期数据的销售支数比例  | 
            |
| 232 | 
                - volume_count_increase_pct = '%.2f' % (sell_volume_count * 100.0 / last_sell_volume_count) if last_sell_volume_count != 0 else -1  | 
            |
| 233 | 
                -  | 
            |
| 234 | 239 | 
                # [经销商维度] 统计周期内销售员排行数据,请按顺序返回  | 
            
| 235 | 240 | 
                     salesmen = SaleclerkSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=ymd, status=True).order_by('-num')[:20]
               | 
            
| 236 | 241 | 
                salesmen = [s.data for s in salesmen]  |