|
@@ -9,6 +9,7 @@ class PlatformActService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'platformact');
|
|
|
this.model = this.ctx.model.System.PlatformAct;
|
|
|
+ this.gjaModel = this.ctx.model.Shop.GoodsJoinAct;
|
|
|
}
|
|
|
async query(filter, { skip = 0, limit, projection } = {}) {
|
|
|
let condition = _.cloneDeep(filter);
|
|
@@ -17,7 +18,10 @@ class PlatformActService extends CrudService {
|
|
|
// 过滤出ref字段
|
|
|
const { populate } = this.getRefMods();
|
|
|
// 带ref查询
|
|
|
- let rs = await this.model.find(condition, projection, { skip, limit, sort: { sort: 1, 'meta.createdAt': -1 } }).populate(populate).exec();
|
|
|
+ let rs = await this.model
|
|
|
+ .find(condition, projection, { skip, limit, sort: { sort: 1, 'meta.createdAt': -1 } })
|
|
|
+ .populate(populate)
|
|
|
+ .exec();
|
|
|
rs = JSON.parse(JSON.stringify(rs));
|
|
|
// 整理ref数据
|
|
|
rs = await this.afterQuery(filter, rs);
|
|
@@ -56,6 +60,13 @@ class PlatformActService extends CrudService {
|
|
|
return { tag, text };
|
|
|
}
|
|
|
|
|
|
+ async beforeUpdate(filter, update) {
|
|
|
+ const id = _.get(filter, 'id');
|
|
|
+ const num = await this.gjaModel.count({ platform_act: id });
|
|
|
+ // 如果活动已经有商品关联了.那就不能修改活动类型了
|
|
|
+ if (num > 0) delete update.type;
|
|
|
+ return { filter, update };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = PlatformActService;
|