Bläddra i källkod

小程序二维码

wushaodong 4 år sedan
förälder
incheckning
81b13ee1b7

+ 5 - 0
apps/WechatApplet/models.py

@@ -84,3 +84,8 @@ class WechatApplet(models.Model):
         }
         page = '/pages/repairList/repairList?sort=wodepaidan&name=我的派单'
         WeChat.sendSubscribeMessage(self.getAccessToken(), openid, template_id, page, data)
+
+    def getWXAppCode(self, company_no):
+        page = 'pages/index/index'
+        filename = WeChat.getWXAppCode(self.getAccessToken(),page, company_no)
+        return filename

+ 5 - 0
apps/tenant/employee/filters.py

@@ -9,6 +9,11 @@ class EmployeeFilter(django_filters.FilterSet):
     company_name = django_filters.CharFilter(field_name='tenant__company_name', lookup_expr='icontains')
     name = django_filters.CharFilter(field_name='name', lookup_expr='icontains')
     tel = django_filters.CharFilter(field_name='tel', lookup_expr='icontains')
+    type = django_filters.CharFilter(method='query_type')
+
+    def query_type(self, queryset, *args):
+        queryset = queryset.filter(type__in=args[1].split(','))
+        return queryset
 
     class Meta:
         model = Employee

+ 1 - 1
apps/tenant/employee/views.py

@@ -49,7 +49,7 @@ class EmployeeViewSet(CustomModelViewSet):
     serializer_class = EmployeeSerializer
 
     def filter_queryset(self, queryset):
-        queryset = queryset.filter(tenant=self.request.user.employee.tenant, type__lt=Employee.REPAIR)
+        queryset = queryset.filter(tenant=self.request.user.employee.tenant)
         f = EmployeeFilter(self.request.GET, queryset=queryset)
         return f.qs
 

+ 1 - 1
apps/tenant/models.py

@@ -16,7 +16,7 @@ class Tenant(models.Model):
     company_no = models.CharField(max_length=10, verbose_name=u'企业编号', blank=True, null=True)
     company_name = models.CharField(max_length=200, verbose_name=u'企业名称', blank=True, null=True)
     organ_code = models.CharField(max_length=200, verbose_name=u'组织代码', blank=True, null=True)
-    # images = models.ForeignKey('Upload', verbose_name='营业执照图片',on_delete=models.PROTECT, blank=True)
+    wxapp_img = models.CharField(verbose_name=u'小程序二维码', max_length=250)
     name = models.CharField(max_length=20, verbose_name=u'联系人名称')
     tel = models.CharField(max_length=20, verbose_name=u'联系人电话')
     address = models.CharField(max_length=200, verbose_name=u'地址', blank=True, null=True)

+ 23 - 0
apps/tenant/views.py

@@ -3,6 +3,7 @@ import traceback
 import datetime
 import time
 from django.db import transaction
+from django.conf import settings
 from rest_framework.decorators import action
 from rest_framework_jwt.views import ObtainJSONWebToken,VerifyJSONWebToken,RefreshJSONWebToken
 from rest_framework.serializers import ValidationError
@@ -17,6 +18,7 @@ from apps.log.models import BizLog
 from apps.tenant.config.models import Config
 from utils.exceptions import CustomError
 from apps.base import Formater
+from apps.WechatApplet.models import WechatApplet
 
 class TenantLoginView(ObtainJSONWebToken):
     serializer_class = TenantJWTSerializer
@@ -116,6 +118,27 @@ class CompanyViewSet(CustomModelViewSet):
             traceback.print_exc()
             return response_error(u'支付失败', request)
 
+    @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)
+
     @action(methods=['get'], detail=True)
     def confirm_pay(self, request, pk):
         pay_id = request.GET.get('pay_id')

+ 8 - 0
ly_baoxiu_admin/settings.py

@@ -122,6 +122,14 @@ WSGI_APPLICATION = 'ly_baoxiu_admin.wsgi.application'
 # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
 
 DATABASES = {
+    # 'default': {
+    #     'ENGINE': 'django.db.backends.mysql',
+    #     'NAME': 'baoxiu',
+    #     'USER': 'baoxiu',
+    #     'PASSWORD': 'baoxiu@20210323',
+    #     'HOST': '139.9.148.181',
+    #     'PORT': 3306,
+    # },
     'default': {
         'ENGINE': 'django.db.backends.mysql',
         'NAME': 'ly_report_repair',

+ 13 - 0
uis/tenant/company/index.html

@@ -65,6 +65,9 @@
                                 </dl>
                             </div>
                         </button>
+                        <button class="layui-btn" id="btn_wxapp_code">
+                            <i class="layui-icon layui-icon-add-circle"></i>小程序二维码
+                            </button>
                         <div style="float:right;">
                             <form class="layui-form" lay-filter="query-form-element">
                                 <div class="seach_items">
@@ -192,6 +195,16 @@
         $('#pay_alipay').on('click', function () {
             pay_order( 2)
         });
+        $('#btn_wxapp_code').on('click', function () {
+            layer.open({
+                type: 2,
+                title: '生成小程序二维码',
+                shadeClose: false,
+                area: ['60%', '70%'],
+                content: 'wxapp_code.html?company_id=' + company_id
+            });
+        });
+
         var pay_order = function (pay_channel) {
 
             layer.open({

+ 2 - 20
uis/tenant/company/pay_order.html

@@ -46,11 +46,10 @@
         base: '../../../layuiadmin/' //静态资源所在路径
     }).extend({
         index: 'lib/index',
-    }).use(['index', 'form', 'table', 'utils'], function () {
+    }).use(['index', 'form'], function () {
         var $ = layui.$
             , admin = layui.admin
-            , form = layui.form
-            , table = layui.table;
+            , form = layui.form;
 
         var company_id = layui.view.getParameterByName('company_id');
         var pay_channel = layui.view.getParameterByName('pay_channel');
@@ -69,23 +68,6 @@
                 $('#id_amount').html(res.data.amount)
                 pay_id = res.data.id
                 $('#pay-code').qrcode({width: 200, height: 200, text: res.data.qrcode});
-                table.render({
-                    elem: '#datagrid'
-                    , data: res.data.rows
-                    , cols: [[
-                        {field: 'no', title: '订单号', width: 170}
-                        , {field: 'product_name', title: '产品名称', width: 130}
-                        , {field: 'amount', title: '金额', align: 'right', width: 80}
-                        , {field: 'branch_text', title: '网点', width: 120}
-                        , {field: 'user_name', title: '下单人', width: 100}
-
-                        , {field: 'name', title: '姓名', width: 100}
-                        , {field: 'id_number', title: '身份证号', width: 180}
-                        , {field: 'vin', title: '车架号', width: 180}
-                        , {field: 'engine_no', title: '发动机号', width: 180}
-                        , {field: 'create_time', title: '下单时间', width: 180}
-                    ]]
-                });
             }
         });
 

+ 72 - 0
uis/tenant/company/wxapp_code.html

@@ -0,0 +1,72 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>二维码</title>
+    <meta name="renderer" content="webkit">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="viewport"
+          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
+    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
+    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
+    <style type="text/css">
+
+        .imgStyle{
+            width: 200px;
+            height: auto;
+        }
+    </style>
+</head>
+<body>
+
+<div class="layui-fluid">
+    <div class="layui-card">
+        <div class="layui-card-body">
+            <div align="center">
+                <br>
+                <img id="wxapp_img" src="" class="imgStyle"/>
+                <br>
+            </div>
+            <form class="layui-form" action="" lay-filter="component-form-element">
+
+                <button class="layui-btn" id="id_save" lay-submit lay-filter="component-form-element"
+                        style="display: none">保存
+                </button>
+            </form>
+        </div>
+    </div>
+</div>
+
+<script src="../../layuiadmin/layui/layui.js"></script>
+<script src="../../layuiadmin/layui/qrcode.js"></script>
+
+<script>
+    layui.config({
+        base: '../../../layuiadmin/' //静态资源所在路径
+    }).extend({
+        index: 'lib/index',
+    }).use(['index', 'form',], function () {
+        var $ = layui.$
+            , admin = layui.admin
+            , form = layui.form;
+        var company_id = layui.view.getParameterByName('company_id');
+        admin.req({
+            url: '/tenant/company/' + company_id + '/get_wxapp_code/',
+            data: {company_id: company_id},
+            done: function (res) {
+                $('#wxapp_img').attr('src', res.data);
+            }
+        });
+
+        form.on('submit(component-form-element)', function (data) {
+            parent.layui.onSubmitChild();
+            return false;
+        });
+
+        parent.layui.submitChild = function () {
+            $("#id_save").click();
+        };
+    });
+</script>
+</body>
+</html>

+ 1 - 1
uis/tenant/employee/index.html

@@ -116,7 +116,7 @@
             , form = layui.form;
         table.render({
             elem: '#datagrid'
-            , url: '/tenant/employee/'
+            , url: '/tenant/employee/?type=1,2,3'
             , cols: [[
                 {field: 'name', title: '姓名', width: 200}
                 , {field: 'tel', title: '电话', width: 200}

+ 29 - 1
utils/wx/wechat.py

@@ -2,8 +2,9 @@
 
 import requests
 import json
+from django.conf import settings
 from utils.exceptions import CustomError
-
+from utils.file_operation import PathAndRename
 
 class WeChat(object):
 
@@ -224,6 +225,33 @@ class WeChat(object):
         #    raise CustomError(u'微信请求失败' + str(result['errcode']) + ':' + result['errmsg'])
         #return result
 
+    @staticmethod
+    def getWXAppCode(access_token, page, company_no):
+        '''获取小程序二维码'''
+        url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={}'.format(access_token)
+        data = {"scene": "company_no={}".format(company_no),
+                "width": 1280,
+                "line_color": {"r": 43, "g": 162, "b": 69},  # 自定义颜色
+                "is_hyaline": True}
+        result = requests.post(url, json=data)
+        # print('-------------------------',result)
+        upload_path = PathAndRename("company/")
+        filename = "%s%s.png" % (
+            upload_path.path,
+            company_no,
+        )
+        filename = filename.lower()
+        full_filename = "%s%s" % (settings.MEDIA_ROOT, filename)
+        with open(full_filename, 'wb') as destination:
+            destination.write(result.content)
+
+
+        # with open('aa.png', 'wb') as f:
+        #     f.write(result.content)
+        #     print(4444444444,f)
+
+        return filename, full_filename
+
     @staticmethod
     def releaseCode(access_token):
         '''已审核代码发布'''