import { OrderEntity } from '../../entity/order';
import { Inject, Post, Provide, Body } from '@midwayjs/decorator';
import { CoolController, BaseController } from '@cool-midway/core';
import { OrderService } from '../../service/order';

@Provide()
@CoolController({
  api: ['update', 'info', 'page'],
  entity: OrderEntity,
  service: OrderService,
})
export class OrdertController extends BaseController {
  @Inject()
  orderService: OrderService;

  @Post('/summary', { summary: '统计' })
  async summary() {
    const { body } = this.baseCtx.request;
    return this.ok(await this.orderService.summary(body));
  }

  @Post('/query', { summary: '查单' })
  async query(@Body('id') id) {
    return this.ok(await this.orderService.queryByApi(id));
  }

  @Post('/notify', { summary: '通知' })
  async notify(@Body('id') id) {
    return this.ok(await this.orderService.notify(id));
  }

  @Post('/toRefund', { summary: '退款' })
  async toRefund(@Body() payload) {
    return this.ok(await this.orderService.toRefund(payload));
  }

  @Post('/code', { summary: '获取订单通道编码' })
  async code(@Body('id') id) {
    return this.ok(id);
  }

  @Post('/mch', { summary: '获取订单商户编码' })
  async mch(@Body('id') id) {
    return this.ok(id);
  }
}
