user.js 1.1 KB

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