wangzhibo
4 天以前 c19f1f7e21c93d1f13b4f44a8a615f65af577559
src/modules/order/service/info.ts
@@ -7,6 +7,7 @@
import { OrderGoodsEntity } from '../entity/goods';
import * as moment from 'moment';
import { UserAddressService } from '../../user/service/address';
import { UserInfoEntity } from '../../user/entity/info';
import { Action, OrderQueue } from '../queue/order';
import { OrderPayService } from './pay';
import { PluginService } from '../../plugin/service/info';
@@ -14,6 +15,7 @@
import { MarketCouponInfoService } from '../../market/service/coupon/info';
import { MarketCouponUserEntity } from '../../market/entity/coupon/user';
import { BaseSysParamService } from '../../base/service/sys/param';
import { BasicdataSorterEntity } from '../../basicdata/entity/sorter';
import BigNumber from 'bignumber.js';
/**
@@ -29,6 +31,9 @@
  @InjectEntityModel(MarketCouponUserEntity)
  marketCouponUserEntity: Repository<MarketCouponUserEntity>;
  @InjectEntityModel(BasicdataSorterEntity)
  basicdataSorterEntity: Repository<BasicdataSorterEntity>;
  @Inject()
  orderGoodsService: OrderGoodsService;
@@ -418,6 +423,72 @@
  }
  /**
   * 分拣员查看校园商城订单(按学校过滤)
   */
  async sorterPage(query: any) {
    const { sorterId, status, page = 1, size = 10, keyWord } = query || {};
    if (!sorterId) {
      throw new CoolCommException('缺少分拣员信息');
    }
    const sorter = await this.basicdataSorterEntity.findOneBy({
      businessId: String(sorterId),
    });
    if (!sorter || sorter.status !== 0) {
      throw new CoolCommException('分拣员账号不可用');
    }
    const find = this.orderInfoEntity
      .createQueryBuilder('a')
      .select([
        'a.*',
        'b.nickName AS nickName',
        'b.phone AS phone',
        'b.unionid AS unionid',
      ])
      .leftJoin(UserInfoEntity, 'b', 'a.userId = b.unionid');
    if (sorter.departmentId) {
      find.andWhere('b.departmentId = :deptId', {
        deptId: sorter.departmentId,
      });
    }
    if (status !== undefined && status !== null && status !== '') {
      find.andWhere('a.status = :status', { status: Number(status) });
    }
    if (keyWord) {
      find.andWhere(
        '(a.orderNum LIKE :kw OR a.title LIKE :kw OR b.nickName LIKE :kw OR b.phone LIKE :kw)',
        { kw: `%${keyWord}%` }
      );
    }
    find.orderBy('a.createTime', 'DESC');
    const result = await this.entityRenderPage(
      find,
      { ...query, page, size },
      false
    );
    const ids = (result.list || []).map((e: any) => e.id);
    if (ids.length) {
      const goodsList = await this.orderGoodsService.getByOrderIds(ids);
      for (const item of result.list) {
        item.goodsList = goodsList.filter(e => e.orderId == item.id);
      }
    }
    return result;
  }
  /**
   * 校园现场发放(不走物流)
   */
  async sorterDeliver(orderId: number, sorterId: string) {
    if (!sorterId) {
      throw new CoolCommException('缺少分拣员信息');
    }
    return this.deliver(orderId, {
      company: '现场发放',
      num: String(sorterId),
    });
  }
  /**
   * 检查库存
   * @param goodsList
   */