couponsApply.js 851 B

123456789101112131415161718192021222324
  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. const { ObjectId } = require('mongoose').Types;
  7. // 创新券申领表
  8. class CouponsApplyService extends CrudService {
  9. constructor(ctx) {
  10. super(ctx, 'coupons_apply');
  11. this.model = this.ctx.model.Cysci.CouponsApply;
  12. }
  13. async create(body) {
  14. const { user_id, coupons_id } = body;
  15. console.log(user_id, coupons_id);
  16. const count = await this.model.count({ user_id: ObjectId(user_id), coupons_id: ObjectId(coupons_id) });
  17. console.log(count);
  18. if (count) throw new BusinessError(ErrorCode.DATA_EXISTED, '已领取该券');
  19. return await this.model.create(body);
  20. }
  21. }
  22. module.exports = CouponsApplyService;