lrf402788946 4 年 前
コミット
005769512a

+ 42 - 0
app/controller/.achieve_apply_expert.js

@@ -0,0 +1,42 @@
+module.exports = {
+  create: {
+    requestBody: ["!expert_id", "!apply_id", "verify", "type"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["expert_id", "apply_id", "verify", "type"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        expert_id: "expert_id",
+        apply_id: "apply_id",
+        type: "type",
+        expert: "expert",
+        apply: "apply",
+        "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,
+    },
+  },
+};

+ 4 - 3
app/controller/.achieve_expert.js

@@ -3,7 +3,6 @@ module.exports = {
     requestBody: [
       "!expert_user_id",
       "expert_name",
-      "!apply_id",
       "phone",
       "password",
     ],
@@ -18,7 +17,6 @@ module.exports = {
       "expert_user_id",
       "expert_name",
       "phone",
-      "apply_id",
       "password",
       "status",
       "verify",
@@ -36,7 +34,6 @@ module.exports = {
         phone: "phone",
         expert_name: "expert_name",
         expert_user_id: "expert_user_id",
-        apply_id: "apply_id",
         status: "status",
         "create_time@start": "create_time@start",
         "create_time@end": "create_time@end",
@@ -57,4 +54,8 @@ module.exports = {
     requestBody: ["!phone", "!password"],
     service: "login",
   },
+  restore: {
+    params: ["!id"],
+    service: "restore",
+  },
 };

+ 13 - 0
app/controller/achieve_apply_expert.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./.achieve_apply_expert.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 专家分配的申请表
+class Achieve_apply_expertController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.achieveApplyExpert;
+  }
+}
+module.exports = CrudController(Achieve_apply_expertController, meta);

+ 24 - 0
app/model/achieve_apply_expert.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 achieve_apply_expert = {
+  expert_id: { type: ObjectId, ref: 'Achieve_expert' }, // 临时专家表的专家id
+  apply_id: { type: ObjectId, ref: 'Achieve_apply' }, // 成果申请id
+  verify: { type: Object }, // 评审详情:分数:score;意见:content
+  type: { type: String }, // 工作类型:1=>评分;2=>会审
+  remark: { type: String, maxLength: 200 },
+  create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
+};
+const schema = new Schema(achieve_apply_expert, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ expert_id: 1 });
+schema.index({ apply_id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Achieve_apply_expert', schema, 'achieve_apply_expert');
+};

+ 0 - 3
app/model/achieve_expert.js

@@ -6,14 +6,11 @@ const { ObjectId } = require('mongoose').Types;
 const { Secret } = require('naf-framework-mongoose/lib/model/schema');
 // 专家临时账号表
 // 使用手机号密码登录
-// 约束条件,不能出现一个专家同时审2个项目,否则登录可能混乱
 const achieve_expert = {
   expert_user_id: { type: ObjectId }, // 专家的用户id
   expert_name: { type: String }, // 专家姓名
   phone: { type: String }, // 电话
-  apply_id: { type: ObjectId }, // 成果申请id
   password: { type: Secret, select: false },
-  verify: { type: Object }, // 评审详情:分数:score;意见:content
   status: { type: String, default: '0' }, // 0=>使用中;-1=>禁用中
   remark: { type: String, maxLength: 200 },
   create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },

+ 1 - 0
app/router.js

@@ -9,4 +9,5 @@ module.exports = app => {
   require('./router/achieve_apply')(app); // 成果评价申请
   require('./router/achieve_verify_record')(app); // 成果评价申请审核记录
   require('./router/achieve_expert')(app); // 专家临时
+  require('./router/achieve_apply_expert')(app); // 成果评价申请-分配专家
 };

+ 11 - 0
app/router/achieve_apply_expert.js

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

+ 1 - 0
app/router/achieve_expert.js

@@ -7,6 +7,7 @@ module.exports = app => {
   const vision = 'v0';
   const target = 'achieveExpert';
   router.post(target, `${profix}${vision}/${target}/login`, controller[target].login);
+  router.post(target, `${profix}${vision}/${target}/restore/:id`, controller[target].restore);
   router.resources(target, `${profix}${vision}/${target}`, controller[target]); // index、create、show、destroy
   router.post(target, `${profix}${vision}/${target}/update/:id`, controller[target].update);
 };

+ 32 - 0
app/service/achieve_apply_expert.js

@@ -0,0 +1,32 @@
+'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 Achieve_apply_expertService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'achieve_apply_expert');
+    this.model = this.ctx.model.AchieveApplyExpert;
+  }
+  async query(querys, { skip = 0, limit = 0 } = {}) {
+    const { expert = false, apply, ...query } = querys;
+    const pop = [];
+    if (expert) pop.push('expert_id');
+    if (apply)pop.push('apply_id');
+    const res = await this.model.find(query)
+      .populate(pop)
+      .skip(parseInt(skip))
+      .limit(parseInt(limit));
+    return res;
+  }
+
+  async count(querys) {
+    const { expert = false, apply, ...query } = querys;
+    const res = await this.model.count(query);
+    return res;
+  }
+}
+
+module.exports = Achieve_apply_expertService;

+ 19 - 3
app/service/achieve_expert.js

@@ -36,14 +36,30 @@ class Achieve_expertService extends CrudService {
     return await this.model.findById(id);
   }
 
+  /**
+   * 冻结账号
+   * @param {Object} id 数据id
+   */
+  async delete({ id }) {
+    await this.model.updateOne({ _id: id }, { status: '1' });
+  }
+
+  /**
+   * 解冻账号
+   * @param {Object} id 数据id
+   */
+  async restore({ id }) {
+    await this.model.updateOne({ _id: id }, { status: '0' });
+  }
   /**
    * 临时专家账号登录
    * @param {Object} params 手机号,密码
    */
   async login({ phone, password }) {
-    const expert = await this.model.findOne({ phone, status: '0' }, '+password');
-    if (!expert) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '您不存在未完成的工作,无需登录');
-    const { password: op } = expert;
+    const expert = await this.model.findOne({ phone }, '+password');
+    if (!expert) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到您的临时账号,如有疑问,请联系管理员');
+    const { password: op, status } = expert;
+    if (status !== '0') throw new BusinessError(ErrorCode.ACCESS_DENIED, '您的临时账号已被注销,如有疑问,请联系管理员');
     const { secret } = op;
     if (secret !== password) throw new BusinessError(ErrorCode.BAD_PASSWORD, '密码错误');
     const data = _.omit(JSON.parse(JSON.stringify(expert)), [ 'expert_name', 'meta', 'password', '__v', 'verify' ]);

+ 4 - 4
app/service/achieve_verify_record.js

@@ -22,10 +22,10 @@ class Achieve_verify_recordService extends CrudService {
     const res = await this.apply.updateOne({ _id: apply_id }, { status });
     if (res.ok && _.isNumber(res.ok) && res.ok > 0) {
       const record = await this.model.create(data);
-      // status=2时(评分已过,需要缴费),需要将该apply_id下的临时专家全部修改成GG状态(status=1)
-      if (status === '2') {
-        await this.expert.updateMany({ apply_id }, { status: '1' });
-      }
+      // 21-03-22 先不需要了:status=2时(评分已过,需要缴费),需要将该apply_id下的临时专家全部修改成GG状态(status=1)
+      // if (status === '2') {
+      //   await this.expert.updateMany({ apply_id }, { status: '1' });
+      // }
       return record;
     }
     throw new BusinessError(ErrorCode.SERVICE_FAULT, '审核失败');