import { Body, Controller, Inject, Post } from '@midwayjs/decorator'; import { ApiTags } from '@midwayjs/swagger'; import { FrameworkErrorEnum, ServiceError } from 'free-midway-component'; import { GroupOrderService } from '../service/groupOrder.service'; import { Kd100Service } from '../util/kd100'; import _ = require('lodash'); import { GroupAfterSaleService } from '../service/groupAfterSale.service'; @ApiTags(['订单其他接口']) @Controller('/orderOthers') export class OrderOthersController { @Inject() kd100: Kd100Service; @Inject() orderService: GroupOrderService; @Inject() afterSaleService: GroupAfterSaleService; @Post('/transport') async transport(@Body('order') order: string) { const od = await this.orderService.fetch(order, { populate: false, lean: true }); if (!od) throw new ServiceError('未找到订单信息', FrameworkErrorEnum.NOT_FOUND_DATA); const transport = _.get(od, 'transport', []); if (transport.length <= 0) return []; const result = []; for (const t of transport) { const no = _.get(t, 'shop_transport_no'); const type = _.get(t, 'shop_transport_type'); const tr = await this.kd100.search({ no, type }); result.push(tr); } return result; } @Post('/afterSale/transport') async afterSaleTransport(@Body('id') id: string) { const asd = await this.afterSaleService.fetch(id); if (!asd) throw new ServiceError('未找到售后数据', FrameworkErrorEnum.NOT_FOUND_DATA); const transport = _.get(asd, 'transport', {}); const ct = { no: _.get(transport, 'customer_transport_no'), type: _.get(transport, 'customer_transport_type') }; const st = { no: _.get(transport, 'shop_transport_no'), type: _.get(transport, 'shop_transport_type') }; const result = { customer: {}, shop: {} }; if (ct.no && ct.type) result.customer = await this.kd100.search(ct); if (st.no && st.type) result.shop = await this.kd100.search(st); return result; } }