|
@@ -66,11 +66,11 @@ class GroupService extends CrudService {
|
|
// 检查是否已经参团
|
|
// 检查是否已经参团
|
|
const cus = _.get(this.ctx, 'user._id', customer);
|
|
const cus = _.get(this.ctx, 'user._id', customer);
|
|
if (!cus) throw new BusinessError(ErrorCode.NOT_LOGIN, '用户未登录');
|
|
if (!cus) throw new BusinessError(ErrorCode.NOT_LOGIN, '用户未登录');
|
|
- const r = data.persons.find(f => f.customer === cus);
|
|
|
|
|
|
+ const r = data.persons.find((f) => f.customer === cus);
|
|
if (r) return { result: false, msg: '您已参团' };
|
|
if (r) return { result: false, msg: '您已参团' };
|
|
|
|
|
|
// 为0是正常的团员
|
|
// 为0是正常的团员
|
|
- const realPersons = persons.filter(f => f.status === '0');
|
|
|
|
|
|
+ const realPersons = persons.filter((f) => f.status === '0');
|
|
if (realPersons.length < person_limit) return { result: true };
|
|
if (realPersons.length < person_limit) return { result: true };
|
|
return { result: false, msg: '当前参团人数已足够' };
|
|
return { result: false, msg: '当前参团人数已足够' };
|
|
}
|
|
}
|
|
@@ -91,9 +91,9 @@ class GroupService extends CrudService {
|
|
if (status !== '0') return;
|
|
if (status !== '0') return;
|
|
const newPersons = JSON.parse(JSON.stringify(persons));
|
|
const newPersons = JSON.parse(JSON.stringify(persons));
|
|
const findPersonCondition = (c1, c2) => ObjectId(c1).equals(c2);
|
|
const findPersonCondition = (c1, c2) => ObjectId(c1).equals(c2);
|
|
- const p = newPersons.find(f => findPersonCondition(f.customer, customer));
|
|
|
|
|
|
+ const p = newPersons.find((f) => findPersonCondition(f.customer, customer));
|
|
if (!p) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到要退团的用户');
|
|
if (!p) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到要退团的用户');
|
|
- const i = newPersons.findIndex(f => findPersonCondition(f.customer, customer));
|
|
|
|
|
|
+ const i = newPersons.findIndex((f) => findPersonCondition(f.customer, customer));
|
|
p.status = '1';
|
|
p.status = '1';
|
|
p.out_time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
p.out_time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
newPersons[i] = p;
|
|
newPersons[i] = p;
|
|
@@ -101,7 +101,7 @@ class GroupService extends CrudService {
|
|
// 团长退团了,根据入团时间降序,顺位成为团长
|
|
// 团长退团了,根据入团时间降序,顺位成为团长
|
|
if (leader === customer) {
|
|
if (leader === customer) {
|
|
let newLeader;
|
|
let newLeader;
|
|
- const orderList = _.orderBy(newPersons, [ 'status', 'join_time' ], [ 'asc', 'asc' ]);
|
|
|
|
|
|
+ const orderList = _.orderBy(newPersons, ['status', 'join_time'], ['asc', 'asc']);
|
|
const head = _.head(orderList);
|
|
const head = _.head(orderList);
|
|
if (head && head.status === '0') {
|
|
if (head && head.status === '0') {
|
|
newLeader = _.get(head, 'customer');
|
|
newLeader = _.get(head, 'customer');
|
|
@@ -141,14 +141,29 @@ class GroupService extends CrudService {
|
|
for (const i of data) {
|
|
for (const i of data) {
|
|
const { persons = [] } = i;
|
|
const { persons = [] } = i;
|
|
for (const p of persons) {
|
|
for (const p of persons) {
|
|
- const user = await this.userModel.findById(p.customer, { name: 1, icon: 1 });
|
|
|
|
|
|
+ const user = await this.getUserInfo(p.customer);
|
|
p.name = _.get(user, 'name');
|
|
p.name = _.get(user, 'name');
|
|
p.icon = _.get(user, 'icon');
|
|
p.icon = _.get(user, 'icon');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ async afterFetch(filter, data) {
|
|
|
|
+ data = JSON.parse(JSON.stringify(data));
|
|
|
|
+ const { persons = [] } = data;
|
|
|
|
+ for (const p of persons) {
|
|
|
|
+ const user = await this.getUserInfo(p.customer);
|
|
|
|
+ p.name = _.get(user, 'name');
|
|
|
|
+ p.icon = _.get(user, 'icon');
|
|
|
|
+ }
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ async getUserInfo(id) {
|
|
|
|
+ const user = await this.userModel.findById(id, { name: 1, icon: 1 });
|
|
|
|
+ return user;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = GroupService;
|
|
module.exports = GroupService;
|