|
@@ -11,6 +11,45 @@ class DockUserService extends CrudService {
|
|
|
super(ctx, 'dock_user');
|
|
|
this.model = this.ctx.model.Dock.DockUser;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 根据展会id查询参展产品
|
|
|
+ * @param {Object} query 查询条件
|
|
|
+ * @param {Object} options 其他条件
|
|
|
+ * @property {String} dock_id 展会id
|
|
|
+ * @property {Object} condition 其他查询条件
|
|
|
+ */
|
|
|
+ async getProductListByDockId({ dock_id, ...condition }, { skip = 0, limit = 0 }) {
|
|
|
+ assert(dock_id, '缺少展会信息');
|
|
|
+ condition = this.dealFilter(condition);
|
|
|
+ // 先查展会下的所有产品
|
|
|
+ const pipeline = [{ $match: { dock_id } }];
|
|
|
+ // 只留产品列表
|
|
|
+ pipeline.push({ $project: { productList: 1 } });
|
|
|
+ // 将产品列表数组拆开成单项Object
|
|
|
+ pipeline.push({ $unwind: '$productList' });
|
|
|
+ // 其他针对产品的查询条件
|
|
|
+ pipeline.push({ $match: condition });
|
|
|
+ // 满足条件的总数
|
|
|
+ const totalRes = await this.model.aggregate([ ...pipeline, { $group: { _id: null, total: { $sum: 1 } } }]);
|
|
|
+ let total = 0;
|
|
|
+ if (totalRes.length > 0) {
|
|
|
+ const totalHead = _.head(totalRes);
|
|
|
+ total = _.get(totalHead, 'total');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分页的是产品,不是展会
|
|
|
+ if (limit) {
|
|
|
+ pipeline.push({ $skip: parseInt(skip) });
|
|
|
+ pipeline.push({ $limit: parseInt(limit) });
|
|
|
+ }
|
|
|
+ let data = await this.model.aggregate(pipeline);
|
|
|
+ data = data.map(i => {
|
|
|
+ const { productList } = i;
|
|
|
+ return productList;
|
|
|
+ });
|
|
|
+ data = _.compact(data);
|
|
|
+ return { data, total };
|
|
|
+ }
|
|
|
async create(data) {
|
|
|
const { dock_id, user_id } = data;
|
|
|
let { productList } = data;
|
|
@@ -36,7 +75,6 @@ class DockUserService extends CrudService {
|
|
|
}
|
|
|
user.productList = user.productList.concat(productList);
|
|
|
return await user.save();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
async update({ id }, data) {
|
|
@@ -45,7 +83,7 @@ class DockUserService extends CrudService {
|
|
|
data.productList = productList.map(i => {
|
|
|
console.log(i.status);
|
|
|
if (i.status === '1') data.status = '1';
|
|
|
- if (!i._id)i._id = ObjectId();
|
|
|
+ if (!i._id) i._id = ObjectId();
|
|
|
else i._id = ObjectId(i._id);
|
|
|
return i;
|
|
|
});
|
|
@@ -82,8 +120,6 @@ class DockUserService extends CrudService {
|
|
|
object.status = status;
|
|
|
await object.save();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
module.exports = DockUserService;
|