cashing.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  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 moment = require('moment');
  7. // 高企申报兑付
  8. class CashingService extends CrudService {
  9. constructor(ctx) {
  10. super(ctx, 'cashing');
  11. this.model = this.ctx.model.Cysci.Cashing;
  12. }
  13. async create({ declare_id, reward_id, ...body }) {
  14. // 将高企/ 研发/奖励 的 is_cashing改成1
  15. if (declare_id) await this.ctx.model.Cysci.Declare.updateOne({ _id: declare_id }, { is_cashing: '1' });
  16. if (reward_id) await this.ctx.model.Cysci.Reward.updateOne({ _id: reward_id }, { is_cashing: '1' });
  17. // 之后将使用的券改为使用 is_use = 1
  18. const { user_id, coupons_id } = body;
  19. await this.ctx.model.Cysci.CouponsApply.updateOne({ user_id, coupons_id }, { is_use: '1' });
  20. // const no = `${moment().format('YYYYMMDD')}${moment().format('x')}DF`;
  21. // body = { ...body, no };
  22. if (declare_id)body.from_id = declare_id;
  23. else if (reward_id)body.from_id = reward_id;
  24. return await this.model.create(body);
  25. }
  26. async getFromId({ from_id }) {
  27. const data = await this.model.findOne({ from_id });
  28. return data;
  29. }
  30. }
  31. module.exports = CashingService;