|
@@ -3,7 +3,7 @@ const { CrudService } = require('naf-framework-mongoose-free/lib/service');
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
const _ = require('lodash');
|
|
const _ = require('lodash');
|
|
const assert = require('assert');
|
|
const assert = require('assert');
|
|
-
|
|
|
|
|
|
+const { ObjectId } = require('mongoose').Types;
|
|
//
|
|
//
|
|
class OrderDetailService extends CrudService {
|
|
class OrderDetailService extends CrudService {
|
|
constructor(ctx) {
|
|
constructor(ctx) {
|
|
@@ -48,6 +48,7 @@ class OrderDetailService extends CrudService {
|
|
}
|
|
}
|
|
// await this.model.insertMany(arr);
|
|
// await this.model.insertMany(arr);
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 将商品规格列表中,优惠的部分提取出来,分单用
|
|
* 将商品规格列表中,优惠的部分提取出来,分单用
|
|
* @param {Array} goodsList 某店的商品列表
|
|
* @param {Array} goodsList 某店的商品列表
|
|
@@ -77,6 +78,17 @@ class OrderDetailService extends CrudService {
|
|
const freight_total = goodsList.reduce((p, n) => this.ctx.plus(p, this.ctx.multiply(n.freight, n.buy_num)), 0);
|
|
const freight_total = goodsList.reduce((p, n) => this.ctx.plus(p, this.ctx.multiply(n.freight, n.buy_num)), 0);
|
|
return { goods_total, freight_total };
|
|
return { goods_total, freight_total };
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ async fetch(filter) {
|
|
|
|
+ assert(filter);
|
|
|
|
+ filter = await this.beforeFetch(filter);
|
|
|
|
+ const { _id, id } = filter;
|
|
|
|
+ if (_id || id) filter = { _id: ObjectId(_id || id) };
|
|
|
|
+ const { populate } = this.getRefMods();
|
|
|
|
+ let res = await this.model.findOne(filter).populate(populate).exec();
|
|
|
|
+ res = await this.afterFetch(filter, res);
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = OrderDetailService;
|
|
module.exports = OrderDetailService;
|