liuyu 4 년 전
부모
커밋
ff6a391007
7개의 변경된 파일127개의 추가작업 그리고 1개의 파일을 삭제
  1. 55 0
      app/controller/.message.js
  2. 16 0
      app/controller/message.js
  3. 8 0
      app/controller/weixin.js
  4. 24 0
      app/model/message.js
  5. 4 0
      app/router.js
  6. 12 0
      app/service/message.js
  7. 8 1
      app/service/weixin.js

+ 55 - 0
app/controller/.message.js

@@ -0,0 +1,55 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "openid",
+      "name",
+      "title",
+      "detail",
+      "date",
+      "remark",
+      "status",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "openid",
+      "name",
+      "title",
+      "detail",
+      "date",
+      "remark",
+      "status",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        openid:  "openid",
+        name: "name",
+        title: "title",
+        detail: "detail",
+        date: "date",
+        remark: "remark",
+        status: "status",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 16 - 0
app/controller/message.js

@@ -0,0 +1,16 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.message.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 消息管理
+class MessageController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.message;
+  }
+}
+
+module.exports = CrudController(MessageController, meta);

+ 8 - 0
app/controller/weixin.js

@@ -124,6 +124,14 @@ class WeixinController extends Controller {
         // TODO: 重定性页面
         // TODO: 重定性页面
         console.log('22222---?' + to_uri);
         console.log('22222---?' + to_uri);
         this.ctx.redirect(to_uri);
         this.ctx.redirect(to_uri);
+      } else if (type === '9') {
+        if (user) {
+          const token = await this.ctx.service.login.createJwt(user);
+          const to_uri = urljoin(redirect_uri, `?openid=${openid}&type=${type}&token=${token}`);
+          // TODO: 重定性页面
+          console.log('99999---?' + to_uri);
+          this.ctx.redirect(to_uri);
+        }
       }
       }
     }
     }
 
 

+ 24 - 0
app/model/message.js

@@ -0,0 +1,24 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 消息表
+const MessageSchema = {
+  openid: { type: String, required: false, maxLength: 200 }, // openid
+  name: { type: String, required: false, maxLength: 200 }, // openid
+  title: { type: String, required: false, maxLength: 200 }, // 标题
+  detail: { type: String, required: false, maxLength: 200 }, // 详细
+  date: { type: String, required: false, maxLength: 200 }, // 时间
+  remark: { type: String, required: false, maxLength: 200 }, // 备注
+  status: { type: String, required: false, default: '0' }, // 状态 0、未读 1、已读
+};
+
+
+const schema = new Schema(MessageSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Message', schema, 'message');
+};

+ 4 - 0
app/router.js

@@ -510,4 +510,8 @@ module.exports = app => {
   // 学校上传任务表设置路由
   // 学校上传任务表设置路由
   router.resources('job', '/api/train/job', controller.job); // index、create、show、destroy
   router.resources('job', '/api/train/job', controller.job); // index、create、show、destroy
   router.post('job', '/api/train/job/update/:id', controller.job.update);
   router.post('job', '/api/train/job/update/:id', controller.job.update);
+
+  // 消息表设置路由
+  router.resources('message', '/api/train/message', controller.message); // index、create、show、destroy
+  router.post('message', '/api/train/message/update/:id', controller.message.update);
 };
 };

+ 12 - 0
app/service/message.js

@@ -0,0 +1,12 @@
+'use strict';
+
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+
+class MessageService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'message');
+    this.model = this.ctx.model.Message;
+  }
+}
+
+module.exports = MessageService;

+ 8 - 1
app/service/weixin.js

@@ -186,7 +186,14 @@ class WeixinAuthService extends AxiosService {
     const url = this.ctx.app.config.sendDirMq + this.ctx.app.config.appid;
     const url = this.ctx.app.config.sendDirMq + this.ctx.app.config.appid;
     let _url = '';
     let _url = '';
     if (tourl) {
     if (tourl) {
-      _url = this.ctx.app.config.baseUrl + '/api/train/auth?state=1&redirect_uri=' + this.ctx.app.config.baseUrl + '/classinfo/&type=template&objid=' + tourl;
+      _url = this.ctx.app.config.baseUrl + '/api/train/auth?state=1&redirect_uri=' + this.ctx.app.config.baseUrl + '/classinfo/&type=9&objid=' + tourl;
+      // 需要回执的时候进行保存处理
+      // 通过openid取得用户基本信息
+      const user = await this.ctx.model.User.findOne({ openid });
+      if (user) {
+        const newdata = { openid, name: user.name, title: first, detail: keyword1, date: keyword2, remark, status: '0' };
+        await this.ctx.model.Message.create(newdata);
+      }
     }
     }
     const requestData = { // 发送模板消息的数据
     const requestData = { // 发送模板消息的数据
       touser: openid,
       touser: openid,