| | |
| | | * @param data |
| | | */ |
| | | async create(data: { |
| | | userId: number; |
| | | userId: string; |
| | | goodsList: OrderGoodsEntity[]; |
| | | addressId: number; |
| | | remark: string; |
| | | title: string; |
| | | couponId?: number; |
| | | payType?: number; |
| | | }) { |
| | | const address = await this.userAddressService.info(data.addressId); |
| | | const payType = Number(data.payType) || 0; |
| | | const order = { |
| | | userId: data.userId, |
| | | address, |
| | | remark: data.remark, |
| | | title: data.title, |
| | | goodsList: data.goodsList, |
| | | payType, |
| | | } as OrderInfoEntity; |
| | | // 检查库存 |
| | | await this.checkStock(data.goodsList); |
| | |
| | | // 生成订单号 |
| | | const orderNum = await this.generateOrderNum(order.id); |
| | | |
| | | // 更新订单 |
| | | await this.orderInfoEntity.update(order.id, { |
| | | orderNum, |
| | | payType, |
| | | }); |
| | | |
| | | // 保存订单商品 |
| | |
| | | * 物流信息 |
| | | * @param orderId |
| | | */ |
| | | async logistics(orderId: number, userId?: number) { |
| | | async logistics(orderId: number, userId?: string) { |
| | | const order: OrderInfoEntity = await this.info(orderId); |
| | | if (userId && order.userId != userId) { |
| | | throw new CoolCommException('非法操作'); |