会员充值活动

现金充值
充值记录ID
This commit is contained in:
2025-02-18 14:25:11 +08:00
parent 02cb55b295
commit 703c4906f9
21 changed files with 465 additions and 71 deletions

View File

@@ -1,6 +1,7 @@
package com.czg.service.order.service;
import com.czg.entity.resp.*;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.resp.CzgResult;
import com.czg.service.order.dto.OrderPayParamDTO;
import com.czg.service.order.dto.VipPayParamDTO;
@@ -11,6 +12,7 @@ import java.util.Map;
/**
* 支付
*
* @author ww
*/
public interface PayService {
@@ -39,6 +41,12 @@ public interface PayService {
*/
CzgResult<Map<String, Object>> microPayOrder(OrderPayParamDTO payParam);
/**
* 现金充值
*/
CzgResult<Object> cashPayVip(VipPayParamDTO payParam);
/**
* js支付
*/
@@ -63,7 +71,7 @@ public interface PayService {
/**
* 订单退款
*/
CzgResult<CzgRefundResp> refundOrder(Long shopId, Long orderId,String refundReason,BigDecimal refundAmount);
CzgResult<CzgRefundResp> refundOrder(Long shopId, Long orderId, String refundReason, BigDecimal refundAmount);
/**

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopActivateService;
import com.czg.account.service.ShopUserService;
import com.czg.entity.notify.CzgPayNotifyDTO;
import com.czg.enums.ShopUserFlowBizEnum;
@@ -51,6 +52,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
private OrderPaymentService paymentService;
@DubboReference
private ShopUserService shopUserService;
@DubboReference
private ShopActivateService activateService;
@Override
public Page<OrderInfoVo> getOrderByPage(OrderInfoQueryDTO param) {
@@ -111,10 +114,12 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if (shopUser == null) {
log.error("会员充值失败会员不存在会员id{}", payment.getSourceId());
} else {
shopUserService.updateChain()
.set(ShopUser::getIsVip, 1)
.eq(ShopUser::getId, payment.getSourceId())
.update();
if (shopUser.getIsVip().equals(0)) {
shopUserService.updateChain()
.set(ShopUser::getIsVip, 1)
.eq(ShopUser::getId, payment.getSourceId())
.update();
}
ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder()
.id(payment.getSourceId())
.money(new BigDecimal(czgCallBackDto.getAmount() / 100L))
@@ -124,11 +129,16 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if ("WECHAT".equals(czgCallBackDto.getPayType())) {
shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.WECHAT_IN);
} else if ("ALIPAY".equals(czgCallBackDto.getPayType())) {
shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.ADMIN_IN);
shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.ALIPAY_IN);
} else {
shopUserMoneyEditDTO.setBizEnum(ShopUserFlowBizEnum.CASH_IN);
}
//更新会员余额 并生成流水
shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
Long flowId = shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
//会员活动
activateService.giveActivate(shopUser.getShopId(), shopUser.getId(),
new BigDecimal(czgCallBackDto.getAmount() / 100L), flowId);
}
}
}

View File

@@ -3,12 +3,15 @@ package com.czg.service.order.service.impl;
import cn.hutool.core.exceptions.ValidateException;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.entity.ShopMerchant;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopActivateService;
import com.czg.account.service.ShopMerchantService;
import com.czg.account.service.ShopUserService;
import com.czg.entity.req.*;
import com.czg.entity.resp.*;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderInfoService;
@@ -27,6 +30,7 @@ import jakarta.validation.constraints.NotBlank;
import lombok.NonNull;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.HashMap;
@@ -45,6 +49,8 @@ public class PayServiceImpl implements PayService {
private SysParamsService sysParamsService;
@DubboReference
private ShopUserService shopUserService;
@DubboReference
private ShopActivateService shopActivateService;
@Resource
private CzgPayService czgPayService;
@Resource
@@ -55,6 +61,7 @@ public class PayServiceImpl implements PayService {
private final BigDecimal MONEY_RATE = new BigDecimal("100");
@Override
@Transactional
public CzgResult<Map<String, Object>> h5PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
@@ -67,6 +74,7 @@ public class PayServiceImpl implements PayService {
@Override
@Transactional
public CzgResult<Map<String, Object>> jsPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
@@ -80,6 +88,7 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Map<String, Object>> ltPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
@@ -91,6 +100,7 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Map<String, Object>> scanPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
@@ -102,6 +112,7 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Map<String, Object>> microPayOrder(OrderPayParamDTO payParam) {
OrderInfo orderInfo = orderInfoService.getById(payParam.getOrderId());
AssertUtil.isNull(orderInfo, "订单不存在");
@@ -114,10 +125,37 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Object> cashPayVip(VipPayParamDTO payParam) {
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
.eq(ShopUser::getUserId, payParam.getUserId()).one();
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
if (shopUser.getIsVip().equals(0)) {
shopUserService.updateChain()
.set(ShopUser::getIsVip, 1)
.eq(ShopUser::getId, payParam.getShopId())
.update();
}
ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder()
.id(shopUser.getId())
.money(payParam.getAmount())
.type(1)
.remark("现金充值")
.bizEnum(ShopUserFlowBizEnum.CASH_IN)
.build();
//更新会员余额 并生成流水
Long flowId = shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
//会员活动
shopActivateService.giveActivate(shopUser.getShopId(), shopUser.getId(), payParam.getAmount(), flowId);
return CzgResult.success();
}
@Override
@Transactional
public CzgResult<Map<String, Object>> jsPayVip(String clintIp, VipPayParamDTO payParam) {
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
.eq(ShopUser::getUserId, payParam.getShopUserId()).one();
AssertUtil.isNull(shopUser,"充值失败 该店铺用户不存在");
.eq(ShopUser::getUserId, payParam.getUserId()).one();
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
@@ -127,10 +165,11 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Map<String, Object>> ltPayVip(String clintIp, VipPayParamDTO payParam) {
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
.eq(ShopUser::getUserId, payParam.getShopUserId()).one();
AssertUtil.isNull(shopUser,"充值失败 该店铺用户不存在");
.eq(ShopUser::getUserId, payParam.getUserId()).one();
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
@@ -140,10 +179,11 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Map<String, Object>> scanPayVip(String clintIp, VipPayParamDTO payParam) {
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
.eq(ShopUser::getUserId, payParam.getShopUserId()).one();
AssertUtil.isNull(shopUser,"充值失败 该店铺用户不存在");
.eq(ShopUser::getUserId, payParam.getUserId()).one();
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberIn", payOrderNo, "", payParam.getAmount()));
return scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNo, payParam.getAmount().multiply(MONEY_RATE).longValue(),
@@ -151,10 +191,11 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<Map<String, Object>> microPayVip(VipPayParamDTO payParam) {
ShopUser shopUser = shopUserService.queryChain().eq(ShopUser::getShopId, payParam.getShopId())
.eq(ShopUser::getUserId, payParam.getShopUserId()).one();
AssertUtil.isNull(shopUser,"充值失败 该店铺用户不存在");
.eq(ShopUser::getUserId, payParam.getUserId()).one();
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
AssertUtil.isBlank(payParam.getAuthCode(), "扫描码不能为空");
String payOrderNo = payParam.getPlatformType() + IdUtil.getSnowflakeNextId();
initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), "memberIn", payOrderNo, payParam.getAuthCode(), payParam.getAmount()));
@@ -164,6 +205,7 @@ public class PayServiceImpl implements PayService {
@Override
@Transactional
public CzgResult<CzgRefundResp> refundOrder(@NonNull Long shopId, @NonNull Long orderId, @NonNull String refundReason, @NonNull BigDecimal refundAmount) {
// refund(shopId, new CzgRefundReq("1", refundReason, refundAmount.multiply(MONEY_RATE).longValue(),
@@ -172,12 +214,14 @@ public class PayServiceImpl implements PayService {
}
@Override
@Transactional
public CzgResult<CzgBaseResp> queryPayOrder(@NonNull Long shopId, String payOrderId, String mchOrderNo) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
return czgPayService.queryPayOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), payOrderId, mchOrderNo);
}
@Override
@Transactional
public CzgResult<CzgRefundResp> queryRefund(@NonNull Long shopId, String mchRefundNo, String refundOrderId) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
return czgPayService.queryRefundOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), mchRefundNo, refundOrderId);
@@ -250,7 +294,7 @@ public class PayServiceImpl implements PayService {
} else if (firstTwoDigits >= 25 && firstTwoDigits <= 30) {
//支付宝支付
bizData.setSubAppid(shopMerchant.getAlipaySmallAppid());
}else {
} else {
throw new ValidateException("扫描码非法或暂不支持");
}
CzgResult<CzgMicroPayResp> czgScanPayResult = czgPayService.microPay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);