lrf402788946 3 роки тому
батько
коміт
a7be988813

+ 60 - 0
app/controller/patent/.purchase.js

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

+ 66 - 0
app/controller/patent/.sell.js

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

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

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

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

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

+ 31 - 0
app/model/patent/purchase.js

@@ -0,0 +1,31 @@
+'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 purchase = {
+  user_id: { type: ObjectId }, // 用户id
+  demand: { type: String }, // 求购专利要求
+  type: { type: String }, // 专利类型
+  purchase_type: { type: String }, // 求购类型:许可,转移,质押
+  money: { type: String }, // 预算金额
+  contacts: { type: String }, // 联系人
+  phone: { type: String }, // 手机号
+  email: { type: String }, // 邮箱
+  status: { type: String }, // 状态
+  remark: { type: String },
+};
+const schema = new Schema(purchase, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ user_id: 1 });
+schema.index({ type: 1 });
+schema.index({ purchase_type: 1 });
+schema.index({ contacts: 1 });
+schema.index({ status: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('PatentPurchase', schema, 'patent_purchase');
+};

+ 35 - 0
app/model/patent/sell.js

@@ -0,0 +1,35 @@
+'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 sell = {
+  user_id: { type: ObjectId }, // 用户id
+  create_number: { type: String }, // 申请号
+  name: { type: String }, // 专利名称
+  inventor: { type: String }, // 权利人
+  type: { type: String }, // 申请类型
+  sell_type: { type: String }, // 交易类型:许可,转移,质押
+  sell_money: { type: String }, // 交易金额
+  contacts: { type: String }, // 联系人
+  phone: { type: String }, // 手机号
+  email: { type: String }, // 邮箱
+  status: { type: String }, // 状态
+  remark: { type: String },
+};
+const schema = new Schema(sell, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ user_id: 1 });
+schema.index({ create_number: 1 });
+schema.index({ name: 1 });
+schema.index({ type: 1 });
+schema.index({ sell_type: 1 });
+schema.index({ contacts: 1 });
+schema.index({ status: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('PatentSell', schema, 'patent_sell');
+};

+ 2 - 0
app/router.js

@@ -73,4 +73,6 @@ module.exports = app => {
   require('./router/patent/disclosure')(app); // 交底表
   require('./router/patent/report')(app); // 评估报告
   require('./router/patent/notice')(app); // 消息通知
+  require('./router/patent/sell')(app); // 交易
+  require('./router/patent/purchase')(app); // 求购
 };

+ 12 - 0
app/router/patent/purchase.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'patent';
+  const target = 'purchase';
+  router.resources(target, `${profix}${vision}/${index}/${target}`, controller[index][target]); // index、create、show、destroy
+  router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, controller[index][target].update);
+};

+ 12 - 0
app/router/patent/sell.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'patent';
+  const target = 'sell';
+  router.resources(target, `${profix}${vision}/${index}/${target}`, controller[index][target]); // index、create、show、destroy
+  router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, controller[index][target].update);
+};

+ 15 - 0
app/service/patent/purchase.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 求购
+class PurchaseService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'purchase');
+    this.model = this.ctx.model.Patent.Purchase;
+  }
+}
+
+module.exports = PurchaseService;

+ 15 - 0
app/service/patent/sell.js

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