会员活动分享:增加是否下线和结束校验,并且给用户加积分。

FFIB 4 lat temu
rodzic
commit
10b28acac4
1 zmienionych plików z 20 dodań i 3 usunięć
  1. 20 3
      api/member_views.py

+ 20 - 3
api/member_views.py

@@ -464,14 +464,28 @@ def activity_group_share(request):
464 464
 
465 465
     if not open_gid:
466 466
         return response()
467
+    
468
+    try:
469
+        user = UserInfo.objects.get(user_id=click_user_id, status=True)
470
+    except:
471
+        return response(UserStatusCode.USER_NOT_FOUND)
467 472
 
468 473
     try:
469 474
         act = MemberActivityInfo.objects.select_for_update().get(activity_id=activity_id, status=True)
470 475
     except MemberActivityInfo.DoesNotExist:
471 476
         return response(MemberActivityStatusCode.ACTIVITY_NOT_FOUND)
477
+    
478
+    isOffline = act.activity_state != 0 or act.final_state == '已结束'
472 479
 
473 480
     # 判断是否给积分 & 给多少积分
474
-    is_integral, integral = get_group_share_info_integral(act.activity_id, share_user_id, open_gid, act.group_share_integral, act.group_share_max_integral)
481
+    if isOffline:
482
+        is_integral = False
483
+        integral = 0
484
+    else:
485
+        is_integral, integral = get_group_share_info_integral(act.activity_id, share_user_id, open_gid, act.group_share_integral, act.group_share_max_integral)
486
+        user.integral += integral
487
+        user.save()
488
+        
475 489
 
476 490
     MemberActivityGroupShareInfo.objects.create(**{
477 491
         'brand_id': act.brand_id,
@@ -481,8 +495,11 @@ def activity_group_share(request):
481 495
         'open_gid': open_gid,
482 496
         'activity_id': activity_id,
483 497
         'title': act.title,
484
-        'is_integral': is_integral,
485
-        'integral': integral,
498
+        'is_integral': False if isOffline else is_integral,
499
+        'integral': False if isOffline else is_integral,
486 500
     })
487 501
 
502
+    if isOffline:
503
+        return response(400002, 'Activity has been offline', '会员活动已下线')
504
+
488 505
     return response()