|
@@ -9,11 +9,18 @@ class OrderService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'order');
|
|
|
this.orderModel = this.ctx.model.Trade.Order;
|
|
|
+ this.orderDetailModel = this.ctx.model.Trade.OrderDetail;
|
|
|
this.shopModel = this.ctx.model.Shop.Shop;
|
|
|
this.goodsRateModel = this.ctx.model.Shop.GoodsRate;
|
|
|
this.afterSaleModel = this.ctx.model.Trade.AfterSale;
|
|
|
}
|
|
|
|
|
|
+ async getOrder({ id }) {
|
|
|
+ const num = await this.orderModel.count({ _id: id });
|
|
|
+ if (num > 0) return this.ctx.service.trade.order.fetch({ id });
|
|
|
+ return this.ctx.service.trade.orderDetail.fetch({ id });
|
|
|
+ }
|
|
|
+
|
|
|
async allOrder(query = {}) {
|
|
|
const { skip, limit } = query;
|
|
|
const customer = _.get(this.ctx, 'user._id');
|
|
@@ -59,18 +66,15 @@ class OrderService extends CrudService {
|
|
|
let obj = {};
|
|
|
if (pay) {
|
|
|
// 这个是order表的数据,需要用order的计算方式
|
|
|
- const buy_num_total = goods.reduce(
|
|
|
- (p, n) => {
|
|
|
- let num = 0;
|
|
|
- if (_.get(n, 'is_set') === '0') num = _.get(n, 'buy_num');
|
|
|
- else {
|
|
|
- const goods = _.get(n, 'goods', []);
|
|
|
- num = goods.reduce((np, nn) => this.ctx.plus(np, nn.buy_num), 0);
|
|
|
- }
|
|
|
- return this.ctx.plus(p, num);
|
|
|
- },
|
|
|
- 0
|
|
|
- );
|
|
|
+ const buy_num_total = goods.reduce((p, n) => {
|
|
|
+ let num = 0;
|
|
|
+ if (_.get(n, 'is_set') === '0') num = _.get(n, 'buy_num');
|
|
|
+ else {
|
|
|
+ const goods = _.get(n, 'goods', []);
|
|
|
+ num = goods.reduce((np, nn) => this.ctx.plus(np, nn.buy_num), 0);
|
|
|
+ }
|
|
|
+ return this.ctx.plus(p, num);
|
|
|
+ }, 0);
|
|
|
obj.buy_num_total = buy_num_total;
|
|
|
obj.real_pay = _.get(i, 'pay.pay_money');
|
|
|
const shopData = _.pick(_.head(goods), [ 'shop', 'shop_name' ]);
|