mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 01:01:52 +08:00
trade:下单时,如果是门店自提,增加核销码的生成
This commit is contained in:
parent
1b477aaa0d
commit
35569c5ec8
@ -18,12 +18,12 @@ public enum DeliveryTypeEnum implements IntArrayValuable {
|
||||
EXPRESS(1, "快递发货"),
|
||||
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}}
|
||||
tenant-id: {{appTenentId}}
|
||||
|
||||
### /trade-order/create 创建订单(基于商品)
|
||||
### /trade-order/create 创建订单(基于商品)【快递】
|
||||
POST {{appApi}}/trade/order/create
|
||||
Content-Type: application/json
|
||||
Authorization: Bearer {{appToken}}
|
||||
@ -27,6 +27,27 @@ tenant-id: {{appTenentId}}
|
||||
"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
|
||||
Authorization: Bearer {{appToken}}
|
||||
|
@ -65,14 +65,10 @@ public interface TradeOrderConvert {
|
||||
@Mapping(source = "calculateRespBO.price.deliveryPrice", target = "deliveryPrice"),
|
||||
@Mapping(source = "calculateRespBO.price.couponPrice", target = "couponPrice"),
|
||||
@Mapping(source = "calculateRespBO.price.pointPrice", target = "pointPrice"),
|
||||
@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"),
|
||||
@Mapping(source = "calculateRespBO.price.payPrice", target = "payPrice")
|
||||
})
|
||||
TradeOrderDO convert(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO,
|
||||
TradePriceCalculateRespBO calculateRespBO, AddressRespDTO address);
|
||||
TradePriceCalculateRespBO calculateRespBO);
|
||||
|
||||
TradeOrderRespDTO convert(TradeOrderDO orderDO);
|
||||
|
||||
@ -215,6 +211,7 @@ public interface TradeOrderConvert {
|
||||
TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO().setUserId(userId)
|
||||
.setCouponId(settlementReqVO.getCouponId()).setPointStatus(settlementReqVO.getPointStatus())
|
||||
.setDeliveryType(settlementReqVO.getDeliveryType()).setAddressId(settlementReqVO.getAddressId())
|
||||
.setPickUpStoreId(settlementReqVO.getPickUpStoreId())
|
||||
.setItems(new ArrayList<>(settlementReqVO.getItems().size()));
|
||||
// 商品项的构建
|
||||
Map<Long, CartDO> cartMap = convertMap(cartList, CartDO::getId);
|
||||
|
@ -224,6 +224,10 @@ public class TradeOrderDO extends BaseDO {
|
||||
* 关联 {@link DeliveryPickUpStoreDO#getId()}
|
||||
*/
|
||||
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.lang.Assert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
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.TradeOrderMapper;
|
||||
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.delivery.DeliveryTypeEnum;
|
||||
import cn.iocoder.yudao.module.trade.enums.order.*;
|
||||
@ -203,44 +203,30 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
|
||||
// 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,
|
||||
TradePriceCalculateRespBO 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);
|
||||
TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, clientIp, createReqVO, calculateRespBO);
|
||||
order.setType(calculateRespBO.getType());
|
||||
order.setNo(orderNoRedisDAO.generate(TradeOrderNoRedisDAO.TRADE_ORDER_NO_PREFIX));
|
||||
order.setStatus(TradeOrderStatusEnum.UNPAID.getStatus());
|
||||
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus());
|
||||
order.setProductCount(getSumValue(calculateRespBO.getItems(), TradePriceCalculateRespBO.OrderItem::getCount, Integer::sum));
|
||||
order.setTerminal(TerminalEnum.H5.getTerminal()); // todo 数据来源?
|
||||
// 支付信息
|
||||
// 支付 + 退款信息
|
||||
order.setAdjustPrice(0).setPayStatus(false);
|
||||
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0);
|
||||
// 物流信息
|
||||
order.setDeliveryType(createReqVO.getDeliveryType());
|
||||
// 退款信息
|
||||
order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0);
|
||||
if (Objects.equals(createReqVO.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getType())) {
|
||||
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);
|
||||
// TODO @puhui999:如果是门店订单,则需要生成核销码;
|
||||
return order;
|
||||
}
|
||||
|
||||
@ -423,7 +409,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
// 1.1 校验并获得交易订单(可发货)
|
||||
TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId());
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -50,9 +50,9 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
|
||||
if (param.getDeliveryType() == null) {
|
||||
return;
|
||||
}
|
||||
if (DeliveryTypeEnum.PICK_UP.getMode().equals(param.getDeliveryType())) {
|
||||
if (DeliveryTypeEnum.PICK_UP.getType().equals(param.getDeliveryType())) {
|
||||
calculateByPickUp(param, result);
|
||||
} else if (DeliveryTypeEnum.EXPRESS.getMode().equals(param.getDeliveryType())) {
|
||||
} else if (DeliveryTypeEnum.EXPRESS.getType().equals(param.getDeliveryType())) {
|
||||
calculateExpress(param, result);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest {
|
||||
public void init(){
|
||||
// 准备参数
|
||||
reqBO = new TradePriceCalculateReqBO()
|
||||
.setDeliveryType(DeliveryTypeEnum.EXPRESS.getMode())
|
||||
.setDeliveryType(DeliveryTypeEnum.EXPRESS.getType())
|
||||
.setAddressId(10L)
|
||||
.setUserId(1L)
|
||||
.setItems(asList(
|
||||
|
Loading…
Reference in New Issue
Block a user