lrf402788946 4 년 전
부모
커밋
96b2eb28f1
37개의 변경된 파일1738개의 추가작업 그리고 804개의 파일을 삭제
  1. 75 0
      app/controller/cysci/.policy.js
  2. 68 0
      app/controller/cysci/.policy_apply.js
  3. 87 0
      app/controller/cysci/.policy_order.js
  4. 58 0
      app/controller/cysci/.ticket.js
  5. 39 0
      app/controller/cysci/.ticket_record.js
  6. 13 0
      app/controller/cysci/policy.js
  7. 13 0
      app/controller/cysci/policy_apply.js
  8. 13 0
      app/controller/cysci/policy_order.js
  9. 17 0
      app/controller/cysci/ticket.js
  10. 13 0
      app/controller/cysci/ticket_record.js
  11. 79 55
      app/controller/statistics/index.js
  12. 102 99
      app/controller/users/.organization.js
  13. 43 0
      app/middleware/policy_apply.js
  14. 48 47
      app/model/organization.js
  15. 37 0
      app/model/policy.js
  16. 32 0
      app/model/policy_apply.js
  17. 43 0
      app/model/policy_order.js
  18. 29 0
      app/model/ticket.js
  19. 24 0
      app/model/ticket_record.js
  20. 50 45
      app/router.js
  21. 12 0
      app/router/cysci/policy.js
  22. 13 0
      app/router/cysci/policy_apply.js
  23. 12 0
      app/router/cysci/policy_order.js
  24. 13 0
      app/router/cysci/ticket.js
  25. 12 0
      app/router/cysci/ticket_record.js
  26. 19 16
      app/router/statistics/index.js
  27. 15 0
      app/service/cysci/policy.js
  28. 15 0
      app/service/cysci/policy_apply.js
  29. 22 0
      app/service/cysci/policy_order.js
  30. 66 0
      app/service/cysci/ticket.js
  31. 15 0
      app/service/cysci/ticket_record.js
  32. 325 258
      app/service/statistics/index.js
  33. 134 102
      app/service/util/util.js
  34. 85 85
      config/config.default.js
  35. 32 32
      config/config.prod.js
  36. 12 12
      config/plugin.js
  37. 53 53
      package.json

+ 75 - 0
app/controller/cysci/.policy.js

@@ -0,0 +1,75 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "user_id",
+      "type",
+      "name",
+      "discount_type",
+      "use_type",
+      "classify",
+      "limit_time",
+      "scale",
+      "allowance",
+      "total_allowance",
+      "unit_allowance",
+      "desc",
+      "status",
+      "remark",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "user_id",
+      "type",
+      "name",
+      "discount_type",
+      "use_type",
+      "classify",
+      "limit_time",
+      "scale",
+      "allowance",
+      "total_allowance",
+      "unit_allowance",
+      "desc",
+      "status",
+      "remark",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        user_id: "user_id",
+        name: "name",
+        type: "type",
+        discount_type: "discount_type",
+        use_type: "use_type",
+        classify: "classify",
+        limit_time: "limit_time",
+        status: "status",
+        "create_time@start": "meta.createdAt@start",
+        "create_time@end": "meta.createdAt@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 68 - 0
app/controller/cysci/.policy_apply.js

@@ -0,0 +1,68 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "user_id",
+      "policy_id",
+      "company",
+      "apply_personal",
+      "phone",
+      "qyfr",
+      "yyzz",
+      "qylr",
+      "record",
+      "status",
+      "remark",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "user_id",
+      "policy_id",
+      "company",
+      "apply_personal",
+      "phone",
+      "qyfr",
+      "yyzz",
+      "qylr",
+      "record",
+      "status",
+
+      "remark",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        user_id: "user_id",
+        policy_id: "policy_id",
+        company: "company",
+        apply_personal: "apply_personal",
+        phone: "phone",
+        status: "status",
+        "create_time@start": "meta.createdAt@start",
+        "create_time@end": "meta.createdAt@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 87 - 0
app/controller/cysci/.policy_order.js

@@ -0,0 +1,87 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "user_id",
+      "policy_id",
+      "apply_id",
+      "policy_user_type",
+      "req_desc",
+      "name",
+      "no",
+      "person",
+      "phone",
+      "email",
+      "mechanism_id",
+      "mechanism_person",
+      "mechanism_mobile",
+      "money",
+      "allowance",
+      "total",
+      "remark",
+      "user_name",
+      "mechanism_name",
+      "status",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "user_id",
+      "policy_id",
+      "apply_id",
+      "policy_user_type",
+      "req_desc",
+      "name",
+      "no",
+      "person",
+      "phone",
+      "email",
+      "mechanism_id",
+      "mechanism_person",
+      "mechanism_mobile",
+      "money",
+      "allowance",
+      "total",
+      "remark",
+      "user_name",
+      "mechanism_name",
+      "status",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        user_id: "user_id",
+        policy_id: "policy_id",
+        apply_id: "apply_id",
+        person: "person",
+        name: "name",
+        mechanism_id: "mechanism_id",
+        user_name: "user_name",
+        mechanism_name: "mechanism_name",
+        "create_time@start": "create_time@start",
+        "create_time@end": "create_time@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 58 - 0
app/controller/cysci/.ticket.js

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

+ 39 - 0
app/controller/cysci/.ticket_record.js

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

+ 13 - 0
app/controller/cysci/policy.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.policy.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 高企政策服务
+class PolicyController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.cysci.policy;
+  }
+}
+module.exports = CrudController(PolicyController, meta);

+ 13 - 0
app/controller/cysci/policy_apply.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.policy_apply.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 高企服务政策申请
+class Policy_applyController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.cysci.policyApply;
+  }
+}
+module.exports = CrudController(Policy_applyController, meta);

+ 13 - 0
app/controller/cysci/policy_order.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.policy_order.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 高企政策服务订单
+class Policy_orderController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.cysci.policyOrder;
+  }
+}
+module.exports = CrudController(Policy_orderController, meta);

+ 17 - 0
app/controller/cysci/ticket.js

@@ -0,0 +1,17 @@
+'use strict';
+const meta = require('./.ticket.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 高企申报
+class TicketController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.cysci.ticket;
+  }
+  async index() {
+    const { data, total } = await this.service.query(this.ctx.query);
+    this.ctx.ok({ data, total });
+  }
+}
+module.exports = CrudController(TicketController, meta);

+ 13 - 0
app/controller/cysci/ticket_record.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.ticket_record.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 创新券记录表
+class Ticket_recordController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.cysci.ticketRecord;
+  }
+}
+module.exports = CrudController(Ticket_recordController, meta);

+ 79 - 55
app/controller/statistics/index.js

@@ -1,55 +1,79 @@
-'use strict';
-const Controller = require('egg').Controller;
-const { CrudController } = require('naf-framework-mongoose/lib/controller');
-
-// 首页-数据动态统计
-class IndexController extends Controller {
-  constructor(ctx) {
-    super(ctx);
-    this.service = this.ctx.service.statistics.index;
-  }
-  async index() {
-    const patent = await this.service.patent(this.ctx.query);
-    const product = await this.service.product(this.ctx.query);
-    const expert = await this.service.expert(this.ctx.query);
-    const circle = await this.service.circle(this.ctx.query);
-    this.ctx.ok({ data: { patent, product, expert, circle } });
-  }
-
-  /**
-   * 首页专利统计
-   */
-  async patent() {
-    const data = await this.service.patent(this.ctx.query);
-    this.ctx.ok({ data });
-  }
-
-  /**
-   * 首页成果统计
-   */
-  async product() {
-    const data = await this.service.product(this.ctx.query);
-    this.ctx.ok({ data });
-  }
-
-  /**
-   * 首页成果统计
-   */
-  async expert() {
-    const data = await this.service.expert(this.ctx.query);
-    this.ctx.ok({ data });
-  }
-  /**
-   * 首页数据统计
-   */
-  async circle() {
-    const data = await this.service.circle(this.ctx.query);
-    this.ctx.ok({ data });
-  }
-
-  async dockIndex() {
-    const res = await this.service.dockIndex(this.ctx.query);
-    this.ctx.ok({ data: res });
-  }
-}
-module.exports = CrudController(IndexController, {});
+'use strict';
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 首页-数据动态统计
+class IndexController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.statistics.index;
+  }
+  async index() {
+    const patent = await this.service.patent(this.ctx.query);
+    const product = await this.service.product(this.ctx.query);
+    const expert = await this.service.expert(this.ctx.query);
+    const circle = await this.service.circle(this.ctx.query);
+    this.ctx.ok({ data: { patent, product, expert, circle } });
+  }
+
+  /**
+   * 首页专利统计
+   */
+  async patent() {
+    const data = await this.service.patent(this.ctx.query);
+    this.ctx.ok({ data });
+  }
+
+  /**
+   * 首页成果统计
+   */
+  async product() {
+    const data = await this.service.product(this.ctx.query);
+    this.ctx.ok({ data });
+  }
+
+  /**
+   * 首页成果统计
+   */
+  async expert() {
+    const data = await this.service.expert(this.ctx.query);
+    this.ctx.ok({ data });
+  }
+  /**
+   * 首页数据统计
+   */
+  async circle() {
+    const data = await this.service.circle(this.ctx.query);
+    this.ctx.ok({ data });
+  }
+
+  async dockIndex() {
+    const res = await this.service.dockIndex(this.ctx.query);
+    this.ctx.ok({ data: res });
+  }
+
+  /**
+   * 企业数量统计
+   */
+  async orgCount() {
+    const res = await this.ctx.service.users.organization.count(this.ctx.query);
+    this.ctx.ok({ data: res });
+  }
+
+  /**
+   * 创新券申请统计
+   */
+  async policyApplyCount() {
+    const data = await this.service.pac();
+    this.ctx.ok({ data });
+  }
+
+  /**
+   * 高企申报个步骤统计
+   */
+  async ticketCount() {
+    const data = await this.service.ticket();
+    this.ctx.ok({ data });
+  }
+}
+module.exports = CrudController(IndexController, {});

+ 102 - 99
app/controller/users/.organization.js

@@ -1,99 +1,102 @@
-module.exports = {
-  create: {
-    requestBody: [
-      "!name",
-      "!password",
-      "phone",
-      "email",
-      "addr",
-      "code",
-      "office_phone",
-      "profession",
-      'institution_code',
-      'companytype',
-      'companydate',
-      'companycapital',
-      'companyperson',
-      'sndqyzsr',
-      'sndyffy',
-      'companytotal',
-      'zjzyfrs',
-      'companybrief',
-      'mainproduct',
-      'qualifications',
-      'remark',
-      'status',
-    ],
-  },
-  destroy: {
-    params: ["!id"],
-    service: "delete",
-  },
-  update: {
-    params: ["!id"],
-    requestBody: [
-      "name",
-      "phone",
-      "email",
-      "addr",
-      "code",
-      "office_phone",
-      "profession",
-      'institution_code',
-      'companytype',
-      'companydate',
-      'companycapital',
-      'companyperson',
-      'sndqyzsr',
-      'sndyffy',
-      'companytotal',
-      'zjzyfrs',
-      'companybrief',
-      'mainproduct',
-      'qualifications',
-      'remark',
-      'status'
-    ],
-  },
-  show: {
-    parameters: {
-      params: ["!id"],
-    },
-    service: "fetch",
-  },
-  index: {
-    parameters: {
-      query: {
-        phone:"phone",
-        code:"code",
-        profession:"profession",
-        institution_code:"institution_code",
-        companyperson:"companyperson",
-        status:"status",
-        "create_time@start": "create_time@start",
-        "create_time@end": "create_time@end",
-      },
-      options: {
-        "isdel": '0' // 默认条件
-      },
-    },
-    service: "query",
-    options: {
-      query: ["skip", "limit"],
-      sort: ["meta.createdAt"],
-      desc: true,
-      count: true,
-    },
-  },
-  //修改密码
-  password: {
-    params: ["!id"],
-    requestBody: ["password"],
-    service: "password",
-  },
-  // 登陆
-  login: {
-    requestBody: ["institution_code", "password"],
-    service: "login",
-  }
-};
+module.exports = {
+  create: {
+    requestBody: [
+      "!name",
+      "!password",
+      "phone",
+      "email",
+      "addr",
+      "code",
+      "office_phone",
+      "profession",
+      "institution_code",
+      "companytype",
+      "companydate",
+      "companycapital",
+      "companyperson",
+      "sndqyzsr",
+      "sndyffy",
+      "companytotal",
+      "zjzyfrs",
+      "companybrief",
+      "mainproduct",
+      "qualifications",
+      "remark",
+      "juris",
+      "status",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "name",
+      "phone",
+      "email",
+      "addr",
+      "code",
+      "office_phone",
+      "profession",
+      "institution_code",
+      "companytype",
+      "companydate",
+      "companycapital",
+      "companyperson",
+      "sndqyzsr",
+      "sndyffy",
+      "companytotal",
+      "zjzyfrs",
+      "companybrief",
+      "mainproduct",
+      "qualifications",
+      "juris",
+      "remark",
+      "status",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        phone: "phone",
+        code: "code",
+        profession: "profession",
+        institution_code: "institution_code",
+        companyperson: "companyperson",
+        status: "status",
+        juris: "juris",
+        "create_time@start": "create_time@start",
+        "create_time@end": "create_time@end",
+      },
+      options: {
+        isdel: "0", // 默认条件
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+  //修改密码
+  password: {
+    params: ["!id"],
+    requestBody: ["password"],
+    service: "password",
+  },
+  // 登陆
+  login: {
+    requestBody: ["institution_code", "password"],
+    service: "login",
+  },
+};

+ 43 - 0
app/middleware/policy_apply.js

@@ -0,0 +1,43 @@
+'use strict';
+const _ = require('lodash');
+
+const idToData = async (ctx, id) => {
+  let res = await ctx.service.cysci.policy.fetch({ id });
+  if (res) {
+    res = JSON.parse(JSON.stringify(res));
+    const { user_id } = res;
+    if (user_id) {
+      const user = await ctx.model.Admin.findById(user_id);
+      if (user) res.user = user;
+    }
+  }
+  return res;
+};
+
+module.exports = options => {
+  return async function policyApply(ctx, next) {
+    console.log('function in policy_apply middleware');
+    const request = ctx.request;
+    await next();
+    const { method } = request;
+    if (method === 'GET') {
+      // 处理get的时policy_id换成对应的数据
+      let { data } = ctx.body;
+      data = JSON.parse(JSON.stringify(data));
+      if (_.isArray(data)) {
+        // 数组,多个,循环查
+        for (const i of data) {
+          const { policy_id } = i;
+          const res = await idToData(ctx, policy_id);
+          if (res)i.policy = res;
+        }
+      } else if (_.isObject(data)) {
+        // 一个,找完就完事
+        const { policy_id } = data;
+        const res = await idToData(ctx, policy_id);
+        if (res) data.policy = res;
+      }
+      ctx.body.data = data;
+    }
+  };
+};

+ 48 - 47
app/model/organization.js

@@ -1,47 +1,48 @@
-'use strict';
-const Schema = require('mongoose').Schema;
-const moment = require('moment');
-const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
-const { Secret } = require('naf-framework-mongoose/lib/model/schema');
-
-// 机构表
-const organization = {
-  name: { type: String, required: true, maxLength: 200 }, // 用户名
-  password: { type: Secret, required: true, select: false }, // 登录密码
-  phone: { type: String, required: false, maxLength: 200 }, // 电话号码
-  email: { type: String, required: false, maxLength: 200 }, // 邮箱
-  addr: { type: String, required: false, maxLength: 500 }, // 地址
-  office_phone: { type: String, required: false, maxLength: 500 }, // 办公电话
-  profession: { type: String, required: false, maxLength: 500 }, // 所属行业
-  institution_code: { type: String, required: false, maxLength: 500 }, // 机构代码
-  code: { type: String, required: false, default: 'INVESTORS' }, // 邀请码
-
-  companytype: { type: String, required: false, maxLength: 300 }, // 注册类型
-  companydate: { type: String, required: false, maxLength: 300 }, // 注册时间
-  companycapital: { type: String, required: false, maxLength: 300 }, // 注册资金
-  companyperson: { type: String, required: false, maxLength: 300 }, // 企业法人
-  sndqyzsr: { type: String, required: false, maxLength: 300 }, // 上年度企业总收入
-  sndyffy: { type: String, required: false, maxLength: 300 }, // 上年度研发费用
-  companytotal: { type: String, required: false, maxLength: 300 }, // 企业总人数
-  zjzyfrs: { type: String, required: false, maxLength: 300 }, // 专&兼职研发人数
-  companybrief: { type: String, required: false }, // 企业简介
-  mainproduct: { type: String, required: false, maxLength: 300 }, // 主要产品
-  qualifications: { type: String, required: false, maxLength: 300 }, // 企业资质&荣誉
-  status: { type: String, required: false, default: '0', maxLength: 200 }, // 审核状态,0-注册,1-通过,2-拒绝
-
-  isdel: { type: String, required: false, default: '0' }, // 0=>未删除;1=>已删除
-  remark: { type: String, maxLength: 200 },
-  create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
-};
-const schema = new Schema(organization, { toJSON: { virtuals: true } });
-schema.index({ id: 1 });
-schema.index({ phone: 1 });
-schema.index({ profession: 1 });
-schema.index({ institution_code: 1 });
-schema.index({ companyperson: 1 });
-schema.index({ 'meta.createdAt': 1 });
-schema.plugin(metaPlugin);
-module.exports = app => {
-  const { mongoose } = app;
-  return mongoose.model('Organization', schema, 'organization');
-};
+'use strict';
+const Schema = require('mongoose').Schema;
+const moment = require('moment');
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { Secret } = require('naf-framework-mongoose/lib/model/schema');
+
+// 机构表
+const organization = {
+  name: { type: String, required: true, maxLength: 200 }, // 用户名
+  password: { type: Secret, required: true, select: false }, // 登录密码
+  phone: { type: String, required: false, maxLength: 200 }, // 电话号码
+  email: { type: String, required: false, maxLength: 200 }, // 邮箱
+  addr: { type: String, required: false, maxLength: 500 }, // 地址
+  office_phone: { type: String, required: false, maxLength: 500 }, // 办公电话
+  profession: { type: String, required: false, maxLength: 500 }, // 所属行业
+  institution_code: { type: String, required: false, maxLength: 500 }, // 机构代码
+  code: { type: String, required: false, default: 'INVESTORS' }, // 邀请码
+
+  companytype: { type: String, required: false, maxLength: 300 }, // 注册类型
+  companydate: { type: String, required: false, maxLength: 300 }, // 注册时间
+  companycapital: { type: String, required: false, maxLength: 300 }, // 注册资金
+  companyperson: { type: String, required: false, maxLength: 300 }, // 企业法人
+  sndqyzsr: { type: String, required: false, maxLength: 300 }, // 上年度企业总收入
+  sndyffy: { type: String, required: false, maxLength: 300 }, // 上年度研发费用
+  companytotal: { type: String, required: false, maxLength: 300 }, // 企业总人数
+  zjzyfrs: { type: String, required: false, maxLength: 300 }, // 专&兼职研发人数
+  companybrief: { type: String, required: false }, // 企业简介
+  mainproduct: { type: String, required: false, maxLength: 300 }, // 主要产品
+  qualifications: { type: String, required: false, maxLength: 300 }, // 企业资质&荣誉
+  status: { type: String, required: false, default: '0', maxLength: 200 }, // 审核状态,0-注册,1-通过,2-拒绝
+  juris: { type: String }, // 辖区
+
+  isdel: { type: String, required: false, default: '0' }, // 0=>未删除;1=>已删除
+  remark: { type: String, maxLength: 200 },
+  create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
+};
+const schema = new Schema(organization, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ phone: 1 });
+schema.index({ profession: 1 });
+schema.index({ institution_code: 1 });
+schema.index({ companyperson: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Organization', schema, 'organization');
+};

+ 37 - 0
app/model/policy.js

@@ -0,0 +1,37 @@
+'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 policy = {
+  user_id: { type: ObjectId }, // 创建者id
+  type: { type: String }, // 0-研发补贴,1-奖励兑现,2-创新券
+  name: { type: String }, // 名称
+  discount_type: { type: String }, // 折扣类型: 全额折扣券;折扣券;定额折扣券
+  use_type: { type: String }, // 使用服务类型
+  classify: { type: String }, // 所属分类
+  limit_time: { type: String }, // 期限
+  scale: { type: String }, // 抵扣比例-为折扣券
+  allowance: { type: String }, // 面额
+  total_allowance: { type: String }, // 券总额度
+  unit_allowance: { type: String }, // 单个企业/团队最大额度
+  desc: { type: String }, // 描述
+  status: { type: String, default: '0' }, // 0:待上架;1:上架;-1:下架
+  remark: { type: String },
+};
+const schema = new Schema(policy, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ user_id: 1 });
+schema.index({ type: 1 });
+schema.index({ name: 1 });
+schema.index({ discount_type: 1 });
+schema.index({ use_type: 1 });
+schema.index({ classify: 1 });
+schema.index({ limit_time: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Policy', schema, 'policy');
+};

+ 32 - 0
app/model/policy_apply.js

@@ -0,0 +1,32 @@
+'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 policy_apply = {
+  user_id: { type: ObjectId }, // 申请人id
+  policy_id: { type: ObjectId }, // 创新券id
+  company: { type: String }, // 申请企业
+  apply_personal: { type: String }, // 申请人
+  phone: { type: String }, // 联系电话
+  qyfr: { type: Array }, // 企业法人
+  yyzz: { type: Array }, // 营业执照
+  qylr: { type: Array }, // 企业利润表
+  record: { type: Array }, // 审核记录
+  remark: { type: String },
+  status: { type: String, default: '0' }, // 0-待处理;1-已通过;2已拒绝
+};
+const schema = new Schema(policy_apply, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ user_id: 1 });
+schema.index({ policy_id: 1 });
+schema.index({ company: 1 });
+schema.index({ apply_personal: 1 });
+schema.index({ phone: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Policy_apply', schema, 'policy_apply');
+};

+ 43 - 0
app/model/policy_order.js

@@ -0,0 +1,43 @@
+'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 policy_order = {
+  user_id: { type: ObjectId }, // 申请用户,需求机构名称
+  policy_id: { type: ObjectId }, // 创新券id
+  apply_id: { type: ObjectId }, // 申请id
+  policy_user_type: { type: String }, // 创新券使用服务类型
+  req_desc: { type: String }, // 需求描述
+  name: { type: String }, // 订单名称
+  no: { type: String, unique: true }, // 订单号,时间戳
+  user_name: { type: String }, // 需方机构名称
+  person: { type: String }, // 申请人
+  phone: { type: String }, // 联系电话
+  email: { type: String }, // 电子邮箱
+  mechanism_id: { type: ObjectId }, // 服务机构,申请中的票子的user._id
+  mechanism_name: { type: String }, // 服务机构
+  mechanism_person: { type: String }, // 服务机构联系人,user的name
+  mechanism_mobile: { type: String }, // 服务机构联系人,user的mobile
+  money: { type: Number }, // 订单总金额
+  allowance: { type: Number }, // 券抵扣金额
+  total: { type: Number }, // 应收金额
+  remark: { type: String }, // 备注
+  status: { type: String, default: '0' }, // 0-待确认;1-确认订单;2-取消订单
+};
+const schema = new Schema(policy_order, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ user_id: 1 });
+schema.index({ policy_id: 1 });
+schema.index({ apply_id: 1 });
+schema.index({ name: 1 });
+schema.index({ mechanism_id: 1 });
+schema.index({ user_name: 1 });
+schema.index({ mechanism_name: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Policy_order', schema, 'policy_order');
+};

+ 29 - 0
app/model/ticket.js

@@ -0,0 +1,29 @@
+'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 ticket = {
+  user_id: { type: ObjectId }, // 用户id
+  mechanism_id: { type: ObjectId }, // 中介机构id
+  material: { type: Array }, // 审核资料
+  medium_material: { type: Array }, // 中介机构审核资料
+  contract: { type: Array }, // 合同
+  status: { type: String, default: '0' },
+  // 0-初审;
+  // 1-初审通过(企业,中介上传合同);-1-初审失败;
+  // 2-高企申报成功;-2:高企申报失败
+  remark: { type: String },
+  create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
+};
+const schema = new Schema(ticket, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ status: 1 });
+schema.index({ user_id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Ticket', schema, 'ticket');
+};

+ 24 - 0
app/model/ticket_record.js

@@ -0,0 +1,24 @@
+'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 ticket_record = {
+  ticket_id: { type: ObjectId },
+  opera_id: { type: ObjectId }, // 审核人
+  status: { type: String }, // 改变为的状态
+  desc: { type: String }, // 建议
+  remark: { type: String },
+  create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
+};
+const schema = new Schema(ticket_record, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ ticket_id: 1 });
+schema.index({ status: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Ticket_record', schema, 'ticket_record');
+};

+ 50 - 45
app/router.js

@@ -1,45 +1,50 @@
-'use strict';
-
-/**
- * @param {Egg.Application} app - egg application
- */
-module.exports = app => {
-  const { router, controller } = app;
-  router.get('/', controller.home.index);
-  const profix = '/api/live/';
-  const vision = 'v0';
-  router.post(`${profix}${vision}/util`, controller.home.utilMethod);
-  router.post(`${profix}${vision}/spm`, controller.home.spm);
-  router.get(`${profix}${vision}/index`, controller.home.indexQuery);
-  require('./router/users/admin')(app); // 管理员
-  require('./router/users/personal')(app); // 个人用户
-  require('./router/users/organization')(app); // 机构用户
-  require('./router/users/expert')(app); // 专家用户
-  require('./router/users/product')(app); // 产品
-  require('./router/users/person_room')(app); // 个人聊天房间
-  require('./router/users/person_chat')(app); // 个人聊天
-  require('./router/users/question')(app); // 调研调查
-  require('./router/users/project_solic')(app); // 项目征集
-  require('./router/system/menu')(app); // 菜单
-  require('./router/system/category')(app); // 字典类别
-  require('./router/system/code')(app); // 字典
-  require('./router/system/invite_code')(app); // 邀请码
-  require('./router/system/notice')(app); // 通知管理
-  require('./router/system/survey')(app); // 建言献策,网上调查
-  require('./router/dock/index')(app); // 展会
-  require('./router/dock/dock_pw')(app); // 展会-图文
-  require('./router/dock/dock_user')(app); // 展会-用户
-  require('./router/dock/dock_chat')(app); // 展会-公共聊天
-  require('./router/dock/transaction')(app); // 交易合同+备案
-  require('./router/dock/road_show')(app); // 路演
-  require('./router/dock/channel')(app); // 科技频道
-  require('./router/dock/channel_video')(app); // 科技频道-视频
-  require('./router/dock/train_chat')(app); // 培训问诊聊天
-  require('./router/tecinfo/column')(app); // 栏目
-  require('./router/tecinfo/news')(app); // 信息
-  require('./router/dock/interview')(app); // 访谈
-  require('./router/dock/train_live')(app); // 培训问诊
-  require('./router/dock/patent')(app); // e专利
-  require('./router/tecinfo/science')(app); // 科技新闻
-  require('./router/statistics/index')(app); // 首页统计
-};
+'use strict';
+
+/**
+ * @param {Egg.Application} app - egg application
+ */
+module.exports = app => {
+  const { router, controller } = app;
+  router.get('/', controller.home.index);
+  const profix = '/api/live/';
+  const vision = 'v0';
+  router.post(`${profix}${vision}/util`, controller.home.utilMethod);
+  router.post(`${profix}${vision}/spm`, controller.home.spm);
+  router.get(`${profix}${vision}/index`, controller.home.indexQuery);
+  require('./router/users/admin')(app); // 管理员
+  require('./router/users/personal')(app); // 个人用户
+  require('./router/users/organization')(app); // 机构用户
+  require('./router/users/expert')(app); // 专家用户
+  require('./router/users/product')(app); // 产品
+  require('./router/users/person_room')(app); // 个人聊天房间
+  require('./router/users/person_chat')(app); // 个人聊天
+  require('./router/users/question')(app); // 调研调查
+  require('./router/users/project_solic')(app); // 项目征集
+  require('./router/system/menu')(app); // 菜单
+  require('./router/system/category')(app); // 字典类别
+  require('./router/system/code')(app); // 字典
+  require('./router/system/invite_code')(app); // 邀请码
+  require('./router/system/notice')(app); // 通知管理
+  require('./router/system/survey')(app); // 建言献策,网上调查
+  require('./router/dock/index')(app); // 展会
+  require('./router/dock/dock_pw')(app); // 展会-图文
+  require('./router/dock/dock_user')(app); // 展会-用户
+  require('./router/dock/dock_chat')(app); // 展会-公共聊天
+  require('./router/dock/transaction')(app); // 交易合同+备案
+  require('./router/dock/road_show')(app); // 路演
+  require('./router/dock/channel')(app); // 科技频道
+  require('./router/dock/channel_video')(app); // 科技频道-视频
+  require('./router/dock/train_chat')(app); // 培训问诊聊天
+  require('./router/tecinfo/column')(app); // 栏目
+  require('./router/tecinfo/news')(app); // 信息
+  require('./router/dock/interview')(app); // 访谈
+  require('./router/dock/train_live')(app); // 培训问诊
+  require('./router/dock/patent')(app); // e专利
+  require('./router/tecinfo/science')(app); // 科技新闻
+  require('./router/statistics/index')(app); // 首页统计
+  require('./router/cysci/policy')(app); // 高企政策
+  require('./router/cysci/policy_apply')(app); // 高企政策申请
+  require('./router/cysci/policy_order')(app); // 高企订单
+  require('./router/cysci/ticket')(app); // 高企申报
+  require('./router/cysci/ticket_record')(app); // 高企申报记录
+};

+ 12 - 0
app/router/cysci/policy.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'cysci';
+  const target = 'policy';
+  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);
+};

+ 13 - 0
app/router/cysci/policy_apply.js

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

+ 12 - 0
app/router/cysci/policy_order.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'cysci';
+  const target = 'policyOrder';
+  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);
+};

+ 13 - 0
app/router/cysci/ticket.js

@@ -0,0 +1,13 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'cysci';
+  const target = 'ticket';
+  router.post(target, `${profix}${vision}/${index}/${target}/status/:id`, controller[index][target].status);
+  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/cysci/ticket_record.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'cysci';
+  const target = 'ticketRecord';
+  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);
+};

+ 19 - 16
app/router/statistics/index.js

@@ -1,16 +1,19 @@
-'use strict';
-
-
-module.exports = app => {
-  const { router, controller } = app;
-  const profix = '/api/live/';
-  const vision = 'v0';
-  const index = 'statistics';
-  const target = 'index';
-  router.get(target, `${profix}${vision}/${index}/${target}/dockIndex`, controller[index][target].dockIndex);
-  router.get(target, `${profix}${vision}/${index}/${target}/index`, controller[index][target].index);
-  router.get(target, `${profix}${vision}/${index}/${target}/patent`, controller[index][target].patent);
-  router.get(target, `${profix}${vision}/${index}/${target}/product`, controller[index][target].product);
-  router.get(target, `${profix}${vision}/${index}/${target}/expert`, controller[index][target].expert);
-  router.get(target, `${profix}${vision}/${index}/${target}/circle`, controller[index][target].circle);
-};
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'statistics';
+  const target = 'index';
+  router.get(target, `${profix}${vision}/${index}/${target}/dockIndex`, controller[index][target].dockIndex);
+  router.get(target, `${profix}${vision}/${index}/${target}/index`, controller[index][target].index);
+  router.get(target, `${profix}${vision}/${index}/${target}/patent`, controller[index][target].patent);
+  router.get(target, `${profix}${vision}/${index}/${target}/product`, controller[index][target].product);
+  router.get(target, `${profix}${vision}/${index}/${target}/expert`, controller[index][target].expert);
+  router.get(target, `${profix}${vision}/${index}/${target}/circle`, controller[index][target].circle);
+  router.get(target, `${profix}${vision}/${index}/${target}/orgCount`, controller[index][target].orgCount);
+  router.get(target, `${profix}${vision}/${index}/${target}/pac`, controller[index][target].policyApplyCount);
+  router.get(target, `${profix}${vision}/${index}/${target}/ticket`, controller[index][target].ticketCount);
+};

+ 15 - 0
app/service/cysci/policy.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 PolicyService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'policy');
+    this.model = this.ctx.model.Policy;
+  }
+}
+
+module.exports = PolicyService;

+ 15 - 0
app/service/cysci/policy_apply.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 Policy_applyService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'policy_apply');
+    this.model = this.ctx.model.PolicyApply;
+  }
+}
+
+module.exports = Policy_applyService;

+ 22 - 0
app/service/cysci/policy_order.js

@@ -0,0 +1,22 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+const moment = require('moment');
+
+// 高企政策服务订单
+class Policy_orderService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'policy_order');
+    this.model = this.ctx.model.PolicyOrder;
+  }
+  async create(body) {
+    const stemp = `${moment().format('YYYYMMDD')}${moment().format('x')}`;
+    body.no = stemp;
+    const res = await this.model.create(body);
+    return res;
+  }
+}
+
+module.exports = Policy_orderService;

+ 66 - 0
app/service/cysci/ticket.js

@@ -0,0 +1,66 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+const { ObjectId } = require('mongoose').Types;
+
+// 高企申报
+class TicketService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'ticket');
+    this.model = this.ctx.model.Ticket;
+    this.record = this.ctx.model.TicketRecord;
+  }
+
+  async query({ skip = 0, limit = 0, ...query } = {}) {
+    const nquery = _.omit(query, [ 'name' ]);
+    if (nquery.user_id) nquery.user_id = ObjectId(nquery.user_id);
+    if (nquery.mechanism_id) nquery.mechanism_id = ObjectId(nquery.mechanism_id);
+    const arr = [
+      { $match: nquery },
+      {
+        $lookup: {
+          from: 'organization',
+          localField: 'user_id',
+          foreignField: '_id',
+          as: 'company',
+        },
+      },
+      { $unwind: '$company' },
+      { $addFields: { name: '$company.name' } },
+      { $project: { _id: 1, name: 1, meta: 1, status: 1 } },
+    ];
+    if (_.get(query, 'name')) {
+      arr.push({ $match: { name: new RegExp(_.get(query, 'name')) } });
+    }
+    let res = await this.model.aggregate(arr);
+    const total = res.length;
+    if (limit && limit !== '0') {
+      res = _.slice(res, parseInt(skip), parseInt(limit));
+    }
+    return { data: res, total };
+  }
+
+  async fetch({ id }) {
+    let res = await this.model.findById(id);
+    if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定数据');
+    res = JSON.parse(JSON.stringify(res));
+    const { user_id } = res;
+    if (user_id) {
+      const company = await this.ctx.model.Organization.findById(user_id);
+      if (company) res.name = company.name;
+    }
+    return res;
+  }
+
+  async status({ id }, body) {
+    const { status } = body;
+    await this.model.updateOne({ _id: id }, { status });
+    // TODO,添加记录
+    body.ticket_id = id;
+    await this.record.create(body);
+  }
+}
+
+module.exports = TicketService;

+ 15 - 0
app/service/cysci/ticket_record.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 Ticket_recordService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'ticket_record');
+    this.model = this.ctx.model.TicketRecord;
+  }
+}
+
+module.exports = Ticket_recordService;

+ 325 - 258
app/service/statistics/index.js

@@ -1,258 +1,325 @@
-'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 IndexService extends CrudService {
-  constructor(ctx) {
-    super(ctx, 'index');
-    this.redis = this.app.redis;
-    this.patentModel = this.ctx.model.Patent;
-    this.code = this.ctx.model.Code;
-    this.productModel = this.ctx.model.Product;
-    this.expertModel = this.ctx.model.Expert;
-    // this.userModel = this.ctx.model.User;
-    this.personalModel = this.ctx.model.Personal;
-    this.organizationModel = this.ctx.model.Organization;
-    this.surveyModel = this.ctx.model.Survey;
-    this.dockUser = this.ctx.model.DockUser;
-    this.tranModel = this.ctx.model.Transaction;
-  }
-  /**
-   * 首页专利统计
-   */
-  async patent() {
-    const res = await this.patentModel.aggregate([
-      {
-        $group: {
-          _id: '$apply_personal',
-          value: { $sum: 1 },
-        },
-      },
-    ]);
-    let arr = [];
-    const other = { name: '其他', value: 0 };
-    for (const i of res) {
-      const { _id, value } = i;
-      const unitList = this.patentUnitList();
-      const unit = unitList.find(
-        f => (_id && _id.includes(f.name)) || f.name.includes(_id)
-      );
-      if (unit) {
-        // 说明是需要单拎出来的数据,现查arr中是否有该单位:有=>数字合并;没有=>创建条目
-        const { name } = unit;
-        const arrItem = arr.find(f => f.name === name);
-        if (arrItem) {
-          const index = arr.findIndex(f => f.name === name);
-          arr[index] = { name, value: (arrItem.value || 0) + value };
-        } else {
-          arr.push({ name, value });
-        }
-      } else {
-        other.value += value;
-      }
-    }
-    arr = _.orderBy(arr, [ 'value' ], [ 'desc' ]);
-    arr.push(other);
-    return arr;
-  }
-
-  /**
-   * 首页成果统计
-   */
-  async product() {
-    const categroy = await this.code.find({ category: '01' });
-    const condition = { type: '1', status: '2' };
-    const arr = [];
-    for (const c of categroy) {
-      const { name } = c;
-      const value = await this.productModel.count({
-        ...condition,
-        field: name,
-      });
-      arr.push({ value, name });
-    }
-    return arr;
-  }
-
-  /**
-   * 首页统计专家
-   */
-  async expert() {
-    const res = await this.expertModel.aggregate([
-      {
-        $group: {
-          _id: '$company',
-          value: { $sum: 1 },
-        },
-      },
-    ]);
-    let arr = [];
-    const other = { name: '其他', value: 0 };
-    for (const i of res) {
-      const { _id, value } = i;
-      const unitList = this.expertList();
-      const unit = unitList.find(
-        f => (_id && _id.includes(f.name)) || f.name.includes(_id)
-      );
-      if (unit) {
-        // 说明是需要单拎出来的数据,现查arr中是否有该单位:有=>数字合并;没有=>创建条目
-        const { name, sort } = unit;
-        const arrItem = arr.find(f => f.name === name);
-        if (arrItem) {
-          const index = arr.findIndex(f => f.name === name);
-          arr[index] = { ...arr[index], value: (arrItem.value || 0) + value };
-        } else {
-          arr.push({ name, value, sort });
-        }
-      } else {
-        other.value += value;
-      }
-    }
-    arr = _.orderBy(arr, [ 'sort' ], [ 'asc' ]);
-    arr.push(other);
-    // 换名
-    arr.map(i => {
-      const r = this.expertList().find(f => f.name === i.name);
-      if (r && r.alias) i.name = r.alias;
-      return i;
-    });
-    return arr;
-  }
-
-  /**
-   * 首页数据统计
-   */
-  async circle() {
-    const arr = [];
-    const organization = await this.organizationModel.count({ status: '1' });
-    arr.push({
-      name: '企业注册数量',
-      value: organization,
-    });
-    // TODO:如果需要专家和个人用户区分开,则is_expert:false, 混查则不需要is_expert条件
-    const user = await this.personalModel.count({ status: '1', is_expert: false });
-    arr.push({
-      name: '个人注册数量',
-      value: user,
-    });
-    const exports = await this.expertModel.count();
-    arr.push({
-      name: '专家注册数量',
-      value: exports,
-    });
-    const products = await this.productModel.count({ status: '2' });
-    arr.push({
-      name: '产品发布数量',
-      value: products,
-    });
-    const surveys = await this.surveyModel.count();
-    arr.push({
-      name: '交流互动',
-      value: surveys,
-    });
-    const trans = await this.tranModel.aggregate([
-      { $match: { status: { $in: [ '0', '1', '3' ] } } },
-      {
-        $group: {
-          _id: '$status',
-          value: { $sum: 1 },
-        },
-      },
-    ]);
-    arr.push({
-      name: '正在洽谈',
-      value: _.get(trans.find(f => f._id === '0'), 'value', 0),
-    });
-    arr.push({
-      name: '达成意向',
-      value: _.get(trans.find(f => f._id === '1'), 'value', 0),
-    });
-    arr.push({
-      name: '对接完成',
-      value: _.get(trans.find(f => f._id === '3'), 'value', 0),
-    });
-    return arr;
-  }
-
-
-  /**
-   * 专家列表
-   */
-  expertList() {
-    return [
-      { name: '中科院长春光学精密机械与物理研究所', alias: '光机所', sort: 1 },
-      { name: '中国科学院长春应用化学研究所', alias: '应化所', sort: 2 },
-      { name: '中国科学院东北地理与农业生态研究所', alias: '地理所', sort: 3 },
-      { name: '吉林大学', sort: 4 },
-      { name: '长春工业大学', sort: 5 },
-    ];
-  }
-
-  /**
-   * 专利单位列表
-   */
-  patentUnitList() {
-    return [
-      { name: '吉林大学' },
-      { name: '长春理工大学' },
-      { name: '东北电力大学' },
-      { name: '吉林工程技术师范学院' },
-      { name: '长春工业大学' },
-      { name: '北华大学' },
-      { name: '吉林农业大学' },
-      { name: '吉林师范大学' },
-      { name: '长春工程学院' },
-      { name: '吉林建筑大学' },
-      { name: '通化师范学院' },
-      { name: '长春大学' },
-      { name: '东北师范大学' },
-      { name: '吉林农业科技学院' },
-    ];
-  }
-
-  // 展会首页统计
-  async dockIndex({ dock_id }) {
-    // 同时在线人数(伪)
-    const tszx = await this.redis.get('login_number');
-    // 特邀嘉宾
-    const tyjb = await this.personalModel.count({ is_expert: true });
-    // 洽谈合作 达成意向 交易完成
-    const trans = await this.tranModel.aggregate([
-      { $match: { status: { $in: [ '0', '1', '3' ] } } },
-      {
-        $group: {
-          _id: '$status',
-          value: { $sum: 1 },
-        },
-      },
-    ]);
-    const qthz = _.get(trans.find(f => f._id === '0'), 'value', 0);
-    const dcyx = _.get(trans.find(f => f._id === '1'), 'value', 0);
-    const jywc = _.get(trans.find(f => f._id === '3'), 'value', 0);
-    // 参展项目
-    const res = await this.dockUser.aggregate()
-      .match({ dock_id: ObjectId(dock_id), 'goodsList.type': '1', 'goodsList.dockStatus': '1' })
-      .unwind('$goodsList')
-      .group({
-        _id: '$dock_id',
-        count: { $sum: 1 },
-      });
-    const czxm = _.get(res[0], 'count');
-    const arr = [
-      { name: '同时在线', num: tszx, unit: '人' },
-      { name: '特邀嘉宾', num: tyjb, unit: '人' },
-      { name: '洽谈合作', num: qthz, unit: '项' },
-      { name: '达成意向', num: dcyx, unit: '项' },
-      { name: '交易完成', num: jywc, unit: '项' },
-      { name: '参展项目', num: czxm, unit: '项' },
-    ];
-    return arr;
-
-  }
-}
-
-module.exports = IndexService;
+'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 IndexService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'index');
+    this.redis = this.app.redis;
+    this.patentModel = this.ctx.model.Patent;
+    this.code = this.ctx.model.Code;
+    this.productModel = this.ctx.model.Product;
+    this.expertModel = this.ctx.model.Expert;
+    // this.userModel = this.ctx.model.User;
+    this.personalModel = this.ctx.model.Personal;
+    this.organizationModel = this.ctx.model.Organization;
+    this.surveyModel = this.ctx.model.Survey;
+    this.dockUser = this.ctx.model.DockUser;
+    this.tranModel = this.ctx.model.Transaction;
+  }
+  /**
+   * 首页专利统计
+   */
+  async patent() {
+    const res = await this.patentModel.aggregate([
+      {
+        $group: {
+          _id: '$apply_personal',
+          value: { $sum: 1 },
+        },
+      },
+    ]);
+    let arr = [];
+    const other = { name: '其他', value: 0 };
+    for (const i of res) {
+      const { _id, value } = i;
+      const unitList = this.patentUnitList();
+      const unit = unitList.find(
+        f => (_id && _id.includes(f.name)) || f.name.includes(_id)
+      );
+      if (unit) {
+        // 说明是需要单拎出来的数据,现查arr中是否有该单位:有=>数字合并;没有=>创建条目
+        const { name } = unit;
+        const arrItem = arr.find(f => f.name === name);
+        if (arrItem) {
+          const index = arr.findIndex(f => f.name === name);
+          arr[index] = { name, value: (arrItem.value || 0) + value };
+        } else {
+          arr.push({ name, value });
+        }
+      } else {
+        other.value += value;
+      }
+    }
+    arr = _.orderBy(arr, [ 'value' ], [ 'desc' ]);
+    arr.push(other);
+    return arr;
+  }
+
+  /**
+   * 首页成果统计
+   */
+  async product() {
+    const categroy = await this.code.find({ category: '01' });
+    const condition = { type: '1', status: '2' };
+    const arr = [];
+    for (const c of categroy) {
+      const { name } = c;
+      const value = await this.productModel.count({
+        ...condition,
+        field: name,
+      });
+      arr.push({ value, name });
+    }
+    return arr;
+  }
+
+  /**
+   * 首页统计专家
+   */
+  async expert() {
+    const res = await this.expertModel.aggregate([
+      {
+        $group: {
+          _id: '$company',
+          value: { $sum: 1 },
+        },
+      },
+    ]);
+    let arr = [];
+    const other = { name: '其他', value: 0 };
+    for (const i of res) {
+      const { _id, value } = i;
+      const unitList = this.expertList();
+      const unit = unitList.find(
+        f => (_id && _id.includes(f.name)) || f.name.includes(_id)
+      );
+      if (unit) {
+        // 说明是需要单拎出来的数据,现查arr中是否有该单位:有=>数字合并;没有=>创建条目
+        const { name, sort } = unit;
+        const arrItem = arr.find(f => f.name === name);
+        if (arrItem) {
+          const index = arr.findIndex(f => f.name === name);
+          arr[index] = { ...arr[index], value: (arrItem.value || 0) + value };
+        } else {
+          arr.push({ name, value, sort });
+        }
+      } else {
+        other.value += value;
+      }
+    }
+    arr = _.orderBy(arr, [ 'sort' ], [ 'asc' ]);
+    arr.push(other);
+    // 换名
+    arr.map(i => {
+      const r = this.expertList().find(f => f.name === i.name);
+      if (r && r.alias) i.name = r.alias;
+      return i;
+    });
+    return arr;
+  }
+
+  /**
+   * 首页数据统计
+   */
+  async circle() {
+    const arr = [];
+    const organization = await this.organizationModel.count({ status: '1' });
+    arr.push({
+      name: '企业注册数量',
+      value: organization,
+    });
+    // TODO:如果需要专家和个人用户区分开,则is_expert:false, 混查则不需要is_expert条件
+    const user = await this.personalModel.count({ status: '1', is_expert: false });
+    arr.push({
+      name: '个人注册数量',
+      value: user,
+    });
+    const exports = await this.expertModel.count();
+    arr.push({
+      name: '专家注册数量',
+      value: exports,
+    });
+    const products = await this.productModel.count({ status: '2' });
+    arr.push({
+      name: '产品发布数量',
+      value: products,
+    });
+    const surveys = await this.surveyModel.count();
+    arr.push({
+      name: '交流互动',
+      value: surveys,
+    });
+    const trans = await this.tranModel.aggregate([
+      { $match: { status: { $in: [ '0', '1', '3' ] } } },
+      {
+        $group: {
+          _id: '$status',
+          value: { $sum: 1 },
+        },
+      },
+    ]);
+    arr.push({
+      name: '正在洽谈',
+      value: _.get(trans.find(f => f._id === '0'), 'value', 0),
+    });
+    arr.push({
+      name: '达成意向',
+      value: _.get(trans.find(f => f._id === '1'), 'value', 0),
+    });
+    arr.push({
+      name: '对接完成',
+      value: _.get(trans.find(f => f._id === '3'), 'value', 0),
+    });
+    return arr;
+  }
+
+
+  /**
+   * 专家列表
+   */
+  expertList() {
+    return [
+      { name: '中科院长春光学精密机械与物理研究所', alias: '光机所', sort: 1 },
+      { name: '中国科学院长春应用化学研究所', alias: '应化所', sort: 2 },
+      { name: '中国科学院东北地理与农业生态研究所', alias: '地理所', sort: 3 },
+      { name: '吉林大学', sort: 4 },
+      { name: '长春工业大学', sort: 5 },
+    ];
+  }
+
+  /**
+   * 专利单位列表
+   */
+  patentUnitList() {
+    return [
+      { name: '吉林大学' },
+      { name: '长春理工大学' },
+      { name: '东北电力大学' },
+      { name: '吉林工程技术师范学院' },
+      { name: '长春工业大学' },
+      { name: '北华大学' },
+      { name: '吉林农业大学' },
+      { name: '吉林师范大学' },
+      { name: '长春工程学院' },
+      { name: '吉林建筑大学' },
+      { name: '通化师范学院' },
+      { name: '长春大学' },
+      { name: '东北师范大学' },
+      { name: '吉林农业科技学院' },
+    ];
+  }
+
+  // 展会首页统计
+  async dockIndex({ dock_id }) {
+    // 同时在线人数(伪)
+    const tszx = await this.redis.get('login_number');
+    // 特邀嘉宾
+    const tyjb = await this.personalModel.count({ is_expert: true });
+    // 洽谈合作 达成意向 交易完成
+    const trans = await this.tranModel.aggregate([
+      { $match: { status: { $in: [ '0', '1', '3' ] } } },
+      {
+        $group: {
+          _id: '$status',
+          value: { $sum: 1 },
+        },
+      },
+    ]);
+    const qthz = _.get(trans.find(f => f._id === '0'), 'value', 0);
+    const dcyx = _.get(trans.find(f => f._id === '1'), 'value', 0);
+    const jywc = _.get(trans.find(f => f._id === '3'), 'value', 0);
+    // 参展项目
+    const res = await this.dockUser.aggregate()
+      .match({ dock_id: ObjectId(dock_id), 'goodsList.type': '1', 'goodsList.dockStatus': '1' })
+      .unwind('$goodsList')
+      .group({
+        _id: '$dock_id',
+        count: { $sum: 1 },
+      });
+    const czxm = _.get(res[0], 'count');
+    const arr = [
+      { name: '同时在线', num: tszx, unit: '人' },
+      { name: '特邀嘉宾', num: tyjb, unit: '人' },
+      { name: '洽谈合作', num: qthz, unit: '项' },
+      { name: '达成意向', num: dcyx, unit: '项' },
+      { name: '交易完成', num: jywc, unit: '项' },
+      { name: '参展项目', num: czxm, unit: '项' },
+    ];
+    return arr;
+
+  }
+
+  /**
+   * 高企服务政策申请统计
+   */
+  async pac() {
+    const res = await this.ctx.model.PolicyApply.aggregate([
+      {
+        $lookup: {
+          from: 'policy',
+          localField: 'policy_id',
+          foreignField: '_id',
+          as: 'policy',
+        },
+      },
+      { $unwind: '$policy' },
+      { $group: {
+        _id: '$policy.type',
+        count: { $sum: 1 },
+      } },
+    ]);
+    const arr = [
+      { key: '奖励兑现', name: '奖励兑现' },
+      { key: '创新券', name: '创新券' },
+      { key: '研发补贴', name: '研发补贴' },
+    ];
+    const obj = this.setData(res, arr);
+    return obj;
+  }
+
+  /**
+   * 高企申报个步骤统计
+   */
+  async ticket() {
+    const res = await this.ctx.model.Ticket.aggregate([
+      { $group: {
+        _id: '$status',
+        count: { $sum: 1 },
+      } },
+    ]);
+    const arr = [
+      { key: '0', name: '企业信息待审中' },
+      { key: '1', name: '企业信息审核成功' },
+      { key: '-1', name: '企业信息审核失败' },
+      { key: '2', name: '高企申报成功' },
+    ];
+    const obj = this.setData(res, arr);
+    return obj;
+  }
+
+  /**
+   * 安排返回值
+   * @param {Array} list 数据[{_id,count}]
+   * @param {*} meta 变换成的另一部信息[{key:_id,name:zh}]
+   */
+  setData(list, meta) {
+    const obj = [];
+    for (const i of meta) {
+      const { key, name } = i;
+      const r = list.find(f => f._id === key);
+      if (r) {
+        obj.push({ name, value: r.count });
+      } else {
+        obj.push({ name, value: 0 });
+      }
+    }
+    return obj;
+  }
+}
+
+module.exports = IndexService;

+ 134 - 102
app/service/util/util.js

@@ -1,102 +1,134 @@
-'use strict';
-const _ = require('lodash');
-const moment = require('moment');
-const { CrudService } = require('naf-framework-mongoose/lib/service');
-const { ObjectId } = require('mongoose').Types;
-const fs = require('fs');
-class UtilService extends CrudService {
-  constructor(ctx) {
-    super(ctx);
-    this.mq = this.ctx.mq;
-  }
-  async utilMethod(query, body) {
-    const path = 'C:\\Users\\liuruifeng\\Desktop\\temp\\export\\ChannelVideo.json';
-    let text = await fs.readFileSync(path, { encoding: 'utf-8' });
-    text = JSON.parse(text);
-    for (const obj of text) {
-      obj.channel_id = { $oid: obj.channel_id };
-    }
-    // const path = 'C:\\Users\\liuruifeng\\Desktop\\temp\\export\\dock.json';
-    // let text = await fs.readFileSync(path, { encoding: 'utf-8' });
-    // text = JSON.parse(text);
-    // const dockArr = [];
-    // const dockUser = [];
-    // for (const obj of text) {
-    //   const dock = _.pick(obj, [ '_id', 'room_id', 'password', 'title', 'start_time', 'end_time', 'province', 'place', 'adminuser', 'phone', 'sponsor', 'organizer', 'videodata', 'vipuser', 'desc', 'status' ]);
-    //   dockArr.push(dock);
-    //   const apply = _.get(obj, 'apply', []);
-    //   const { _id } = obj;
-    //   for (const a of apply) {
-    //     a.dock_id = _id;
-    //     a.user_id = { $oid: a.user_id };
-    //     dockUser.push(a);
-    //   }
-    // }
-    // // await fs.writeFileSync('C:\\Users\\liuruifeng\\Desktop\\temp\\export\\dock_data.json', JSON.stringify(dockArr));
-    await fs.writeFileSync('C:\\Users\\liuruifeng\\Desktop\\temp\\export\\ChannelVideo-rewrite.json', JSON.stringify(text));
-    // const eupath = 'C:\\Users\\liuruifeng\\Desktop\\temp\\export\\expert,s_user.json';
-    // let eutext = await fs.readFileSync(eupath, { encoding: 'utf-8' });
-    // eutext = JSON.parse(eutext);
-    // console.log(eutext.length);
-    // for (const obj of text) {
-    //   if (_.isObject(obj.password)) continue;
-    //   const { password } = obj;
-    //   obj.password = { secret: password, mech: 'plain', createdAt: { $date: '2020-09-27T07:48:05.643Z' }, updatedAt: { $date: '2020-09-27T07:48:05.643Z' } };
-    // }
-    // await fs.writeFileSync('C:\\Users\\liuruifeng\\Desktop\\temp\\export\\role-5-rewrite.json', JSON.stringify(text));
-
-  }
-
-  dealQuery(query) {
-    return this.turnFilter(this.turnDateRangeQuery(query));
-  }
-
-  /**
-   * 将查询条件中模糊查询的标识转换成对应object
-   * @param {Object} filter 查询条件
-   */
-  turnFilter(filter) {
-    const str = /^%\S*%$/;
-    const keys = Object.keys(filter);
-    for (const key of keys) {
-      const res = key.match(str);
-      if (res) {
-        const newKey = key.slice(1, key.length - 1);
-        filter[newKey] = new RegExp(filter[key]);
-        delete filter[key];
-      }
-    }
-    return filter;
-  }
-  /**
-   * 将时间转换成对应查询Object
-   * @param {Object} filter 查询条件
-   */
-  turnDateRangeQuery(filter) {
-    const keys = Object.keys(filter);
-    for (const k of keys) {
-      if (k.includes('@')) {
-        const karr = k.split('@');
-        //  因为是针对处理范围日期,所以必须只有,开始时间和结束时间
-        if (karr.length === 2) {
-          const type = karr[1];
-          if (type === 'start') {
-            filter[karr[0]] = {
-              ..._.get(filter, karr[0], {}),
-              $gte: filter[k],
-            };
-          } else {
-            filter[karr[0]] = {
-              ..._.get(filter, karr[0], {}),
-              $lte: filter[k],
-            };
-          }
-          delete filter[k];
-        }
-      }
-    }
-    return filter;
-  }
-
-}
-module.exports = UtilService;
+'use strict';
+const _ = require('lodash');
+const moment = require('moment');
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { ObjectId } = require('mongoose').Types;
+const fs = require('fs');
+class UtilService extends CrudService {
+  constructor(ctx) {
+    super(ctx);
+    this.mq = this.ctx.mq;
+  }
+  async utilMethod(query, body) {
+    const path = 'C:\\Users\\liuruifeng\\Desktop\\temp\\organization.json';
+    let text = await fs.readFileSync(path, { encoding: 'utf-8' });
+    text = JSON.parse(text);
+    for (const i of text) {
+      i.passwd = _.cloneDeep(i.password);
+      delete i.password;
+    }
+    await fs.writeFileSync('C:\\Users\\liuruifeng\\Desktop\\temp\\no.json', JSON.stringify(text));
+
+
+    // const path = 'C:\\Users\\liuruifeng\\Desktop\\temp\\expert.json';
+    // let text = await fs.readFileSync(path, { encoding: 'utf-8' });
+    // text = JSON.parse(text);
+    // const ids = text.map(i => i.user_id.$oid);
+    // const users = await this.ctx.model.Personal.find({ _id: ids }, '+password');
+    // for (const i of text) {
+    //   const r = users.find(f => ObjectId(f._id).equals(i.user_id.$oid));
+    //   if (r) {
+    //     const { addr, office_phone, profession, name, phone } = r;
+    //     if (name)i.name = name;
+    //     if (phone)i.phone = phone;
+    //     if (addr)i.addr = addr;
+    //     if (office_phone)i.office_phone = office_phone;
+    //     if (profession)i.profession = profession;
+    //   }
+    //   const { img_path } = i;
+    //   const arr = [];
+    //   if (_.isString(img_path)) {
+    //     arr.push({ name: 'icon', url: img_path });
+    //   }
+    //   i.img_path = arr;
+    //   delete i.user_id;
+    // }
+    // await fs.writeFileSync('C:\\Users\\liuruifeng\\Desktop\\temp\\new-expert.json', JSON.stringify(text));
+
+
+    // for (const obj of text) {
+    //   obj.channel_id = { $oid: obj.channel_id };
+    // }
+    // const path = 'C:\\Users\\liuruifeng\\Desktop\\temp\\export\\dock.json';
+    // let text = await fs.readFileSync(path, { encoding: 'utf-8' });
+    // text = JSON.parse(text);
+    // const dockArr = [];
+    // const dockUser = [];
+    // for (const obj of text) {
+    //   const dock = _.pick(obj, [ '_id', 'room_id', 'password', 'title', 'start_time', 'end_time', 'province', 'place', 'adminuser', 'phone', 'sponsor', 'organizer', 'videodata', 'vipuser', 'desc', 'status' ]);
+    //   dockArr.push(dock);
+    //   const apply = _.get(obj, 'apply', []);
+    //   const { _id } = obj;
+    //   for (const a of apply) {
+    //     a.dock_id = _id;
+    //     a.user_id = { $oid: a.user_id };
+    //     dockUser.push(a);
+    //   }
+    // }
+    // // await fs.writeFileSync('C:\\Users\\liuruifeng\\Desktop\\temp\\export\\dock_data.json', JSON.stringify(dockArr));
+    // const eupath = 'C:\\Users\\liuruifeng\\Desktop\\temp\\export\\expert,s_user.json';
+    // let eutext = await fs.readFileSync(eupath, { encoding: 'utf-8' });
+    // eutext = JSON.parse(eutext);
+    // console.log(eutext.length);
+    // for (const obj of text) {
+    //   if (_.isObject(obj.password)) continue;
+    //   const { password } = obj;
+    //   obj.password = { secret: password, mech: 'plain', createdAt: { $date: '2020-09-27T07:48:05.643Z' }, updatedAt: { $date: '2020-09-27T07:48:05.643Z' } };
+    // }
+    // await fs.writeFileSync('C:\\Users\\liuruifeng\\Desktop\\temp\\export\\role-5-rewrite.json', JSON.stringify(text));
+
+  }
+
+  dealQuery(query) {
+    return this.turnFilter(this.turnDateRangeQuery(query));
+  }
+
+  /**
+   * 将查询条件中模糊查询的标识转换成对应object
+   * @param {Object} filter 查询条件
+   */
+  turnFilter(filter) {
+    const str = /^%\S*%$/;
+    const keys = Object.keys(filter);
+    for (const key of keys) {
+      const res = key.match(str);
+      if (res) {
+        const newKey = key.slice(1, key.length - 1);
+        filter[newKey] = new RegExp(filter[key]);
+        delete filter[key];
+      }
+    }
+    return filter;
+  }
+  /**
+   * 将时间转换成对应查询Object
+   * @param {Object} filter 查询条件
+   */
+  turnDateRangeQuery(filter) {
+    const keys = Object.keys(filter);
+    for (const k of keys) {
+      if (k.includes('@')) {
+        const karr = k.split('@');
+        //  因为是针对处理范围日期,所以必须只有,开始时间和结束时间
+        if (karr.length === 2) {
+          const type = karr[1];
+          if (type === 'start') {
+            filter[karr[0]] = {
+              ..._.get(filter, karr[0], {}),
+              $gte: filter[k],
+            };
+          } else {
+            filter[karr[0]] = {
+              ..._.get(filter, karr[0], {}),
+              $lte: filter[k],
+            };
+          }
+          delete filter[k];
+        }
+      }
+    }
+    return filter;
+  }
+
+}
+module.exports = UtilService;

+ 85 - 85
config/config.default.js

@@ -1,85 +1,85 @@
-/* eslint valid-jsdoc: "off" */
-
-'use strict';
-const { jwt } = require('./config.secret');
-
-/**
- * @param {Egg.EggAppInfo} appInfo app info
- */
-module.exports = appInfo => {
-  /**
-   * built-in config
-   * @type {Egg.EggAppConfig}
-   **/
-  const config = exports = {};
-
-  // use for cookie sign key, should change to your own and keep security
-  config.keys = appInfo.name + '_1611133759961_4798';
-
-  // add your middleware config here
-  config.middleware = [];
-
-  // add your user config here
-  const userConfig = {
-    // myAppName: 'egg',
-  };
-
-  config.cluster = {
-    listen: {
-      port: 9101,
-    },
-  };
-  config.jwt = {
-    ...jwt,
-    expiresIn: '1d',
-    issuer: 'test',
-  };
-
-  config.dbName = 'new-platform';
-  config.mongoose = {
-    url: `mongodb://localhost:27017/${config.dbName}`,
-    options: {
-      // user: 'admin',
-      // pass: '111111',
-      // authSource: 'admin',
-      // useNewUrlParser: true,
-      // useCreateIndex: true,
-    },
-  };
-
-  config.amqp = {
-    client: {
-      hostname: '127.0.0.1',
-      username: 'visit',
-      password: 'visit',
-      vhost: 'platform',
-    },
-    app: true,
-    agent: true,
-  };
-
-  config.redis = {
-    client: {
-      port: 6379, // Redis port
-      host: '127.0.0.1', // Redis host
-      password: 123456,
-      db: 1,
-    },
-  };
-
-  config.session = {
-    maxAge: 1000 * 60 * 30, // 30=>30min
-    renew: true,
-  };
-
-  config.export = {
-    root_path: 'D:\\workspace\\service\\service-file\\upload\\',
-  };
-  config.project = {
-    mission: 'http://127.0.0.1:4001',
-  };
-  return {
-    ...config,
-    ...userConfig,
-  };
-};
+/* eslint valid-jsdoc: "off" */
+
+'use strict';
+const { jwt } = require('./config.secret');
+
+/**
+ * @param {Egg.EggAppInfo} appInfo app info
+ */
+module.exports = appInfo => {
+  /**
+   * built-in config
+   * @type {Egg.EggAppConfig}
+   **/
+  const config = exports = {};
+
+  // use for cookie sign key, should change to your own and keep security
+  config.keys = appInfo.name + '_1611133759961_4798';
+
+  // add your middleware config here
+  config.middleware = [];
+
+  // add your user config here
+  const userConfig = {
+    // myAppName: 'egg',
+  };
+
+  config.cluster = {
+    listen: {
+      port: 9101,
+    },
+  };
+  config.jwt = {
+    ...jwt,
+    expiresIn: '1d',
+    issuer: 'test',
+  };
+
+  config.dbName = 'new-platform';
+  config.mongoose = {
+    url: `mongodb://localhost:27017/${config.dbName}`,
+    options: {
+      // user: 'admin',
+      // pass: '111111',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
+    },
+  };
+
+  config.amqp = {
+    client: {
+      hostname: '127.0.0.1',
+      username: 'visit',
+      password: 'visit',
+      vhost: 'platform',
+    },
+    app: true,
+    agent: true,
+  };
+
+  config.redis = {
+    client: {
+      port: 6379, // Redis port
+      host: '127.0.0.1', // Redis host
+      password: 123456,
+      db: 1,
+    },
+  };
+
+  config.session = {
+    maxAge: 1000 * 60 * 30, // 30=>30min
+    renew: true,
+  };
+
+  config.export = {
+    root_path: 'D:\\workspace\\service\\service-file\\upload\\',
+  };
+  config.project = {
+    mission: 'http://127.0.0.1:4001',
+  };
+  return {
+    ...config,
+    ...userConfig,
+  };
+};

+ 32 - 32
config/config.prod.js

@@ -1,32 +1,32 @@
-'use strict';
-
-module.exports = () => {
-  const config = exports = {};
-
-  config.logger = {
-    level: 'INFO',
-    consoleLevel: 'INFO',
-  };
-  config.dbName = 'new-platform';
-  config.mongoose = {
-    url: `mongodb://localhost:27017/${config.dbName}`,
-    options: {
-      user: 'admin',
-      pass: 'admin',
-      authSource: 'admin',
-      useNewUrlParser: true,
-      useCreateIndex: true,
-    },
-  };
-  // redis config
-  config.redis = {
-    client: {
-      port: 6379, // Redis port
-      host: '127.0.0.1', // Redis host
-      password: 123456,
-      db: 0,
-    },
-  };
-
-  return config;
-};
+'use strict';
+
+module.exports = () => {
+  const config = exports = {};
+
+  config.logger = {
+    level: 'INFO',
+    consoleLevel: 'INFO',
+  };
+  config.dbName = 'new-platform';
+  config.mongoose = {
+    url: `mongodb://localhost:27017/${config.dbName}`,
+    options: {
+      user: 'admin',
+      pass: 'admin',
+      authSource: 'admin',
+      useNewUrlParser: true,
+      useCreateIndex: true,
+    },
+  };
+  // redis config
+  config.redis = {
+    client: {
+      port: 6379, // Redis port
+      host: '127.0.0.1', // Redis host
+      password: 123456,
+      db: 0,
+    },
+  };
+
+  return config;
+};

+ 12 - 12
config/plugin.js

@@ -1,12 +1,12 @@
-'use strict';
-
-/** @type Egg.EggPlugin */
-exports.amqp = {
-  enable: true,
-  package: 'egg-naf-amqp',
-};
-exports.redis = {
-  enable: true,
-  package: 'egg-redis',
-};
-
+'use strict';
+
+/** @type Egg.EggPlugin */
+exports.amqp = {
+  enable: true,
+  package: 'egg-naf-amqp',
+};
+exports.redis = {
+  enable: true,
+  package: 'egg-redis',
+};
+

+ 53 - 53
package.json

@@ -1,53 +1,53 @@
-{
-  "name": "service-live",
-  "version": "1.0.0",
-  "description": "直播平台服务端重构",
-  "private": true,
-  "egg": {
-    "framework": "naf-framework-mongoose"
-  },
-  "dependencies": {
-    "egg": "^2.15.1",
-    "egg-naf-amqp": "0.0.13",
-    "egg-redis": "^2.4.0",
-    "egg-scripts": "^2.11.0",
-    "exceljs": "^4.2.0",
-    "lodash": "^4.17.15",
-    "moment": "^2.24.0",
-    "naf-framework-mongoose": "^0.6.11"
-  },
-  "devDependencies": {
-    "autod": "^3.0.1",
-    "autod-egg": "^1.1.0",
-    "egg-bin": "^4.11.0",
-    "egg-ci": "^1.11.0",
-    "egg-mock": "^3.21.0",
-    "eslint": "^5.13.0",
-    "eslint-config-egg": "^7.1.0",
-    "jsonwebtoken": "^8.5.1"
-  },
-  "engines": {
-    "node": ">=10.0.0"
-  },
-  "scripts": {
-    "start": "egg-scripts start --daemon --title=egg-server-service-live",
-    "stop": "egg-scripts stop --title=egg-server-service-live",
-    "dev": "egg-bin dev",
-    "debug": "egg-bin debug",
-    "test": "npm run lint -- --fix && npm run test-local",
-    "test-local": "egg-bin test",
-    "cov": "egg-bin cov",
-    "lint": "eslint .",
-    "ci": "npm run lint && npm run cov",
-    "autod": "autod"
-  },
-  "ci": {
-    "version": "10"
-  },
-  "repository": {
-    "type": "git",
-    "url": ""
-  },
-  "author": "free",
-  "license": "MIT"
-}
+{
+  "name": "service-live",
+  "version": "1.0.0",
+  "description": "直播平台服务端重构",
+  "private": true,
+  "egg": {
+    "framework": "naf-framework-mongoose"
+  },
+  "dependencies": {
+    "egg": "^2.15.1",
+    "egg-naf-amqp": "0.0.13",
+    "egg-redis": "^2.4.0",
+    "egg-scripts": "^2.11.0",
+    "exceljs": "^4.2.0",
+    "lodash": "^4.17.15",
+    "moment": "^2.24.0",
+    "naf-framework-mongoose": "^0.6.11"
+  },
+  "devDependencies": {
+    "autod": "^3.0.1",
+    "autod-egg": "^1.1.0",
+    "egg-bin": "^4.11.0",
+    "egg-ci": "^1.11.0",
+    "egg-mock": "^3.21.0",
+    "eslint": "^5.13.0",
+    "eslint-config-egg": "^7.1.0",
+    "jsonwebtoken": "^8.5.1"
+  },
+  "engines": {
+    "node": ">=10.0.0"
+  },
+  "scripts": {
+    "start": "egg-scripts start --daemon --title=egg-server-service-live",
+    "stop": "egg-scripts stop --title=egg-server-service-live",
+    "dev": "egg-bin dev",
+    "debug": "egg-bin debug",
+    "test": "npm run lint -- --fix && npm run test-local",
+    "test-local": "egg-bin test",
+    "cov": "egg-bin cov",
+    "lint": "eslint .",
+    "ci": "npm run lint && npm run cov",
+    "autod": "autod"
+  },
+  "ci": {
+    "version": "10"
+  },
+  "repository": {
+    "type": "git",
+    "url": ""
+  },
+  "author": "free",
+  "license": "MIT"
+}