lrf402788946 4 years ago
parent
commit
c76df4e47a
2 changed files with 17 additions and 2 deletions
  1. 1 1
      app/service/patient.js
  2. 16 1
      app/service/weixin.js

+ 1 - 1
app/service/patient.js

@@ -36,7 +36,7 @@ class PatientService extends CrudService {
   async create(data) {
     const { name, tel, openid, groupid } = data;
     assert(name, '患者名称不能为空');
-    assert(tel, '患者电话不能为空');
+    // assert(tel, '患者电话不能为空');
     assert(openid, '微信openid不能为空');
     assert(groupid, '缺少群信息项');
 

+ 16 - 1
app/service/weixin.js

@@ -70,7 +70,22 @@ class WeixinAuthService extends AxiosService {
     if (fqueries)fqueries = JSON.parse(fqueries);
     let { redirect_uri, groupid, doctorid } = fqueries;
     let queryStr = `?openid=${openid}`;
-    if (groupid) queryStr = `${queryStr}&groupid=${groupid}`;
+    // TODO 验证redirect_uri,如果有groupid,type=group=>用户入驻,直接处理
+    if (groupid) {
+      if (redirect_uri.includes('type=group')) {
+        // TODO加用户,进组
+        const udata = { name: object.nickname, icon: object.headimgurl, openid: object.openid, groupid };
+        try {
+          await this.ctx.service.patient.create(udata);
+        } catch (error) {
+          this.logger.error(error);
+        }
+      } else {
+        // TODO 点击进入群组聊天,不过没改也没加
+        queryStr = `${queryStr}&groupid=${groupid}`;
+
+      }
+    }
     if (doctorid) queryStr = `${queryStr}&doctorid=${doctorid}`;
     redirect_uri = urljoin(redirect_uri, queryStr);
     this.ctx.redirect(redirect_uri);