|
@@ -0,0 +1,60 @@
|
|
|
+'use strict';
|
|
|
+const { CrudService } = require('naf-framework-mongoose/lib/service');
|
|
|
+const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
+const _ = require('lodash');
|
|
|
+const assert = require('assert');
|
|
|
+
|
|
|
+// 只属于这个项目的工具service
|
|
|
+class SpmService extends CrudService {
|
|
|
+ constructor(ctx) {
|
|
|
+ super(ctx, 'spm');
|
|
|
+ this.org = this.ctx.model.Organization;
|
|
|
+ this.personal = this.ctx.model.Personal;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 入口,根据method,分配到函数中进行处理,返回结果
|
|
|
+ * @param {Object} {method} method:在这个service的函数
|
|
|
+ * @param {*} body 条件
|
|
|
+ */
|
|
|
+ async index({ method }, body) {
|
|
|
+ return await this[method](body);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户信息,个人(专家)/企业都有可能
|
|
|
+ * @param {Object} condition 条件
|
|
|
+ */
|
|
|
+ async getAllUser(condition) {
|
|
|
+ const { ids } = condition;
|
|
|
+ const projection = 'name phone';
|
|
|
+ // 直接先用ids在企业表中查询
|
|
|
+ let arr = [];
|
|
|
+ const org = await this.org.find({ _id: ids }, projection);
|
|
|
+ arr = arr.concat(org);
|
|
|
+ if (org.length !== ids.length) {
|
|
|
+ // 还有个人用户,再查
|
|
|
+ const personal = await this.personal.find({ _id: ids }, projection);
|
|
|
+ arr = arr.concat(personal);
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据条件查找用户
|
|
|
+ * @param {Object} condition 查询条件
|
|
|
+ */
|
|
|
+ async getUser(condition) {
|
|
|
+ let res;
|
|
|
+ // 先查是不是企业
|
|
|
+ const org = await this.org.findOne(condition);
|
|
|
+ if (org) res = org;
|
|
|
+ else {
|
|
|
+ const personal = await this.personal.findOne(condition);
|
|
|
+ if (personal) res = personal;
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+module.exports = SpmService;
|