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
import {
  CoolController,
  BaseController,
  CoolUrlTag,
  TagTypes,
} from '@cool-midway/core';
import { GoodsInfoEntity } from '../../entity/info';
import { GoodsInfoService } from '../../service/info';
import { GoodsTypeEntity } from '../../entity/type';
 
/**
 * 商品信息
 */
@CoolUrlTag({
  key: TagTypes.IGNORE_TOKEN,
  value: ['page', 'info'],
})
@CoolController({
  api: ['page', 'info'],
  entity: GoodsInfoEntity,
  service: GoodsInfoService,
  pageQueryOp: {
    keyWordLikeFields: ['title'],
    fieldEq: ['a.typeId'],
    select: ['a.*', 'b.name as typeName'],
    where: ctx => {
      const { minPrice, maxPrice } = ctx.request.body;
      return [
        // 过滤掉已下架商品
        ['a.status = :status', { status: 1 }],
        // 价格区间
        ['a.price >= :minPrice', { minPrice }, minPrice],
        ['a.price <= :maxPrice', { maxPrice }, maxPrice],
      ];
    },
    join: [
      {
        entity: GoodsTypeEntity,
        alias: 'b',
        condition: 'a.typeId = b.id',
      },
    ],
  },
})
export class AppGoodsInfoController extends BaseController {}