mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-29 18:51:53 +08:00
trade:下单时,如果是门店自提,增加核销码的生成
This commit is contained in:
parent
1b477aaa0d
commit
35569c5ec8
@ -18,12 +18,12 @@ public enum DeliveryTypeEnum implements IntArrayValuable {
|
|||||||
EXPRESS(1, "快递发货"),
|
EXPRESS(1, "快递发货"),
|
||||||
PICK_UP(2, "用户自提"),;
|
PICK_UP(2, "用户自提"),;
|
||||||
|
|
||||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DeliveryTypeEnum::getMode).toArray();
|
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DeliveryTypeEnum::getType).toArray();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配送方式
|
* 配送方式
|
||||||
*/
|
*/
|
||||||
private final Integer mode;
|
private final Integer type;
|
||||||
/**
|
/**
|
||||||
* 状态名
|
* 状态名
|
||||||
*/
|
*/
|
||||||
|
@ -8,7 +8,7 @@ GET {{appApi}}/trade/order/settlement?type=0&items[0].cartId=50&couponId=1
|
|||||||
Authorization: Bearer {{appToken}}
|
Authorization: Bearer {{appToken}}
|
||||||
tenant-id: {{appTenentId}}
|
tenant-id: {{appTenentId}}
|
||||||
|
|
||||||
### /trade-order/create 创建订单(基于商品)
|
### /trade-order/create 创建订单(基于商品)【快递】
|
||||||
POST {{appApi}}/trade/order/create
|
POST {{appApi}}/trade/order/create
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Authorization: Bearer {{appToken}}
|
Authorization: Bearer {{appToken}}
|
||||||
@ -27,6 +27,27 @@ tenant-id: {{appTenentId}}
|
|||||||
"remark": "我是备注"
|
"remark": "我是备注"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
### /trade-order/create 创建订单(基于商品)【自提】
|
||||||
|
POST {{appApi}}/trade/order/create
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Bearer {{appToken}}
|
||||||
|
tenant-id: {{appTenentId}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"pointStatus": true,
|
||||||
|
"deliveryType": 2,
|
||||||
|
"pickUpStoreId": 1,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"skuId": 1,
|
||||||
|
"count": 2
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"remark": "我是备注",
|
||||||
|
"receiverName": "土豆",
|
||||||
|
"receiverMobile": "15601691300"
|
||||||
|
}
|
||||||
|
|
||||||
### 获得订单交易的分页
|
### 获得订单交易的分页
|
||||||
GET {{appApi}}/trade/order/page?pageNo=1&pageSize=10
|
GET {{appApi}}/trade/order/page?pageNo=1&pageSize=10
|
||||||
Authorization: Bearer {{appToken}}
|
Authorization: Bearer {{appToken}}
|
||||||
|
@ -65,14 +65,10 @@ public interface TradeOrderConvert {
|
|||||||
@Mapping(source = "calculateRespBO.price.deliveryPrice", target = "deliveryPrice"),
|
@Mapping(source = "calculateRespBO.price.deliveryPrice", target = "deliveryPrice"),
|
||||||
@Mapping(source = "calculateRespBO.price.couponPrice", target = "couponPrice"),
|
@Mapping(source = "calculateRespBO.price.couponPrice", target = "couponPrice"),
|
||||||
@Mapping(source = "calculateRespBO.price.pointPrice", target = "pointPrice"),
|
@Mapping(source = "calculateRespBO.price.pointPrice", target = "pointPrice"),
|
||||||
@Mapping(source = "calculateRespBO.price.payPrice", target = "payPrice"),
|
@Mapping(source = "calculateRespBO.price.payPrice", target = "payPrice")
|
||||||
@Mapping(source = "address.name", target = "receiverName"),
|
|
||||||
@Mapping(source = "address.mobile", target = "receiverMobile"),
|
|
||||||
@Mapping(source = "address.areaId", target = "receiverAreaId"),
|
|
||||||
@Mapping(source = "address.detailAddress", target = "receiverDetailAddress"),
|
|
||||||
})
|
})
|
||||||
TradeOrderDO convert(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO,
|
TradeOrderDO convert(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO,
|
||||||
TradePriceCalculateRespBO calculateRespBO, AddressRespDTO address);
|
TradePriceCalculateRespBO calculateRespBO);
|
||||||
|
|
||||||
TradeOrderRespDTO convert(TradeOrderDO orderDO);
|
TradeOrderRespDTO convert(TradeOrderDO orderDO);
|
||||||
|
|
||||||
@ -215,6 +211,7 @@ public interface TradeOrderConvert {
|
|||||||
TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO().setUserId(userId)
|
TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO().setUserId(userId)
|
||||||
.setCouponId(settlementReqVO.getCouponId()).setPointStatus(settlementReqVO.getPointStatus())
|
.setCouponId(settlementReqVO.getCouponId()).setPointStatus(settlementReqVO.getPointStatus())
|
||||||
.setDeliveryType(settlementReqVO.getDeliveryType()).setAddressId(settlementReqVO.getAddressId())
|
.setDeliveryType(settlementReqVO.getDeliveryType()).setAddressId(settlementReqVO.getAddressId())
|
||||||
|
.setPickUpStoreId(settlementReqVO.getPickUpStoreId())
|
||||||
.setItems(new ArrayList<>(settlementReqVO.getItems().size()));
|
.setItems(new ArrayList<>(settlementReqVO.getItems().size()));
|
||||||
// 商品项的构建
|
// 商品项的构建
|
||||||
Map<Long, CartDO> cartMap = convertMap(cartList, CartDO::getId);
|
Map<Long, CartDO> cartMap = convertMap(cartList, CartDO::getId);
|
||||||
|
@ -224,6 +224,10 @@ public class TradeOrderDO extends BaseDO {
|
|||||||
* 关联 {@link DeliveryPickUpStoreDO#getId()}
|
* 关联 {@link DeliveryPickUpStoreDO#getId()}
|
||||||
*/
|
*/
|
||||||
private Long pickUpStoreId;
|
private Long pickUpStoreId;
|
||||||
|
/**
|
||||||
|
* 自提核销码
|
||||||
|
*/
|
||||||
|
private String pickUpVerifyCode;
|
||||||
|
|
||||||
// ========== 售后基本信息 ==========
|
// ========== 售后基本信息 ==========
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.service.order;
|
|||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||||
@ -42,7 +43,6 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
|
|||||||
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper;
|
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper;
|
||||||
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper;
|
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper;
|
||||||
import cn.iocoder.yudao.module.trade.dal.redis.no.TradeOrderNoRedisDAO;
|
import cn.iocoder.yudao.module.trade.dal.redis.no.TradeOrderNoRedisDAO;
|
||||||
import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants;
|
|
||||||
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
|
import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum;
|
||||||
import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum;
|
import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum;
|
||||||
import cn.iocoder.yudao.module.trade.enums.order.*;
|
import cn.iocoder.yudao.module.trade.enums.order.*;
|
||||||
@ -203,44 +203,30 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
|
|
||||||
// TODO @puhui999:订单超时,自动取消;
|
// TODO @puhui999:订单超时,自动取消;
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验收件地址是否存在
|
|
||||||
*
|
|
||||||
* @param userId 用户编号
|
|
||||||
* @param addressId 收件地址编号
|
|
||||||
* @return 收件地址
|
|
||||||
*/
|
|
||||||
private AddressRespDTO validateAddress(Long userId, Long addressId) {
|
|
||||||
AddressRespDTO address = addressApi.getAddress(addressId, userId);
|
|
||||||
if (address == null) {
|
|
||||||
throw exception(ErrorCodeConstants.ORDER_CREATE_ADDRESS_NOT_FOUND);
|
|
||||||
}
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TradeOrderDO createTradeOrder(Long userId, String clientIp, AppTradeOrderCreateReqVO createReqVO,
|
private TradeOrderDO createTradeOrder(Long userId, String clientIp, AppTradeOrderCreateReqVO createReqVO,
|
||||||
TradePriceCalculateRespBO calculateRespBO) {
|
TradePriceCalculateRespBO calculateRespBO) {
|
||||||
// 用户选择物流配送的时候才需要填写收货地址
|
TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, clientIp, createReqVO, calculateRespBO);
|
||||||
AddressRespDTO address = new AddressRespDTO();
|
|
||||||
if (Objects.equals(createReqVO.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getMode())) {
|
|
||||||
// 用户收件地址的校验
|
|
||||||
address = validateAddress(userId, createReqVO.getAddressId());
|
|
||||||
}
|
|
||||||
TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, clientIp, createReqVO, calculateRespBO, address);
|
|
||||||
order.setType(calculateRespBO.getType());
|
order.setType(calculateRespBO.getType());
|
||||||
order.setNo(orderNoRedisDAO.generate(TradeOrderNoRedisDAO.TRADE_ORDER_NO_PREFIX));
|
order.setNo(orderNoRedisDAO.generate(TradeOrderNoRedisDAO.TRADE_ORDER_NO_PREFIX));
|
||||||
order.setStatus(TradeOrderStatusEnum.UNPAID.getStatus());
|
order.setStatus(TradeOrderStatusEnum.UNPAID.getStatus());
|
||||||
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
|
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
|
||||||
order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum));
|
order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum));
|
||||||
order.setTerminal(TerminalEnum.H5.getTerminal()); // todo 数据来源?
|
order.setTerminal(TerminalEnum.H5.getTerminal()); // todo 数据来源?
|
||||||
// 支付信息
|
// 支付 + 退款信息
|
||||||
order.setAdjustPrice(0).setPayStatus(false);
|
order.setAdjustPrice(0).setPayStatus(false);
|
||||||
|
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0);
|
||||||
// 物流信息
|
// 物流信息
|
||||||
order.setDeliveryType(createReqVO.getDeliveryType());
|
order.setDeliveryType(createReqVO.getDeliveryType());
|
||||||
// 退款信息
|
if (Objects.equals(createReqVO.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getType())) {
|
||||||
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0);
|
AddressRespDTO address = addressApi.getAddress(createReqVO.getAddressId(), userId);
|
||||||
|
Assert.notNull(address, "地址({}) 不能为空", createReqVO.getAddressId()); // 价格计算时,已经计算
|
||||||
|
order.setReceiverName(address.getName()).setReceiverMobile(address.getMobile())
|
||||||
|
.setReceiverAreaId(address.getAreaId()).setReceiverDetailAddress(address.getDetailAddress());
|
||||||
|
} else if (Objects.equals(createReqVO.getDeliveryType(), DeliveryTypeEnum.PICK_UP.getType())) {
|
||||||
|
order.setReceiverName(createReqVO.getReceiverName()).setReceiverMobile(createReqVO.getReceiverMobile());
|
||||||
|
order.setPickUpVerifyCode(RandomUtil.randomNumbers(8)); // 随机一个核销码,长度为 8 位
|
||||||
|
}
|
||||||
tradeOrderMapper.insert(order);
|
tradeOrderMapper.insert(order);
|
||||||
// TODO @puhui999:如果是门店订单,则需要生成核销码;
|
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,7 +409,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
// 1.1 校验并获得交易订单(可发货)
|
// 1.1 校验并获得交易订单(可发货)
|
||||||
TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId());
|
TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId());
|
||||||
// 1.2 校验 deliveryType 是否为快递,是快递才可以发货
|
// 1.2 校验 deliveryType 是否为快递,是快递才可以发货
|
||||||
if (ObjectUtil.notEqual(order.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getMode())) {
|
if (ObjectUtil.notEqual(order.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getType())) {
|
||||||
throw exception(ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS);
|
throw exception(ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,9 +50,9 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
|
|||||||
if (param.getDeliveryType() == null) {
|
if (param.getDeliveryType() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DeliveryTypeEnum.PICK_UP.getMode().equals(param.getDeliveryType())) {
|
if (DeliveryTypeEnum.PICK_UP.getType().equals(param.getDeliveryType())) {
|
||||||
calculateByPickUp(param, result);
|
calculateByPickUp(param, result);
|
||||||
} else if (DeliveryTypeEnum.EXPRESS.getMode().equals(param.getDeliveryType())) {
|
} else if (DeliveryTypeEnum.EXPRESS.getType().equals(param.getDeliveryType())) {
|
||||||
calculateExpress(param, result);
|
calculateExpress(param, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest {
|
|||||||
public void init(){
|
public void init(){
|
||||||
// 准备参数
|
// 准备参数
|
||||||
reqBO = new TradePriceCalculateReqBO()
|
reqBO = new TradePriceCalculateReqBO()
|
||||||
.setDeliveryType(DeliveryTypeEnum.EXPRESS.getMode())
|
.setDeliveryType(DeliveryTypeEnum.EXPRESS.getType())
|
||||||
.setAddressId(10L)
|
.setAddressId(10L)
|
||||||
.setUserId(1L)
|
.setUserId(1L)
|
||||||
.setItems(asList(
|
.setItems(asList(
|
||||||
|
Loading…
Reference in New Issue
Block a user