|
@@ -99,10 +99,11 @@ class GroupService extends CrudService {
|
|
|
newPersons[i] = p;
|
|
|
const updateData = { persons: newPersons };
|
|
|
// 团长退团了,根据入团时间降序,顺位成为团长
|
|
|
- if (leader === customer) {
|
|
|
+ if (ObjectId(leader).equals(customer)) {
|
|
|
let newLeader;
|
|
|
- const orderList = _.orderBy(newPersons, [ 'status', 'join_time' ], [ 'asc', 'asc' ]);
|
|
|
+ const orderList = _.orderBy(newPersons.filter(f => f.customer !== customer), [ 'status', 'join_time' ], [ 'asc', 'asc' ]);
|
|
|
const head = _.head(orderList);
|
|
|
+ console.log(head);
|
|
|
if (head && head.status === '0') {
|
|
|
newLeader = _.get(head, 'customer');
|
|
|
updateData.leader = newLeader;
|
|
@@ -111,6 +112,7 @@ class GroupService extends CrudService {
|
|
|
// 判断是否都退团了
|
|
|
const allRefund = newPersons.every(e => e.status === '1');
|
|
|
if (allRefund) updateData.status = '-1';
|
|
|
+ console.log(updateData);
|
|
|
tran.update('Group', group, updateData);
|
|
|
}
|
|
|
|
|
@@ -134,9 +136,13 @@ class GroupService extends CrudService {
|
|
|
|
|
|
async beforeQuery(filter) {
|
|
|
const gsv = _.get(filter, 'goodsSpec._id');
|
|
|
+ if (gsv) filter['goodsSpec._id'] = ObjectId(gsv);
|
|
|
const gv = _.get(filter, 'goods._id');
|
|
|
if (gv) filter['goods._id'] = ObjectId(gv);
|
|
|
- if (gsv) filter['goodsSpec._id'] = ObjectId(gsv);
|
|
|
+ const p = _.get(filter, 'persons.customer');
|
|
|
+ if (p) {
|
|
|
+ filter['persons.status'] = '0';
|
|
|
+ }
|
|
|
return filter;
|
|
|
}
|
|
|
async afterQuery(filter, data) {
|