guhongwei 3 years ago
parent
commit
9b858d1260

+ 43 - 0
app/controller/patent/.patent_order.js

@@ -0,0 +1,43 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "user_id",
+      "status",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "user_id",
+      "status",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        user_id: "user_id",
+        status: "status",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 13 - 0
app/controller/patent/patent_order.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.patent_order.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 交易订单
+class PatentorderController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.patent.patent_order;
+  }
+}
+module.exports = CrudController(PatentorderController, meta);

+ 21 - 0
app/model/patent/patent_order.js

@@ -0,0 +1,21 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+// 交易订单表
+const patentorder = {
+  user_id: { type: ObjectId }, // 用户id
+  status: { type: String }, // 状态
+  remark: { type: String },
+};
+const schema = new Schema(patentorder, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ user_id: 1 });
+schema.index({ status: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('PatentOrder', schema, 'patent_order');
+};

+ 1 - 0
app/router.js

@@ -75,4 +75,5 @@ module.exports = app => {
   require('./router/patent/notice')(app); // 消息通知
   require('./router/patent/sell')(app); // 交易
   require('./router/patent/purchase')(app); // 求购
+  require('./router/patent/patent_order')(app); // 交易订单
 };

+ 16 - 0
app/service/patent/patent_order.js

@@ -0,0 +1,16 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const { ObjectId } = require('mongoose').Types;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 交易订单
+class PatentorderService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'patent_order');
+    this.model = this.ctx.model.Patent.patent_order;
+  }
+}
+
+module.exports = PatentorderService;