From 1b477aaa0d46985efff9f8891c762e54d7bf9c00 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 20 Sep 2023 20:21:41 +0800 Subject: [PATCH 01/42] =?UTF-8?q?trade=EF=BC=9A=E4=BC=98=E5=8C=96=E4=B8=8B?= =?UTF-8?q?=E5=8D=95=E9=80=BB=E8=BE=91=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/product/api/sku/ProductSkuApi.java | 2 +- .../trade/enums/ErrorCodeConstants.java | 3 +- .../enums/delivery/DeliveryTypeEnum.java | 1 - .../app/order/AppTradeOrderController.http | 3 +- .../app/order/AppTradeOrderController.java | 9 +- .../order/vo/AppTradeOrderCreateReqVO.java | 9 ++ .../vo/AppTradeOrderSettlementReqVO.java | 4 +- .../convert/order/TradeOrderConvert.java | 27 ++--- .../dal/dataobject/order/TradeOrderDO.java | 9 +- .../order/TradeOrderUpdateServiceImpl.java | 114 +++++++++--------- .../handler/TradeCombinationHandler.java | 5 + .../price/bo/TradePriceCalculateReqBO.java | 53 ++++++-- .../price/bo/TradePriceCalculateRespBO.java | 5 + .../TradeDeliveryPriceCalculator.java | 47 ++++++-- .../TradePointUsePriceCalculator.java | 29 +++++ .../calculator/TradePriceCalculator.java | 6 +- .../TradePriceCalculatorHelper.java | 20 ++- .../price/TradePriceServiceImplTest.java | 2 +- .../yudao-module-member-api/pom.xml | 7 ++ .../member/api/point/MemberPointApi.java | 16 ++- .../enums/point/MemberPointBizTypeEnum.java | 6 +- .../member/api/point/MemberPointApiImpl.java | 9 ++ 22 files changed, 272 insertions(+), 114 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApi.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApi.java index 2ed262cde..3581fdb91 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApi.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/ProductSkuApi.java @@ -39,7 +39,7 @@ public interface ProductSkuApi { List getSkuListBySpuId(Collection spuIds); /** - * 更新 SKU 库存 + * 更新 SKU 库存(增加 or 减少) * * @param updateStockReqDTO 更新请求 */ diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 4b8410b83..500601442 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -58,8 +58,9 @@ public interface ErrorCodeConstants { // ========== Price 相关 1011003000 ============ ErrorCode PRICE_CALCULATE_PAY_PRICE_ILLEGAL = new ErrorCode(1011003000, "支付价格计算异常,原因:价格小于等于 0"); - ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDR_IS_EMPTY = new ErrorCode(1011003001, "计算快递运费异常,收件人地址编号为空"); + ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003001, "计算快递运费异常,收件人地址编号为空"); ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1011003002, "计算快递运费异常,找不到对应的运费模板"); + ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_PICK_UP_STORE_IS_EMPTY = new ErrorCode(1011003003, "计算快递运费异常,自提点为空"); // ========== 物流 Express 模块 1011004000 ========== ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1011004000, "快递公司不存在"); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryTypeEnum.java index 7754f115d..210f5c307 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryTypeEnum.java @@ -15,7 +15,6 @@ import java.util.Arrays; @AllArgsConstructor public enum DeliveryTypeEnum implements IntArrayValuable { - NULL(0, "无需物流"), EXPRESS(1, "快递发货"), PICK_UP(2, "用户自提"),; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.http b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.http index 4f3de0c5d..b62e6eb1f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.http +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.http @@ -15,7 +15,8 @@ Authorization: Bearer {{appToken}} tenant-id: {{appTenentId}} { - "type": 0, + "pointStatus": true, + "deliveryType": 1, "addressId": 21, "items": [ { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 888a3d4df..4bbd98a27 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.trade.controller.app.order; -import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; @@ -12,11 +11,8 @@ import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; -import cn.iocoder.yudao.module.trade.enums.order.TradeOrderOperateTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; -import cn.iocoder.yudao.module.trade.framework.order.core.annotations.TradeOrderLog; -import cn.iocoder.yudao.module.trade.framework.order.core.utils.TradeOrderLogUtils; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; @@ -65,10 +61,7 @@ public class AppTradeOrderController { @PostMapping("/create") @Operation(summary = "创建订单") @PreAuthenticated - @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.TEST) - public CommonResult createOrder(@RequestBody AppTradeOrderCreateReqVO createReqVO) { - TradeOrderLogUtils.setOrderInfo(10L, 1, 2, - MapUtil.builder().put("nickname", "小明").put("thing", "种土豆").build()); + public CommonResult createOrder(@Valid @RequestBody AppTradeOrderCreateReqVO createReqVO) { TradeOrderDO order = tradeOrderUpdateService.createOrder(getLoginUserId(), getClientIP(), createReqVO); return success(new AppTradeOrderCreateRespVO().setId(order.getId()).setPayOrderId(order.getPayOrderId())); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderCreateReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderCreateReqVO.java index 11031a884..2f4503d02 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderCreateReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderCreateReqVO.java @@ -1,8 +1,11 @@ package cn.iocoder.yudao.module.trade.controller.app.order.vo; +import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; +import javax.validation.constraints.AssertTrue; + @Schema(description = "用户 App - 交易订单创建 Request VO") @Data public class AppTradeOrderCreateReqVO extends AppTradeOrderSettlementReqVO { @@ -10,4 +13,10 @@ public class AppTradeOrderCreateReqVO extends AppTradeOrderSettlementReqVO { @Schema(description = "备注", example = "这个是我的订单哟") private String remark; + @AssertTrue(message = "配送方式不能为空") + @JsonIgnore + public boolean isDeliveryTypeNotNull() { + return getDeliveryType() != null; + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java index 929a2ec19..74535d173 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java @@ -30,7 +30,7 @@ public class AppTradeOrderSettlementReqVO { private Boolean pointStatus; // ========== 配送相关相关字段 ========== - @Schema(description = "配送方式", required = true, example = "1") + @Schema(description = "配送方式", example = "1") @InEnum(value = DeliveryTypeEnum.class, message = "配送方式不正确") private Integer deliveryType; @@ -62,6 +62,8 @@ public class AppTradeOrderSettlementReqVO { @Schema(description = "砍价活动编号", example = "123") private Long bargainActivityId; + // TODO @puhui999:可以写个参数校验,如果 seckillActivityId 或 combinationActivityId 或 combinationHeadId 的情况,items 应该只有一个 + @Data @Schema(description = "用户 App - 商品项") @Valid diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index d5b9546d0..4688ca9ef 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -56,6 +56,7 @@ public interface TradeOrderConvert { @Mappings({ @Mapping(target = "id", ignore = true), + @Mapping(source = "userId", target = "userId"), @Mapping(source = "createReqVO.couponId", target = "couponId"), @Mapping(target = "remark", ignore = true), @Mapping(source = "createReqVO.remark", target = "userRemark"), @@ -89,22 +90,15 @@ public interface TradeOrderConvert { TradeOrderItemDO convert(TradePriceCalculateRespBO.OrderItem item); default ProductSkuUpdateStockReqDTO convert(List list) { - return new ProductSkuUpdateStockReqDTO(TradeOrderConvert.INSTANCE.convertList(list)); - } - - default ProductSkuUpdateStockReqDTO convertNegative(List list) { - List items = TradeOrderConvert.INSTANCE.convertList(list); - items.forEach(item -> item.setIncrCount(-item.getIncrCount())); + List items = CollectionUtils.convertList(list, item -> + new ProductSkuUpdateStockReqDTO.Item().setId(item.getSkuId()).setIncrCount(-item.getCount())); + return new ProductSkuUpdateStockReqDTO(items); + } + default ProductSkuUpdateStockReqDTO convertNegative(List list) { + List items = CollectionUtils.convertList(list, item -> + new ProductSkuUpdateStockReqDTO.Item().setId(item.getSkuId()).setIncrCount(-item.getCount())); return new ProductSkuUpdateStockReqDTO(items); } - - List convertList(List list); - - @Mappings({ - @Mapping(source = "skuId", target = "id"), - @Mapping(source = "count", target = "incrCount"), - }) - ProductSkuUpdateStockReqDTO.Item convert(TradeOrderItemDO bean); default PayOrderCreateReqDTO convert(TradeOrderDO order, List orderItems, TradePriceCalculateRespBO calculateRespBO, TradeOrderProperties orderProperties) { @@ -218,8 +212,9 @@ public interface TradeOrderConvert { default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO, List cartList) { - TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO(); - reqBO.setUserId(userId).setCouponId(settlementReqVO.getCouponId()).setAddressId(settlementReqVO.getAddressId()) + TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO().setUserId(userId) + .setCouponId(settlementReqVO.getCouponId()).setPointStatus(settlementReqVO.getPointStatus()) + .setDeliveryType(settlementReqVO.getDeliveryType()).setAddressId(settlementReqVO.getAddressId()) .setItems(new ArrayList<>(settlementReqVO.getItems().size())); // 商品项的构建 Map cartMap = convertMap(cartList, CartDO::getId); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java index 9d8133ef2..bcf50c6d3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java @@ -251,12 +251,19 @@ public class TradeOrderDO extends BaseDO { * 对应 taobao 的 trade.coupon_fee 字段 */ private Integer couponPrice; - // TODO 芋艿:需要记录使用的积分; + /** + * 使用的积分 + */ + private Integer usePoint; /** * 积分抵扣的金额,单位:分 * * 对应 taobao 的 trade.point_fee 字段 */ private Integer pointPrice; +// /** +// * 奖励的积分 TODO 疯狂:可以使用这个字段哈; +// */ +// private Integer rewardPoint; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 102418260..8f3bff38b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -47,6 +47,7 @@ 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.*; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; +import cn.iocoder.yudao.module.trade.framework.order.core.annotations.TradeOrderLog; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; import cn.iocoder.yudao.module.trade.service.cart.CartService; @@ -182,32 +183,24 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CREATE) public TradeOrderDO createOrder(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO) { - // 1、执行订单创建前置处理器 - // TODO @puhui999:最好也抽个 beforeOrderCreate 方法;不要 BO 各自处理参数岂不美哉? - TradeBeforeOrderCreateReqBO beforeOrderCreateReqBO = TradeOrderConvert.INSTANCE.convert(createReqVO); - beforeOrderCreateReqBO.setOrderType(validateActivity(createReqVO)); - beforeOrderCreateReqBO.setUserId(userId); - beforeOrderCreateReqBO.setCount(getSumValue(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCount, Integer::sum)); - // TODO @puhui999:这里有个纠结点;handler 的定义是只处理指定类型的订单的拓展逻辑;还是通用的 handler,类似可以处理优惠劵等等 - tradeOrderHandlers.forEach(handler -> handler.beforeOrderCreate(beforeOrderCreateReqBO)); - - // 2. 价格计算 + // 0. 价格计算 TradePriceCalculateRespBO calculateRespBO = calculatePrice(userId, createReqVO); + // 1. 订单创建前的逻辑 + beforeCreateTradeOrder(userId, createReqVO, calculateRespBO); + // 2.1 插入 TradeOrderDO 订单 TradeOrderDO order = createTradeOrder(userId, userIp, createReqVO, calculateRespBO); // 2.2 插入 TradeOrderItemDO 订单项 List orderItems = createTradeOrderItems(order, calculateRespBO); - // 3. 订单创建完后的逻辑 + // 3. 订单创建后的逻辑 afterCreateTradeOrder(userId, createReqVO, order, orderItems, calculateRespBO); - - // TODO @LeeYan9: 是可以思考下, 订单的营销优惠记录, 应该记录在哪里, 微信讨论起来! return order; } - // TODO @puhui999:订单超时,自动取消; /** @@ -234,9 +227,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { address = validateAddress(userId, createReqVO.getAddressId()); } TradeOrderDO order = TradeOrderConvert.INSTANCE.convert(userId, clientIp, createReqVO, calculateRespBO, address); - String no = orderNoRedisDAO.generate(TradeOrderNoRedisDAO.TRADE_ORDER_NO_PREFIX); - order.setType(validateActivity(createReqVO)); - order.setNo(no); + 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)); @@ -252,71 +244,80 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { return order; } - /** - * 校验活动,并返回订单类型 - * - * @param createReqVO 请求参数 - * @return 订单类型 - */ - private Integer validateActivity(AppTradeOrderCreateReqVO createReqVO) { - if (createReqVO.getSeckillActivityId() != null) { - return TradeOrderTypeEnum.SECKILL.getType(); - } - if (createReqVO.getCombinationActivityId() != null) { - return TradeOrderTypeEnum.COMBINATION.getType(); - } - // TODO 砍价敬请期待 - return TradeOrderTypeEnum.NORMAL.getType(); - } - - private List createTradeOrderItems(TradeOrderDO tradeOrderDO, TradePriceCalculateRespBO calculateRespBO) { + private List createTradeOrderItems(TradeOrderDO tradeOrderDO, + TradePriceCalculateRespBO calculateRespBO) { List orderItems = TradeOrderConvert.INSTANCE.convertList(tradeOrderDO, calculateRespBO); tradeOrderItemMapper.insertBatch(orderItems); return orderItems; } /** - * 执行创建完创建完订单后的逻辑 + * 订单创建前,执行前置逻辑 + * + * @param userId 用户编号 + * @param createReqVO 创建订单请求 + * @param calculateRespBO 订单价格计算结果 + */ + private void beforeCreateTradeOrder(Long userId, AppTradeOrderCreateReqVO createReqVO, + TradePriceCalculateRespBO calculateRespBO) { + // 1. 执行订单创建前置处理器 + TradeBeforeOrderCreateReqBO beforeOrderCreateReqBO = TradeOrderConvert.INSTANCE.convert(createReqVO); + beforeOrderCreateReqBO.setOrderType(calculateRespBO.getType()); + beforeOrderCreateReqBO.setUserId(userId); + beforeOrderCreateReqBO.setCount(getSumValue(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCount, Integer::sum)); + // TODO @puhui999:这里有个纠结点;handler 的定义是只处理指定类型的订单的拓展逻辑;还是通用的 handler,类似可以处理优惠劵等等 + tradeOrderHandlers.forEach(handler -> handler.beforeOrderCreate(beforeOrderCreateReqBO)); + + // 2. 下单时扣减商品库存 + productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convertNegative(createReqVO.getItems())); + } + + /** + * 订单创建后,执行后置逻辑 * * 例如说:优惠劵的扣减、积分的扣减、支付单的创建等等 * * @param userId 用户编号 * @param createReqVO 创建订单请求 - * @param tradeOrderDO 交易订单 + * @param order 交易订单 * @param calculateRespBO 订单价格计算结果 */ private void afterCreateTradeOrder(Long userId, AppTradeOrderCreateReqVO createReqVO, - TradeOrderDO tradeOrderDO, List orderItems, + TradeOrderDO order, List orderItems, TradePriceCalculateRespBO calculateRespBO) { - // 执行订单创建后置处理器 - tradeOrderHandlers.forEach(handler -> handler.afterOrderCreate(TradeOrderConvert.INSTANCE.convert(userId, createReqVO, tradeOrderDO, orderItems.get(0)))); + // 1. 执行订单创建后置处理器 + // TODO @puhui999:从通用性来说,应该不用 orderItems.get(0) + tradeOrderHandlers.forEach(handler -> handler.afterOrderCreate( + TradeOrderConvert.INSTANCE.convert(userId, createReqVO, order, orderItems.get(0)))); - // 扣减积分 TODO 芋艿:待实现,需要前置; - // 这个是不是应该放到支付成功之后?如果支付后的话,可能积分可以重复使用哈。资源类,都要预扣 - - // 有使用优惠券时更新 TODO 芋艿:需要前置; + // 2. 有使用优惠券时更新 + // 不在前置扣减的原因,是因为优惠劵要记录使用的订单号 if (createReqVO.getCouponId() != null) { couponApi.useCoupon(new CouponUseReqDTO().setId(createReqVO.getCouponId()).setUserId(userId) - .setOrderId(tradeOrderDO.getId())); + .setOrderId(order.getId())); } - // 下单时扣减商品库存 - productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convertNegative(orderItems)); + // 3. 扣减积分 + // 不在前置扣减的原因,是因为积分扣减时,需要记录关联业务 + if (order.getUsePoint() != null && order.getUsePoint() > 0) { + memberPointApi.reducePoint(userId, calculateRespBO.getUsePoint(), + MemberPointBizTypeEnum.ORDER_USE.getType(), String.valueOf(order.getId())); + } - // 删除购物车商品 + // 4. 删除购物车商品 Set cartIds = convertSet(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCartId); if (CollUtil.isNotEmpty(cartIds)) { cartService.deleteCart(userId, cartIds); } - // 生成预支付 - createPayOrder(tradeOrderDO, orderItems, calculateRespBO); + // 5. 生成预支付 + createPayOrder(order, orderItems, calculateRespBO); - // 增加订单日志 TODO 芋艿:待实现 + // TODO @LeeYan9: 是可以思考下, 订单的营销优惠记录, 应该记录在哪里, 微信讨论起来! } - - private void createPayOrder(TradeOrderDO order, List orderItems, TradePriceCalculateRespBO calculateRespBO) { + private void createPayOrder(TradeOrderDO order, List orderItems, + TradePriceCalculateRespBO calculateRespBO) { // 创建支付单,用于后续的支付 PayOrderCreateReqDTO payOrderCreateReqDTO = TradeOrderConvert.INSTANCE.convert( order, orderItems, calculateRespBO, tradeOrderProperties); @@ -344,6 +345,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } // 校验活动 // 1、拼团活动 + // TODO @puhui999:这块也抽象到 handler 里 if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 combinationRecordApi.updateRecordStatusToInProgress(order.getUserId(), order.getId(), LocalDateTime.now()); @@ -741,6 +743,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { couponApi.returnUsedCoupon(order.getCouponId()); // 4.回滚积分:积分是支付成功后才增加的吧? 回复:每个项目不同,目前看下来,确认收货貌似更合适,我再看看其它项目的业务选择; + // TODO @疯狂:有赞是可配置(支付 or 确认收货),我们按照支付好列;然后这里的退积分,指的是下单时的积分抵扣。 // TODO 芋艿:OrderLog @@ -773,17 +776,18 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Async protected void addUserPointAsync(Long userId, Integer payPrice, Long orderId) { - int bizType = MemberPointBizTypeEnum.ORDER_BUY.getType(); + // TODO @疯狂:具体多少积分,需要分成 2 不分:1. 支付金额;2. 商品金额 + int bizType = MemberPointBizTypeEnum.ORDER_REWARD.getType(); memberPointApi.addPoint(userId, payPrice, bizType, String.valueOf(orderId)); } @Async protected void reduceUserPointAsync(Long userId, Integer refundPrice, Long afterSaleId) { + // TODO @疯狂:退款时,按照金额比例,退还积分;https://help.youzan.com/displaylist/detail_4_4-1-49185 int bizType = MemberPointBizTypeEnum.ORDER_CANCEL.getType(); memberPointApi.addPoint(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); } - @Async protected void addBrokerageAsync(Long userId, Long orderId) { MemberUserRespDTO user = memberUserApi.getUser(userId); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index ad777b380..42a2f8139 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -37,6 +37,11 @@ public class TradeCombinationHandler implements TradeOrderHandler { @Override public void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO) { + // TODO @puhui999:需要判断下; + if (true) { + return; + } + // 创建砍价记录 combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(reqBO)); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java index ff5faea26..67019a49a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.trade.service.price.bo; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; -import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import lombok.Data; import javax.validation.Valid; @@ -17,13 +16,6 @@ import java.util.List; @Data public class TradePriceCalculateReqBO { - /** - * 订单类型 - * - * 枚举 {@link TradeOrderTypeEnum} - */ - private Integer type; - /** * 用户编号 * @@ -37,13 +29,12 @@ public class TradePriceCalculateReqBO { * 对应 CouponDO 的 id 编号 */ private Long couponId; - + // TODO @疯狂:需要增加一个 PriceCalculator 实现积分扣减的计算;写回到 TradePriceCalculateRespBO 的 usePoint /** - * 收货地址编号 - * - * 对应 MemberAddressDO 的 id 编号 + * 是否使用积分 */ - private Long addressId; + @NotNull(message = "是否使用积分不能为空") + private Boolean pointStatus; /** * 配送方式 @@ -51,6 +42,18 @@ public class TradePriceCalculateReqBO { * 枚举 {@link DeliveryTypeEnum} */ private Integer deliveryType; + /** + * 收货地址编号 + * + * 对应 MemberAddressDO 的 id 编号 + */ + private Long addressId; + /** + * 自提门店编号 + * + * 对应 PickUpStoreDO 的 id 编号 + */ + private Long pickUpStoreId; /** * 商品 SKU 数组 @@ -58,6 +61,30 @@ public class TradePriceCalculateReqBO { @NotNull(message = "商品数组不能为空") private List items; + // ========== 秒杀活动相关字段 ========== + /** + * 秒杀活动编号 + */ + private Long seckillActivityId; + + // ========== 拼团活动相关字段 ========== + // TODO @puhui999:是不是拼团记录的编号哈? + /** + * 拼团活动编号 + */ + private Long combinationActivityId; + + /** + * 拼团团长编号 + */ + private Long combinationHeadId; + + // ========== 砍价活动相关字段 ========== + /** + * 砍价活动编号 + */ + private Long bargainActivityId; + /** * 商品 SKU */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java index 76fb68c1f..1171cd8f2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java @@ -48,6 +48,11 @@ public class TradePriceCalculateRespBO { */ private Long couponId; + /** + * 使用的积分 + */ + private Integer usePoint; + /** * 订单价格 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java index 5454c450d..7c395dbbf 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java @@ -2,11 +2,14 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; +import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryExpressChargeModeEnum; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressTemplateService; +import cn.iocoder.yudao.module.trade.service.delivery.DeliveryPickUpStoreService; import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateRespBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; @@ -22,8 +25,7 @@ import java.util.Set; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDR_IS_EMPTY; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; /** * 运费的 {@link TradePriceCalculator} 实现类 @@ -37,20 +39,41 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { @Resource private AddressApi addressApi; + + @Resource + private DeliveryPickUpStoreService deliveryPickUpStoreService; @Resource private DeliveryExpressTemplateService deliveryExpressTemplateService; @Override public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { - // TODO @芋艿:如果门店自提,需要校验是否开启; - // 1.1 判断配送方式 - if (param.getDeliveryType() == null || DeliveryTypeEnum.PICK_UP.getMode().equals(param.getDeliveryType())) { + if (param.getDeliveryType() == null) { return; } - if (param.getAddressId() == null) { - throw exception(PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDR_IS_EMPTY); + if (DeliveryTypeEnum.PICK_UP.getMode().equals(param.getDeliveryType())) { + calculateByPickUp(param, result); + } else if (DeliveryTypeEnum.EXPRESS.getMode().equals(param.getDeliveryType())) { + calculateExpress(param, result); + } + } + + private void calculateByPickUp(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + if (param.getPickUpStoreId() == null) { + throw exception(PRICE_CALCULATE_DELIVERY_PRICE_PICK_UP_STORE_IS_EMPTY); + } + DeliveryPickUpStoreDO pickUpStore = deliveryPickUpStoreService.getDeliveryPickUpStore(param.getPickUpStoreId()); + if (pickUpStore == null || CommonStatusEnum.DISABLE.getStatus().equals(pickUpStore.getStatus())) { + throw exception(PICK_UP_STORE_NOT_EXISTS); + } + } + + // ========= 快递发货 ========== + + private void calculateExpress(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // 1. 得到收件地址区域 + if (param.getAddressId() == null) { + throw exception(PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDRESS_IS_EMPTY); } - // 1.2 得到收件地址区域 AddressRespDTO address = addressApi.getAddress(param.getAddressId(), param.getUserId()); Assert.notNull(address, "收件人({})的地址,不能为空", param.getUserId()); @@ -89,8 +112,12 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { for (OrderItem orderItem : orderItems) { totalCount += orderItem.getCount(); totalPrice += orderItem.getPayPrice(); - totalWeight += totalWeight + orderItem.getWeight() * orderItem.getCount(); - totalVolume += totalVolume + orderItem.getVolume() * orderItem.getCount(); + if (orderItem.getWeight() != null) { + totalWeight += totalWeight + orderItem.getWeight() * orderItem.getCount(); + } + if (orderItem.getVolume() != null) { + totalVolume += totalVolume + orderItem.getVolume() * orderItem.getCount(); + } } // 优先判断是否包邮. 如果包邮不计算快递运费 if (isExpressFree(templateBO.getChargeMode(), totalCount, totalWeight, diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java new file mode 100644 index 000000000..6bd479802 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.trade.service.price.calculator; + +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +/** + * 使用积分的 {@link TradePriceCalculator} 实现类 + * + * @author owen + */ +@Component +@Order(TradePriceCalculator.ORDER_POINT_USE) +@Slf4j +public class TradePointUsePriceCalculator implements TradePriceCalculator { + + @Override + public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // TODO 疯狂:待实现,嘿嘿; + if (param.getPointStatus()) { + result.setUsePoint(10); + } else { + result.setUsePoint(0); + } + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java index 92ae9c2ee..cddc1ea21 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java @@ -6,6 +6,9 @@ import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; /** * 价格计算的计算器接口 * + * 优惠计算顺序: + * 1. 积分抵现、会员价、优惠券、粉丝专享价、满减送哪个优先计算? + * * @author 芋道源码 */ public interface TradePriceCalculator { @@ -13,12 +16,13 @@ public interface TradePriceCalculator { int ORDER_DISCOUNT_ACTIVITY = 10; int ORDER_REWARD_ACTIVITY = 20; int ORDER_COUPON = 30; + int ORDER_POINT_USE = 40; /** * 快递运费的计算 * * 放在各种营销活动、优惠劵后面 TODO */ - int ORDER_DELIVERY = 40; + int ORDER_DELIVERY = 50; void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java index bd3d3b5be..b8b9e0fb9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java @@ -4,6 +4,7 @@ import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; @@ -28,7 +29,7 @@ public class TradePriceCalculatorHelper { List spuList, List skuList) { // 创建 PriceCalculateRespDTO 对象 TradePriceCalculateRespBO result = new TradePriceCalculateRespBO(); - result.setType(param.getType()); + result.setType(getOrderType(param)); result.setPromotions(new ArrayList<>()); // 创建它的 OrderItem 属性 @@ -69,6 +70,23 @@ public class TradePriceCalculatorHelper { return result; } + /** + * 计算订单类型 + * + * @param param 计算参数 + * @return 订单类型 + */ + private static Integer getOrderType(TradePriceCalculateReqBO param) { + if (param.getSeckillActivityId() != null) { + return TradeOrderTypeEnum.SECKILL.getType(); + } + if (param.getCombinationActivityId() != null) { + return TradeOrderTypeEnum.COMBINATION.getType(); + } + // TODO 砍价敬请期待 + return TradeOrderTypeEnum.NORMAL.getType(); + } + /** * 基于订单项,重新计算 price 总价 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImplTest.java index 473e3920e..b998f87b1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImplTest.java @@ -45,7 +45,7 @@ public class TradePriceServiceImplTest extends BaseMockitoUnitTest { public void testCalculatePrice() { // 准备参数 TradePriceCalculateReqBO calculateReqBO = new TradePriceCalculateReqBO() - .setType(TradeOrderTypeEnum.NORMAL.getType()).setUserId(10L) + .setUserId(10L) .setCouponId(20L).setAddressId(30L) .setItems(Arrays.asList( new TradePriceCalculateReqBO.Item().setSkuId(100L).setCount(1).setSelected(true), diff --git a/yudao-module-member/yudao-module-member-api/pom.xml b/yudao-module-member/yudao-module-member-api/pom.xml index 961bfb656..1f60cd0fc 100644 --- a/yudao-module-member/yudao-module-member-api/pom.xml +++ b/yudao-module-member/yudao-module-member-api/pom.xml @@ -21,6 +21,13 @@ cn.iocoder.boot yudao-common + + + + org.springframework.boot + spring-boot-starter-validation + true + diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java index 5181211f2..3eb749fb6 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.member.api.point; import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; +import javax.validation.constraints.Min; + /** * 用户积分的 API 接口 * @@ -17,6 +19,18 @@ public interface MemberPointApi { * @param bizType 业务类型 {@link MemberPointBizTypeEnum} * @param bizId 业务编号 */ - void addPoint(Long userId, Integer point, Integer bizType, String bizId); + void addPoint(Long userId, @Min(value = 1L, message = "积分必须是正数") Integer point, + Integer bizType, String bizId); + + /** + * 减少用户积分 + * + * @param userId 用户编号 + * @param point 积分 + * @param bizType 业务类型 {@link MemberPointBizTypeEnum} + * @param bizId 业务编号 + */ + void reducePoint(Long userId, @Min(value = 1L, message = "积分必须是正数") Integer point, + Integer bizType, String bizId); } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java index 3d314a4a2..fe76cdb52 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java @@ -17,8 +17,10 @@ import java.util.Objects; public enum MemberPointBizTypeEnum implements IntArrayValuable { SIGN(1, "签到", "签到获得 {} 积分", true), - ORDER_BUY(10, "订单消费", "下单获得 {} 积分", true), - ORDER_CANCEL(11, "订单取消", "退单获得 {} 积分", false); // 退回积分 + ORDER_REWARD(10, "订单奖励", "下单获得 {} 积分", true), + ORDER_CANCEL(11, "订单取消", "退单获得 {} 积分", false), // 退回积分 + ORDER_USE(12, "订单使用", "下单使用 {} 积分", false), // 扣减积分 + ; /** * 类型 diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java index 81eec0782..ee407eaf6 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java @@ -31,4 +31,13 @@ public class MemberPointApiImpl implements MemberPointApi { memberPointRecordService.createPointRecord(userId, point, bizTypeEnum, bizId); } + @Override + public void reducePoint(Long userId, Integer point, Integer bizType, String bizId) { + MemberPointBizTypeEnum bizTypeEnum = MemberPointBizTypeEnum.getByType(bizType); + if (bizTypeEnum == null) { + throw exception(POINT_RECORD_BIZ_NOT_SUPPORT); + } + memberPointRecordService.createPointRecord(userId, point, bizTypeEnum, bizId); + } + } From 35569c5ec8a0286c914b4d6e9f200024455eea70 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 20 Sep 2023 23:21:00 +0800 Subject: [PATCH 02/42] =?UTF-8?q?trade=EF=BC=9A=E4=B8=8B=E5=8D=95=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=98=AF=E9=97=A8=E5=BA=97=E8=87=AA?= =?UTF-8?q?=E6=8F=90=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=A0=B8=E9=94=80=E7=A0=81?= =?UTF-8?q?=E7=9A=84=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/delivery/DeliveryTypeEnum.java | 4 +- .../app/order/AppTradeOrderController.http | 23 +++++++++- .../convert/order/TradeOrderConvert.java | 9 ++-- .../dal/dataobject/order/TradeOrderDO.java | 4 ++ .../order/TradeOrderUpdateServiceImpl.java | 42 +++++++------------ .../TradeDeliveryPriceCalculator.java | 4 +- .../TradeDeliveryPriceCalculatorTest.java | 2 +- 7 files changed, 48 insertions(+), 40 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryTypeEnum.java index 210f5c307..27e11370c 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryTypeEnum.java @@ -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; /** * 状态名 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.http b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.http index b62e6eb1f..4a9441694 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.http +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.http @@ -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}} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index 4688ca9ef..aa78cd170 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -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 cartMap = convertMap(cartList, CartDO::getId); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java index bcf50c6d3..bb68fc1ac 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java @@ -224,6 +224,10 @@ public class TradeOrderDO extends BaseDO { * 关联 {@link DeliveryPickUpStoreDO#getId()} */ private Long pickUpStoreId; + /** + * 自提核销码 + */ + private String pickUpVerifyCode; // ========== 售后基本信息 ========== /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 8f3bff38b..3cdb364b5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -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); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java index 7c395dbbf..5d9201efa 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java @@ -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); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java index 1f408cf47..0bb44978c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java @@ -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( From dbd7ab5f231c60bac29ee4346263057fb32c879c Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Thu, 21 Sep 2023 17:31:58 +0800 Subject: [PATCH 03/42] =?UTF-8?q?code=20review=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/pay_wallet.sql | 8 ++++---- .../AppPayWalletRechargeCreateReqVO.java | 7 ++++--- .../wallet/PayWalletRechargeConvert.java | 11 +++-------- .../dataobject/wallet/PayWalletRechargeDO.java | 17 +++++++++-------- .../pay/dal/mysql/wallet/PayWalletMapper.java | 13 ++++++------- .../wallet/PayWalletRechargeServiceImpl.java | 8 +++++--- .../service/wallet/PayWalletServiceImpl.java | 6 +++--- 7 files changed, 34 insertions(+), 36 deletions(-) diff --git a/sql/mysql/pay_wallet.sql b/sql/mysql/pay_wallet.sql index e9cc6a288..e3d92239c 100644 --- a/sql/mysql/pay_wallet.sql +++ b/sql/mysql/pay_wallet.sql @@ -50,17 +50,17 @@ CREATE TABLE `pay_wallet_recharge` ( `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', `wallet_id` bigint NOT NULL COMMENT '会员钱包 id', - `price` int NOT NULL COMMENT '用户实际到账余额,例如充 100 送 20,则该值是 120', + `total_price` int NOT NULL COMMENT '用户实际到账余额,例如充 100 送 20,则该值是 120', `pay_price` int NOT NULL COMMENT '实际支付金额', - `wallet_bonus` int NOT NULL COMMENT '钱包赠送金额', + `bonus_price` int NOT NULL COMMENT '钱包赠送金额', `pay_status` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已支付:[0:未支付 1:已经支付过]', `pay_order_id` bigint NULL COMMENT '支付订单编号', `pay_channel_code` varchar(16) NULL COMMENT '支付成功的支付渠道', `pay_time` datetime NULL COMMENT '订单支付时间', `pay_refund_id` bigint NULL COMMENT '支付退款单编号', - `refund_price` int NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额', + `refund_total_price` int NOT NULL DEFAULT 0 COMMENT '退款金额,包含赠送金额', `refund_pay_price` int NOT NULL DEFAULT 0 COMMENT '退款支付金额', - `refund_wallet_bonus` int NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额', + `refund_bonus_price` int NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额', `refund_time` datetime NULL COMMENT '退款时间', `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java index 45125e8c0..44af54c35 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import javax.validation.constraints.DecimalMin; +import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; @Schema(description = "用户 APP - 创建钱包充值 Request VO") @@ -12,14 +13,14 @@ public class AppPayWalletRechargeCreateReqVO { @Schema(description = "支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") @NotNull(message = "支付金额不能为空") - // TODO @jason999:是不是 @Min 哈? - @DecimalMin(value = "0", inclusive = false, message = "支付金额必须大于零") + @Min(value = 1, message = "支付金额必须大于零") private Integer payPrice; // TODO @jason:这个是不是后端计算出来呀?不然前端可以直接搞了。。。 + // TOTO 那是不是搞一个充值模板 @Schema(description = "钱包赠送金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") @NotNull(message = "钱包赠送金额不能为空") @DecimalMin(value = "0", message = "钱包赠送金额必须大于等于零") - private Integer walletBonus; + private Integer bonusPrice; } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java index 584144734..4e53db3a6 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletRechargeConvert.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalle import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateRespVO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; /** @@ -14,14 +15,8 @@ public interface PayWalletRechargeConvert { PayWalletRechargeConvert INSTANCE = Mappers.getMapper(PayWalletRechargeConvert.class); - PayWalletRechargeDO convert(AppPayWalletRechargeCreateReqVO vo); - - // TODO @jason:好像 price 相加,可以写个表达式的,通过 @Mapping - default PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo) { - PayWalletRechargeDO walletRecharge = convert(vo); - return walletRecharge.setWalletId(walletId) - .setPrice(walletRecharge.getPayPrice() + walletRecharge.getWalletBonus()); - } + @Mapping(target = "totalPrice", expression = "java(vo.getPayPrice() + vo.getBonusPrice() )") + PayWalletRechargeDO convert(Long walletId, AppPayWalletRechargeCreateReqVO vo); AppPayWalletRechargeCreateRespVO convert(PayWalletRechargeDO bean); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java index 939b9b4a1..dc56e5614 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java @@ -31,22 +31,21 @@ public class PayWalletRechargeDO extends BaseDO { */ private Long walletId; - // TODO @jason:要不改成 totalPrice? /** * 用户实际到账余额 * * 例如充 100 送 20,则该值是 120 */ - private Integer price; + private Integer totalPrice; /** * 实际支付金额 */ private Integer payPrice; - // TODO @jason:bonusPrice 哈,更统一一点; + /** * 钱包赠送金额 */ - private Integer walletBonus; + private Integer bonusPrice; /** * 是否已支付 @@ -62,6 +61,7 @@ public class PayWalletRechargeDO extends BaseDO { * 关联 {@link PayOrderDO#getId()} */ private Long payOrderId; + /** * 支付成功的支付渠道 * @@ -79,20 +79,21 @@ public class PayWalletRechargeDO extends BaseDO { * 关联 {@link PayRefundDO#getId()} */ private Long payRefundId; - // TODO @jason:要不改成 refundTotalPrice? + /** * 退款金额,包含赠送金额 */ - private Integer refundPrice; + private Integer refundTotalPrice; /** * 退款支付金额 */ private Integer refundPayPrice; - // TODO @jason:要不改成 refundBonusPrice? + /** * 退款钱包赠送金额 */ - private Integer refundWalletBonus; + private Integer refundBonusPrice; + /** * 退款时间 */ diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java index 57f9250d6..47c4c2009 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java @@ -14,15 +14,13 @@ public interface PayWalletMapper extends BaseMapperX { PayWalletDO::getUserType, userType); } - // TODO @jason:下面几个更新方法,把 id 放前面哈。一般来说,重要参数放前面; - /** * 当消费退款时候, 更新钱包 * - * @param price 消费金额 * @param id 钱包 id + * @param price 消费金额 */ - default int updateWhenConsumptionRefund(Integer price, Long id){ + default int updateWhenConsumptionRefund(Long id, Integer price){ LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" balance = balance + " + price + ", total_expense = total_expense - " + price) @@ -36,7 +34,7 @@ public interface PayWalletMapper extends BaseMapperX { * @param price 消费金额 * @param id 钱包 id */ - default int updateWhenConsumption(Integer price, Long id){ + default int updateWhenConsumption(Long id, Integer price){ LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" balance = balance - " + price + ", total_expense = total_expense + " + price) @@ -47,10 +45,11 @@ public interface PayWalletMapper extends BaseMapperX { /** * 当充值的时候,更新钱包 - * @param price 钱包金额 + * * @param id 钱包 id + * @param price 钱包金额 */ - default int updateWhenRecharge(Integer price, Long id){ + default int updateWhenRecharge(Long id, Integer price){ LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" balance = balance + " + price + ", total_recharge = total_recharge + " + price) diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java index 771dfd383..0259627c7 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java @@ -66,8 +66,9 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { // 2.2 更新钱包充值记录中支付订单 walletRechargeMapper.updateById(new PayWalletRechargeDO().setPayOrderId(payOrderId) .setId(walletRecharge.getId())); - // TODO @jason:是不是你直接返回就好啦;然后 payOrderId 设置下; - return walletRechargeMapper.selectById(walletRecharge.getId()); + + walletRecharge.setPayOrderId(payOrderId); + return walletRecharge; } @Override @@ -92,8 +93,9 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { // 3. 更新钱包余额 // TODO @jason:这样的话,未来提现会不会把充值的,也提现走哈。类似先充 100,送 110;然后提现 110; + // TODO 需要钱包中加个可提现余额 payWalletService.addWalletBalance(walletRecharge.getWalletId(), String.valueOf(id), - PayWalletBizTypeEnum.RECHARGE, walletRecharge.getPrice()); + PayWalletBizTypeEnum.RECHARGE, walletRecharge.getTotalPrice()); } private PayOrderDO validateWalletRechargerCanPaid(PayWalletRechargeDO walletRecharge, Long payOrderId) { diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index 346e8523e..542e567ed 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -125,7 +125,7 @@ public class PayWalletServiceImpl implements PayWalletService { int updateCounts = 0 ; switch (bizType) { case PAYMENT: { - updateCounts = walletMapper.updateWhenConsumption(price, payWallet.getId()); + updateCounts = walletMapper.updateWhenConsumption(payWallet.getId(), price); break; } case RECHARGE_REFUND: { @@ -156,11 +156,11 @@ public class PayWalletServiceImpl implements PayWalletService { // 1.2 更新钱包金额 switch (bizType) { case PAYMENT_REFUND: { // 退款更新 - walletMapper.updateWhenConsumptionRefund(price, payWallet.getId()); + walletMapper.updateWhenConsumptionRefund(payWallet.getId(), price); break; } case RECHARGE: { // 充值更新 - walletMapper.updateWhenRecharge(price, payWallet.getId()); + walletMapper.updateWhenRecharge(payWallet.getId(), price); break; } // TODO 其它类型;这里可以先跑异常;避免有业务搞错; From 5949727c8daba66c38f8b78f21ca9efb0dcf448e Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 21 Sep 2023 22:02:22 +0800 Subject: [PATCH 04/42] =?UTF-8?q?trade=EF=BC=9A=E5=85=A8=E5=B1=80=E9=85=8D?= =?UTF-8?q?=E9=80=81=E4=BB=B7=E6=A0=BC=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dal/dataobject/config/TradeConfigDO.java | 11 ++++++ .../TradeDeliveryPriceCalculator.java | 30 +++++++++++++-- .../TradeDeliveryPriceCalculatorTest.java | 38 ++++++++++++++++++- 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java index a0c6d3858..a6704db4f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java @@ -35,6 +35,17 @@ public class TradeConfigDO extends BaseDO { @TableId private Long id; + // ========== 配送相关 ========== + // TODO 芋艿:未配置 + /** + * 是否启用全场包邮 + */ + private Boolean deliveryExpressFreeEnabled; + /** + * 全场包邮的最小金额,单位:分 + */ + private Integer deliveryExpressFreePrice; + // ========== 分销相关 ========== /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java index 5d9201efa..7a4669801 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java @@ -5,9 +5,11 @@ import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryExpressChargeModeEnum; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressTemplateService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryPickUpStoreService; import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateRespBO; @@ -44,6 +46,8 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { private DeliveryPickUpStoreService deliveryPickUpStoreService; @Resource private DeliveryExpressTemplateService deliveryExpressTemplateService; + @Resource + private TradeConfigService tradeConfigService; @Override public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { @@ -70,19 +74,25 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { // ========= 快递发货 ========== private void calculateExpress(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { - // 1. 得到收件地址区域 + // 0. 得到收件地址区域 if (param.getAddressId() == null) { throw exception(PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDRESS_IS_EMPTY); } AddressRespDTO address = addressApi.getAddress(param.getAddressId(), param.getUserId()); Assert.notNull(address, "收件人({})的地址,不能为空", param.getUserId()); - // 2. 过滤出已选中的商品SKU + // 情况一:全局包邮 + if (isGlobalExpressFree(param, result)) { + return; + } + + // 情况二: + // 2.1 过滤出已选中的商品SKU List selectedItem = filterList(result.getItems(), OrderItem::getSelected); Set deliveryTemplateIds = convertSet(selectedItem, OrderItem::getDeliveryTemplateId); Map expressTemplateMap = deliveryExpressTemplateService.getExpressTemplateMapByIdsAndArea(deliveryTemplateIds, address.getAreaId()); - // 3. 计算配送费用 + // 2.2 计算配送费用 if (CollUtil.isEmpty(expressTemplateMap)) { log.error("[calculate][找不到商品 templateIds {} areaId{} 对应的运费模板]", deliveryTemplateIds, address.getAreaId()); throw exception(PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND); @@ -90,6 +100,20 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { calculateDeliveryPrice(selectedItem, expressTemplateMap, result); } + /** + * 是否全局包邮 + * + * @param param 计算信息 + * @param result 计算结果 + * @return 是否包邮 + */ + private boolean isGlobalExpressFree(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + TradeConfigDO config = tradeConfigService.getTradeConfig(); + return config != null + && Boolean.TRUE.equals(config.getDeliveryExpressFreeEnabled()) // 开启包邮 + && result.getPrice().getPayPrice() >= config.getDeliveryExpressFreePrice(); // 满足包邮的价格 + } + private void calculateDeliveryPrice(List selectedSkus, Map expressTemplateMap, TradePriceCalculateRespBO result) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java index 0bb44978c..5aa75fd94 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java @@ -4,8 +4,10 @@ import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryExpressChargeModeEnum; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressTemplateService; import cn.iocoder.yudao.module.trade.service.delivery.bo.DeliveryExpressTemplateRespBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; @@ -34,10 +36,14 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { @InjectMocks private TradeDeliveryPriceCalculator calculator; + @Mock private AddressApi addressApi; + @Mock private DeliveryExpressTemplateService deliveryExpressTemplateService; + @Mock + private TradeConfigService tradeConfigService; private TradePriceCalculateReqBO reqBO; private TradePriceCalculateRespBO resultBO; @@ -89,9 +95,37 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { .setCharge(chargeBO).setFree(freeBO)); } + @Test + @DisplayName("全场包邮") + public void testCalculate_expressGlobalFree() { + // mock 方法(全场包邮) + when(tradeConfigService.getTradeConfig()).thenReturn(new TradeConfigDO().setDeliveryExpressFreeEnabled(true) + .setDeliveryExpressFreePrice(2200)); + + // 调用 + calculator.calculate(reqBO, resultBO); + TradePriceCalculateRespBO.Price price = resultBO.getPrice(); + assertThat(price) + .extracting("totalPrice","discountPrice","couponPrice","pointPrice","deliveryPrice","payPrice") + .containsExactly(2200, 0, 0, 0, 0, 2200); + assertThat(resultBO.getItems()).hasSize(3); + // 断言:SKU1 + assertThat(resultBO.getItems().get(0)) + .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice") + .containsExactly(100, 2, 0, 0, 0, 0, 200); + // 断言:SKU2 + assertThat(resultBO.getItems().get(1)) + .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice") + .containsExactly(200, 10, 0, 0, 0, 0, 2000); + // 断言:SKU3 未选中 + assertThat(resultBO.getItems().get(2)) + .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice") + .containsExactly(300, 1, 0, 0, 0, 0, 300); + } + @Test @DisplayName("按件计算运费不包邮的情况") - public void testCalculateByExpressTemplateCharge() { + public void testCalculate_expressTemplateCharge() { // SKU 1 : 100 * 2 = 200 // SKU 2 :200 * 10 = 2000 // 运费 首件 1000 + 续件 2000 = 3000 @@ -123,7 +157,7 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { @Test @DisplayName("按件计算运费包邮的情况") - public void testCalculateByExpressTemplateFree() { + public void testCalculate_expressTemplateFree() { // SKU 1 : 100 * 2 = 200 // SKU 2 :200 * 10 = 2000 // 运费 0 From 5ed99a91057c31bae88b1a6e18d79804247a961f Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 19 Sep 2023 22:34:50 +0800 Subject: [PATCH 05/42] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=20-=20=E6=95=B4=E7=90=86=E5=8C=85=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{record => }/BrokerageRecordController.java | 12 ++++++------ .../{user => }/BrokerageUserController.java | 12 ++++++------ .../BrokerageWithdrawController.java | 14 +++++++------- .../vo => vo/record}/BrokerageRecordBaseVO.java | 2 +- .../vo => vo/record}/BrokerageRecordPageReqVO.java | 2 +- .../vo => vo/record}/BrokerageRecordRespVO.java | 2 +- .../{user/vo => vo/user}/BrokerageUserBaseVO.java | 2 +- .../BrokerageUserClearBrokerageUserReqVO.java | 2 +- .../vo => vo/user}/BrokerageUserPageReqVO.java | 2 +- .../{user/vo => vo/user}/BrokerageUserRespVO.java | 2 +- .../BrokerageUserUpdateBrokerageEnabledReqVO.java | 2 +- .../BrokerageUserUpdateBrokerageUserReqVO.java | 2 +- .../withdraw}/BrokerageWithdrawBaseVO.java | 2 +- .../withdraw}/BrokerageWithdrawPageReqVO.java | 2 +- .../withdraw}/BrokerageWithdrawRejectReqVO.java | 2 +- .../withdraw}/BrokerageWithdrawRespVO.java | 2 +- .../brokerage/AppBrokerageRecordController.java | 2 +- .../app/brokerage/AppBrokerageUserController.java | 2 +- .../{record => }/BrokerageRecordConvert.java | 8 ++++---- .../brokerage/{user => }/BrokerageUserConvert.java | 6 +++--- .../{withdraw => }/BrokerageWithdrawConvert.java | 8 ++++---- .../brokerage/{record => }/BrokerageRecordDO.java | 2 +- .../brokerage/{user => }/BrokerageUserDO.java | 2 +- .../{withdraw => }/BrokerageWithdrawDO.java | 2 +- .../{record => }/BrokerageRecordMapper.java | 6 +++--- .../brokerage/{user => }/BrokerageUserMapper.java | 6 +++--- .../{withdraw => }/BrokerageWithdrawMapper.java | 6 +++--- .../job/brokerage/BrokerageRecordUnfreezeJob.java | 2 +- .../{record => }/BrokerageRecordService.java | 6 +++--- .../{record => }/BrokerageRecordServiceImpl.java | 13 ++++++------- .../brokerage/{user => }/BrokerageUserService.java | 6 +++--- .../{user => }/BrokerageUserServiceImpl.java | 8 ++++---- .../{withdraw => }/BrokerageWithdrawService.java | 6 +++--- .../BrokerageWithdrawServiceImpl.java | 9 ++++----- .../service/order/TradeOrderUpdateServiceImpl.java | 2 +- .../BrokerageRecordServiceImplTest.java | 11 ++++++----- .../{user => }/BrokerageUserServiceImplTest.java | 9 +++++---- .../BrokerageWithdrawServiceImplTest.java | 9 ++++----- 38 files changed, 97 insertions(+), 98 deletions(-) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{record => }/BrokerageRecordController.java (89%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{user => }/BrokerageUserController.java (93%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{withdraw => }/BrokerageWithdrawController.java (89%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{record/vo => vo/record}/BrokerageRecordBaseVO.java (99%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{record/vo => vo/record}/BrokerageRecordPageReqVO.java (98%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{record/vo => vo/record}/BrokerageRecordRespVO.java (99%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{user/vo => vo/user}/BrokerageUserBaseVO.java (99%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{user/vo => vo/user}/BrokerageUserClearBrokerageUserReqVO.java (98%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{user/vo => vo/user}/BrokerageUserPageReqVO.java (99%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{user/vo => vo/user}/BrokerageUserRespVO.java (99%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{user/vo => vo/user}/BrokerageUserUpdateBrokerageEnabledReqVO.java (98%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{user/vo => vo/user}/BrokerageUserUpdateBrokerageUserReqVO.java (98%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{withdraw/vo => vo/withdraw}/BrokerageWithdrawBaseVO.java (99%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{withdraw/vo => vo/withdraw}/BrokerageWithdrawPageReqVO.java (99%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{withdraw/vo => vo/withdraw}/BrokerageWithdrawRejectReqVO.java (98%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/{withdraw/vo => vo/withdraw}/BrokerageWithdrawRespVO.java (98%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/{record => }/BrokerageRecordConvert.java (91%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/{user => }/BrokerageUserConvert.java (93%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/{withdraw => }/BrokerageWithdrawConvert.java (85%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/{record => }/BrokerageRecordDO.java (96%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/{user => }/BrokerageUserDO.java (95%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/{withdraw => }/BrokerageWithdrawDO.java (96%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/{record => }/BrokerageRecordMapper.java (93%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/{user => }/BrokerageUserMapper.java (96%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/{withdraw => }/BrokerageWithdrawMapper.java (89%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/{record => }/BrokerageRecordService.java (91%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/{record => }/BrokerageRecordServiceImpl.java (95%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/{user => }/BrokerageUserService.java (95%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/{user => }/BrokerageUserServiceImpl.java (97%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/{withdraw => }/BrokerageWithdrawService.java (83%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/{withdraw => }/BrokerageWithdrawServiceImpl.java (91%) rename yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/{record => }/BrokerageRecordServiceImplTest.java (91%) rename yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/{user => }/BrokerageUserServiceImplTest.java (88%) rename yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/{withdraw => brokerage}/BrokerageWithdrawServiceImplTest.java (91%) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/BrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageRecordController.java similarity index 89% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/BrokerageRecordController.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageRecordController.java index 9bb135670..ff9bd5285 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/BrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageRecordController.java @@ -1,14 +1,14 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordRespVO; -import cn.iocoder.yudao.module.trade.convert.brokerage.record.BrokerageRecordConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java similarity index 93% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java index d90900061..548fdce0a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/BrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java @@ -1,17 +1,17 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.*; -import cn.iocoder.yudao.module.trade.convert.brokerage.user.BrokerageUserConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.*; +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; -import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/BrokerageWithdrawController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageWithdrawController.java similarity index 89% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/BrokerageWithdrawController.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageWithdrawController.java index 1ba6130a2..609cfa433 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/BrokerageWithdrawController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageWithdrawController.java @@ -1,16 +1,16 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawRejectReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawPageReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawRespVO; -import cn.iocoder.yudao.module.trade.convert.brokerage.withdraw.BrokerageWithdrawConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRejectReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRespVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageWithdrawConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; -import cn.iocoder.yudao.module.trade.service.brokerage.withdraw.BrokerageWithdrawService; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/record/BrokerageRecordBaseVO.java similarity index 99% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/record/BrokerageRecordBaseVO.java index 425758631..0c53f99fb 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/record/BrokerageRecordBaseVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/record/BrokerageRecordPageReqVO.java similarity index 98% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/record/BrokerageRecordPageReqVO.java index 8d0eeff3f..36c4744e8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/record/BrokerageRecordPageReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record; import cn.iocoder.yudao.framework.common.pojo.PageParam; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/record/BrokerageRecordRespVO.java similarity index 99% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/record/BrokerageRecordRespVO.java index 1f58b53ee..224ecf1e5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/BrokerageRecordRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/record/BrokerageRecordRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserBaseVO.java similarity index 99% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserBaseVO.java index 34f792b72..05e5935b0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserBaseVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserClearBrokerageUserReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserClearBrokerageUserReqVO.java similarity index 98% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserClearBrokerageUserReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserClearBrokerageUserReqVO.java index edb0102a0..5a05c56ce 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserClearBrokerageUserReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserClearBrokerageUserReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserPageReqVO.java similarity index 99% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserPageReqVO.java index 1f7816355..cb0ce8954 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserPageReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user; import cn.iocoder.yudao.framework.common.pojo.PageParam; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserRespVO.java similarity index 99% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserRespVO.java index 4aa3e5732..4713d8e13 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserUpdateBrokerageEnabledReqVO.java similarity index 98% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserUpdateBrokerageEnabledReqVO.java index 92001e698..d097855a2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageEnabledReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserUpdateBrokerageEnabledReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserUpdateBrokerageUserReqVO.java similarity index 98% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserUpdateBrokerageUserReqVO.java index d62c7fd1e..56391c4d5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/BrokerageUserUpdateBrokerageUserReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserUpdateBrokerageUserReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawBaseVO.java similarity index 99% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawBaseVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawBaseVO.java index 58f0ee8ef..8aca8a2bb 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawBaseVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawPageReqVO.java similarity index 99% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawPageReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawPageReqVO.java index c6f56878a..b18ff74af 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawPageReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.validation.InEnum; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawRejectReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawRejectReqVO.java similarity index 98% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawRejectReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawRejectReqVO.java index 72e26c547..23e6c28e5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawRejectReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawRejectReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawRespVO.java similarity index 98% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawRespVO.java index c21d5b539..de74bb4f6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/withdraw/vo/BrokerageWithdrawRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/withdraw/BrokerageWithdrawRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo; +package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java index 66fb2994a..62f592351 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java @@ -6,7 +6,7 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageProductPriceRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO; -import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 208ecee2e..6d3296cb9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*; -import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java similarity index 91% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java index 5d620a898..4b3c23fed 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/BrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java @@ -1,12 +1,12 @@ -package cn.iocoder.yudao.module.trade.convert.brokerage.record; +package cn.iocoder.yudao.module.trade.convert.brokerage; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordRespVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import org.mapstruct.Mapper; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java similarity index 93% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java index 83101a1de..e904f6bfc 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/user/BrokerageUserConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java @@ -1,10 +1,10 @@ -package cn.iocoder.yudao.module.trade.convert.brokerage.user; +package cn.iocoder.yudao.module.trade.convert.brokerage; import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserRespVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserRespVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/withdraw/BrokerageWithdrawConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java similarity index 85% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/withdraw/BrokerageWithdrawConvert.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java index 3aa28db5e..f4c27e334 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/withdraw/BrokerageWithdrawConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java @@ -1,10 +1,10 @@ -package cn.iocoder.yudao.module.trade.convert.brokerage.withdraw; +package cn.iocoder.yudao.module.trade.convert.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawRejectReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawRespVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRejectReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRespVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageRecordDO.java similarity index 96% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageRecordDO.java index 0f59eada5..c819d723b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/BrokerageRecordDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageRecordDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record; +package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageUserDO.java similarity index 95% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageUserDO.java index 3493cac97..320bd0b07 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/BrokerageUserDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageUserDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user; +package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.KeySequence; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/withdraw/BrokerageWithdrawDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageWithdrawDO.java similarity index 96% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/withdraw/BrokerageWithdrawDO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageWithdrawDO.java index be5b41285..ff937e96d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/withdraw/BrokerageWithdrawDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageWithdrawDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw; +package cn.iocoder.yudao.module.trade.dal.dataobject.brokerage; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java similarity index 93% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java index dcc627b78..a3c177526 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/BrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java @@ -1,10 +1,10 @@ -package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record; +package cn.iocoder.yudao.module.trade.dal.mysql.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java similarity index 96% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java index 239625b17..e0a45c0db 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/user/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java @@ -1,11 +1,11 @@ -package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user; +package cn.iocoder.yudao.module.trade.dal.mysql.brokerage; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/withdraw/BrokerageWithdrawMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java similarity index 89% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/withdraw/BrokerageWithdrawMapper.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java index d5269fd55..9c36238f9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/withdraw/BrokerageWithdrawMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java @@ -1,10 +1,10 @@ -package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.withdraw; +package cn.iocoder.yudao.module.trade.dal.mysql.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/BrokerageRecordUnfreezeJob.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/BrokerageRecordUnfreezeJob.java index c221408e5..cd81e44ec 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/BrokerageRecordUnfreezeJob.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/BrokerageRecordUnfreezeJob.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.trade.job.brokerage; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; -import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; import org.springframework.stereotype.Component; import javax.annotation.Resource; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java similarity index 91% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java index a6ef0b659..bfdb5929c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java @@ -1,8 +1,8 @@ -package cn.iocoder.yudao.module.trade.service.brokerage.record; +package cn.iocoder.yudao.module.trade.service.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java similarity index 95% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java index 5752f0615..0d1a4e0bf 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.service.brokerage.record; +package cn.iocoder.yudao.module.trade.service.brokerage; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.BooleanUtil; @@ -7,17 +7,16 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.convert.brokerage.record.BrokerageRecordConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.BrokerageRecordMapper; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageRecordMapper; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; -import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java similarity index 95% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java index 88b84d9f4..db4ff1046 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java @@ -1,9 +1,9 @@ -package cn.iocoder.yudao.module.trade.service.brokerage.user; +package cn.iocoder.yudao.module.trade.service.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java similarity index 97% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java index 614393be2..e2b9d88e0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.service.brokerage.user; +package cn.iocoder.yudao.module.trade.service.brokerage; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; @@ -6,10 +6,10 @@ import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.BrokerageUserMapper; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageUserMapper; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/withdraw/BrokerageWithdrawService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java similarity index 83% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/withdraw/BrokerageWithdrawService.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java index 26c1d4a8e..f2db25243 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/withdraw/BrokerageWithdrawService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java @@ -1,8 +1,8 @@ -package cn.iocoder.yudao.module.trade.service.brokerage.withdraw; +package cn.iocoder.yudao.module.trade.service.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/withdraw/BrokerageWithdrawServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java similarity index 91% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/withdraw/BrokerageWithdrawServiceImpl.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java index 9369de782..ec50a7e81 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/withdraw/BrokerageWithdrawServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.service.brokerage.withdraw; +package cn.iocoder.yudao.module.trade.service.brokerage; import cn.hutool.core.date.LocalDateTimeUtil; import cn.hutool.core.map.MapUtil; @@ -6,12 +6,11 @@ import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi; import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.withdraw.BrokerageWithdrawMapper; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageWithdrawMapper; import cn.iocoder.yudao.module.trade.enums.MessageTemplateConstants; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; -import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 3cdb364b5..c4f1677e5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -49,7 +49,7 @@ import cn.iocoder.yudao.module.trade.enums.order.*; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.framework.order.core.annotations.TradeOrderLog; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; import cn.iocoder.yudao.module.trade.service.cart.CartService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; import cn.iocoder.yudao.module.trade.service.message.TradeMessageService; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImplTest.java similarity index 91% rename from yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImplTest.java index abf2b37c1..99a815e5e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/BrokerageRecordServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImplTest.java @@ -1,12 +1,13 @@ -package cn.iocoder.yudao.module.trade.service.brokerage.record; +package cn.iocoder.yudao.module.trade.service.brokerage; import cn.hutool.core.util.NumberUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.BrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.BrokerageRecordDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.BrokerageRecordMapper; -import cn.iocoder.yudao.module.trade.service.brokerage.user.BrokerageUserService; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageRecordMapper; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordServiceImpl; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImplTest.java similarity index 88% rename from yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImplTest.java index 1c505e1b4..88157c204 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/BrokerageUserServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImplTest.java @@ -1,10 +1,11 @@ -package cn.iocoder.yudao.module.trade.service.brokerage.user; +package cn.iocoder.yudao.module.trade.service.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.user.vo.BrokerageUserPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.BrokerageUserDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.user.BrokerageUserMapper; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageUserMapper; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserServiceImpl; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/withdraw/BrokerageWithdrawServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImplTest.java similarity index 91% rename from yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/withdraw/BrokerageWithdrawServiceImplTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImplTest.java index ce53b38a6..98e4f6115 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/withdraw/BrokerageWithdrawServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImplTest.java @@ -1,11 +1,10 @@ -package cn.iocoder.yudao.module.trade.service.withdraw; +package cn.iocoder.yudao.module.trade.service.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.withdraw.vo.BrokerageWithdrawPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.withdraw.BrokerageWithdrawDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.withdraw.BrokerageWithdrawMapper; -import cn.iocoder.yudao.module.trade.service.brokerage.withdraw.BrokerageWithdrawServiceImpl; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageWithdrawMapper; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; From a7de955926c9c6fb45adbad2bf8daa68967cd551 Mon Sep 17 00:00:00 2001 From: owen Date: Thu, 21 Sep 2023 23:56:34 +0800 Subject: [PATCH 06/42] =?UTF-8?q?trade:=20=E5=88=86=E9=94=80=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=20-=20=E6=8F=90=E7=8E=B0=E7=94=B3=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 43 +++++----- .../trade/enums/ErrorCodeConstants.java | 2 + .../brokerage/BrokerageRecordBizTypeEnum.java | 1 + .../brokerage/AppBrokerageUserController.java | 2 +- .../AppBrokerageWithdrawController.java | 8 +- .../vo/user/AppBrokerageUserRespVO.java | 2 +- .../AppBrokerageWithdrawCreateReqVO.java | 6 +- .../brokerage/BrokerageRecordConvert.java | 3 +- .../brokerage/BrokerageWithdrawConvert.java | 4 +- .../brokerage/BrokerageWithdrawDO.java | 2 +- .../dal/dataobject/config/TradeConfigDO.java | 4 + .../mysql/brokerage/BrokerageUserMapper.java | 11 +-- .../brokerage/BrokerageRecordService.java | 11 +++ .../brokerage/BrokerageRecordServiceImpl.java | 28 +++++++ .../brokerage/BrokerageUserService.java | 3 +- .../brokerage/BrokerageUserServiceImpl.java | 5 +- .../brokerage/BrokerageWithdrawService.java | 12 ++- .../BrokerageWithdrawServiceImpl.java | 83 +++++++++++++++++-- .../BrokerageWithdrawServiceImplTest.java | 30 +++++++ .../src/test/resources/sql/create_tables.sql | 2 +- 20 files changed, 216 insertions(+), 46 deletions(-) diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 179bfcda0..a46e1070a 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -1,25 +1,29 @@ -- 增加配置表 create table trade_config ( - id bigint auto_increment comment '自增主键' primary key, - brokerage_enabled bit default 1 not null comment '是否启用分佣', - brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:1-人人分销 2-指定分销', - brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 1-没有推广人,2-新用户, 3-扫码覆盖', - brokerage_post_urls varchar(2000) default '' null comment '分销海报图地址数组', - brokerage_first_percent int default 0 not null comment '一级返佣比例', - brokerage_second_percent int default 0 not null comment '二级返佣比例', - brokerage_withdraw_min_price int default 0 not null comment '用户提现最低金额', - brokerage_bank_names varchar(200) default '' not null comment '提现银行(字典类型=brokerage_bank_name)', - brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)', - brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝', - creator varchar(64) default '' null comment '创建者', - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', - updater varchar(64) default '' null comment '更新者', - update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', - deleted bit default b'0' not null comment '是否删除', - tenant_id bigint default 0 not null comment '租户编号' + id bigint auto_increment comment '自增主键' primary key, + brokerage_enabled bit default 1 not null comment '是否启用分佣', + brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:1-人人分销 2-指定分销', + brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 1-没有推广人,2-新用户, 3-扫码覆盖', + brokerage_post_urls varchar(2000) default '' null comment '分销海报图地址数组', + brokerage_first_percent int default 0 not null comment '一级返佣比例', + brokerage_second_percent int default 0 not null comment '二级返佣比例', + brokerage_withdraw_min_price int default 0 not null comment '用户提现最低金额', + brokerage_withdraw_fee_percent int default 0 not null comment '提现手续费百分比', + brokerage_bank_names varchar(200) default '' not null comment '提现银行(字典类型=brokerage_bank_name)', + brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)', + brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝', + creator varchar(64) default '' null comment '创建者', + create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', + updater varchar(64) default '' null comment '更新者', + update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', + deleted bit default b'0' not null comment '是否删除', + tenant_id bigint default 0 not null comment '租户编号' ) comment '交易中心配置'; +# alter table trade_config +# add brokerage_withdraw_fee_percent int default 0 not null comment '提现手续费百分比' after brokerage_withdraw_min_price; + # alter table trade_brokerage_user # add level int not null default 1 comment '等级' after frozen_price; # alter table trade_brokerage_user @@ -83,7 +87,7 @@ create index idx_status on trade_brokerage_record (status) comment '状态'; create table trade_brokerage_withdraw ( - id int auto_increment comment '编号' + id bigint auto_increment comment '编号' primary key, user_id bigint not null comment '用户编号', price int default 0 not null comment '提现金额', @@ -137,7 +141,8 @@ insert into system_dict_type(type, name) values ('brokerage_record_biz_type', '佣金记录业务类型'); insert into system_dict_data(dict_type, label, value, sort) values ('brokerage_record_biz_type', '订单返佣', 1, 1), - ('brokerage_record_biz_type', '申请提现', 2, 2); + ('brokerage_record_biz_type', '申请提现', 2, 2), + ('brokerage_record_biz_type', '申请提现驳回', 3, 3); insert into system_dict_type(type, name) values ('brokerage_record_status', '佣金记录状态'); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 500601442..f591a0d60 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -93,5 +93,7 @@ public interface ErrorCodeConstants { // ========== 分销提现 模块 1011008000 ========== ErrorCode BROKERAGE_WITHDRAW_NOT_EXISTS = new ErrorCode(1011008000, "佣金提现记录不存在"); ErrorCode BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING = new ErrorCode(1011008001, "佣金提现记录状态不是审核中"); + ErrorCode BROKERAGE_WITHDRAW_MIN_PRICE = new ErrorCode(1011008002, "提现金额不能低于{}元"); + ErrorCode BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH = new ErrorCode(1011008003, "您当前最多可提现{}元"); } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java index ae798a6ac..73fbb4c91 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java @@ -17,6 +17,7 @@ public enum BrokerageRecordBizTypeEnum implements IntArrayValuable { ORDER(1, "获得推广佣金", "获得推广佣金 {}", true), WITHDRAW(2, "提现申请", "提现申请扣除佣金 {}", false), + WITHDRAW_REJECT(3, "提现申请驳回", "提现申请驳回返还佣金 {}", true), ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageRecordBizTypeEnum::getType).toArray(); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 6d3296cb9..f0b894c9e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -38,7 +38,7 @@ public class AppBrokerageUserController { public CommonResult getBrokerageUser() { AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO() .setBrokerageEnabled(true) - .setPrice(2000) + .setBrokeragePrice(2000) .setFrozenPrice(3000); return success(respVO); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java index 1f6d383ea..f65aee42c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java @@ -5,16 +5,19 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; import javax.validation.Valid; import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; import static java.util.Arrays.asList; @Tag(name = "用户 APP - 分销提现") @@ -23,6 +26,8 @@ import static java.util.Arrays.asList; @Validated @Slf4j public class AppBrokerageWithdrawController { + @Resource + private BrokerageWithdrawService brokerageWithdrawService; // TODO 芋艿:临时 mock => @GetMapping("/page") @@ -36,12 +41,11 @@ public class AppBrokerageWithdrawController { return success(new PageResult<>(asList(vo1, vo2), 10L)); } - // TODO 芋艿:临时 mock => @PostMapping("/create") @Operation(summary = "创建分销提现") @PreAuthenticated public CommonResult createBrokerageWithdraw(@RequestBody @Valid AppBrokerageWithdrawCreateReqVO createReqVO) { - return success(1L); + return success(brokerageWithdrawService.createBrokerageWithdraw(createReqVO, getLoginUserId())); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java index 40b70bed2..f98da7eb6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserRespVO.java @@ -11,7 +11,7 @@ public class AppBrokerageUserRespVO { private Boolean brokerageEnabled; @Schema(description = "可用的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "2408") - private Integer price; + private Integer brokeragePrice; @Schema(description = "冻结的佣金,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "234") private Integer frozenPrice; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java index a8b1523b2..1a3997db9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java @@ -8,8 +8,9 @@ import lombok.Data; import org.hibernate.validator.constraints.URL; import javax.validation.Validator; -import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.PositiveOrZero; @Schema(description = "用户 App - 分销提现创建 Request VO") @Data @@ -20,7 +21,8 @@ public class AppBrokerageWithdrawCreateReqVO { private Integer type; @Schema(description = "提现金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") - @Min(value = 1, message = "提现金额不能小于 1") + @PositiveOrZero(message = "提现金额不能小于 0") + @NotNull(message = "提现金额不能为空") private Integer price; // ========== 银行卡、微信、支付宝 提现相关字段 ========== diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java index 4b3c23fed..e85ad24d3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.convert.brokerage; +import cn.hutool.core.math.Money; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -45,7 +46,7 @@ public interface BrokerageRecordConvert { .setBizType(bizType.getType()).setBizId(bizId) .setPrice(brokeragePrice).setTotalPrice(user.getBrokeragePrice()) .setTitle(title) - .setDescription(StrUtil.format(bizType.getDescription(), String.format("¥%.2f", brokeragePrice / 100d))) + .setDescription(StrUtil.format(bizType.getDescription(), new Money(0, Math.abs(brokeragePrice)))) .setStatus(status).setFrozenDays(brokerageFrozenDays).setUnfreezeTime(unfreezeTime) .setSourceUserLevel(sourceUserLevel).setSourceUserId(sourceUserId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java index f4c27e334..bbc168aee 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java @@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.trade.convert.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRejectReqVO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -22,7 +22,7 @@ public interface BrokerageWithdrawConvert { BrokerageWithdrawConvert INSTANCE = Mappers.getMapper(BrokerageWithdrawConvert.class); - BrokerageWithdrawDO convert(BrokerageWithdrawRejectReqVO bean); + BrokerageWithdrawDO convert(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId, Integer feePrice); BrokerageWithdrawRespVO convert(BrokerageWithdrawDO bean); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageWithdrawDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageWithdrawDO.java index ff937e96d..f31c23800 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageWithdrawDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageWithdrawDO.java @@ -29,7 +29,7 @@ public class BrokerageWithdrawDO extends BaseDO { * 编号 */ @TableId - private Integer id; + private Long id; /** * 用户编号 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java index a6704db4f..7fac1de38 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java @@ -81,6 +81,10 @@ public class TradeConfigDO extends BaseDO { * 用户提现最低金额 */ private Integer brokerageWithdrawMinPrice; + /** + * 用户提现手续费百分比 + */ + private Integer brokerageWithdrawFeePercent; /** * 提现银行 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java index e0a45c0db..ea39d1054 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java @@ -38,7 +38,7 @@ public interface BrokerageUserMapper extends BaseMapperX { default void updatePriceIncr(Long id, Integer incrCount) { Assert.isTrue(incrCount > 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" price = price + " + incrCount) + .setSql(" brokerage_price = brokerage_price + " + incrCount) .eq(BrokerageUserDO::getId, id); update(null, lambdaUpdateWrapper); } @@ -49,13 +49,14 @@ public interface BrokerageUserMapper extends BaseMapperX { * * @param id 用户编号 * @param incrCount 增加佣金(负数) + * @return 更新行数 */ - default void updatePriceDecr(Long id, Integer incrCount) { + default int updatePriceDecr(Long id, Integer incrCount) { Assert.isTrue(incrCount < 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .setSql(" price = price + " + incrCount) // 负数,所以使用 + 号 + .setSql(" brokerage_price = brokerage_price + " + incrCount) // 负数,所以使用 + 号 .eq(BrokerageUserDO::getId, id); - update(null, lambdaUpdateWrapper); + return update(null, lambdaUpdateWrapper); } /** @@ -98,7 +99,7 @@ public interface BrokerageUserMapper extends BaseMapperX { Assert.isTrue(incrCount < 0); LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() .setSql(" frozen_price = frozen_price + " + incrCount + // 负数,所以使用 + 号 - ", price = price + " + -incrCount) // 负数,所以使用 - 号 + ", brokerage_price = brokerage_price + " + -incrCount) // 负数,所以使用 - 号 .eq(BrokerageUserDO::getId, id) .ge(BrokerageUserDO::getFrozenPrice, -incrCount); // cas 逻辑 return update(null, lambdaUpdateWrapper); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java index bfdb5929c..39359586f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java @@ -42,6 +42,17 @@ public interface BrokerageRecordService { */ void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, @Valid List list); + /** + * 增加佣金 + * + * @param userId 会员编号 + * @param bizType 业务类型 + * @param bizId 业务编号 + * @param brokeragePrice 佣金 + * @param title 标题 + */ + void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, int brokeragePrice, String title); + /** * 取消佣金:将佣金记录,状态修改为已失效 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java index 0d1a4e0bf..7995e201c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.trade.service.brokerage; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.math.Money; import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; @@ -28,6 +29,10 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Optional; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH; /** * 佣金记录 Service 实现类 @@ -217,6 +222,29 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { return summaryBO != null ? summaryBO : new UserBrokerageSummaryBO(0, 0); } + @Override + @Transactional(rollbackFor = Exception.class) + public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, int brokeragePrice, String title) { + // 校验佣金余额 + BrokerageUserDO user = brokerageUserService.getBrokerageUser(userId); + int balance = Optional.of(user) + .map(BrokerageUserDO::getBrokeragePrice).orElse(0); + if (balance < brokeragePrice) { + throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance)); + } + + // 扣减佣金余额 + boolean success = brokerageUserService.updateUserPrice(userId, brokeragePrice); + if (!success) { + throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance)); + } + + // 新增记录 + BrokerageRecordDO record = BrokerageRecordConvert.INSTANCE.convert(user, bizType, bizId, 0, brokeragePrice, + null, title, null, null); + brokerageRecordMapper.insert(record); + } + @Transactional(rollbackFor = Exception.class) public boolean unfreezeRecord(BrokerageRecordDO record) { // 更新记录状态 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java index db4ff1046..083edc44a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java @@ -70,8 +70,9 @@ public interface BrokerageUserService { * * @param id 用户编号 * @param price 用户可用佣金 + * @return 更新结果 */ - void updateUserPrice(Long id, Integer price); + boolean updateUserPrice(Long id, Integer price); /** * 更新用户冻结佣金 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java index e2b9d88e0..bab10ddc3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java @@ -110,12 +110,13 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } @Override - public void updateUserPrice(Long id, Integer price) { + public boolean updateUserPrice(Long id, Integer price) { if (price > 0) { brokerageUserMapper.updatePriceIncr(id, price); } else if (price < 0) { - brokerageUserMapper.updatePriceDecr(id, price); + return brokerageUserMapper.updatePriceDecr(id, price) > 0; } + return true; } @Override diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java index f2db25243..35b7b07e0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.service.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; @@ -13,7 +14,7 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum public interface BrokerageWithdrawService { /** - * 审核佣金提现 + * 【管理员】审核佣金提现 * * @param id 佣金编号 * @param status 审核状态 @@ -37,4 +38,13 @@ public interface BrokerageWithdrawService { * @return 佣金提现分页 */ PageResult getBrokerageWithdrawPage(BrokerageWithdrawPageReqVO pageReqVO); + + /** + * 【会员】创建佣金提现 + * + * @param createReqVO 创建信息 + * @param userId 会员用户编号 + * @return 佣金提现编号 + */ + Long createBrokerageWithdraw(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java index ec50a7e81..218cd7240 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java @@ -2,26 +2,34 @@ package cn.iocoder.yudao.module.trade.service.brokerage; import cn.hutool.core.date.LocalDateTimeUtil; import cn.hutool.core.map.MapUtil; +import cn.hutool.core.math.Money; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi; import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageWithdrawConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageWithdrawMapper; import cn.iocoder.yudao.module.trade.enums.MessageTemplateConstants; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawTypeEnum; +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import javax.validation.Validator; import java.time.LocalDateTime; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_WITHDRAW_NOT_EXISTS; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; /** * 佣金提现 Service 实现类 @@ -37,10 +45,15 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { @Resource private BrokerageRecordService brokerageRecordService; + @Resource + private TradeConfigService tradeConfigService; @Resource private NotifyMessageSendApi notifyMessageSendApi; + @Resource + private Validator validator; + @Override @Transactional(rollbackFor = Exception.class) public void auditBrokerageWithdraw(Integer id, BrokerageWithdrawStatusEnum status, String auditReason) { @@ -61,19 +74,26 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { throw exception(BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING); } - // 3. 驳回时需要退还用户佣金 String templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_APPROVE; - if (BrokerageWithdrawStatusEnum.AUDIT_FAIL.equals(status)) { + if (BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.equals(status)) { + // 3.1 通过时佣金转余额 + if (BrokerageWithdrawTypeEnum.WALLET.getType().equals(withdraw.getType())) { + // todo + } + } else if (BrokerageWithdrawStatusEnum.AUDIT_FAIL.equals(status)) { templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_REJECT; - // todo @owen -// brokerageRecordService.addBrokerage(withdraw.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW, withdraw.getPrice(), ""); + // 3.2 驳回时需要退还用户佣金 + brokerageRecordService.addBrokerage(withdraw.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT, + String.valueOf(withdraw.getId()), withdraw.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT.getTitle()); + } else { + throw new IllegalArgumentException("不支持的提现状态"); } // 4. 通知用户 Map templateParams = MapUtil.builder() .put("createTime", LocalDateTimeUtil.formatNormal(withdraw.getCreateTime())) - .put("price", String.format("%.2f", withdraw.getPrice() / 100d)) + .put("price", new Money(0, withdraw.getPrice()).toString()) .put("reason", withdraw.getAuditReason()) .build(); NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO() @@ -100,4 +120,53 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { return brokerageWithdrawMapper.selectPage(pageReqVO); } + @Override + @Transactional(rollbackFor = Exception.class) + public Long createBrokerageWithdraw(AppBrokerageWithdrawCreateReqVO createReqVO, Long userId) { + // 校验提现金额 + TradeConfigDO tradeConfig = validateWithdrawPrice(createReqVO.getPrice()); + // 校验提现参数 + createReqVO.validate(validator); + + // 计算手续费 + Integer feePrice = calculateFeePrice(createReqVO.getPrice(), tradeConfig.getBrokerageWithdrawFeePercent()); + // 创建佣金提现记录 + BrokerageWithdrawDO withdraw = BrokerageWithdrawConvert.INSTANCE.convert(createReqVO, userId, feePrice); + brokerageWithdrawMapper.insert(withdraw); + + // 创建用户佣金记录 + brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.WITHDRAW, String.valueOf(withdraw.getId()), + -createReqVO.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW.getTitle()); + + return withdraw.getId(); + } + + /** + * 计算提现手续费 + * + * @param withdrawPrice 提现金额 + * @param percent 手续费百分比 + * @return 提现手续费 + */ + Integer calculateFeePrice(Integer withdrawPrice, Integer percent) { + Integer feePrice = 0; + if (percent != null && percent > 0) { + feePrice = MoneyUtils.calculateRatePrice(withdrawPrice, Double.valueOf(percent)); + } + return feePrice; + } + + /** + * 校验提现金额要求 + * + * @param withdrawPrice 提现金额 + * @return 分销配置 + */ + TradeConfigDO validateWithdrawPrice(Integer withdrawPrice) { + TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); + if (tradeConfig.getBrokerageWithdrawMinPrice() != null && withdrawPrice < tradeConfig.getBrokerageWithdrawMinPrice()) { + throw exception(BROKERAGE_WITHDRAW_MIN_PRICE, new Money(0, tradeConfig.getBrokerageWithdrawMinPrice())); + } + return tradeConfig; + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImplTest.java index 98e4f6115..af0cdbb1a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImplTest.java @@ -2,14 +2,18 @@ package cn.iocoder.yudao.module.trade.service.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; +import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageWithdrawMapper; +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import javax.annotation.Resource; +import javax.validation.Validator; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; @@ -32,6 +36,19 @@ public class BrokerageWithdrawServiceImplTest extends BaseDbUnitTest { @Resource private BrokerageWithdrawMapper brokerageWithdrawMapper; + @MockBean + private BrokerageRecordService brokerageRecordService; + @MockBean + private BrokerageUserService brokerageUserService; + @MockBean + private TradeConfigService tradeConfigService; + + @MockBean + private NotifyMessageSendApi notifyMessageSendApi; + + @Resource + private Validator validator; + @Test @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 public void testGetBrokerageWithdrawPage() { @@ -84,4 +101,17 @@ public class BrokerageWithdrawServiceImplTest extends BaseDbUnitTest { assertPojoEquals(dbBrokerageWithdraw, pageResult.getList().get(0)); } + @Test + public void testCalculateFeePrice() { + Integer withdrawPrice = 100; + // 测试手续费比例未设置 + Integer percent = null; + assertEquals(brokerageWithdrawService.calculateFeePrice(withdrawPrice, percent), 0); + // 测试手续费给为0 + percent = 0; + assertEquals(brokerageWithdrawService.calculateFeePrice(withdrawPrice, percent), 0); + // 测试手续费 + percent = 1; + assertEquals(brokerageWithdrawService.calculateFeePrice(withdrawPrice, percent), 1); + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql index e78cd187b..d263fdfb9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql @@ -186,6 +186,6 @@ CREATE TABLE IF NOT EXISTS "trade_brokerage_withdraw" "updater" varchar DEFAULT '', "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0',目 + "tenant_id" bigint not null default '0', PRIMARY KEY ("id") ) COMMENT '佣金提现'; \ No newline at end of file From 594e4d5fee6a6bc102e7b2a89fb30cc2c7b08b16 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 22 Sep 2023 15:11:06 +0800 Subject: [PATCH 07/42] =?UTF-8?q?system:=20uniapp=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AD=97=E5=85=B8=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/dict/AppDictDataController.java | 33 +++++++++++++++++++ .../app/dict/vo/AppDictDataRespVO.java | 20 +++++++++++ .../system/convert/dict/DictDataConvert.java | 3 +- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java index c4946c371..d0b661a4a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java @@ -1,4 +1,37 @@ package cn.iocoder.yudao.module.system.controller.app.dict; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; +import cn.iocoder.yudao.module.system.controller.app.dict.vo.AppDictDataRespVO; +import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; +import cn.iocoder.yudao.module.system.service.dict.DictDataService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "用户 App - 字典数据") +@RestController +@RequestMapping("/system/dict-data") +@Validated public class AppDictDataController { + + @Resource + private DictDataService dictDataService; + + @GetMapping("/type/{dictType}") + @Operation(summary = "根据字典类型查询字典数据信息") + public CommonResult> getDicts(@PathVariable String dictType) { + List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(dictType)); + return success(DictDataConvert.INSTANCE.convertList2(list)); + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java new file mode 100644 index 000000000..4ee511507 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.system.controller.app.dict.vo; + +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataBaseVO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@Schema(description = "用户 App - 字典数据信息 Response VO") +@Data +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class AppDictDataRespVO extends DictDataBaseVO { + + @Schema(description = "字典数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Long id; + +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java index 89e4d9e06..ee347cbf8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java @@ -3,11 +3,11 @@ package cn.iocoder.yudao.module.system.convert.dict; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.*; +import cn.iocoder.yudao.module.system.controller.app.dict.vo.AppDictDataRespVO; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; -import java.util.Collection; import java.util.List; @Mapper @@ -29,4 +29,5 @@ public interface DictDataConvert { DictDataRespDTO convert02(DictDataDO bean); + List convertList2(List list); } From f72a087007266c68de56e4e58882c7994686f93e Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 22 Sep 2023 15:42:59 +0800 Subject: [PATCH 08/42] =?UTF-8?q?=E5=88=86=E4=BD=A3:=20=E6=88=91=E7=9A=84?= =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../brokerage/AppBrokerageUserController.java | 30 ++++++++++++++----- .../user/AppBrokerageUserMySummaryRespVO.java | 4 +-- .../brokerage/BrokerageRecordMapper.java | 6 ++++ .../brokerage/BrokerageWithdrawMapper.java | 4 +++ .../brokerage/BrokerageRecordService.java | 12 ++++++++ .../brokerage/BrokerageRecordServiceImpl.java | 5 ++++ .../brokerage/BrokerageWithdrawService.java | 10 +++++++ .../BrokerageWithdrawServiceImpl.java | 5 ++++ 8 files changed, 67 insertions(+), 9 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index f0b894c9e..fbfa0f68d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -1,10 +1,15 @@ package cn.iocoder.yudao.module.trade.controller.app.brokerage; +import cn.hutool.core.date.LocalDateTimeUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -16,6 +21,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; import java.time.LocalDateTime; +import java.util.Optional; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @@ -30,6 +36,10 @@ import static java.util.Arrays.asList; public class AppBrokerageUserController { @Resource private BrokerageUserService brokerageUserService; + @Resource + private BrokerageRecordService brokerageRecordService; + @Resource + private BrokerageWithdrawService brokerageWithdrawService; // TODO 芋艿:临时 mock => @GetMapping("/get") @@ -50,18 +60,24 @@ public class AppBrokerageUserController { return success(brokerageUserService.bindBrokerageUser(getLoginUserId(), reqVO.getBindUserId(), false)); } - // TODO 芋艿:临时 mock => @GetMapping("/get-summary") @Operation(summary = "获得个人分销统计") @PreAuthenticated public CommonResult getBrokerageUserSummary() { + Long userId = getLoginUserId(); + LocalDateTime yesterday = LocalDateTime.now().minusDays(1); + LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); + LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); + AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() - .setYesterdayPrice(1) - .setBrokeragePrice(2) - .setFrozenPrice(3) - .setWithdrawPrice(4) - .setFirstBrokerageUserCount(166) - .setSecondBrokerageUserCount(233); + .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime)) + .setWithdrawPrice(brokerageWithdrawService.getSummaryPriceByUserIdAndStatus(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.getStatus())) + .setBrokeragePrice(0) + .setFrozenPrice(0) + .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1)) + .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2)); + Optional.ofNullable(brokerageUserService.getBrokerageUser(userId)) + .ifPresent(user -> respVO.setBrokeragePrice(user.getBrokeragePrice()).setFrozenPrice(user.getFrozenPrice())); return success(respVO); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java index cc9a03ebc..8a0c387c6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserMySummaryRespVO.java @@ -20,9 +20,9 @@ public class AppBrokerageUserMySummaryRespVO { private Integer frozenPrice; @Schema(description = "分销用户数量(一级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Integer firstBrokerageUserCount; + private Long firstBrokerageUserCount; @Schema(description = "分销用户数量(二级)", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") - private Integer secondBrokerageUserCount; + private Long secondBrokerageUserCount; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java index a3c177526..ba378c2fa 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java @@ -57,4 +57,10 @@ public interface BrokerageRecordMapper extends BaseMapperX { @Param("bizType") Integer bizType, @Param("status") Integer status); + @Select("SELECT SUM(price) FROM trade_brokerage_record WHERE user_id = #{userId} AND biz_type = #{bizType} " + + "AND create_time BETWEEN #{beginTime} AND #{endTime}") + Integer selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(@Param("userId") Long userId, + @Param("bizType") Integer bizType, + @Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java index 9c36238f9..293fdf51c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.Brok import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; /** * 佣金提现 Mapper @@ -34,4 +36,6 @@ public interface BrokerageWithdrawMapper extends BaseMapperX Date: Fri, 22 Sep 2023 18:06:11 +0800 Subject: [PATCH 09/42] =?UTF-8?q?=E5=88=86=E4=BD=A3:=20=E6=8F=90=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../brokerage/AppBrokerageUserController.java | 9 ++++---- .../AppBrokerageWithdrawCreateReqVO.java | 2 +- .../app/config/AppTradeConfigController.java | 23 +++++++++++-------- .../app/config/vo/AppTradeConfigRespVO.java | 3 +++ .../brokerage/BrokerageRecordService.java | 2 +- .../brokerage/BrokerageRecordServiceImpl.java | 4 ++-- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index fbfa0f68d..28f2251db 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; @@ -41,15 +42,15 @@ public class AppBrokerageUserController { @Resource private BrokerageWithdrawService brokerageWithdrawService; - // TODO 芋艿:临时 mock => @GetMapping("/get") @Operation(summary = "获得个人分销信息") @PreAuthenticated public CommonResult getBrokerageUser() { + Optional user = Optional.ofNullable(brokerageUserService.getBrokerageUser(getLoginUserId())); AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO() - .setBrokerageEnabled(true) - .setBrokeragePrice(2000) - .setFrozenPrice(3000); + .setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(false)) + .setBrokeragePrice(user.map(BrokerageUserDO::getBrokeragePrice).orElse(0)) + .setFrozenPrice(user.map(BrokerageUserDO::getFrozenPrice).orElse(0)); return success(respVO); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java index 1a3997db9..d49957d25 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawCreateReqVO.java @@ -43,7 +43,7 @@ public class AppBrokerageWithdrawCreateReqVO { @NotBlank(message = "持卡人姓名不能为空", groups = {Bank.class}) private String name; @Schema(description = "提现银行", example = "1") - @NotBlank(message = "提现银行不能为空", groups = {Bank.class}) + @NotNull(message = "提现银行不能为空", groups = {Bank.class}) private Integer bankName; @Schema(description = "开户地址", example = "海淀支行") private String bankAddress; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java index 65c879a02..cb6e3813a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.module.trade.controller.app.config; +import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.trade.controller.app.config.vo.AppTradeConfigRespVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; +import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -10,8 +13,9 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; + import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static java.util.Arrays.asList; @Tag(name = "用户 App - 交易配置") @RestController @@ -20,17 +24,18 @@ import static java.util.Arrays.asList; @Validated @Slf4j public class AppTradeConfigController { + @Resource + private TradeConfigService tradeConfigService; @GetMapping("/get") public CommonResult getTradeConfig() { - AppTradeConfigRespVO respVO = new AppTradeConfigRespVO(); - respVO.setBrokeragePosterUrls(asList( - "https://api.java.crmeb.net/crmebimage/product/2020/08/03/755bf516b1ca4b6db3bfeaa4dd5901cdh71kob20re.jpg", - "https://api.java.crmeb.net/crmebimage/maintain/2021/03/01/406d729b84ed4ec9a2171bfcf6fd0634ughzbz9kfi.jpg", - "https://api.java.crmeb.net/crmebimage/maintain/2021/03/01/efb1e4e7fe604fe1988b4213ce08cb11tdsyijtd2r.jpg" - )); - respVO.setBrokerageFrozenDays(10); - respVO.setBrokerageWithdrawMinPrice(100); + TradeConfigDO tradeConfig = ObjUtil.defaultIfNull(tradeConfigService.getTradeConfig(), new TradeConfigDO()); + + AppTradeConfigRespVO respVO = new AppTradeConfigRespVO() + .setBrokeragePosterUrls(tradeConfig.getBrokeragePostUrls()) + .setBrokerageFrozenDays(tradeConfig.getBrokerageFrozenDays()) + .setBrokerageWithdrawMinPrice(tradeConfig.getBrokerageWithdrawMinPrice()) + .setBrokerageWithdrawType(tradeConfig.getBrokerageWithdrawType()); return success(respVO); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java index 73abf7ab4..cd7de5287 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java @@ -18,4 +18,7 @@ public class AppTradeConfigRespVO { @Schema(description = "佣金提现最小金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") private Integer brokerageWithdrawMinPrice; + @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 2]") + private List brokerageWithdrawType; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java index 2ca251cba..2fe9ca581 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java @@ -52,7 +52,7 @@ public interface BrokerageRecordService { * @param brokeragePrice 佣金 * @param title 标题 */ - void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, int brokeragePrice, String title); + void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title); /** * 取消佣金:将佣金记录,状态修改为已失效 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java index a5c50d5f0..3d3cf394a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java @@ -229,12 +229,12 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { @Override @Transactional(rollbackFor = Exception.class) - public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, int brokeragePrice, String title) { + public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title) { // 校验佣金余额 BrokerageUserDO user = brokerageUserService.getBrokerageUser(userId); int balance = Optional.of(user) .map(BrokerageUserDO::getBrokeragePrice).orElse(0); - if (balance < brokeragePrice) { + if (balance + brokeragePrice < 0) { throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance)); } From 637ae8ce1d7cb7c0570aeab827fb508937273daf Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 22 Sep 2023 18:35:43 +0800 Subject: [PATCH 10/42] =?UTF-8?q?=E5=88=86=E4=BD=A3:=20=E6=8F=90=E7=8E=B0?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BrokerageWithdrawStatusEnum.java | 1 + .../AppBrokerageWithdrawController.java | 25 ++++++++++++------- .../brokerage/BrokerageWithdrawConvert.java | 11 ++++++++ .../module/system/api/dict/DictDataApi.java | 19 ++++++++++++++ .../system/api/dict/DictDataApiImpl.java | 17 +++++++++++++ .../app/dict/AppDictDataController.java | 2 +- .../system/convert/dict/DictDataConvert.java | 4 ++- 7 files changed, 68 insertions(+), 11 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java index a80aad02a..daf0da3aa 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java @@ -22,6 +22,7 @@ public enum BrokerageWithdrawStatusEnum implements IntArrayValuable { WITHDRAW_FAIL(21, "提现失败"), ; + public static final String DICT_TYPE = "BROKERAGE_WITHDRAW_STATUS"; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageWithdrawStatusEnum::getStatus).toArray(); /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java index f65aee42c..ba1b06a1e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java @@ -3,8 +3,13 @@ package cn.iocoder.yudao.module.trade.controller.app.brokerage; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; +import cn.iocoder.yudao.module.system.api.dict.DictDataApi; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageWithdrawConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -14,11 +19,10 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.time.LocalDateTime; +import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; -import static java.util.Arrays.asList; @Tag(name = "用户 APP - 分销提现") @RestController @@ -29,16 +33,19 @@ public class AppBrokerageWithdrawController { @Resource private BrokerageWithdrawService brokerageWithdrawService; - // TODO 芋艿:临时 mock => + @Resource + private DictDataApi dictDataApi; + @GetMapping("/page") @Operation(summary = "获得分销提现分页") @PreAuthenticated - public CommonResult> getBrokerageWithdrawPage() { - AppBrokerageWithdrawRespVO vo1 = new AppBrokerageWithdrawRespVO() - .setId(1L).setStatus(10).setPrice(10).setStatusName("审批通过").setCreateTime(LocalDateTime.now()); - AppBrokerageWithdrawRespVO vo2 = new AppBrokerageWithdrawRespVO() - .setId(2L).setStatus(0).setPrice(20).setStatusName("审批中").setCreateTime(LocalDateTime.now()); - return success(new PageResult<>(asList(vo1, vo2), 10L)); + public CommonResult> getBrokerageWithdrawPage(BrokerageWithdrawPageReqVO pageReqVO) { + // 分页查询 + pageReqVO.setUserId(getLoginUserId()); + PageResult pageResult = brokerageWithdrawService.getBrokerageWithdrawPage(pageReqVO); + // 拼接信息 + Map statusNameMap = dictDataApi.getDictDataLabelMap(BrokerageWithdrawStatusEnum.DICT_TYPE); + return success(BrokerageWithdrawConvert.INSTANCE.convertPage02(pageResult, statusNameMap)); } @PostMapping("/create") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java index bbc168aee..142315ed1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java @@ -1,9 +1,11 @@ package cn.iocoder.yudao.module.trade.convert.brokerage; +import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -38,4 +40,13 @@ public interface BrokerageWithdrawConvert { return result; } + PageResult convertPage02(PageResult pageResult); + + default PageResult convertPage02(PageResult pageResult, Map statusNameMap) { + PageResult result = convertPage02(pageResult); + for (AppBrokerageWithdrawRespVO vo : result.getList()) { + vo.setStatusName(MapUtil.getStr(statusNameMap, String.valueOf(vo.getStatus()), "")); + } + return result; + } } diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java index 3bc28c89e..34c33c568 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.system.api.dict; import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; import java.util.Collection; +import java.util.List; +import java.util.Map; /** * 字典数据 API 接口 @@ -30,6 +32,23 @@ public interface DictDataApi { */ DictDataRespDTO getDictData(String type, String value); + /** + * 获得指定类型的字典数据,从缓存中 + * + * @param type 字典类型 + * @return 字典数据 + */ + List getDictDataList(String type); + + /** + * 获得指定类型的字典数据 标签字典,从缓存中 + * key:value, value: label + * + * @param type 字典类型 + * @return 字典数据 + */ + Map getDictDataLabelMap(String type); + /** * 解析获得指定的字典数据,从缓存中 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java index e88771fa7..cf16c07b7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.api.dict; import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; +import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import cn.iocoder.yudao.module.system.service.dict.DictDataService; @@ -8,6 +9,10 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Collection; +import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; /** * 字典数据 API 实现类 @@ -31,6 +36,18 @@ public class DictDataApiImpl implements DictDataApi { return DictDataConvert.INSTANCE.convert02(dictData); } + @Override + public List getDictDataList(String type) { + List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(type)); + return DictDataConvert.INSTANCE.convertList04(list); + } + + @Override + public Map getDictDataLabelMap(String type) { + List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(type)); + return convertMap(list, DictDataDO::getValue, DictDataDO::getLabel); + } + @Override public DictDataRespDTO parseDictData(String dictType, String label) { DictDataDO dictData = dictDataService.parseDictData(dictType, label); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java index d0b661a4a..0b5909f35 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java @@ -32,6 +32,6 @@ public class AppDictDataController { @Operation(summary = "根据字典类型查询字典数据信息") public CommonResult> getDicts(@PathVariable String dictType) { List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(dictType)); - return success(DictDataConvert.INSTANCE.convertList2(list)); + return success(DictDataConvert.INSTANCE.convertList03(list)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java index ee347cbf8..1c4895110 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/dict/DictDataConvert.java @@ -29,5 +29,7 @@ public interface DictDataConvert { DictDataRespDTO convert02(DictDataDO bean); - List convertList2(List list); + List convertList03(List list); + + List convertList04(List list); } From eddc897cd8253b0824abbacd75657a9d19e147b3 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 22 Sep 2023 18:48:16 +0800 Subject: [PATCH 11/42] =?UTF-8?q?=E5=88=86=E4=BD=A3:=20=E6=8F=90=E7=8E=B0?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppBrokerageWithdrawController.java | 8 +++---- .../AppBrokerageWithdrawPageReqVO.java | 22 +++++++++++++++++++ .../brokerage/BrokerageWithdrawConvert.java | 4 ++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawPageReqVO.java diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java index ba1b06a1e..434022f6a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java @@ -4,8 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.system.api.dict.DictDataApi; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageWithdrawConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; @@ -39,10 +39,10 @@ public class AppBrokerageWithdrawController { @GetMapping("/page") @Operation(summary = "获得分销提现分页") @PreAuthenticated - public CommonResult> getBrokerageWithdrawPage(BrokerageWithdrawPageReqVO pageReqVO) { + public CommonResult> getBrokerageWithdrawPage(AppBrokerageWithdrawPageReqVO pageReqVO) { // 分页查询 - pageReqVO.setUserId(getLoginUserId()); - PageResult pageResult = brokerageWithdrawService.getBrokerageWithdrawPage(pageReqVO); + PageResult pageResult = brokerageWithdrawService.getBrokerageWithdrawPage( + BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId())); // 拼接信息 Map statusNameMap = dictDataApi.getDictDataLabelMap(BrokerageWithdrawStatusEnum.DICT_TYPE); return success(BrokerageWithdrawConvert.INSTANCE.convertPage02(pageResult, statusNameMap)); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawPageReqVO.java new file mode 100644 index 000000000..b1757d43e --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/withdraw/AppBrokerageWithdrawPageReqVO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawTypeEnum; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "应用 App - 分销提现分页 Request VO") +@Data +public class AppBrokerageWithdrawPageReqVO extends PageParam { + + @Schema(description = "类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @InEnum(value = BrokerageWithdrawTypeEnum.class, message = "类型必须是 {value}") + private Integer type; + + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + @InEnum(value = BrokerageWithdrawStatusEnum.class, message = "状态必须是 {value}") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java index 142315ed1..82932bbe5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java @@ -3,8 +3,10 @@ package cn.iocoder.yudao.module.trade.convert.brokerage; import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; import org.mapstruct.Mapper; @@ -49,4 +51,6 @@ public interface BrokerageWithdrawConvert { } return result; } + + BrokerageWithdrawPageReqVO convert(AppBrokerageWithdrawPageReqVO pageReqVO, Long userId); } From 7a8a440eb6aeac2d543a51626b85c4f1f14d3429 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 22 Sep 2023 18:49:26 +0800 Subject: [PATCH 12/42] =?UTF-8?q?=E5=88=86=E4=BD=A3:=20=E4=BD=A3=E9=87=91?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppBrokerageRecordController.java | 18 ++++++++---------- .../brokerage/BrokerageRecordConvert.java | 7 +++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java index 62f592351..0b7d01ed8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java @@ -6,6 +6,9 @@ import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageProductPriceRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -18,11 +21,9 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.validation.Valid; -import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; -import static java.util.Arrays.asList; @Tag(name = "用户 APP - 分销用户") @RestController @@ -32,19 +33,16 @@ import static java.util.Arrays.asList; public class AppBrokerageRecordController { @Resource private BrokerageUserService brokerageUserService; + @Resource + private BrokerageRecordService brokerageRecordService; - // TODO 芋艿:临时 mock => @GetMapping("/page") @Operation(summary = "获得分销记录分页") @PreAuthenticated public CommonResult> getBrokerageRecordPage(@Valid AppBrokerageRecordPageReqVO pageReqVO) { - AppBrokerageRecordRespVO vo1 = new AppBrokerageRecordRespVO() - .setId(1L).setPrice(10).setTitle("收到钱").setCreateTime(LocalDateTime.now()) - .setFinishTime(LocalDateTime.now()); - AppBrokerageRecordRespVO vo2 = new AppBrokerageRecordRespVO() - .setId(2L).setPrice(-20).setTitle("提现钱").setCreateTime(LocalDateTime.now()) - .setFinishTime(LocalDateTime.now()); - return success(new PageResult<>(asList(vo1, vo2), 10L)); + PageResult pageResult = brokerageRecordService.getBrokerageRecordPage( + BrokerageRecordConvert.INSTANCE.convert(pageReqVO, getLoginUserId())); + return success(BrokerageRecordConvert.INSTANCE.convertPage02(pageResult)); } @GetMapping("/get-product-brokerage-price") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java index e85ad24d3..d81d96c3c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java @@ -5,7 +5,10 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; @@ -61,4 +64,8 @@ public interface BrokerageRecordConvert { } return result; } + + BrokerageRecordPageReqVO convert(AppBrokerageRecordPageReqVO pageReqVO, Long userId); + + PageResult convertPage02(PageResult pageResult); } From 910ffa7a5ac82cf6ba2b7e1f1219e95e69aaf95f Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Fri, 22 Sep 2023 19:04:59 +0800 Subject: [PATCH 13/42] =?UTF-8?q?=E9=92=B1=E5=8C=85=E5=85=85=E5=80=BC?= =?UTF-8?q?=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/pay_wallet.sql | 2 + .../module/pay/enums/ErrorCodeConstants.java | 8 +- .../wallet/PayWalletRechargeController.java | 48 ++++++++ .../AppPayWalletRechargeController.java | 3 - .../dal/dataobject/wallet/PayWalletDO.java | 5 + .../wallet/PayWalletRechargeDO.java | 8 ++ .../pay/dal/mysql/wallet/PayWalletMapper.java | 46 ++++++- .../mysql/wallet/PayWalletRechargeMapper.java | 5 + .../wallet/PayWalletRechargeService.java | 13 ++ .../wallet/PayWalletRechargeServiceImpl.java | 116 ++++++++++++++++++ .../pay/service/wallet/PayWalletService.java | 21 +++- .../service/wallet/PayWalletServiceImpl.java | 40 +++++- 12 files changed, 300 insertions(+), 15 deletions(-) create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/wallet/PayWalletRechargeController.java diff --git a/sql/mysql/pay_wallet.sql b/sql/mysql/pay_wallet.sql index e3d92239c..840da078b 100644 --- a/sql/mysql/pay_wallet.sql +++ b/sql/mysql/pay_wallet.sql @@ -10,6 +10,7 @@ CREATE TABLE `pay_wallet` `balance` int NOT NULL DEFAULT 0 COMMENT '余额,单位分', `total_expense` int NOT NULL DEFAULT 0 COMMENT '累计支出,单位分', `total_recharge` int NOT NULL DEFAULT 0 COMMENT '累计充值,单位分', + `freeze_price` int NOT NULL DEFAULT 0 COMMENT '冻结金额,单位分', `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', @@ -62,6 +63,7 @@ CREATE TABLE `pay_wallet_recharge` `refund_pay_price` int NOT NULL DEFAULT 0 COMMENT '退款支付金额', `refund_bonus_price` int NOT NULL DEFAULT 0 COMMENT '退款钱包赠送金额', `refund_time` datetime NULL COMMENT '退款时间', + `refund_status` int NOT NULL DEFAULT 0 COMMENT '退款状态', `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java index 87b046a63..815c18fb9 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java @@ -46,6 +46,7 @@ public interface ErrorCodeConstants { ErrorCode WALLET_TRANSACTION_NOT_FOUND = new ErrorCode(1007007002, "未找到对应的钱包交易"); ErrorCode WALLET_REFUND_AMOUNT_ERROR = new ErrorCode(1007007003, "钱包退款金额不对"); ErrorCode WALLET_REFUND_EXIST = new ErrorCode(1007007004, "已经存在钱包退款"); + ErrorCode WALLET_FREEZE_PRICE_NOT_ENOUGH = new ErrorCode(1007007005, "钱包冻结余额不足"); // TODO @jason:把钱包充值,单独搞个错误码段哈; @@ -54,7 +55,12 @@ public interface ErrorCodeConstants { ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR = new ErrorCode(1007007007, "钱包充值更新支付状态失败,支付单编号不匹配"); ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_STATUS_NOT_SUCCESS = new ErrorCode(1007007008, "钱包充值更新支付状态失败,支付单状态不是【支付成功】状态"); ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_PRICE_NOT_MATCH = new ErrorCode(1007007009, "钱包充值更新支付状态失败,支付单金额不匹配"); - + ErrorCode WALLET_RECHARGE_REFUND_FAIL_NOT_PAID = new ErrorCode(1007900010, "钱包发起退款失败,钱包充值订单未支付"); + ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUNDED = new ErrorCode(1007900011, "钱包发起退款失败,钱包充值订单已退款"); + ErrorCode WALLET_RECHARGE_REFUND_BALANCE_NOT_ENOUGH = new ErrorCode(1007900012, "钱包发起退款失败,钱包余额不足"); + ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_ORDER_ID_ERROR = new ErrorCode(1007900013, "钱包退款更新失败,钱包退款单编号不匹配"); + ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_NOT_FOUND = new ErrorCode(1007900014, "钱包退款更新失败,退款订单不存在"); + ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_PRICE_NOT_MATCH = new ErrorCode(1007900015, "钱包退款更新失败,退款单金额不匹配"); // ========== 示例订单 1007900000 ========== ErrorCode DEMO_ORDER_NOT_FOUND = new ErrorCode(1007900000, "示例订单不存在"); ErrorCode DEMO_ORDER_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1007900001, "示例订单更新支付状态失败,订单不是【未支付】状态"); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/wallet/PayWalletRechargeController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/wallet/PayWalletRechargeController.java new file mode 100644 index 000000000..feaa13447 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/wallet/PayWalletRechargeController.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.module.pay.controller.admin.wallet; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.module.pay.api.notify.dto.PayRefundNotifyReqDTO; +import cn.iocoder.yudao.module.pay.service.wallet.PayWalletRechargeService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.annotation.security.PermitAll; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; + +@Tag(name = "管理后台 - 钱包充值") +@RestController +@RequestMapping("/pay/wallet-recharge") +@Validated +@Slf4j +public class PayWalletRechargeController { + + @Resource + private PayWalletRechargeService walletRechargeService; + + + @GetMapping("/refund") + @Operation(summary = "发起钱包充值退款") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + public CommonResult refundWalletRecharge(@RequestParam("id") Long id) { + walletRechargeService.refundWalletRecharge(id,getClientIP()); + return success(true); + } + + @PostMapping("/update-refunded") + @Operation(summary = "更新钱包充值为已退款") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob + @PermitAll // 无需登录, 内部校验实现 + @OperateLog(enable = false) // 禁用操作日志,因为没有操作人 + public CommonResult updateWalletRechargeRefunded(@RequestBody PayRefundNotifyReqDTO notifyReqDTO) { + walletRechargeService.updateWalletRechargeRefunded( + Long.valueOf(notifyReqDTO.getMerchantOrderId()), notifyReqDTO.getPayRefundId()); + return success(true); + } +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java index 6ce0cff3f..d0bb0cfce 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletRechargeController.java @@ -53,7 +53,4 @@ public class AppPayWalletRechargeController { notifyReqDTO.getPayOrderId()); return success(true); } - - // TODO @jason:管理后台,是不是可以搞个发起退款; - } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java index 4536ae635..a3c54c969 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletDO.java @@ -42,6 +42,11 @@ public class PayWalletDO extends BaseDO { */ private Integer balance; + /** + * 冻结金额,单位分 + */ + private Integer freezePrice; + /** * 累计支出,单位分 */ diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java index dc56e5614..728d6eaab 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletRechargeDO.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pay.dal.dataobject.wallet; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO; import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO; +import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -99,4 +100,11 @@ public class PayWalletRechargeDO extends BaseDO { */ private LocalDateTime refundTime; + /** + * 退款状态 + * + * 枚举 {@link PayRefundStatusEnum} + */ + private Integer refundStatus; + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java index 47c4c2009..11fc6edbb 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java @@ -56,7 +56,51 @@ public interface PayWalletMapper extends BaseMapperX { .eq(PayWalletDO::getId, id); return update(null, lambdaUpdateWrapper); } - + + /** + * 冻结钱包部分余额 + * @param id 钱包 id + * @param price 冻结金额 + */ + default int freezePrice(Long id, Integer price){ + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" balance = balance - " + price + + ", freeze_price = freeze_price + " + price) + .eq(PayWalletDO::getId, id) + .ge(PayWalletDO::getBalance, price); // cas 逻辑 + return update(null, lambdaUpdateWrapper); + } + + /** + * 解冻钱包余额 + * @param id 钱包 id + * @param price 解冻金额 + */ + default int unFreezePrice(Long id, Integer price){ + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" balance = balance + " + price + + ", freeze_price = freeze_price - " + price) + .eq(PayWalletDO::getId, id) + .ge(PayWalletDO::getFreezePrice, price); // cas 逻辑 + return update(null, lambdaUpdateWrapper); + } + + /** + * 当充值退款时, 更新钱包 + * @param id 钱包 id + * @param price 退款金额 + */ + default int updateWhenRechargeRefund(Long id, Integer price){ + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" freeze_price = freeze_price - " + price + + ", total_recharge = total_recharge - " + price) + .eq(PayWalletDO::getId, id) + .ge(PayWalletDO::getFreezePrice, price) + .ge(PayWalletDO::getTotalRecharge, price);// cas 逻辑 + return update(null, lambdaUpdateWrapper); + } + + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java index 506d978dc..65994b2f3 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java @@ -13,6 +13,11 @@ public interface PayWalletRechargeMapper extends BaseMapperX() + .eq(PayWalletRechargeDO::getId, id).eq(PayWalletRechargeDO::getRefundStatus, whereRefundStatus)); + } + } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java index 1a167474b..908a77f78 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java @@ -29,4 +29,17 @@ public interface PayWalletRechargeService { */ void updateWalletRechargerPaid(Long id, Long payOrderId); + /** + * 发起钱包充值退款 + * @param id 钱包充值编号 + * @param userIp 用户 ip 地址 + */ + void refundWalletRecharge(Long id, String userIp); + + /** + * 更新钱包充值记录为已退款 + * @param id 钱包充值 id + * @param payRefundId 退款单id + */ + void updateWalletRechargeRefunded(Long id, Long payRefundId); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java index 0259627c7..ed9b77c1d 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java @@ -1,15 +1,21 @@ package cn.iocoder.yudao.module.pay.service.wallet; +import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.framework.pay.core.enums.refund.PayRefundStatusRespEnum; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; +import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO; import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO; import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert; import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO; +import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO; import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletRechargeMapper; import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum; +import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum; import cn.iocoder.yudao.module.pay.service.order.PayOrderService; +import cn.iocoder.yudao.module.pay.service.refund.PayRefundService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -24,6 +30,7 @@ import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.add import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum.*; /** * 钱包充值 Service 实现类 @@ -47,6 +54,8 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { private PayWalletService payWalletService; @Resource private PayOrderService payOrderService; + @Resource + private PayRefundService payRefundService; @Override @Transactional(rollbackFor = Exception.class) @@ -98,6 +107,113 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService { PayWalletBizTypeEnum.RECHARGE, walletRecharge.getTotalPrice()); } + @Override + @Transactional(rollbackFor = Exception.class) + public void refundWalletRecharge(Long id, String userIp) { + // 1.1 获取钱包充值记录 + PayWalletRechargeDO walletRecharge = walletRechargeMapper.selectById(id); + if (walletRecharge == null) { + log.error("[refundWalletRecharge][钱包充值记录不存在,钱包充值记录 id({})]", id); + throw exception(WALLET_RECHARGE_NOT_FOUND); + } + // 1.2 校验钱包充值是否可以发起退款 + PayWalletDO wallet = validateWalletRechargeCanRefund(walletRecharge); + // 2 冻结退款的余额, 暂时只处理赠送的余额也全部退回 + payWalletService.freezePrice(wallet.getId(), walletRecharge.getTotalPrice()); + // 3 创建退款单 + String walletRechargeId = String.valueOf(id); + String refundId = walletRechargeId + "-refund"; + Long payRefundId = payRefundService.createPayRefund(new PayRefundCreateReqDTO() + .setAppId(WALLET_PAY_APP_ID).setUserIp(userIp) + .setMerchantOrderId(walletRechargeId) + .setMerchantRefundId(refundId) + .setReason("想退钱").setPrice(walletRecharge.getPayPrice())); + // 4 更新充值记录退款单号 + walletRechargeMapper.updateById(new PayWalletRechargeDO().setPayRefundId(payRefundId) + .setRefundStatus(WAITING.getStatus()).setId(walletRecharge.getId())); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateWalletRechargeRefunded(Long id, Long payRefundId) { + // 1.1 获取钱包充值记录 + PayWalletRechargeDO walletRecharge = walletRechargeMapper.selectById(id); + if (walletRecharge == null) { + log.error("[updateWalletRechargerPaid][钱包充值记录不存在,钱包充值记录 id({})]", id); + throw exception(WALLET_RECHARGE_NOT_FOUND); + } + // 1.2 校验钱包充值是否可以更新已退款 + PayRefundDO payRefund = validateWalletRechargeCanRefunded(walletRecharge, payRefundId); + + PayWalletRechargeDO updateObj = new PayWalletRechargeDO().setId(id); + // 退款成功 + if (PayRefundStatusEnum.isSuccess(payRefund.getStatus())) { + // 2.1 更新钱包余额 + payWalletService.reduceWalletBalance(walletRecharge.getWalletId(), id, + PayWalletBizTypeEnum.RECHARGE_REFUND, walletRecharge.getTotalPrice()); + + updateObj.setRefundStatus(SUCCESS.getStatus()).setRefundTime(payRefund.getSuccessTime()) + .setRefundTotalPrice(walletRecharge.getTotalPrice()).setRefundPayPrice(walletRecharge.getPayPrice()) + .setRefundBonusPrice(walletRecharge.getBonusPrice()); + } + // 退款失败 + if (PayRefundStatusRespEnum.isFailure(payRefund.getStatus())) { + // 2.2 解冻余额 + payWalletService.unFreezePrice(walletRecharge.getWalletId(), walletRecharge.getTotalPrice()); + + updateObj.setRefundStatus(FAILURE.getStatus()); + } + // 3. 更新钱包充值的退款字段 + walletRechargeMapper.updateByIdAndRefunded(id, WAITING.getStatus(), updateObj); + } + + private PayRefundDO validateWalletRechargeCanRefunded(PayWalletRechargeDO walletRecharge, Long payRefundId) { + // 1. 校验退款订单匹配 + if (notEqual(walletRecharge.getPayRefundId(), payRefundId)) { + log.error("[validateWalletRechargeCanRefunded][钱包充值({}) 退款单不匹配({}),请进行处理!钱包充值的数据是:{}]", + walletRecharge.getId(), payRefundId, toJsonString(walletRecharge)); + throw exception(WALLET_RECHARGE_REFUND_FAIL_REFUND_ORDER_ID_ERROR); + } + + // 2.1 校验退款订单 + PayRefundDO payRefund = payRefundService.getRefund(payRefundId); + if (payRefund == null) { + log.error("[validateWalletRechargeCanRefunded][payRefund({})不存在]", payRefundId); + throw exception(WALLET_RECHARGE_REFUND_FAIL_REFUND_NOT_FOUND); + } + // 2.2 校验退款金额一致 + if (notEqual(payRefund.getRefundPrice(), walletRecharge.getPayPrice())) { + log.error("[validateWalletRechargeCanRefunded][钱包({}) payRefund({}) 退款金额不匹配,请进行处理!钱包数据是:{},payRefund 数据是:{}]", + walletRecharge.getId(), payRefundId, toJsonString(walletRecharge), toJsonString(payRefund)); + throw exception(WALLET_RECHARGE_REFUND_FAIL_REFUND_PRICE_NOT_MATCH); + } + // 2.3 校验退款订单商户订单是否匹配 + if (notEqual(payRefund.getMerchantOrderId(), walletRecharge.getId().toString())) { + log.error("[validateWalletRechargeCanRefunded][钱包({}) 退款单不匹配({}),请进行处理!payRefund 数据是:{}]", + walletRecharge.getId(), payRefundId, toJsonString(payRefund)); + throw exception(WALLET_RECHARGE_REFUND_FAIL_REFUND_ORDER_ID_ERROR); + } + return payRefund; + } + + private PayWalletDO validateWalletRechargeCanRefund(PayWalletRechargeDO walletRecharge) { + // 校验充值订单是否支付 + if (!walletRecharge.getPayStatus()) { + throw exception(WALLET_RECHARGE_REFUND_FAIL_NOT_PAID); + } + // 校验充值订单是否已退款 + if (walletRecharge.getPayRefundId() != null) { + throw exception(WALLET_RECHARGE_REFUND_FAIL_REFUNDED); + } + // 校验钱包余额是否足够 + PayWalletDO wallet = payWalletService.getWallet(walletRecharge.getWalletId()); + Assert.notNull(wallet, "用户钱包({}) 不存在", wallet.getId()); + if (wallet.getBalance() < walletRecharge.getTotalPrice()) { + throw exception(WALLET_RECHARGE_REFUND_BALANCE_NOT_ENOUGH); + } + return wallet; + } + private PayOrderDO validateWalletRechargerCanPaid(PayWalletRechargeDO walletRecharge, Long payOrderId) { // 1.1 校验充值记录的支付状态 if (walletRecharge.getPayStatus()) { diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java index ed8dcee9f..1703d8e1b 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java @@ -50,15 +50,14 @@ public interface PayWalletService { /** * 扣减钱包余额 * - * @param userId 用户 id - * @param userType 用户类型 + * @param walletId 钱包 id * @param bizId 业务关联 id * @param bizType 业务关联分类 * @param price 扣减金额 * @return 钱包流水 */ - PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType, - Long bizId, PayWalletBizTypeEnum bizType, Integer price); + PayWalletTransactionDO reduceWalletBalance(Long walletId, Long bizId, + PayWalletBizTypeEnum bizType, Integer price); /** * 增加钱包余额 @@ -72,4 +71,18 @@ public interface PayWalletService { PayWalletTransactionDO addWalletBalance(Long walletId, String bizId, PayWalletBizTypeEnum bizType, Integer price); + /** + * 冻结钱包部分余额 + * + * @param id 钱包编号 + * @param price 冻结金额 + */ + void freezePrice(Long id, Integer price); + + /** + * 解冻钱包余额 + * @param id 钱包编号 + * @param price 解冻金额 + */ + void unFreezePrice(Long id, Integer price); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index 542e567ed..9a83ffb83 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -68,8 +68,9 @@ public class PayWalletServiceImpl implements PayWalletService { if (orderExtension == null) { throw exception(PAY_ORDER_EXTENSION_NOT_FOUND); } + PayWalletDO wallet = getOrCreateWallet(userId, userType); // 2. 扣减余额 - return reduceWalletBalance(userId, userType, orderExtension.getOrderId(), PAYMENT, price); + return reduceWalletBalance(wallet.getId(), orderExtension.getOrderId(), PAYMENT, price); } @Override @@ -116,10 +117,14 @@ public class PayWalletServiceImpl implements PayWalletService { } @Override - public PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType, - Long bizId, PayWalletBizTypeEnum bizType, Integer price) { + public PayWalletTransactionDO reduceWalletBalance(Long walletId, Long bizId, + PayWalletBizTypeEnum bizType, Integer price) { // 1. 获取钱包 - PayWalletDO payWallet = getOrCreateWallet(userId, userType); + PayWalletDO payWallet = getWallet(walletId); + if (payWallet == null) { + log.error("[reduceWalletBalance],用户钱包({})不存在.", walletId); + throw exception(WALLET_NOT_FOUND); + } // 2.1 扣除余额 int updateCounts = 0 ; @@ -129,9 +134,13 @@ public class PayWalletServiceImpl implements PayWalletService { break; } case RECHARGE_REFUND: { - // TODO + updateCounts = walletMapper.updateWhenRechargeRefund(payWallet.getId(), price); break; } + default: { + // TODO 其它类型待实现 + throw new UnsupportedOperationException("待实现"); + } } if (updateCounts == 0) { throw exception(WALLET_BALANCE_NOT_ENOUGH); @@ -163,7 +172,10 @@ public class PayWalletServiceImpl implements PayWalletService { walletMapper.updateWhenRecharge(payWallet.getId(), price); break; } - // TODO 其它类型;这里可以先跑异常;避免有业务搞错; + default: { + // TODO 其它类型待实现 + throw new UnsupportedOperationException("待实现"); + } } // 2. 生成钱包流水 @@ -173,4 +185,20 @@ public class PayWalletServiceImpl implements PayWalletService { return walletTransactionService.createWalletTransaction(transactionCreateReqBO); } + @Override + public void freezePrice(Long id, Integer price) { + int updateCounts = walletMapper.freezePrice(id, price); + if (updateCounts == 0) { + throw exception(WALLET_BALANCE_NOT_ENOUGH); + } + } + + @Override + public void unFreezePrice(Long id, Integer price) { + int updateCounts = walletMapper.unFreezePrice(id, price); + if (updateCounts == 0) { + throw exception(WALLET_FREEZE_PRICE_NOT_ENOUGH); + } + } + } From 972b01c001e95edd83e9649c6e37a76ce2252154 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 22 Sep 2023 20:55:05 +0800 Subject: [PATCH 14/42] =?UTF-8?q?=E5=88=86=E4=BD=A3:=20=E4=BD=A3=E9=87=91?= =?UTF-8?q?=E6=8E=92=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../brokerage/AppBrokerageUserController.java | 32 +++++++++---------- .../brokerage/BrokerageRecordConvert.java | 11 +++++++ .../brokerage/BrokerageRecordMapper.java | 12 +++++++ .../brokerage/BrokerageRecordService.java | 18 +++++++++++ .../brokerage/BrokerageRecordServiceImpl.java | 25 +++++++++++++++ 5 files changed, 81 insertions(+), 17 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 28f2251db..672bff974 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -4,7 +4,10 @@ import cn.hutool.core.date.LocalDateTimeUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*; +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; @@ -22,9 +25,11 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; import java.time.LocalDateTime; +import java.util.Map; import java.util.Optional; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static java.util.Arrays.asList; @@ -42,6 +47,9 @@ public class AppBrokerageUserController { @Resource private BrokerageWithdrawService brokerageWithdrawService; + @Resource + private MemberUserApi memberUserApi; + @GetMapping("/get") @Operation(summary = "获得个人分销信息") @PreAuthenticated @@ -102,24 +110,15 @@ public class AppBrokerageUserController { return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); } - // TODO 芋艿:临时 mock => @GetMapping("/rank-page-by-price") @Operation(summary = "获得分销用户排行分页(基于佣金)") @PreAuthenticated public CommonResult> getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) { - AppBrokerageUserRankByPriceRespVO vo1 = new AppBrokerageUserRankByPriceRespVO() - .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(10); - AppBrokerageUserRankByPriceRespVO vo2 = new AppBrokerageUserRankByPriceRespVO() - .setId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(6); - AppBrokerageUserRankByPriceRespVO vo3 = new AppBrokerageUserRankByPriceRespVO() - .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(4); - AppBrokerageUserRankByPriceRespVO vo4 = new AppBrokerageUserRankByPriceRespVO() - .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(4); - return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); + // 分页查询 + PageResult pageResult = brokerageRecordService.getBrokerageUserChildSummaryPageByPrice(pageReqVO); + // 拼接数据 + Map userMap = memberUserApi.getUserMap(convertSet(pageResult.getList(), AppBrokerageUserRankByPriceRespVO::getId)); + return success(BrokerageRecordConvert.INSTANCE.convertPage03(pageResult, userMap)); } // TODO 芋艿:临时 mock => @@ -139,13 +138,12 @@ public class AppBrokerageUserController { return success(new PageResult<>(asList(vo1, vo2), 10L)); } - // TODO 芋艿:临时 mock => @GetMapping("/get-rank-by-price") @Operation(summary = "获得分销用户排行(基于佣金)") @Parameter(name = "times", description = "时间段", required = true) - public CommonResult bindBrokerageUser( + public CommonResult getRankByPrice( @RequestParam("times") @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) LocalDateTime[] times) { - return success(1); + return success(brokerageRecordService.getUserRankByPrice(getLoginUserId(), times)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java index d81d96c3c..175db060c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java @@ -9,11 +9,13 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.Broker import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; import org.mapstruct.factory.Mappers; import java.time.LocalDateTime; @@ -68,4 +70,13 @@ public interface BrokerageRecordConvert { BrokerageRecordPageReqVO convert(AppBrokerageRecordPageReqVO pageReqVO, Long userId); PageResult convertPage02(PageResult pageResult); + + default PageResult convertPage03(PageResult pageResult, Map userMap) { + for (AppBrokerageUserRankByPriceRespVO vo : pageResult.getList()) { + copyTo(userMap.get(vo.getId()), vo); + } + return pageResult; + } + + void copyTo(MemberUserRespDTO from, @MappingTarget AppBrokerageUserRankByPriceRespVO to); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java index ba378c2fa..1393472d3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java @@ -4,9 +4,11 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; @@ -63,4 +65,14 @@ public interface BrokerageRecordMapper extends BaseMapperX { @Param("bizType") Integer bizType, @Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + + @Select("SELECT user_id AS id, SUM(price) AS brokeragePrice FROM trade_brokerage_record " + + "WHERE biz_type = #{bizType} AND status = #{status} AND create_time BETWEEN #{beginTime} AND #{endTime} " + + "GROUP BY user_id " + + "ORDER BY SUM(price) DESC") + IPage selectSummaryPricePageGroupByUserId(IPage page, + @Param("bizType") Integer bizType, + @Param("status") Integer status, + @Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java index 2fe9ca581..d58bec6e1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.trade.service.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; @@ -90,4 +92,20 @@ public interface BrokerageRecordService { * @return 用户佣金合计 */ Integer getSummaryPriceByUserId(Long userId, Integer bizType, LocalDateTime beginTime, LocalDateTime endTime); + + /** + * 获得用户佣金排行分页列表(基于佣金总数) + * @param pageReqVO 分页查询 + * @return 排行榜分页 + */ + PageResult getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO); + + /** + * 获取用户的排名(基于佣金总数) + * + * @param userId 用户编号 + * @param times 时间范围 + * @return 用户的排名 + */ + Integer getUserRankByPrice(Long userId, LocalDateTime[] times); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java index 3d3cf394a..b63097661 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java @@ -2,13 +2,17 @@ package cn.iocoder.yudao.module.trade.service.brokerage; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.math.Money; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; +import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; @@ -19,6 +23,7 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; +import com.baomidou.mybatisplus.core.metadata.IPage; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -227,6 +232,26 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { return brokerageRecordMapper.selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(userId, bizType, beginTime, endTime); } + @Override + public PageResult getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) { + IPage pageResult = brokerageRecordMapper.selectSummaryPricePageGroupByUserId(MyBatisUtils.buildPage(pageReqVO), + BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus(), + ArrayUtil.get(pageReqVO.getTimes(), 0), ArrayUtil.get(pageReqVO.getTimes(), 1)); + return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); + } + + @Override + public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) { + AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times); + // 取前100名 + pageParam.setPageSize(100); + PageResult pageResult = getBrokerageUserChildSummaryPageByPrice(pageParam); + // 获得索引 + int index = CollUtil.indexOf(pageResult.getList(), user -> Objects.equals(userId, user.getId())); + // 获得排名 + return index + 1; + } + @Override @Transactional(rollbackFor = Exception.class) public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title) { From ee15b802b24f52359ed610263186bbee6a051073 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 22 Sep 2023 21:12:09 +0800 Subject: [PATCH 15/42] =?UTF-8?q?=E5=88=86=E4=BD=A3:=20=E6=8E=A8=E5=B9=BF?= =?UTF-8?q?=E4=BA=BA=E6=8E=92=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../brokerage/AppBrokerageUserController.java | 20 ++++++------------- .../brokerage/BrokerageUserConvert.java | 11 ++++++++++ .../brokerage/BrokerageRecordMapper.java | 5 +++-- .../mysql/brokerage/BrokerageUserMapper.java | 14 +++++++++++++ .../brokerage/BrokerageUserService.java | 10 ++++++++++ .../brokerage/BrokerageUserServiceImpl.java | 12 +++++++++++ 6 files changed, 56 insertions(+), 16 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 672bff974..85cc086f3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.*; import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert; +import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; @@ -90,24 +91,15 @@ public class AppBrokerageUserController { return success(respVO); } - // TODO 芋艿:临时 mock => @GetMapping("/rank-page-by-user-count") @Operation(summary = "获得分销用户排行分页(基于用户量)") @PreAuthenticated public CommonResult> getBrokerageUserRankPageByUserCount(AppBrokerageUserRankPageReqVO pageReqVO) { - AppBrokerageUserRankByUserCountRespVO vo1 = new AppBrokerageUserRankByUserCountRespVO() - .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokerageUserCount(10); - AppBrokerageUserRankByUserCountRespVO vo2 = new AppBrokerageUserRankByUserCountRespVO() - .setId(2L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokerageUserCount(6); - AppBrokerageUserRankByUserCountRespVO vo3 = new AppBrokerageUserRankByUserCountRespVO() - .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokerageUserCount(4); - AppBrokerageUserRankByUserCountRespVO vo4 = new AppBrokerageUserRankByUserCountRespVO() - .setId(3L).setNickname("芋3**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokerageUserCount(4); - return success(new PageResult<>(asList(vo1, vo2, vo3, vo4), 10L)); + // 分页查询 + PageResult pageResult = brokerageUserService.getBrokerageUserRankPageByUserCount(pageReqVO); + // 拼接数据 + Map userMap = memberUserApi.getUserMap(convertSet(pageResult.getList(), AppBrokerageUserRankByUserCountRespVO::getId)); + return success(BrokerageUserConvert.INSTANCE.convertPage03(pageResult, userMap)); } @GetMapping("/rank-page-by-price") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java index e904f6bfc..e1d218416 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java @@ -4,9 +4,11 @@ import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; import org.mapstruct.factory.Mappers; import java.util.List; @@ -55,4 +57,13 @@ public interface BrokerageUserConvert { user -> target.setNickname(user.getNickname()).setAvatar(user.getAvatar())); return target; } + + default PageResult convertPage03(PageResult pageResult, Map userMap) { + for (AppBrokerageUserRankByUserCountRespVO vo : pageResult.getList()) { + copyTo(userMap.get(vo.getId()), vo); + } + return pageResult; + } + + void copyTo(MemberUserRespDTO from, @MappingTarget AppBrokerageUserRankByUserCountRespVO to); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java index 1393472d3..4faa86c8d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java @@ -67,9 +67,10 @@ public interface BrokerageRecordMapper extends BaseMapperX { @Param("endTime") LocalDateTime endTime); @Select("SELECT user_id AS id, SUM(price) AS brokeragePrice FROM trade_brokerage_record " + - "WHERE biz_type = #{bizType} AND status = #{status} AND create_time BETWEEN #{beginTime} AND #{endTime} " + + "WHERE biz_type = #{bizType} AND status = #{status} AND deleted = FALSE " + + "AND unfreeze_time BETWEEN #{beginTime} AND #{endTime} " + "GROUP BY user_id " + - "ORDER BY SUM(price) DESC") + "ORDER BY brokeragePrice DESC") IPage selectSummaryPricePageGroupByUserId(IPage page, @Param("bizType") Integer bizType, @Param("status") Integer status, diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java index ea39d1054..6b39766f5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java @@ -5,10 +5,16 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import java.time.LocalDateTime; import java.util.List; /** @@ -124,4 +130,12 @@ public interface BrokerageUserMapper extends BaseMapperX { .inIfPresent(BrokerageUserDO::getLevel, levels)); } + @Select("SELECT bind_user_id AS id, COUNT(1) AS brokerageUserCount FROM trade_brokerage_user " + + "WHERE bind_user_id IS NOT NULL AND deleted = FALSE " + + "AND bind_user_time BETWEEN #{beginTime} AND #{endTime} " + + "GROUP BY bind_user_id " + + "ORDER BY brokerageUserCount DESC") + IPage selectCountPageGroupByBindUserId(Page page, + @Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java index 083edc44a..756a910fa 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.trade.service.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import javax.validation.constraints.NotNull; @@ -130,4 +132,12 @@ public interface BrokerageUserService { * @return 是否有分销资格 */ Boolean getUserBrokerageEnabled(Long userId); + + /** + * 获得推广人排行 + * + * @param pageReqVO 分页查询 + * @return 推广人排行 + */ + PageResult getBrokerageUserRankPageByUserCount(AppBrokerageUserRankPageReqVO pageReqVO); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java index bab10ddc3..da3c725a4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java @@ -2,17 +2,22 @@ package cn.iocoder.yudao.module.trade.service.brokerage; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageUserMapper; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageBindModeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageEnabledConditionEnum; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; +import com.baomidou.mybatisplus.core.metadata.IPage; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -208,6 +213,13 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { .orElse(false); } + @Override + public PageResult getBrokerageUserRankPageByUserCount(AppBrokerageUserRankPageReqVO pageReqVO) { + IPage pageResult = brokerageUserMapper.selectCountPageGroupByBindUserId(MyBatisUtils.buildPage(pageReqVO), + ArrayUtil.get(pageReqVO.getTimes(), 0), ArrayUtil.get(pageReqVO.getTimes(), 1)); + return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); + } + private boolean isUserCanBind(BrokerageUserDO user, Boolean isNewUser) { // 校验分销功能是否启用 TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); From 7c4fbc63dc21f71ad62ea9c9a05af3e8acafbf50 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 22 Sep 2023 21:56:09 +0800 Subject: [PATCH 16/42] =?UTF-8?q?trade=EF=BC=9A=E7=89=A9=E6=B5=81=E8=B4=B9?= =?UTF-8?q?=E7=94=A8=E8=AE=A1=E7=AE=97=EF=BC=8C=E5=A2=9E=E5=8A=A0=E9=87=91?= =?UTF-8?q?=E9=A2=9D=20divide=20=E5=88=86=E6=8B=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeliveryExpressChargeModeEnum.java | 2 +- .../TradeDeliveryPriceCalculator.java | 165 ++++++------------ .../TradeDeliveryPriceCalculatorTest.java | 6 +- 3 files changed, 61 insertions(+), 112 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryExpressChargeModeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryExpressChargeModeEnum.java index a4b5252ee..7503dd322 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryExpressChargeModeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/delivery/DeliveryExpressChargeModeEnum.java @@ -16,7 +16,7 @@ import java.util.Arrays; @Getter public enum DeliveryExpressChargeModeEnum implements IntArrayValuable { - PIECE(1, "按件"), + COUNT(1, "按件"), WEIGHT(2,"按重量"), VOLUME(3, "按体积"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java index 7a4669801..20c3feee3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; @@ -55,13 +56,13 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { return; } if (DeliveryTypeEnum.PICK_UP.getType().equals(param.getDeliveryType())) { - calculateByPickUp(param, result); + calculateByPickUp(param); } else if (DeliveryTypeEnum.EXPRESS.getType().equals(param.getDeliveryType())) { calculateExpress(param, result); } } - private void calculateByPickUp(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + private void calculateByPickUp(TradePriceCalculateReqBO param) { if (param.getPickUpStoreId() == null) { throw exception(PRICE_CALCULATE_DELIVERY_PRICE_PICK_UP_STORE_IS_EMPTY); } @@ -82,12 +83,12 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { Assert.notNull(address, "收件人({})的地址,不能为空", param.getUserId()); // 情况一:全局包邮 - if (isGlobalExpressFree(param, result)) { + if (isGlobalExpressFree(result)) { return; } - // 情况二: - // 2.1 过滤出已选中的商品SKU + // 情况二:快递模版 + // 2.1 过滤出已选中的商品 SKU List selectedItem = filterList(result.getItems(), OrderItem::getSelected); Set deliveryTemplateIds = convertSet(selectedItem, OrderItem::getDeliveryTemplateId); Map expressTemplateMap = @@ -103,11 +104,10 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { /** * 是否全局包邮 * - * @param param 计算信息 * @param result 计算结果 * @return 是否包邮 */ - private boolean isGlobalExpressFree(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + private boolean isGlobalExpressFree(TradePriceCalculateRespBO result) { TradeConfigDO config = tradeConfigService.getTradeConfig(); return config != null && Boolean.TRUE.equals(config.getDeliveryExpressFreeEnabled()) // 开启包邮 @@ -118,9 +118,9 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { Map expressTemplateMap, TradePriceCalculateRespBO result) { // 按商品运费模板来计算商品的运费:相同的运费模板可能对应多条订单商品 SKU - Map> tplIdItemMap = convertMultiMap(selectedSkus, OrderItem::getDeliveryTemplateId); + Map> template2ItemMap = convertMultiMap(selectedSkus, OrderItem::getDeliveryTemplateId); // 依次计算快递运费 - for (Map.Entry> entry : tplIdItemMap.entrySet()) { + for (Map.Entry> entry : template2ItemMap.entrySet()) { Long templateId = entry.getKey(); List orderItems = entry.getValue(); DeliveryExpressTemplateRespBO templateBO = expressTemplateMap.get(templateId); @@ -128,30 +128,12 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { log.error("[calculateDeliveryPrice][不能计算快递运费,找不到 templateId({}) 对应的运费模板配置]", templateId); continue; } - // 总件数, 总金额, 总重量, 总体积 - int totalCount = 0; - int totalPrice = 0; - double totalWeight = 0; - double totalVolume = 0; - for (OrderItem orderItem : orderItems) { - totalCount += orderItem.getCount(); - totalPrice += orderItem.getPayPrice(); - if (orderItem.getWeight() != null) { - totalWeight += totalWeight + orderItem.getWeight() * orderItem.getCount(); - } - if (orderItem.getVolume() != null) { - totalVolume += totalVolume + orderItem.getVolume() * orderItem.getCount(); - } - } - // 优先判断是否包邮. 如果包邮不计算快递运费 - if (isExpressFree(templateBO.getChargeMode(), totalCount, totalWeight, - totalVolume, totalPrice, templateBO.getFree())) { + // 1. 优先判断是否包邮。如果包邮不计算快递运费 + if (isExpressTemplateFree(orderItems, templateBO.getChargeMode(), templateBO.getFree())) { continue; } - // 计算快递运费 - calculateExpressFeeByChargeMode(totalCount, totalWeight, totalVolume, - templateBO.getChargeMode(), templateBO.getCharge(), orderItems); - + // 2. 计算快递运费 + calculateExpressFeeByChargeMode(orderItems, templateBO.getChargeMode(), templateBO.getCharge()); } TradePriceCalculatorHelper.recountAllPrice(result); } @@ -159,73 +141,44 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { /** * 按配送方式来计算运费 * - * @param totalCount 总件数 - * @param totalWeight 总重量 - * @param totalVolume 总体积 + * @param orderItems SKU 商品项目 * @param chargeMode 配送计费方式 * @param templateCharge 快递运费配置 - * @param orderItems SKU 商品项目 */ - private void calculateExpressFeeByChargeMode(double totalCount, double totalWeight, double totalVolume, - int chargeMode, DeliveryExpressTemplateRespBO.Charge templateCharge, - List orderItems) { + private void calculateExpressFeeByChargeMode(List orderItems, Integer chargeMode, + DeliveryExpressTemplateRespBO.Charge templateCharge) { if (templateCharge == null) { log.error("[calculateExpressFeeByChargeMode][计算快递运费时,找不到 SKU({}) 对应的运费模版]", orderItems); return; } - DeliveryExpressChargeModeEnum chargeModeEnum = DeliveryExpressChargeModeEnum.valueOf(chargeMode); - switch (chargeModeEnum) { - case PIECE: { - calculateExpressFee(totalCount, templateCharge, orderItems); - break; - } - case WEIGHT: { - calculateExpressFee(totalWeight, templateCharge, orderItems); - break; - } - case VOLUME: { - calculateExpressFee(totalVolume, templateCharge, orderItems); - break; - } - } - } - - /** - * 计算 SKU 商品快递费用 - * - * @param total 总件数/总重量/总体积 - * @param templateCharge 快递运费配置 - * @param orderItems SKU 商品项目 - */ - private void calculateExpressFee(double total, DeliveryExpressTemplateRespBO.Charge templateCharge, List orderItems) { + double totalChargeValue = getTotalChargeValue(orderItems, chargeMode); + // 1. 计算 SKU 商品快递费用 int deliveryPrice; - if (total <= templateCharge.getStartCount()) { + if (totalChargeValue <= templateCharge.getStartCount()) { deliveryPrice = templateCharge.getStartPrice(); } else { - double remainWeight = total - templateCharge.getStartCount(); + double remainWeight = totalChargeValue - templateCharge.getStartCount(); // 剩余重量/ 续件 = 续件的次数. 向上取整 int extraNum = (int) Math.ceil(remainWeight / templateCharge.getExtraCount()); int extraPrice = templateCharge.getExtraPrice() * extraNum; deliveryPrice = templateCharge.getStartPrice() + extraPrice; } - // 分摊快递费用到 SKU. 退费的时候,可能按照 SKU 考虑退费金额 - divideDeliveryPrice(deliveryPrice, orderItems); - } - /** - * 快递运费分摊到每个 SKU 商品上 - * - * @param deliveryPrice 快递运费 - * @param orderItems SKU 商品 - */ - private void divideDeliveryPrice(int deliveryPrice, List orderItems) { - // TODO @jason:分摊的话,是不是要按照比例呀?重量、价格、数量等等, - // 按比例是不是有点复杂。后面看看是否需要; - // TODO 可以看看别的项目怎么搞的哈。 - int dividePrice = deliveryPrice / orderItems.size(); - for (OrderItem item : orderItems) { + // 2. 分摊快递费用到 SKU. 退费的时候,可能按照 SKU 考虑退费金额 + int remainPrice = deliveryPrice; + for (int i = 0; i < orderItems.size(); i++) { + TradePriceCalculateRespBO.OrderItem item = orderItems.get(i); + int partPrice; + double chargeValue = getChargeValue(item, chargeMode); + if (i < orderItems.size() - 1) { // 减一的原因,是因为拆分时,如果按照比例,可能会出现.所以最后一个,使用反减 + partPrice = (int) (deliveryPrice * (chargeValue / totalChargeValue)); + remainPrice -= partPrice; + } else { + partPrice = remainPrice; + } + Assert.isTrue(partPrice >= 0, "分摊金额必须大于等于 0"); // 更新快递运费 - item.setDeliveryPrice(dividePrice); + item.setDeliveryPrice(partPrice); TradePriceCalculatorHelper.recountPayPrice(item); } } @@ -234,42 +187,38 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { * 检查是否包邮 * * @param chargeMode 配送计费方式 - * @param totalCount 总件数 - * @param totalWeight 总重量 - * @param totalVolume 总体积 - * @param totalPrice 总金额 * @param templateFree 包邮配置 */ - private boolean isExpressFree(Integer chargeMode, int totalCount, double totalWeight, - double totalVolume, int totalPrice, DeliveryExpressTemplateRespBO.Free templateFree) { + private boolean isExpressTemplateFree(List orderItems, Integer chargeMode, + DeliveryExpressTemplateRespBO.Free templateFree) { if (templateFree == null) { return false; } + double totalChargeValue = getTotalChargeValue(orderItems, chargeMode); + double totalPrice = TradePriceCalculatorHelper.calculateTotalPayPrice(orderItems); + return totalChargeValue >= templateFree.getFreeCount() && totalPrice >= templateFree.getFreePrice(); + } + + private double getTotalChargeValue(List orderItems, Integer chargeMode) { + double total = 0; + for (OrderItem orderItem : orderItems) { + total += getChargeValue(orderItem, chargeMode); + } + return total; + } + + private double getChargeValue(OrderItem orderItem, Integer chargeMode) { DeliveryExpressChargeModeEnum chargeModeEnum = DeliveryExpressChargeModeEnum.valueOf(chargeMode); switch (chargeModeEnum) { - case PIECE: - // 两个条件都满足才包邮 - if (totalCount >= templateFree.getFreeCount() && totalPrice >= templateFree.getFreePrice()) { - return true; - } - break; + case COUNT: + return orderItem.getCount(); case WEIGHT: - // freeCount 是不是应该是 double ?? - // TODO @jason:要不配置的时候,把它的单位和商品对齐?到底是 kg、还是斤 - // TODO @芋艿 目前 包邮 件数/重量/体积 都用的是这个字段 - // TODO @jason:那要不快递模版也改成 kg?这样是不是就不用 double ? - if (totalWeight >= templateFree.getFreeCount() - && totalPrice >= templateFree.getFreePrice()) { - return true; - } - break; + return orderItem.getWeight() != null ? orderItem.getWeight() * orderItem.getCount() : 0; case VOLUME: - if (totalVolume >= templateFree.getFreeCount() - && totalPrice >= templateFree.getFreePrice()) { - return true; - } - break; + return orderItem.getVolume() != null ? orderItem.getVolume() * orderItem.getCount() : 0; + default: + throw new IllegalArgumentException(StrUtil.format("未知的计费模式({})", chargeMode)); } - return false; } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java index 5aa75fd94..3c1c107ed 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculatorTest.java @@ -91,7 +91,7 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { item -> item.setFreeCount(20).setFreePrice(100)); // 准备 SP 运费模板数据 templateRespBO = randomPojo(DeliveryExpressTemplateRespBO.class, - item -> item.setChargeMode(DeliveryExpressChargeModeEnum.PIECE.getType()) + item -> item.setChargeMode(DeliveryExpressChargeModeEnum.COUNT.getType()) .setCharge(chargeBO).setFree(freeBO)); } @@ -144,11 +144,11 @@ public class TradeDeliveryPriceCalculatorTest extends BaseMockitoUnitTest { // 断言:SKU1 assertThat(resultBO.getItems().get(0)) .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice") - .containsExactly(100, 2, 0, 0, 0, 1500, 1700); + .containsExactly(100, 2, 0, 0, 0, 500, 700); // 断言:SKU2 assertThat(resultBO.getItems().get(1)) .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice") - .containsExactly(200, 10, 0, 0, 0, 1500, 3500); + .containsExactly(200, 10, 0, 0, 0, 2500, 4500); // 断言:SKU3 未选中 assertThat(resultBO.getItems().get(2)) .extracting("price", "count","discountPrice" ,"couponPrice", "pointPrice","deliveryPrice","payPrice") From ad0513c87ccd21ef9fd9f2fcd8f074ab42415982 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 22 Sep 2023 22:12:15 +0800 Subject: [PATCH 17/42] =?UTF-8?q?=E5=88=86=E4=BD=A3:=20=E6=8E=A8=E5=B9=BF?= =?UTF-8?q?=E4=BA=BA=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../brokerage/AppBrokerageUserController.java | 14 ++---- .../AppBrokerageUserChildSummaryRespVO.java | 2 +- .../mysql/brokerage/BrokerageUserMapper.java | 6 +++ .../brokerage/BrokerageUserService.java | 11 +++++ .../brokerage/BrokerageUserServiceImpl.java | 8 ++++ .../mapper/brokerage/BrokerageUserMapper.xml | 44 +++++++++++++++++++ 6 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 85cc086f3..13d1493e9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -33,7 +33,6 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; -import static java.util.Arrays.asList; @Tag(name = "用户 APP - 分销用户") @RestController @@ -113,21 +112,14 @@ public class AppBrokerageUserController { return success(BrokerageRecordConvert.INSTANCE.convertPage03(pageResult, userMap)); } - // TODO 芋艿:临时 mock => @GetMapping("/child-summary-page") @Operation(summary = "获得下级分销统计分页") @PreAuthenticated public CommonResult> getBrokerageUserChildSummaryPage( AppBrokerageUserChildSummaryPageReqVO pageReqVO) { - AppBrokerageUserChildSummaryRespVO vo1 = new AppBrokerageUserChildSummaryRespVO() - .setId(1L).setNickname("芋1**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(10).setBrokeragePrice(20).setBrokerageOrderCount(30) - .setBrokerageTime(LocalDateTime.now()); - AppBrokerageUserChildSummaryRespVO vo2 = new AppBrokerageUserChildSummaryRespVO() - .setId(1L).setNickname("芋2**艿").setAvatar("http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg") - .setBrokeragePrice(20).setBrokeragePrice(30).setBrokerageOrderCount(40) - .setBrokerageTime(LocalDateTime.now()); - return success(new PageResult<>(asList(vo1, vo2), 10L)); + // 分页查询 + PageResult pageResult = brokerageUserService.getBrokerageUserChildSummaryPage(pageReqVO, getLoginUserId()); + return success(pageResult); } @GetMapping("/get-rank-by-price") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java index 1beb1b5e2..6bc4184e8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/vo/user/AppBrokerageUserChildSummaryRespVO.java @@ -27,7 +27,7 @@ public class AppBrokerageUserChildSummaryRespVO { @Schema(description = "分销用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "30") private Integer brokerageUserCount; - @Schema(description = "成为分销员时间", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "绑定推广员的时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime brokerageTime; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java index 6b39766f5..2212ba7f4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java @@ -5,6 +5,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -138,4 +140,8 @@ public interface BrokerageUserMapper extends BaseMapperX { IPage selectCountPageGroupByBindUserId(Page page, @Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + + IPage selectSummaryPageByUserId(Page page, + @Param("param") AppBrokerageUserChildSummaryPageReqVO param, + @Param("userId") Long userId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java index 756a910fa..8fc8c1960 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.trade.service.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; @@ -140,4 +142,13 @@ public interface BrokerageUserService { * @return 推广人排行 */ PageResult getBrokerageUserRankPageByUserCount(AppBrokerageUserRankPageReqVO pageReqVO); + + /** + * 获得下级分销统计分页 + * + * @param pageReqVO 分页查询 + * @param userId 用户编号 + * @return 下级分销统计分页 + */ + PageResult getBrokerageUserChildSummaryPage(AppBrokerageUserChildSummaryPageReqVO pageReqVO, Long userId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java index da3c725a4..3a9e3e242 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java @@ -9,6 +9,8 @@ import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; @@ -220,6 +222,12 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); } + @Override + public PageResult getBrokerageUserChildSummaryPage(AppBrokerageUserChildSummaryPageReqVO pageReqVO, Long userId) { + IPage pageResult = brokerageUserMapper.selectSummaryPageByUserId(MyBatisUtils.buildPage(pageReqVO), pageReqVO, userId); + return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); + } + private boolean isUserCanBind(BrokerageUserDO user, Boolean isNewUser) { // 校验分销功能是否启用 TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml b/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml new file mode 100644 index 000000000..4605f6744 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml @@ -0,0 +1,44 @@ + + + + + + From 6e6486ccae2d8d039e83563d307bddf6a535bb1c Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 22 Sep 2023 22:51:46 +0800 Subject: [PATCH 18/42] =?UTF-8?q?Trade:=20=E5=AE=8C=E5=96=84=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 4 ++-- .../admin/config/vo/TradeConfigBaseVO.java | 16 ++++++++++++++++ .../dal/dataobject/config/TradeConfigDO.java | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index a46e1070a..a38c51f4b 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -3,8 +3,8 @@ create table trade_config ( id bigint auto_increment comment '自增主键' primary key, brokerage_enabled bit default 1 not null comment '是否启用分佣', - brokerage_enabled_condition tinyint default 0 not null comment '分佣模式:1-人人分销 2-指定分销', - brokerage_bind_mode tinyint default 0 not null comment '分销关系绑定模式: 1-没有推广人,2-新用户, 3-扫码覆盖', + brokerage_enabled_condition tinyint default 1 not null comment '分佣模式:1-人人分销 2-指定分销', + brokerage_bind_mode tinyint default 1 not null comment '分销关系绑定模式: 1-没有推广人,2-新用户, 3-扫码覆盖', brokerage_post_urls varchar(2000) default '' null comment '分销海报图地址数组', brokerage_first_percent int default 0 not null comment '一级返佣比例', brokerage_second_percent int default 0 not null comment '二级返佣比例', diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java index ee20156f1..39ffefa49 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java @@ -19,6 +19,17 @@ import java.util.List; */ @Data public class TradeConfigBaseVO { + /** + * 是否启用全场包邮 + */ + @Schema(description = "是否启用全场包邮", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") + @NotNull(message = "是否启用全场包邮不能为空") + private Boolean deliveryExpressFreeEnabled; + + @Schema(description = "全场包邮的最小金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + @NotNull(message = "全场包邮的最小金额不能为空") + @PositiveOrZero(message = "全场包邮的最小金额不能是负数") + private Integer deliveryExpressFreePrice; // ========== 分销相关 ========== @@ -54,6 +65,11 @@ public class TradeConfigBaseVO { @PositiveOrZero(message = "用户提现最低金额不能是负数") private Integer brokerageWithdrawMinPrice; + @Schema(description = "用户提现手续费百分比", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000") + @NotNull(message = "用户提现手续费百分比不能为空") + @PositiveOrZero(message = "用户提现手续费百分比不能是负数") + private Integer brokerageWithdrawFeePercent; + @Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") @NotEmpty(message = "提现银行不能为空") private List brokerageBankNames; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java index 7fac1de38..e01563237 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java @@ -36,7 +36,7 @@ public class TradeConfigDO extends BaseDO { private Long id; // ========== 配送相关 ========== - // TODO 芋艿:未配置 + /** * 是否启用全场包邮 */ From bbd18afbcc5d06ec9291947dac9c86114db9ad06 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 22 Sep 2023 23:13:39 +0800 Subject: [PATCH 19/42] =?UTF-8?q?=E5=88=86=E4=BD=A3:=20=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E7=94=A8=E6=88=B7=E5=85=B3=E7=B3=BB=E6=A0=91?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 2 - .../dataobject/brokerage/BrokerageUserDO.java | 9 --- .../mysql/brokerage/BrokerageUserMapper.java | 17 +++-- .../brokerage/BrokerageUserServiceImpl.java | 75 ++++++++----------- 4 files changed, 39 insertions(+), 64 deletions(-) diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index a38c51f4b..4c1d8d7e8 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -40,8 +40,6 @@ create table trade_brokerage_user brokerage_time datetime null comment '成为分销员时间', price int default 0 not null comment '可用佣金', frozen_price int default 0 not null comment '冻结佣金', - level int default 1 not null comment '等级', - path varchar(2000) null comment '路径', creator varchar(64) default '' null comment '创建者', create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', updater varchar(64) default '' null comment '更新者', diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageUserDO.java index 320bd0b07..8d73858ec 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageUserDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/BrokerageUserDO.java @@ -59,13 +59,4 @@ public class BrokerageUserDO extends BaseDO { * 冻结佣金 */ private Integer frozenPrice; - - /** - * 等级 - */ - private Integer level; - /** - * 路径 - */ - private String path; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java index 2212ba7f4..9bd2fe078 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java @@ -27,13 +27,12 @@ import java.util.List; @Mapper public interface BrokerageUserMapper extends BaseMapperX { - default PageResult selectPage(BrokerageUserPageReqVO reqVO, List levels) { + default PageResult selectPage(BrokerageUserPageReqVO reqVO, List bindUserIds) { return selectPage(reqVO, new LambdaQueryWrapperX() .eqIfPresent(BrokerageUserDO::getBrokerageEnabled, reqVO.getBrokerageEnabled()) .betweenIfPresent(BrokerageUserDO::getCreateTime, reqVO.getCreateTime()) .betweenIfPresent(BrokerageUserDO::getBindUserTime, reqVO.getBindUserTime()) - .findInSetIfPresent(BrokerageUserDO::getPath, reqVO.getBindUserId()) - .inIfPresent(BrokerageUserDO::getLevel, levels) + .inIfPresent(BrokerageUserDO::getBindUserId, bindUserIds) .orderByDesc(BrokerageUserDO::getId)); } @@ -116,8 +115,7 @@ public interface BrokerageUserMapper extends BaseMapperX { default void updateBindUserIdAndBindUserTimeToNull(Long id) { update(null, new LambdaUpdateWrapper() .eq(BrokerageUserDO::getId, id) - .set(BrokerageUserDO::getBindUserId, null).set(BrokerageUserDO::getBindUserTime, null) - .set(BrokerageUserDO::getLevel, 1).set(BrokerageUserDO::getPath, "")); + .set(BrokerageUserDO::getBindUserId, null).set(BrokerageUserDO::getBindUserTime, null)); } default void updateEnabledFalseAndBrokerageTimeToNull(Long id) { @@ -126,10 +124,9 @@ public interface BrokerageUserMapper extends BaseMapperX { .set(BrokerageUserDO::getBrokerageEnabled, false).set(BrokerageUserDO::getBrokerageTime, null)); } - default Long selectCountByBindUserIdAndLevelIn(Long bindUserId, List levels) { + default Long selectCountByBindUserIdIn(List bindUserIds) { return selectCount(new LambdaQueryWrapperX() - .findInSetIfPresent(BrokerageUserDO::getPath, bindUserId) - .inIfPresent(BrokerageUserDO::getLevel, levels)); + .inIfPresent(BrokerageUserDO::getBindUserId, bindUserIds)); } @Select("SELECT bind_user_id AS id, COUNT(1) AS brokerageUserCount FROM trade_brokerage_user " + @@ -144,4 +141,8 @@ public interface BrokerageUserMapper extends BaseMapperX { IPage selectSummaryPageByUserId(Page page, @Param("param") AppBrokerageUserChildSummaryPageReqVO param, @Param("userId") Long userId); + + default List selectListByBindUserId(Long bindUserId) { + return selectList(BrokerageUserDO::getBindUserId, bindUserId); + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java index 3a9e3e242..650edda13 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java @@ -4,8 +4,6 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.BooleanUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO; @@ -25,9 +23,13 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.Optional; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; /** @@ -57,8 +59,8 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { @Override public PageResult getBrokerageUserPage(BrokerageUserPageReqVO pageReqVO) { - List levels = buildUserQueryLevels(pageReqVO.getBindUserId(), pageReqVO.getLevel()); - return brokerageUserMapper.selectPage(pageReqVO, levels); + List bindUserIds = buildBindUserIdsByLevel(pageReqVO.getBindUserId(), pageReqVO.getLevel()); + return brokerageUserMapper.selectPage(pageReqVO, bindUserIds); } @Override @@ -66,6 +68,11 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { // 校验存在 BrokerageUserDO brokerageUser = validateBrokerageUserExists(id); + // 绑定关系未发生变化 + if (Objects.equals(brokerageUser.getBindUserId(), bindUserId)) { + return; + } + // 情况一:清除推广员 if (bindUserId == null) { // 清除推广员 @@ -73,12 +80,6 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { return; } - // 绑定关系未发生变化 - // TODO @疯狂:这个放到“情况一”之前,貌似也没关系? - if (Objects.equals(brokerageUser.getBindUserId(), bindUserId)) { - return; - } - // 情况二:修改推广员 validateCanBindUser(brokerageUser, bindUserId); brokerageUserMapper.updateById(fillBindUserData(bindUserId, new BrokerageUserDO().setId(id))); @@ -146,11 +147,11 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { @Override public Long getBrokerageUserCountByBindUserId(Long bindUserId, Integer level) { - List levels = buildUserQueryLevels(bindUserId, level); - if (CollUtil.isEmpty(levels)) { + List bindUserIds = buildBindUserIdsByLevel(bindUserId, level); + if (CollUtil.isEmpty(bindUserIds)) { return 0L; } - return brokerageUserMapper.selectCountByBindUserIdAndLevelIn(bindUserId, levels); + return brokerageUserMapper.selectCountByBindUserIdIn(bindUserIds); } @Override @@ -185,20 +186,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } private BrokerageUserDO fillBindUserData(Long bindUserId, BrokerageUserDO brokerageUser) { - BrokerageUserDO bindUser = getBrokerageUser(bindUserId); - - Integer bindUserLevel = 0; - String bindUserPath = ""; - if (bindUser != null) { - bindUserLevel = ObjectUtil.defaultIfNull(bindUser.getLevel(), 0); - bindUserPath = bindUser.getPath(); - } - - String path = StrUtil.isEmpty(bindUserPath) - ? String.valueOf(bindUserId) - : String.format("%s,%s", bindUserPath, bindUserId); - return brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now()) - .setLevel(bindUserLevel + 1).setPath(path); + return brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now()); } @Override @@ -267,28 +255,25 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } // 下级不能绑定自己的上级 - if (StrUtil.split(bindUser.getPath(), ",").contains(String.valueOf(user.getId()))) { - throw exception(BROKERAGE_BIND_LOOP); + for (int i = 0; i <= Short.MAX_VALUE; i++) { + if (Objects.equals(bindUser.getBindUserId(), user.getId())) { + throw exception(BROKERAGE_BIND_LOOP); + } + bindUser = getBrokerageUser(bindUser.getBindUserId()); } } - // TODO @芋艿:这个层级,要微信讨论下; - private List buildUserQueryLevels(Long bindUserId, Integer level) { - List levels = new ArrayList<>(2); - - BrokerageUserDO bindUser = getBrokerageUser(bindUserId); - if (bindUser == null) { - return levels; + private List buildBindUserIdsByLevel(Long bindUserId, Integer level) { + List bindUserIds = CollUtil.newArrayList(); + if (level == null || level == 1) { + bindUserIds.add(bindUserId); + } + if (level == null || level == 2) { + List firstUserIds = convertList(brokerageUserMapper.selectListByBindUserId(bindUserId), BrokerageUserDO::getId); + bindUserIds.addAll(firstUserIds); } - if (level == null) { - // 默认查两层 - levels.add(bindUser.getLevel() + 1); - levels.add(bindUser.getLevel() + 2); - } else { - levels.add(bindUser.getLevel() + level); - } - return levels; + return bindUserIds; } From f30fa390674a4859bae68c6f5ad3b0b758ab37f4 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 22 Sep 2023 23:15:10 +0800 Subject: [PATCH 20/42] =?UTF-8?q?=E4=BF=AE=E6=94=B9Review=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/mybatis/core/query/LambdaQueryWrapperX.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java index 7cfd096a4..a728365e6 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java @@ -100,14 +100,6 @@ public class LambdaQueryWrapperX extends LambdaQueryWrapper { return betweenIfPresent(column, val1, val2); } - // TODO @疯狂:这个是 mysql 独有的,不好做成通用的哈。如果多层级,有没可能先查询一个层级,再查询一个层级;形成 set 后,直接去 in? - public LambdaQueryWrapperX findInSetIfPresent(SFunction column, Object val) { - if (val != null) { - return (LambdaQueryWrapperX) super.apply("FIND_IN_SET({0}, " + columnToString(column) + ")", val); - } - return this; - } - // ========== 重写父类方法,方便链式调用 ========== @Override From 9451342aae40c88c11a24b3238641a66535a1aac Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 22 Sep 2023 23:54:18 +0800 Subject: [PATCH 21/42] =?UTF-8?q?trade=EF=BC=9A=E8=90=A5=E9=94=80=E5=95=86?= =?UTF-8?q?=E5=93=81=EF=BC=88=E6=8B=BC=E5=9B=A2=E3=80=81=E7=A0=8D=E4=BB=B7?= =?UTF-8?q?=EF=BC=89=E4=B8=8D=E8=83=BD=E4=BD=BF=E7=94=A8=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=8A=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/trade/enums/ErrorCodeConstants.java | 7 +------ .../price/calculator/TradeCouponPriceCalculator.java | 7 +++++++ .../price/calculator/TradeCouponPriceCalculatorTest.java | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 500601442..ecd31499d 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -12,12 +12,6 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; public interface ErrorCodeConstants { // ========== Order 模块 1011000000 ========== - ErrorCode ORDER_CREATE_SKU_NOT_FOUND = new ErrorCode(1011000001, "商品 SKU 不存在"); - ErrorCode ORDER_CREATE_SPU_NOT_SALE = new ErrorCode(1011000002, "商品 SPU 不可售卖"); - ErrorCode ORDER_CREATE_SKU_STOCK_NOT_ENOUGH = new ErrorCode(1011000004, "商品 SKU 库存不足"); - ErrorCode ORDER_CREATE_SPU_NOT_FOUND = new ErrorCode(1011000005, "商品 SPU 不可售卖"); - ErrorCode ORDER_CREATE_ADDRESS_NOT_FOUND = new ErrorCode(1011000006, "收货地址不存在"); - ErrorCode ORDER_ITEM_NOT_FOUND = new ErrorCode(1011000010, "交易订单项不存在"); ErrorCode ORDER_NOT_FOUND = new ErrorCode(1011000011, "交易订单不存在"); ErrorCode ORDER_ITEM_UPDATE_AFTER_SALE_STATUS_FAIL = new ErrorCode(1011000012, "交易订单项更新售后状态失败,请重试"); @@ -61,6 +55,7 @@ public interface ErrorCodeConstants { ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003001, "计算快递运费异常,收件人地址编号为空"); ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1011003002, "计算快递运费异常,找不到对应的运费模板"); ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_PICK_UP_STORE_IS_EMPTY = new ErrorCode(1011003003, "计算快递运费异常,自提点为空"); + ErrorCode PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER = new ErrorCode(1011003004, "参与秒杀、拼团、砍价的营销商品,无法使用优惠劵"); // ========== 物流 Express 模块 1011004000 ========== ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1011004000, "快递公司不存在"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculator.java index 68955ce51..b871186bd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculator.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO; @@ -9,6 +10,7 @@ import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.springframework.core.annotation.Order; @@ -22,6 +24,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_NO_MATCH_MIN_PRICE; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_NO_MATCH_SPU; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER; /** * 优惠劵的 {@link TradePriceCalculator} 实现类 @@ -44,6 +47,10 @@ public class TradeCouponPriceCalculator implements TradePriceCalculator { CouponRespDTO coupon = couponApi.validateCoupon(new CouponValidReqDTO() .setId(param.getCouponId()).setUserId(param.getUserId())); Assert.notNull(coupon, "校验通过的优惠劵({}),不能为空", param.getCouponId()); + // 1.2 只有【普通】订单,才允许使用优惠劵 + if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) { + throw exception(PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER); + } // 2.1 获得匹配的商品 SKU 数组 List orderItems = filterMatchCouponOrderItems(result, coupon); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculatorTest.java index 94ac66c9b..06655e0b2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeCouponPriceCalculatorTest.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.junit.jupiter.api.Test; @@ -47,6 +48,7 @@ public class TradeCouponPriceCalculatorTest extends BaseMockitoUnitTest { new TradePriceCalculateReqBO.Item().setSkuId(40L).setCount(5).setSelected(false) // 匹配优惠劵,但是未选中 )); TradePriceCalculateRespBO result = new TradePriceCalculateRespBO() + .setType(TradeOrderTypeEnum.NORMAL.getType()) .setPrice(new TradePriceCalculateRespBO.Price()) .setPromotions(new ArrayList<>()) .setItems(asList( From 71d6311bd4aa4a547ac7f882c59044031325c6a1 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Sep 2023 09:27:29 +0800 Subject: [PATCH 22/42] =?UTF-8?q?code=20review=EF=BC=9A=E6=8B=BC=E5=9B=A2?= =?UTF-8?q?=E3=80=81=E7=A7=92=E6=9D=80=E7=AD=89=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/enums/ErrorCodeConstants.java | 2 - .../AppCombinationActivityController.java | 22 +++---- .../seckill/AppSeckillActivityController.java | 19 +++--- .../seckill/AppSeckillConfigController.java | 3 +- .../bargain/BargainActivityConvert.java | 8 +-- .../CombinationActivityConvert.java | 8 +-- .../SeckillActivityConvert.java | 8 +-- .../CombinationActivityMapper.java | 16 +---- .../CombinationActivityService.java | 11 ++++ .../CombinationActivityServiceImpl.java | 2 +- .../aftersale/TradeAfterSaleController.java | 2 +- .../aftersale/TradeAfterSaleConvert.java | 6 +- .../core/dto/TradeAfterSaleLogRespVO.java | 58 ------------------- .../core/service/AfterSaleLogService.java | 2 +- .../aftersale/TradeAfterSaleServiceImpl.java | 3 +- 15 files changed, 46 insertions(+), 124 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespVO.java diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 798e59851..4fc58004a 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -56,7 +56,6 @@ public interface ErrorCodeConstants { ErrorCode SECKILL_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013008004, "秒杀活动未关闭或未结束,不能删除"); ErrorCode SECKILL_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1013008005, "秒杀活动已关闭,不能重复关闭"); ErrorCode SECKILL_ACTIVITY_UPDATE_STOCK_FAIL = new ErrorCode(1013008006, "秒杀失败,原因秒杀库存不足"); - ErrorCode SECKILL_ACTIVITY_APP_STATUS_CLOSED = new ErrorCode(1013008007, "秒杀活动已关闭"); // ========== 秒杀时段 1013009000 ========== ErrorCode SECKILL_CONFIG_NOT_EXISTS = new ErrorCode(1013009000, "秒杀时段不存在"); @@ -69,7 +68,6 @@ public interface ErrorCodeConstants { ErrorCode COMBINATION_ACTIVITY_STATUS_DISABLE_NOT_UPDATE = new ErrorCode(1013010002, "拼团活动已关闭不能修改"); ErrorCode COMBINATION_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED_OR_END = new ErrorCode(1013010003, "拼团活动未关闭或未结束,不能删除"); ErrorCode COMBINATION_ACTIVITY_STATUS_DISABLE = new ErrorCode(1013010004, "拼团失败,原因:拼团活动已关闭"); - ErrorCode COMBINATION_ACTIVITY_APP_STATUS_DISABLE = new ErrorCode(1013010005, "拼团活动已关闭"); // ========== 拼团记录 1013011000 ========== ErrorCode COMBINATION_RECORD_NOT_EXISTS = new ErrorCode(1013011000, "拼团不存在"); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java index d09292de9..ee1d5ed17 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationActivityController.java @@ -24,14 +24,12 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import static cn.hutool.core.util.ObjectUtil.defaultIfNull; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_ACTIVITY_APP_STATUS_DISABLE; @Tag(name = "用户 APP - 拼团活动") @RestController @@ -44,7 +42,7 @@ public class AppCombinationActivityController { @Resource private ProductSpuApi spuApi; - + // TODO 芋艿:增加 Spring Cache @GetMapping("/list") @Operation(summary = "获得拼团活动列表", description = "用于小程序首页") @Parameter(name = "count", description = "需要展示的数量", example = "6") @@ -52,11 +50,10 @@ public class AppCombinationActivityController { @RequestParam(name = "count", defaultValue = "6") Integer count) { List list = activityService.getCombinationActivityListByCount(defaultIfNull(count, 6)); if (CollUtil.isEmpty(list)) { - return success(CombinationActivityConvert.INSTANCE.convertAppList(list)); + return success(Collections.emptyList()); } - + // 拼接返回 List spuList = spuApi.getSpuList(convertList(list, CombinationActivityDO::getSpuId)); - // TODO 芋艿:增加 Spring Cache return success(CombinationActivityConvert.INSTANCE.convertAppList(list, spuList)); } @@ -67,7 +64,7 @@ public class AppCombinationActivityController { if (CollUtil.isEmpty(result.getList())) { return success(PageResult.empty(result.getTotal())); } - + // 拼接返回 List spuList = spuApi.getSpuList(convertList(result.getList(), CombinationActivityDO::getSpuId)); return success(CombinationActivityConvert.INSTANCE.convertAppPage(result, spuList)); } @@ -78,15 +75,12 @@ public class AppCombinationActivityController { public CommonResult getCombinationActivityDetail(@RequestParam("id") Long id) { // 1、获取活动 CombinationActivityDO combinationActivity = activityService.getCombinationActivity(id); - if (combinationActivity == null) { + if (combinationActivity == null + || ObjectUtil.equal(combinationActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { return success(null); } - if (ObjectUtil.equal(combinationActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { - throw exception(COMBINATION_ACTIVITY_APP_STATUS_DISABLE); - } - // 2、获取活动商品 - List products = activityService.getCombinationProductsByActivityIds(Arrays.asList(combinationActivity.getId())); + List products = activityService.getCombinationProductsByActivityId(combinationActivity.getId()); return success(CombinationActivityConvert.INSTANCE.convert3(combinationActivity, products)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java index 7ee0027ed..a83b87ae2 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillActivityController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.controller.app.seckill; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; @@ -29,10 +30,8 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.SECKILL_ACTIVITY_APP_STATUS_CLOSED; @Tag(name = "用户 App - 秒杀活动") @RestController @@ -48,6 +47,7 @@ public class AppSeckillActivityController { @Resource private ProductSpuApi spuApi; + // TODO 芋艿:需要增加 spring cache @GetMapping("/get-now") @Operation(summary = "获得当前秒杀活动", description = "获取当前正在进行的活动,提供给首页使用") public CommonResult getNowSeckillActivity() { @@ -61,7 +61,6 @@ public class AppSeckillActivityController { List activityList = activityService.getSeckillActivityListByConfigIdAndStatus(configList.getId(), CommonStatusEnum.ENABLE.getStatus()); // 3 获取 spu 信息 List spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId)); - // TODO 芋艿:需要增加 spring cache return success(SeckillActivityConvert.INSTANCE.convert(configList, activityList, spuList)); } @@ -70,7 +69,9 @@ public class AppSeckillActivityController { public CommonResult> getSeckillActivityPage(AppSeckillActivityPageReqVO pageReqVO) { // 1. 查询满足当前阶段的活动 PageResult pageResult = activityService.getSeckillActivityAppPageByConfigId(pageReqVO); - + if (CollUtil.isEmpty(pageResult.getList())) { + return success(PageResult.empty(pageResult.getTotal())); + } // 2. 拼接数据 List spuList = spuApi.getSpuList(convertList(pageResult.getList(), SeckillActivityDO::getSpuId)); return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, spuList)); @@ -88,16 +89,14 @@ public class AppSeckillActivityController { // 2. 获取活动 SeckillActivityDO seckillActivity = activityService.getSeckillActivity(id); - if (seckillActivity == null) { + if (seckillActivity == null + || ObjectUtil.equal(seckillActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { return success(null); } - if (ObjectUtil.equal(seckillActivity.getStatus(), CommonStatusEnum.DISABLE.getStatus())) { - throw exception(SECKILL_ACTIVITY_APP_STATUS_CLOSED); - } // 3. 拼接数据 - List products = activityService.getSeckillProductListByActivityId(seckillActivity.getId()); - return success(SeckillActivityConvert.INSTANCE.convert3(seckillActivity, products, configList)); + List productList = activityService.getSeckillProductListByActivityId(seckillActivity.getId()); + return success(SeckillActivityConvert.INSTANCE.convert3(seckillActivity, productList, configList)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java index 2795ca9a4..ec60b2141 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/seckill/AppSeckillConfigController.java @@ -28,7 +28,8 @@ public class AppSeckillConfigController { @GetMapping("/list") @Operation(summary = "获得秒杀时间段列表") public CommonResult> getSeckillConfigList() { - return success(SeckillConfigConvert.INSTANCE.convertList2(configService.getSeckillConfigListByStatus(CommonStatusEnum.ENABLE.getStatus()))); + return success(SeckillConfigConvert.INSTANCE.convertList2( + configService.getSeckillConfigListByStatus(CommonStatusEnum.ENABLE.getStatus()))); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java index 954558b01..92791ed76 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/bargain/BargainActivityConvert.java @@ -73,9 +73,7 @@ public interface BargainActivityConvert { // 拼接关联属性 Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); List list = CollectionUtils.convertList(result.getList(), item -> { - findAndThen(spuMap, item.getSpuId(), spu -> { - item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()); - }); + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); return item; }); result.setList(list); @@ -88,9 +86,7 @@ public interface BargainActivityConvert { List activityList = convertAppList(list); Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); return CollectionUtils.convertList(activityList, item -> { - findAndThen(spuMap, item.getSpuId(), spu -> { - item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()); - }); + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); return item; }); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index 07a9c4df3..f92dbef59 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -61,9 +61,7 @@ public interface CombinationActivityConvert { Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); PageResult pageResult = convertPage(page); pageResult.getList().forEach(item -> { - MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> { - item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()); - }); + MapUtils.findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl())); item.setProducts(convertList2(productList)); }); return pageResult; @@ -118,9 +116,7 @@ public interface CombinationActivityConvert { List activityList = convertAppList(list); Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); return CollectionUtils.convertList(activityList, item -> { - findAndThen(spuMap, item.getSpuId(), spu -> { - item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()); - }); + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); return item; }); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java index f0da88cbc..e1fcc35d8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/seckill/seckillactivity/SeckillActivityConvert.java @@ -113,11 +113,8 @@ public interface SeckillActivityConvert { PageResult result = convertPage1(pageResult); Map spuMap = convertMap(spuList, ProductSpuRespDTO::getId); List list = CollectionUtils.convertList(result.getList(), item -> { - findAndThen(spuMap, item.getSpuId(), spu -> { - item.setPicUrl(spu.getPicUrl()) - .setMarketPrice(spu.getMarketPrice()) - .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); - }); + findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()) + .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit()))); return item; }); result.setList(list); @@ -131,6 +128,7 @@ public interface SeckillActivityConvert { default AppSeckillActivityDetailRespVO convert3(SeckillActivityDO seckillActivity, List products, SeckillConfigDO filteredConfig) { return convert2(seckillActivity) .setProducts(convertList1(products)) + // TODO @puhui999:要不要在里面 default 一个方法,处理这个事件;简洁一点; .setStartTime(LocalDateTimeUtil.parse(LocalDateTimeUtil.format(seckillActivity.getStartTime(), "yyyy-MM-dd") + " " + filteredConfig.getStartTime(), "yyyy-MM-dd HH:mm:ss")) // 活动开始日期和时段结合 .setEndTime(LocalDateTimeUtil.parse(LocalDateTimeUtil.format(seckillActivity.getEndTime(), "yyyy-MM-dd") + " " + filteredConfig.getEndTime(), diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java index 0dce45a28..5672c34dc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java @@ -29,26 +29,12 @@ public interface CombinationActivityMapper extends BaseMapperX selectPage(PageParam pageParam, Integer status) { return selectPage(pageParam, new LambdaQueryWrapperX() .eq(CombinationActivityDO::getStatus, status)); } - /** - * 查询 status 状态的活动分页 - * - * @param status 状态 - * @param count 限制条数 - * @return 活动分页 - */ - default List selectList(Integer status, Integer count) { + default List selectListByStatus(Integer status, Integer count) { return selectList(new LambdaQueryWrapperX() .eq(CombinationActivityDO::getStatus, status) .last("LIMIT " + count)); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java index c2a090b72..c5f72e6a6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityService.java @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP import javax.validation.Valid; import java.util.Collection; +import java.util.Collections; import java.util.List; /** @@ -65,6 +66,16 @@ public interface CombinationActivityService { */ PageResult getCombinationActivityPage(CombinationActivityPageReqVO pageReqVO); + /** + * 获得拼团活动商品列表 + * + * @param activityId 拼团活动 id + * @return 拼团活动的商品列表 + */ + default List getCombinationProductsByActivityId(Long activityId) { + return getCombinationProductsByActivityIds(Collections.singletonList(activityId)); + } + /** * 获得拼团活动商品列表 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index 87a633064..2dc715039 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -247,7 +247,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic @Override public List getCombinationActivityListByCount(Integer count) { - return combinationActivityMapper.selectList(CommonStatusEnum.ENABLE.getStatus(), count); + return combinationActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus(), count); } @Override diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java index a3fcfae40..3b438568b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/aftersale/TradeAfterSaleController.java @@ -8,11 +8,11 @@ import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.pay.api.notify.dto.PayRefundNotifyReqDTO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.*; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService; import cn.iocoder.yudao.module.trade.service.aftersale.TradeAfterSaleService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java index dc220ad31..9faaefb5d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/aftersale/TradeAfterSaleConvert.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO; import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleDetailRespVO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRespPageItemVO; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO; import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderBaseVO; @@ -15,7 +16,6 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO; import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleLogDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -68,7 +68,7 @@ public interface TradeAfterSaleConvert { PageResult convertPage02(PageResult page); List convertList(List list); - + default TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, TradeOrderDO order, List orderItems, MemberUserRespDTO user, List logs) { TradeAfterSaleDetailRespVO respVO = convert(afterSale, orderItems); @@ -81,7 +81,7 @@ public interface TradeAfterSaleConvert { return respVO; } - List convertList1(List list); + List convertList1(List list); @Mapping(target = "id", source = "afterSale.id") TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, List orderItems); TradeOrderBaseVO convert(TradeOrderDO order); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespVO.java deleted file mode 100644 index 328aab944..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/dto/TradeAfterSaleLogRespVO.java +++ /dev/null @@ -1,58 +0,0 @@ -package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.validation.constraints.NotNull; -import java.time.LocalDateTime; - -/** - * 贸易售后日志详情 DTO - * - * @author HUIHUI - */ -@Data -@NoArgsConstructor -@AllArgsConstructor -public class TradeAfterSaleLogRespVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20669") - private Long id; - - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "22634") - @NotNull(message = "用户编号不能为空") - private Long userId; - - @Schema(description = "用户类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") - @NotNull(message = "用户类型不能为空") - private Integer userType; - - @Schema(description = "售后编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3023") - @NotNull(message = "售后编号不能为空") - private Long afterSaleId; - - @Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25870") - @NotNull(message = "订单编号不能为空") - private Long orderId; - - @Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23154") - @NotNull(message = "订单项编号不能为空") - private Long orderItemId; - - @Schema(description = "售后状态(之前)", example = "2") - private Integer beforeStatus; - - @Schema(description = "售后状态(之后)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "售后状态(之后)不能为空") - private Integer afterStatus; - - @Schema(description = "操作明细", requiredMode = Schema.RequiredMode.REQUIRED, example = "维权完成,退款金额:¥37776.00") - @NotNull(message = "操作明细不能为空") - private String content; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime createTime; - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java index 2f9245c01..53019a30b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/aftersalelog/core/service/AfterSaleLogService.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO; import java.util.List; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java index 1b7866da8..80acf9b99 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/TradeAfterSaleServiceImpl.java @@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleDisagreeReqVO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSalePageReqVO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRefuseReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.log.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleDeliveryReqVO; import cn.iocoder.yudao.module.trade.convert.aftersale.TradeAfterSaleConvert; @@ -26,7 +27,6 @@ import cn.iocoder.yudao.module.trade.enums.aftersale.TradeAfterSaleWayEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogCreateReqDTO; -import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.dto.TradeAfterSaleLogRespVO; import cn.iocoder.yudao.module.trade.framework.aftersalelog.core.service.AfterSaleLogService; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; @@ -449,6 +449,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa } } + // TODO @puhui999:应该返回 do 哈。 @Override public List getLog(Long afterSaleId) { // TODO 不熟悉流程先这么滴 From 052328c5fafca745051e5f6c9378f47ee21c44df Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 23 Sep 2023 14:11:16 +0800 Subject: [PATCH 23/42] =?UTF-8?q?=E7=A7=AF=E5=88=86=EF=BC=9A=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E7=A7=AF=E5=88=86=E8=8E=B7=E5=BE=97=E3=80=81=E9=80=80?= =?UTF-8?q?=E8=BF=98=E3=80=81=E4=BD=BF=E7=94=A8=20=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/point.sql | 6 ++ .../api/spu/dto/ProductSpuRespDTO.java | 5 ++ .../enums/common/PromotionTypeEnum.java | 3 +- .../dal/dataobject/order/TradeOrderDO.java | 12 ++- .../dataobject/order/TradeOrderItemDO.java | 8 ++ .../order/TradeOrderUpdateServiceImpl.java | 68 +++++++------- .../service/price/TradePriceServiceImpl.java | 1 - .../price/bo/TradePriceCalculateReqBO.java | 2 +- .../price/bo/TradePriceCalculateRespBO.java | 14 +++ .../calculator/TradePointGiveCalculator.java | 62 +++++++++++++ .../TradePointUsePriceCalculator.java | 88 ++++++++++++++++++- .../calculator/TradePriceCalculator.java | 4 + .../TradePriceCalculatorHelper.java | 51 +++++++---- .../member/api/point/MemberPointApi.java | 8 ++ .../point/dto/MemberPointConfigRespDTO.java | 30 +++++++ .../api/user/dto/MemberUserRespDTO.java | 5 +- .../member/enums/ErrorCodeConstants.java | 1 + .../enums/point/MemberPointBizTypeEnum.java | 4 +- .../member/api/point/MemberPointApiImpl.java | 15 +++- .../point/MemberPointConfigConvert.java | 2 + .../dal/mysql/user/MemberUserMapper.java | 31 +++++++ .../point/MemberPointRecordServiceImpl.java | 38 ++++---- .../service/user/MemberUserService.java | 3 +- .../service/user/MemberUserServiceImpl.java | 9 +- 24 files changed, 383 insertions(+), 87 deletions(-) create mode 100644 sql/mysql/point.sql create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointGiveCalculator.java create mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/dto/MemberPointConfigRespDTO.java diff --git a/sql/mysql/point.sql b/sql/mysql/point.sql new file mode 100644 index 000000000..44123ea1b --- /dev/null +++ b/sql/mysql/point.sql @@ -0,0 +1,6 @@ +ALTER TABLE trade_order ADD COLUMN use_point int NOT NULL DEFAULT 0 COMMENT '使用的积分' AFTER point_price; +ALTER TABLE trade_order ADD COLUMN refund_point int NOT NULL DEFAULT 0 COMMENT '退还的使用积分' AFTER use_point; +ALTER TABLE trade_order ADD COLUMN give_point int NOT NULL DEFAULT 0 COMMENT '赠送的积分' AFTER refund_point; + +ALTER TABLE trade_order_item ADD COLUMN use_point int NOT NULL DEFAULT 0 COMMENT '使用的积分' AFTER point_price; +ALTER TABLE trade_order_item ADD COLUMN give_point int NOT NULL DEFAULT 0 COMMENT '赠送的积分' AFTER use_point; diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java index ab93431f4..b6b6b996d 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java @@ -110,6 +110,11 @@ public class ProductSpuRespDTO { // ========== 物流相关字段 ========= + /** + * 赠送积分 + */ + private Integer giveIntegral; + /** * 物流配置模板编号 * diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java index 874651ea3..65af63406 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java @@ -23,7 +23,8 @@ public enum PromotionTypeEnum implements IntArrayValuable { REWARD_ACTIVITY(5, "满减送"), MEMBER(6, "会员折扣"), - COUPON(7, "优惠劵") + COUPON(7, "优惠劵"), + POINT(8, "积分") ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionTypeEnum::getType).toArray(); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java index bb68fc1ac..f7a03a52b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java @@ -265,9 +265,13 @@ public class TradeOrderDO extends BaseDO { * 对应 taobao 的 trade.point_fee 字段 */ private Integer pointPrice; -// /** -// * 奖励的积分 TODO 疯狂:可以使用这个字段哈; -// */ -// private Integer rewardPoint; + /** + * 赠送的积分 + */ + private Integer givePoint; + /** + * 退还的使用的积分 + */ + private Integer refundPoint; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java index 27dd13f67..77b455344 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java @@ -143,6 +143,14 @@ public class TradeOrderItemDO extends BaseDO { * 对应 taobao 的 trade.point_fee 字段 */ private Integer pointPrice; + /** + * 使用的积分 + */ + private Integer usePoint; + /** + * 赠送的积分 + */ + private Integer givePoint; // TODO @芋艿:如果商品 vip 折扣时,到底是新增一个 vipPrice 记录优惠记录,还是 vipDiscountPrice,记录 vip 的优惠;还是直接使用 vipPrice; // 目前 crmeb 的选择,单独一个 vipPrice 记录优惠价格;感觉不一定合理,可以在看看有赞的; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index c4f1677e5..e2ff20c7c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -24,6 +24,7 @@ import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum; import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; import cn.iocoder.yudao.module.promotion.api.bargain.BargainRecordApi; import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; @@ -48,8 +49,8 @@ import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.*; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.framework.order.core.annotations.TradeOrderLog; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.cart.CartService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; import cn.iocoder.yudao.module.trade.service.message.TradeMessageService; @@ -105,6 +106,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Resource private TradeMessageService tradeMessageService; + @Resource + private ProductSpuApi productSpuApi; @Resource private ProductSkuApi productSkuApi; @Resource @@ -240,8 +243,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { /** * 订单创建前,执行前置逻辑 * - * @param userId 用户编号 - * @param createReqVO 创建订单请求 + * @param userId 用户编号 + * @param createReqVO 创建订单请求 * @param calculateRespBO 订单价格计算结果 */ private void beforeCreateTradeOrder(Long userId, AppTradeOrderCreateReqVO createReqVO, @@ -260,12 +263,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { /** * 订单创建后,执行后置逻辑 - * + *

* 例如说:优惠劵的扣减、积分的扣减、支付单的创建等等 * * @param userId 用户编号 * @param createReqVO 创建订单请求 - * @param order 交易订单 + * @param order 交易订单 * @param calculateRespBO 订单价格计算结果 */ private void afterCreateTradeOrder(Long userId, AppTradeOrderCreateReqVO createReqVO, @@ -283,12 +286,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { .setOrderId(order.getId())); } - // 3. 扣减积分 + // 3. 扣减积分(抵扣) // 不在前置扣减的原因,是因为积分扣减时,需要记录关联业务 - if (order.getUsePoint() != null && order.getUsePoint() > 0) { - memberPointApi.reducePoint(userId, calculateRespBO.getUsePoint(), - MemberPointBizTypeEnum.ORDER_USE.getType(), String.valueOf(order.getId())); - } + reduceUserPoint(order.getUserId(), order.getUsePoint(), MemberPointBizTypeEnum.ORDER_USE, order.getId()); // 4. 删除购物车商品 Set cartIds = convertSet(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCartId); @@ -342,8 +342,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:OrderLog - // 增加用户积分 - getSelf().addUserPointAsync(order.getUserId(), order.getPayPrice(), order.getId()); + // 增加用户积分(赠送) + addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_REWARD, order.getId()); // 增加用户经验 getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); // 增加用户佣金 @@ -640,11 +640,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { return; } // 计算总的退款金额 - TradeOrderDO order = tradeOrderMapper.selectById(tradeOrderItemMapper.selectById(id).getOrderId()); + TradeOrderItemDO orderItem = tradeOrderItemMapper.selectById(id); + TradeOrderDO order = tradeOrderMapper.selectById(orderItem.getOrderId()); Integer orderRefundPrice = order.getRefundPrice() + refundPrice; if (isAllOrderItemAfterSaleSuccess(order.getId())) { // 如果都售后成功,则需要取消订单 tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()) - .setRefundStatus(TradeOrderRefundStatusEnum.ALL.getStatus()).setRefundPrice(orderRefundPrice) + .setRefundStatus(TradeOrderRefundStatusEnum.ALL.getStatus()).setRefundPrice(orderRefundPrice).setRefundPoint(order.getRefundPoint() + orderItem.getUsePoint()) .setCancelType(TradeOrderCancelTypeEnum.AFTER_SALE_CLOSE.getType()).setCancelTime(LocalDateTime.now())); // TODO 芋艿:记录订单日志 @@ -655,12 +656,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { .setRefundStatus(TradeOrderRefundStatusEnum.PART.getStatus()).setRefundPrice(orderRefundPrice)); } - // 扣减用户积分 - getSelf().reduceUserPointAsync(order.getUserId(), orderRefundPrice, afterSaleId); - // 扣减用户经验 - getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); - // 更新分佣记录为已失效 - getSelf().cancelBrokerageAsync(order.getUserId(), id); + // 售后成功后,执行数据回滚逻辑 + if (Objects.equals(newAfterSaleStatus, TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus())) { + // 扣减用户积分(赠送的) + reduceUserPoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, afterSaleId); + // 增加用户积分(返还抵扣) + addUserPoint(order.getUserId(), orderItem.getUsePoint(), MemberPointBizTypeEnum.AFTER_SALE_REFUND_USED, afterSaleId); + // 扣减用户经验 + getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); + // 更新分佣记录为已失效 + getSelf().cancelBrokerageAsync(order.getUserId(), id); + } } @Override @@ -728,8 +734,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 3.回滚优惠券 couponApi.returnUsedCoupon(order.getCouponId()); - // 4.回滚积分:积分是支付成功后才增加的吧? 回复:每个项目不同,目前看下来,确认收货貌似更合适,我再看看其它项目的业务选择; - // TODO @疯狂:有赞是可配置(支付 or 确认收货),我们按照支付好列;然后这里的退积分,指的是下单时的积分抵扣。 + // 4.回滚积分(抵扣的) + addUserPoint(order.getUserId(), order.getUsePoint(), MemberPointBizTypeEnum.ORDER_CANCEL, order.getId()); // TODO 芋艿:OrderLog @@ -760,18 +766,16 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { memberLevelApi.addExperience(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); } - @Async - protected void addUserPointAsync(Long userId, Integer payPrice, Long orderId) { - // TODO @疯狂:具体多少积分,需要分成 2 不分:1. 支付金额;2. 商品金额 - int bizType = MemberPointBizTypeEnum.ORDER_REWARD.getType(); - memberPointApi.addPoint(userId, payPrice, bizType, String.valueOf(orderId)); + protected void addUserPoint(Long userId, Integer point, MemberPointBizTypeEnum bizType, Long bizId) { + if (point != null && point > 0) { + memberPointApi.addPoint(userId, point, bizType.getType(), String.valueOf(bizId)); + } } - @Async - protected void reduceUserPointAsync(Long userId, Integer refundPrice, Long afterSaleId) { - // TODO @疯狂:退款时,按照金额比例,退还积分;https://help.youzan.com/displaylist/detail_4_4-1-49185 - int bizType = MemberPointBizTypeEnum.ORDER_CANCEL.getType(); - memberPointApi.addPoint(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); + protected void reduceUserPoint(Long userId, Integer point, MemberPointBizTypeEnum bizType, Long bizId) { + if (point != null && point > 0) { + memberPointApi.reducePoint(userId, point, bizType.getType(), String.valueOf(bizId)); + } } @Async diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java index e211374bf..a6982c177 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/TradePriceServiceImpl.java @@ -41,7 +41,6 @@ public class TradePriceServiceImpl implements TradePriceService { @Resource private List priceCalculators; - // TODO @疯狂:需要搞个 TradePriceCalculator,计算赠送积分; @Override public TradePriceCalculateRespBO calculatePrice(TradePriceCalculateReqBO calculateReqBO) { // 1.1 获得商品 SKU 数组 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java index 67019a49a..a908a93b9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java @@ -29,7 +29,7 @@ public class TradePriceCalculateReqBO { * 对应 CouponDO 的 id 编号 */ private Long couponId; - // TODO @疯狂:需要增加一个 PriceCalculator 实现积分扣减的计算;写回到 TradePriceCalculateRespBO 的 usePoint + /** * 是否使用积分 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java index 1171cd8f2..786c478bc 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java @@ -53,6 +53,11 @@ public class TradePriceCalculateRespBO { */ private Integer usePoint; + /** + * 使用的积分 + */ + private Integer givePoint; + /** * 订单价格 */ @@ -158,6 +163,10 @@ public class TradePriceCalculateRespBO { * 对应 taobao 的 trade.point_fee 字段 */ private Integer pointPrice; + /** + * 使用的积分 + */ + private Integer usePoint; /** * 应付金额(总),单位:分 * @@ -205,6 +214,11 @@ public class TradePriceCalculateRespBO { */ private List properties; + /** + * 使用的积分 + */ + private Integer givePoint; + } /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointGiveCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointGiveCalculator.java new file mode 100644 index 000000000..4fb2b2d7b --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointGiveCalculator.java @@ -0,0 +1,62 @@ +package cn.iocoder.yudao.module.trade.service.price.calculator; + +import cn.hutool.core.util.BooleanUtil; +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; +import cn.iocoder.yudao.module.member.api.point.MemberPointApi; +import cn.iocoder.yudao.module.member.api.point.dto.MemberPointConfigRespDTO; +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Optional; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; + +/** + * 赠送积分的 {@link TradePriceCalculator} 实现类 + * + * @author owen + */ +@Component +@Order(TradePriceCalculator.ORDER_POINT_GIVE) +@Slf4j +public class TradePointGiveCalculator implements TradePriceCalculator { + @Resource + private MemberPointApi memberPointApi; + + @Override + public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // 1.1 校验积分功能是否开启 + int givePointPerYuan = Optional.ofNullable(memberPointApi.getConfig()) + .filter(config -> BooleanUtil.isTrue(config.getTradeDeductEnable())) + .map(MemberPointConfigRespDTO::getTradeGivePoint) + .orElse(0); + if (givePointPerYuan <= 0) { + return; + } + // 1.2 校验支付金额 + if (result.getPrice().getPayPrice() <= 0) { + return; + } + + // 2.1 计算赠送积分 + int givePoint = MoneyUtils.calculateRatePriceFloor(result.getPrice().getPayPrice(), (double) givePointPerYuan); + // 2.2 计算分摊的赠送积分 + List orderItems = filterList(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSelected); + List dividePoints = TradePriceCalculatorHelper.dividePrice(orderItems, givePoint); + + // 3.2 更新 SKU 赠送积分 + for (int i = 0; i < orderItems.size(); i++) { + TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i); + // 商品可能赠送了积分,所以这里要加上 + orderItem.setGivePoint(orderItem.getGivePoint() + dividePoints.get(i)); + TradePriceCalculatorHelper.recountPayPrice(orderItem); + } + // 3.3 更新订单赠送积分 + TradePriceCalculatorHelper.recountAllGivePoint(result); + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java index 6bd479802..b2fd10572 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePointUsePriceCalculator.java @@ -1,11 +1,25 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; +import cn.hutool.core.util.BooleanUtil; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.module.member.api.point.MemberPointApi; +import cn.iocoder.yudao.module.member.api.point.dto.MemberPointConfigRespDTO; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import lombok.extern.slf4j.Slf4j; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; +import javax.annotation.Resource; +import java.math.RoundingMode; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; + /** * 使用积分的 {@link TradePriceCalculator} 实现类 * @@ -15,15 +29,81 @@ import org.springframework.stereotype.Component; @Order(TradePriceCalculator.ORDER_POINT_USE) @Slf4j public class TradePointUsePriceCalculator implements TradePriceCalculator { + @Resource + private MemberPointApi memberPointApi; + @Resource + private MemberUserApi memberUserApi; @Override public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { - // TODO 疯狂:待实现,嘿嘿; - if (param.getPointStatus()) { - result.setUsePoint(10); - } else { + // 1.1 校验是否使用积分 + if (!BooleanUtil.isTrue(param.getPointStatus())) { result.setUsePoint(0); + return; } + // 1.2 校验积分抵扣是否开启 + MemberPointConfigRespDTO config = memberPointApi.getConfig(); + if (!checkDeductPointEnable(config)) { + return; + } + // 1.3 校验用户积分余额 + MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); + if (user.getPoint() == null || user.getPoint() < 0) { + return; + } + + // 2.1 计算积分优惠金额 + int pointPrice = calculatePointPrice(config, user.getPoint(), result); + // 2.1 计算分摊的积分、抵扣金额 + List orderItems = filterList(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSelected); + List dividePointPrices = TradePriceCalculatorHelper.dividePrice(orderItems, pointPrice); + List divideUsePoints = TradePriceCalculatorHelper.dividePrice(orderItems, result.getUsePoint()); + + // 3.1 记录优惠明细 + TradePriceCalculatorHelper.addPromotion(result, orderItems, + param.getUserId(), "积分抵扣", PromotionTypeEnum.POINT.getType(), + StrUtil.format("积分抵扣:省 {} 元", TradePriceCalculatorHelper.formatPrice(pointPrice)), + dividePointPrices); + // 3.2 更新 SKU 优惠金额 + for (int i = 0; i < orderItems.size(); i++) { + TradePriceCalculateRespBO.OrderItem orderItem = orderItems.get(i); + orderItem.setPointPrice(dividePointPrices.get(i)); + orderItem.setUsePoint(divideUsePoints.get(i)); + TradePriceCalculatorHelper.recountPayPrice(orderItem); + } + TradePriceCalculatorHelper.recountAllPrice(result); } + private boolean checkDeductPointEnable(MemberPointConfigRespDTO config) { + if (config == null) { + return false; + } + if (!BooleanUtil.isTrue(config.getTradeDeductEnable())) { + return false; + } + + // 有没有配置:1 积分抵扣多少分 + return config.getTradeDeductUnitPrice() != null && config.getTradeDeductUnitPrice() > 0; + } + + private Integer calculatePointPrice(MemberPointConfigRespDTO config, Integer usePoint, TradePriceCalculateRespBO result) { + // 每个订单最多可以使用的积分数量 + if (config.getTradeDeductMaxPrice() != null && config.getTradeDeductMaxPrice() > 0) { + usePoint = Math.min(usePoint, config.getTradeDeductMaxPrice()); + } + // 积分优惠金额(分) + int pointPrice = usePoint * config.getTradeDeductUnitPrice(); + // 0元购!!!:用户积分比较多时,积分可以抵扣的金额要大于支付金额, 这时需要根据支付金额反推使用多少积分 + if (result.getPrice().getPayPrice() < pointPrice) { + pointPrice = result.getPrice().getPayPrice(); + // 反推需要扣除的积分 + usePoint = NumberUtil.toBigDecimal(pointPrice) + .divide(NumberUtil.toBigDecimal(config.getTradeDeductUnitPrice()), 0, RoundingMode.HALF_UP) + .intValue(); + } + // 记录使用的积分 + result.setUsePoint(usePoint); + + return pointPrice; + } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java index cddc1ea21..e5b18e88e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java @@ -23,6 +23,10 @@ public interface TradePriceCalculator { * 放在各种营销活动、优惠劵后面 TODO */ int ORDER_DELIVERY = 50; + /** + * 赠送积分,放最后 + */ + int ORDER_POINT_GIVE = 999; void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java index b8b9e0fb9..9a0a7e1d5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java @@ -58,7 +58,8 @@ public class TradePriceCalculatorHelper { .setWeight(sku.getWeight()).setVolume(sku.getVolume()); // spu 信息 orderItem.setSpuName(spu.getName()).setCategoryId(spu.getCategoryId()) - .setDeliveryTemplateId(spu.getDeliveryTemplateId()); + .setDeliveryTemplateId(spu.getDeliveryTemplateId()) + .setGivePoint(spu.getGiveIntegral()).setUsePoint(0); if (orderItem.getPicUrl() == null) { orderItem.setPicUrl(spu.getPicUrl()); } @@ -67,6 +68,7 @@ public class TradePriceCalculatorHelper { // 创建它的 Price 属性 result.setPrice(new TradePriceCalculateRespBO.Price()); recountAllPrice(result); + recountAllGivePoint(result); return result; } @@ -111,13 +113,22 @@ public class TradePriceCalculatorHelper { }); } + /** + * 基于订单项,重新计算赠送积分 + * + * @param result 计算结果 + */ + public static void recountAllGivePoint(TradePriceCalculateRespBO result) { + result.setGivePoint(getSumValue(result.getItems(), item -> item.getSelected() ? item.getGivePoint() : 0, Integer::sum)); + } + /** * 重新计算单个订单项的支付金额 * * @param orderItem 订单项 */ public static void recountPayPrice(TradePriceCalculateRespBO.OrderItem orderItem) { - orderItem.setPayPrice(orderItem.getPrice()* orderItem.getCount() + orderItem.setPayPrice(orderItem.getPrice() * orderItem.getCount() - orderItem.getDiscountPrice() + orderItem.getDeliveryPrice() - orderItem.getCouponPrice() @@ -145,6 +156,12 @@ public class TradePriceCalculatorHelper { if (orderItem.getPointPrice() == null) { orderItem.setPointPrice(0); } + if (orderItem.getUsePoint() == null) { + orderItem.setUsePoint(0); + } + if (orderItem.getGivePoint() == null) { + orderItem.setGivePoint(0); + } recountPayPrice(orderItem); }); } @@ -169,7 +186,7 @@ public class TradePriceCalculatorHelper { */ public static Integer calculateTotalCount(List orderItems) { return getSumValue(orderItems, - orderItem -> orderItem.getSelected() ? orderItem.getCount() : 0, // 未选中的情况下,不计算数量 + orderItem -> orderItem.getSelected() ? orderItem.getCount() : 0, // 未选中的情况下,不计算数量 Integer::sum); } @@ -177,7 +194,7 @@ public class TradePriceCalculatorHelper { * 按照支付金额,返回每个订单项的分摊金额数组 * * @param orderItems 订单项数组 - * @param price 金额 + * @param price 金额 * @return 分摊金额数组,和传入的 orderItems 一一对应 */ public static List dividePrice(List orderItems, Integer price) { @@ -210,12 +227,12 @@ public class TradePriceCalculatorHelper { /** * 添加【匹配】单个 OrderItem 的营销明细 * - * @param result 价格计算结果 + * @param result 价格计算结果 * @param orderItem 单个订单商品 SKU - * @param id 营销编号 - * @param name 营销名字 - * @param description 满足条件的提示 - * @param type 营销类型 + * @param id 营销编号 + * @param name 营销名字 + * @param description 满足条件的提示 + * @param type 营销类型 * @param discountPrice 单个订单商品 SKU 的优惠价格(总) */ public static void addPromotion(TradePriceCalculateRespBO result, TradePriceCalculateRespBO.OrderItem orderItem, @@ -226,7 +243,7 @@ public class TradePriceCalculatorHelper { /** * 添加【匹配】多个 OrderItem 的营销明细 * - * @param result 价格计算结果 + * @param result 价格计算结果 * @param orderItems 多个订单商品 SKU * @param id 营销编号 * @param name 营销名字 @@ -235,7 +252,7 @@ public class TradePriceCalculatorHelper { * @param discountPrices 多个订单商品 SKU 的优惠价格(总),和 orderItems 一一对应 */ public static void addPromotion(TradePriceCalculateRespBO result, List orderItems, - Long id, String name, Integer type, String description, List discountPrices) { + Long id, String name, Integer type, String description, List discountPrices) { // 创建营销明细 Item List promotionItems = new ArrayList<>(discountPrices.size()); for (int i = 0; i < orderItems.size(); i++) { @@ -255,12 +272,12 @@ public class TradePriceCalculatorHelper { /** * 添加【不匹配】多个 OrderItem 的营销明细 * - * @param result 价格计算结果 - * @param orderItems 多个订单商品 SKU - * @param id 营销编号 - * @param name 营销名字 - * @param description 满足条件的提示 - * @param type 营销类型 + * @param result 价格计算结果 + * @param orderItems 多个订单商品 SKU + * @param id 营销编号 + * @param name 营销名字 + * @param description 满足条件的提示 + * @param type 营销类型 */ public static void addNotMatchPromotion(TradePriceCalculateRespBO result, List orderItems, Long id, String name, Integer type, String description) { diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java index 3eb749fb6..c6df95f7c 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApi.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.member.api.point; +import cn.iocoder.yudao.module.member.api.point.dto.MemberPointConfigRespDTO; import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; import javax.validation.constraints.Min; @@ -11,6 +12,13 @@ import javax.validation.constraints.Min; */ public interface MemberPointApi { + /** + * 获得积分配置 + * + * @return 积分配置 + */ + MemberPointConfigRespDTO getConfig(); + /** * 增加用户积分 * diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/dto/MemberPointConfigRespDTO.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/dto/MemberPointConfigRespDTO.java new file mode 100644 index 000000000..a9783352a --- /dev/null +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/point/dto/MemberPointConfigRespDTO.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.member.api.point.dto; + +import lombok.Data; + +/** + * 用户信息 Response DTO + * + * @author 芋道源码 + */ +@Data +public class MemberPointConfigRespDTO { + /** + * 积分抵扣开关 + */ + private Boolean tradeDeductEnable; + /** + * 积分抵扣,单位:分 + *

+ * 1 积分抵扣多少分 + */ + private Integer tradeDeductUnitPrice; + /** + * 积分抵扣最大值 + */ + private Integer tradeDeductMaxPrice; + /** + * 1 元赠送多少分 + */ + private Integer tradeGivePoint; +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java index 10d96365f..0fa2c3e0b 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java @@ -33,5 +33,8 @@ public class MemberUserRespDTO { * 手机 */ private String mobile; - + /** + * 积分 + */ + private Integer point; } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index 933f17168..c25de2461 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java @@ -13,6 +13,7 @@ public interface ErrorCodeConstants { ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在"); ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1004001001, "手机号未注册用户"); ErrorCode USER_MOBILE_USED = new ErrorCode(1004001002, "修改手机失败,该手机号({})已经被使用"); + ErrorCode USER_POINT_NOT_ENOUGH = new ErrorCode(1004001003, "用户积分余额不足"); // ========== AUTH 模块 1004003000 ========== ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1004003000, "登录失败,账号密码不正确"); diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java index fe76cdb52..68e61cc9f 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java @@ -18,8 +18,10 @@ public enum MemberPointBizTypeEnum implements IntArrayValuable { SIGN(1, "签到", "签到获得 {} 积分", true), ORDER_REWARD(10, "订单奖励", "下单获得 {} 积分", true), - ORDER_CANCEL(11, "订单取消", "退单获得 {} 积分", false), // 退回积分 + ORDER_CANCEL(11, "订单取消", "订单取消,退还 {} 积分", true), // 退回积分 ORDER_USE(12, "订单使用", "下单使用 {} 积分", false), // 扣减积分 + AFTER_SALE_REFUND_USED(13, "订单退款", "订单退款,退还 {} 积分", true), // 退回积分 + AFTER_SALE_DEDUCT_GIVE(14, "订单退款", "订单退款,扣除赠送的 {} 积分", false), // 扣减积分 ; /** diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java index ee407eaf6..51239388a 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/point/MemberPointApiImpl.java @@ -1,6 +1,10 @@ package cn.iocoder.yudao.module.member.api.point; +import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.module.member.api.point.dto.MemberPointConfigRespDTO; +import cn.iocoder.yudao.module.member.convert.point.MemberPointConfigConvert; import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; +import cn.iocoder.yudao.module.member.service.point.MemberPointConfigService; import cn.iocoder.yudao.module.member.service.point.MemberPointRecordService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -21,9 +25,17 @@ public class MemberPointApiImpl implements MemberPointApi { @Resource private MemberPointRecordService memberPointRecordService; + @Resource + private MemberPointConfigService memberPointConfigService; + + @Override + public MemberPointConfigRespDTO getConfig() { + return MemberPointConfigConvert.INSTANCE.convert01(memberPointConfigService.getPointConfig()); + } @Override public void addPoint(Long userId, Integer point, Integer bizType, String bizId) { + Assert.isTrue(point > 0); MemberPointBizTypeEnum bizTypeEnum = MemberPointBizTypeEnum.getByType(bizType); if (bizTypeEnum == null) { throw exception(POINT_RECORD_BIZ_NOT_SUPPORT); @@ -33,11 +45,12 @@ public class MemberPointApiImpl implements MemberPointApi { @Override public void reducePoint(Long userId, Integer point, Integer bizType, String bizId) { + Assert.isTrue(point > 0); MemberPointBizTypeEnum bizTypeEnum = MemberPointBizTypeEnum.getByType(bizType); if (bizTypeEnum == null) { throw exception(POINT_RECORD_BIZ_NOT_SUPPORT); } - memberPointRecordService.createPointRecord(userId, point, bizTypeEnum, bizId); + memberPointRecordService.createPointRecord(userId, -point, bizTypeEnum, bizId); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/point/MemberPointConfigConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/point/MemberPointConfigConvert.java index e600378bb..c7f0e9881 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/point/MemberPointConfigConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/point/MemberPointConfigConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.member.convert.point; +import cn.iocoder.yudao.module.member.api.point.dto.MemberPointConfigRespDTO; import cn.iocoder.yudao.module.member.controller.admin.point.vo.config.MemberPointConfigRespVO; import cn.iocoder.yudao.module.member.controller.admin.point.vo.config.MemberPointConfigSaveReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; @@ -20,4 +21,5 @@ public interface MemberPointConfigConvert { MemberPointConfigDO convert(MemberPointConfigSaveReqVO bean); + MemberPointConfigRespDTO convert01(MemberPointConfigDO pointConfig); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java index 902057272..3f871020c 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java @@ -1,12 +1,14 @@ package cn.iocoder.yudao.module.member.dal.mysql.user; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.lang.Assert; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -62,4 +64,33 @@ public interface MemberUserMapper extends BaseMapperX { .apply("FIND_IN_SET({0}, tag_ids)", tagId)); } + /** + * 更新用户积分(增加) + * + * @param id 用户编号 + * @param incrCount 增加积分(正数) + */ + default void updatePointIncr(Long id, Integer incrCount) { + Assert.isTrue(incrCount > 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" point = point + " + incrCount) + .eq(MemberUserDO::getId, id); + update(null, lambdaUpdateWrapper); + } + + /** + * 更新用户积分(减少) + * + * @param id 用户编号 + * @param incrCount 增加积分(负数) + * @return 更新行数 + */ + default int updatePointDecr(Long id, Integer incrCount) { + Assert.isTrue(incrCount < 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" point = point + " + incrCount) // 负数,所以使用 + 号 + .eq(MemberUserDO::getId, id); + return update(null, lambdaUpdateWrapper); + } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java index a28e94795..da67a9ec2 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java @@ -5,7 +5,6 @@ import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPointRecordPageReqVO; -import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointConfigDO; import cn.iocoder.yudao.module.member.dal.dataobject.point.MemberPointRecordDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.dal.mysql.point.MemberPointRecordMapper; @@ -14,6 +13,7 @@ import cn.iocoder.yudao.module.member.service.user.MemberUserService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; @@ -21,7 +21,9 @@ import javax.annotation.Resource; import java.util.List; import java.util.Set; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.USER_POINT_NOT_ENOUGH; /** @@ -36,8 +38,6 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { @Resource private MemberPointRecordMapper memberPointRecordMapper; - @Resource - private MemberPointConfigService memberPointConfigService; @Resource private MemberUserService memberUserService; @@ -64,32 +64,28 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { } @Override + @Transactional(rollbackFor = Exception.class) public void createPointRecord(Long userId, Integer point, MemberPointBizTypeEnum bizType, String bizId) { - MemberPointConfigDO pointConfig = memberPointConfigService.getPointConfig(); - if (pointConfig == null || pointConfig.getTradeGivePoint() == null) { - log.error("[createPointRecord][增加积分失败:tradeGivePoint 未配置,userId({}) point({}) bizType({}) bizId({})]", - userId, point, bizType.getType(), bizId); - return; - } - - // 1. 根据配置的比例,换算实际的积分 - point = point * pointConfig.getTradeGivePoint(); - if (!bizType.isAdd() && point > 0) { - point = -point; - } - - // 2. 增加积分记录 + // 1. 校验用户积分余额 MemberUserDO user = memberUserService.getUser(userId); Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0); - Integer totalPoint = userPoint + point; // 用户变动后的积分 + int totalPoint = userPoint + point; // 用户变动后的积分 + if (totalPoint < 0) { + throw exception(USER_POINT_NOT_ENOUGH); + } + + // 2. 更新用户积分 + boolean success = memberUserService.updateUserPoint(userId, point); + if (!success) { + throw exception(USER_POINT_NOT_ENOUGH); + } + + // 3. 增加积分记录 MemberPointRecordDO record = new MemberPointRecordDO() .setUserId(userId).setBizId(bizId).setBizType(bizType.getType()) .setTitle(bizType.getName()).setDescription(StrUtil.format(bizType.getDescription(), point)) .setPoint(point).setTotalPoint(totalPoint); memberPointRecordMapper.insert(record); - - // 3. 更新用户积分 - memberUserService.updateUserPoint(userId, totalPoint); } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index f1a0a7265..50433a559 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -164,6 +164,7 @@ public interface MemberUserService { * * @param userId 用户编号 * @param point 积分数量 + * @return 更新结果 */ - void updateUserPoint(Long userId, Integer point); + boolean updateUserPoint(Long userId, Integer point); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index 8381c73f1..3119c48db 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -260,8 +260,13 @@ public class MemberUserServiceImpl implements MemberUserService { } @Override - public void updateUserPoint(Long userId, Integer point) { - memberUserMapper.updateById(new MemberUserDO().setId(userId).setPoint(point)); + public boolean updateUserPoint(Long id, Integer point) { + if (point > 0) { + memberUserMapper.updatePointIncr(id, point); + } else if (point < 0) { + return memberUserMapper.updatePointDecr(id, point) > 0; + } + return true; } } From e9c9ac0cabe54a44e3cc37f0039466051cfb3fc0 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Sep 2023 17:47:39 +0800 Subject: [PATCH 24/42] =?UTF-8?q?trade=EF=BC=9A=E7=A1=AE=E8=AE=A4=E6=94=B6?= =?UTF-8?q?=E8=B4=A7=E6=97=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/TradeOrderOperateTypeEnum.java | 2 +- .../order/TradeOrderUpdateServiceImpl.java | 47 +++++++++++++++---- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java index f16e35601..892d638b0 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java @@ -14,7 +14,7 @@ import lombok.RequiredArgsConstructor; public enum TradeOrderOperateTypeEnum { MEMBER_CREATE(1, "用户下单"), - TEST(2, "用户({nickname})做了({thing})"), + MEMBER_RECEIVE(30, "用户已收货") ; /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index ad06c801b..0767fc9d6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -48,6 +48,7 @@ import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.*; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.framework.order.core.annotations.TradeOrderLog; +import cn.iocoder.yudao.module.trade.framework.order.core.utils.TradeOrderLogUtils; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.brokerage.record.BrokerageRecordService; import cn.iocoder.yudao.module.trade.service.cart.CartService; @@ -299,6 +300,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 5. 生成预支付 createPayOrder(order, orderItems, calculateRespBO); + // 6. 插入订单日志 + TradeOrderLogUtils.setOrderInfo(order.getId(), null, order.getStatus()); + // TODO @LeeYan9: 是可以思考下, 订单的营销优惠记录, 应该记录在哪里, 微信讨论起来! } @@ -343,7 +347,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:OrderLog // 增加用户积分 - getSelf().addUserPointAsync(order.getUserId(), order.getPayPrice(), order.getId()); + getSelf().addMemberPointAsync(order.getUserId(), order.getPayPrice(), order.getId()); // 增加用户经验 getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); // 增加用户佣金 @@ -492,7 +496,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { if (updateCount == 0) { throw exception(ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED); } - // TODO 芋艿:OrderLog // TODO 芋艿:lili 发送订单变化的消息 @@ -500,7 +503,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // TODO 芋艿:销售佣金的记录; - // TODO 芋艿:获得积分; + // 插入订单日志 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus()); } @Override @@ -664,7 +668,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { } // 扣减用户积分 - getSelf().reduceUserPointAsync(order.getUserId(), orderRefundPrice, afterSaleId); + getSelf().reduceMemberPointAsync(order.getUserId(), orderRefundPrice, afterSaleId); // 扣减用户经验 getSelf().reduceUserExperienceAsync(order.getUserId(), orderRefundPrice, afterSaleId); // 更新分佣记录为已失效 @@ -768,29 +772,54 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { memberLevelApi.addExperience(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); } + /** + * 添加用户积分 + * + * 目前是支付成功后,就会创建积分记录。 + * + * 业内还有两种做法,可以根据自己的业务调整: + * 1. 确认收货后,才创建积分记录 + * 2. 支付 or 下单成功时,创建积分记录(冻结),确认收货解冻或者 n 天后解冻 + * + * @param userId 用户编号 + * @param payPrice 支付金额 + * @param orderId 订单编号 + */ @Async - protected void addUserPointAsync(Long userId, Integer payPrice, Long orderId) { + protected void addMemberPointAsync(Long userId, Integer payPrice, Long orderId) { // TODO @疯狂:具体多少积分,需要分成 2 不分:1. 支付金额;2. 商品金额 int bizType = MemberPointBizTypeEnum.ORDER_REWARD.getType(); memberPointApi.addPoint(userId, payPrice, bizType, String.valueOf(orderId)); } @Async - protected void reduceUserPointAsync(Long userId, Integer refundPrice, Long afterSaleId) { + protected void reduceMemberPointAsync(Long userId, Integer refundPrice, Long afterSaleId) { // TODO @疯狂:退款时,按照金额比例,退还积分;https://help.youzan.com/displaylist/detail_4_4-1-49185 int bizType = MemberPointBizTypeEnum.ORDER_CANCEL.getType(); memberPointApi.addPoint(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); } + /** + * 创建分销记录 + * + * 目前是支付成功后,就会创建分销记录。 + * + * 业内还有两种做法,可以根据自己的业务调整: + * 1. 确认收货后,才创建分销记录 + * 2. 支付 or 下单成功时,创建分销记录(冻结),确认收货解冻或者 n 天后解冻 + * + * @param userId 用户编号 + * @param orderId 订单编号 + */ @Async protected void addBrokerageAsync(Long userId, Long orderId) { MemberUserRespDTO user = memberUserApi.getUser(userId); Assert.notNull(user); - + // 每一个订单项,都会去生成分销记录 List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); - List list = convertList(orderItems, + List addList = convertList(orderItems, item -> TradeOrderConvert.INSTANCE.convert(user, item, productSkuApi.getSku(item.getSkuId()))); - brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, list); + brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, addList); } @Async From a9485ad6bffd9974fd1be267ef474d90d51b71cd Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Sep 2023 18:13:35 +0800 Subject: [PATCH 25/42] =?UTF-8?q?trade=EF=BC=9A=E5=8F=96=E6=B6=88=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E3=80=81=E7=A1=AE=E8=AE=A4=E6=94=B6=E8=B4=A7=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=A2=E5=8D=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/TradeOrderOperateTypeEnum.java | 4 ++- .../order/core/aop/TradeOrderLogAspect.java | 3 +++ .../order/TradeOrderUpdateServiceImpl.java | 26 ++++++++++++------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java index 892d638b0..08353c3b5 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java @@ -14,7 +14,9 @@ import lombok.RequiredArgsConstructor; public enum TradeOrderOperateTypeEnum { MEMBER_CREATE(1, "用户下单"), - MEMBER_RECEIVE(30, "用户已收货") + MEMBER_RECEIVE(30, "用户已收货"), + MEMBER_COMMENT(31, "用户评价"), + MEMBER_CANCEL(40, "取消订单"), ; /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/TradeOrderLogAspect.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/TradeOrderLogAspect.java index e8349220f..127291b1c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/TradeOrderLogAspect.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/order/core/aop/TradeOrderLogAspect.java @@ -63,6 +63,9 @@ public class TradeOrderLogAspect { Long userId = getUserId(); // 1.2 订单信息 Long orderId = ORDER_ID.get(); + if (orderId == null) { // 如果未设置,只有注解,说明不需要记录订单日志 + return; + } Integer beforeStatus = BEFORE_STATUS.get(); Integer afterStatus = AFTER_STATUS.get(); Map exts = ObjectUtil.defaultIfNull(EXTS.get(), emptyMap()); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 0767fc9d6..f4d72a37e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -486,6 +486,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_RECEIVE) public void receiveOrder(Long userId, Long id) { // 校验并获得交易订单(可收货) TradeOrderDO order = validateOrderReceivable(userId, id); @@ -677,6 +678,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_COMMENT) public Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO) { // 先通过订单项 ID,查询订单项是否存在 TradeOrderItemDO orderItem = tradeOrderItemMapper.selectByIdAndUserId(createReqVO.getOrderItemId(), userId); @@ -704,12 +706,15 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { List orderItems = tradeOrderItemMapper.selectListByOrderId(order.getId()); if (!anyMatch(orderItems, item -> Objects.equals(item.getCommentStatus(), Boolean.FALSE))) { tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()).setCommentStatus(Boolean.TRUE)); - // TODO 待实现:已完成评价,要不要写一条订单日志?目前 crmeb 会写,有赞可以研究下 + // 增加订单日志 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus()); } return comment; } @Override + @Transactional(rollbackFor = Exception.class) + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CANCEL) public void cancelOrder(Long userId, Long id) { // 校验存在 TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId); @@ -721,7 +726,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); } - // 1.更新 TradeOrderDO 状态为已取消 + // 1. 更新 TradeOrderDO 状态为已取消 int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(), new TradeOrderDO().setStatus(TradeOrderStatusEnum.CANCELED.getStatus()) .setCancelTime(LocalDateTime.now()) @@ -730,22 +735,23 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); } - // TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来 + // TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来;回复:从订单里拿呀 tradeOrderHandlers.forEach(handler -> handler.rollback()); - // 2.回滚库存 + // 2. 回滚库存 List orderItems = tradeOrderItemMapper.selectListByOrderId(id); productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems)); - // 3.回滚优惠券 - couponApi.returnUsedCoupon(order.getCouponId()); + // 3. 回滚优惠券 + if (order.getCouponId() > 0) { + couponApi.returnUsedCoupon(order.getCouponId()); + } - // 4.回滚积分:积分是支付成功后才增加的吧? 回复:每个项目不同,目前看下来,确认收货貌似更合适,我再看看其它项目的业务选择; + // 4. 回滚积分:积分是支付成功后才增加的吧? 回复:每个项目不同,目前看下来,确认收货貌似更合适,我再看看其它项目的业务选择; // TODO @疯狂:有赞是可配置(支付 or 确认收货),我们按照支付好列;然后这里的退积分,指的是下单时的积分抵扣。 - // TODO 芋艿:OrderLog - - // TODO 芋艿:lili 发送订单变化的消息 + // 5. 增加订单日志 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus()); } /** From 1da14a3f53d8429e3d3028974a9462b4301f5151 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Sep 2023 20:23:28 +0800 Subject: [PATCH 26/42] =?UTF-8?q?trade=EF=BC=9A=E5=88=A0=E9=99=A4=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/ErrorCodeConstants.java | 1 + .../order/TradeOrderOperateTypeEnum.java | 1 + .../app/order/AppTradeOrderController.java | 2 +- .../order/TradeOrderUpdateService.java | 23 ++++++++---- .../order/TradeOrderUpdateServiceImpl.java | 37 +++++++++++++++---- 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index ecd31499d..ffdba1fcf 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -31,6 +31,7 @@ public interface ErrorCodeConstants { ErrorCode ORDER_UPDATE_PRICE_FAIL_PAID = new ErrorCode(1011000026, "支付订单调价失败,原因:支付订单已付款,不能调价"); ErrorCode ORDER_UPDATE_PRICE_FAIL_EQUAL = new ErrorCode(1011000027, "支付订单调价失败,原因:价格没有变化"); ErrorCode ORDER_UPDATE_PRICE_FAIL_NOT_ITEM = new ErrorCode(1011000028, "支付订单调价失败,原因:订单项不存在"); + ErrorCode ORDER_DELETE_FAIL_STATUS_NOT_CANCEL = new ErrorCode(1011000029, "交易订单删除失败,订单不是【已取消】状态"); // ========== After Sale 模块 1011000100 ========== ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在"); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java index 08353c3b5..517928551 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderOperateTypeEnum.java @@ -17,6 +17,7 @@ public enum TradeOrderOperateTypeEnum { MEMBER_RECEIVE(30, "用户已收货"), MEMBER_COMMENT(31, "用户评价"), MEMBER_CANCEL(40, "取消订单"), + MEMBER_DELETE(41, "删除订单"), ; /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 4bbd98a27..f1d361d91 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -156,7 +156,7 @@ public class AppTradeOrderController { @Operation(summary = "删除交易订单") @Parameter(name = "id", description = "交易订单编号") public CommonResult deleteOrder(@RequestParam("id") Long id) { - // TODO @芋艿:未实现,mock 用 + tradeOrderUpdateService.deleteOrder(getLoginUserId(), id); return success(true); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java index ee9128b6c..3de830df9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java @@ -62,6 +62,22 @@ public interface TradeOrderUpdateService { */ void receiveOrder(Long userId, Long id); + /** + * 【会员】取消订单 + * + * @param userId 用户编号 + * @param id 订单编号 + */ + void cancelOrder(Long userId, Long id); + + /** + * 【会员】删除订单 + * + * @param userId 用户编号 + * @param id 订单编号 + */ + void deleteOrder(Long userId, Long id); + /** * 【管理员】交易订单备注 * @@ -117,11 +133,4 @@ public interface TradeOrderUpdateService { */ Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO); - /** - * 【会员】取消订单 - * - * @param userId 用户ID - * @param id 订单编号 - */ - void cancelOrder(Long userId, Long id); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index f4d72a37e..00b350a10 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -716,17 +716,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Transactional(rollbackFor = Exception.class) @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_CANCEL) public void cancelOrder(Long userId, Long id) { - // 校验存在 + // 1.1 校验存在 TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId); if (order == null) { throw exception(ORDER_NOT_FOUND); } - // 校验状态 + // 1.2 校验状态 if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.UNPAID.getStatus())) { throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); } - // 1. 更新 TradeOrderDO 状态为已取消 + // 2. 更新 TradeOrderDO 状态为已取消 int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(), new TradeOrderDO().setStatus(TradeOrderStatusEnum.CANCELED.getStatus()) .setCancelTime(LocalDateTime.now()) @@ -735,25 +735,46 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); } - // TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来;回复:从订单里拿呀 + // 3. TODO 活动相关库存回滚需要活动 id,活动 id 怎么获取?app 端能否传过来;回复:从订单里拿呀 tradeOrderHandlers.forEach(handler -> handler.rollback()); - // 2. 回滚库存 + // 4. 回滚库存 List orderItems = tradeOrderItemMapper.selectListByOrderId(id); productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems)); - // 3. 回滚优惠券 + // 5. 回滚优惠券 if (order.getCouponId() > 0) { couponApi.returnUsedCoupon(order.getCouponId()); } - // 4. 回滚积分:积分是支付成功后才增加的吧? 回复:每个项目不同,目前看下来,确认收货貌似更合适,我再看看其它项目的业务选择; + // 6. 回滚积分:积分是支付成功后才增加的吧? 回复:每个项目不同,目前看下来,确认收货貌似更合适,我再看看其它项目的业务选择; // TODO @疯狂:有赞是可配置(支付 or 确认收货),我们按照支付好列;然后这里的退积分,指的是下单时的积分抵扣。 - // 5. 增加订单日志 + // 7. 增加订单日志 TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus()); } + @Override + @Transactional(rollbackFor = Exception.class) + @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_DELETE) + public void deleteOrder(Long userId, Long id) { + // 1.1 校验存在 + TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId); + if (order == null) { + throw exception(ORDER_NOT_FOUND); + } + // 1.2 校验状态 + if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus())) { + throw exception(ORDER_DELETE_FAIL_STATUS_NOT_CANCEL); + } + + // 2. 删除订单 + tradeOrderMapper.deleteById(id); + + // 3. 记录日志 + TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), order.getStatus()); + } + /** * 判断指定订单的所有订单项,是不是都售后成功 * From aa5525d1f58aa2e39731cbd6461a1e18c9c57b81 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Sep 2023 22:21:23 +0800 Subject: [PATCH 27/42] =?UTF-8?q?code=20review=EF=BC=9A=E8=90=A5=E9=94=80?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=20&=20=E4=BA=A4=E6=98=93=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=9A=84=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/bargain/BargainActivityApi.java | 2 +- .../mysql/bargain/BargainActivityMapper.java | 2 +- .../SeckillActivityMapper.java | 2 +- .../seckillactivity/SeckillProductMapper.java | 11 ++++++-- .../bargain/BargainActivityServiceImpl.java | 6 ++-- .../CombinationRecordServiceImpl.java | 6 ++++ .../seckill/SeckillActivityServiceImpl.java | 28 ++++++++----------- .../order/TradeOrderQueryServiceImpl.java | 4 +-- .../order/handler/TradeBargainHandler.java | 7 +++-- .../order/handler/TradeOrderHandler.java | 3 ++ .../order/handler/TradeSeckillHandler.java | 6 +++- 11 files changed, 47 insertions(+), 30 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java index eb912e417..0f9812629 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/bargain/BargainActivityApi.java @@ -11,7 +11,7 @@ public interface BargainActivityApi { * 更新砍价活动库存 * * @param id 砍价活动编号 - * @param count 购买数量 + * @param count 购买数量 */ void updateBargainActivityStock(Long id, Integer count); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java index a7fe3e58d..de518f60c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java @@ -38,7 +38,7 @@ public interface BargainActivityMapper extends BaseMapperX { * @param count 扣减的库存数量 * @return 影响的行数 */ - default int updateActivityStock(Long id, int count) { + default int updateStock(Long id, int count) { return update(null, new LambdaUpdateWrapper() .eq(BargainActivityDO::getId, id) .ge(BargainActivityDO::getStock, count) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index 8ce12092f..7e2afdc85 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -41,7 +41,7 @@ public interface SeckillActivityMapper extends BaseMapperX { * @param count 扣减的库存数量 * @return 影响的行数 */ - default int updateActivityStock(Long id, int count) { + default int updateStock(Long id, int count) { return update(null, new LambdaUpdateWrapper() .eq(SeckillActivityDO::getId, id) .gt(SeckillActivityDO::getTotalStock, 0) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java index 5ca2dae24..db34aa744 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java @@ -16,8 +16,13 @@ import java.util.List; @Mapper public interface SeckillProductMapper extends BaseMapperX { - default List selectListByActivityId(Long id) { - return selectList(SeckillProductDO::getActivityId, id); + default List selectListByActivityId(Long activityId) { + return selectList(SeckillProductDO::getActivityId, activityId); + } + + default SeckillProductDO selectByActivityIdAndSkuId(Long activityId, Long skuId) { + return selectOne(SeckillProductDO::getActivityId, activityId, + SeckillProductDO::getSkuId, skuId); } default List selectListByActivityId(Collection ids) { @@ -31,7 +36,7 @@ public interface SeckillProductMapper extends BaseMapperX { * @param count 扣减的库存数量 * @return 影响的行数 */ - default int updateActivityStock(Long id, int count) { + default int updateStock(Long id, int count) { return update(null, new LambdaUpdateWrapper() .eq(SeckillProductDO::getId, id) .gt(SeckillProductDO::getStock, count) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 95e50eff5..546b95041 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -75,16 +75,18 @@ public class BargainActivityServiceImpl implements BargainActivityService { } @Override - @Transactional(rollbackFor = Exception.class) public void updateBargainActivityStock(Long id, Integer count) { // 查询砍价活动 BargainActivityDO activity = getBargainActivity(id); if (activity == null) { throw exception(BARGAIN_ACTIVITY_NOT_EXISTS); } + if (count > activity.getStock()) { + throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL); + } // 更新砍价库存 - int updateCount = bargainActivityMapper.updateActivityStock(id, count); + int updateCount = bargainActivityMapper.updateStock(id, count); if (updateCount == 0) { throw exception(BARGAIN_ACTIVITY_UPDATE_STOCK_FAIL); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index bb62295b8..047e060a9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -96,12 +96,15 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return recordDO; } + // TODO @puhui999:有一个应该在创建那要做下;就是当前 activityId 已经有未支付的订单,不允许在发起新的;要么支付,要么去掉先; + @Override @Transactional(rollbackFor = Exception.class) public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { // 1.1 校验拼团活动 CombinationActivityDO activity = combinationActivityService.validateCombinationActivityExists(reqDTO.getActivityId()); // 1.2 需要校验下,他当前是不是已经参加了该拼团; + // TODO @puhui999:拼团应该可以重复参加;应该去校验总共的上限哈,就是 activity.totalLimitCount CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(reqDTO.getUserId(), reqDTO.getOrderId()); if (recordDO != null) { throw exception(COMBINATION_RECORD_EXISTS); @@ -111,6 +114,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { if (CollUtil.isNotEmpty(recordDOList)) { throw exception(COMBINATION_RECORD_FAILED_HAVE_JOINED); } + // TODO @puhui999:有个开始时间未校验 // 1.4 校验当前活动是否过期 if (LocalDateTime.now().isAfter(activity.getEndTime())) { throw exception(COMBINATION_RECORD_FAILED_TIME_END); @@ -128,6 +132,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } } + // TODO @puhui999:单次限购 + // 2. 创建拼团记录 MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index 0092cf1b8..6e05191bf 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -149,31 +149,25 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Override @Transactional(rollbackFor = Exception.class) public void updateSeckillStock(Long id, Long skuId, Integer count) { - // 1、校验秒杀活动是否存在 + // 1.1 校验活动库存是否充足 SeckillActivityDO seckillActivity = getSeckillActivity(id); - // 1.1、校验库存是否充足 - if (seckillActivity.getTotalStock() < count) { + if (count > seckillActivity.getTotalStock()) { + throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); + } + // 1.2 校验商品库存是否充足 + SeckillProductDO product = seckillProductMapper.selectByActivityIdAndSkuId(id, skuId); + if (product == null || count > product.getStock()) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } - // 2、获取活动商品 - List products = getSeckillProductListByActivityId(id); - // 2.1、过滤出购买的商品 - SeckillProductDO product = findFirst(products, item -> ObjectUtil.equal(skuId, item.getSkuId())); - // 2.2、检查活动商品库存是否充足 - boolean isSufficient = product == null || (product.getStock() == 0 || (product.getStock() < count) || (product.getStock() - count) < 0); - if (isSufficient) { - throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); - } - - // 3、更新活动商品库存 - int updateCount = seckillProductMapper.updateActivityStock(product.getId(), count); + // 2.1 更新活动商品库存 + int updateCount = seckillProductMapper.updateStock(product.getId(), count); if (updateCount == 0) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } - // 4、更新活动库存 - updateCount = seckillActivityMapper.updateActivityStock(seckillActivity.getId(), count); + // 2.2 更新活动库存 + updateCount = seckillActivityMapper.updateStock(seckillActivity.getId(), count); if (updateCount == 0) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java index 733ec9780..910e8c911 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java @@ -106,7 +106,7 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { if (order == null) { throw exception(ORDER_NOT_FOUND); } - + // 查询物流 return getExpressTrackList(order); } @@ -117,7 +117,7 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { if (order == null) { throw exception(ORDER_NOT_FOUND); } - + // 查询物流 return getExpressTrackList(order); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java index 72def213d..18a276fde 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java @@ -20,14 +20,17 @@ public class TradeBargainHandler implements TradeOrderHandler { @Resource private BargainActivityApi bargainActivityApi; + // TODO @puhui999:先临时写在这里;在价格计算时,如果是秒杀商品,需要校验如下条件: + // 1. 商品存在、库存充足、单次限购; + // 2. 活动进行中、时间段符合 + @Override public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { // 如果是砍价订单 if (ObjectUtil.notEqual(TradeOrderTypeEnum.BARGAIN.getType(), reqBO.getOrderType())) { return; } - - // 额外扣减砍价的库存 + // 扣减砍价活动的库存 bargainActivityApi.updateBargainActivityStock(reqBO.getBargainActivityId(), reqBO.getCount()); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java index b747e35d4..47426dd9b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java @@ -24,9 +24,12 @@ public interface TradeOrderHandler { */ void afterOrderCreate(TradeAfterOrderCreateReqBO reqBO); + // TODO @puhui999:这个搞成订单取消 /** * 回滚 */ void rollback(); + // TODO @puhui999:再搞个订单项取消哈 + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java index ce1dfdb05..652717b77 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java @@ -20,13 +20,17 @@ public class TradeSeckillHandler implements TradeOrderHandler { @Resource private SeckillActivityApi seckillActivityApi; + // TODO @puhui999:先临时写在这里;在价格计算时,如果是秒杀商品,需要校验如下条件: + // 1. 商品存在、库存充足、单次限购; + // 2. 活动进行中、时间段符合 + @Override public void beforeOrderCreate(TradeBeforeOrderCreateReqBO reqBO) { // 如果是秒杀订单:额外扣减秒杀的库存; if (ObjectUtil.notEqual(TradeOrderTypeEnum.SECKILL.getType(), reqBO.getOrderType())) { return; } - + // 扣减秒杀活动的库存 seckillActivityApi.updateSeckillStock(reqBO.getSeckillActivityId(), reqBO.getSkuId(), reqBO.getCount()); } From bf0e7d2c7747b6e14a122df37f6bae559f95039b Mon Sep 17 00:00:00 2001 From: owen Date: Sat, 23 Sep 2023 23:42:20 +0800 Subject: [PATCH 28/42] =?UTF-8?q?System=EF=BC=9A=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=97=E8=A1=A8=E8=BF=87=E6=BB=A4=E5=B7=B2?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/system/service/dict/DictDataServiceImpl.java | 2 +- .../system/service/dict/DictDataServiceImplTest.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java index eccd2c219..7cca762f4 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java @@ -49,7 +49,7 @@ public class DictDataServiceImpl implements DictDataService { @Override public List getDictDataList() { - List list = dictDataMapper.selectList(); + List list = dictDataMapper.selectList(DictDataDO::getStatus, CommonStatusEnum.ENABLE.getStatus()); list.sort(COMPARATOR_TYPE_AND_SORT); return list; } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java index 1e4dc9f90..bb962b0dd 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImplTest.java @@ -43,10 +43,15 @@ public class DictDataServiceImplTest extends BaseDbUnitTest { @Test public void testGetDictDataList() { // mock 数据 - DictDataDO dictDataDO01 = randomDictDataDO().setDictType("yunai").setSort(2); + DictDataDO dictDataDO01 = randomDictDataDO().setDictType("yunai").setSort(2) + .setStatus(CommonStatusEnum.ENABLE.getStatus()); dictDataMapper.insert(dictDataDO01); - DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setSort(1); + DictDataDO dictDataDO02 = randomDictDataDO().setDictType("yunai").setSort(1) + .setStatus(CommonStatusEnum.ENABLE.getStatus()); dictDataMapper.insert(dictDataDO02); + DictDataDO dictDataDO03 = randomDictDataDO().setDictType("yunai").setSort(3) + .setStatus(CommonStatusEnum.DISABLE.getStatus()); + dictDataMapper.insert(dictDataDO03); // 准备参数 // 调用 From 53e789dfdcfe27c7cf43d96f194e2237d6dea22f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 23 Sep 2023 23:58:22 +0800 Subject: [PATCH 29/42] =?UTF-8?q?trade=EF=BC=9A=E8=AE=A2=E5=8D=95=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=20vip=20=E4=BC=98=E6=83=A0=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/common/PromotionTypeEnum.java | 2 +- .../convert/order/TradeOrderConvert.java | 1 + .../dal/dataobject/order/TradeOrderDO.java | 5 + .../dataobject/order/TradeOrderItemDO.java | 5 + .../price/bo/TradePriceCalculateRespBO.java | 10 ++ .../TradeMemberLevelPriceCalculator.java | 82 +++++++++++++ .../calculator/TradePriceCalculator.java | 1 + .../TradePriceCalculatorHelper.java | 12 +- .../TradeMemberLevelPriceCalculatorTest.java | 116 ++++++++++++++++++ .../member/api/level/MemberLevelApi.java | 9 ++ .../api/level/dto/MemberLevelRespDTO.java | 41 +++++++ .../api/user/dto/MemberUserRespDTO.java | 7 ++ .../member/api/level/MemberLevelApiImpl.java | 7 ++ .../convert/level/MemberLevelConvert.java | 3 + 14 files changed, 297 insertions(+), 4 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java create mode 100644 yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/dto/MemberLevelRespDTO.java diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java index 874651ea3..628f6fe9f 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/common/PromotionTypeEnum.java @@ -22,7 +22,7 @@ public enum PromotionTypeEnum implements IntArrayValuable { DISCOUNT_ACTIVITY(4, "限时折扣"), REWARD_ACTIVITY(5, "满减送"), - MEMBER(6, "会员折扣"), + MEMBER_LEVEL(6, "会员折扣"), COUPON(7, "优惠劵") ; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index aa78cd170..85d9fa39a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -65,6 +65,7 @@ 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.vipPrice", target = "vipPrice"), @Mapping(source = "calculateRespBO.price.payPrice", target = "payPrice") }) TradeOrderDO convert(Long userId, String userIp, AppTradeOrderCreateReqVO createReqVO, diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java index bb68fc1ac..52f8c794d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java @@ -168,6 +168,7 @@ public class TradeOrderDO extends BaseDO { * - {@link #discountPrice} * + {@link #deliveryPrice} * + {@link #adjustPrice} + * - {@link #vipPrice} */ private Integer payPrice; @@ -269,5 +270,9 @@ public class TradeOrderDO extends BaseDO { // * 奖励的积分 TODO 疯狂:可以使用这个字段哈; // */ // private Integer rewardPoint; + /** + * VIP 减免金额,单位:分 + */ + private Integer vipPrice; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java index 27dd13f67..760471d3a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java @@ -126,6 +126,7 @@ public class TradeOrderItemDO extends BaseDO { * - {@link #discountPrice} * + {@link #deliveryPrice} * + {@link #adjustPrice} + * - {@link #vipPrice} */ private Integer payPrice; @@ -143,6 +144,10 @@ public class TradeOrderItemDO extends BaseDO { * 对应 taobao 的 trade.point_fee 字段 */ private Integer pointPrice; + /** + * VIP 减免金额,单位:分 + */ + private Integer vipPrice; // TODO @芋艿:如果商品 vip 折扣时,到底是新增一个 vipPrice 记录优惠记录,还是 vipDiscountPrice,记录 vip 的优惠;还是直接使用 vipPrice; // 目前 crmeb 的选择,单独一个 vipPrice 记录优惠价格;感觉不一定合理,可以在看看有赞的; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java index 1171cd8f2..6820059a7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateRespBO.java @@ -89,6 +89,10 @@ public class TradePriceCalculateRespBO { * 对应 taobao 的 trade.point_fee 字段 */ private Integer pointPrice; + /** + * VIP 减免金额,单位:分 + */ + private Integer vipPrice; /** * 最终购买金额(总),单位:分 * @@ -97,6 +101,7 @@ public class TradePriceCalculateRespBO { * - {@link #pointPrice} * - {@link #discountPrice} * + {@link #deliveryPrice} + * - {@link #vipPrice} */ private Integer payPrice; @@ -158,6 +163,10 @@ public class TradePriceCalculateRespBO { * 对应 taobao 的 trade.point_fee 字段 */ private Integer pointPrice; + /** + * VIP 减免金额,单位:分 + */ + private Integer vipPrice; /** * 应付金额(总),单位:分 * @@ -166,6 +175,7 @@ public class TradePriceCalculateRespBO { * - {@link #pointPrice} * - {@link #discountPrice} * + {@link #deliveryPrice} + * - {@link #vipPrice} */ private Integer payPrice; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java new file mode 100644 index 000000000..7bf0d1d29 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.trade.service.price.calculator; + +import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculatorHelper.formatPrice; + +/** + * 会员 VIP 折扣的 {@link TradePriceCalculator} 实现类 + * + * @author 芋道源码 + */ +@Component +@Order(TradePriceCalculator.ORDER_MEMBER_LEVEL) +public class TradeMemberLevelPriceCalculator implements TradePriceCalculator { + + @Resource + private MemberLevelApi memberLevelApi; + @Resource + private MemberUserApi memberUserApi; + + @Override + public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // 1. 获得用户的会员等级 + MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); + if (user.getLevelId() == null || user.getLevelId() <= 0) { + return; + } + MemberLevelRespDTO level = memberLevelApi.getMemberLevel(user.getLevelId()); + if (level == null || level.getDiscountPercent() == null) { + return; + } + + // 2. 计算每个 SKU 的优惠金额 + result.getItems().forEach(orderItem -> { + // 2.1 计算优惠金额 + Integer vipPrice = calculateVipPrice(orderItem.getPayPrice(), level.getDiscountPercent()); + if (vipPrice <= 0) { + return; + } + + // 2.2 记录优惠明细 + if (orderItem.getSelected()) { + // 注意,只有在选中的情况下,才会记录到优惠明细。否则仅仅是更新 SKU 优惠金额,用于展示 + TradePriceCalculatorHelper.addPromotion(result, orderItem, + level.getId(), level.getName(), PromotionTypeEnum.MEMBER_LEVEL.getType(), + String.format("会员等级折扣:省 %s 元", formatPrice(vipPrice)), + vipPrice); + } + + // 2.3 更新 SKU 的优惠金额 + orderItem.setVipPrice(vipPrice); + TradePriceCalculatorHelper.recountPayPrice(orderItem); + }); + TradePriceCalculatorHelper.recountAllPrice(result); + } + + /** + * 计算会员 VIP 优惠价格 + * + * @param price 原价 + * @param discountPercent 折扣 + * @return 优惠价格 + */ + public Integer calculateVipPrice(Integer price, Integer discountPercent) { + if (discountPercent == null) { + return 0; + } + Integer newPrice = price * discountPercent / 100; + return price - newPrice; + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java index cddc1ea21..fa647aea9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculator.java @@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; */ public interface TradePriceCalculator { + int ORDER_MEMBER_LEVEL = 5; int ORDER_DISCOUNT_ACTIVITY = 10; int ORDER_REWARD_ACTIVITY = 20; int ORDER_COUPON = 30; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java index b8b9e0fb9..df047122c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradePriceCalculatorHelper.java @@ -52,7 +52,7 @@ public class TradePriceCalculatorHelper { .setCount(item.getCount()).setCartId(item.getCartId()).setSelected(item.getSelected()); // sku 价格 orderItem.setPrice(sku.getPrice()).setPayPrice(sku.getPrice() * item.getCount()) - .setDiscountPrice(0).setDeliveryPrice(0).setCouponPrice(0).setPointPrice(0); + .setDiscountPrice(0).setDeliveryPrice(0).setCouponPrice(0).setPointPrice(0).setVipPrice(0); // sku 信息 orderItem.setPicUrl(sku.getPicUrl()).setProperties(sku.getProperties()) .setWeight(sku.getWeight()).setVolume(sku.getVolume()); @@ -96,7 +96,7 @@ public class TradePriceCalculatorHelper { // 先重置 TradePriceCalculateRespBO.Price price = result.getPrice(); price.setTotalPrice(0).setDiscountPrice(0).setDeliveryPrice(0) - .setCouponPrice(0).setPointPrice(0).setPayPrice(0); + .setCouponPrice(0).setPointPrice(0).setVipPrice(0).setPayPrice(0); // 再合计 item result.getItems().forEach(item -> { if (!item.getSelected()) { @@ -107,6 +107,7 @@ public class TradePriceCalculatorHelper { price.setDeliveryPrice(price.getDeliveryPrice() + item.getDeliveryPrice()); price.setCouponPrice(price.getCouponPrice() + item.getCouponPrice()); price.setPointPrice(price.getPointPrice() + item.getPointPrice()); + price.setVipPrice(price.getVipPrice() + item.getVipPrice()); price.setPayPrice(price.getPayPrice() + item.getPayPrice()); }); } @@ -121,7 +122,9 @@ public class TradePriceCalculatorHelper { - orderItem.getDiscountPrice() + orderItem.getDeliveryPrice() - orderItem.getCouponPrice() - - orderItem.getPointPrice()); + - orderItem.getPointPrice() + - orderItem.getVipPrice() + ); } /** @@ -145,6 +148,9 @@ public class TradePriceCalculatorHelper { if (orderItem.getPointPrice() == null) { orderItem.setPointPrice(0); } + if (orderItem.getVipPrice() == null) { + orderItem.setVipPrice(0); + } recountPayPrice(orderItem); }); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java new file mode 100644 index 000000000..568940366 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java @@ -0,0 +1,116 @@ +package cn.iocoder.yudao.module.trade.service.price.calculator; + +import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; +import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; +import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +import java.util.ArrayList; + +import static java.util.Arrays.asList; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +/** + * {@link TradeMemberLevelPriceCalculator} 的单元测试类 + * + * @author 芋道源码 + */ +public class TradeMemberLevelPriceCalculatorTest extends BaseMockitoUnitTest { + + @InjectMocks + private TradeMemberLevelPriceCalculator memberLevelPriceCalculator; + + @Mock + private MemberLevelApi memberLevelApi; + @Mock + private MemberUserApi memberUserApi; + + @Test + public void testCalculate() { + // 准备参数 + TradePriceCalculateReqBO param = new TradePriceCalculateReqBO() + .setUserId(1024L) + .setItems(asList( + new TradePriceCalculateReqBO.Item().setSkuId(10L).setCount(2).setSelected(true), // 匹配活动,且已选中 + new TradePriceCalculateReqBO.Item().setSkuId(20L).setCount(3).setSelected(false) // 匹配活动,但未选中 + )); + TradePriceCalculateRespBO result = new TradePriceCalculateRespBO() + .setPrice(new TradePriceCalculateRespBO.Price()) + .setPromotions(new ArrayList<>()) + .setItems(asList( + new TradePriceCalculateRespBO.OrderItem().setSkuId(10L).setCount(2).setSelected(true) + .setPrice(100), + new TradePriceCalculateRespBO.OrderItem().setSkuId(20L).setCount(3).setSelected(false) + .setPrice(50) + )); + // 保证价格被初始化上 + TradePriceCalculatorHelper.recountPayPrice(result.getItems()); + TradePriceCalculatorHelper.recountAllPrice(result); + + // mock 方法(会员等级) + when(memberUserApi.getUser(eq(1024L))).thenReturn(new MemberUserRespDTO().setLevelId(2048L)); + when(memberLevelApi.getMemberLevel(eq(2048L))).thenReturn( + new MemberLevelRespDTO().setId(2048L).setName("VIP 会员").setDiscountPercent(60)); + + // 调用 + memberLevelPriceCalculator.calculate(param, result); + // 断言:Price 部分 + TradePriceCalculateRespBO.Price price = result.getPrice(); + assertEquals(price.getTotalPrice(), 200); + assertEquals(price.getDiscountPrice(), 0); + assertEquals(price.getPointPrice(), 0); + assertEquals(price.getDeliveryPrice(), 0); + assertEquals(price.getCouponPrice(), 0); + assertEquals(price.getVipPrice(), 80); + assertEquals(price.getPayPrice(), 120); + assertNull(result.getCouponId()); + // 断言:SKU 1 + assertEquals(result.getItems().size(), 2); + TradePriceCalculateRespBO.OrderItem orderItem01 = result.getItems().get(0); + assertEquals(orderItem01.getSkuId(), 10L); + assertEquals(orderItem01.getCount(), 2); + assertEquals(orderItem01.getPrice(), 100); + assertEquals(orderItem01.getDiscountPrice(), 0); + assertEquals(orderItem01.getDeliveryPrice(), 0); + assertEquals(orderItem01.getCouponPrice(), 0); + assertEquals(orderItem01.getPointPrice(), 0); + assertEquals(orderItem01.getVipPrice(), 80); + assertEquals(orderItem01.getPayPrice(), 120); + // 断言:SKU 2 + TradePriceCalculateRespBO.OrderItem orderItem02 = result.getItems().get(1); + assertEquals(orderItem02.getSkuId(), 20L); + assertEquals(orderItem02.getCount(), 3); + assertEquals(orderItem02.getPrice(), 50); + assertEquals(orderItem02.getDiscountPrice(), 0); + assertEquals(orderItem02.getDeliveryPrice(), 0); + assertEquals(orderItem02.getCouponPrice(), 0); + assertEquals(orderItem02.getPointPrice(), 0); + assertEquals(orderItem02.getVipPrice(), 60); + assertEquals(orderItem02.getPayPrice(), 90); + // 断言:Promotion 部分 + assertEquals(result.getPromotions().size(), 1); + TradePriceCalculateRespBO.Promotion promotion01 = result.getPromotions().get(0); + assertEquals(promotion01.getId(), 2048L); + assertEquals(promotion01.getName(), "VIP 会员"); + assertEquals(promotion01.getType(), PromotionTypeEnum.MEMBER_LEVEL.getType()); + assertEquals(promotion01.getTotalPrice(), 200); + assertEquals(promotion01.getDiscountPrice(), 80); + assertTrue(promotion01.getMatch()); + assertEquals(promotion01.getDescription(), "会员等级折扣:省 0.80 元"); + TradePriceCalculateRespBO.PromotionItem promotionItem01 = promotion01.getItems().get(0); + assertEquals(promotion01.getItems().size(), 1); + assertEquals(promotionItem01.getSkuId(), 10L); + assertEquals(promotionItem01.getTotalPrice(), 200); + assertEquals(promotionItem01.getDiscountPrice(), 80); + } + +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java index 2091189a2..1ddd899cb 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.member.api.level; +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; /** @@ -9,6 +10,14 @@ import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; */ public interface MemberLevelApi { + /** + * 获得会员等级 + * + * @param id 会员等级编号 + * @return 会员等级 + */ + MemberLevelRespDTO getMemberLevel(Long id); + /** * 增加会员经验 * diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/dto/MemberLevelRespDTO.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/dto/MemberLevelRespDTO.java new file mode 100644 index 000000000..a72d65f23 --- /dev/null +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/dto/MemberLevelRespDTO.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.member.api.level.dto; + +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import lombok.Data; + +/** + * 会员等级 Resp DTO + * + * @author 芋道源码 + */ +@Data +public class MemberLevelRespDTO { + + /** + * 编号 + */ + private Long id; + /** + * 等级名称 + */ + private String name; + /** + * 等级 + */ + private Integer level; + /** + * 升级经验 + */ + private Integer experience; + /** + * 享受折扣 + */ + private Integer discountPercent; + /** + * 状态 + * + * 枚举 {@link CommonStatusEnum} + */ + private Integer status; + +} diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java index 10d96365f..c8cedb06f 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java @@ -34,4 +34,11 @@ public class MemberUserRespDTO { */ private String mobile; + // ========== 其它信息 ========== + + /** + * 会员级别编号 + */ + private Long levelId; + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java index 3cd2cad65..519a8e8a1 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.member.api.level; +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; +import cn.iocoder.yudao.module.member.convert.level.MemberLevelConvert; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; import cn.iocoder.yudao.module.member.service.level.MemberLevelService; import org.springframework.stereotype.Service; @@ -22,6 +24,11 @@ public class MemberLevelApiImpl implements MemberLevelApi { @Resource private MemberLevelService memberLevelService; + @Override + public MemberLevelRespDTO getMemberLevel(Long id) { + return MemberLevelConvert.INSTANCE.convert02(memberLevelService.getLevel(id)); + } + @Override public void addExperience(Long userId, Integer experience, Integer bizType, String bizId) { MemberExperienceBizTypeEnum bizTypeEnum = MemberExperienceBizTypeEnum.getByType(bizType); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java index 073f76027..f2282815e 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/level/MemberLevelConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.member.convert.level; +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelCreateReqVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelRespVO; import cn.iocoder.yudao.module.member.controller.admin.level.vo.level.MemberLevelSimpleRespVO; @@ -33,4 +34,6 @@ public interface MemberLevelConvert { List convertList02(List list); + MemberLevelRespDTO convert02(MemberLevelDO bean); + } From b4587fd79e5f58cfe52544c87f4146d9c2fdb235 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 24 Sep 2023 00:45:32 +0800 Subject: [PATCH 30/42] =?UTF-8?q?product=EF=BC=9A=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=A1=A8=EF=BC=8C=E5=A2=9E=E5=8A=A0=20vip=20=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao-module-product-biz/pom.xml | 6 -- .../property/ProductPropertyValueApiImpl.java | 2 +- .../ProductPropertyValueController.java | 7 +- .../app/spu/AppProductSpuController.java | 72 +++++++++++++++++-- .../ProductPropertyValueConvert.java | 2 +- .../convert/spu/ProductSpuConvert.java | 7 -- .../yudao/module/product/package-info.java | 2 +- .../ProductPropertyValueServiceImpl.java | 2 +- .../trade/enums/ErrorCodeConstants.java | 2 - .../vo/AppTradeOrderSettlementRespVO.java | 3 + .../TradeDeliveryPriceCalculator.java | 6 +- .../TradeDiscountActivityPriceCalculator.java | 6 ++ .../TradeMemberLevelPriceCalculator.java | 6 ++ .../TradeRewardActivityPriceCalculator.java | 6 ++ ...deDiscountActivityPriceCalculatorTest.java | 2 + .../TradeMemberLevelPriceCalculatorTest.java | 2 + ...radeRewardActivityPriceCalculatorTest.java | 3 + 17 files changed, 103 insertions(+), 33 deletions(-) rename yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/{propertyvalue => property}/ProductPropertyValueConvert.java (97%) diff --git a/yudao-module-mall/yudao-module-product-biz/pom.xml b/yudao-module-mall/yudao-module-product-biz/pom.xml index 674f49fc4..f6190ceda 100644 --- a/yudao-module-mall/yudao-module-product-biz/pom.xml +++ b/yudao-module-mall/yudao-module-product-biz/pom.xml @@ -23,12 +23,6 @@ yudao-module-product-api ${revision} - - - cn.iocoder.boot - yudao-module-trade-api - ${revision} - cn.iocoder.boot yudao-module-member-api diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/property/ProductPropertyValueApiImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/property/ProductPropertyValueApiImpl.java index 9aab9e560..d3eaaf42d 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/property/ProductPropertyValueApiImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/api/property/ProductPropertyValueApiImpl.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.product.api.property; import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; -import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert; +import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert; import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java index fbac32712..54ce881d1 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/property/ProductPropertyValueController.java @@ -1,14 +1,12 @@ package cn.iocoder.yudao.module.product.controller.admin.property; -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.crypto.symmetric.AES; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO; -import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert; +import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert; import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -20,9 +18,6 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.Arrays; -import java.util.List; - import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Tag(name = "管理后台 - 商品属性值") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java index 5d79ba7d1..3c9d8f8be 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/spu/AppProductSpuController.java @@ -1,10 +1,15 @@ package cn.iocoder.yudao.module.product.controller.app.spu; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; +import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuDetailRespVO; -import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageRespVO; import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageReqVO; +import cn.iocoder.yudao.module.product.controller.app.spu.vo.AppProductSpuPageRespVO; import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert; import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; @@ -23,10 +28,12 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.Collections; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_ENABLE; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; @@ -41,6 +48,11 @@ public class AppProductSpuController { @Resource private ProductSkuService productSkuService; + @Resource + private MemberLevelApi memberLevelApi; + @Resource + private MemberUserApi memberUserApi; + @GetMapping("/list") @Operation(summary = "获得商品 SPU 列表") @Parameters({ @@ -51,14 +63,32 @@ public class AppProductSpuController { @RequestParam("recommendType") String recommendType, @RequestParam(value = "count", defaultValue = "10") Integer count) { List list = productSpuService.getSpuList(recommendType, count); - return success(ProductSpuConvert.INSTANCE.convertListForGetSpuList(list)); + if (CollUtil.isEmpty(list)) { + return success(Collections.emptyList()); + } + + // 拼接返回 + List voList = ProductSpuConvert.INSTANCE.convertListForGetSpuList(list); + // 处理 vip 价格 + MemberLevelRespDTO memberLevel = getMemberLevel(); + voList.forEach(vo -> vo.setVipPrice(calculateVipPrice(vo.getPrice(), memberLevel))); + return success(voList); } @GetMapping("/page") @Operation(summary = "获得商品 SPU 分页") public CommonResult> getSpuPage(@Valid AppProductSpuPageReqVO pageVO) { PageResult pageResult = productSpuService.getSpuPage(pageVO); - return success(ProductSpuConvert.INSTANCE.convertPageForGetSpuPage(pageResult)); + if (CollUtil.isEmpty(pageResult.getList())) { + return success(PageResult.empty(pageResult.getTotal())); + } + + // 拼接返回 + PageResult voPageResult = ProductSpuConvert.INSTANCE.convertPageForGetSpuPage(pageResult); + // 处理 vip 价格 + MemberLevelRespDTO memberLevel = getMemberLevel(); + voPageResult.getList().forEach(vo -> vo.setVipPrice(calculateVipPrice(vo.getPrice(), memberLevel))); + return success(voPageResult); } @GetMapping("/get-detail") @@ -74,10 +104,40 @@ public class AppProductSpuController { throw exception(SPU_NOT_ENABLE); } - // 查询商品 SKU + // 拼接返回 List skus = productSkuService.getSkuListBySpuId(spu.getId()); - // 拼接 - return success(ProductSpuConvert.INSTANCE.convertForGetSpuDetail(spu, skus)); + AppProductSpuDetailRespVO detailVO = ProductSpuConvert.INSTANCE.convertForGetSpuDetail(spu, skus); + // 处理 vip 价格 + MemberLevelRespDTO memberLevel = getMemberLevel(); + detailVO.setVipPrice(calculateVipPrice(detailVO.getPrice(), memberLevel)); + return success(detailVO); + } + + private MemberLevelRespDTO getMemberLevel() { + Long userId = getLoginUserId(); + if (userId == null) { + return null; + } + MemberUserRespDTO user = memberUserApi.getUser(userId); + if (user.getLevelId() == null || user.getLevelId() <= 0) { + return null; + } + return memberLevelApi.getMemberLevel(user.getLevelId()); + } + + /** + * 计算会员 VIP 优惠价格 + * + * @param price 原价 + * @param memberLevel 会员等级 + * @return 优惠价格 + */ + public Integer calculateVipPrice(Integer price, MemberLevelRespDTO memberLevel) { + if (memberLevel == null || memberLevel.getDiscountPercent() == null) { + return 0; + } + Integer newPrice = price * memberLevel.getDiscountPercent() / 100; + return price - newPrice; } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/propertyvalue/ProductPropertyValueConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyValueConvert.java similarity index 97% rename from yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/propertyvalue/ProductPropertyValueConvert.java rename to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyValueConvert.java index d6167c174..5429f35fe 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/propertyvalue/ProductPropertyValueConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/property/ProductPropertyValueConvert.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.product.convert.propertyvalue; +package cn.iocoder.yudao.module.product.convert.property; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java index 6d52e5cad..e8e6a8bc1 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/spu/ProductSpuConvert.java @@ -79,8 +79,6 @@ public interface ProductSpuConvert { ProductSpuDO spu = list.get(i); AppProductSpuPageRespVO spuVO = voList.get(i); spuVO.setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); - // 计算 vip 价格 TODO 芋艿:临时的逻辑,等 vip 支持后 - spuVO.setVipPrice((int) (spuVO.getPrice() * 0.9)); } return voList; } @@ -95,11 +93,6 @@ public interface ProductSpuConvert { .setUnitName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.PRODUCT_UNIT, spu.getUnit())); // 处理 SKU spuVO.setSkus(convertListForGetSpuDetail(skus)); - // 计算 vip 价格 TODO 芋艿:临时的逻辑,等 vip 支持后 - if (true) { - spuVO.setVipPrice((int) (spuVO.getPrice() * 0.9)); - spuVO.getSkus().forEach(sku -> sku.setVipPrice((int) (sku.getPrice() * 0.9))); - } return spuVO; } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/package-info.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/package-info.java index 01967857e..e32942933 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/package-info.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/package-info.java @@ -1,5 +1,5 @@ /** - * trade 模块,主要实现交易相关功能 + * product 模块,主要实现交易相关功能 * 例如:订单、退款、购物车等功能。 * * 1. Controller URL:以 /product/ 开头,避免和其它 Module 冲突 diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java index 6b4d1e9c8..0f74bca1f 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/property/ProductPropertyValueServiceImpl.java @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO; import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO; -import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert; +import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO; import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO; import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyValueMapper; diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index ffdba1fcf..6ba8ac37a 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -53,9 +53,7 @@ public interface ErrorCodeConstants { // ========== Price 相关 1011003000 ============ ErrorCode PRICE_CALCULATE_PAY_PRICE_ILLEGAL = new ErrorCode(1011003000, "支付价格计算异常,原因:价格小于等于 0"); - ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDRESS_IS_EMPTY = new ErrorCode(1011003001, "计算快递运费异常,收件人地址编号为空"); ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1011003002, "计算快递运费异常,找不到对应的运费模板"); - ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_PICK_UP_STORE_IS_EMPTY = new ErrorCode(1011003003, "计算快递运费异常,自提点为空"); ErrorCode PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER = new ErrorCode(1011003004, "参与秒杀、拼团、砍价的营销商品,无法使用优惠劵"); // ========== 物流 Express 模块 1011004000 ========== diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementRespVO.java index bd0312753..4b5d98a37 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementRespVO.java @@ -82,6 +82,9 @@ public class AppTradeOrderSettlementRespVO { @Schema(description = "积分抵扣的金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50") private Integer pointPrice; + @Schema(description = "VIP 减免金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "30") + private Integer vipPrice; + @Schema(description = "实际支付金额(总),单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "450") private Integer payPrice; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java index 20c3feee3..01796ad0e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDeliveryPriceCalculator.java @@ -64,7 +64,8 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { private void calculateByPickUp(TradePriceCalculateReqBO param) { if (param.getPickUpStoreId() == null) { - throw exception(PRICE_CALCULATE_DELIVERY_PRICE_PICK_UP_STORE_IS_EMPTY); + // 价格计算时,如果为空就不算~最终下单,会校验该字段不允许空 + return; } DeliveryPickUpStoreDO pickUpStore = deliveryPickUpStoreService.getDeliveryPickUpStore(param.getPickUpStoreId()); if (pickUpStore == null || CommonStatusEnum.DISABLE.getStatus().equals(pickUpStore.getStatus())) { @@ -77,7 +78,8 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator { private void calculateExpress(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { // 0. 得到收件地址区域 if (param.getAddressId() == null) { - throw exception(PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDRESS_IS_EMPTY); + // 价格计算时,如果为空就不算~最终下单,会校验该字段不允许空 + return; } AddressRespDTO address = addressApi.getAddress(param.getAddressId(), param.getUserId()); Assert.notNull(address, "收件人({})的地址,不能为空", param.getUserId()); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java index fe465f37d..a42780625 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculator.java @@ -1,11 +1,13 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.module.promotion.api.discount.DiscountActivityApi; import cn.iocoder.yudao.module.promotion.api.discount.dto.DiscountProductRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.springframework.core.annotation.Order; @@ -33,6 +35,10 @@ public class TradeDiscountActivityPriceCalculator implements TradePriceCalculato @Override public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // 0. 只有【普通】订单,才计算该优惠 + if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) { + return; + } // 获得 SKU 对应的限时折扣活动 List discountProducts = discountActivityApi.getMatchDiscountProductList( convertSet(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSkuId)); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java index 7bf0d1d29..8aee001d5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculator.java @@ -1,10 +1,12 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.springframework.core.annotation.Order; @@ -30,6 +32,10 @@ public class TradeMemberLevelPriceCalculator implements TradePriceCalculator { @Override public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // 0. 只有【普通】订单,才计算该优惠 + if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) { + return; + } // 1. 获得用户的会员等级 MemberUserRespDTO user = memberUserApi.getUser(param.getUserId()); if (user.getLevelId() == null || user.getLevelId() <= 0) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculator.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculator.java index f2cfe71cd..d9b44c2b6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculator.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculator.java @@ -1,11 +1,13 @@ package cn.iocoder.yudao.module.trade.service.price.calculator; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.module.promotion.api.reward.RewardActivityApi; import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.springframework.core.annotation.Order; @@ -32,6 +34,10 @@ public class TradeRewardActivityPriceCalculator implements TradePriceCalculator @Override public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { + // 0. 只有【普通】订单,才计算该优惠 + if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) { + return; + } // 获得 SKU 对应的满减送活动 List rewardActivities = rewardActivityApi.getMatchRewardActivityList( convertSet(result.getItems(), TradePriceCalculateRespBO.OrderItem::getSpuId)); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculatorTest.java index 9175e1643..21760217c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeDiscountActivityPriceCalculatorTest.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.promotion.api.discount.DiscountActivityApi; import cn.iocoder.yudao.module.promotion.api.discount.dto.DiscountProductRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.junit.jupiter.api.Test; @@ -42,6 +43,7 @@ public class TradeDiscountActivityPriceCalculatorTest extends BaseMockitoUnitTes new TradePriceCalculateReqBO.Item().setSkuId(20L).setCount(3).setSelected(false) // 匹配活动,但未选中 )); TradePriceCalculateRespBO result = new TradePriceCalculateRespBO() + .setType(TradeOrderTypeEnum.NORMAL.getType()) .setPrice(new TradePriceCalculateRespBO.Price()) .setPromotions(new ArrayList<>()) .setItems(asList( diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java index 568940366..44e783103 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeMemberLevelPriceCalculatorTest.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.member.api.level.dto.MemberLevelRespDTO; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.junit.jupiter.api.Test; @@ -44,6 +45,7 @@ public class TradeMemberLevelPriceCalculatorTest extends BaseMockitoUnitTest { new TradePriceCalculateReqBO.Item().setSkuId(20L).setCount(3).setSelected(false) // 匹配活动,但未选中 )); TradePriceCalculateRespBO result = new TradePriceCalculateRespBO() + .setType(TradeOrderTypeEnum.NORMAL.getType()) .setPrice(new TradePriceCalculateRespBO.Price()) .setPromotions(new ArrayList<>()) .setItems(asList( diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculatorTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculatorTest.java index 30107d5b4..de72ed616 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculatorTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculatorTest.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.promotion.api.reward.RewardActivityApi; import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO; import cn.iocoder.yudao.module.promotion.enums.common.PromotionConditionTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; +import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import org.junit.jupiter.api.Test; @@ -44,6 +45,7 @@ public class TradeRewardActivityPriceCalculatorTest extends BaseMockitoUnitTest new TradePriceCalculateReqBO.Item().setSkuId(30L).setCount(4).setSelected(true) // 匹配活动 2 )); TradePriceCalculateRespBO result = new TradePriceCalculateRespBO() + .setType(TradeOrderTypeEnum.NORMAL.getType()) .setPrice(new TradePriceCalculateRespBO.Price()) .setPromotions(new ArrayList<>()) .setItems(asList( @@ -157,6 +159,7 @@ public class TradeRewardActivityPriceCalculatorTest extends BaseMockitoUnitTest new TradePriceCalculateReqBO.Item().setSkuId(30L).setCount(4).setSelected(true) )); TradePriceCalculateRespBO result = new TradePriceCalculateRespBO() + .setType(TradeOrderTypeEnum.NORMAL.getType()) .setPrice(new TradePriceCalculateRespBO.Price()) .setPromotions(new ArrayList<>()) .setItems(asList( From 29b806e675a16542998bb5da7730930884dd9487 Mon Sep 17 00:00:00 2001 From: owen Date: Sun, 24 Sep 2023 09:57:09 +0800 Subject: [PATCH 31/42] =?UTF-8?q?Framework=EF=BC=9A=E5=A2=9E=E5=8A=A0Local?= =?UTF-8?q?Date=E3=80=81LocalTime=E5=BA=8F=E5=88=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/YudaoJacksonAutoConfiguration.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java index 56f9aeaa6..40b446b28 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java @@ -1,18 +1,24 @@ package cn.iocoder.yudao.framework.jackson.config; -import cn.iocoder.yudao.framework.jackson.core.databind.NumberSerializer; +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeDeserializer; import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeSerializer; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; +import cn.iocoder.yudao.framework.jackson.core.databind.NumberSerializer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.context.annotation.Bean; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; @AutoConfiguration @Slf4j @@ -36,6 +42,10 @@ public class YudaoJacksonAutoConfiguration { simpleModule .addSerializer(Long.class, NumberSerializer.INSTANCE) .addSerializer(Long.TYPE, NumberSerializer.INSTANCE) + .addSerializer(LocalDate.class, LocalDateSerializer.INSTANCE) + .addDeserializer(LocalDate.class, LocalDateDeserializer.INSTANCE) + .addSerializer(LocalTime.class, LocalTimeSerializer.INSTANCE) + .addDeserializer(LocalTime.class, LocalTimeDeserializer.INSTANCE) .addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE) .addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE); From 60f766f35cdf8b23f566fe4b8807e3769ac7e615 Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Sun, 24 Sep 2023 10:49:13 +0800 Subject: [PATCH 32/42] =?UTF-8?q?=E9=92=B1=E5=8C=85=E5=85=85=E5=80=BC?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E5=A4=9A=E6=AC=A1=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/pay/enums/ErrorCodeConstants.java | 30 +++++++++---------- .../service/wallet/PayWalletServiceImpl.java | 10 ++----- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java index 815c18fb9..df8ac53fc 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java @@ -44,23 +44,21 @@ public interface ErrorCodeConstants { ErrorCode WALLET_NOT_FOUND = new ErrorCode(1007007000, "用户钱包不存在"); ErrorCode WALLET_BALANCE_NOT_ENOUGH = new ErrorCode(1007007001, "钱包余额不足"); ErrorCode WALLET_TRANSACTION_NOT_FOUND = new ErrorCode(1007007002, "未找到对应的钱包交易"); - ErrorCode WALLET_REFUND_AMOUNT_ERROR = new ErrorCode(1007007003, "钱包退款金额不对"); - ErrorCode WALLET_REFUND_EXIST = new ErrorCode(1007007004, "已经存在钱包退款"); - ErrorCode WALLET_FREEZE_PRICE_NOT_ENOUGH = new ErrorCode(1007007005, "钱包冻结余额不足"); + ErrorCode WALLET_REFUND_EXIST = new ErrorCode(1007007003, "已经存在钱包退款"); + ErrorCode WALLET_FREEZE_PRICE_NOT_ENOUGH = new ErrorCode(1007007004, "钱包冻结余额不足"); - // TODO @jason:把钱包充值,单独搞个错误码段哈; - - ErrorCode WALLET_RECHARGE_NOT_FOUND = new ErrorCode(1007007005, "钱包充值记录不存在"); - ErrorCode WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1007007006, "钱包充值更新支付状态失败,钱包充值记录不是【未支付】状态"); - ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR = new ErrorCode(1007007007, "钱包充值更新支付状态失败,支付单编号不匹配"); - ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_STATUS_NOT_SUCCESS = new ErrorCode(1007007008, "钱包充值更新支付状态失败,支付单状态不是【支付成功】状态"); - ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_PRICE_NOT_MATCH = new ErrorCode(1007007009, "钱包充值更新支付状态失败,支付单金额不匹配"); - ErrorCode WALLET_RECHARGE_REFUND_FAIL_NOT_PAID = new ErrorCode(1007900010, "钱包发起退款失败,钱包充值订单未支付"); - ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUNDED = new ErrorCode(1007900011, "钱包发起退款失败,钱包充值订单已退款"); - ErrorCode WALLET_RECHARGE_REFUND_BALANCE_NOT_ENOUGH = new ErrorCode(1007900012, "钱包发起退款失败,钱包余额不足"); - ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_ORDER_ID_ERROR = new ErrorCode(1007900013, "钱包退款更新失败,钱包退款单编号不匹配"); - ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_NOT_FOUND = new ErrorCode(1007900014, "钱包退款更新失败,退款订单不存在"); - ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_PRICE_NOT_MATCH = new ErrorCode(1007900015, "钱包退款更新失败,退款单金额不匹配"); + // ========== 钱包充值模块 1007008000 ========== + ErrorCode WALLET_RECHARGE_NOT_FOUND = new ErrorCode(1007008000, "钱包充值记录不存在"); + ErrorCode WALLET_RECHARGE_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1007008001, "钱包充值更新支付状态失败,钱包充值记录不是【未支付】状态"); + ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_ID_ERROR = new ErrorCode(1007008002, "钱包充值更新支付状态失败,支付单编号不匹配"); + ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_ORDER_STATUS_NOT_SUCCESS = new ErrorCode(1007008003, "钱包充值更新支付状态失败,支付单状态不是【支付成功】状态"); + ErrorCode WALLET_RECHARGE_UPDATE_PAID_PAY_PRICE_NOT_MATCH = new ErrorCode(1007008004, "钱包充值更新支付状态失败,支付单金额不匹配"); + ErrorCode WALLET_RECHARGE_REFUND_FAIL_NOT_PAID = new ErrorCode(1007008005, "钱包发起退款失败,钱包充值订单未支付"); + ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUNDED = new ErrorCode(1007008006, "钱包发起退款失败,钱包充值订单已退款"); + ErrorCode WALLET_RECHARGE_REFUND_BALANCE_NOT_ENOUGH = new ErrorCode(1007008007, "钱包发起退款失败,钱包余额不足"); + ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_ORDER_ID_ERROR = new ErrorCode(1007008008, "钱包退款更新失败,钱包退款单编号不匹配"); + ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_NOT_FOUND = new ErrorCode(1007008009, "钱包退款更新失败,退款订单不存在"); + ErrorCode WALLET_RECHARGE_REFUND_FAIL_REFUND_PRICE_NOT_MATCH = new ErrorCode(1007008010, "钱包退款更新失败,退款单金额不匹配"); // ========== 示例订单 1007900000 ========== ErrorCode DEMO_ORDER_NOT_FOUND = new ErrorCode(1007900000, "示例订单不存在"); ErrorCode DEMO_ORDER_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1007900001, "示例订单更新支付状态失败,订单不是【未支付】状态"); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index 9a83ffb83..c14d20cfa 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -82,7 +82,7 @@ public class PayWalletServiceImpl implements PayWalletService { throw exception(REFUND_NOT_FOUND); } // 1.2 校验是否可以退款 - Long walletId = validateWalletCanRefund(payRefund.getId(), payRefund.getChannelOrderNo(), refundPrice); + Long walletId = validateWalletCanRefund(payRefund.getId(), payRefund.getChannelOrderNo()); PayWalletDO wallet = walletMapper.selectById(walletId); Assert.notNull(wallet, "钱包 {} 不存在", walletId); @@ -96,18 +96,12 @@ public class PayWalletServiceImpl implements PayWalletService { * @param refundId 支付退款单 id * @param walletPayNo 钱包支付 no */ - private Long validateWalletCanRefund(Long refundId, String walletPayNo, Integer refundPrice) { + private Long validateWalletCanRefund(Long refundId, String walletPayNo) { // 1. 校验钱包支付交易存在 PayWalletTransactionDO walletTransaction = walletTransactionService.getWalletTransactionByNo(walletPayNo); if (walletTransaction == null) { throw exception(WALLET_TRANSACTION_NOT_FOUND); } - // 原来的支付金额 - // TODO @jason:应该允许多次退款哈; - int amount = - walletTransaction.getPrice(); - if (refundPrice != amount) { - throw exception(WALLET_REFUND_AMOUNT_ERROR); - } PayWalletTransactionDO refundTransaction = walletTransactionService.getWalletTransaction( String.valueOf(refundId), PAYMENT_REFUND); if (refundTransaction != null) { From 421bb7d1548667fdc8844e59345d9ce504c40cab Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 24 Sep 2023 11:56:00 +0800 Subject: [PATCH 33/42] =?UTF-8?q?code=20review=EF=BC=9A=E5=88=86=E9=94=80?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pom.xml | 2 +- .../trade/enums/ErrorCodeConstants.java | 4 ++-- .../BrokerageWithdrawStatusEnum.java | 2 ++ .../AppBrokerageRecordController.java | 1 + .../brokerage/AppBrokerageUserController.java | 9 ++++---- .../AppBrokerageWithdrawController.java | 2 ++ .../app/config/AppTradeConfigController.java | 5 +++- .../app/config/vo/AppTradeConfigRespVO.java | 1 + .../delivery/AppDeliverConfigController.java | 1 + .../brokerage/BrokerageUserConvert.java | 8 +++---- .../brokerage/BrokerageRecordMapper.java | 5 ++-- .../mysql/brokerage/BrokerageUserMapper.java | 1 + .../brokerage/BrokerageWithdrawMapper.java | 4 +++- .../brokerage/BrokerageRecordService.java | 6 +++-- .../brokerage/BrokerageRecordServiceImpl.java | 11 +++++---- .../brokerage/BrokerageUserServiceImpl.java | 23 +++++++++++++++---- .../brokerage/BrokerageWithdrawService.java | 1 - .../mapper/brokerage/BrokerageUserMapper.xml | 13 +++++------ .../system/api/dict/DictDataApiImpl.java | 1 + .../app/dict/AppDictDataController.java | 4 +++- .../app/dict/vo/AppDictDataRespVO.java | 2 ++ 21 files changed, 71 insertions(+), 35 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-error-code/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-error-code/pom.xml index ff3c32d97..06e41c1eb 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-error-code/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-biz-error-code/pom.xml @@ -14,7 +14,7 @@ ${project.artifactId} 错误码 ErrorCode 的自动配置功能,提供如下功能: - 1. 远程读取:项目启动时,从 system-server 服务,读取数据库中的 ErrorCode 错误码,实现错误码的提水可配置; + 1. 远程读取:项目启动时,从 system-server 服务,读取数据库中的 ErrorCode 错误码,实现错误码的提示可配置; 2. 自动更新:管理员在管理后台修数据库中的 ErrorCode 错误码时,项目自动从 system-server 服务加载最新的 ErrorCode 错误码; 3. 自动写入:项目启动时,将项目本地的错误码写到 system-server 服务中,方便管理员在管理后台编辑; diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 52018bf4f..da0d8fa2b 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -87,7 +87,7 @@ public interface ErrorCodeConstants { // ========== 分销提现 模块 1011008000 ========== ErrorCode BROKERAGE_WITHDRAW_NOT_EXISTS = new ErrorCode(1011008000, "佣金提现记录不存在"); ErrorCode BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING = new ErrorCode(1011008001, "佣金提现记录状态不是审核中"); - ErrorCode BROKERAGE_WITHDRAW_MIN_PRICE = new ErrorCode(1011008002, "提现金额不能低于{}元"); - ErrorCode BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH = new ErrorCode(1011008003, "您当前最多可提现{}元"); + ErrorCode BROKERAGE_WITHDRAW_MIN_PRICE = new ErrorCode(1011008002, "提现金额不能低于 {} 元"); + ErrorCode BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH = new ErrorCode(1011008003, "您当前最多可提现 {} 元"); } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java index daf0da3aa..59dfbfbc8 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java @@ -22,7 +22,9 @@ public enum BrokerageWithdrawStatusEnum implements IntArrayValuable { WITHDRAW_FAIL(21, "提现失败"), ; + // TODO @疯狂:字典现在枚举在每个模块的 DictTypeConstants 里哈;可以创建一个出来;主要是想,治理每个模块到底有多少个枚举; public static final String DICT_TYPE = "BROKERAGE_WITHDRAW_STATUS"; + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageWithdrawStatusEnum::getStatus).toArray(); /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java index 0b7d01ed8..f5c3385db 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java @@ -45,6 +45,7 @@ public class AppBrokerageRecordController { return success(BrokerageRecordConvert.INSTANCE.convertPage02(pageResult)); } + // TODO @疯狂:这里还有一个漏网之鱼~ @GetMapping("/get-product-brokerage-price") @Operation(summary = "获得商品的分销金额") public CommonResult getProductBrokeragePrice(@RequestParam("spuId") Long spuId) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 13d1493e9..c7db41647 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -55,6 +55,7 @@ public class AppBrokerageUserController { @PreAuthenticated public CommonResult getBrokerageUser() { Optional user = Optional.ofNullable(brokerageUserService.getBrokerageUser(getLoginUserId())); + // 返回数据 AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO() .setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(false)) .setBrokeragePrice(user.map(BrokerageUserDO::getBrokeragePrice).orElse(0)) @@ -66,6 +67,7 @@ public class AppBrokerageUserController { @Operation(summary = "绑定推广员") @PreAuthenticated public CommonResult bindBrokerageUser(@Valid @RequestBody AppBrokerageUserBindReqVO reqVO) { + // TODO @疯狂:是不是 isNewUser 不用传递哈,交给 service 自己计算出来? return success(brokerageUserService.bindBrokerageUser(getLoginUserId(), reqVO.getBindUserId(), false)); } @@ -74,17 +76,17 @@ public class AppBrokerageUserController { @PreAuthenticated public CommonResult getBrokerageUserSummary() { Long userId = getLoginUserId(); + // 统计 yesterdayPrice、withdrawPrice、firstBrokerageUserCount、secondBrokerageUserCount 字段 LocalDateTime yesterday = LocalDateTime.now().minusDays(1); LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); - AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime)) .setWithdrawPrice(brokerageWithdrawService.getSummaryPriceByUserIdAndStatus(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.getStatus())) - .setBrokeragePrice(0) - .setFrozenPrice(0) + .setBrokeragePrice(0).setFrozenPrice(0) .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1)) .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2)); + // 设置 brokeragePrice、frozenPrice 字段 Optional.ofNullable(brokerageUserService.getBrokerageUser(userId)) .ifPresent(user -> respVO.setBrokeragePrice(user.getBrokeragePrice()).setFrozenPrice(user.getFrozenPrice())); return success(respVO); @@ -117,7 +119,6 @@ public class AppBrokerageUserController { @PreAuthenticated public CommonResult> getBrokerageUserChildSummaryPage( AppBrokerageUserChildSummaryPageReqVO pageReqVO) { - // 分页查询 PageResult pageResult = brokerageUserService.getBrokerageUserChildSummaryPage(pageReqVO, getLoginUserId()); return success(pageResult); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java index 434022f6a..77bae4be9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java @@ -30,6 +30,7 @@ import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLogi @Validated @Slf4j public class AppBrokerageWithdrawController { + @Resource private BrokerageWithdrawService brokerageWithdrawService; @@ -44,6 +45,7 @@ public class AppBrokerageWithdrawController { PageResult pageResult = brokerageWithdrawService.getBrokerageWithdrawPage( BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId())); // 拼接信息 + // TODO @疯狂:后端可以直接用 DictFrameworkUtils.getDictDataLabel() 去渲染哈;这样就不用 getDictDataLabelMap 方法了; Map statusNameMap = dictDataApi.getDictDataLabelMap(BrokerageWithdrawStatusEnum.DICT_TYPE); return success(BrokerageWithdrawConvert.INSTANCE.convertPage02(pageResult, statusNameMap)); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java index cb6e3813a..47c21ed57 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.trade.controller.app.config.vo.AppTradeConfigRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -24,13 +25,15 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Validated @Slf4j public class AppTradeConfigController { + @Resource private TradeConfigService tradeConfigService; @GetMapping("/get") + @Operation(summary = "获得交易配置") public CommonResult getTradeConfig() { TradeConfigDO tradeConfig = ObjUtil.defaultIfNull(tradeConfigService.getTradeConfig(), new TradeConfigDO()); - + // TODO @疯狂:是不是直接 convert 就好啦; AppTradeConfigRespVO respVO = new AppTradeConfigRespVO() .setBrokeragePosterUrls(tradeConfig.getBrokeragePostUrls()) .setBrokerageFrozenDays(tradeConfig.getBrokerageFrozenDays()) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java index cd7de5287..099e37c56 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java @@ -18,6 +18,7 @@ public class AppTradeConfigRespVO { @Schema(description = "佣金提现最小金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") private Integer brokerageWithdrawMinPrice; + // TODO @疯狂:如果是 list,要不加个 s,复数; @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 2]") private List brokerageWithdrawType; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverConfigController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverConfigController.java index d5b86fcb0..1d4e36f90 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverConfigController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverConfigController.java @@ -17,6 +17,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Validated public class AppDeliverConfigController { + // TODO @芋艿:这里后面干掉,合并到 AppTradeConfigController 中 @GetMapping("/get") @Operation(summary = "获得配送配置") public CommonResult getDeliveryConfig() { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java index e1d218416..41e51401e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java @@ -58,12 +58,12 @@ public interface BrokerageUserConvert { return target; } - default PageResult convertPage03(PageResult pageResult, Map userMap) { - for (AppBrokerageUserRankByUserCountRespVO vo : pageResult.getList()) { - copyTo(userMap.get(vo.getId()), vo); - } + default PageResult convertPage03(PageResult pageResult, + Map userMap) { + pageResult.getList().forEach(vo -> copyTo(userMap.get(vo.getId()), vo)); return pageResult; } void copyTo(MemberUserRespDTO from, @MappingTarget AppBrokerageUserRankByUserCountRespVO to); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java index 4faa86c8d..f42fa3d0c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java @@ -25,7 +25,6 @@ import java.util.List; public interface BrokerageRecordMapper extends BaseMapperX { default PageResult selectPage(BrokerageRecordPageReqVO reqVO) { - // 分页查询 return selectPage(reqVO, new LambdaQueryWrapperX() .eqIfPresent(BrokerageRecordDO::getUserId, reqVO.getUserId()) .eqIfPresent(BrokerageRecordDO::getBizType, reqVO.getBizType()) @@ -59,7 +58,8 @@ public interface BrokerageRecordMapper extends BaseMapperX { @Param("bizType") Integer bizType, @Param("status") Integer status); - @Select("SELECT SUM(price) FROM trade_brokerage_record WHERE user_id = #{userId} AND biz_type = #{bizType} " + + @Select("SELECT SUM(price) FROM trade_brokerage_record " + + "WHERE user_id = #{userId} AND biz_type = #{bizType} " + "AND create_time BETWEEN #{beginTime} AND #{endTime}") Integer selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(@Param("userId") Long userId, @Param("bizType") Integer bizType, @@ -76,4 +76,5 @@ public interface BrokerageRecordMapper extends BaseMapperX { @Param("status") Integer status, @Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java index 9bd2fe078..fc53ce942 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java @@ -145,4 +145,5 @@ public interface BrokerageUserMapper extends BaseMapperX { default List selectListByBindUserId(Long bindUserId) { return selectList(BrokerageUserDO::getBindUserId, bindUserId); } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java index 293fdf51c..92f54046e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java @@ -36,6 +36,8 @@ public interface BrokerageWithdrawMapper extends BaseMapperX getBrokerageRecordPage(BrokerageRecordPageReqVO pageReqVO); /** - * 增加佣金 + * 增加佣金【多级分佣】 * * @param userId 会员编号 * @param bizType 业务类型 @@ -46,7 +46,7 @@ public interface BrokerageRecordService { void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, @Valid List list); /** - * 增加佣金 + * 增加佣金【只针对自己】 * * @param userId 会员编号 * @param bizType 业务类型 @@ -95,6 +95,7 @@ public interface BrokerageRecordService { /** * 获得用户佣金排行分页列表(基于佣金总数) + * * @param pageReqVO 分页查询 * @return 排行榜分页 */ @@ -108,4 +109,5 @@ public interface BrokerageRecordService { * @return 用户的排名 */ Integer getUserRankByPrice(Long userId, LocalDateTime[] times); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java index b63097661..88114731d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java @@ -240,10 +240,11 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); } + // TODO @疯狂:这个求出来,应该是不准的?例如说超过 100+ 名后? @Override public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) { AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times); - // 取前100名 + // 取前 100 名 pageParam.setPageSize(100); PageResult pageResult = getBrokerageUserChildSummaryPageByPrice(pageParam); // 获得索引 @@ -255,21 +256,23 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { @Override @Transactional(rollbackFor = Exception.class) public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title) { - // 校验佣金余额 + // 1. 校验佣金余额 BrokerageUserDO user = brokerageUserService.getBrokerageUser(userId); int balance = Optional.of(user) .map(BrokerageUserDO::getBrokeragePrice).orElse(0); if (balance + brokeragePrice < 0) { + // TODO @疯狂:要不 MoneyUtils 那,统一搞个 format 金额的方法?然后把分到元的字符串,统一收口掉; throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance)); } - // 扣减佣金余额 + // 2. 更新佣金余额 boolean success = brokerageUserService.updateUserPrice(userId, brokeragePrice); if (!success) { + // 失败时,则抛出异常。只会出现扣减佣金时,余额不足的情况 throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance)); } - // 新增记录 + // 3. 新增记录 BrokerageRecordDO record = BrokerageRecordConvert.INSTANCE.convert(user, bizType, bizId, 0, brokeragePrice, null, title, null, null); brokerageRecordMapper.insert(record); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java index 650edda13..658e99326 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java @@ -67,7 +67,6 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { public void updateBrokerageUserId(Long id, Long bindUserId) { // 校验存在 BrokerageUserDO brokerageUser = validateBrokerageUserExists(id); - // 绑定关系未发生变化 if (Objects.equals(brokerageUser.getBindUserId(), bindUserId)) { return; @@ -185,6 +184,13 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { return true; } + /** + * 补全绑定用户的字段 + * + * @param bindUserId 绑定的用户编号 + * @param brokerageUser update 对象 + * @return 补全后的 update 对象 + */ private BrokerageUserDO fillBindUserData(Long bindUserId, BrokerageUserDO brokerageUser) { return brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now()); } @@ -255,6 +261,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } // 下级不能绑定自己的上级 + // TODO @疯狂:这里是不是查询不到的时候,应该有个 break 结束循环哈 for (int i = 0; i <= Short.MAX_VALUE; i++) { if (Objects.equals(bindUser.getBindUserId(), user.getId())) { throw exception(BROKERAGE_BIND_LOOP); @@ -263,18 +270,24 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } } + /** + * 根据绑定用户编号,获得绑定用户编号列表 + * + * @param bindUserId 绑定用户编号 + * @param level 绑定用户的层级。 + * 如果 level 为空,则查询 1+2 两个层级 + * @return 绑定用户编号列表 + */ private List buildBindUserIdsByLevel(Long bindUserId, Integer level) { + Assert.isTrue(level == null || level <= 2, "目前只支持 level 小于等于 2"); List bindUserIds = CollUtil.newArrayList(); if (level == null || level == 1) { bindUserIds.add(bindUserId); } if (level == null || level == 2) { - List firstUserIds = convertList(brokerageUserMapper.selectListByBindUserId(bindUserId), BrokerageUserDO::getId); - bindUserIds.addAll(firstUserIds); + bindUserIds.addAll(convertList(brokerageUserMapper.selectListByBindUserId(bindUserId), BrokerageUserDO::getId)); } - return bindUserIds; - } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java index 66279c998..a80234da5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java @@ -20,7 +20,6 @@ public interface BrokerageWithdrawService { * @param status 审核状态 * @param auditReason 驳回原因 */ - void auditBrokerageWithdraw(Integer id, BrokerageWithdrawStatusEnum status, String auditReason); /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml b/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml index 4605f6744..b1a1ef8d6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml @@ -4,14 +4,13 @@ + diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java index cf16c07b7..d50ac0299 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java @@ -38,6 +38,7 @@ public class DictDataApiImpl implements DictDataApi { @Override public List getDictDataList(String type) { + // TODO @疯狂:不用 DictDataExportReqVO 哈;可以考虑直接加个允许传递 type 传递的 List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(type)); return DictDataConvert.INSTANCE.convertList04(list); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java index 0b5909f35..95ae7e187 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java @@ -28,10 +28,12 @@ public class AppDictDataController { @Resource private DictDataService dictDataService; + // TODO @疯狂:暂时不用 path 参数哈;主要考虑一些中间件支持的一般,例如说链路追踪之类的;还是作为一个参数噶; @GetMapping("/type/{dictType}") @Operation(summary = "根据字典类型查询字典数据信息") - public CommonResult> getDicts(@PathVariable String dictType) { + public CommonResult> getDictDataList(@PathVariable String dictType) { List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(dictType)); return success(DictDataConvert.INSTANCE.convertList03(list)); } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java index 4ee511507..307fa9821 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java @@ -14,6 +14,8 @@ import lombok.NoArgsConstructor; @EqualsAndHashCode(callSuper = true) public class AppDictDataRespVO extends DictDataBaseVO { + // TODO @疯狂:app 的接口,不集成 admin 接口的 vo 哈;看看是不是只返回必要的字段,类似 remark、sort 不好返回的哈; + @Schema(description = "字典数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; From e9fd377772fdacce40ba2e88dafa593b3b480e2d Mon Sep 17 00:00:00 2001 From: owen Date: Sun, 24 Sep 2023 20:28:44 +0800 Subject: [PATCH 34/42] =?UTF-8?q?=E5=88=86=E9=94=80=EF=BC=9AReview?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/number/MoneyUtils.java | 48 +++++++++++++------ .../module/trade/enums/DictTypeConstants.java | 11 +++++ .../BrokerageWithdrawStatusEnum.java | 3 -- .../brokerage/AppBrokerageUserController.java | 4 +- .../AppBrokerageWithdrawController.java | 7 +-- .../app/config/AppTradeConfigController.java | 9 +--- .../brokerage/BrokerageRecordConvert.java | 3 +- .../brokerage/BrokerageWithdrawConvert.java | 7 +-- .../convert/config/TradeConfigConvert.java | 2 + .../brokerage/BrokerageRecordServiceImpl.java | 7 +-- .../brokerage/BrokerageUserServiceImpl.java | 11 +++-- .../BrokerageWithdrawServiceImpl.java | 4 +- .../api/user/dto/MemberUserRespDTO.java | 6 +++ .../module/system/api/dict/DictDataApi.java | 25 ++-------- .../system/api/dict/DictDataApiImpl.java | 18 ------- .../app/dict/AppDictDataController.java | 12 ++--- .../app/dict/vo/AppDictDataRespVO.java | 31 +++++++++--- .../system/dal/mysql/dict/DictDataMapper.java | 4 ++ .../system/service/dict/DictDataService.java | 14 ++++-- .../service/dict/DictDataServiceImpl.java | 7 +++ 20 files changed, 131 insertions(+), 102 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java index e2fd3fa6e..cac8438e0 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.framework.common.util.number; +import cn.hutool.core.math.Money; import cn.hutool.core.util.NumberUtil; import java.math.BigDecimal; @@ -16,7 +17,7 @@ public class MoneyUtils { * 计算百分比金额,四舍五入 * * @param price 金额 - * @param rate 百分比,例如说 56.77% 则传入 56.77 + * @param rate 百分比,例如说 56.77% 则传入 56.77 * @return 百分比金额 */ public static Integer calculateRatePrice(Integer price, Double rate) { @@ -27,24 +28,43 @@ public class MoneyUtils { * 计算百分比金额,向下传入 * * @param price 金额 - * @param rate 百分比,例如说 56.77% 则传入 56.77 + * @param rate 百分比,例如说 56.77% 则传入 56.77 * @return 百分比金额 */ public static Integer calculateRatePriceFloor(Integer price, Double rate) { return calculateRatePrice(price, rate, 0, RoundingMode.FLOOR).intValue(); } - /** - * 计算百分比金额 - * - * @param price 金额 - * @param rate 百分比,例如说 56.77% 则传入 56.77 - * @param scale 保留小数位数 - * @param roundingMode 舍入模式 - */ - public static BigDecimal calculateRatePrice(Number price, Number rate, int scale, RoundingMode roundingMode) { - return NumberUtil.toBigDecimal(price).multiply(NumberUtil.toBigDecimal(rate)) // 乘以 - .divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以 100 - } + /** + * 计算百分比金额 + * + * @param price 金额 + * @param rate 百分比,例如说 56.77% 则传入 56.77 + * @param scale 保留小数位数 + * @param roundingMode 舍入模式 + */ + public static BigDecimal calculateRatePrice(Number price, Number rate, int scale, RoundingMode roundingMode) { + return NumberUtil.toBigDecimal(price).multiply(NumberUtil.toBigDecimal(rate)) // 乘以 + .divide(BigDecimal.valueOf(100), scale, roundingMode); // 除以 100 + } + /** + * 分转元 + * + * @param fen 分 + * @return 元 + */ + public static BigDecimal fenToYuan(int fen) { + return new Money(0, fen).getAmount(); + } + + /** + * 分转元(字符串) + * + * @param fen 分 + * @return 元 + */ + public static String fenToYuanStr(int fen) { + return new Money(0, fen).toString(); + } } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java new file mode 100644 index 000000000..4ff3c95f2 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java @@ -0,0 +1,11 @@ +package cn.iocoder.yudao.module.trade.enums; + +/** + * Trade 字典类型的枚举类 + * + * @author owen + */ +public interface DictTypeConstants { + + String BROKERAGE_WITHDRAW_STATUS = "brokerage_withdraw_status"; // 佣金提现状态 +} diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java index 59dfbfbc8..a80aad02a 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java @@ -22,9 +22,6 @@ public enum BrokerageWithdrawStatusEnum implements IntArrayValuable { WITHDRAW_FAIL(21, "提现失败"), ; - // TODO @疯狂:字典现在枚举在每个模块的 DictTypeConstants 里哈;可以创建一个出来;主要是想,治理每个模块到底有多少个枚举; - public static final String DICT_TYPE = "BROKERAGE_WITHDRAW_STATUS"; - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageWithdrawStatusEnum::getStatus).toArray(); /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index c7db41647..5471e0b54 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -67,8 +67,8 @@ public class AppBrokerageUserController { @Operation(summary = "绑定推广员") @PreAuthenticated public CommonResult bindBrokerageUser(@Valid @RequestBody AppBrokerageUserBindReqVO reqVO) { - // TODO @疯狂:是不是 isNewUser 不用传递哈,交给 service 自己计算出来? - return success(brokerageUserService.bindBrokerageUser(getLoginUserId(), reqVO.getBindUserId(), false)); + MemberUserRespDTO user = memberUserApi.getUser(getLoginUserId()); + return success(brokerageUserService.bindBrokerageUser(user.getId(), reqVO.getBindUserId(), user.getCreateTime())); } @GetMapping("/get-summary") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java index 77bae4be9..8ca12b79b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBro import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageWithdrawConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; -import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -19,7 +18,6 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.Map; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; @@ -44,10 +42,7 @@ public class AppBrokerageWithdrawController { // 分页查询 PageResult pageResult = brokerageWithdrawService.getBrokerageWithdrawPage( BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId())); - // 拼接信息 - // TODO @疯狂:后端可以直接用 DictFrameworkUtils.getDictDataLabel() 去渲染哈;这样就不用 getDictDataLabelMap 方法了; - Map statusNameMap = dictDataApi.getDictDataLabelMap(BrokerageWithdrawStatusEnum.DICT_TYPE); - return success(BrokerageWithdrawConvert.INSTANCE.convertPage02(pageResult, statusNameMap)); + return success(BrokerageWithdrawConvert.INSTANCE.convertPage03(pageResult)); } @PostMapping("/create") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java index 47c21ed57..6b7660a1c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.trade.controller.app.config; import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.trade.controller.app.config.vo.AppTradeConfigRespVO; +import cn.iocoder.yudao.module.trade.convert.config.TradeConfigConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import io.swagger.v3.oas.annotations.Operation; @@ -33,13 +34,7 @@ public class AppTradeConfigController { @Operation(summary = "获得交易配置") public CommonResult getTradeConfig() { TradeConfigDO tradeConfig = ObjUtil.defaultIfNull(tradeConfigService.getTradeConfig(), new TradeConfigDO()); - // TODO @疯狂:是不是直接 convert 就好啦; - AppTradeConfigRespVO respVO = new AppTradeConfigRespVO() - .setBrokeragePosterUrls(tradeConfig.getBrokeragePostUrls()) - .setBrokerageFrozenDays(tradeConfig.getBrokerageFrozenDays()) - .setBrokerageWithdrawMinPrice(tradeConfig.getBrokerageWithdrawMinPrice()) - .setBrokerageWithdrawType(tradeConfig.getBrokerageWithdrawType()); - return success(respVO); + return success(TradeConfigConvert.INSTANCE.convert02(tradeConfig)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java index 175db060c..e6c0e4f8c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageRecordConvert.java @@ -4,6 +4,7 @@ import cn.hutool.core.math.Money; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordRespVO; @@ -51,7 +52,7 @@ public interface BrokerageRecordConvert { .setBizType(bizType.getType()).setBizId(bizId) .setPrice(brokeragePrice).setTotalPrice(user.getBrokeragePrice()) .setTitle(title) - .setDescription(StrUtil.format(bizType.getDescription(), new Money(0, Math.abs(brokeragePrice)))) + .setDescription(StrUtil.format(bizType.getDescription(), MoneyUtils.fenToYuanStr(Math.abs(brokeragePrice)))) .setStatus(status).setFrozenDays(brokerageFrozenDays).setUnfreezeTime(unfreezeTime) .setSourceUserLevel(sourceUserLevel).setSourceUserId(sourceUserId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java index 82932bbe5..69441ab07 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageWithdrawConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.trade.convert.brokerage; -import cn.hutool.core.map.MapUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawRespVO; @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBro import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; +import cn.iocoder.yudao.module.trade.enums.DictTypeConstants; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -44,10 +45,10 @@ public interface BrokerageWithdrawConvert { PageResult convertPage02(PageResult pageResult); - default PageResult convertPage02(PageResult pageResult, Map statusNameMap) { + default PageResult convertPage03(PageResult pageResult) { PageResult result = convertPage02(pageResult); for (AppBrokerageWithdrawRespVO vo : result.getList()) { - vo.setStatusName(MapUtil.getStr(statusNameMap, String.valueOf(vo.getStatus()), "")); + vo.setStatusName(DictFrameworkUtils.getDictDataLabel(DictTypeConstants.BROKERAGE_WITHDRAW_STATUS, vo.getStatus())); } return result; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java index 031f1198a..57da020c2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/config/TradeConfigConvert.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.convert.config; import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigRespVO; import cn.iocoder.yudao.module.trade.controller.admin.config.vo.TradeConfigSaveReqVO; +import cn.iocoder.yudao.module.trade.controller.app.config.vo.AppTradeConfigRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -20,4 +21,5 @@ public interface TradeConfigConvert { TradeConfigRespVO convert(TradeConfigDO bean); + AppTradeConfigRespVO convert02(TradeConfigDO tradeConfig); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java index 88114731d..1080dbfc1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.trade.service.brokerage; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.math.Money; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; @@ -240,7 +239,6 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); } - // TODO @疯狂:这个求出来,应该是不准的?例如说超过 100+ 名后? @Override public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) { AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times); @@ -261,15 +259,14 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { int balance = Optional.of(user) .map(BrokerageUserDO::getBrokeragePrice).orElse(0); if (balance + brokeragePrice < 0) { - // TODO @疯狂:要不 MoneyUtils 那,统一搞个 format 金额的方法?然后把分到元的字符串,统一收口掉; - throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance)); + throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, MoneyUtils.fenToYuanStr(balance)); } // 2. 更新佣金余额 boolean success = brokerageUserService.updateUserPrice(userId, brokeragePrice); if (!success) { // 失败时,则抛出异常。只会出现扣减佣金时,余额不足的情况 - throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance)); + throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, MoneyUtils.fenToYuanStr(balance)); } // 3. 新增记录 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java index 658e99326..182e457b5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java @@ -187,7 +187,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { /** * 补全绑定用户的字段 * - * @param bindUserId 绑定的用户编号 + * @param bindUserId 绑定的用户编号 * @param brokerageUser update 对象 * @return 补全后的 update 对象 */ @@ -261,12 +261,15 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } // 下级不能绑定自己的上级 - // TODO @疯狂:这里是不是查询不到的时候,应该有个 break 结束循环哈 for (int i = 0; i <= Short.MAX_VALUE; i++) { if (Objects.equals(bindUser.getBindUserId(), user.getId())) { throw exception(BROKERAGE_BIND_LOOP); } bindUser = getBrokerageUser(bindUser.getBindUserId()); + // 找到根节点,结束循环 + if (bindUser == null || bindUser.getBindUserId() == null) { + break; + } } } @@ -274,8 +277,8 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { * 根据绑定用户编号,获得绑定用户编号列表 * * @param bindUserId 绑定用户编号 - * @param level 绑定用户的层级。 - * 如果 level 为空,则查询 1+2 两个层级 + * @param level 绑定用户的层级。 + * 如果 level 为空,则查询 1+2 两个层级 * @return 绑定用户编号列表 */ private List buildBindUserIdsByLevel(Long bindUserId, Integer level) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java index 82334955c..783b0685a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java @@ -93,7 +93,7 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { // 4. 通知用户 Map templateParams = MapUtil.builder() .put("createTime", LocalDateTimeUtil.formatNormal(withdraw.getCreateTime())) - .put("price", new Money(0, withdraw.getPrice()).toString()) + .put("price", MoneyUtils.fenToYuanStr(withdraw.getPrice())) .put("reason", withdraw.getAuditReason()) .build(); NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO() @@ -170,7 +170,7 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { TradeConfigDO validateWithdrawPrice(Integer withdrawPrice) { TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); if (tradeConfig.getBrokerageWithdrawMinPrice() != null && withdrawPrice < tradeConfig.getBrokerageWithdrawMinPrice()) { - throw exception(BROKERAGE_WITHDRAW_MIN_PRICE, new Money(0, tradeConfig.getBrokerageWithdrawMinPrice())); + throw exception(BROKERAGE_WITHDRAW_MIN_PRICE, MoneyUtils.fenToYuanStr(tradeConfig.getBrokerageWithdrawMinPrice())); } return tradeConfig; } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java index c426fbbf1..85dad84d7 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.member.api.user.dto; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import lombok.Data; +import java.time.LocalDateTime; + /** * 用户信息 Response DTO * @@ -33,6 +35,10 @@ public class MemberUserRespDTO { * 手机 */ private String mobile; + /** + * 创建时间 + */ + private LocalDateTime createTime; // ========== 其它信息 ========== diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java index 34c33c568..107184564 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApi.java @@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.system.api.dict; import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; import java.util.Collection; -import java.util.List; -import java.util.Map; /** * 字典数据 API 接口 @@ -19,40 +17,23 @@ public interface DictDataApi { * 2. 字典数据被禁用 * * @param dictType 字典类型 - * @param values 字典数据值的数组 + * @param values 字典数据值的数组 */ void validateDictDataList(String dictType, Collection values); /** * 获得指定的字典数据,从缓存中 * - * @param type 字典类型 + * @param type 字典类型 * @param value 字典数据值 * @return 字典数据 */ DictDataRespDTO getDictData(String type, String value); - /** - * 获得指定类型的字典数据,从缓存中 - * - * @param type 字典类型 - * @return 字典数据 - */ - List getDictDataList(String type); - - /** - * 获得指定类型的字典数据 标签字典,从缓存中 - * key:value, value: label - * - * @param type 字典类型 - * @return 字典数据 - */ - Map getDictDataLabelMap(String type); - /** * 解析获得指定的字典数据,从缓存中 * - * @param type 字典类型 + * @param type 字典类型 * @param label 字典数据标签 * @return 字典数据 */ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java index d50ac0299..e88771fa7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.system.api.dict; import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import cn.iocoder.yudao.module.system.service.dict.DictDataService; @@ -9,10 +8,6 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Collection; -import java.util.List; -import java.util.Map; - -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; /** * 字典数据 API 实现类 @@ -36,19 +31,6 @@ public class DictDataApiImpl implements DictDataApi { return DictDataConvert.INSTANCE.convert02(dictData); } - @Override - public List getDictDataList(String type) { - // TODO @疯狂:不用 DictDataExportReqVO 哈;可以考虑直接加个允许传递 type 传递的 - List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(type)); - return DictDataConvert.INSTANCE.convertList04(list); - } - - @Override - public Map getDictDataLabelMap(String type) { - List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(type)); - return convertMap(list, DictDataDO::getValue, DictDataDO::getLabel); - } - @Override public DictDataRespDTO parseDictData(String dictType, String label) { DictDataDO dictData = dictDataService.parseDictData(dictType, label); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java index 95ae7e187..2332875b8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java @@ -1,17 +1,17 @@ package cn.iocoder.yudao.module.system.controller.app.dict; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataExportReqVO; import cn.iocoder.yudao.module.system.controller.app.dict.vo.AppDictDataRespVO; import cn.iocoder.yudao.module.system.convert.dict.DictDataConvert; import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO; import cn.iocoder.yudao.module.system.service.dict.DictDataService; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; @@ -28,11 +28,11 @@ public class AppDictDataController { @Resource private DictDataService dictDataService; - // TODO @疯狂:暂时不用 path 参数哈;主要考虑一些中间件支持的一般,例如说链路追踪之类的;还是作为一个参数噶; - @GetMapping("/type/{dictType}") + @GetMapping("/type") @Operation(summary = "根据字典类型查询字典数据信息") - public CommonResult> getDictDataList(@PathVariable String dictType) { - List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(dictType)); + @Parameter(name = "type", description = "字典类型", required = true, example = "common_status") + public CommonResult> getDictDataListByType(@RequestParam String type) { + List list = dictDataService.getEnabledDictDataListByType(type); return success(DictDataConvert.INSTANCE.convertList03(list)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java index 307fa9821..b7dfaf230 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java @@ -1,22 +1,41 @@ package cn.iocoder.yudao.module.system.controller.app.dict.vo; -import cn.iocoder.yudao.module.system.controller.admin.dict.vo.data.DictDataBaseVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Data; -import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + @Schema(description = "用户 App - 字典数据信息 Response VO") @Data @NoArgsConstructor @AllArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class AppDictDataRespVO extends DictDataBaseVO { - - // TODO @疯狂:app 的接口,不集成 admin 接口的 vo 哈;看看是不是只返回必要的字段,类似 remark、sort 不好返回的哈; +public class AppDictDataRespVO { @Schema(description = "字典数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id; + @Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") + @NotBlank(message = "字典标签不能为空") + @Size(max = 100, message = "字典标签长度不能超过100个字符") + private String label; + + @Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder") + @NotBlank(message = "字典键值不能为空") + @Size(max = 100, message = "字典键值长度不能超过100个字符") + private String value; + + @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex") + @NotBlank(message = "字典类型不能为空") + @Size(max = 100, message = "字典类型长度不能超过100个字符") + private String dictType; + + @Schema(description = "颜色类型,default、primary、success、info、warning、danger", example = "default") + private String colorType; + @Schema(description = "css 样式", example = "btn-visible") + private String cssClass; + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java index 244825093..85da83a5d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java @@ -48,4 +48,8 @@ public interface DictDataMapper extends BaseMapperX { .eqIfPresent(DictDataDO::getStatus, reqVO.getStatus())); } + default List selectListByTypeAndStatus(String dictType, Integer status) { + return selectList(new LambdaQueryWrapper() + .eq(DictDataDO::getDictType, dictType).eq(DictDataDO::getStatus, status)); + } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java index d2eb8c519..3fc6a4071 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataService.java @@ -62,6 +62,14 @@ public interface DictDataService { */ List getDictDataList(DictDataExportReqVO reqVO); + /** + * 获得字典数据列表 + * + * @param dictType 字典类型 + * @return 字典数据列表 + */ + List getEnabledDictDataListByType(String dictType); + /** * 获得字典数据详情 * @@ -84,7 +92,7 @@ public interface DictDataService { * 2. 字典数据被禁用 * * @param dictType 字典类型 - * @param values 字典数据值的数组 + * @param values 字典数据值的数组 */ void validateDictDataList(String dictType, Collection values); @@ -92,7 +100,7 @@ public interface DictDataService { * 获得指定的字典数据 * * @param dictType 字典类型 - * @param value 字典数据值 + * @param value 字典数据值 * @return 字典数据 */ DictDataDO getDictData(String dictType, String value); @@ -101,7 +109,7 @@ public interface DictDataService { * 解析获得指定的字典数据,从缓存中 * * @param dictType 字典类型 - * @param label 字典数据标签 + * @param label 字典数据标签 * @return 字典数据 */ DictDataDO parseDictData(String dictType, String label); diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java index 7cca762f4..8a49719fb 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java @@ -66,6 +66,13 @@ public class DictDataServiceImpl implements DictDataService { return list; } + @Override + public List getEnabledDictDataListByType(String dictType) { + List list = dictDataMapper.selectListByTypeAndStatus(dictType, CommonStatusEnum.ENABLE.getStatus()); + list.sort(COMPARATOR_TYPE_AND_SORT); + return list; + } + @Override public DictDataDO getDictData(Long id) { return dictDataMapper.selectById(id); From 9856e179741730ff185212da37d60dc89efe5372 Mon Sep 17 00:00:00 2001 From: owen Date: Sun, 24 Sep 2023 22:27:24 +0800 Subject: [PATCH 35/42] =?UTF-8?q?=E5=88=86=E9=94=80=EF=BC=9A=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E5=95=86=E5=93=81=EF=BC=8C=E8=AE=A1=E7=AE=97=E6=8E=A8?= =?UTF-8?q?=E5=B9=BF=E5=91=98=E5=8F=AF=E4=BB=A5=E5=BE=97=E5=88=B0=E7=9A=84?= =?UTF-8?q?=E4=BD=A3=E9=87=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/spu/dto/ProductSpuRespDTO.java | 10 ++++ .../AppBrokerageRecordController.java | 10 +--- .../convert/order/TradeOrderConvert.java | 13 ++++- .../brokerage/BrokerageRecordService.java | 9 +++ .../brokerage/BrokerageRecordServiceImpl.java | 58 +++++++++++++++++++ .../order/TradeOrderUpdateServiceImpl.java | 3 +- 6 files changed, 90 insertions(+), 13 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java index b6b6b996d..fe2939efc 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java @@ -137,4 +137,14 @@ public class ProductSpuRespDTO { */ private Integer clickCount; + + // ========== 分销相关字段 ========= + + /** + * 分销类型 + * + * false - 默认 + * true - 自行设置 + */ + private Boolean subCommissionType; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java index f5c3385db..7cbd6e551 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBroke import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; -import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; @@ -31,8 +30,6 @@ import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLogi @Validated @Slf4j public class AppBrokerageRecordController { - @Resource - private BrokerageUserService brokerageUserService; @Resource private BrokerageRecordService brokerageRecordService; @@ -45,15 +42,10 @@ public class AppBrokerageRecordController { return success(BrokerageRecordConvert.INSTANCE.convertPage02(pageResult)); } - // TODO @疯狂:这里还有一个漏网之鱼~ @GetMapping("/get-product-brokerage-price") @Operation(summary = "获得商品的分销金额") public CommonResult getProductBrokeragePrice(@RequestParam("spuId") Long spuId) { - AppBrokerageProductPriceRespVO respVO = new AppBrokerageProductPriceRespVO(); - respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId())); - respVO.setBrokerageMinPrice(1); - respVO.setBrokerageMaxPrice(2); - return success(respVO); + return success(brokerageRecordService.calculateProductBrokeragePrice(spuId, getLoginUserId())); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index 85d9fa39a..1dcbda7e0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.convert.order; +import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; @@ -14,6 +15,7 @@ import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDT import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO; @@ -266,11 +268,16 @@ public interface TradeOrderConvert { TradeOrderDO convert(TradeOrderRemarkReqVO reqVO); - default BrokerageAddReqBO convert(MemberUserRespDTO user, TradeOrderItemDO item, ProductSkuRespDTO sku) { - return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())).setSourceUserId(item.getUserId()) + default BrokerageAddReqBO convert(MemberUserRespDTO user, TradeOrderItemDO item, + ProductSpuRespDTO spu, ProductSkuRespDTO sku) { + BrokerageAddReqBO bo = new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())).setSourceUserId(item.getUserId()) .setBasePrice(item.getPayPrice() * item.getCount()) .setTitle(StrUtil.format("{}成功购买{}", user.getNickname(), item.getSpuName())) - .setFirstFixedPrice(sku.getFirstBrokeragePrice()).setSecondFixedPrice(sku.getSecondBrokeragePrice()); + .setFirstFixedPrice(0).setSecondFixedPrice(0); + if (BooleanUtil.isTrue(spu.getSubCommissionType())) { + bo.setFirstFixedPrice(sku.getFirstBrokeragePrice()).setSecondFixedPrice(sku.getSecondBrokeragePrice()); + } + return bo; } TradeBeforeOrderCreateReqBO convert(AppTradeOrderCreateReqVO createReqVO); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java index 7981d9baf..875c29cfd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.service.brokerage; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageProductPriceRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; @@ -110,4 +111,12 @@ public interface BrokerageRecordService { */ Integer getUserRankByPrice(Long userId, LocalDateTime[] times); + /** + * 计算商品被购买后,推广员可以得到的佣金 + * + * @param spuId 商品编号 + * @param userId 用户编号 + * @return 用户佣金 + */ + AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long spuId, Long userId); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java index 1080dbfc1..24d86160d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.trade.service.brokerage; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.BooleanUtil; import cn.hutool.core.util.ObjectUtil; @@ -9,7 +10,12 @@ import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; +import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; +import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.record.AppBrokerageProductPriceRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO; import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageRecordConvert; @@ -36,6 +42,9 @@ import java.util.Objects; import java.util.Optional; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMaxValue; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMinValue; +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH; /** @@ -55,6 +64,11 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { @Resource private BrokerageUserService brokerageUserService; + @Resource + private ProductSpuApi productSpuApi; + @Resource + private ProductSkuApi productSkuApi; + @Override public BrokerageRecordDO getBrokerageRecord(Integer id) { return brokerageRecordMapper.selectById(id); @@ -293,6 +307,50 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { return true; } + @Override + public AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long spuId, Long userId) { + // 1. 构建默认的返回值 + AppBrokerageProductPriceRespVO respVO = new AppBrokerageProductPriceRespVO().setEnabled(false) + .setBrokerageMinPrice(0).setBrokerageMaxPrice(0); + + // 2.1 校验分销功能是否开启 + TradeConfigDO tradeConfig = tradeConfigService.getTradeConfig(); + if (tradeConfig == null || !BooleanUtil.isTrue(tradeConfig.getBrokerageEnabled())) { + return respVO; + } + + // 2.2 校验用户是否有分销资格 + respVO.setEnabled(brokerageUserService.getUserBrokerageEnabled(getLoginUserId())); + if (!BooleanUtil.isTrue(respVO.getEnabled())) { + return respVO; + } + + Integer fixedMinPrice = 0; + Integer fixedMaxPrice = 0; + Integer spuMinPrice = 0; + Integer spuMaxPrice = 0; + // 2.3 校验商品是否存在 + ProductSpuRespDTO spu = productSpuApi.getSpu(spuId); + if (spu == null) { + return respVO; + } + + List skuList = productSkuApi.getSkuListBySpuId(ListUtil.of(spuId)); + if (BooleanUtil.isTrue(spu.getSubCommissionType())) { + // 3.1 商品单独分佣模式 + fixedMinPrice = getMinValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice); + fixedMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice); + } else { + // 3.2 全局分佣模式(根据商品价格比例计算) + spuMinPrice = getMinValue(skuList, ProductSkuRespDTO::getPrice); + spuMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getPrice); + } + + respVO.setBrokerageMinPrice(calculatePrice(spuMinPrice, tradeConfig.getBrokerageFirstPercent(), fixedMinPrice)); + respVO.setBrokerageMaxPrice(calculatePrice(spuMaxPrice, tradeConfig.getBrokerageFirstPercent(), fixedMaxPrice)); + return respVO; + } + /** * 获得自身的代理对象,解决 AOP 生效问题 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 6e2148140..42e77fc4b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -849,7 +849,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 每一个订单项,都会去生成分销记录 List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); List addList = convertList(orderItems, - item -> TradeOrderConvert.INSTANCE.convert(user, item, productSkuApi.getSku(item.getSkuId()))); + item -> TradeOrderConvert.INSTANCE.convert(user, item, + productSpuApi.getSpu(item.getSpuId()), productSkuApi.getSku(item.getSkuId()))); brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, addList); } From 967e578d547534d3e59eb65f940f60b464a83866 Mon Sep 17 00:00:00 2001 From: owen Date: Sun, 24 Sep 2023 22:32:13 +0800 Subject: [PATCH 36/42] =?UTF-8?q?=E5=88=86=E9=94=80=EF=BC=9A=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E6=8F=90=E7=8E=B0=E7=B1=BB=E5=9E=8B=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 40 +++++++++---------- .../admin/config/vo/TradeConfigBaseVO.java | 2 +- .../app/config/vo/AppTradeConfigRespVO.java | 3 +- .../dal/dataobject/config/TradeConfigDO.java | 2 +- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 4c1d8d7e8..3c0051435 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -1,25 +1,25 @@ -- 增加配置表 -create table trade_config +CREATE TABLE trade_config ( - id bigint auto_increment comment '自增主键' primary key, - brokerage_enabled bit default 1 not null comment '是否启用分佣', - brokerage_enabled_condition tinyint default 1 not null comment '分佣模式:1-人人分销 2-指定分销', - brokerage_bind_mode tinyint default 1 not null comment '分销关系绑定模式: 1-没有推广人,2-新用户, 3-扫码覆盖', - brokerage_post_urls varchar(2000) default '' null comment '分销海报图地址数组', - brokerage_first_percent int default 0 not null comment '一级返佣比例', - brokerage_second_percent int default 0 not null comment '二级返佣比例', - brokerage_withdraw_min_price int default 0 not null comment '用户提现最低金额', - brokerage_withdraw_fee_percent int default 0 not null comment '提现手续费百分比', - brokerage_bank_names varchar(200) default '' not null comment '提现银行(字典类型=brokerage_bank_name)', - brokerage_frozen_days int default 7 not null comment '佣金冻结时间(天)', - brokerage_withdraw_type varchar(32) default '1,2,3,4' not null comment '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝', - creator varchar(64) default '' null comment '创建者', - create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间', - updater varchar(64) default '' null comment '更新者', - update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', - deleted bit default b'0' not null comment '是否删除', - tenant_id bigint default 0 not null comment '租户编号' -) comment '交易中心配置'; + id BIGINT AUTO_INCREMENT COMMENT '自增主键' PRIMARY KEY, + brokerage_enabled BIT DEFAULT 1 NOT NULL COMMENT '是否启用分佣', + brokerage_enabled_condition TINYINT DEFAULT 1 NOT NULL COMMENT '分佣模式:1-人人分销 2-指定分销', + brokerage_bind_mode TINYINT DEFAULT 1 NOT NULL COMMENT '分销关系绑定模式: 1-没有推广人,2-新用户, 3-扫码覆盖', + brokerage_post_urls VARCHAR(2000) DEFAULT '' NULL COMMENT '分销海报图地址数组', + brokerage_first_percent INT DEFAULT 0 NOT NULL COMMENT '一级返佣比例', + brokerage_second_percent INT DEFAULT 0 NOT NULL COMMENT '二级返佣比例', + brokerage_withdraw_min_price INT DEFAULT 0 NOT NULL COMMENT '用户提现最低金额', + brokerage_withdraw_fee_percent INT DEFAULT 0 NOT NULL COMMENT '提现手续费百分比', + brokerage_bank_names VARCHAR(200) DEFAULT '' NOT NULL COMMENT '提现银行(字典类型=brokerage_bank_name)', + brokerage_frozen_days INT DEFAULT 7 NOT NULL COMMENT '佣金冻结时间(天)', + brokerage_withdraw_types VARCHAR(32) DEFAULT '1,2,3,4' NOT NULL COMMENT '提现方式:1-钱包;2-银行卡;3-微信;4-支付宝', + creator VARCHAR(64) DEFAULT '' NULL COMMENT '创建者', + create_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建时间', + updater VARCHAR(64) DEFAULT '' NULL COMMENT '更新者', + update_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + deleted BIT DEFAULT b'0' NOT NULL COMMENT '是否删除', + tenant_id BIGINT DEFAULT 0 NOT NULL COMMENT '租户编号' +) COMMENT '交易中心配置'; # alter table trade_config # add brokerage_withdraw_fee_percent int default 0 not null comment '提现手续费百分比' after brokerage_withdraw_min_price; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java index 39ffefa49..3006c62f0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java @@ -82,6 +82,6 @@ public class TradeConfigBaseVO { @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") @NotNull(message = "提现方式不能为空") @InEnum(value = BrokerageWithdrawTypeEnum.class, message = "提现方式必须是 {value}") - private List brokerageWithdrawType; + private List brokerageWithdrawTypes; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java index 099e37c56..0d590f834 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java @@ -18,8 +18,7 @@ public class AppTradeConfigRespVO { @Schema(description = "佣金提现最小金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") private Integer brokerageWithdrawMinPrice; - // TODO @疯狂:如果是 list,要不加个 s,复数; @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 2]") - private List brokerageWithdrawType; + private List brokerageWithdrawTypes; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java index e01563237..8781c60ed 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java @@ -100,6 +100,6 @@ public class TradeConfigDO extends BaseDO { * 枚举 {@link BrokerageWithdrawTypeEnum 对应的类} */ @TableField(typeHandler = IntegerListTypeHandler.class) - private List brokerageWithdrawType; + private List brokerageWithdrawTypes; } From 0b84c1873668fc23c3ee88e94da05580ae0539a5 Mon Sep 17 00:00:00 2001 From: owen Date: Sun, 24 Sep 2023 23:18:51 +0800 Subject: [PATCH 37/42] =?UTF-8?q?=E5=88=86=E9=94=80=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E5=88=86=E4=BA=AB=E6=B5=B7=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/brokerage.sql | 2 +- .../trade/controller/admin/config/vo/TradeConfigBaseVO.java | 2 +- .../yudao/module/trade/dal/dataobject/config/TradeConfigDO.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 3c0051435..797f2563a 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -5,7 +5,7 @@ CREATE TABLE trade_config brokerage_enabled BIT DEFAULT 1 NOT NULL COMMENT '是否启用分佣', brokerage_enabled_condition TINYINT DEFAULT 1 NOT NULL COMMENT '分佣模式:1-人人分销 2-指定分销', brokerage_bind_mode TINYINT DEFAULT 1 NOT NULL COMMENT '分销关系绑定模式: 1-没有推广人,2-新用户, 3-扫码覆盖', - brokerage_post_urls VARCHAR(2000) DEFAULT '' NULL COMMENT '分销海报图地址数组', + brokerage_poster_urls VARCHAR(2000) DEFAULT '' NULL COMMENT '分销海报图地址数组', brokerage_first_percent INT DEFAULT 0 NOT NULL COMMENT '一级返佣比例', brokerage_second_percent INT DEFAULT 0 NOT NULL COMMENT '二级返佣比例', brokerage_withdraw_min_price INT DEFAULT 0 NOT NULL COMMENT '用户提现最低金额', diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java index 3006c62f0..dfad27e03 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java @@ -48,7 +48,7 @@ public class TradeConfigBaseVO { private Integer brokerageBindMode; @Schema(description = "分销海报图地址数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/yudao.jpg]") - private List brokeragePostUrls; + private List brokeragePosterUrls; @Schema(description = "一级返佣比例", requiredMode = Schema.RequiredMode.REQUIRED, example = "5") @NotNull(message = "一级返佣比例不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java index 8781c60ed..01de52b5b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/config/TradeConfigDO.java @@ -68,7 +68,7 @@ public class TradeConfigDO extends BaseDO { * 分销海报图地址数组 */ @TableField(typeHandler = JacksonTypeHandler.class) - private List brokeragePostUrls; + private List brokeragePosterUrls; /** * 一级返佣比例 */ From 3dca66eefa2a2a6b34447288bb32d06624d588ed Mon Sep 17 00:00:00 2001 From: owen Date: Mon, 25 Sep 2023 08:05:29 +0800 Subject: [PATCH 38/42] =?UTF-8?q?=E5=88=86=E9=94=80=EF=BC=9A=E6=8F=90?= =?UTF-8?q?=E7=8E=B0=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../brokerage/BrokerageUserController.java | 12 +++++++-- .../brokerage/AppBrokerageUserController.java | 3 ++- .../brokerage/BrokerageUserConvert.java | 13 +++++++--- .../brokerage/BrokerageWithdrawMapper.java | 6 ++--- .../brokerage/BrokerageWithdrawService.java | 9 ++++--- .../BrokerageWithdrawServiceImpl.java | 7 ++--- .../brokerage/bo/UserWithdrawSummaryBO.java | 26 +++++++++++++++++++ 7 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserWithdrawSummaryBO.java diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java index 548fdce0a..f12a62358 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java @@ -9,9 +9,12 @@ import cn.iocoder.yudao.module.trade.convert.brokerage.BrokerageUserConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -38,6 +41,8 @@ public class BrokerageUserController { private BrokerageUserService brokerageUserService; @Resource private BrokerageRecordService brokerageRecordService; + @Resource + private BrokerageWithdrawService brokerageWithdrawService; @Resource private MemberUserApi memberUserApi; @@ -97,9 +102,12 @@ public class BrokerageUserController { userId -> userId, userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null)); - // todo 合计提现 + // 合计提现 + Map withdrawMap = convertMap(userIds, + userId -> userId, + userId -> brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)); - return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap)); + return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap, withdrawMap)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 5471e0b54..2e8db1bbc 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -15,6 +15,7 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageWithdrawService; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -82,7 +83,7 @@ public class AppBrokerageUserController { LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime)) - .setWithdrawPrice(brokerageWithdrawService.getSummaryPriceByUserIdAndStatus(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.getStatus())) + .setWithdrawPrice(Optional.ofNullable(brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)).map(UserWithdrawSummaryBO::getPrice).orElse(0)) .setBrokeragePrice(0).setFrozenPrice(0) .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1)) .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2)); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java index 41e51401e..6a578032d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.Brokerag import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; import org.mapstruct.Mapper; import org.mapstruct.MappingTarget; import org.mapstruct.factory.Mappers; @@ -29,13 +30,14 @@ public interface BrokerageUserConvert { List convertList(List list); - PageResult convertPage(PageResult page); + PageResult convertPage(PageResult page, Map userMap, Map brokerageUserCountMap, Map userOrderSummaryMap); default PageResult convertPage(PageResult pageResult, Map userMap, Map brokerageUserCountMap, - Map userOrderSummaryMap) { - PageResult result = convertPage(pageResult); + Map userOrderSummaryMap, + Map withdrawMap) { + PageResult result = convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap); for (BrokerageUserRespVO userVO : result.getList()) { // 用户信息 copyTo(userMap.get(userVO.getId()), userVO); @@ -46,7 +48,10 @@ public interface BrokerageUserConvert { Optional orderSummaryOptional = Optional.ofNullable(userOrderSummaryMap.get(userVO.getId())); userVO.setBrokerageOrderCount(orderSummaryOptional.map(UserBrokerageSummaryBO::getCount).orElse(0)) .setBrokerageOrderPrice(orderSummaryOptional.map(UserBrokerageSummaryBO::getPrice).orElse(0)); - // todo 已提现次数、已提现金额 + // 已提现次数、已提现金额 + Optional withdrawSummaryOptional = Optional.ofNullable(withdrawMap.get(userVO.getId())); + userVO.setWithdrawCount(withdrawSummaryOptional.map(UserWithdrawSummaryBO::getCount).orElse(0)) + .setWithdrawPrice(withdrawSummaryOptional.map(UserWithdrawSummaryBO::getPrice).orElse(0)); userVO.setWithdrawCount(0).setWithdrawPrice(0); } return result; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java index 92f54046e..8b2fbb8ab 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -36,8 +37,7 @@ public interface BrokerageWithdrawMapper extends BaseMapperX Date: Mon, 25 Sep 2023 08:34:58 +0800 Subject: [PATCH 39/42] =?UTF-8?q?Pay=20Client=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=BD=AC=E8=B4=A6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/pay/core/client/PayClient.java | 10 ++ .../dto/transfer/PayTransferRespDTO.java | 91 +++++++++++++++ .../transfer/PayTransferUnifiedReqDTO.java | 65 +++++++++++ .../core/client/impl/AbstractPayClient.java | 22 ++++ .../impl/alipay/AbstractAlipayPayClient.java | 6 + .../impl/alipay/AlipayAppPayClient.java | 6 + .../impl/alipay/AlipayBarPayClient.java | 6 + .../client/impl/alipay/AlipayPcPayClient.java | 6 + .../client/impl/alipay/AlipayQrPayClient.java | 6 + .../impl/alipay/AlipayTransferClient.java | 105 ++++++++++++++++++ .../impl/alipay/AlipayWapPayClient.java | 6 + .../core/client/impl/mock/MockPayClient.java | 6 + .../impl/weixin/AbstractWxPayClient.java | 6 + .../core/enums/channel/PayChannelEnum.java | 1 + .../transfer/PayTransferStatusRespEnum.java | 21 ++++ .../enums/transfer/PayTransferTypeEnum.java | 36 ++++++ .../framework/pay/wallet/WalletPayClient.java | 6 + 17 files changed, 405 insertions(+) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferRespDTO.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferUnifiedReqDTO.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayTransferClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/transfer/PayTransferStatusRespEnum.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/transfer/PayTransferTypeEnum.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClient.java index 4d163be55..18ae017d1 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClient.java @@ -4,6 +4,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO; +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO; import java.util.Map; @@ -76,4 +78,12 @@ public interface PayClient { */ PayRefundRespDTO getRefund(String outTradeNo, String outRefundNo); + /** + * 调用渠道,进行转账 + * + * @param reqDTO 统一转账请求信息 + * @return 转账信息 + */ + PayTransferRespDTO unifiedTransfer(PayTransferUnifiedReqDTO reqDTO); + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferRespDTO.java new file mode 100644 index 000000000..1de0de2fc --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferRespDTO.java @@ -0,0 +1,91 @@ +package cn.iocoder.yudao.framework.pay.core.client.dto.transfer; + +import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferStatusRespEnum; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 统一转账 Response DTO + * + * @author jason + */ +@Data +public class PayTransferRespDTO { + + private Integer status; + + /** + * 外部转账单号 + * + */ + private String outTransferNo; + + /** + * 支付渠道编号 + */ + private String channelOrderNo; + + /** + * 支付成功时间 + */ + private LocalDateTime successTime; + + /** + * 原始的返回结果 + */ + private Object rawData; + + /** + * 调用渠道的错误码 + */ + private String channelErrorCode; + /** + * 调用渠道报错时,错误信息 + */ + private String channelErrorMsg; + + /** + * 创建【WAITING】状态的转账返回 + */ + public static PayTransferRespDTO waitingOf(String channelOrderNo, + String outTransferNo, Object rawData) { + PayTransferRespDTO respDTO = new PayTransferRespDTO(); + respDTO.status = PayTransferStatusRespEnum.WAITING.getStatus(); + respDTO.channelOrderNo = channelOrderNo; + respDTO.outTransferNo = outTransferNo; + respDTO.rawData = rawData; + return respDTO; + } + + /** + * 创建【FAILURE】状态的转账返回 + */ + public static PayTransferRespDTO failureOf(String channelErrorCode, String channelErrorMsg, + String outTransferNo, Object rawData) { + PayTransferRespDTO respDTO = new PayTransferRespDTO(); + respDTO.status = PayTransferStatusRespEnum.FAILURE.getStatus(); + respDTO.channelErrorCode = channelErrorCode; + respDTO.channelErrorMsg = channelErrorMsg; + // 相对通用的字段 + respDTO.outTransferNo = outTransferNo; + respDTO.rawData = rawData; + return respDTO; + } + + /** + * 创建【SUCCESS】状态的转账返回 + */ + public static PayTransferRespDTO successOf(String channelTransferNo, LocalDateTime successTime, + String outTransferNo, Object rawData) { + PayTransferRespDTO respDTO = new PayTransferRespDTO(); + respDTO.status = PayTransferStatusRespEnum.SUCCESS.getStatus(); + respDTO.channelOrderNo = channelTransferNo; + respDTO.successTime = successTime; + // 相对通用的字段 + respDTO.outTransferNo = outTransferNo; + respDTO.rawData = rawData; + return respDTO; + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferUnifiedReqDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferUnifiedReqDTO.java new file mode 100644 index 000000000..6d1ef3998 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferUnifiedReqDTO.java @@ -0,0 +1,65 @@ +package cn.iocoder.yudao.framework.pay.core.client.dto.transfer; + +import cn.iocoder.yudao.framework.common.validation.InEnum; +import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferTypeEnum; +import lombok.Data; +import org.hibernate.validator.constraints.Length; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.Map; + +/** + * 统一转账 Request DTO + * + * @author jason + */ +@Data +public class PayTransferUnifiedReqDTO { + + /** + * 转账类型 + * + * 关联 {@link PayTransferTypeEnum#getType()} + */ + @NotNull(message = "转账类型不能为空") + @InEnum(PayTransferTypeEnum.class) + private Integer type; + + /** + * 用户 IP + */ + @NotEmpty(message = "用户 IP 不能为空") + private String userIp; + + @NotEmpty(message = "外部转账单编号不能为空") + private String outTransferNo; + + /** + * 转账金额,单位:分 + */ + @NotNull(message = "转账金额不能为空") + @Min(value = 1, message = "转账金额必须大于零") + private Integer price; + + /** + * 转账标题 + */ + @NotEmpty(message = "转账标题不能为空") + @Length(max = 128, message = "转账标题不能超过 128") + private String title; + + /** + * 收款方信息,转账类型不同信息不同 + */ + @NotEmpty(message = "收款方信息 不能为空") + private Map payeeInfo; + + /** + * 支付渠道的额外参数 + * + */ + private Map channelExtras; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java index e8f898b2e..66546d784 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java @@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO; +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO; import cn.iocoder.yudao.framework.pay.core.client.exception.PayException; import lombok.extern.slf4j.Slf4j; @@ -181,6 +183,26 @@ public abstract class AbstractPayClient implemen protected abstract PayRefundRespDTO doGetRefund(String outTradeNo, String outRefundNo) throws Throwable; + @Override + public final PayTransferRespDTO unifiedTransfer(PayTransferUnifiedReqDTO reqDTO) { + ValidationUtils.validate(reqDTO); + PayTransferRespDTO resp; + try{ + resp = doUnifiedTransfer(reqDTO); + }catch (ServiceException ex) { // 业务异常,都是实现类已经翻译,所以直接抛出即可 + throw ex; + } catch (Throwable ex) { + // 系统异常,则包装成 PayException 异常抛出 + log.error("[unifiedTransfer][客户端({}) request({}) 发起转账异常]", + getId(), toJsonString(reqDTO), ex); + throw buildPayException(ex); + } + return resp; + } + + protected abstract PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) + throws Throwable; + // ========== 各种工具方法 ========== private PayException buildPayException(Throwable ex) { diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java index b1edf87ac..e62120ae5 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java @@ -150,6 +150,10 @@ public abstract class AbstractAlipayPayClient extends AbstractPayClient { throw new UnsupportedOperationException("模拟支付无支付回调"); } + @Override + protected PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) { + throw new UnsupportedOperationException("待实现"); + } } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/AbstractWxPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/AbstractWxPayClient.java index 87b9c4bc2..f4f326a65 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/AbstractWxPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/AbstractWxPayClient.java @@ -12,6 +12,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO; +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO; import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; @@ -425,6 +427,10 @@ public abstract class AbstractWxPayClient extends AbstractPayClient item.getType().equals(type), values()); + } +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java index 5591238f6..9bd8a6eec 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java @@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO; +import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO; import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig; import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; @@ -174,4 +176,8 @@ public class WalletPayClient extends AbstractPayClient { throw new IllegalStateException(String.format("支付退款单[%s] 状态不正确", outRefundNo)); } + @Override + public PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) { + throw new UnsupportedOperationException("待实现"); + } } From 16af31d980ee6480b00e50be3f932586ae00d320 Mon Sep 17 00:00:00 2001 From: owen Date: Mon, 25 Sep 2023 08:36:55 +0800 Subject: [PATCH 40/42] =?UTF-8?q?=E5=88=86=E9=94=80=EF=BC=9A@Select=20sql?= =?UTF-8?q?=E8=AF=AD=E5=8F=A5=E5=A2=9E=E5=8A=A0=E9=80=BB=E8=BE=91=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=AD=97=E6=AE=B5=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/dal/mysql/brokerage/BrokerageRecordMapper.java | 4 ++-- .../trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java index f42fa3d0c..eb55a8c4c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java @@ -53,14 +53,14 @@ public interface BrokerageRecordMapper extends BaseMapperX { } @Select("SELECT COUNT(1), SUM(price) FROM trade_brokerage_record " + - "WHERE user_id = #{userId} AND biz_type = #{bizType} AND status = #{status}") + "WHERE user_id = #{userId} AND biz_type = #{bizType} AND status = #{status} AND deleted = FALSE") UserBrokerageSummaryBO selectCountAndSumPriceByUserIdAndBizTypeAndStatus(@Param("userId") Long userId, @Param("bizType") Integer bizType, @Param("status") Integer status); @Select("SELECT SUM(price) FROM trade_brokerage_record " + "WHERE user_id = #{userId} AND biz_type = #{bizType} " + - "AND create_time BETWEEN #{beginTime} AND #{endTime}") + "AND create_time BETWEEN #{beginTime} AND #{endTime} AND deleted = FALSE") Integer selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(@Param("userId") Long userId, @Param("bizType") Integer bizType, @Param("beginTime") LocalDateTime beginTime, diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java index 8b2fbb8ab..aa9fc09e0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java @@ -38,6 +38,7 @@ public interface BrokerageWithdrawMapper extends BaseMapperX Date: Mon, 25 Sep 2023 09:39:39 +0800 Subject: [PATCH 41/42] =?UTF-8?q?code=20review=EF=BC=9A=E5=88=86=E9=94=80?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/number/MoneyUtils.java | 3 +++ .../api/spu/dto/ProductSpuRespDTO.java | 1 + .../dal/dataobject/spu/ProductSpuDO.java | 1 + .../module/trade/enums/DictTypeConstants.java | 1 + .../brokerage/BrokerageUserController.java | 7 ++++--- .../brokerage/AppBrokerageUserController.java | 4 +++- .../brokerage/BrokerageWithdrawMapper.java | 1 + .../brokerage/BrokerageRecordServiceImpl.java | 19 ++++++++----------- .../brokerage/BrokerageUserServiceImpl.java | 1 + .../api/user/dto/MemberUserRespDTO.java | 2 +- .../app/dict/AppDictDataController.java | 2 +- .../app/dict/vo/AppDictDataRespVO.java | 12 ------------ .../system/dal/mysql/dict/DictDataMapper.java | 4 +++- 13 files changed, 28 insertions(+), 30 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java index cac8438e0..e0b739920 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java @@ -61,10 +61,13 @@ public class MoneyUtils { /** * 分转元(字符串) * + * 例如说 fen 为 1 时,则结果为 0.01 + * * @param fen 分 * @return 元 */ public static String fenToYuanStr(int fen) { return new Money(0, fen).toString(); } + } diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java index fe2939efc..cad6bfcb2 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java @@ -147,4 +147,5 @@ public class ProductSpuRespDTO { * true - 自行设置 */ private Boolean subCommissionType; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java index 905bb890b..9e073fee7 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/spu/ProductSpuDO.java @@ -179,6 +179,7 @@ public class ProductSpuDO extends BaseDO { @TableField(typeHandler = JacksonTypeHandler.class) private List giveCouponTemplateIds; + // TODO @puhui999:字段估计要改成 brokerageType /** * 分销类型 * diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java index 4ff3c95f2..ff09e59d8 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/DictTypeConstants.java @@ -8,4 +8,5 @@ package cn.iocoder.yudao.module.trade.enums; public interface DictTypeConstants { String BROKERAGE_WITHDRAW_STATUS = "brokerage_withdraw_status"; // 佣金提现状态 + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java index f12a62358..8d27dd3b4 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java @@ -92,6 +92,7 @@ public class BrokerageUserController { Set userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId); // 查询用户信息 Map userMap = memberUserApi.getUserMap(userIds); + // TODO @疯狂:看看下面两个 getBrokerageUserCountByBindUserId、getWithdrawSummaryByUserId 有没可能一次性出结果,不然 n 次有点太花性能了; // 合计分佣订单 Map userOrderSummaryMap = convertMap(userIds, userId -> userId, @@ -101,13 +102,13 @@ public class BrokerageUserController { Map brokerageUserCountMap = convertMap(userIds, userId -> userId, userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null)); - // 合计提现 Map withdrawMap = convertMap(userIds, userId -> userId, userId -> brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)); - - return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap, withdrawMap)); + // 拼接返回 + return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, + userOrderSummaryMap, withdrawMap)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 2e8db1bbc..da78f9dff 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -77,13 +77,15 @@ public class AppBrokerageUserController { @PreAuthenticated public CommonResult getBrokerageUserSummary() { Long userId = getLoginUserId(); + // TODO @疯狂:后面这种,要不也改成 convert;感觉 controller 这样更容易看到整体;核心其实是 86、8/87、9/90、9/91 这阶段 // 统计 yesterdayPrice、withdrawPrice、firstBrokerageUserCount、secondBrokerageUserCount 字段 LocalDateTime yesterday = LocalDateTime.now().minusDays(1); LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime)) - .setWithdrawPrice(Optional.ofNullable(brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)).map(UserWithdrawSummaryBO::getPrice).orElse(0)) + .setWithdrawPrice(Optional.ofNullable(brokerageWithdrawService.getWithdrawSummaryByUserId(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS)) + .map(UserWithdrawSummaryBO::getPrice).orElse(0)) .setBrokeragePrice(0).setFrozenPrice(0) .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1)) .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2)); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java index aa9fc09e0..f8ca4c5b7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java @@ -41,4 +41,5 @@ public interface BrokerageWithdrawMapper extends BaseMapperX skuList = productSkuApi.getSkuListBySpuId(ListUtil.of(spuId)); if (BooleanUtil.isTrue(spu.getSubCommissionType())) { - // 3.1 商品单独分佣模式 fixedMinPrice = getMinValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice); fixedMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getFirstBrokeragePrice); + // 3.2 全局分佣模式(根据商品价格比例计算) } else { - // 3.2 全局分佣模式(根据商品价格比例计算) spuMinPrice = getMinValue(skuList, ProductSkuRespDTO::getPrice); spuMaxPrice = getMaxValue(skuList, ProductSkuRespDTO::getPrice); } - respVO.setBrokerageMinPrice(calculatePrice(spuMinPrice, tradeConfig.getBrokerageFirstPercent(), fixedMinPrice)); respVO.setBrokerageMaxPrice(calculatePrice(spuMaxPrice, tradeConfig.getBrokerageFirstPercent(), fixedMaxPrice)); return respVO; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java index 182e457b5..8672f3069 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java @@ -236,6 +236,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { // 校验分销关系绑定模式 if (BrokerageBindModeEnum.REGISTER.getMode().equals(tradeConfig.getBrokerageBindMode())) { + // TODO @疯狂:是不是把 isNewUser 挪到这里好点呀? if (!BooleanUtil.isTrue(isNewUser)) { throw exception(BROKERAGE_BIND_MODE_REGISTER); // 只有在注册时可以绑定 } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java index 85dad84d7..e55eda154 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/user/dto/MemberUserRespDTO.java @@ -36,7 +36,7 @@ public class MemberUserRespDTO { */ private String mobile; /** - * 创建时间 + * 创建时间(注册时间) */ private LocalDateTime createTime; diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java index 2332875b8..1f4f78c80 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java @@ -31,7 +31,7 @@ public class AppDictDataController { @GetMapping("/type") @Operation(summary = "根据字典类型查询字典数据信息") @Parameter(name = "type", description = "字典类型", required = true, example = "common_status") - public CommonResult> getDictDataListByType(@RequestParam String type) { + public CommonResult> getDictDataListByType(@RequestParam("type") String type) { List list = dictDataService.getEnabledDictDataListByType(type); return success(DictDataConvert.INSTANCE.convertList03(list)); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java index b7dfaf230..e2d141603 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java @@ -6,7 +6,6 @@ import lombok.Data; import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; @Schema(description = "用户 App - 字典数据信息 Response VO") @@ -19,23 +18,12 @@ public class AppDictDataRespVO { private Long id; @Schema(description = "字典标签", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") - @NotBlank(message = "字典标签不能为空") - @Size(max = 100, message = "字典标签长度不能超过100个字符") private String label; @Schema(description = "字典值", requiredMode = Schema.RequiredMode.REQUIRED, example = "iocoder") - @NotBlank(message = "字典键值不能为空") - @Size(max = 100, message = "字典键值长度不能超过100个字符") private String value; @Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex") - @NotBlank(message = "字典类型不能为空") - @Size(max = 100, message = "字典类型长度不能超过100个字符") private String dictType; - @Schema(description = "颜色类型,default、primary、success、info、warning、danger", example = "default") - private String colorType; - @Schema(description = "css 样式", example = "btn-visible") - private String cssClass; - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java index 85da83a5d..f92c86298 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java @@ -50,6 +50,8 @@ public interface DictDataMapper extends BaseMapperX { default List selectListByTypeAndStatus(String dictType, Integer status) { return selectList(new LambdaQueryWrapper() - .eq(DictDataDO::getDictType, dictType).eq(DictDataDO::getStatus, status)); + .eq(DictDataDO::getDictType, dictType) + .eq(DictDataDO::getStatus, status)); } + } From 6fcff0863a858a3e44ab26e46baac4e4a3021d7b Mon Sep 17 00:00:00 2001 From: jason <2667446@qq.com> Date: Mon, 25 Sep 2023 10:43:23 +0800 Subject: [PATCH 42/42] =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=AE=9D=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E9=80=80=E6=AC=BE=E6=8E=A5=E5=8F=A3=20subCode=20=3D?= =?UTF-8?q?=3D=20ACQ.SYSTEM=5FERROR=20=E8=BF=94=E5=9B=9E=20WAITING=20?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/core/client/dto/transfer/PayTransferRespDTO.java | 5 +++++ .../core/client/dto/transfer/PayTransferUnifiedReqDTO.java | 2 +- .../pay/core/client/impl/PayClientFactoryImpl.java | 2 ++ .../core/client/impl/alipay/AbstractAlipayPayClient.java | 2 +- .../pay/core/client/impl/alipay/AlipayTransferClient.java | 6 ++---- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferRespDTO.java index 1de0de2fc..bd961dfa3 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferRespDTO.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferRespDTO.java @@ -13,6 +13,11 @@ import java.time.LocalDateTime; @Data public class PayTransferRespDTO { + /** + * 转账状态 + * + * 关联 {@link PayTransferStatusRespEnum#getStatus()} + */ private Integer status; /** diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferUnifiedReqDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferUnifiedReqDTO.java index 6d1ef3998..2cb2267cc 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferUnifiedReqDTO.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/transfer/PayTransferUnifiedReqDTO.java @@ -51,7 +51,7 @@ public class PayTransferUnifiedReqDTO { private String title; /** - * 收款方信息,转账类型不同信息不同 + * 收款方信息,转账类型不同,收款方信息不同 */ @NotEmpty(message = "收款方信息 不能为空") private Map payeeInfo; diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java index 0b39587ab..8e85bd4cd 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java @@ -50,6 +50,8 @@ public class PayClientFactoryImpl implements PayClientFactory { clientClass.put(ALIPAY_APP, AlipayAppPayClient.class); clientClass.put(ALIPAY_PC, AlipayPcPayClient.class); clientClass.put(ALIPAY_BAR, AlipayBarPayClient.class); + // 支付包转账客户端 + clientClass.put(ALIPAY_TRANSFER, AlipayTransferClient.class); // Mock 支付客户端 clientClass.put(MOCK, MockPayClient.class); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java index e62120ae5..ceafe5a30 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayPayClient.java @@ -151,7 +151,7 @@ public abstract class AbstractAlipayPayClient extends AbstractPayClient