orderOthers.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Body, Controller, Inject, Post } from '@midwayjs/decorator';
  2. import { ApiTags } from '@midwayjs/swagger';
  3. import { FrameworkErrorEnum, ServiceError } from 'free-midway-component';
  4. import { GroupOrderService } from '../service/groupOrder.service';
  5. import { Kd100Service } from '../util/kd100';
  6. import _ = require('lodash');
  7. import { GroupAfterSaleService } from '../service/groupAfterSale.service';
  8. @ApiTags(['订单其他接口'])
  9. @Controller('/orderOthers')
  10. export class OrderOthersController {
  11. @Inject()
  12. kd100: Kd100Service;
  13. @Inject()
  14. orderService: GroupOrderService;
  15. @Inject()
  16. afterSaleService: GroupAfterSaleService;
  17. @Post('/transport')
  18. async transport(@Body('order') order: string) {
  19. const od = await this.orderService.fetch(order, { populate: false, lean: true });
  20. if (!od) throw new ServiceError('未找到订单信息', FrameworkErrorEnum.NOT_FOUND_DATA);
  21. const transport = _.get(od, 'transport', []);
  22. if (transport.length <= 0) return [];
  23. const result = [];
  24. for (const t of transport) {
  25. const no = _.get(t, 'shop_transport_no');
  26. const type = _.get(t, 'shop_transport_type');
  27. const tr = await this.kd100.search({ no, type });
  28. result.push(tr);
  29. }
  30. return result;
  31. }
  32. @Post('/afterSale/transport')
  33. async afterSaleTransport(@Body('id') id: string) {
  34. const asd = await this.afterSaleService.fetch(id);
  35. if (!asd) throw new ServiceError('未找到售后数据', FrameworkErrorEnum.NOT_FOUND_DATA);
  36. const transport = _.get(asd, 'transport', {});
  37. const ct = { no: _.get(transport, 'customer_transport_no'), type: _.get(transport, 'customer_transport_type') };
  38. const st = { no: _.get(transport, 'shop_transport_no'), type: _.get(transport, 'shop_transport_type') };
  39. const result = { customer: {}, shop: {} };
  40. if (ct.no && ct.type) result.customer = await this.kd100.search(ct);
  41. if (st.no && st.type) result.shop = await this.kd100.search(st);
  42. return result;
  43. }
  44. }