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
import { BaseCoolQueue, CoolQueue } from '@cool-midway/task';
import { Inject } from '@midwayjs/core';
import { OrderInfoService } from '../service/info';
 
// 行为
export enum Action {
  // 超时未支付
  TIMEOUT = 0,
  // 自动确认收货
  CONFIRM = 1,
}
 
/**
 * 队列
 */
@CoolQueue()
export abstract class OrderQueue extends BaseCoolQueue {
  @Inject()
  orderInfoService: OrderInfoService;
 
  async data(job: any, done: any) {
    const action = job.data.action;
    if (action == Action.TIMEOUT) {
      // 关闭订单
      await this.orderInfoService.close(job.data.orderId, '超时未支付');
    }
    if (action == Action.CONFIRM) {
      // 自动确认收货
      await this.orderInfoService.autoConfirm(job.data.orderId);
    }
    done();
  }
}