wangzhibo
6 天以前 3f249e399659dcd09d3fe58071b146e50e45c17f
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
87
88
import { CoolController, BaseController } from '@cool-midway/core';
import { OrderInfoEntity } from '../../entity/info';
import { OrderInfoService } from '../../service/info';
import { UserInfoEntity } from '../../../user/entity/info';
import { Body, Get, Inject, Post, Query } from '@midwayjs/core';
 
/**
 * 订单信息
 */
@CoolController({
  api: ['delete', 'update', 'info', 'list', 'page'],
  entity: OrderInfoEntity,
  service: OrderInfoService,
  pageQueryOp: {
    keyWordLikeFields: ['a.title', 'a.orderNum', 'b.nickName'],
    select: ['a.*', 'b.nickName', 'b.avatarUrl'],
    fieldEq: ['a.status', 'a.payType'],
    join: [
      {
        entity: UserInfoEntity,
        alias: 'b',
        condition: 'a.userId = b.id',
      },
    ],
    where: ctx => {
      const { startTime, endTime, refundApplyStartTime, refundApplyEndTime } =
        ctx.request.body;
      return [
        // 过滤创建时间
        ['a.createTime >= :startTime', { startTime }, startTime],
        ['a.createTime <= :endTime', { endTime }, endTime],
        // 过滤退款时间
        [
          'a.refundApplyTime >= :refundApplyStartTime',
          { refundApplyStartTime },
          refundApplyStartTime,
        ],
        [
          'a.refundApplyTime <= :refundApplyEndTime',
          { refundApplyEndTime },
          refundApplyEndTime,
        ],
      ];
    },
  },
})
export class AdminOrderInfoController extends BaseController {
  @Inject()
  orderInfoService: OrderInfoService;
 
  @Post('/refundHandle', { summary: '退款处理' })
  async refundHandle(
    @Body('orderId') orderId: number,
    // 0-拒绝 1-同意
    @Body('action') action: number,
    // 拒绝原因
    @Body('refuseReason') refuseReason: string,
    // 退款金额
    @Body('amount') amount: number
  ) {
    await this.orderInfoService.refundHandle(
      orderId,
      action,
      refuseReason,
      amount
    );
    return this.ok();
  }
 
  @Get('/logistics', { summary: '物流信息' })
  async logistics(@Query('orderId') orderId: number) {
    return this.ok(await this.orderInfoService.logistics(orderId));
  }
 
  @Post('/deliver', { summary: '发货' })
  async deliver(
    @Body('orderId') orderId: number,
    @Body('logistics')
    logistics: {
      // 物流公司
      company: string;
      // 物流单号
      num: string;
    }
  ) {
    return this.ok(await this.orderInfoService.deliver(orderId, logistics));
  }
}