Bläddra i källkod

验证企业有效期

wushaodong 4 år sedan
förälder
incheckning
3a817e15e6
4 ändrade filer med 34 tillägg och 3 borttagningar
  1. 20 0
      apps/tenant/models.py
  2. 8 2
      apps/wxapp/serializers.py
  3. 3 0
      apps/wxapp/tenant/views.py
  4. 3 1
      ly_baoxiu_admin/settings.py

+ 20 - 0
apps/tenant/models.py

@@ -1,4 +1,6 @@
 # coding=utf-8
+import datetime
+import time
 from django.db import models
 from django.conf import settings
 from django.db.models import Q
@@ -44,6 +46,24 @@ class Tenant(models.Model):
             rows = rows.filter(~Q(id=exclude_id))
         return rows.count()
 
+    @staticmethod
+    def check_validity(id):
+        if not id:
+            return True
+        tenant = Tenant.objects.filter(id=id).first()
+        if tenant.status == settings.OVERDUE:
+            return False
+        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)
+        if diff < 0:
+            tenant.status = settings.OVERDUE
+            tenant.save()
+            return False
+        return True
+
     @staticmethod
     def getById(id):
         try:

+ 8 - 2
apps/wxapp/serializers.py

@@ -7,7 +7,7 @@ from django.db.models import Q
 from rest_framework import serializers
 from rest_framework_jwt.settings import api_settings
 
-from apps.WechatApplet.models import WechatApplet
+from apps.tenant.models import Tenant
 from apps.wxapp.models import CustomerWechat
 from apps.log.models import BizLog
 from apps.wxapp import customer_log
@@ -39,12 +39,15 @@ class WechatLoginSerializer(serializers.Serializer):
 
             payload = jwt_payload_handler(user)
             customer_log(customer_wechat.customer, BizLog.INSERT, u'用户微信登录,username=%s' % user.username)
+            tenant_id = customer_wechat.customer.tenant and customer_wechat.customer.tenant.id or ''
+            is_validity = Tenant.check_validity(tenant_id)
             return {
                 'bind': 1,
                 'user_id': user.id,
                 'token': jwt_encode_handler(payload),
                 'openid': customer_wechat.openid,
-                'tenant_id': customer_wechat.customer.tenant and customer_wechat.customer.tenant.id or '',
+                'tenant_id': tenant_id,
+                'is_validity': is_validity,
                 'nick_name': settings.WEAPP['nick_name'],
                 'name': customer_wechat.customer.name or '',
                 'tel': customer_wechat.customer.tel or '',
@@ -71,12 +74,15 @@ class WechatBindSerializer(serializers.Serializer):
             user = customer.user
             payload = jwt_payload_handler(user)
             customer_log(customer, BizLog.INSERT, u'用户微信登录,username=%s' % user.username)
+            tenant_id = customer.tenant and customer.tenant.id or ''
+            is_validity = Tenant.check_validity(tenant_id)
             return {
                 'token': jwt_encode_handler(payload),
                 'user_id': user.id,
                 'name': customer.name or '',
                 'tel': customer.tel or '',
                 'face': customer.face,
+                'is_validity': is_validity,
                 'user_type': customer.type,  # 用户类别,1为平台管理员,2为管理者,3检修人,4报修人
                 'forbid_baoxiu': 'true' and customer.status == Employee.DISABLE or 'false',  # 是否禁用报修,
                 'tenant_id': customer.tenant and customer.tenant.id or '',

+ 3 - 0
apps/wxapp/tenant/views.py

@@ -57,6 +57,9 @@ class TenantViewSet(CustomModelViewSet):
     def bind_company(self, request, pk):
         # 绑定企业,pk 企业编号
         try:
+            is_validity = Tenant.check_validity(pk)
+            if not is_validity:
+                raise CustomError('该企业认证已过期,请联系管理员续费!')
             with transaction.atomic():
                 user = self.request.user
                 tenant = Tenant.getByNo(pk)

+ 3 - 1
ly_baoxiu_admin/settings.py

@@ -173,10 +173,12 @@ GENDER_CHOICES = (
 DEFAULT = 0
 PASS = 1
 REJECT = 2
+OVERDUE = 3
 CHECK_STATE_CHOICES = (
     (DEFAULT, u'未审核'),
     (PASS, u'已通过'),
     (REJECT, u'未通过'),
+    (OVERDUE, u'已过期'),
 )
 
 NOT_CHECKED = 1
@@ -271,7 +273,7 @@ WEAPP = {
     'nick_name': '燎原云报修', # 燎原云报修小程序
     'appid': 'wx0a4ed500a98c0507',
     'secret': '0700bb3a58cd09505e78d7c7d1781042',
-    'message_template': 'V-b3rOtf47SbxsIoN1o2IdAL7cNjfrCnrlD6m-XEeYs',
+    'message_template': '5ucRHdj_NFmfcDVllWohAJ5OqU6bQm5EpfALxtppNBc',
 }
 #支付宝支付
 ALIPAY_SETTING11 = {