|
@@ -16,12 +16,37 @@ class UserService extends CrudService {
|
|
|
this.schModel = this.ctx.model.School;
|
|
|
this.hModel = this.ctx.model.Headteacher;
|
|
|
}
|
|
|
-
|
|
|
+ async query({ name, ...info }, options) {
|
|
|
+ const newoptions = await this.ctx.service.util.getQueryOptions(options);
|
|
|
+ const query = { ...info };
|
|
|
+ if (name) {
|
|
|
+ query.name = { $regex: name };
|
|
|
+ }
|
|
|
+ let res = await this.model.find(query, '+passwd', newoptions).exec();
|
|
|
+ res = JSON.parse(JSON.stringify(res));
|
|
|
+ for (const user of res) {
|
|
|
+ if (user) {
|
|
|
+ const { passwd } = user;
|
|
|
+ user.passwd = passwd.secret;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ async count({ name, ...info }) {
|
|
|
+ const query = { ...info };
|
|
|
+ if (name) {
|
|
|
+ query.name = { $regex: name };
|
|
|
+ }
|
|
|
+ const res = await this.model.count(query);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
// 重写创建方法
|
|
|
async create(data) {
|
|
|
const { name, mobile, passwd, type, gender } = data;
|
|
|
assert(name && mobile && passwd && type, '缺少部分信息项');
|
|
|
- assert(/^\d{11}$/i.test(mobile), 'mobile无效');
|
|
|
+ if (type !== '0') {
|
|
|
+ assert(/^\d{11}$/i.test(mobile), 'mobile无效');
|
|
|
+ }
|
|
|
const newdata = data;
|
|
|
newdata.passwd = { secret: passwd };
|
|
|
const res = await this.model.create(newdata);
|
|
@@ -35,7 +60,7 @@ class UserService extends CrudService {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- async update({ id }, { name, mobile, passwd, openid }) {
|
|
|
+ async update({ id }, { name, mobile, passwd, openid, status }) {
|
|
|
assert(id, '缺少部分信息项');
|
|
|
const user = await this.model.findById(id);
|
|
|
if (!user) {
|
|
@@ -53,7 +78,11 @@ class UserService extends CrudService {
|
|
|
if (openid) {
|
|
|
user.openid = openid;
|
|
|
}
|
|
|
- user.status = '1';
|
|
|
+ if (status) {
|
|
|
+ user.status = status;
|
|
|
+ } else {
|
|
|
+ user.status = '1';
|
|
|
+ }
|
|
|
await user.save();
|
|
|
return user;
|
|
|
}
|
|
@@ -86,7 +115,9 @@ class UserService extends CrudService {
|
|
|
user.unionid = unionid;
|
|
|
await user.save();
|
|
|
} else {
|
|
|
- const stud = await this.stuModel.findOne({ id_number: { $regex: `^${id_number}$`, $options: 'i' } });
|
|
|
+ const stud = await this.stuModel.findOne({
|
|
|
+ id_number: { $regex: `^${id_number}$`, $options: 'i' },
|
|
|
+ });
|
|
|
if (!stud) {
|
|
|
throw new BusinessError(ErrorCode.USER_NOT_EXIST);
|
|
|
}
|
|
@@ -95,7 +126,14 @@ class UserService extends CrudService {
|
|
|
await stud.save();
|
|
|
// 再次检查是否有该用户,需要用uid查
|
|
|
const have_user = await this.model.findOne({ uid: stud.id });
|
|
|
- const newdata = { name: stud.name, mobile: stud.phone, type: '4', uid: stud.id, openid, unionid };
|
|
|
+ const newdata = {
|
|
|
+ name: stud.name,
|
|
|
+ mobile: stud.phone,
|
|
|
+ type: '4',
|
|
|
+ uid: stud.id,
|
|
|
+ openid,
|
|
|
+ unionid,
|
|
|
+ };
|
|
|
if (have_user) {
|
|
|
if (stud.name) have_user.name = stud.name;
|
|
|
if (stud.phone) have_user.mobile = stud.phone;
|
|
@@ -128,7 +166,8 @@ class UserService extends CrudService {
|
|
|
headers: {
|
|
|
userid: uid,
|
|
|
openid,
|
|
|
- } };
|
|
|
+ },
|
|
|
+ };
|
|
|
await mq.topic('qrcode.bind', qrcode, msg, parm);
|
|
|
} else {
|
|
|
this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
|
|
@@ -218,7 +257,12 @@ class UserService extends CrudService {
|
|
|
for (const sch of schools) {
|
|
|
const user = await this.model.findOne({ uid: sch.id, type: '2' });
|
|
|
if (!user) {
|
|
|
- const newdata = { name: sch.name, mobile: sch.code, type: '2', uid: sch.id };
|
|
|
+ const newdata = {
|
|
|
+ name: sch.name,
|
|
|
+ mobile: sch.code,
|
|
|
+ type: '2',
|
|
|
+ uid: sch.id,
|
|
|
+ };
|
|
|
newdata.passwd = { secret: '12345678' };
|
|
|
await this.model.create(newdata);
|
|
|
}
|
|
@@ -229,7 +273,9 @@ class UserService extends CrudService {
|
|
|
// 学生小程序绑定
|
|
|
async appbind(data) {
|
|
|
const { name, mobile, appopenid } = data;
|
|
|
- console.error(`appBind: name=>${name} / mobile=>${mobile} / appopenid = ${appopenid}`);
|
|
|
+ console.error(
|
|
|
+ `appBind: name=>${name} / mobile=>${mobile} / appopenid = ${appopenid}`
|
|
|
+ );
|
|
|
assert(name, '缺少姓名');
|
|
|
assert(mobile, '缺少手机号');
|
|
|
assert(appopenid, '缺少小程序openid');
|
|
@@ -245,7 +291,6 @@ class UserService extends CrudService {
|
|
|
// );
|
|
|
return res;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
module.exports = UserService;
|