wushaodong 4 år sedan
förälder
incheckning
7a912ca3bd

+ 14 - 0
apps/WechatApplet/models.py

@@ -70,3 +70,17 @@ class WechatApplet(models.Model):
         }
         page = '/pages/certificate/certificate'
         WeChat.sendSubscribeMessage(self.getAccessToken(), openid, template_id, page, data)
+
+    def sendDispatchMsg(self, openid, name, address, fault_des, time, no):
+        template_id = settings.WEAPP['message_template_dispatch']
+        if not template_id:
+            return
+        data = {
+            'character_string1': {'value': no},
+            'thing3':{'value':fault_des},
+            'time5':{'value':time.strftime('%Y-%m-%d %H:%M:%S')},
+            'thing6':{'value': name},
+            'thing8':{'value': address},
+        }
+        page = '/pages/repairList/repairList?sort=wodepaidan&name=我的派单'
+        WeChat.sendSubscribeMessage(self.getAccessToken(), openid, template_id, page, data)

+ 6 - 1
apps/tenant/repair_order/views.py

@@ -15,7 +15,8 @@ from .models import RepairOrder, RepairOrderRecord
 from .filters import RepairOrderFilter
 from apps.tenant import tenant_log
 from apps.log.models import BizLog
-from apps.tenant.employee.serializers import Employee, EmployeeSerializer
+from apps.tenant.employee.serializers import Employee, EmployeeSerializer,User
+from apps.wxapp.models import CustomerWechat
 
 class DictView(APIView):
     permission_classes = [IsTenantUser, ]
@@ -100,6 +101,10 @@ class RepairOrderViewSet(CustomModelViewSet):
                 if not instance.status == settings.CHECKED:
                     return response_ok('当前报修工单状态非待派单状态,不能进行派单!')
                 instance.dispatch_repair_order(user, user_ids)
+            if user.id != user_ids:
+                user = User.objects.filter(id=user_ids).first()
+                CustomerWechat.sendDispatchMsg(user, instance.user.employee.name, instance.device_address,
+                                            instance.fault_des, instance.create_time, instance.no)
         except CustomError as e:
             return response_error(e.get_error_msg())
         except Exception as e:

+ 15 - 0
apps/wxapp/models.py

@@ -102,3 +102,18 @@ class CustomerWechat(models.Model):
         if wechat_customer:
             applet= WechatApplet.objects.filter(authorizer_appid=settings.WEAPP['appid']).first()
             applet.sendWaitCheckMsg(wechat_customer.openid, name, address, fault_des, no)
+
+    @staticmethod
+    def sendDispatchMsg(user, name, address, fault_des, time, no):
+        """
+        :param user: 接收人
+        :param name: 下单人姓名
+        :param address: 地址
+        :param fault_des: 描述
+        :param no: 单号
+        :param time: 报修时间
+        """
+        wechat_customer = CustomerWechat.objects.filter(customer__user=user).first()
+        if wechat_customer:
+            applet= WechatApplet.objects.filter(authorizer_appid=settings.WEAPP['appid']).first()
+            applet.sendDispatchMsg(wechat_customer.openid, name, address, fault_des, time, no)

+ 4 - 2
apps/wxapp/serializers.py

@@ -56,7 +56,8 @@ class WechatLoginSerializer(serializers.Serializer):
                 'face': customer_wechat.customer.face,
                 'user_type': customer_wechat.customer.type,  # 用户类别,1为平台管理员,2为管理者,3检修人,4报修人
                 'forbid_baoxiu': 'true' and customer_wechat.customer.status == Employee.DISABLE or 'false',  # 是否禁用报修,
-                'emplate_id': [settings.WEAPP['message_template_finish'],settings.WEAPP['message_template_wait_check'],],
+                'emplate_id': [settings.WEAPP['message_template_finish'],settings.WEAPP['message_template_wait_check'],
+                               settings.WEAPP['message_template_dispatch'],],
             }
 
         else:
@@ -91,7 +92,8 @@ class WechatBindSerializer(serializers.Serializer):
                 'user_type': customer.type,  # 用户类别,1为平台管理员,2为管理者,3检修人,4报修人
                 'forbid_baoxiu': 'true' and customer.status == Employee.DISABLE or 'false',  # 是否禁用报修,
                 'tenant_id': tenant_id,
-                'emplate_id': [settings.WEAPP['message_template_finish'],settings.WEAPP['message_template_wait_check'],],
+                'emplate_id': [settings.WEAPP['message_template_finish'],settings.WEAPP['message_template_wait_check'],
+                               settings.WEAPP['message_template_dispatch'],],
             }
 
         else:

+ 1 - 0
ly_baoxiu_admin/settings.py

@@ -272,6 +272,7 @@ WEAPP = {
     'secret': '0700bb3a58cd09505e78d7c7d1781042',
     'message_template_finish': '5ucRHdj_NFmfcDVllWohAJ5OqU6bQm5EpfALxtppNBc',
     'message_template_wait_check': 'LF--h-xq5FyprUYsHCL_W3ktVgfFZI6A1cobk911j_4',
+    'message_template_dispatch': 'R7Mhwlep5ZFCJ0ehqc6WP4yveuZ34YFqMz3mVuQay1s',
 }
 #支付宝支付
 ALIPAY_SETTING11 = {