|
@@ -149,59 +149,7 @@ class UserCouponService extends CrudService {
|
|
|
uc.canUse = true;
|
|
|
}
|
|
|
if (couponList.length <= 0) return [];
|
|
|
- const dictDataModel = this.ctx.model.Dev.DictData;
|
|
|
- // 过期字典
|
|
|
- const expList = await dictDataModel.find({ code: 'coupon_expire_type' });
|
|
|
- // 减免字典
|
|
|
- const disList = await dictDataModel.find({ code: 'coupon_discount_type' });
|
|
|
- // 使用字典
|
|
|
- const useList = await dictDataModel.find({ code: 'coupon_use_limit' });
|
|
|
- // 领取字典
|
|
|
- const getList = await dictDataModel.find({ code: 'coupon_get_limit' });
|
|
|
- couponList = couponList.map(i => {
|
|
|
- const { _id, canUse, coupon, meta } = i;
|
|
|
- let obj = { _id, canUse, name: _.get(coupon, 'name') };
|
|
|
- // 失效
|
|
|
- const expire_type = _.get(coupon, 'expire_type');
|
|
|
- const expire_type_label = _.get(
|
|
|
- expList.find(f => f.value === expire_type),
|
|
|
- 'label'
|
|
|
- );
|
|
|
- let expire_time = _.get(coupon, `expire_config.${expire_type}`);
|
|
|
- if (expire_time) {
|
|
|
- if (expire_type === 'fixed') expire_time = expire_time.join(' 至 ');
|
|
|
- else {
|
|
|
- expire_time = moment(meta.createdAt).add(expire_time, 'days').format('YYYY-MM-DD HH:mm:ss');
|
|
|
- }
|
|
|
- }
|
|
|
- obj = { ...obj, expire_type, expire_type_label, expire_time };
|
|
|
- // 减免
|
|
|
- const discount_type = _.get(coupon, 'discount_type');
|
|
|
- const discount_type_label = _.get(
|
|
|
- disList.find(f => f.value === discount_type),
|
|
|
- 'label'
|
|
|
- );
|
|
|
- const discount_config = _.get(coupon, 'discount_config');
|
|
|
- obj = { ...obj, discount_type, discount_type_label, discount_config };
|
|
|
- // 使用
|
|
|
- const use_limit = _.get(coupon, 'use_limit');
|
|
|
- const use_limit_label = _.get(
|
|
|
- useList.find(f => f.value === use_limit),
|
|
|
- 'label'
|
|
|
- );
|
|
|
- const use_limit_config = _.get(coupon, 'use_limit_config');
|
|
|
- obj = { ...obj, use_limit, use_limit_label, use_limit_config };
|
|
|
|
|
|
- // 领取
|
|
|
- const get_limit = _.get(coupon, 'get_limit');
|
|
|
- const get_limit_label = _.get(
|
|
|
- getList.find(f => f.value === get_limit),
|
|
|
- 'label'
|
|
|
- );
|
|
|
- const get_limit_config = _.get(coupon, 'get_limit_config');
|
|
|
- obj = { ...obj, get_limit, get_limit_label, get_limit_config };
|
|
|
- return obj;
|
|
|
- });
|
|
|
return couponList;
|
|
|
}
|
|
|
|
|
@@ -502,6 +450,69 @@ class UserCouponService extends CrudService {
|
|
|
});
|
|
|
return arr;
|
|
|
}
|
|
|
+
|
|
|
+ // 转换为显示的格式
|
|
|
+ async makeShowData(couponList) {
|
|
|
+ const dictDataModel = this.ctx.model.Dev.DictData;
|
|
|
+ // 过期字典
|
|
|
+ const expList = await dictDataModel.find({ code: 'coupon_expire_type' });
|
|
|
+ // 减免字典
|
|
|
+ const disList = await dictDataModel.find({ code: 'coupon_discount_type' });
|
|
|
+ // 使用字典
|
|
|
+ const useList = await dictDataModel.find({ code: 'coupon_use_limit' });
|
|
|
+ // 领取字典
|
|
|
+ const getList = await dictDataModel.find({ code: 'coupon_get_limit' });
|
|
|
+ couponList = couponList.map(i => {
|
|
|
+ const { _id, canUse, coupon, meta } = i;
|
|
|
+ let obj = { _id, canUse, name: _.get(coupon, 'name') };
|
|
|
+ // 失效
|
|
|
+ const expire_type = _.get(coupon, 'expire_type');
|
|
|
+ const expire_type_label = _.get(
|
|
|
+ expList.find(f => f.value === expire_type),
|
|
|
+ 'label'
|
|
|
+ );
|
|
|
+ let expire_time = _.get(coupon, `expire_config.${expire_type}`);
|
|
|
+ if (expire_time) {
|
|
|
+ if (expire_type === 'fixed') expire_time = expire_time.join(' 至 ');
|
|
|
+ else {
|
|
|
+ expire_time = moment(meta.createdAt).add(expire_time, 'days').format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ obj = { ...obj, expire_type, expire_type_label, expire_time };
|
|
|
+ // 减免
|
|
|
+ const discount_type = _.get(coupon, 'discount_type');
|
|
|
+ const discount_type_label = _.get(
|
|
|
+ disList.find(f => f.value === discount_type),
|
|
|
+ 'label'
|
|
|
+ );
|
|
|
+ const discount_config = _.get(coupon, 'discount_config');
|
|
|
+ obj = { ...obj, discount_type, discount_type_label, discount_config };
|
|
|
+ // 使用
|
|
|
+ const use_limit = _.get(coupon, 'use_limit');
|
|
|
+ const use_limit_label = _.get(
|
|
|
+ useList.find(f => f.value === use_limit),
|
|
|
+ 'label'
|
|
|
+ );
|
|
|
+ const use_limit_config = _.get(coupon, 'use_limit_config');
|
|
|
+ obj = { ...obj, use_limit, use_limit_label, use_limit_config };
|
|
|
+
|
|
|
+ // 领取
|
|
|
+ const get_limit = _.get(coupon, 'get_limit');
|
|
|
+ const get_limit_label = _.get(
|
|
|
+ getList.find(f => f.value === get_limit),
|
|
|
+ 'label'
|
|
|
+ );
|
|
|
+ const get_limit_config = _.get(coupon, 'get_limit_config');
|
|
|
+ obj = { ...obj, get_limit, get_limit_label, get_limit_config };
|
|
|
+ return obj;
|
|
|
+ });
|
|
|
+ return couponList;
|
|
|
+ }
|
|
|
+ async afterQuery(filter, data) {
|
|
|
+ data = JSON.parse(JSON.stringify(data));
|
|
|
+ data = this.makeShowData(data);
|
|
|
+ return data;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = UserCouponService;
|