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