util.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
  4. const _ = require('lodash');
  5. // 业务工具
  6. class UtilController extends Controller {
  7. constructor(ctx) {
  8. super(ctx);
  9. this.queryObject = this.ctx.query;
  10. this.bodyObject = this.ctx.request.body;
  11. this.service = this.ctx.service.util;
  12. this.tradeService = this.ctx.service.util.trade;
  13. }
  14. async util() {
  15. const request = this.ctx.request;
  16. console.log(request);
  17. const ip = _.get(request, 'header.x-real-ip');
  18. const forward = _.get(request, 'header.x-forwarded-for');
  19. const host = _.get(request, 'header.host');
  20. const referer = _.get(request, 'header.referer');
  21. const query = this.ctx.query;
  22. const body = _.get(request, 'body');
  23. this.ctx.body = 'GG';
  24. }
  25. /**
  26. * 查询是否可以购买
  27. */
  28. async checkCanBuy() {
  29. const data = await this.tradeService.checkCanBuy(this.bodyObject);
  30. this.ctx.ok({ data });
  31. }
  32. async checkCartBuy() {
  33. const data = await this.tradeService.checkCartBuy(this.bodyObject);
  34. this.ctx.ok({ data });
  35. }
  36. }
  37. module.exports = CrudController(UtilController, {});