|
@@ -14,6 +14,7 @@ class GroupService extends CrudService {
|
|
|
this.goodsModel = this.ctx.model.Shop.Goods;
|
|
|
this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
|
|
|
this.userModel = this.ctx.model.User.User;
|
|
|
+ this.orderModel = this.ctx.model.Trade.Order;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -82,17 +83,21 @@ class GroupService extends CrudService {
|
|
|
* @param tran
|
|
|
*/
|
|
|
async refund({ group, customer }, tran) {
|
|
|
- const groupData = await this.model.findById(group);
|
|
|
+ let groupData = await this.model.findById(group);
|
|
|
if (!groupData) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到拼团数据');
|
|
|
- const { persons, leader } = groupData;
|
|
|
+ groupData = JSON.parse(JSON.stringify(groupData));
|
|
|
+ const { persons, leader, status } = groupData;
|
|
|
+ // 检查团状态,如果已经结束,就不需要该团这边的数据了
|
|
|
+ if (status !== '0') return;
|
|
|
const newPersons = JSON.parse(JSON.stringify(persons));
|
|
|
- const findPersonCondition = (c1, c2) => c1 === c2;
|
|
|
+ const findPersonCondition = (c1, c2) => ObjectId(c1).equals(c2);
|
|
|
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));
|
|
|
p.status = '1';
|
|
|
+ p.out_time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
newPersons[i] = p;
|
|
|
- const updateData = { newPersons };
|
|
|
+ const updateData = { persons: newPersons };
|
|
|
// 团长退团了,根据入团时间降序,顺位成为团长
|
|
|
if (leader === customer) {
|
|
|
let newLeader;
|
|
@@ -106,6 +111,18 @@ class GroupService extends CrudService {
|
|
|
tran.update('Group', group, updateData);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取团信息
|
|
|
+ * @param {Object} query 地址参数
|
|
|
+ * @param {String} query.order_id 订单id
|
|
|
+ */
|
|
|
+ async getGroup({ order_id }) {
|
|
|
+ assert(order_id, '缺少订单信息');
|
|
|
+ const order = await this.orderModel.findById(order_id, { group: 1 });
|
|
|
+ if (!order) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
|
|
|
+ return _.get(order, 'group');
|
|
|
+ }
|
|
|
+
|
|
|
async beforeQuery(filter) {
|
|
|
const gsv = _.get(filter, 'goodsSpec._id');
|
|
|
const gv = _.get(filter, 'goods._id');
|