|
@@ -66,11 +66,11 @@ class GroupService extends CrudService {
|
|
|
// 检查是否已经参团
|
|
|
const cus = _.get(this.ctx, 'user._id', customer);
|
|
|
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: '您已参团' };
|
|
|
|
|
|
// 为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 };
|
|
|
return { result: false, msg: '当前参团人数已足够' };
|
|
|
}
|
|
@@ -91,9 +91,9 @@ class GroupService extends CrudService {
|
|
|
if (status !== '0') return;
|
|
|
const newPersons = JSON.parse(JSON.stringify(persons));
|
|
|
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, '未找到要退团的用户');
|
|
|
- const i = newPersons.findIndex((f) => findPersonCondition(f.customer, customer));
|
|
|
+ const i = newPersons.findIndex(f => findPersonCondition(f.customer, customer));
|
|
|
p.status = '1';
|
|
|
p.out_time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
newPersons[i] = p;
|
|
@@ -101,13 +101,16 @@ class GroupService extends CrudService {
|
|
|
// 团长退团了,根据入团时间降序,顺位成为团长
|
|
|
if (leader === customer) {
|
|
|
let newLeader;
|
|
|
- const orderList = _.orderBy(newPersons, ['status', 'join_time'], ['asc', 'asc']);
|
|
|
+ const orderList = _.orderBy(newPersons, [ 'status', 'join_time' ], [ 'asc', 'asc' ]);
|
|
|
const head = _.head(orderList);
|
|
|
if (head && head.status === '0') {
|
|
|
newLeader = _.get(head, 'customer');
|
|
|
updateData.leader = newLeader;
|
|
|
}
|
|
|
}
|
|
|
+ // 判断是否都退团了
|
|
|
+ const allRefund = newPersons.every(e => e.status === '1');
|
|
|
+ if (allRefund) updateData.status = '-1';
|
|
|
tran.update('Group', group, updateData);
|
|
|
}
|
|
|
|