From afaca094f52941927263c9e2fe409cd76c9d20e1 Mon Sep 17 00:00:00 2001 From: Jack <46790855@qq.com> Date: Tue, 30 Sep 2025 22:16:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=80=E6=AC=BE=20=E9=85=8D=E9=80=81?= =?UTF-8?q?=E8=B4=B9=20=E6=B5=81=E7=A8=8B=E6=9B=B4=E6=94=B9=EF=BC=8C?= =?UTF-8?q?=E6=8B=89=E5=8D=A1=E6=8B=89=20=E5=90=88=E5=8D=95=20=E9=9C=80?= =?UTF-8?q?=E5=88=86=E5=BC=80=20=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/common/constant/CommonConstant.java | 5 + .../exception/GlobalExceptionHandler.java | 4 +- .../common/modules/order/ShopOrderData.java | 3 + .../modules/order/dto/MchOrderInfoDTO.java | 2 + .../mall/common/pojo/dto/LklSeparateDTO.java | 4 +- .../service/impl/LakalaPayServiceImpl.java | 4 + .../impl/PayConsumeTradeServiceImpl.java | 358 +----------------- .../shop/lakala/service/LakalaApiService.java | 24 ++ .../service/impl/LakalaApiServiceImpl.java | 107 ++++++ .../impl/ShopMessageTemplateServiceImpl.java | 81 ++-- .../admin/ShopOrderReturnController.java | 3 + .../order/service/ShopOrderLklService.java | 19 + .../impl/ShopOrderBaseServiceImpl.java | 62 ++- .../service/impl/ShopOrderLklServiceImpl.java | 62 +++ .../impl/ShopOrderReturnServiceImpl.java | 65 ++-- .../mapper/order/ShopOrderBaseMapper.xml | 4 +- .../mapper/order/ShopOrderDataMapper.xml | 2 +- 17 files changed, 367 insertions(+), 442 deletions(-) diff --git a/mall-common/src/main/java/com/suisung/mall/common/constant/CommonConstant.java b/mall-common/src/main/java/com/suisung/mall/common/constant/CommonConstant.java index 52c0ec0f..5837be79 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/constant/CommonConstant.java +++ b/mall-common/src/main/java/com/suisung/mall/common/constant/CommonConstant.java @@ -110,4 +110,9 @@ public class CommonConstant { //秒杀活动订阅消息模板id public static final String BIND_SUB_TMPL_SKILL = "kiDj_hSF_ASwD-Dlgxnypi6IJBQZ12a-hEpd3zZ-Uxc"; + //分账计算方式:1-按总金额;2-按可分账金额; + public static final int SeparateCalcMode_TotalAmt = 1; + public static final int SeparateCalcMode_CanSeparateAmt = 2; + + } diff --git a/mall-common/src/main/java/com/suisung/mall/common/exception/GlobalExceptionHandler.java b/mall-common/src/main/java/com/suisung/mall/common/exception/GlobalExceptionHandler.java index 850a999c..f36913fe 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/exception/GlobalExceptionHandler.java +++ b/mall-common/src/main/java/com/suisung/mall/common/exception/GlobalExceptionHandler.java @@ -3,6 +3,7 @@ package com.suisung.mall.common.exception; import cn.hutool.core.util.StrUtil; import com.suisung.mall.common.api.CommonResult; import com.suisung.mall.common.api.ResultCode; +import io.seata.rm.datasource.exec.LockWaitTimeoutException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.dao.DataAccessException; @@ -91,13 +92,14 @@ public class GlobalExceptionHandler { /** * 处理系统级异常(数据库异常/通用异常) */ - @ExceptionHandler({SQLException.class, DataAccessException.class, Exception.class}) + @ExceptionHandler({SQLException.class, DataAccessException.class, LockWaitTimeoutException.class, Exception.class}) public CommonResult handleSystemException(HttpServletRequest req, Exception e) { logError(req, e.getMessage(), e); if (e instanceof SQLException || e instanceof DataAccessException) { return CommonResult.failed("系统数据异常,请联系管理员!"); } + return CommonResult.failed("系统内部异常,请联系管理员!"); } diff --git a/mall-common/src/main/java/com/suisung/mall/common/modules/order/ShopOrderData.java b/mall-common/src/main/java/com/suisung/mall/common/modules/order/ShopOrderData.java index d00071c8..152a1839 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/modules/order/ShopOrderData.java +++ b/mall-common/src/main/java/com/suisung/mall/common/modules/order/ShopOrderData.java @@ -92,6 +92,9 @@ public class ShopOrderData implements Serializable { @ApiModelProperty(value = "实际运费金额-卖家可修改") private BigDecimal order_shipping_fee; + @ApiModelProperty(value = "平台内部运费金额") + private BigDecimal order_shipping_fee_inner; + @ApiModelProperty(value = "总计分账金额(从拉卡拉上分账,分给平台和代理商费用),单位:元") private BigDecimal total_separate_value; diff --git a/mall-common/src/main/java/com/suisung/mall/common/modules/order/dto/MchOrderInfoDTO.java b/mall-common/src/main/java/com/suisung/mall/common/modules/order/dto/MchOrderInfoDTO.java index 09dc7562..002a4a4b 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/modules/order/dto/MchOrderInfoDTO.java +++ b/mall-common/src/main/java/com/suisung/mall/common/modules/order/dto/MchOrderInfoDTO.java @@ -72,6 +72,8 @@ public class MchOrderInfoDTO implements Serializable { private Integer delivery_type_id; @ApiModelProperty(value = "订单运费") private BigDecimal order_shipping_fee; + @ApiModelProperty(value = "平台内部配送费") + private BigDecimal order_shipping_fee_inner; @ApiModelProperty(value = "平台费") private BigDecimal platform_fee; @ApiModelProperty(value = "店铺统一设置的打包费") diff --git a/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/LklSeparateDTO.java b/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/LklSeparateDTO.java index 13c43d3a..7050b80f 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/LklSeparateDTO.java +++ b/mall-common/src/main/java/com/suisung/mall/common/pojo/dto/LklSeparateDTO.java @@ -68,8 +68,8 @@ public class LklSeparateDTO { dto2.setMchRatio(new BigDecimal("0.95")); // 商家分账比例 0.857 (会产生小数) dto2.setPlatRatio(new BigDecimal("0.06")); // 平台分账比例 0.01 // 不设置一级和二级代理商分账比例,测试不参与分账的情况 - // dto2.setAgent1stRatio(new BigDecimal("0.01")); // 一级代理商分账比例 0.023 (会产生小数) - // dto2.setAgent2ndRatio(new BigDecimal("0.04")); // 二级代理商分账比例 0.031 (会产生小数) + dto2.setAgent1stRatio(new BigDecimal("0.11")); // 一级代理商分账比例 0.023 (会产生小数) + dto2.setAgent2ndRatio(new BigDecimal("0.04")); // 二级代理商分账比例 0.031 (会产生小数) SharingResult result2 = dto2.sharingOnCanSeparateAmount(); System.out.println(result2); diff --git a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaPayServiceImpl.java b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaPayServiceImpl.java index af84ef61..7777d5df 100644 --- a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaPayServiceImpl.java +++ b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/LakalaPayServiceImpl.java @@ -574,6 +574,10 @@ public class LakalaPayServiceImpl implements LakalaPayService { // TODO 重要的逻辑,获取是否已经分账?已分账:分账退回;查商家账户余额够不够退回?够就执行退回 + if (StrUtil.isBlank(refundReason)) { + refundReason = "商家与买方协商退款"; + } + // 5. 构造退款请求并发送 V3LabsRelationRefundRequest refundRequest = new V3LabsRelationRefundRequest(); refundRequest.setOutTradeNo(outTradeNo); diff --git a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayConsumeTradeServiceImpl.java b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayConsumeTradeServiceImpl.java index 873fc809..a8678096 100644 --- a/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayConsumeTradeServiceImpl.java +++ b/mall-pay/src/main/java/com/suisung/mall/pay/service/impl/PayConsumeTradeServiceImpl.java @@ -188,7 +188,7 @@ public class PayConsumeTradeServiceImpl extends BaseServiceImpl return_rows) { - List paid_return_id_row = new ArrayList<>(); - - // 原路退回标记 - boolean order_refund_flag = accountBaseConfigService.getConfig("order_refund_flag", false); - List order_id_rows = return_rows.stream().map(ShopOrderReturn::getOrder_id).distinct().collect(Collectors.toList()); - - List order_data_rows = shopService.getsShopOrderData(order_id_rows); - - List store_ids = return_rows.stream().map(ShopOrderReturn::getStore_id).distinct().collect(Collectors.toList()); - List store_rows = shopService.getsShopStoreBase(store_ids); - - List user_ids = return_rows.stream().map(ShopOrderReturn::getBuyer_user_id).distinct().collect(Collectors.toList()); - // 不使用缓存防止缓存被保存导致回滚异常 - List payUserResources = payUserResourceService.listByIds(user_ids); - List order_info_rows = shopService.getsShopOrderInfo(order_id_rows); - - List return_ids = return_rows.stream().map(ShopOrderReturn::getReturn_id).distinct().collect(Collectors.toList()); - if (CollUtil.isEmpty(return_ids)) { - return false; - } - - Map queryParams = new HashMap(); - queryParams.put("return_id:in", return_ids); - List orderReturnItemList = shopService.findShopOrderReturnItem(queryParams); - if (CollUtil.isEmpty(orderReturnItemList)) { - throw new ApiException(I18nUtil._("没有找到相关的退货商品信息!")); - } - - List order_item_ids = orderReturnItemList.stream().map(ShopOrderReturnItem::getOrder_item_id).distinct().collect(Collectors.toList()); - List orderItemList = shopService.getsShopOrderItem(order_item_ids); - - Date curTime = new Date(); - DateTime ymdTime = DateUtil.parse(DateUtil.format(curTime, "yyyy-MM-dd")); - - float points_vaue_rate = accountBaseConfigService.getConfig("points_vaue_rate", 0f); - - // 积分抵扣,暂时忽略,不涉及此处支付。 - // 按照次序,依次支付。 - for (ShopOrderReturn return_row : return_rows) { - - Integer user_id = return_row.getBuyer_user_id(); - if (CheckUtil.isEmpty(user_id)) { - throw new ApiException(I18nUtil._("买家信息有误!")); - } - - Integer buyer_store_id = return_row.getBuyer_store_id(); - - Integer store_id = return_row.getStore_id(); - Optional storeOpl = store_rows.stream().filter(s -> ObjectUtil.equal(Convert.toInt(s.get("store_id")), store_id)).findFirst(); - Map store_row = storeOpl.orElseGet(HashMap::new); - - Integer seller_id = (Integer) store_row.get("user_id"); - if (CheckUtil.isEmpty(seller_id)) { - throw new ApiException(I18nUtil._("卖家信息有误!")); - } - - // 判断当前余额 - Optional userResourceOpl = payUserResources.stream().filter(s -> ObjectUtil.equal(user_id, s.getUser_id())).findFirst(); - PayUserResource user_resource_row = userResourceOpl.orElseGet(PayUserResource::new); - - // todo 判断是否需要退佣金 $return_row['return_commision_fee'] - BigDecimal return_commision_fee = BigDecimal.ZERO; - - // 不是退运费 - String order_id = return_row.getOrder_id(); - Integer return_is_shipping_fee = return_row.getReturn_is_shipping_fee(); - if (CheckUtil.isEmpty(return_is_shipping_fee)) { - float withdraw_received_day = Convert.toFloat(accountBaseConfigService.getConfig("withdraw_received_day")); - if (withdraw_received_day == 0) { - withdraw_received_day = 7f; - } - - if (withdraw_received_day >= 0) { - Optional orderInfoOpl = order_info_rows.stream().filter(s -> ObjectUtil.equal(order_id, s.getOrder_id())).findFirst(); - ShopOrderInfo order_info_row = orderInfoOpl.orElseGet(ShopOrderInfo::new); - - Integer order_state_id = order_info_row.getOrder_state_id(); - Integer order_is_paid = order_info_row.getOrder_is_paid(); - Long order_deal_time = order_info_row.getOrder_deal_time(); - long time = DateUtil.offsetDay(curTime, -7).getTime(); - - // 未到可结算时间可退佣金 - if (ObjectUtil.equal(order_state_id, StateCode.ORDER_STATE_FINISH) - && ObjectUtil.equal(order_is_paid, StateCode.ORDER_PAID_STATE_YES) - && order_deal_time < time) { - return_commision_fee = BigDecimal.ZERO; - } else { - return_commision_fee = return_row.getReturn_commision_fee(); - } - } - } - - BigDecimal waiting_refund_amount = return_row.getReturn_refund_amount(); - if (CheckUtil.isNotEmpty(waiting_refund_amount)) { - - Optional OrderDataOpl = order_data_rows.stream().filter(s -> ObjectUtil.equal(s.getOrder_id(), order_id)).findFirst(); - ShopOrderData order_data_row = OrderDataOpl.orElseGet(ShopOrderData::new); - - BigDecimal order_points_fee = order_data_row.getOrder_points_fee(); - BigDecimal order_refund_agree_points = order_data_row.getOrder_refund_agree_points(); - - BigDecimal buyer_user_money = waiting_refund_amount; - BigDecimal buyer_user_points = BigDecimal.ZERO; - - BigDecimal seller_user_money = waiting_refund_amount.negate(); - String return_id = return_row.getReturn_id(); - - // 写入流水 - PayConsumeRecord buyer_consume_record_row = new PayConsumeRecord(); - - buyer_consume_record_row.setOrder_id(return_id); - buyer_consume_record_row.setUser_id(user_id); - buyer_consume_record_row.setStore_id(buyer_store_id); - buyer_consume_record_row.setUser_nickname(""); // todo User_nickname - buyer_consume_record_row.setRecord_date(ymdTime); - buyer_consume_record_row.setRecord_year(DateUtil.year(ymdTime)); - buyer_consume_record_row.setRecord_month(DateUtil.month(ymdTime) + 1); - buyer_consume_record_row.setRecord_day(DateUtil.dayOfMonth(ymdTime)); - buyer_consume_record_row.setRecord_title(I18nUtil._("退款单:") + return_id); - buyer_consume_record_row.setRecord_time(curTime); - buyer_consume_record_row.setPayment_met_id(PaymentType.PAYMENT_MET_MONEY); - - // 增加流水 - buyer_consume_record_row.setRecord_money(waiting_refund_amount); // 佣金问题? - buyer_consume_record_row.setTrade_type_id(StateCode.TRADE_TYPE_REFUND_GATHERING); - - // 卖家流水记录 - PayConsumeRecord seller_consume_record_row = ObjectUtil.clone(buyer_consume_record_row); - - seller_consume_record_row.setUser_id(seller_id); - seller_consume_record_row.setStore_id(store_id); - seller_consume_record_row.setRecord_money(NumberUtil.add(waiting_refund_amount.negate(), return_commision_fee)); - seller_consume_record_row.setRecord_commission_fee(return_commision_fee.negate()); - seller_consume_record_row.setTrade_type_id(StateCode.TRADE_TYPE_REFUND_PAY); - - order_data_row.setOrder_refund_agree_amount(NumberUtil.add(waiting_refund_amount, order_refund_agree_points)); - - // todo 不能在这里统计,并发情况下seata操作同一张表数据会导致无法回滚的问题 原因:A线程修改完数据记录到undo_log表中,回滚的时候发现B线程也修改了这个数据 - // 平台佣金总额 - /*if (CheckUtil.isNotEmpty(return_commision_fee)) { - PayPlantformResource plantform_resource_row = payPlantformResourceService.get(DATA_ID); - if (plantform_resource_row == null) { - plantform_resource_row = new PayPlantformResource(); - plantform_resource_row.setPlantform_resource_id(DATA_ID); - } - plantform_resource_row.setPlantform_commission_fee(NumberUtil.add(return_commision_fee.negate(), plantform_resource_row.getPlantform_commission_fee())); - if (!payPlantformResourceService.saveOrUpdate(plantform_resource_row)) { - throw new ApiException(ResultCode.FAILED); - } - - BigDecimal order_commission_fee_refund = order_data_row.getOrder_commission_fee_refund(); - order_data_row.setOrder_commission_fee_refund(NumberUtil.add(order_commission_fee_refund, return_commision_fee)); - }*/ - - // 读取退款单项目 - List order_return_item_rows = orderReturnItemList.stream().filter(s -> ObjectUtil.equal(s.getReturn_id(), return_id)).collect(Collectors.toList()); - if (CollUtil.isNotEmpty(orderItemList)) { - - List order_item_rows = new ArrayList<>(); - for (ShopOrderReturnItem order_return_item_row : order_return_item_rows) { - - Long order_item_id = order_return_item_row.getOrder_item_id(); - Optional orderItemOpl = orderItemList.stream().filter(s -> ObjectUtil.equal(order_item_id, s.getOrder_item_id())).findFirst(); - if (orderItemOpl.isPresent()) { - ShopOrderItem order_item_row = orderItemOpl.get(); - - BigDecimal return_item_subtotal = order_return_item_row.getReturn_item_subtotal(); - Integer return_item_num = order_return_item_row.getReturn_item_num(); - BigDecimal order_item_return_agree_amount = order_item_row.getOrder_item_return_agree_amount(); - Integer order_item_return_agree_num = ObjectUtil.defaultIfNull(order_item_row.getOrder_item_return_agree_num(), 0); - - order_item_row.setOrder_item_return_agree_amount(NumberUtil.add(order_item_return_agree_amount, return_item_subtotal)); - order_item_row.setOrder_item_return_agree_num(order_item_return_agree_num + return_item_num); - - // 订单未结算才发放佣金 - if (CheckUtil.isNotEmpty(return_commision_fee)) { - BigDecimal return_item_commision_fee = order_return_item_row.getReturn_item_commision_fee(); - BigDecimal order_item_commission_fee_refund = ObjectUtil.defaultIfNull(order_item_row.getOrder_item_commission_fee_refund(), BigDecimal.ZERO); - order_item_row.setOrder_item_commission_fee_refund(NumberUtil.add(return_item_commision_fee, order_item_commission_fee_refund)); - } - order_item_rows.add(order_item_row); - } - } - - if (CollUtil.isNotEmpty(order_item_rows)) { - if (!shopService.editsShopOrderItem(order_item_rows)) { - throw new ApiException(I18nUtil._("修改订单商品数据失败!")); - } - } - } - - // 买家数据 - if (!payConsumeRecordService.saveOrUpdate(buyer_consume_record_row)) { - throw new ApiException(I18nUtil._("添加买家流水数据失败!")); - } - - // 如果混合了积分,优先退积分 - if (order_points_fee.compareTo(BigDecimal.ZERO) > 0 - && order_points_fee.compareTo(order_refund_agree_points) > 0) { - BigDecimal refund_points = NumberUtil.round(NumberUtil.min(NumberUtil.sub(order_points_fee, order_refund_agree_points)), 2); - buyer_user_money = NumberUtil.round(NumberUtil.sub(buyer_user_money, refund_points), 2); - - if (points_vaue_rate > 0) { - buyer_user_points = NumberUtil.div(refund_points, points_vaue_rate); - } - order_data_row.setOrder_refund_agree_points(NumberUtil.add(order_refund_agree_points, refund_points)); - } - - // todo 优化代码 - if (order_refund_flag) { - // 读取在线支付信息,如果无在线支付信息,则余额支付 否则在线支付【联合支付】判断 - QueryWrapper depositQueryWrapper = new QueryWrapper<>(); - depositQueryWrapper.apply(order_id != null, "FIND_IN_SET ('" + order_id + "', order_id )"); - PayConsumeDeposit consume_row = payConsumeDepositService.findOne(depositQueryWrapper); - - if (consume_row != null) { - Integer payment_channel_id = consume_row.getPayment_channel_id(); - PayPaymentChannel payment_channel_row = payPaymentChannelService.get(payment_channel_id); - String payment_channel_code = payment_channel_row.getPayment_channel_code(); - BigDecimal deposit_total_fee = consume_row.getDeposit_total_fee(); - - if (Arrays.asList("alipay", "wx_native").contains(payment_channel_code)) { - BigDecimal d_money = NumberUtil.round(NumberUtil.sub(buyer_user_money, deposit_total_fee), 2); - if (d_money.compareTo(BigDecimal.ZERO) > 0) { - PayUserResource payUserResource = payUserResourceService.getById(user_id); - payUserResource.setUser_money(NumberUtil.add(payUserResource.getUser_money(), d_money)); - if (!payUserResourceService.edit(payUserResource)) { - throw new ApiException(I18nUtil._("用户退款失败!")); - } - } - - if (buyer_user_points.compareTo(BigDecimal.ZERO) > 0) { - if (!payUserResourceService.points(user_id, buyer_user_points, PointsType.POINTS_TYPE_CONSUME_RETRUN, return_id, store_id, null, return_id)) { - throw new ApiException(I18nUtil._("用户退积分失败!")); - } - } - - String deposit_trade_no = consume_row.getDeposit_trade_no(); - - ShopOrderReturn orderReturn = new ShopOrderReturn(); - orderReturn.setReturn_id(return_id); - orderReturn.setReturn_channel_code(payment_channel_code); - orderReturn.setDeposit_trade_no(deposit_trade_no); - orderReturn.setPayment_channel_id(payment_channel_id); - orderReturn.setTrade_payment_amount(deposit_total_fee); - if (!shopService.editShopOrderReturn(orderReturn)) { - throw new ApiException(I18nUtil._("修改退单信息失败!")); - } - } else { - if (buyer_user_money.compareTo(BigDecimal.ZERO) > 0) { - PayUserResource payUserResource = payUserResourceService.getById(user_id); - payUserResource.setUser_money(NumberUtil.add(payUserResource.getUser_money(), buyer_user_money)); - if (!payUserResourceService.edit(payUserResource)) { - throw new ApiException(I18nUtil._("用户退款失败!")); - } - } - - if (buyer_user_points.compareTo(BigDecimal.ZERO) > 0) { - if (!payUserResourceService.points(user_id, buyer_user_points, PointsType.POINTS_TYPE_CONSUME_RETRUN, return_id, store_id, null, return_id)) { - throw new ApiException(I18nUtil._("用户退积分失败!")); - } - } - - ShopOrderReturn orderReturn = new ShopOrderReturn(); - orderReturn.setReturn_id(return_id); - orderReturn.setReturn_channel_flag(1); - if (!shopService.editShopOrderReturn(orderReturn)) { - throw new ApiException(I18nUtil._("修改退单信息失败!")); - } - } - } else { - if (buyer_user_money.compareTo(BigDecimal.ZERO) > 0) { - PayUserResource payUserResource = payUserResourceService.getById(user_id); - payUserResource.setUser_money(NumberUtil.add(payUserResource.getUser_money(), buyer_user_money)); - if (!payUserResourceService.edit(payUserResource)) { - throw new ApiException(I18nUtil._("用户退款失败!")); - } - } - - if (buyer_user_points.compareTo(BigDecimal.ZERO) > 0) { - if (!payUserResourceService.points(user_id, buyer_user_points, PointsType.POINTS_TYPE_CONSUME_RETRUN, return_id, store_id, null, return_id)) { - throw new ApiException(I18nUtil._("用户退积分失败!")); - } - } - - ShopOrderReturn orderReturn = new ShopOrderReturn(); - orderReturn.setReturn_id(return_id); - orderReturn.setReturn_channel_flag(1); - if (!shopService.editShopOrderReturn(orderReturn)) { - throw new ApiException(I18nUtil._("修改退单信息失败!")); - } - } - } else { - if (buyer_user_money.compareTo(BigDecimal.ZERO) > 0) { - PayUserResource payUserResource = payUserResourceService.getById(user_id); - payUserResource.setUser_money(NumberUtil.add(payUserResource.getUser_money(), buyer_user_money)); - if (!payUserResourceService.edit(payUserResource)) { - throw new ApiException(I18nUtil._("用户退款失败!")); - } - } - - if (buyer_user_points.compareTo(BigDecimal.ZERO) > 0) { - if (!payUserResourceService.points(user_id, buyer_user_points, PointsType.POINTS_TYPE_CONSUME_RETRUN, return_id, store_id, null, return_id)) { - throw new ApiException(I18nUtil._("用户退积分失败!")); - } - } - - ShopOrderReturn orderReturn = new ShopOrderReturn(); - orderReturn.setReturn_id(return_id); - orderReturn.setReturn_channel_flag(1); - if (!shopService.editShopOrderReturn(orderReturn)) { - throw new ApiException(I18nUtil._("修改退单信息失败!")); - } - } - - if (!shopService.editShopOrderData(order_data_row)) { - throw new ApiException(I18nUtil._("修改详细信息失败!")); - } - - // todo 修改订单状态? - if (buyer_user_money != null) { - // 流水记录 - if (!payConsumeRecordService.saveOrUpdate(seller_consume_record_row)) { - throw new ApiException(I18nUtil._("写入卖家信息失败!")); - } - - seller_user_money = NumberUtil.add(buyer_user_money.negate(), return_commision_fee); - PayUserResource payUserResource = payUserResourceService.getById(seller_id); - payUserResource.setUser_money(NumberUtil.add(payUserResource.getUser_money(), seller_user_money)); - if (!payUserResourceService.edit(payUserResource)) { - throw new ApiException(I18nUtil._("卖家用户退款失败!")); - } - } - - paid_return_id_row.add(return_id); - } - } - - if (CollUtil.isNotEmpty(paid_return_id_row)) { - // 远程服务器订单更改放入 - // 本地服务器订单更改 - if (!shopService.setReturnPaidYes(paid_return_id_row)) { - throw new ApiException(ResultCode.FAILED); - } - } - - return true; - } /** * 更改交易订单的订单状态和付款状态 diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/LakalaApiService.java b/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/LakalaApiService.java index 6f12006b..43fdabd5 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/LakalaApiService.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/LakalaApiService.java @@ -11,9 +11,11 @@ package com.suisung.mall.shop.lakala.service; import cn.hutool.json.JSONObject; import com.suisung.mall.common.api.CommonResult; import com.suisung.mall.common.modules.store.ShopMchEntry; +import com.suisung.mall.common.pojo.dto.LklSeparateDTO; import org.springframework.data.util.Pair; import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; /** * 拉卡拉业务接口 @@ -350,4 +352,26 @@ public interface LakalaApiService { */ JSONObject ewalletWithDrawNotify(HttpServletRequest request); + /** + * 商户分账参数计算及评估 + * + * @param splitMode 分账模式:1-总金额为基准分账,2-可分账金额基准分账,必填参数 + * @param orderPayAmount 订单支付总金额(单位:分)必填参数 + * @param shippingFeeInner 平台内部配送费(单位:分)必填参数 + * @param mchSplitRatioRaw 商户分账比例值(分子值,如10表示10%)必填参数 + * @param platSplitRatio 平台分账比例(百分比值,如0.01表示1%)可选参数 + * @param agent1stRatio 一级分账比例(百分比值,如0.01表示1%)可选参数 + * @param agent2ndRatio 二级分账比例(百分比值,如0.01表示1%)可选参数 + * @param refCanSeparateAmt 参考可分金额(单位:分) 可选参数 + * @return Pair 分账参数评估结果,第一个元素表示是否成功,第二个元素为分账参数对象 + */ + Pair calculateAndEvaluateSharingParams(int splitMode, + Integer orderPayAmount, + Integer shippingFeeInner, + BigDecimal mchSplitRatioRaw, + BigDecimal platSplitRatio, + BigDecimal agent1stRatio, + BigDecimal agent2ndRatio, + Integer refCanSeparateAmt); + } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/impl/LakalaApiServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/impl/LakalaApiServiceImpl.java index 311cb06c..2f17c316 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/impl/LakalaApiServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/lakala/service/impl/LakalaApiServiceImpl.java @@ -3612,4 +3612,111 @@ public class LakalaApiServiceImpl implements LakalaApiService { } } + + /** + * 商户分账参数计算及评估 + * + * @param splitMode 分账模式:1-总金额为基准分账,2-可分账金额基准分账,必填参数 + * @param orderPayAmount 订单支付总金额(单位:分)必填参数 + * @param shippingFeeInner 平台内部配送费(单位:分)必填参数 + * @param mchSplitRatioRaw 商户分账比例值(分子值,如10表示10%)必填参数 + * @param platSplitRatio 平台分账比例(百分比值,如0.01表示1%)可选参数 + * @param agent1stRatio 一级分账比例(百分比值,如0.01表示1%)可选参数 + * @param agent2ndRatio 二级分账比例(百分比值,如0.01表示1%)可选参数 + * @param refCanSeparateAmt 参考可分金额(单位:分) 可选参数 + * @return Pair 分账参数评估结果,第一个元素表示是否成功,第二个元素为分账参数对象 + */ + @Override + public Pair calculateAndEvaluateSharingParams(int splitMode, + Integer orderPayAmount, + Integer shippingFeeInner, + BigDecimal mchSplitRatioRaw, + BigDecimal platSplitRatio, + BigDecimal agent1stRatio, + BigDecimal agent2ndRatio, + Integer refCanSeparateAmt) { + log.debug("[分账参数计算] 开始计算分账参数: splitMode={}, orderPayAmount={}, shippingFeeInner={}, " + + "mchSplitRatioRaw={}, platSplitRatio={}, agent1stRatio={}, agent2ndRatio={}, refCanSeparateAmt={}", + splitMode, orderPayAmount, shippingFeeInner, mchSplitRatioRaw, platSplitRatio, + agent1stRatio, agent2ndRatio, refCanSeparateAmt); + + // 参数校验 + if (orderPayAmount == null || orderPayAmount <= 0) { + log.warn("[分账参数计算] 订单支付金额参数无效: orderPayAmount={}", orderPayAmount); + return Pair.of(false, null); + } + + if (mchSplitRatioRaw == null || mchSplitRatioRaw.compareTo(BigDecimal.ZERO) <= 0 || mchSplitRatioRaw.compareTo(BigDecimal.valueOf(100)) > 0) { + log.warn("[分账参数计算] 商户分账比例参数无效: mchSplitRatioRaw={}", mchSplitRatioRaw); + return Pair.of(false, null); + } + + if (splitMode != 1 && splitMode != 2) { + log.warn("[分账参数计算] 分账模式参数错误: splitMode={}", splitMode); + return Pair.of(false, null); + } + + // 计算商家分账比例(转换为小数) + BigDecimal mchSplitRatio = mchSplitRatioRaw.divide(new BigDecimal(100)); + log.debug("[分账参数计算] 商家分账比例转换: {} -> {}", mchSplitRatioRaw, mchSplitRatio); + + // 平台分账比例处理 + BigDecimal platformSplitRatio = platSplitRatio; + if (platformSplitRatio == null || platformSplitRatio.compareTo(BigDecimal.ZERO) <= 0) { + platformSplitRatio = BigDecimal.valueOf(0.01); // 默认平台分账1% + log.debug("[分账参数计算] 使用默认平台分账比例: {}", platformSplitRatio); + } + + // 内部配送费处理 + Integer actualShippingFeeInner = CheckUtil.isEmpty(shippingFeeInner) ? 0 : shippingFeeInner; + BigDecimal wxFeeRatio = StrUtil.isEmpty(wxFee) ? BigDecimal.valueOf(0.0025) : new BigDecimal(wxFee).divide(BigDecimal.valueOf(100)); + log.debug("[分账参数计算] 配送费: {}, 拉卡拉费率: {}", actualShippingFeeInner, wxFeeRatio); + + // 构建分账参数对象 + LklSeparateDTO lklSeparateDTO = new LklSeparateDTO(); + lklSeparateDTO.setTotalSeparateAmount(orderPayAmount); + lklSeparateDTO.setShippingFee(actualShippingFeeInner); + lklSeparateDTO.setLklRatio(wxFeeRatio); // 拉卡拉给的微信分账比例 0.0025 千分之2.5 + lklSeparateDTO.setMchRatio(mchSplitRatio); + lklSeparateDTO.setPlatRatio(platformSplitRatio); + + // 设置代理商分账比例 + if (agent1stRatio != null && agent1stRatio.compareTo(BigDecimal.ZERO) > 0) { + lklSeparateDTO.setAgent1stRatio(agent1stRatio); + log.debug("[分账参数计算] 设置一级代理商分账比例: {}", agent1stRatio); + } + + if (agent2ndRatio != null && agent2ndRatio.compareTo(BigDecimal.ZERO) > 0) { + lklSeparateDTO.setAgent2ndRatio(agent2ndRatio); + log.debug("[分账参数计算] 设置二级代理商分账比例: {}", agent2ndRatio); + } + + // 设置参考可分账金额 + if (refCanSeparateAmt != null && refCanSeparateAmt > 0) { + lklSeparateDTO.setRefCanSeparateAmount(refCanSeparateAmt); + log.debug("[分账参数计算] 设置参考可分账金额: {}", refCanSeparateAmt); + } + + // 根据分账模式执行不同的分账计算 + LklSeparateDTO.SharingResult canSeparateAmtResult; + if (splitMode == 1) { + // 总金额为基准分账 + log.debug("[分账参数计算] 使用总金额为基准分账模式"); + canSeparateAmtResult = lklSeparateDTO.sharingOnTotalAmount(); + } else { + // 可分金额基准分账 + log.debug("[分账参数计算] 使用可分账金额基准分账模式"); + canSeparateAmtResult = lklSeparateDTO.sharingOnCanSeparateAmount(); + } + + if (!canSeparateAmtResult.isSuccess()) { + log.warn("[分账参数计算] 分账参数评估失败: {}", canSeparateAmtResult.getErrorMessage()); + return Pair.of(false, lklSeparateDTO); + } + + log.info("[分账参数计算] 分账参数计算评估成功, result={}", lklSeparateDTO); + return Pair.of(true, lklSeparateDTO); + } + + } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/message/service/impl/ShopMessageTemplateServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/message/service/impl/ShopMessageTemplateServiceImpl.java index 5ee629a2..fff857fb 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/message/service/impl/ShopMessageTemplateServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/message/service/impl/ShopMessageTemplateServiceImpl.java @@ -80,6 +80,8 @@ import static com.suisung.mall.common.utils.I18nUtil._; @Slf4j public class ShopMessageTemplateServiceImpl extends BaseServiceImpl implements ShopMessageTemplateService { + // 批处理阈值 + private static final int BATCH_SIZE = 30; @Autowired ShopStoreBaseService shopStoreBaseService; @Autowired @@ -90,19 +92,13 @@ public class ShopMessageTemplateServiceImpl extends BaseServiceImpl mobiles, String tmplCode, Map tmplParams) { + // 过滤重复手机号,避免重复发送短信 + List uniqueMobiles = mobiles.stream() + .filter(StrUtil::isNotBlank) + .distinct() + .collect(Collectors.toList()); + int successCnt = 0; - for (String mobile : mobiles) { + for (String mobile : uniqueMobiles) { if (aliyunSmsSend(mobile, tmplCode, tmplParams)) { successCnt++; } @@ -676,22 +678,23 @@ public class ShopMessageTemplateServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); queryWrapper.eq("tplmsg_id", 1022);//todo 后期改为动态 ShopWechatTplmsg wechatTplmsg = shopWechatTplmsgService.getOne(queryWrapper); - ShopStoreBase shopStoreBase= shopStoreBaseService.get(wechatTplmsg.getStore_id()); + ShopStoreBase shopStoreBase = shopStoreBaseService.get(wechatTplmsg.getStore_id()); args.put("storeName", shopStoreBase.getStore_name()); if (wechatTplmsg != null) { - Map timeArgs=getActiveTime(); + Map timeArgs = getActiveTime(); args.putAll(timeArgs); String wechatTplData = getXcxWechatTplData(open_id, wechatTplmsg, args); log.info(wechatTplData); @@ -720,10 +723,10 @@ public class ShopMessageTemplateServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); queryWrapper.eq("tplmsg_id", 1022);//todo 后期改为动态 ShopWechatTplmsg wechatTplmsg = shopWechatTplmsgService.getOne(queryWrapper); - ShopStoreBase shopStoreBase= shopStoreBaseService.get(wechatTplmsg.getStore_id()); - Map args=new HashMap(); + ShopStoreBase shopStoreBase = shopStoreBaseService.get(wechatTplmsg.getStore_id()); + Map args = new HashMap(); String[] activeProfiles = environment.getActiveProfiles(); String activeProfile = activeProfiles[0]; args.put("storeName", shopStoreBase.getStore_name()); - args.put("evn",activeProfile); - Map timeArgs=getActiveTime(); + args.put("evn", activeProfile); + Map timeArgs = getActiveTime(); args.putAll(timeArgs); - int total= (int) allBindCount; - Integer pages= CommonUtil.getPagesCount(total,BATCH_SIZE); + int total = (int) allBindCount; + Integer pages = CommonUtil.getPagesCount(total, BATCH_SIZE); ExecutorService executor = Executors.newFixedThreadPool(6); List> futures = new ArrayList<>(); - for (int i=1;i<=pages;i++){ - List finalList=accountService.getAllBindPage(CommonConstant.BIND_SUB_TMPL_SKILL,i,BATCH_SIZE); + for (int i = 1; i <= pages; i++) { + List finalList = accountService.getAllBindPage(CommonConstant.BIND_SUB_TMPL_SKILL, i, BATCH_SIZE); int finalI = i; futures.add(executor.submit(() -> { finalList.forEach(accountUserBindConnect -> { - String open_id=accountUserBindConnect.getBind_openid(); - if(StrUtil.isNotEmpty(open_id)){ + String open_id = accountUserBindConnect.getBind_openid(); + if (StrUtil.isNotEmpty(open_id)) { String wechatTplData = getXcxWechatTplData(open_id, wechatTplmsg, args); String result = WxHttpUtil.request(WxHttpUtil.MethodType.POST, WxHttpUtil.WxType.XCX, accessToken, url, null, wechatTplData); JSONObject resultJson = JSONUtil.parseObj(result); @@ -775,7 +778,7 @@ public class ShopMessageTemplateServiceImpl extends BaseServiceImpl { @@ -113,4 +114,22 @@ public interface ShopOrderLklService extends IBaseService { * @return */ Boolean safeUpdate(ShopOrderLkl record); + + /** + * 获取平台内部订单配送费 + * + * @param storeId 店铺Id + * @param orderId 订单编号 + * @return + */ + Integer getOrderShippingFeeInner(Integer storeId, String orderId); + + /** + * 获取平台内部订单配送费 + * + * @param storeId 店铺Id + * @param orderId 订单编号 + * @return + */ + BigDecimal getOrderShippingFeeInnerToDecimal(Integer storeId, String orderId); } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderBaseServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderBaseServiceImpl.java index 47dc8acf..d77a68ae 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderBaseServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderBaseServiceImpl.java @@ -56,6 +56,7 @@ import com.suisung.mall.common.modules.product.ShopProductItem; import com.suisung.mall.common.modules.product.ShopProductValidPeriod; import com.suisung.mall.common.modules.store.*; import com.suisung.mall.common.modules.user.*; +import com.suisung.mall.common.pojo.dto.LklSeparateDTO; import com.suisung.mall.common.pojo.dto.StandardAddressDTO; import com.suisung.mall.common.pojo.dto.WxOrderBaseInfoDTO; import com.suisung.mall.common.pojo.req.*; @@ -3228,6 +3229,8 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl tmplArgs = new HashMap<>(2); - // tmplArgs.put("order_id", order_id); - // tmplArgs.put("order_payment_amount", order_payment_amount); - // 所有店铺管理员的发送邮件, 提醒商家:您有一笔新的订单 ${order_id},请及时处理。 - // shopMessageTemplateService.aliyunSmsSend(shopKeeperMobiles, "SMS_476810378", tmplArgs); + Map tmplArgs = new HashMap<>(2); + tmplArgs.put("order_id", order_id); + tmplArgs.put("order_payment_amount", order_payment_amount); +// 所有店铺管理员的发送邮件, 提醒商家:您有一笔新的订单 ${order_id},请及时处理。 + shopMessageTemplateService.aliyunSmsSend(shopKeeperMobiles, "SMS_476810378", tmplArgs); } // 付款成功,对通知推广员进行提醒 @@ -6554,6 +6557,8 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl calcResult = lakalaApiService.calculateAndEvaluateSharingParams( + CommonConstant.SeparateCalcMode_CanSeparateAmt, + Convert.toInt(order_payment_amount.multiply(BigDecimal.valueOf(100))), + innerMinDeliverFee, + storeSplitRatio, + BigDecimal.valueOf(0.01), + null, null, null); // 计算平台费 - BigDecimal platform_fee = calculatePlatformAndAgentShareAmount(Convert.toInt(base_row.get("store_id")), split_amount_from); - data_row.setTotal_separate_value(platform_fee); // 从拉卡拉分账,给平台和代理商的总计分账金额 - data_row.setPlatform_fee(platform_fee); + if (calcResult != null && calcResult.getFirst() && calcResult.getSecond() != null) { + try { + LklSeparateDTO lklSeparateDTO = calcResult.getSecond(); + // 确保分账金额不为负数 + BigDecimal totalSeparateAmount = BigDecimal.valueOf(lklSeparateDTO.getCanSeparateAmount()) + .divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP); + BigDecimal platformFee = BigDecimal.valueOf(lklSeparateDTO.getPlatAmount() + lklSeparateDTO.getAgent1stAmount() + lklSeparateDTO.getAgent2ndAmount()) + .divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP); + // 防止负值 + data_row.setTotal_separate_value(totalSeparateAmount.max(BigDecimal.ZERO)); + data_row.setPlatform_fee(platformFee.max(BigDecimal.ZERO)); + } catch (Exception e) { + log.warn("分账金额计算异常,使用默认值: {}", e.getMessage()); + data_row.setTotal_separate_value(BigDecimal.ZERO); + data_row.setPlatform_fee(BigDecimal.ZERO); + } + } else { + log.warn("拉卡拉分账参数计算失败,使用默认值"); + data_row.setTotal_separate_value(BigDecimal.ZERO); + data_row.setPlatform_fee(BigDecimal.ZERO); + } Integer voucher_id = (Integer) order_voucher_row.get("voucher_id"); String voucher_code = (String) order_voucher_row.get("voucher_code"); diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderLklServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderLklServiceImpl.java index 5dc261b8..14ebbf37 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderLklServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderLklServiceImpl.java @@ -33,8 +33,10 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; +import java.math.RoundingMode; import java.time.LocalDateTime; import java.util.List; +import java.util.Optional; @Slf4j @Service @@ -596,4 +598,64 @@ public class ShopOrderLklServiceImpl extends BaseServiceImpl queryWrapper = new QueryWrapper<>(); + queryWrapper.select("shopping_fee_inner"); + queryWrapper.eq("store_id", storeId); + queryWrapper.eq("order_id", orderId); + + ShopOrderLkl shopOrderLkl = findOne(queryWrapper); + Integer fee = Optional.ofNullable(shopOrderLkl) + .map(ShopOrderLkl::getShopping_fee_inner) + .orElse(0); + + log.debug("[获取平台内部订单运费] 查询成功, storeId={}, orderId={}, fee={}", storeId, orderId, fee); + return fee; + } catch (Exception e) { + log.error("[获取平台内部订单运费] 系统异常, storeId={}, orderId={}", storeId, orderId, e); + return 0; + } + } + + @Override + public BigDecimal getOrderShippingFeeInnerToDecimal(Integer storeId, String orderId) { + // 参数校验 + if (storeId == null || StringUtils.isBlank(orderId)) { + log.warn("[获取平台内部订单运费(Decimal)] 参数校验失败:storeId或orderId为空, storeId={}, orderId={}", storeId, orderId); + return BigDecimal.ZERO; + } + + try { + // 调用已有的方法获取运费(单位:分) + Integer feeInCents = getOrderShippingFeeInner(storeId, orderId); + + // 转换为元为单位的BigDecimal + BigDecimal feeInYuan = new BigDecimal(feeInCents).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP); + + log.debug("[获取平台内部订单运费(Decimal)] 查询成功, storeId={}, orderId={}, feeInCents={}, feeInYuan={}", + storeId, orderId, feeInCents, feeInYuan); + return feeInYuan; + } catch (Exception e) { + log.error("[获取平台内部订单运费(Decimal)] 系统异常, storeId={}, orderId={}", storeId, orderId, e); + return BigDecimal.ZERO; + } + } + + } diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderReturnServiceImpl.java b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderReturnServiceImpl.java index ec7b624f..eae5a6b9 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderReturnServiceImpl.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/order/service/impl/ShopOrderReturnServiceImpl.java @@ -196,6 +196,10 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl 0) { // 退款金额+打包费 - BigDecimal order_refund_amount_add_fee = NumberUtil.add( + BigDecimal orderRefundAmountAddFee = NumberUtil.add( order_data_row.getOrder_refund_amount(), order_data_row.getPacking_fee()); // 最后一个退款订单如果有打包费,加上打包费 - return_row.setReturn_refund_amount(order_refund_amount_add_fee); + return_row.setReturn_refund_amount(orderRefundAmountAddFee); logger.debug("已添加打包费到退款金额,订单ID: {}", order_id); } - // 有运费的订单 + + // 有运费的,重新生成一个运费退单 if (order_data_row != null && - order_data_row.getOrder_shipping_fee() != null && - order_data_row.getOrder_shipping_fee().compareTo(BigDecimal.ZERO) > 0) { + order_data_row.getOrder_shipping_fee_inner() != null && + order_data_row.getOrder_shipping_fee_inner().compareTo(BigDecimal.ZERO) > 0) { // 运费大于0的, 执行退运费操作, 有两种方案,1、生成退运费售后服务单; 2、直接执行退款 // 1、生成独立退运费售后服务单,需注意运费是退给运费代理商的,需要获取代理商的交易单号 @@ -1630,8 +1635,15 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl orderItems = shopOrderItemService.find(new QueryWrapper().eq("order_id", orderId)); if (CollectionUtil.isEmpty(orderItems)) return CommonResult.failed("无可退货商品"); - + // === 3. 检查退货单 === ShopOrderReturn refundOrder = findOne(new QueryWrapper() .eq("order_id", orderId) @@ -2616,7 +2620,6 @@ public class ShopOrderReturnServiceImpl extends BaseServiceImpl + @@ -780,11 +781,12 @@ AS is_new_buyer, oi.payment_time, od.order_shipping_fee, + IFNULL(od.order_shipping_fee_inner, 0) as order_shipping_fee_inner, (od.order_discount_amount + od.voucher_price + od.order_points_fee + od.order_adjust_fee) as total_discount_amount, - (ob.order_product_amount-od.order_discount_amount-od.voucher_price-od.order_points_fee-od.order_adjust_fee-od.platform_fee-od.order_shipping_fee+od.packing_fee) + (ob.order_product_amount-od.order_discount_amount-od.voucher_price-od.order_points_fee-od.order_adjust_fee-od.platform_fee-order_shipping_fee_inner+od.packing_fee) as order_income_amount, od.platform_fee, od.packing_fee, diff --git a/mall-shop/src/main/resources/mapper/order/ShopOrderDataMapper.xml b/mall-shop/src/main/resources/mapper/order/ShopOrderDataMapper.xml index e46db78d..4a522494 100644 --- a/mall-shop/src/main/resources/mapper/order/ShopOrderDataMapper.xml +++ b/mall-shop/src/main/resources/mapper/order/ShopOrderDataMapper.xml @@ -7,7 +7,7 @@ , order_desc, order_delay_time, delivery_type_id, delivery_time_id, delivery_time, delivery_time_rang, delivery_time_h, delivery_time_i, delivery_istimer, invoice_type_id, invoice_company_code, order_invoice_title, order_message, order_item_amount, order_discount_amount, order_adjust_fee, order_points_fee, - order_shipping_fee_amount, order_shipping_fee, platform_fee, packing_fee, voucher_id, voucher_number, voucher_price, redpacket_id, + order_shipping_fee_amount, order_shipping_fee,order_shipping_fee_inner, platform_fee, packing_fee, voucher_id, voucher_number, voucher_price, redpacket_id, redpacket_number, redpacket_price, order_redpacket_price, order_resource_ext1, order_resource_ext2, order_resource_ext3, trade_payment_money, trade_payment_recharge_card, trade_payment_credit, order_refund_status, order_refund_amount, order_refund_agree_amount, order_return_status, order_return_num,