From 1b288400da64afa45b6f5a92b74a691fd670880f Mon Sep 17 00:00:00 2001 From: 13233904609 <13233904609@163.cm> Date: Tue, 3 Sep 2024 14:29:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E9=80=81=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/spu/dto/ProductSpuRespDTO.java | 4 ++ .../trade/enums/ErrorCodeConstants.java | 2 + .../app/order/AppTradeOrderController.java | 17 +++++++++ .../BrokerageWithdrawServiceImpl.java | 38 ++++++++++++++----- .../enums/wallet/PayWalletBizTypeEnum.java | 3 +- .../service/order/PayOrderServiceImpl.java | 2 + .../service/wallet/PayWalletServiceImpl.java | 8 ++++ 7 files changed, 63 insertions(+), 11 deletions(-) diff --git a/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java b/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java index 5479b9a..2637131 100644 --- a/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java +++ b/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/spu/dto/ProductSpuRespDTO.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.product.api.spu.dto; import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; import lombok.Data; +import java.util.List; + // TODO @LeeYan9: ProductSpuRespDTO /** * 商品 SPU 信息 Response DTO @@ -93,4 +95,6 @@ public class ProductSpuRespDTO { */ private Boolean subCommissionType; + private List deliveryTypes; + } diff --git a/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 02173a6..b18438f 100644 --- a/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -94,4 +94,6 @@ public interface ErrorCodeConstants { ErrorCode BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH = new ErrorCode(1_011_008_003, "您当前最多可提现 {} 元"); ErrorCode VERIFY_LOG_NOT_EXISTS = new ErrorCode(1_011_008_004, "门店核销记录不存在"); + + ErrorCode DELIVERY_NOT_EXISTS = new ErrorCode(1_011_008_005, "订单中商品某个商品配送方式不支持"); } diff --git a/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 48def81..8de8cb4 100644 --- a/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.controller.app.order; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; @@ -48,12 +49,15 @@ import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error; 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.security.core.util.SecurityFrameworkUtils.getLoginUser; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.PAY_ORDER_EXTENSION_STATUS_IS_NOT_WAITING; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.DELIVERY_NOT_EXISTS; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_UPDATE_PAID_STATUS_NOT_UNPAID; @Tag(name = "用户 App - 交易订单") @RestController @@ -139,6 +143,19 @@ public class AppTradeOrderController { LoginUser loginUser = getLoginUser(); createReqVO.setReceiverName(loginUser.getInfo().getOrDefault("nickname","")); createReqVO.setReceiverMobile(loginUser.getInfo().getOrDefault("mobile","")); + //判断商品配送方式 + List items = createReqVO.getItems(); + if(ObjectUtil.isNotEmpty(items)){ + for (AppTradeOrderSettlementReqVO.Item item:items) { + ProductSkuRespDTO sku = productSkuApi.getSku(item.getSkuId()); + ProductSpuRespDTO spu = productSpuApi.getSpu(sku.getSpuId()); + if(ObjectUtil.isNotEmpty(spu.getDeliveryTypes())){ + if(!CollUtil.contains(spu.getDeliveryTypes(),createReqVO.getDeliveryType())){ + throw exception0(1_011_008_006,"商品:"+spu.getName()+"配送方式不支持,请修改后重新提交!"); + } + } + } + } TradeOrderDO order = tradeOrderUpdateService.createOrder(getLoginUserId(), createReqVO); return success(new AppTradeOrderCreateRespVO().setId(order.getId()).setPayOrderId(order.getPayOrderId())); } diff --git a/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java b/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java index 6a938f9..d414a09 100644 --- a/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java +++ b/ruoyi-vue-pro-master/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java @@ -38,14 +38,16 @@ import javax.annotation.Resource; import javax.validation.Validator; import java.io.IOException; import java.io.InputStreamReader; +import java.math.BigDecimal; import java.net.HttpURLConnection; import java.net.URL; +import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.util.*; import org.springframework.core.io.ResourceLoader; import org.springframework.beans.factory.annotation.Value; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum.RECHARGE; +import static cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum.*; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; /** @@ -134,19 +136,35 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { paramMap.put("alipay_cert_path_string", keyContent1); paramMap.put("alipay_root_cert_path_string", keyContent2); paramMap.put("remark", "余额提现到支付宝"); - paramMap.put("out_biz_no", "111222333"); - paramMap.put("account", "13233904609");//账号 - paramMap.put("name", "马腾达"); - paramMap.put("amount", "0.1"); - String result= HttpUtil.post(gateway, paramMap); + paramMap.put("out_biz_no", new SimpleDateFormat("yyyyMMddhhmmss").format(new Date())+"-"+withdraw.getId()); + paramMap.put("account", withdraw.getAccountNo());//账号 + paramMap.put("name", withdraw.getName()); + paramMap.put("amount", BigDecimal.valueOf(withdraw.getPrice()).subtract(BigDecimal.valueOf(withdraw.getFeePrice())).divide(BigDecimal.valueOf(100))); + String result= HttpUtil.post(gateway, JSON.toJSONString(paramMap)); + JSONObject jsonObject = JSONObject.parseObject(result); + if(jsonObject.containsKey("msg")){ + if(ObjectUtil.equal("success",jsonObject.getString("msg"))){ + withdraw.setStatus(11); + withdraw.setAuditTime(LocalDateTime.now()); + }else{ + withdraw.setStatus(21); + withdraw.setAuditTime(LocalDateTime.now()); + //提现失败返还余额 + PayWalletDTO orCreateWallet = payWalletApi.getOrCreateWallet(withdraw.getUserId(), 1); + payWalletApi.addWalletBalance(orCreateWallet.getId(),withdraw.getId()+"",WITHDRAW_LOSE,withdraw.getPrice()); + } + } + brokerageWithdrawMapper.updateById(withdraw); System.out.println(result); } // TODO 疯狂:调用转账接口 } else if (BrokerageWithdrawStatusEnum.AUDIT_FAIL.equals(status)) { - templateCode = MessageTemplateConstants.BROKERAGE_WITHDRAW_AUDIT_REJECT; - // 3.2 驳回时需要退还用户佣金 - brokerageRecordService.addBrokerage(withdraw.getUserId(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT, - String.valueOf(withdraw.getId()), withdraw.getPrice(), BrokerageRecordBizTypeEnum.WITHDRAW_REJECT.getTitle()); + //提现失败返还余额 + PayWalletDTO orCreateWallet = payWalletApi.getOrCreateWallet(withdraw.getUserId(), 1); + payWalletApi.addWalletBalance(orCreateWallet.getId(),withdraw.getId()+"",WITHDRAW_REJECT,withdraw.getPrice()); + withdraw.setStatus(20); + withdraw.setAuditTime(LocalDateTime.now()); + brokerageWithdrawMapper.updateById(withdraw); } else { throw new IllegalArgumentException("不支持的提现状态:" + status); } diff --git a/ruoyi-vue-pro-master/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/wallet/PayWalletBizTypeEnum.java b/ruoyi-vue-pro-master/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/wallet/PayWalletBizTypeEnum.java index d23cafd..f71bbba 100644 --- a/ruoyi-vue-pro-master/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/wallet/PayWalletBizTypeEnum.java +++ b/ruoyi-vue-pro-master/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/wallet/PayWalletBizTypeEnum.java @@ -20,7 +20,8 @@ public enum PayWalletBizTypeEnum implements IntArrayValuable { PAYMENT(3, "支付"), PAYMENT_REFUND(4, "支付退款"), WITHDRAW(5, "提现申请"), - WITHDRAW_REJECT(6, "提现申请驳回"); + WITHDRAW_REJECT(6, "提现申请驳回"), + WITHDRAW_LOSE(7, "提现失败退还零钱"); diff --git a/ruoyi-vue-pro-master/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java b/ruoyi-vue-pro-master/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java index bdac905..1986e21 100644 --- a/ruoyi-vue-pro-master/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java +++ b/ruoyi-vue-pro-master/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java @@ -162,6 +162,8 @@ public class PayOrderServiceImpl implements PayOrderService { PayChannelDO channel = validateChannelCanSubmit(order.getAppId(), reqVO.getChannelCode()); PayClient client = channelService.getPayClient(channel.getId()); + //校验配送方式否支持 + // 2. 插入 PayOrderExtensionDO String no = noRedisDAO.generate(payProperties.getOrderNoPrefix()); PayOrderExtensionDO orderExtension = PayOrderConvert.INSTANCE.convert(reqVO, userIp) diff --git a/ruoyi-vue-pro-master/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/ruoyi-vue-pro-master/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index 59d6afa..a5445c1 100644 --- a/ruoyi-vue-pro-master/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/ruoyi-vue-pro-master/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -233,6 +233,14 @@ public class PayWalletServiceImpl implements PayWalletService { walletMapper.updateWhenRecharge(payWallet.getId(), price); break; } + case WITHDRAW_REJECT: { // 充值更新 + walletMapper.updateWhenRecharge(payWallet.getId(), price); + break; + } + case WITHDRAW_LOSE: { // 充值更新 + walletMapper.updateWhenRecharge(payWallet.getId(), price); + break; + } default: { // TODO 其它类型待实现 throw new UnsupportedOperationException("待实现");