Browse Source

优化修改

hujingpei 4 years ago
parent
commit
3587cc2b6f
3 changed files with 19 additions and 14 deletions
  1. 9 12
      apps/admin/tenant/views.py
  2. 8 1
      apps/tenant/models.py
  3. 2 1
      apps/tenant/notices/models.py

+ 9 - 12
apps/admin/tenant/views.py

@@ -142,27 +142,24 @@ class MemberRemindViewSet(APIView):
 
     def get(self, request):
         tenant = request.user.employee.tenant
+
         today = datetime.datetime.now().strftime('%Y-%m-%d')
         today_stamp = time.mktime(time.strptime(today, "%Y-%m-%d"))
-
         end_date = time.mktime(time.strptime(tenant.end_date.strftime('%Y-%m-%d'), '%Y-%m-%d'))
         diff = (int(end_date) - int(today_stamp))/86400
 
-        employee = Employee.objects.filter(tenant=tenant,type=1).first()
-        user = User.objects.filter(username=employee.tel).first()
-        notice_data = {
-            'title': "",
-            'content': "",
-            'tenant': tenant,
-            'type': Notices.MESSAGE,
-            'range': Notices.ADMIN,
-        }
-        if diff <= 40:
+        end_time = (timezone.now() + datetime.timedelta(days=30)).strftime('%Y-%m-%d')
+        tenant = Tenant.objects.filter(id=tenant.id,end_date__lte=end_time).first()
+        notice = Notices.objects.filter(type=Notices.RENEW, end_time__isnull=True,tenant=tenant)
+
+        if not notice and diff <= 30:
+            employee = Employee.objects.filter(tenant=tenant,type=Employee.SUPER).first()
+            user = employee.user
             notice_data = {
                 'title': '会员到期提醒,请点击查看!',
                 'content': '您的会员还有{0}天到期!请及时续费,以免影响您的正常使用!'.format(diff),
                 'tenant': tenant,
-                'type': Notices.MESSAGE,
+                'type': Notices.RENEW,
                 'range': Notices.ADMIN,
                 # 'end_time': (timezone.now() + datetime.timedelta(days=int(diff))).strftime('%Y-%m-%d'),
             }

+ 8 - 1
apps/tenant/models.py

@@ -159,7 +159,14 @@ class Pay(models.Model):
         self.tenant.status = settings.PASS
         self.tenant.edition = self.edition_year.split(',')[0]
         self.tenant.save()
-        Pay.objects.filter(tenant=self.tenant,amount__isnull=True).delete()
+        Pay.objects.filter(tenant=self.tenant, amount__isnull=True).delete()
+
+        try:
+            from apps.tenant.notices.models import Notices
+        except ImportError:
+            pass
+        Notices.objects.filter(tenant=self.tenant,type=Notices.RENEW).update(end_date=datetime.datetime.now())
+
 
     # 支付宝回调,付款
     def payConfirm(self, no):

+ 2 - 1
apps/tenant/notices/models.py

@@ -1,6 +1,5 @@
 # coding=utf-8
 
-
 from django.db import models
 from django.conf import settings
 
@@ -10,9 +9,11 @@ from apps.tenant.models import Tenant
 class Notices(models.Model):
     NOTICE = 1
     MESSAGE = 2
+    RENEW = 3
     TYPE_CHOICES = (
         (NOTICE, u'集体通知'),
         (MESSAGE, u'个人消息'),
+        (RENEW, u'续费提醒'),
     )
 
     ALL = 1