Pārlūkot izejas kodu

Merge branch 'master' of http://git.cc-lotus.info/Free-consumables/server-haocai

lrf402788946 3 gadi atpakaļ
vecāks
revīzija
bed80cdbbb

+ 3 - 0
app/controller/.examine.js

@@ -1,6 +1,7 @@
 module.exports = {
   create: {
     requestBody: [
+      "order_num",
       "personal",
       "examine_time",
       "opinion",
@@ -18,6 +19,7 @@ module.exports = {
   update: {
     params: ["!id"],
     requestBody: [
+      "order_num",
       "personal",
       "examine_time",
       "opinion",
@@ -37,6 +39,7 @@ module.exports = {
   index: {
     parameters: {
       query: {
+        order_num:'order_num',
         personal: "personal",
         mech_id: "order.mech_id",
         status: "status",

+ 2 - 0
app/controller/.market.js

@@ -4,6 +4,7 @@ module.exports = {
       "mech_id",
       "mech_name",
       "type",
+      "type_id",
       "name",
       "brief",
       "money",
@@ -21,6 +22,7 @@ module.exports = {
       "mech_id",
       "mech_name",
       "type",
+      "type_id",
       "name",
       "brief",
       "money",

+ 39 - 0
app/controller/.type.js

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

+ 12 - 0
app/controller/type.js

@@ -0,0 +1,12 @@
+'use strict';
+const meta = require("./.type.js");
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+class TypeController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.type;
+  }
+}
+module.exports = CrudController(TypeController, meta);

+ 3 - 1
app/model/examine.js

@@ -4,7 +4,8 @@ const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
 const { ObjectId } = require('mongoose').Types;
 // 审批表
 const examine = {
-  personal: { type: ObjectId }, // 审批人
+  order_num: { type: String }, // 审批单号
+  personal: { type: String }, // 审批人
   examine_time: { type: String }, // 审批时间
   opinion: { type: String }, // 审批意见
   status: { type: String }, // 审批结果 【0:待审中,1:审核通过,2:审核未通过】
@@ -16,6 +17,7 @@ const examine = {
 };
 const schema = new Schema(examine, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });
+schema.index({ order_num: 1 });
 schema.index({ personal: 1 });
 schema.index({ examine_time: 1 });
 schema.index({ status: 1 });

+ 2 - 0
app/model/market.js

@@ -7,6 +7,7 @@ const market = {
   mech_id: { type: ObjectId }, // 商户id
   mech_name: { type: String }, // 商户名称
   type: { type: String }, // 分类
+  type_id: { type: ObjectId }, // 分类id
   name: { type: String }, // 商品名称
   brief: { type: String }, // 简介
   money: { type: Number }, // 单价
@@ -19,6 +20,7 @@ schema.index({ id: 1 });
 schema.index({ mech_id: 1 });
 schema.index({ mech_name: 1 });
 schema.index({ type: 1 });
+schema.index({ type_id: 1 });
 schema.index({ name: 1 });
 schema.index({ money: 1 });
 schema.index({ status: 1 });

+ 20 - 0
app/model/type.js

@@ -0,0 +1,20 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+const { ObjectId } = require('mongoose').Types;
+// 商品类型
+const type = {
+  code: { type: String }, // 类别code
+  name: { type: String }, // 名称
+  remark: { type: String },
+};
+const schema = new Schema(type, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ code: 1 });
+schema.index({ name: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model("Type", schema, "type");
+};

+ 7 - 6
app/router.js

@@ -3,10 +3,11 @@
 /**
  * @param {Egg.Application} app - egg application
  */
-module.exports = app => {
+module.exports = (app) => {
   const { router, controller } = app;
-  router.get('/', controller.home.index);
-  require('./z_router/user')(app); // 用户
-  require('./z_router/market')(app); // 商品
-  require('./z_router/examine')(app); // 审批
-};
+  router.get("/", controller.home.index);
+  require("./z_router/user")(app); // 用户
+  require("./z_router/type")(app); // 商类型
+  require("./z_router/market")(app); // 商品
+  require("./z_router/examine")(app); // 审批
+};;

+ 15 - 0
app/service/type.js

@@ -0,0 +1,15 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 类型
+class TypeService extends CrudService {
+  constructor(ctx) {
+    super(ctx, "type");
+    this.model = this.ctx.model.Type;
+  }
+}
+
+module.exports = TypeService;

+ 10 - 0
app/z_router/type.js

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

+ 17 - 0
ecosystem.config.js

@@ -0,0 +1,17 @@
+'use strict';
+
+const app = 'service-haocai';
+module.exports = {
+  apps: [{
+    name: app, // 应用名称
+    script: './server.js', // 实际启动脚本
+    out: `./logs/${app}.log`,
+    error: `./logs/${app}.err`,
+    watch: [ // 监控变化的目录,一旦变化,自动重启
+      'app', 'config',
+    ],
+    env: {
+      NODE_ENV: 'production', // 环境参数,当前指定为生产环境
+    },
+  }],
+};

+ 9 - 0
server.js

@@ -0,0 +1,9 @@
+
+// eslint-disable-next-line strict
+const egg = require('egg');
+
+const workers = Number(process.argv[2] || require('os').cpus().length);
+egg.startCluster({
+  workers,
+  baseDir: __dirname,
+});