积分
This commit is contained in:
@@ -3,6 +3,8 @@ package com.czg.service.order.service;
|
||||
import com.czg.entity.resp.CzgBaseResp;
|
||||
import com.czg.entity.resp.CzgRefundResp;
|
||||
import com.czg.order.dto.OrderInfoRefundDTO;
|
||||
import com.czg.order.dto.PointGoodsExchangeDTO;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.order.dto.*;
|
||||
import lombok.NonNull;
|
||||
@@ -17,6 +19,8 @@ import java.util.Map;
|
||||
* @author ww
|
||||
*/
|
||||
public interface PayService {
|
||||
//-----------------------------------------------------------------订单支付--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 挂账
|
||||
*/
|
||||
@@ -28,15 +32,10 @@ public interface PayService {
|
||||
CzgResult<Object> cashPayOrder(OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 会员支付
|
||||
* 余额支付
|
||||
*/
|
||||
CzgResult<Object> vipPayOrder(OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 充值并付款
|
||||
*/
|
||||
CzgResult<Map<String, Object>> rechargePayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* h5支付
|
||||
*/
|
||||
@@ -47,6 +46,9 @@ public interface PayService {
|
||||
*/
|
||||
CzgResult<Map<String, Object>> jsPayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 空订单支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> js2PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
@@ -63,7 +65,13 @@ public interface PayService {
|
||||
* 聚合反扫
|
||||
*/
|
||||
CzgResult<Map<String, Object>> microPayOrder(OrderPayParamDTO payParam);
|
||||
//-----------------------------------------------------------------订单+会员 一起支付-----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 充值并付款
|
||||
*/
|
||||
CzgResult<Map<String, Object>> rechargePayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
//-----------------------------------------------------------------会员支付--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 现金充值
|
||||
@@ -89,6 +97,18 @@ public interface PayService {
|
||||
* 聚合反扫
|
||||
*/
|
||||
CzgResult<Map<String, Object>> microPayVip(VipPayParamDTO payParam);
|
||||
//-----------------------------------------------------------------会员开通购买 ----------------------------------------------------------
|
||||
|
||||
CzgResult<Map<String, Object>> ltPayMember(String clientIP, VipMemberPayParamDTO payParam);
|
||||
|
||||
CzgResult<Map<String, Object>> recharge(String clientIP, VipPayParamDTO rechargeDTO, Long userId);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------积分商品 付款 ----------------------------------------------------------
|
||||
|
||||
CzgResult<Map<String, Object>> ltPayPointsGoods(String ip, PointGoodsExchangeDTO param, Long recordId);
|
||||
|
||||
//-----------------------------------------------------------------退款-----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 退款前校验
|
||||
@@ -107,6 +127,21 @@ public interface PayService {
|
||||
*/
|
||||
void refundOrder(Long shopId, Long orderId, Long payOrderId, String refPayOrderNo, String refundReason, BigDecimal refundAmount);
|
||||
|
||||
/**
|
||||
* 统一退款接口
|
||||
*
|
||||
* @param refPayOrderNo 自定义退单号
|
||||
*/
|
||||
void unifyRefund(Long shopId, Long sourceId, Long payOrderId, String refPayOrderNo, String refundReason, BigDecimal refundAmount);
|
||||
|
||||
/**
|
||||
* 退款补偿使用
|
||||
*/
|
||||
void unifyRefund(OrderPayment payment, String refPayOrderNo);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------支付查询 ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 支付查询
|
||||
*
|
||||
@@ -122,8 +157,4 @@ public interface PayService {
|
||||
* @param refundOrderId 平台退款订单号 二选一
|
||||
*/
|
||||
CzgResult<CzgRefundResp> queryRefund(Long shopId, String mchRefundNo, String refundOrderId);
|
||||
|
||||
CzgResult<Map<String, Object>> ltPayMember(String clientIP, VipMemberPayParamDTO payParam);
|
||||
|
||||
CzgResult<Map<String, Object>> recharge(String clientIP, VipPayParamDTO rechargeDTO, Long userId);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import java.util.Map;
|
||||
public class DistributionPayServiceImpl implements DistributionPayService {
|
||||
private final BigDecimal MONEY_RATE = new BigDecimal("100");
|
||||
|
||||
@DubboReference
|
||||
@Resource
|
||||
private OrderPaymentService orderPaymentService;
|
||||
@Resource
|
||||
private MkDistributionConfigService configService;
|
||||
|
||||
@@ -25,8 +25,10 @@ import com.czg.exception.OrderCancelException;
|
||||
import com.czg.exception.OrderValidateException;
|
||||
import com.czg.market.dto.MkDiscountActivityDTO;
|
||||
import com.czg.market.entity.MkDiscountThreshold;
|
||||
import com.czg.market.entity.MkPointsConfig;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.enums.PointsConstant;
|
||||
import com.czg.market.service.*;
|
||||
import com.czg.order.dto.*;
|
||||
import com.czg.order.entity.CashierCart;
|
||||
@@ -34,10 +36,7 @@ import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.enums.PayEnums;
|
||||
import com.czg.order.service.CashierCartService;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
import com.czg.order.service.OrderInfoCustomService;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.order.service.*;
|
||||
import com.czg.order.vo.*;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.service.ProductRpcService;
|
||||
@@ -104,8 +103,6 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
@Resource
|
||||
private MkDistributionUserService distributionUserService;
|
||||
@DubboReference
|
||||
private MemberPointsService pointsService;
|
||||
@DubboReference
|
||||
private ProductService productService;
|
||||
@DubboReference
|
||||
private ProductRpcService productRpcService;
|
||||
@@ -119,11 +116,15 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
private ShopUserFlowService flowService;
|
||||
@DubboReference
|
||||
private ShopTableService shopTableService;
|
||||
@DubboReference
|
||||
private PointsBasicSettingService pointsBasicService;
|
||||
@Resource
|
||||
private MkShopConsumerCouponService consumerCouponService;
|
||||
@Resource
|
||||
private MkPointsUserService pointsUserService;
|
||||
@Resource
|
||||
private MkPointsConfigService pointsConfigService;
|
||||
@Resource
|
||||
private PointsGoodPayService goodPayService;
|
||||
@Resource
|
||||
private ShopCouponService couponService;
|
||||
@Resource
|
||||
private MkShopCouponRecordService couponRecordService;
|
||||
@@ -132,8 +133,6 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
@Resource
|
||||
private MkShopConsumeDiscountRecordService newConsumerDiscountRecordService;
|
||||
@Resource
|
||||
private MemberOrderService memberOrderService;
|
||||
@Resource
|
||||
private MkDiscountActivityService discountActService;
|
||||
@Resource
|
||||
private MkShopRechargeService shopRechargeService;
|
||||
@@ -376,11 +375,10 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
param.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0);
|
||||
}
|
||||
// 积分校验
|
||||
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
|
||||
PointsBasicSetting pointSetting = pointsBasicService.getById(mainShopId);
|
||||
MkPointsConfig pointSetting = pointsConfigService.getOne(QueryWrapper.create().eq(MkPointsConfig::getShopId, shopId));
|
||||
boolean usePointsDeduction = param.getPointsNum() > 0 || param.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0;
|
||||
if (usePointsDeduction) {
|
||||
if (pointSetting == null || !pointSetting.getEnableDeduction().equals(1)) {
|
||||
if (pointSetting == null || !pointSetting.getEnableRewards().equals(1)) {
|
||||
throw new OrderValidateException("生成支付订单失败,该店铺未开启积分抵扣");
|
||||
}
|
||||
if (param.getUserId() == null) {
|
||||
@@ -396,24 +394,11 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
}
|
||||
}
|
||||
|
||||
if (param.getPointsNum() > 0 && (!param.isFreeDine() || param.isWithPoints())) {
|
||||
if (pointSetting == null || !pointSetting.getEnableDeduction().equals(1)) {
|
||||
throw new OrderValidateException("生成支付订单失败,该店铺未开启积分抵扣");
|
||||
}
|
||||
if (param.getUserId() == null) {
|
||||
throw new OrderValidateException("生成支付订单失败,请选择用户后再使用积分抵扣");
|
||||
}
|
||||
} else if (param.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
throw new OrderValidateException("生成支付订单失败,已使用积分抵扣,积分数量不正确");
|
||||
}
|
||||
ShopUser shopUser = null;
|
||||
if (param.getUserId() != null) {
|
||||
UserInfo userInfo = userInfoService.getById(param.getUserId());
|
||||
AssertUtil.isNull(userInfo, "生成支付订单失败,用户信息不存在");
|
||||
shopUser = shopUserService.getShopUserInfo(shopId, param.getUserId());
|
||||
if (param.getPointsNum() > 0 && !shopUser.getIsVip().equals(1) && pointSetting.getDeductionGroup().contains("vip")) {
|
||||
throw new OrderValidateException("生成支付订单失败,该店铺仅会员可使用积分抵扣");
|
||||
}
|
||||
orderInfo.setUserId(userInfo.getId());
|
||||
}
|
||||
//会员价校验
|
||||
@@ -1075,7 +1060,8 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
distributionUserService.costUpgradeLevelBefore(orderInfo.getUserId(), orderInfo.getShopId());
|
||||
// 分销奖励
|
||||
distributionUserService.distribute(orderInfo.getId(), orderInfo.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order");
|
||||
} else if ("memberIn".equals(payment.getPayType()) || "free".equals(payment.getPayType())) {
|
||||
}
|
||||
else if ("memberIn".equals(payment.getPayType()) || "free".equals(payment.getPayType())) {
|
||||
boolean isFree = "free".equals(payment.getPayType());
|
||||
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
|
||||
OrderInfo orderInfo = null;
|
||||
@@ -1175,7 +1161,8 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
// if (orderInfo != null) {
|
||||
// distributionUserService.distribute(payment.getId(), payment.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), payment.getShopId(), "recharge");
|
||||
// }
|
||||
} else if ("memberPay".equals(payment.getPayType())) {
|
||||
}
|
||||
else if ("memberPay".equals(payment.getPayType())) {
|
||||
//购买会员
|
||||
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
|
||||
memberConfigService.joinMember(payment.getShopId(), shopUser.getUserId(), payment.getRelatedId());
|
||||
@@ -1183,8 +1170,11 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
// memberConfigService.deliver(shopUser.getMainShopId(), shopUser.getUserId(), TableValueConstant.MemberExpFlow.Type.COST, payment.getAmount(), null, payment.getId());
|
||||
|
||||
// 分销员开通
|
||||
} else if ("distribution".equals(payment.getPayType())) {
|
||||
}
|
||||
else if ("distribution".equals(payment.getPayType())) {
|
||||
distributionUserService.open(payment.getSourceId(), payment.getAmount(), payment.getShopId(), payment.getId());
|
||||
}else if("point".equals(payment.getPayType())){
|
||||
goodPayService.payCallBack(payment.getSourceId());
|
||||
}
|
||||
}
|
||||
paymentService.updateById(payment);
|
||||
@@ -1274,7 +1264,9 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
}
|
||||
//积分使用
|
||||
if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() > 0) {
|
||||
pointsService.deductPoints(shopUser.getId(), orderInfo.getPointsNum(), "积分抵扣账单", orderInfo);
|
||||
pointsUserService.alterPoints(null, shopUser.getId(), orderInfo.getShopId(), PointsConstant.SUB,
|
||||
orderInfo.getPointsNum(), orderInfo.getId().toString(), "积分抵扣账单");
|
||||
|
||||
}
|
||||
//更新优惠券信息
|
||||
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList()) && !"null".equals(orderInfo.getCouponInfoList())) {
|
||||
@@ -1296,7 +1288,10 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
if ((orderInfo.getPayType() != null && !ArrayUtil.contains(payTypes, orderInfo.getPayType()))
|
||||
|| (payType != null && !ArrayUtil.contains(payTypes, payType))) {
|
||||
//下单赠送积分
|
||||
pointsService.consumeAwardPoints(shopUser.getId(), orderInfo);
|
||||
pointsConfigService.consumeAwardPoints(shopUser.getId(), orderInfo);
|
||||
// pointsUserService.alterPoints(null, shopUser.getId(), orderInfo.getShopId(), PointsConstant.ADD,
|
||||
// rechargeDetail.getRewardPoints(), orderInfo.getId(), "下单赠送积分");
|
||||
|
||||
//消费返现
|
||||
if (!orderInfo.getPayType().equals(PayEnums.CASH_PAY.getValue())) {
|
||||
consumeCashbackService.cashback(orderInfo.getShopId(), shopUser.getUserId(), orderInfo.getPayAmount(), orderInfo.getId(), orderInfo.getOrderNo());
|
||||
@@ -1509,7 +1504,8 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
}
|
||||
//积分使用
|
||||
if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() > 0) {
|
||||
pointsService.deductPoints(shopUser.getId(), orderInfo.getPointsNum(), "积分抵扣账单", orderInfo);
|
||||
pointsUserService.alterPoints(null, shopUser.getId(), orderInfo.getShopId(), PointsConstant.ADD,
|
||||
orderInfo.getPointsNum(), orderInfo.getId().toString(), "积分抵扣账单");
|
||||
}
|
||||
//更新优惠券信息
|
||||
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList()) && !"null".equals(orderInfo.getCouponInfoList())) {
|
||||
|
||||
@@ -25,13 +25,13 @@ import com.czg.market.service.*;
|
||||
import com.czg.market.vo.MkShopRechargeVO;
|
||||
import com.czg.order.dto.CheckOrderPay;
|
||||
import com.czg.order.dto.OrderInfoRefundDTO;
|
||||
import com.czg.order.dto.PointGoodsExchangeDTO;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.enums.PayEnums;
|
||||
import com.czg.order.service.CreditBuyerOrderService;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
import com.czg.market.service.OrderInfoService;
|
||||
import com.czg.order.service.OrderInfoCustomService;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.resp.CzgRespCode;
|
||||
@@ -88,8 +88,6 @@ public class PayServiceImpl implements PayService {
|
||||
@Resource
|
||||
private MkShopCouponRecordService recordService;
|
||||
@DubboReference
|
||||
private MemberPointsService pointsService;
|
||||
@DubboReference
|
||||
private FreeDineConfigService freeConfigService;
|
||||
@Resource
|
||||
private CzgPayService czgPayService;
|
||||
@@ -227,7 +225,7 @@ public class PayServiceImpl implements PayService {
|
||||
boolean exists = shopInfoService.exists(QueryWrapper.create()
|
||||
.eq(ShopInfo::getMainId, shopInfo.getMainId())
|
||||
.eq(ShopInfo::getId, orderInfo.getShopId()));
|
||||
if(!exists){
|
||||
if (!exists) {
|
||||
return CzgResult.failure("违规操作,请确认店铺后重试");
|
||||
}
|
||||
}
|
||||
@@ -253,7 +251,6 @@ public class PayServiceImpl implements PayService {
|
||||
LocalDateTime.now(), flowId, PayEnums.VIP_PAY);
|
||||
|
||||
|
||||
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@@ -437,16 +434,6 @@ public class PayServiceImpl implements PayService {
|
||||
shopUserService.updateById(updateInfo);
|
||||
}
|
||||
shopRechargeService.recharge(shopUser.getMainShopId(), shopUser.getId(), payParam.getRechargeDetailId(), payParam.getAmount(), null, "cash", ShopUserFlowBizEnum.CASH_IN);
|
||||
// ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
|
||||
// .setId(shopUser.getId())
|
||||
// .setMoney(payParam.getAmount())
|
||||
// .setType(1)
|
||||
// .setRemark("现金充值")
|
||||
// .setBizEnum(ShopUserFlowBizEnum.CASH_IN);
|
||||
// //更新会员余额 并生成流水
|
||||
// Long flowId = shopUserService.updateMoney(shopUserMoneyEditDTO);
|
||||
//TODO 以前的会员活动
|
||||
//shopActivateService.giveActivate(shopUser, payParam.getAmount(), payParam.getActivateId(), flowId);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@@ -531,7 +518,8 @@ public class PayServiceImpl implements PayService {
|
||||
initOrderPayment(new OrderPayment(rechargeDTO.getShopId(), shopUser.getId(), isFree ? "free" : "memberIn", payOrderNo,
|
||||
"", amount, isFree ? rechargeDTO.getOrderId() : rechargeDTO.getRechargeDetailId()));
|
||||
return ltPay(rechargeDTO.getShopId(), rechargeDTO.getPayType(), new CzgLtPayReq(payOrderNo, amount.multiply(MONEY_RATE).longValue(),
|
||||
rechargeDTO.getPayType(), "会员充值", "wechatPay".equals(rechargeDTO.getPayType()) ? userInfo.getWechatOpenId() : userInfo.getAlipayOpenId(), clientIP, rechargeDTO.getReturnUrl(), rechargeDTO.getBuyerRemark(), ""));
|
||||
rechargeDTO.getPayType(), "会员充值", "wechatPay".equals(rechargeDTO.getPayType()) ? userInfo.getWechatOpenId() : userInfo.getAlipayOpenId(),
|
||||
clientIP, rechargeDTO.getReturnUrl(), rechargeDTO.getBuyerRemark(), ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -563,6 +551,19 @@ public class PayServiceImpl implements PayService {
|
||||
return mapCzgResult;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Map<String, Object>> ltPayPointsGoods(String ip, PointGoodsExchangeDTO param, Long mkPointsGoodsRecordId) {
|
||||
AssertUtil.isBlank(param.getOpenId(), "用户小程序ID不能为空");
|
||||
AssertUtil.isBlank(param.getPayType(), "支付方式不能为空");
|
||||
String payOrderNo = "DH" + IdUtil.getSnowflakeNextId();
|
||||
initOrderPayment(new OrderPayment(param.getShopId(), mkPointsGoodsRecordId, "point", payOrderNo,
|
||||
"", param.getPrice(), null));
|
||||
return ltPay(param.getShopId(), param.getPayType(), new CzgLtPayReq(payOrderNo, param.getPrice().multiply(MONEY_RATE).longValue(),
|
||||
param.getPayType(), "积分商品购买", param.getOpenId(), ip, "", "", ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgResult<Map<String, BigDecimal>> refundVipBefore(VipRefundDTO payParam) {
|
||||
Map<String, BigDecimal> resultMap = new HashMap<>(5);
|
||||
@@ -645,7 +646,7 @@ public class PayServiceImpl implements PayService {
|
||||
.setMoney(refPayParam.getRefAmount())
|
||||
.setType(0)
|
||||
.setRemark("退款")
|
||||
.setBizEnum(refPayParam.isCashRefund() ? ShopUserFlowBizEnum.RECHARGE_CASH_REFUND : ShopUserFlowBizEnum.RECHARGE_REFUND )
|
||||
.setBizEnum(refPayParam.isCashRefund() ? ShopUserFlowBizEnum.RECHARGE_CASH_REFUND : ShopUserFlowBizEnum.RECHARGE_REFUND)
|
||||
.setRelationId(refPaymentId)
|
||||
.setRechargeId(inFlow.getId());
|
||||
//更新会员余额 并生成流水
|
||||
@@ -708,7 +709,7 @@ public class PayServiceImpl implements PayService {
|
||||
//可退数量=订单数量-退单数量-退菜数量
|
||||
BigDecimal returnNum = orderDetail.getNum().subtract(orderDetail.getRefundNum()).subtract(orderDetail.getReturnNum());
|
||||
if (returnNum.compareTo(BigDecimal.ZERO) <= 0 || returnNum.compareTo(refundDetail.getNum()) < 0) {
|
||||
throw new CzgException("退单失败," + orderDetail.getProductName() + "可退数量不足");
|
||||
throw new CzgException("退单失败," + orderDetail.getProductName() + "可退数量不足");
|
||||
}
|
||||
refundDetail.setReturnAmount(refundDetail.getNum().multiply(orderDetail.getUnitPrice()).setScale(2, RoundingMode.UP));
|
||||
if (isPay) {
|
||||
@@ -727,10 +728,10 @@ public class PayServiceImpl implements PayService {
|
||||
orderDetail.setRefundNo(refPayOrderNo);
|
||||
orderDetail.setRefundRemark(orderDetail.getRefundRemark() + param.getRefundReason());
|
||||
// if (isPay) {
|
||||
orderDetail.setReturnAmount(orderDetail.getReturnAmount().add(refundDetail.getReturnAmount()));
|
||||
if (orderDetail.getReturnAmount().compareTo(orderDetail.getPayAmount()) > 0) {
|
||||
orderDetail.setReturnAmount(orderDetail.getPayAmount());
|
||||
}
|
||||
orderDetail.setReturnAmount(orderDetail.getReturnAmount().add(refundDetail.getReturnAmount()));
|
||||
if (orderDetail.getReturnAmount().compareTo(orderDetail.getPayAmount()) > 0) {
|
||||
orderDetail.setReturnAmount(orderDetail.getPayAmount());
|
||||
}
|
||||
// }
|
||||
orderDetailService.updateById(orderDetail);
|
||||
if (orderDetail.getProductId() != null && orderDetail.getProductId() > 0) {
|
||||
@@ -820,7 +821,7 @@ public class PayServiceImpl implements PayService {
|
||||
@NonNull String refundReason, @NonNull BigDecimal refundAmount) {
|
||||
OrderPayment payment = paymentService.getById(payOrderId);
|
||||
AssertUtil.isNull(payment, "退款失败支付记录不存在");
|
||||
Long refundId = initOrderPayment(new OrderPayment(shopId, orderId, "refund", refPayOrderNo, null, refundAmount));
|
||||
Long refundId = initOrderPayment(new OrderPayment(shopId, orderId, "refund", refPayOrderNo, null, refundAmount, payment.getId()));
|
||||
CzgResult<CzgRefundResp> refund = refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(MONEY_RATE).longValue(),
|
||||
payment.getOrderNo(), ""));
|
||||
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getState())) {
|
||||
@@ -838,6 +839,59 @@ public class PayServiceImpl implements PayService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void unifyRefund(@NonNull Long shopId, @NonNull Long sourceId, @NonNull Long payOrderId, @NonNull String refPayOrderNo,
|
||||
@NonNull String refundReason, @NonNull BigDecimal refundAmount) {
|
||||
OrderPayment payment = paymentService.getById(payOrderId);
|
||||
AssertUtil.isNull(payment, "退款失败,支付记录不存在");
|
||||
Long refundId = initOrderPayment(new OrderPayment(shopId, sourceId, "refund", refPayOrderNo, null, refundAmount, payment.getId()));
|
||||
CzgResult<CzgRefundResp> refund = refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(MONEY_RATE).longValue(),
|
||||
payment.getOrderNo(), ""));
|
||||
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getState())) {
|
||||
paymentService.updateChain()
|
||||
.eq(OrderPayment::getId, refundId)
|
||||
.set(OrderPayment::getTradeNumber, refund.getData().getRefundOrderId())
|
||||
.set(OrderPayment::getRespJson, JSONObject.toJSONString(refund.getData()))
|
||||
.set(OrderPayment::getPayStatus, "fail")
|
||||
.update();
|
||||
} else {
|
||||
paymentService.updateChain()
|
||||
.eq(OrderPayment::getId, refundId)
|
||||
.set(OrderPayment::getPayTime, refund.getData().getRefundTime())
|
||||
.set(OrderPayment::getTradeNumber, refund.getData().getRefundOrderId())
|
||||
.set(OrderPayment::getRespJson, JSONObject.toJSONString(refund.getData()))
|
||||
.set(OrderPayment::getPayStatus, "success")
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void unifyRefund(OrderPayment refundPayment, String refPayOrderNo) {
|
||||
OrderPayment payment = paymentService.getById(refundPayment.getRelatedId());
|
||||
AssertUtil.isNull(payment, "退款失败,支付记录不存在");
|
||||
Long refundId = refundPayment.getId();
|
||||
CzgResult<CzgRefundResp> refund = refund(payment.getShopId(), new CzgRefundReq(refPayOrderNo, "退款补偿", refundPayment.getAmount().multiply(MONEY_RATE).longValue(),
|
||||
payment.getOrderNo(), ""));
|
||||
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getState())) {
|
||||
paymentService.updateChain()
|
||||
.eq(OrderPayment::getId, refundId)
|
||||
.set(OrderPayment::getTradeNumber, refund.getData().getRefundOrderId())
|
||||
.set(OrderPayment::getRespJson, JSONObject.toJSONString(refund.getData()))
|
||||
.set(OrderPayment::getPayStatus, "fail")
|
||||
.update();
|
||||
} else {
|
||||
paymentService.updateChain()
|
||||
.eq(OrderPayment::getId, refundId)
|
||||
.set(OrderPayment::getPayTime, refund.getData().getRefundTime())
|
||||
.set(OrderPayment::getTradeNumber, refund.getData().getRefundOrderId())
|
||||
.set(OrderPayment::getRespJson, JSONObject.toJSONString(refund.getData()))
|
||||
.set(OrderPayment::getPayStatus, "success")
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<CzgBaseResp> queryPayOrder(@NonNull Long shopId, String payOrderId, String mchOrderNo) {
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.market.dto.MkShopCouponGiftDTO;
|
||||
import com.czg.market.entity.MkPointsGoods;
|
||||
import com.czg.market.entity.MkPointsGoodsRecord;
|
||||
import com.czg.market.entity.MkPointsUser;
|
||||
import com.czg.market.enums.PointsConstant;
|
||||
import com.czg.market.service.MkPointsGoodsRecordService;
|
||||
import com.czg.market.service.MkPointsGoodsService;
|
||||
import com.czg.market.service.MkPointsUserService;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.order.dto.PointGoodsExchangeDTO;
|
||||
import com.czg.order.dto.PointGoodsRefundDTO;
|
||||
import com.czg.order.service.PointsGoodPayService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.order.service.PayService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PointsGoodPayServiceImpl implements PointsGoodPayService {
|
||||
@Resource
|
||||
private ShopUserService shopUserService;
|
||||
@Resource
|
||||
private MkPointsUserService pointsUserService;
|
||||
@Resource
|
||||
private MkPointsGoodsService goodsService;
|
||||
@Resource
|
||||
private MkPointsGoodsRecordService goodsRecordService;
|
||||
@Resource
|
||||
private MkShopCouponRecordService couponRecordService;
|
||||
@Resource
|
||||
@Lazy
|
||||
private PayService payService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Map<String, Object>> exchange(String ip, PointGoodsExchangeDTO param) {
|
||||
MkPointsGoods goods = goodsService.getById(param.getPointsGoodsId());
|
||||
if (goods == null) {
|
||||
throw new CzgException("兑换失败,商品不存在");
|
||||
}
|
||||
if (goods.getStatus() != 1) {
|
||||
throw new CzgException("兑换失败,商品已下架");
|
||||
}
|
||||
Integer boughtCount = goodsRecordService.getOneAs(QueryWrapper.create().select("sum(number)")
|
||||
.eq(MkPointsGoodsRecord::getPointsGoodsId, param.getPointsGoodsId())
|
||||
.ne(MkPointsGoodsRecord::getStatus, "已退款")
|
||||
.eq(MkPointsGoodsRecord::getUserId, param.getUserId()), Integer.class);
|
||||
if (goods.getLimitQuota() > 0 && boughtCount != null && boughtCount >= goods.getLimitQuota()) {
|
||||
throw new CzgException("兑换失败,该商品每人限制兑换" + goods.getLimitQuota() + "件");
|
||||
}
|
||||
MkPointsUser pointsUser = pointsUserService.getPointsUser(param.getShopId(), null, param.getUserId());
|
||||
if (pointsUser == null) {
|
||||
throw new CzgException("兑换失败,用户积分不足");
|
||||
}
|
||||
if (goods.getRequiredPoints() > 0 && pointsUser.getPointBalance() < (long) goods.getRequiredPoints() * param.getNumber()) {
|
||||
throw new CzgException("兑换失败,积分不足");
|
||||
}
|
||||
ShopUser shopUser = shopUserService.getUserInfo(param.getShopId(), param.getUserId());
|
||||
if (shopUser == null) {
|
||||
throw new CzgException("兑换失败,店铺用户不存在");
|
||||
}
|
||||
|
||||
MkPointsGoodsRecord record = new MkPointsGoodsRecord();
|
||||
record.setOrderNo("DH" + IdUtil.getSnowflakeNextId());
|
||||
record.setShopId(param.getShopId());
|
||||
record.setPointsGoodsId(param.getPointsGoodsId());
|
||||
record.setPointsGoodsName(goods.getGoodsName());
|
||||
record.setGoodsImageUrl(goods.getGoodsImageUrl());
|
||||
record.setGoodsCategory(goods.getGoodsCategory());
|
||||
record.setReceiveType(goods.getReceiveType());
|
||||
record.setShopUserId(shopUser.getId());
|
||||
record.setUserId(param.getUserId());
|
||||
record.setNumber(param.getNumber());
|
||||
record.setSpendPoints(goods.getRequiredPoints() * param.getNumber());
|
||||
record.setExtraPaymentAmount(goods.getExtraPrice() != null ? goods.getExtraPrice().multiply(new BigDecimal(param.getNumber())) : BigDecimal.ZERO);
|
||||
if (goods.getExtraPrice() != null && goods.getExtraPrice().compareTo(BigDecimal.ZERO) > 0) {
|
||||
param.setPrice(record.getExtraPaymentAmount());
|
||||
record.setStatus("待支付");
|
||||
record.setIsDel(1);
|
||||
goodsRecordService.save(record);
|
||||
return payService.ltPayPointsGoods(ip, param, record.getId());
|
||||
}
|
||||
|
||||
//正常处理
|
||||
exchangeAfter(record, goods);
|
||||
return CzgResult.success(BeanUtil.beanToMap(record));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyRefund(PointGoodsRefundDTO param, Long shopId) {
|
||||
MkPointsGoodsRecord record = goodsRecordService.getOne(QueryWrapper.create()
|
||||
.eq(MkPointsGoodsRecord::getId, param.getRecordId())
|
||||
.eq(MkPointsGoodsRecord::getShopId, shopId));
|
||||
if (record == null) {
|
||||
throw new CzgException("操作失败,记录不存在");
|
||||
}
|
||||
//退积分
|
||||
if (record.getSpendPoints() != null && record.getSpendPoints() > 0) {
|
||||
//回增积分
|
||||
pointsUserService.alterPoints(record.getUserId(), record.getShopUserId(), record.getShopId(), PointsConstant.ADD,
|
||||
record.getSpendPoints(), record.getId().toString(), "积分商品兑换退款");
|
||||
}
|
||||
//退钱
|
||||
if (record.getExtraPaymentAmount() != null && record.getExtraPaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
String refPayOrderNo = "REP" + IdUtil.getSnowflakeNextId();
|
||||
payService.unifyRefund(shopId, record.getId(), record.getPayOrderId(), refPayOrderNo, param.getReason(), record.getExtraPaymentAmount());
|
||||
}
|
||||
MkPointsGoodsRecord upRecord = new MkPointsGoodsRecord();
|
||||
upRecord.setId(record.getId());
|
||||
upRecord.setStatus("已退款");
|
||||
upRecord.setCancelOrRefundReason(param.getReason());
|
||||
upRecord.setCancelOrRefundTime(LocalDateTime.now());
|
||||
return goodsRecordService.updateById(upRecord);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void payCallBack(Long recordId) {
|
||||
MkPointsGoodsRecord record = goodsRecordService.getById(recordId);
|
||||
if (record == null) {
|
||||
log.error("积分兑换商品发放失败,记录不存在");
|
||||
}
|
||||
exchangeAfter(record, null);
|
||||
}
|
||||
|
||||
|
||||
private MkPointsGoodsRecord exchangeAfter(MkPointsGoodsRecord record, MkPointsGoods goods) {
|
||||
if (goods == null) {
|
||||
goods = goodsService.getById(record.getPointsGoodsId());
|
||||
}
|
||||
//扣除积分
|
||||
pointsUserService.alterPoints(record.getUserId(), null, record.getShopId(), PointsConstant.SUB,
|
||||
record.getSpendPoints(), record.getId().toString(), "积分商品兑换");
|
||||
record.setIsDel(0);
|
||||
if (goods.getGoodsCategory().equals("优惠券")) {
|
||||
record.setStatus("已完成");
|
||||
record.setCheckoutTime(LocalDateTime.now());
|
||||
goodsRecordService.save(record);
|
||||
MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO()
|
||||
.setCouponId(goods.getCouponId())
|
||||
.setShopId(record.getShopId())
|
||||
.setSourceId(record.getId())
|
||||
.setShopUserId(record.getId())
|
||||
.setSource("积分兑换");
|
||||
couponRecordService.receiveCoupon(giftDTO, record.getNumber(), false);
|
||||
return record;
|
||||
}else {
|
||||
record.setStatus("待核销");
|
||||
record.setCouponCode(RandomUtil.randomNumbers(12));
|
||||
}
|
||||
goodsService.upNumberById(goods.getId(), goods.getQuantity() - record.getNumber(), goods.getTotalExchangeCount() + record.getNumber());
|
||||
goodsRecordService.save(record);
|
||||
return record;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user