@@ -73,6 +73,9 @@ class Command(CompatibilityBaseCommand): |
||
73 | 73 |
|
74 | 74 |
else: |
75 | 75 |
# 发放会员权益 |
76 |
+ active_at = tc.utc_datetime() |
|
77 |
+ expire_at = tc.utc_datetime(days=365) |
|
78 |
+ |
|
76 | 79 |
rights = RightInfo.objects.filter(is_send_coupon=True, status=True) |
77 | 80 |
for right in rights: |
78 | 81 |
if user.level == UserInfo.MEMBER_LRC: |
@@ -109,10 +112,13 @@ class Command(CompatibilityBaseCommand): |
||
109 | 112 |
coupon_detail=coupon.coupon_detail, |
110 | 113 |
coupon_value=coupon.coupon_value, |
111 | 114 |
coupon_image=coupon.coupon_image, |
112 |
- active_at=tc.utc_datetime(), |
|
113 |
- expire_at=tc.utc_datetime(days=365), |
|
115 |
+ active_at=active_at, |
|
116 |
+ expire_at=expire_at, |
|
114 | 117 |
coupon_valid_period=coupon.coupon_valid_period, |
115 | 118 |
coupon_limit_model_ids=coupon.coupon_limit_model_ids, |
116 | 119 |
) |
117 | 120 |
|
121 |
+ user.coupon_expire_at = expire_at |
|
122 |
+ user.save() |
|
123 |
+ |
|
118 | 124 |
close_old_connections() |
@@ -0,0 +1,95 @@ |
||
1 |
+# -*- coding: utf-8 -*- |
|
2 |
+ |
|
3 |
+import logging |
|
4 |
+ |
|
5 |
+from django_six import CompatibilityBaseCommand, close_old_connections |
|
6 |
+from TimeConvert import TimeConvert as tc |
|
7 |
+ |
|
8 |
+from account.models import UserInfo |
|
9 |
+from coupon.models import CouponInfo, UserCouponInfo |
|
10 |
+from member.models import RightInfo |
|
11 |
+from utils.redis.connect import r |
|
12 |
+from utils.redis.rkeys import MEMBER_SEND_COUPON_LIST2 |
|
13 |
+ |
|
14 |
+ |
|
15 |
+logger = logging.getLogger('console') |
|
16 |
+ |
|
17 |
+ |
|
18 |
+class Command(CompatibilityBaseCommand): |
|
19 |
+ def handle(self, *args, **options): |
|
20 |
+ |
|
21 |
+ logger.info('Member coupon is dealing') |
|
22 |
+ |
|
23 |
+ while True: |
|
24 |
+ # r.rpushjson('TEMPLET_CMD_KEY', { |
|
25 |
+ # 'brand_id': 'brand_id', |
|
26 |
+ # 'user_id': 'user_id', |
|
27 |
+ # }) |
|
28 |
+ k, v = r.blpopjson(MEMBER_SEND_COUPON_LIST2, 60) |
|
29 |
+ |
|
30 |
+ if not v: |
|
31 |
+ continue |
|
32 |
+ |
|
33 |
+ close_old_connections() |
|
34 |
+ |
|
35 |
+ logger.info(v) |
|
36 |
+ |
|
37 |
+ brand_id = v.get('brand_id', '') |
|
38 |
+ user_id = v.get('user_id', '') |
|
39 |
+ |
|
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 |
+ |
|
70 |
+ try: |
|
71 |
+ coupon = CouponInfo.objects.get(coupon_id=coupon_id) |
|
72 |
+ except CouponInfo.DoesNotExist: |
|
73 |
+ continue |
|
74 |
+ |
|
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 |
+ print(user_id, coupon_id, user.coupon_expire_at, tc.utc_datetime(user.coupon_expire_at, days=365)) |
|
91 |
+ |
|
92 |
+ user.coupon_expire_at = expire_at |
|
93 |
+ user.save() |
|
94 |
+ |
|
95 |
+ close_old_connections() |
@@ -0,0 +1,18 @@ |
||
1 |
+# -*- coding: utf-8 -*- |
|
2 |
+ |
|
3 |
+import logging |
|
4 |
+ |
|
5 |
+from django_six import CompatibilityBaseCommand |
|
6 |
+ |
|
7 |
+from account.models import UserInfo |
|
8 |
+from coupon.models import CouponInfo, UserCouponInfo |
|
9 |
+from member.models import RightInfo |
|
10 |
+from TimeConvert import TimeConvert as tc |
|
11 |
+ |
|
12 |
+ |
|
13 |
+logger = logging.getLogger('console') |
|
14 |
+ |
|
15 |
+ |
|
16 |
+class Command(CompatibilityBaseCommand): |
|
17 |
+ def handle(self, *args, **options): |
|
18 |
+ users = UserInfo.objects.filter(coupon_expire_at__lte=tc.utc_datetime(), status=True) |
@@ -19,6 +19,7 @@ SUBSCRIBE_USERINFO_LIST = 'subscribe:userinfo:%s' |
||
19 | 19 |
|
20 | 20 |
MEMBER_SHOT_DATA = 'kodo:member:shot:data' |
21 | 21 |
MEMBER_SEND_COUPON_LIST = 'kodo:member:send:coupon:list' |
22 |
+MEMBER_SEND_COUPON_LIST2 = 'kodo:member:send:coupon:list2' |
|
22 | 23 |
MEMBER_UPGRADE_INFO = 'kodo:member:upgrade:info:%s:%s' # brand_id, user_id |
23 | 24 |
|
24 | 25 |
# 七牛 |