|
@@ -118,9 +118,15 @@ class GroupService extends CrudService {
|
|
|
*/
|
|
|
async getGroup({ order_id }) {
|
|
|
assert(order_id, '缺少订单信息');
|
|
|
- const order = await this.orderModel.findById(order_id, { group: 1 });
|
|
|
+ const order = await this.orderModel.findById(order_id, { group: 1, customer: 1 });
|
|
|
if (!order) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
|
|
|
- return _.get(order, 'group');
|
|
|
+ let group = _.get(order, 'group');
|
|
|
+ if (!ObjectId.isValid(group)) {
|
|
|
+ const customer = _.get(order, 'customer');
|
|
|
+ const groupData = await this.model.findOne({ 'persons.customer': customer }, { _id: 1 }).sort({ 'meta.createdAt': -1 });
|
|
|
+ group = _.get(groupData, '_id');
|
|
|
+ }
|
|
|
+ return group;
|
|
|
}
|
|
|
|
|
|
async beforeQuery(filter) {
|