@@ -0,0 +1,19 @@ |
||
1 |
+# -*- coding: utf-8 -*- |
|
2 |
+# Generated by Django 3.2.16 on 2022-10-27 10:38 |
|
3 |
+ |
|
4 |
+from django.db import migrations, models |
|
5 |
+ |
|
6 |
+ |
|
7 |
+class Migration(migrations.Migration): |
|
8 |
+ |
|
9 |
+ dependencies = [ |
|
10 |
+ ('account', '0055_userintegralincomeexpensesinfo_final_integral'), |
|
11 |
+ ] |
|
12 |
+ |
|
13 |
+ operations = [ |
|
14 |
+ migrations.AlterField( |
|
15 |
+ model_name='userintegralincomeexpensesinfo', |
|
16 |
+ name='integral_from', |
|
17 |
+ field=models.IntegerField(choices=[(0, '产品'), (1, '分享'), (2, '投稿'), (99, '会员活动投稿福利')], default=0, help_text='积分来源', verbose_name='integral_from'), |
|
18 |
+ ), |
|
19 |
+ ] |
@@ -331,11 +331,13 @@ class UserIntegralIncomeExpensesInfo(BaseModelMixin): |
||
331 | 331 |
PRODUCT = 0 |
332 | 332 |
SHARE = 1 |
333 | 333 |
CONTRIBUTE = 2 |
334 |
+ MEMBER_ACTIVITY_CONTRIBUTION_WELFARE = 99 |
|
334 | 335 |
|
335 | 336 |
INTEGRAL_FROM = ( |
336 | 337 |
(PRODUCT, u'产品'), |
337 | 338 |
(SHARE, u'分享'), |
338 | 339 |
(CONTRIBUTE, u'投稿'), |
340 |
+ (MEMBER_ACTIVITY_CONTRIBUTION_WELFARE, u'会员活动投稿福利'), |
|
339 | 341 |
) |
340 | 342 |
|
341 | 343 |
user_id = models.CharField(_(u'user_id'), max_length=32, blank=True, null=True, help_text=u'用户唯一标识', db_index=True) |
@@ -13,7 +13,7 @@ from pywe_miniapp import get_shareinfo |
||
13 | 13 |
from pywe_storage import RedisStorage |
14 | 14 |
from TimeConvert import TimeConvert as tc |
15 | 15 |
|
16 |
-from account.models import UserInfo |
|
16 |
+from account.models import UserInfo, UserIntegralIncomeExpensesInfo |
|
17 | 17 |
from coupon.models import UserCouponInfo |
18 | 18 |
from member.models import (GoodsInfo, GoodsOrderInfo, MemberActivityContributionInfo, |
19 | 19 |
MemberActivityContributionWelfareUnlockingInfo, MemberActivityGroupShareInfo, |
@@ -501,7 +501,7 @@ def activity_group_share(request): |
||
501 | 501 |
return response() |
502 | 502 |
|
503 | 503 |
try: |
504 |
- user = UserInfo.objects.get(user_id=share_user_id, status=True) |
|
504 |
+ user = UserInfo.objects.select_for_update().get(user_id=share_user_id, status=True) |
|
505 | 505 |
except UserInfo.DoesNotExist: |
506 | 506 |
return response(UserStatusCode.USER_NOT_FOUND) |
507 | 507 |
|
@@ -753,5 +753,21 @@ def activity_contribute_welfare_unlocking_handled(request): |
||
753 | 753 |
unlocking.save() |
754 | 754 |
|
755 | 755 |
# TODO: 积分相关逻辑在这里处理? |
756 |
+ try: |
|
757 |
+ user = UserInfo.objects.select_for_update().get(user_id=user_id, status=True) |
|
758 |
+ except UserInfo.DoesNotExist: |
|
759 |
+ return response(UserStatusCode.USER_NOT_FOUND) |
|
760 |
+ |
|
761 |
+ user.integral += unlocking.welfare_value |
|
762 |
+ user.save() |
|
763 |
+ |
|
764 |
+ UserIntegralIncomeExpensesInfo.objects.create( |
|
765 |
+ brand_id=brand_id, |
|
766 |
+ user_id=user_id, |
|
767 |
+ integral_from=UserIntegralIncomeExpensesInfo.MEMBER_ACTIVITY_CONTRIBUTION_WELFARE, |
|
768 |
+ integral=unlocking.welfare_value, |
|
769 |
+ final_integral=user.integral, |
|
770 |
+ remark=unlocking.id, |
|
771 |
+ ) |
|
756 | 772 |
|
757 | 773 |
return response(200, 'Update Member Activity Contribute Welfare Unblocking Success', u'处理会员活动投稿福利解锁成功') |
@@ -3,6 +3,7 @@ |
||
3 | 3 |
import logging |
4 | 4 |
import time |
5 | 5 |
|
6 |
+from django.db import transaction |
|
6 | 7 |
from django_six import CompatibilityBaseCommand, close_old_connections |
7 | 8 |
from TimeConvert import TimeConvert as tc |
8 | 9 |
|
@@ -42,83 +43,84 @@ class Command(CompatibilityBaseCommand): |
||
42 | 43 |
# TODO: Opt by delay execute |
43 | 44 |
time.sleep(5) |
44 | 45 |
|
45 |
- try: |
|
46 |
- user = UserInfo.objects.get(user_id=user_id) |
|
47 |
- except UserInfo.DoesNotExist: |
|
48 |
- continue |
|
49 |
- |
|
50 |
- if coupon_id: |
|
51 |
- # 发放商城兑换券 |
|
46 |
+ with transaction.atomic(): |
|
52 | 47 |
try: |
53 |
- coupon = CouponInfo.objects.get(coupon_id=coupon_id) |
|
54 |
- except CouponInfo.DoesNotExist: |
|
48 |
+ user = UserInfo.objects.get(user_id=user_id) |
|
49 |
+ except UserInfo.DoesNotExist: |
|
55 | 50 |
continue |
56 | 51 |
|
57 |
- UserCouponInfo.objects.create( |
|
58 |
- brand_id=coupon.brand_id, |
|
59 |
- brand_name=coupon.brand_name, |
|
60 |
- coupon_id=coupon_id, |
|
61 |
- user_id=user_id, |
|
62 |
- coupon_title=coupon.coupon_title, |
|
63 |
- coupon_detail=coupon.coupon_detail, |
|
64 |
- coupon_value=coupon.coupon_value, |
|
65 |
- coupon_image=coupon.coupon_image, |
|
66 |
- coupon_from='INTEGRAL_MALL', |
|
67 |
- active_at=tc.utc_datetime(), |
|
68 |
- expire_at=tc.utc_datetime(days=coupon.coupon_valid_period) if coupon.coupon_expire_type == CouponInfo.CHANGED_EXPIRED_TIME else coupon.coupon_expire_at, |
|
69 |
- coupon_valid_period=coupon.coupon_valid_period, |
|
70 |
- coupon_limit_model_ids=coupon.coupon_limit_model_ids, |
|
71 |
- is_coupon_admin_writeoff=coupon.is_coupon_admin_writeoff, |
|
72 |
- ) |
|
73 |
- |
|
74 |
- else: |
|
75 |
- # 发放会员权益 |
|
76 |
- active_at = tc.utc_datetime() |
|
77 |
- expire_at = tc.utc_datetime(days=365) |
|
78 |
- |
|
79 |
- rights = RightInfo.objects.filter(is_send_coupon=True, status=True) |
|
80 |
- for right in rights: |
|
81 |
- if user.level == UserInfo.MEMBER_LRC: |
|
82 |
- coupon_id = right.coupon_level1_id |
|
83 |
- coupon_num = right.coupon_level1_num |
|
84 |
- elif user.level == UserInfo.MEMBER_SILVER: |
|
85 |
- coupon_id = right.coupon_level2_id |
|
86 |
- coupon_num = right.coupon_level2_num |
|
87 |
- elif user.level == UserInfo.MEMBER_GOLD: |
|
88 |
- coupon_id = right.coupon_level3_id |
|
89 |
- coupon_num = right.coupon_level3_num |
|
90 |
- elif user.level == UserInfo.MEMBER_WHITE_GOLD: |
|
91 |
- coupon_id = right.coupon_level4_id |
|
92 |
- coupon_num = right.coupon_level4_num |
|
93 |
- elif user.level == UserInfo.MEMBER_BLACK_GOLD: |
|
94 |
- coupon_id = right.coupon_level5_id |
|
95 |
- coupon_num = right.coupon_level5_num |
|
96 |
- |
|
97 |
- if not coupon_id: |
|
98 |
- continue |
|
99 |
- |
|
52 |
+ if coupon_id: |
|
53 |
+ # 发放商城兑换券 |
|
100 | 54 |
try: |
101 | 55 |
coupon = CouponInfo.objects.get(coupon_id=coupon_id) |
102 | 56 |
except CouponInfo.DoesNotExist: |
103 | 57 |
continue |
104 | 58 |
|
105 |
- for _ in range(right.coupon_num or coupon_num): |
|
106 |
- UserCouponInfo.objects.create( |
|
107 |
- brand_id=coupon.brand_id, |
|
108 |
- brand_name=coupon.brand_name, |
|
109 |
- coupon_id=coupon_id, |
|
110 |
- user_id=user_id, |
|
111 |
- coupon_title=coupon.coupon_title, |
|
112 |
- coupon_detail=coupon.coupon_detail, |
|
113 |
- coupon_value=coupon.coupon_value, |
|
114 |
- coupon_image=coupon.coupon_image, |
|
115 |
- active_at=active_at, |
|
116 |
- expire_at=expire_at, |
|
117 |
- coupon_valid_period=coupon.coupon_valid_period, |
|
118 |
- coupon_limit_model_ids=coupon.coupon_limit_model_ids, |
|
119 |
- ) |
|
120 |
- |
|
121 |
- user.coupon_expire_at = expire_at |
|
122 |
- user.save() |
|
59 |
+ UserCouponInfo.objects.create( |
|
60 |
+ brand_id=coupon.brand_id, |
|
61 |
+ brand_name=coupon.brand_name, |
|
62 |
+ coupon_id=coupon_id, |
|
63 |
+ user_id=user_id, |
|
64 |
+ coupon_title=coupon.coupon_title, |
|
65 |
+ coupon_detail=coupon.coupon_detail, |
|
66 |
+ coupon_value=coupon.coupon_value, |
|
67 |
+ coupon_image=coupon.coupon_image, |
|
68 |
+ coupon_from='INTEGRAL_MALL', |
|
69 |
+ active_at=tc.utc_datetime(), |
|
70 |
+ expire_at=tc.utc_datetime(days=coupon.coupon_valid_period) if coupon.coupon_expire_type == CouponInfo.CHANGED_EXPIRED_TIME else coupon.coupon_expire_at, |
|
71 |
+ coupon_valid_period=coupon.coupon_valid_period, |
|
72 |
+ coupon_limit_model_ids=coupon.coupon_limit_model_ids, |
|
73 |
+ is_coupon_admin_writeoff=coupon.is_coupon_admin_writeoff, |
|
74 |
+ ) |
|
75 |
+ |
|
76 |
+ else: |
|
77 |
+ # 发放会员权益 |
|
78 |
+ active_at = tc.utc_datetime() |
|
79 |
+ expire_at = tc.utc_datetime(days=365) |
|
80 |
+ |
|
81 |
+ rights = RightInfo.objects.filter(is_send_coupon=True, status=True) |
|
82 |
+ for right in rights: |
|
83 |
+ if user.level == UserInfo.MEMBER_LRC: |
|
84 |
+ coupon_id = right.coupon_level1_id |
|
85 |
+ coupon_num = right.coupon_level1_num |
|
86 |
+ elif user.level == UserInfo.MEMBER_SILVER: |
|
87 |
+ coupon_id = right.coupon_level2_id |
|
88 |
+ coupon_num = right.coupon_level2_num |
|
89 |
+ elif user.level == UserInfo.MEMBER_GOLD: |
|
90 |
+ coupon_id = right.coupon_level3_id |
|
91 |
+ coupon_num = right.coupon_level3_num |
|
92 |
+ elif user.level == UserInfo.MEMBER_WHITE_GOLD: |
|
93 |
+ coupon_id = right.coupon_level4_id |
|
94 |
+ coupon_num = right.coupon_level4_num |
|
95 |
+ elif user.level == UserInfo.MEMBER_BLACK_GOLD: |
|
96 |
+ coupon_id = right.coupon_level5_id |
|
97 |
+ coupon_num = right.coupon_level5_num |
|
98 |
+ |
|
99 |
+ if not coupon_id: |
|
100 |
+ continue |
|
101 |
+ |
|
102 |
+ try: |
|
103 |
+ coupon = CouponInfo.objects.get(coupon_id=coupon_id) |
|
104 |
+ except CouponInfo.DoesNotExist: |
|
105 |
+ continue |
|
106 |
+ |
|
107 |
+ for _ in range(right.coupon_num or coupon_num): |
|
108 |
+ UserCouponInfo.objects.create( |
|
109 |
+ brand_id=coupon.brand_id, |
|
110 |
+ brand_name=coupon.brand_name, |
|
111 |
+ coupon_id=coupon_id, |
|
112 |
+ user_id=user_id, |
|
113 |
+ coupon_title=coupon.coupon_title, |
|
114 |
+ coupon_detail=coupon.coupon_detail, |
|
115 |
+ coupon_value=coupon.coupon_value, |
|
116 |
+ coupon_image=coupon.coupon_image, |
|
117 |
+ active_at=active_at, |
|
118 |
+ expire_at=expire_at, |
|
119 |
+ coupon_valid_period=coupon.coupon_valid_period, |
|
120 |
+ coupon_limit_model_ids=coupon.coupon_limit_model_ids, |
|
121 |
+ ) |
|
122 |
+ |
|
123 |
+ user.coupon_expire_at = expire_at |
|
124 |
+ user.save() |
|
123 | 125 |
|
124 | 126 |
close_old_connections() |
@@ -2,6 +2,7 @@ |
||
2 | 2 |
|
3 | 3 |
import logging |
4 | 4 |
|
5 |
+from django.db import transaction |
|
5 | 6 |
from django_six import CompatibilityBaseCommand, close_old_connections |
6 | 7 |
from TimeConvert import TimeConvert as tc |
7 | 8 |
|
@@ -37,58 +38,59 @@ class Command(CompatibilityBaseCommand): |
||
37 | 38 |
brand_id = v.get('brand_id', '') |
38 | 39 |
user_id = v.get('user_id', '') |
39 | 40 |
|
40 |
- try: |
|
41 |
- user = UserInfo.objects.get(user_id=user_id) |
|
42 |
- except UserInfo.DoesNotExist: |
|
43 |
- continue |
|
44 |
- |
|
45 |
- active_at = user.coupon_expire_at |
|
46 |
- expire_at = tc.utc_datetime(user.coupon_expire_at, days=365) |
|
47 |
- |
|
48 |
- # 发放会员权益 |
|
49 |
- rights = RightInfo.objects.filter(is_send_coupon=True, is_continue_send_coupon=True, status=True) |
|
50 |
- for right in rights: |
|
51 |
- if user.level == UserInfo.MEMBER_LRC: |
|
52 |
- coupon_id = right.coupon_level1_id |
|
53 |
- coupon_num = right.coupon_level1_num |
|
54 |
- elif user.level == UserInfo.MEMBER_SILVER: |
|
55 |
- coupon_id = right.coupon_level2_id |
|
56 |
- coupon_num = right.coupon_level2_num |
|
57 |
- elif user.level == UserInfo.MEMBER_GOLD: |
|
58 |
- coupon_id = right.coupon_level3_id |
|
59 |
- coupon_num = right.coupon_level3_num |
|
60 |
- elif user.level == UserInfo.MEMBER_WHITE_GOLD: |
|
61 |
- coupon_id = right.coupon_level4_id |
|
62 |
- coupon_num = right.coupon_level4_num |
|
63 |
- elif user.level == UserInfo.MEMBER_BLACK_GOLD: |
|
64 |
- coupon_id = right.coupon_level5_id |
|
65 |
- coupon_num = right.coupon_level5_num |
|
66 |
- |
|
67 |
- if not coupon_id: |
|
68 |
- continue |
|
69 |
- |
|
41 |
+ with transaction.atomic(): |
|
70 | 42 |
try: |
71 |
- coupon = CouponInfo.objects.get(coupon_id=coupon_id) |
|
72 |
- except CouponInfo.DoesNotExist: |
|
43 |
+ user = UserInfo.objects.get(user_id=user_id) |
|
44 |
+ except UserInfo.DoesNotExist: |
|
73 | 45 |
continue |
74 | 46 |
|
75 |
- for _ in range(right.coupon_num or coupon_num): |
|
76 |
- UserCouponInfo.objects.create( |
|
77 |
- brand_id=coupon.brand_id, |
|
78 |
- brand_name=coupon.brand_name, |
|
79 |
- coupon_id=coupon_id, |
|
80 |
- user_id=user_id, |
|
81 |
- coupon_title=coupon.coupon_title, |
|
82 |
- coupon_detail=coupon.coupon_detail, |
|
83 |
- coupon_value=coupon.coupon_value, |
|
84 |
- coupon_image=coupon.coupon_image, |
|
85 |
- active_at=active_at, |
|
86 |
- expire_at=expire_at, |
|
87 |
- coupon_valid_period=coupon.coupon_valid_period, |
|
88 |
- coupon_limit_model_ids=coupon.coupon_limit_model_ids, |
|
89 |
- ) |
|
90 |
- |
|
91 |
- user.coupon_expire_at = expire_at |
|
92 |
- user.save() |
|
47 |
+ active_at = user.coupon_expire_at |
|
48 |
+ expire_at = tc.utc_datetime(user.coupon_expire_at, days=365) |
|
49 |
+ |
|
50 |
+ # 发放会员权益 |
|
51 |
+ rights = RightInfo.objects.filter(is_send_coupon=True, is_continue_send_coupon=True, status=True) |
|
52 |
+ for right in rights: |
|
53 |
+ if user.level == UserInfo.MEMBER_LRC: |
|
54 |
+ coupon_id = right.coupon_level1_id |
|
55 |
+ coupon_num = right.coupon_level1_num |
|
56 |
+ elif user.level == UserInfo.MEMBER_SILVER: |
|
57 |
+ coupon_id = right.coupon_level2_id |
|
58 |
+ coupon_num = right.coupon_level2_num |
|
59 |
+ elif user.level == UserInfo.MEMBER_GOLD: |
|
60 |
+ coupon_id = right.coupon_level3_id |
|
61 |
+ coupon_num = right.coupon_level3_num |
|
62 |
+ elif user.level == UserInfo.MEMBER_WHITE_GOLD: |
|
63 |
+ coupon_id = right.coupon_level4_id |
|
64 |
+ coupon_num = right.coupon_level4_num |
|
65 |
+ elif user.level == UserInfo.MEMBER_BLACK_GOLD: |
|
66 |
+ coupon_id = right.coupon_level5_id |
|
67 |
+ coupon_num = right.coupon_level5_num |
|
68 |
+ |
|
69 |
+ if not coupon_id: |
|
70 |
+ continue |
|
71 |
+ |
|
72 |
+ try: |
|
73 |
+ coupon = CouponInfo.objects.get(coupon_id=coupon_id) |
|
74 |
+ except CouponInfo.DoesNotExist: |
|
75 |
+ continue |
|
76 |
+ |
|
77 |
+ for _ in range(right.coupon_num or coupon_num): |
|
78 |
+ UserCouponInfo.objects.create( |
|
79 |
+ brand_id=coupon.brand_id, |
|
80 |
+ brand_name=coupon.brand_name, |
|
81 |
+ coupon_id=coupon_id, |
|
82 |
+ user_id=user_id, |
|
83 |
+ coupon_title=coupon.coupon_title, |
|
84 |
+ coupon_detail=coupon.coupon_detail, |
|
85 |
+ coupon_value=coupon.coupon_value, |
|
86 |
+ coupon_image=coupon.coupon_image, |
|
87 |
+ active_at=active_at, |
|
88 |
+ expire_at=expire_at, |
|
89 |
+ coupon_valid_period=coupon.coupon_valid_period, |
|
90 |
+ coupon_limit_model_ids=coupon.coupon_limit_model_ids, |
|
91 |
+ ) |
|
92 |
+ |
|
93 |
+ user.coupon_expire_at = expire_at |
|
94 |
+ user.save() |
|
93 | 95 |
|
94 | 96 |
close_old_connections() |
@@ -110,7 +110,7 @@ class MemberActivityContributionWelfareInfoAdmin(admin.ModelAdmin): |
||
110 | 110 |
|
111 | 111 |
|
112 | 112 |
class MemberActivityContributionWelfareUnlockingInfoAdmin(admin.ModelAdmin): |
113 |
- list_display = ('unlocking_id', 'admin_id', 'user_id', 'activity_id', 'contribution_id', 'welfare_id', 'name', 'phone', 'address', 'tracking_number', 'is_handled', 'status', 'created_at', 'updated_at') |
|
113 |
+ list_display = ('unlocking_id', 'admin_id', 'user_id', 'activity_id', 'contribution_id', 'welfare_id', 'welfare_value', 'name', 'phone', 'address', 'tracking_number', 'is_handled', 'status', 'created_at', 'updated_at') |
|
114 | 114 |
list_filter = ('admin_id', 'activity_id', 'welfare_id', 'is_handled', 'status') |
115 | 115 |
|
116 | 116 |
|
@@ -0,0 +1,19 @@ |
||
1 |
+# -*- coding: utf-8 -*- |
|
2 |
+# Generated by Django 3.2.16 on 2022-10-27 10:38 |
|
3 |
+ |
|
4 |
+from django.db import migrations, models |
|
5 |
+ |
|
6 |
+ |
|
7 |
+class Migration(migrations.Migration): |
|
8 |
+ |
|
9 |
+ dependencies = [ |
|
10 |
+ ('member', '0045_auto_20221026_2102'), |
|
11 |
+ ] |
|
12 |
+ |
|
13 |
+ operations = [ |
|
14 |
+ migrations.AddField( |
|
15 |
+ model_name='memberactivitycontributionwelfareunlockinginfo', |
|
16 |
+ name='welfare_value', |
|
17 |
+ field=models.IntegerField(default=0, help_text='福利数量', verbose_name='welfare_value'), |
|
18 |
+ ), |
|
19 |
+ ] |
@@ -811,6 +811,7 @@ class MemberActivityContributionWelfareUnlockingInfo(BaseModelMixin, BrandInfoMi |
||
811 | 811 |
contribution_id = models.CharField(_(u'contribution_id'), max_length=32, blank=True, null=True, help_text=u'投稿唯一标识', db_index=True) |
812 | 812 |
|
813 | 813 |
welfare_id = models.CharField(_(u'welfare_id'), max_length=32, blank=True, null=True, help_text=u'福利唯一标识', db_index=True) |
814 |
+ welfare_value = models.IntegerField(_(u'welfare_value'), default=0, help_text=_(u'福利数量')) |
|
814 | 815 |
|
815 | 816 |
name = models.CharField(_(u'name'), max_length=255, blank=True, null=True, help_text=u'姓名') |
816 | 817 |
phone = models.CharField(_(u'phone'), max_length=255, blank=True, null=True, help_text=u'电话') |
@@ -318,19 +318,20 @@ def user_integral_add(request): |
||
318 | 318 |
return response(ProductBrandStatusCode.BRAND_NOT_MATCH) |
319 | 319 |
|
320 | 320 |
try: |
321 |
- user = UserInfo.objects.get(user_id=user_id, status=True) |
|
321 |
+ user = UserInfo.objects.select_for_update().get(user_id=user_id, status=True) |
|
322 | 322 |
except UserInfo.DoesNotExist: |
323 | 323 |
return response(UserStatusCode.USER_NOT_FOUND) |
324 | 324 |
|
325 |
+ user.integral += integral |
|
326 |
+ user.save() |
|
327 |
+ |
|
325 | 328 |
UserIntegralIncomeExpensesInfo.objects.create( |
326 | 329 |
brand_id=brand_id, |
327 | 330 |
user_id=user_id, |
328 | 331 |
integral_from=UserIntegralIncomeExpensesInfo.CONTRIBUTE, |
329 | 332 |
integral=integral, |
330 |
- remark=remark |
|
333 |
+ final_integral=user.integral, |
|
334 |
+ remark=remark, |
|
331 | 335 |
) |
332 | 336 |
|
333 |
- user.integral += integral |
|
334 |
- user.save() |
|
335 |
- |
|
336 | 337 |
return response(200, 'Add User Integral Success', u'添加用户投稿积分成功') |