|
@@ -1,6 +1,8 @@
|
|
|
# coding=utf-8
|
|
|
from django.conf import settings
|
|
|
import datetime
|
|
|
+import traceback
|
|
|
+
|
|
|
from django.utils import timezone
|
|
|
from utils.custom_modelviewset import CustomModelViewSet
|
|
|
from utils.permission import IsAdministratorUser
|
|
@@ -18,6 +20,8 @@ from apps.account.models import User
|
|
|
from .filters import TenantFilter
|
|
|
from apps.tenant.option.models import Option
|
|
|
from apps.tenant.notices.models import Notices, NoticesToUser
|
|
|
+from apps.WechatApplet.models import WechatApplet
|
|
|
+
|
|
|
|
|
|
class TenantViewSet(CustomModelViewSet):
|
|
|
permission_classes = [IsAdministratorUser, ]
|
|
@@ -117,3 +121,24 @@ class TenantViewSet(CustomModelViewSet):
|
|
|
except Exception as e:
|
|
|
return response_error(str(e))
|
|
|
return response_ok('审核完成!')
|
|
|
+
|
|
|
+ @action(methods=['get'], detail=True)
|
|
|
+ def get_wxapp_code(self, request, pk):
|
|
|
+ try:
|
|
|
+ tenant = Tenant.objects.filter(id=pk).first()
|
|
|
+ if tenant:
|
|
|
+ company_no = tenant.company_no
|
|
|
+ else:
|
|
|
+ raise CustomError('获取企业信息失败,请刷新重试!')
|
|
|
+ if not tenant.wxapp_img:
|
|
|
+ applet = WechatApplet.objects.filter(authorizer_appid=settings.WEAPP['appid']).first()
|
|
|
+ filename = applet.getWXAppCode(company_no)
|
|
|
+ tenant.wxapp_img = "{0}{1}".format(settings.MEDIA_URL, filename)
|
|
|
+ tenant.save()
|
|
|
+
|
|
|
+ return response_ok(tenant.wxapp_img)
|
|
|
+ except CustomError as e:
|
|
|
+ return response_error(str(e))
|
|
|
+ except Exception as e:
|
|
|
+ traceback.print_exc()
|
|
|
+ return response_error(u'支付失败', request)
|