lrf402788946 4 years ago
parent
commit
92073c8d23

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

@@ -39,4 +39,8 @@ module.exports = {
       count: true,
     },
   },
+  getWork: {
+    params: ["!expert_id"],
+    service: "getWork",
+  },
 };

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

@@ -70,4 +70,8 @@ module.exports = {
     params: ["!id"],
     service: "restore",
   },
+
+  getExpertList: {
+    service: "getExpertList",
+  },
 };

+ 1 - 1
app/model/achieve_expert.js

@@ -9,7 +9,7 @@ const { Secret } = require('naf-framework-mongoose/lib/model/schema');
 const achieve_expert = {
   expert_user_id: { type: ObjectId }, // 专家的用户id
   expert_name: { type: String }, // 专家姓名
-  phone: { type: String }, // 电话
+  phone: { type: String }, // 电话/登陆用
   company: { type: String }, // 工作单位
   group_zw: { type: String }, // 评价专家组职务
   major: { type: String }, // 所学专业

+ 1 - 0
app/router/achieve_apply_expert.js

@@ -6,6 +6,7 @@ module.exports = app => {
   const profix = '/api/achieve/';
   const vision = 'v0';
   const target = 'achieveApplyExpert';
+  router.get(target, `${profix}${vision}/${target}/getWork/:expert_id`, controller[target].getWork);
   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

@@ -6,6 +6,7 @@ module.exports = app => {
   const profix = '/api/achieve/';
   const vision = 'v0';
   const target = 'achieveExpert';
+  router.get(target, `${profix}${vision}/${target}/getExpertList`, controller[target].getExpertList);
   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

+ 16 - 1
app/service/achieve_apply_expert.js

@@ -9,6 +9,7 @@ class Achieve_apply_expertService extends CrudService {
   constructor(ctx) {
     super(ctx, 'achieve_apply_expert');
     this.model = this.ctx.model.AchieveApplyExpert;
+    this.expert = this.ctx.model.AchieveExpert;
   }
   async query(querys, { skip = 0, limit = 0 } = {}) {
     const { expert = false, apply, ...query } = querys;
@@ -30,7 +31,6 @@ class Achieve_apply_expertService extends CrudService {
 
   async create(data) {
     const { apply_id, expert_id, type } = data;
-    console.log(expert_id);
     let idata = [];
     if (_.isArray(expert_id)) {
       for (const e_id of expert_id) {
@@ -50,6 +50,21 @@ class Achieve_apply_expertService extends CrudService {
     const count = await this.model.count(data);
     return count <= 0;
   }
+
+  async update({ id }, body) {
+    const data = await this.model.findById(id);
+    if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '数据不存在');
+    const { expert_id } = data;
+    // 专家变!不可用
+    await this.expert.updateOne({ _id: expert_id }, { status: '1' });
+    await this.model.updateOne({ _id: id }, body);
+  }
+
+  async getWork({ expert_id }) {
+    const data = await this.model.findOne({ expert_id }).populate('apply_id');
+    if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到您需要审核的成果');
+    return data;
+  }
 }
 
 module.exports = Achieve_apply_expertService;

+ 23 - 3
app/service/achieve_expert.js

@@ -1,6 +1,7 @@
 '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');
 const jwt = require('jsonwebtoken');
@@ -56,10 +57,10 @@ class Achieve_expertService extends CrudService {
    * @param {Object} params 手机号,密码
    */
   async login({ phone, password }) {
-    const expert = await this.model.findOne({ phone }, '+password');
+    const expert = await this.model.findOne({ phone, status: '0' }, '+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 { password: op } = 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' ]);
@@ -74,6 +75,25 @@ class Achieve_expertService extends CrudService {
     const res = await this.model.find({ _id: ids });
     return res;
   }
+
+  /**
+   * 获取可以生成临时账号的专家列表
+   */
+  async getExpertList() {
+    // 1,去live项目中把所有专家整来
+    // 2,到achieve_expert表里,把可以使用的临时账号(status=0)的专家id都拿来
+    // 3.把1中2的结果去掉,返回
+    let expertList = [];
+    const eres = await this.ctx.service.util.httpUtil.cpost('/spm', 'live', { service: 'users.expert', method: 'query' }, { method: 'useService' });
+    if (eres) expertList = eres.data;
+    const have_accounts = await this.model.find({ status: 0 }, 'expert_user_id');
+    expertList = expertList.map(i => {
+      const res = have_accounts.find(ae => ObjectId(ae.expert_user_id).equals(i.user_id));
+      if (res)i.cant_use = true;
+      return i;
+    });
+    return expertList;
+  }
 }
 
 module.exports = Achieve_expertService;

+ 3 - 0
app/service/achieve_verify_record.js

@@ -26,6 +26,9 @@ class Achieve_verify_recordService extends CrudService {
       // if (status === '2') {
       //   await this.expert.updateMany({ apply_id }, { status: '1' });
       // }
+      // if (status === '3') {
+      //   await this.expert.updateMany({ apply_id }, { status: '1' });
+      // }
       return record;
     }
     throw new BusinessError(ErrorCode.SERVICE_FAULT, '审核失败');