|
@@ -12,6 +12,7 @@ class GroupService extends CrudService {
|
|
this.model = this.ctx.model.Group.Group;
|
|
this.model = this.ctx.model.Group.Group;
|
|
this.goodsModel = this.ctx.model.Shop.Goods;
|
|
this.goodsModel = this.ctx.model.Shop.Goods;
|
|
this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
|
|
this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
|
|
|
|
+ this.userModel = this.ctx.model.User.User;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -20,10 +21,11 @@ class GroupService extends CrudService {
|
|
* @param {Transaction} tran 数据库事务实例
|
|
* @param {Transaction} tran 数据库事务实例
|
|
*/
|
|
*/
|
|
async create(orderDetail, tran) {
|
|
async create(orderDetail, tran) {
|
|
- const { goods: goodsInfo, customer, shop } = orderDetail;
|
|
|
|
- const goods_id = _.get(goodsInfo, 'goods._id');
|
|
|
|
|
|
+ const { goods: goodsInfos, customer, shop } = orderDetail;
|
|
|
|
+ const g = _.head(goodsInfos);
|
|
|
|
+ const goods_id = _.get(g, 'goods._id');
|
|
const goods = await this.goodsModel.findById(goods_id);
|
|
const goods = await this.goodsModel.findById(goods_id);
|
|
- const goodsSpec_id = _.get(goodsInfo, '_id');
|
|
|
|
|
|
+ const goodsSpec_id = _.get(g, '_id');
|
|
const goodsSpec = await this.goodsSpecModel.findById(goodsSpec_id);
|
|
const goodsSpec = await this.goodsSpecModel.findById(goodsSpec_id);
|
|
const person_limit = _.get(goodsSpec, 'group_config.need_person');
|
|
const person_limit = _.get(goodsSpec, 'group_config.need_person');
|
|
const leader = customer;
|
|
const leader = customer;
|
|
@@ -96,6 +98,20 @@ class GroupService extends CrudService {
|
|
}
|
|
}
|
|
tran.update('Group', group, updateData);
|
|
tran.update('Group', group, updateData);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ async afterQuery(filter, data) {
|
|
|
|
+ data = JSON.parse(JSON.stringify(data));
|
|
|
|
+ for (const i of data) {
|
|
|
|
+ const { persons = [] } = i;
|
|
|
|
+ for (const p of persons) {
|
|
|
|
+ const user = await this.userModel.findById(p.customer, { name: 1 });
|
|
|
|
+ p.name = _.get(user, 'name');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = GroupService;
|
|
module.exports = GroupService;
|