'use strict'; const { CrudService } = require('naf-framework-mongoose-free/lib/service'); const { BusinessError, ErrorCode } = require('naf-core').Error; const _ = require('lodash'); const assert = require('assert'); // class UserService extends CrudService { constructor(ctx) { super(ctx, 'user'); this.orderModel = this.ctx.model.Trade.Order; this.orderDetailModel = this.ctx.model.Trade.OrderDetail; this.afterSaleModel = this.ctx.model.Trade.AfterSale; } async toDeal() { const customer = _.get(this.ctx, 'user._id'); if (!customer) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到当前用户信息'); // 未支付订单/已支付订单/发货中订单/售后 const notPay = await this.orderModel.count({ customer, status: '0' }); const isPay = await this.orderDetailModel.count({ customer, status: '1' }); const allSend = await this.orderDetailModel.count({ customer, status: '2' }); const afterSale = await this.afterSaleModel.count({ customer, status: { $in: [ '0', '1', '2', '3', '4', '5' ] } }); return { notPay, isPay, allSend, afterSale }; } } module.exports = UserService;