|
@@ -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;
|