wangzhibo
6 天以前 7dcc2997614f849258091f5d66e648317a40d323
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { CoolController, BaseController } from '@cool-midway/core';
import { OrderInfoEntity } from '../../entity/info';
import { OrderInfoService } from '../../service/info';
import { Body, Get, Inject, Post, Query } from '@midwayjs/core';
import { OrderGoodsEntity } from '../../entity/goods';
 
/**
 * 订单信息
 */
@CoolController({
  api: ['info', 'page', 'update'],
  entity: OrderInfoEntity,
  service: OrderInfoService,
  pageQueryOp: {
    fieldEq: ['status'],
    where: ctx => {
      return [
        // 过滤用户ID
        ['a.userId = :userId', { userId: ctx.user.id }],
      ];
    },
  },
})
export class AppOrderInfoController extends BaseController {
  @Inject()
  orderInfoService: OrderInfoService;
 
  @Inject()
  ctx;
 
  @Post('/create', { summary: '创建订单' })
  async create(
    @Body('data')
    data: {
      goodsList: OrderGoodsEntity[];
      addressId: number;
      remark: string;
      title: string;
      couponId: number;
    }
  ) {
    return this.ok(
      await this.orderInfoService.create({
        ...data,
        userId: this.ctx.user.id,
      })
    );
  }
 
  @Post('/cancel', { summary: '取消订单' })
  async cancel(
    @Body('orderId') orderId: number,
    @Body('remark') remark: string
  ) {
    return this.ok(await this.orderInfoService.close(orderId, remark));
  }
 
  @Post('/refund', { summary: '退款' })
  async refund(
    @Body('orderId') orderId: number,
    @Body('reason') reason: string
  ) {
    return this.ok(
      await this.orderInfoService.refund(this.ctx.user.id, orderId, reason)
    );
  }
 
  @Get('/confirm', { summary: '确认收货' })
  async confirm(@Query('orderId') orderId: number) {
    return this.ok(
      await this.orderInfoService.confirm(orderId, this.ctx.user.id)
    );
  }
 
  @Get('/logistics', { summary: '物流信息' })
  async logistics(@Query('orderId') orderId: number) {
    return this.ok(
      await this.orderInfoService.logistics(orderId, this.ctx.user.id)
    );
  }
 
  @Get('/userCount', { summary: '用户订单统计' })
  async userCount() {
    return this.ok(await this.orderInfoService.userCount(this.ctx.user.id));
  }
}