Merge branch 'pay' into test
This commit is contained in:
@@ -32,6 +32,8 @@ public class AggregateMerchantVO extends AggregateMerchantDto{
|
||||
* 微信进件签名地址
|
||||
*/
|
||||
private String wechatSignUrl;
|
||||
private String wechatApplyId;
|
||||
private String alipayOrderId;
|
||||
|
||||
/**
|
||||
* {@link com.czg.PayCst.EntryStatus}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.czg.service.order.dto;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
* @author ww
|
||||
*/
|
||||
@Data
|
||||
public class CreateOrderDTO {
|
||||
@NotBlank(message = "桌号不能为空")
|
||||
private String tableCode;
|
||||
@NotBlank(message = "用餐模式 堂食 dine-in 外带 take-out 外卖 take-away")
|
||||
private String dineMode;
|
||||
/**
|
||||
* 平台类型
|
||||
* 微信小程序 WX
|
||||
* 支付宝小程序 ALI
|
||||
* 收银机客户端 PC
|
||||
* PC管理端 APC
|
||||
* APP管理端 APP
|
||||
*/
|
||||
@NotBlank(message = "平台类型不能为空")
|
||||
private String platformType;
|
||||
|
||||
/**
|
||||
* 是否使用了霸王餐
|
||||
*/
|
||||
private boolean isFreeDine = false;
|
||||
|
||||
private String remark;
|
||||
|
||||
// 使用的积分抵扣数量
|
||||
private Integer pointsNum;
|
||||
|
||||
// 使用的优惠券
|
||||
@Valid
|
||||
private List<UserCouponInfoDTO> userCouponInfos = new ArrayList<>();
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.czg.service.order.dto;
|
||||
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 支付接收参数 实体类
|
||||
*
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
public class RechargeDTO {
|
||||
@NotNull(message = "店铺不能为空")
|
||||
private Long shopId;
|
||||
private Long shopUserId;
|
||||
|
||||
/**
|
||||
* 充值金额id
|
||||
*/
|
||||
private Long rechargeDetailId;
|
||||
@DecimalMin("0.01")
|
||||
private BigDecimal amount;
|
||||
private Integer allPack;
|
||||
|
||||
/**
|
||||
* 跳转地址
|
||||
*/
|
||||
private String returnUrl;
|
||||
/**
|
||||
* 平台类型 pc 收银机客户端 wechat 微信小程序 alipay 支付宝小程序 admin-pc PC管理端 admin-app APP管理端
|
||||
*/
|
||||
private String platformType;
|
||||
|
||||
private String openId;
|
||||
|
||||
private String buyerRemark;
|
||||
|
||||
private String payType;
|
||||
|
||||
private Long orderId;
|
||||
private Integer seatNum;
|
||||
/**
|
||||
* 用户端 使用 全打包 或者 全不打包
|
||||
*/
|
||||
private Integer userAllPack;
|
||||
|
||||
public boolean isAllPack() {
|
||||
return allPack != null && allPack == 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.czg.service.order.dto;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
public class UserCouponInfoDTO {
|
||||
private Long userCouponId;
|
||||
@Min(1)
|
||||
private Integer num;
|
||||
}
|
||||
@@ -7,33 +7,20 @@ import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 支付
|
||||
* 分销员支付
|
||||
*
|
||||
* @author ww
|
||||
*/
|
||||
public interface DistributionPayService {
|
||||
/**
|
||||
* 现金支付
|
||||
*/
|
||||
CzgResult<Object> cashPayOrder(MkDistributionPayDTO payParam);
|
||||
|
||||
|
||||
/**
|
||||
* 小程序支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> ltPayOrder(String clintIp, MkDistributionPayDTO payParam);
|
||||
|
||||
/**
|
||||
* PC扫码支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> scanPayOrder(String clintIp, MkDistributionPayDTO payParam);
|
||||
|
||||
/**
|
||||
* 反扫
|
||||
* 运营端小程序余额充值
|
||||
*/
|
||||
CzgResult<Map<String, Object>> microPayOrder(MkDistributionPayDTO payParam);
|
||||
|
||||
|
||||
Map<String, String> mchRecharge(String clientIP, MkDistributionPayDTO payParam);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.czg.service.order.service;
|
||||
|
||||
import com.czg.order.dto.OrderInfoRefundDTO;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.order.dto.OrderPayParamDTO;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
*/
|
||||
public interface OrderPayService {
|
||||
|
||||
/**
|
||||
* 挂账
|
||||
*/
|
||||
CzgResult<Object> creditPayOrder(OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 现金支付
|
||||
*/
|
||||
CzgResult<Object> cashPayOrder(OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 余额支付
|
||||
*/
|
||||
CzgResult<Object> vipPayOrder(OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* h5支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> h5PayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* js支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> jsPayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 空订单支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> js2PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 小程序支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> ltPayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* PC扫码支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> scanPayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 聚合反扫
|
||||
*/
|
||||
CzgResult<Map<String, Object>> microPayOrder(OrderPayParamDTO payParam);
|
||||
//-----------------------------------------------------------------订单+会员 一起支付-----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 充值并付款
|
||||
*/
|
||||
CzgResult<Map<String, Object>> rechargePayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------退款-----------------------------------------------------------------
|
||||
|
||||
//订单退款
|
||||
CzgResult<Object> refundOrderBefore(OrderInfoRefundDTO param);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,15 +1,11 @@
|
||||
package com.czg.service.order.service;
|
||||
|
||||
import com.czg.entity.req.*;
|
||||
import com.czg.entity.resp.CzgBaseResp;
|
||||
import com.czg.entity.resp.CzgRefundResp;
|
||||
import com.czg.order.dto.LtPayOtherDTO;
|
||||
import com.czg.order.dto.OrderInfoRefundDTO;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.order.dto.OrderPayParamDTO;
|
||||
import com.czg.service.order.dto.VipMemberPayParamDTO;
|
||||
import com.czg.service.order.dto.VipPayParamDTO;
|
||||
import com.czg.service.order.dto.VipRefundDTO;
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -22,129 +18,45 @@ import java.util.Map;
|
||||
* @author ww
|
||||
*/
|
||||
public interface PayService {
|
||||
//-----------------------------------------------------------------订单支付--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 挂账
|
||||
*/
|
||||
CzgResult<Object> creditPayOrder(OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 现金支付
|
||||
*/
|
||||
CzgResult<Object> cashPayOrder(OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 余额支付
|
||||
*/
|
||||
CzgResult<Object> vipPayOrder(OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* h5支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> h5PayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* js支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> jsPayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 空订单支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> js2PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 小程序支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> ltPayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* PC扫码支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> scanPayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 聚合反扫
|
||||
*/
|
||||
CzgResult<Map<String, Object>> microPayOrder(OrderPayParamDTO payParam);
|
||||
//-----------------------------------------------------------------订单+会员 一起支付-----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 充值并付款
|
||||
*/
|
||||
CzgResult<Map<String, Object>> rechargePayOrder(String clintIp, OrderPayParamDTO payParam);
|
||||
//-----------------------------------------------------------------会员支付--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 现金充值
|
||||
*/
|
||||
CzgResult<Object> cashPayVip(VipPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* js支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> jsPayVip(String clintIp, VipPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 小程序支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> ltPayVip(String clintIp, VipPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* PC扫码支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> scanPayVip(String clintIp, VipPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 聚合反扫
|
||||
*/
|
||||
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);
|
||||
BigDecimal MONEY_RATE = new BigDecimal("100");
|
||||
|
||||
|
||||
Long initOrderPayment(OrderPayment payment);
|
||||
|
||||
//-----------------------------------------------------------------付款 ----------------------------------------------------------
|
||||
CzgResult<Map<String, Object>> h5Pay(@NonNull Long shopId, CzgH5PayReq bizData);
|
||||
CzgResult<Map<String, Object>> jsPay(@NonNull Long shopId, @NonNull String payType, CzgJsPayReq bizData);
|
||||
CzgResult<Map<String, Object>> ltPay(@NonNull Long shopId, String payType, CzgLtPayReq bizData);
|
||||
CzgResult<Map<String, Object>> scanPay(@NonNull Long shopId, CzgScanPayReq bizData);
|
||||
CzgResult<Map<String, Object>> microPay(@NonNull Long shopId, CzgMicroPayReq bizData);
|
||||
//-----------------------------------------------------------------积分商品/拼团 付款 ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @param param 支付参数
|
||||
* @param payType 暂时只有 POINT 积分 和 WARE 拼团商品
|
||||
* @param payType {@link com.czg.constants.PayTypeConstants.SourceType} 常量
|
||||
* @param detail 操作描述 如 积分商品购买 / 拼团商品购买
|
||||
*/
|
||||
CzgResult<Map<String, Object>> ltPayOther(LtPayOtherDTO param, String payType, String detail);
|
||||
|
||||
//-----------------------------------------------------------------退款-----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 退款前校验
|
||||
*/
|
||||
CzgResult<Map<String, BigDecimal>> refundVipBefore(VipRefundDTO payParam);
|
||||
|
||||
/**
|
||||
* 会员退款
|
||||
* 退款
|
||||
* 目前订单 会员 使用
|
||||
*/
|
||||
CzgResult<Object> refundVip(VipRefundDTO payParam);
|
||||
|
||||
CzgResult<Object> refundOrderBefore(OrderInfoRefundDTO param);
|
||||
|
||||
/**
|
||||
* 订单退款
|
||||
*/
|
||||
void refundOrder(Long shopId, Long orderId, Long payOrderId, String refPayOrderNo, String refundReason, BigDecimal refundAmount);
|
||||
|
||||
CzgResult<CzgRefundResp> refund(@NonNull Long shopId, CzgRefundReq bizData);
|
||||
/**
|
||||
* 统一退款接口
|
||||
*
|
||||
* 目前 拼团商品 积分商品 套餐推广 使用
|
||||
* @param refPayOrderNo 自定义退单号 {@link com.czg.enums.OrderNoPrefixEnum} + 雪花Id
|
||||
*/
|
||||
void unifyRefund(Long shopId, Long sourceId, Long payOrderId, String refPayOrderNo, String refundReason, BigDecimal refundAmount);
|
||||
|
||||
/**
|
||||
* 退款补偿使用
|
||||
* 目前 拼团商品 积分商品 套餐推广 使用
|
||||
* (退款 账户余额不足时 会失败定时任务)
|
||||
*/
|
||||
void unifyRefund(OrderPayment payment, String refPayOrderNo);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package com.czg.service.order.service;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.dto.req.AggregateMerchantDto;
|
||||
import com.czg.service.order.dto.AggregateMerchantVO;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
@@ -12,8 +13,22 @@ import com.czg.order.entity.ShopDirectMerchant;
|
||||
*/
|
||||
public interface ShopDirectMerchantService extends IService<ShopDirectMerchant> {
|
||||
|
||||
/**
|
||||
* ocr识别图片
|
||||
* @param url 图片地址
|
||||
* @param type IdCard 身份证
|
||||
* BankCard 银行卡
|
||||
* BusinessLicense 营业执照
|
||||
*/
|
||||
JSONObject getInfoByImg(String url, String type) throws Exception;
|
||||
|
||||
/**
|
||||
* 获取进件信息
|
||||
*/
|
||||
AggregateMerchantVO getEntry(Long shopId);
|
||||
|
||||
/**
|
||||
* 申请进件
|
||||
*/
|
||||
boolean entryManager(AggregateMerchantDto reqDto);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.czg.service.order.service;
|
||||
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.order.dto.VipMemberPayParamDTO;
|
||||
import com.czg.service.order.dto.VipPayParamDTO;
|
||||
import com.czg.service.order.dto.VipRefundDTO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 用户余额 充值/会员购买开通
|
||||
* @author ww
|
||||
*/
|
||||
public interface ShopUserPayService {
|
||||
|
||||
//-----------------------------------------------------------------会员支付--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 现金充值
|
||||
*/
|
||||
CzgResult<Object> cashPayVip(VipPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* js支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> jsPayVip(String clintIp, VipPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 小程序支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> ltPayVip(String clintIp, VipPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* PC扫码支付
|
||||
*/
|
||||
CzgResult<Map<String, Object>> scanPayVip(String clintIp, VipPayParamDTO payParam);
|
||||
|
||||
/**
|
||||
* 聚合反扫
|
||||
*/
|
||||
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, BigDecimal>> refundVipBefore(VipRefundDTO payParam);
|
||||
|
||||
/**
|
||||
* 会员退款
|
||||
*/
|
||||
CzgResult<Object> refundVip(VipRefundDTO payParam);
|
||||
}
|
||||
@@ -3,17 +3,16 @@ package com.czg.service.order.service.impl;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.entity.UserInfo;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.account.service.UserInfoService;
|
||||
import com.czg.constant.TableValueConstant;
|
||||
import com.czg.constants.PayTypeConstants;
|
||||
import com.czg.entity.req.CzgLtPayReq;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.market.service.MkDistributionConfigService;
|
||||
import com.czg.market.vo.MkDistributionConfigVO;
|
||||
import com.czg.order.dto.MkDistributionPayDTO;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.constants.PayTypeConstants;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.market.service.impl.WxServiceImpl;
|
||||
@@ -44,8 +43,6 @@ public class DistributionPayServiceImpl implements DistributionPayService {
|
||||
@Resource
|
||||
private PayServiceImpl payService;
|
||||
|
||||
@DubboReference
|
||||
private ShopInfoService shopInfoService;
|
||||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
@DubboReference
|
||||
@@ -89,11 +86,6 @@ public class DistributionPayServiceImpl implements DistributionPayService {
|
||||
return initInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgResult<Object> cashPayOrder(MkDistributionPayDTO payParam) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgResult<Map<String, Object>> ltPayOrder(String clintIp, MkDistributionPayDTO payParam) {
|
||||
InitInfo initInfo = initPayment(payParam.getUserId(), payParam, false);
|
||||
@@ -106,14 +98,4 @@ public class DistributionPayServiceImpl implements DistributionPayService {
|
||||
InitInfo initInfo = initPayment(payParam.getUserId() == null ? payParam.getShopId() : payParam.getUserId(), payParam, true);
|
||||
return wxService.v3Pay(initInfo.openId, payParam.getAmount(), "商户运营余额充值", initInfo.payment.getOrderNo(), initInfo.payment.getSourceType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgResult<Map<String, Object>> scanPayOrder(String clintIp, MkDistributionPayDTO payParam) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgResult<Map<String, Object>> microPayOrder(MkDistributionPayDTO payParam) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,561 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.digest.MD5;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.entity.UserInfo;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.account.service.UserInfoService;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
import com.czg.config.RedisCst;
|
||||
import com.czg.constants.PayTypeConstants;
|
||||
import com.czg.entity.req.*;
|
||||
import com.czg.entity.resp.CzgRefundResp;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.exception.PaySuccessException;
|
||||
import com.czg.market.entity.MkShopRechargeDetail;
|
||||
import com.czg.market.enums.PointsConstant;
|
||||
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.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.order.service.OrderInfoCustomService;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.RedisService;
|
||||
import com.czg.service.order.dto.OrderPayParamDTO;
|
||||
import com.czg.service.order.enums.OrderStatusEnums;
|
||||
import com.czg.service.order.service.OrderPayService;
|
||||
import com.czg.service.order.service.PayService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.CzgRandomUtils;
|
||||
import com.czg.utils.FunUtils;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class OrderPayServiceImpl implements OrderPayService {
|
||||
@Resource
|
||||
private PayService payService;
|
||||
@Resource
|
||||
private OrderPaymentService paymentService;
|
||||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
@DubboReference
|
||||
private UserInfoService userInfoService;
|
||||
@DubboReference
|
||||
private ShopInfoService shopInfoService;
|
||||
@Resource
|
||||
private OrderInfoCustomService orderInfoCustomService;
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
@Resource
|
||||
private CreditBuyerOrderService buyerOrderService;
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
@Resource
|
||||
private RabbitPublisher rabbitPublisher;
|
||||
@Resource
|
||||
private MkShopRechargeService shopRechargeService;
|
||||
@Resource
|
||||
private MkShopRechargeDetailService shopRechargeDetailService;
|
||||
@Resource
|
||||
private OrderDetailService orderDetailService;
|
||||
@Resource
|
||||
private MkDistributionUserService distributionUserService;
|
||||
@Resource
|
||||
private MkShopConsumerCouponService consumerCouponService;
|
||||
@Resource
|
||||
private MkPointsUserService mkPointsUserService;
|
||||
@Resource
|
||||
private MkConsumeCashbackService consumeCashbackService;
|
||||
@Resource
|
||||
private MkPointsConfigService pointsConfigService;
|
||||
|
||||
private OrderInfo checkPay(CheckOrderPay checkOrderPay) {
|
||||
OrderInfo orderInfo = orderInfoCustomService.checkOrderPay(checkOrderPay);
|
||||
if (orderInfo.getOrderAmount().compareTo(BigDecimal.ZERO) == 0) {
|
||||
//发送打票信息
|
||||
//orderId_0_0 订单ID_先付后付(1先付0后付)_订单状态 0未完成 1完成
|
||||
//orderInfo.getId() + "_" + (!"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0) + "_0"
|
||||
rabbitPublisher.sendOrderPrintMsg(orderInfo.getId() + "_" + (!"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0) + "_1", orderInfo.getIsPrint() == 1);
|
||||
redisService.del(RedisCst.classKeyExpired.EXPIRED_ORDER + orderInfo.getId());
|
||||
throw new PaySuccessException("支付成功");
|
||||
}
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(noRollbackFor = PaySuccessException.class)
|
||||
public CzgResult<Object> creditPayOrder(OrderPayParamDTO payParam) {
|
||||
AssertUtil.isNull(payParam.getCreditBuyerId(), "请选择挂账人后支付");
|
||||
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
|
||||
orderInfo.setCreditBuyerId(payParam.getCreditBuyerId());
|
||||
orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
|
||||
LocalDateTime.now(), null, PayEnums.CREDIT_PAY);
|
||||
//挂账后续逻辑
|
||||
buyerOrderService.save(payParam.getCreditBuyerId().toString(), orderInfo.getId());
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(noRollbackFor = PaySuccessException.class)
|
||||
public CzgResult<Object> cashPayOrder(OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
|
||||
orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
|
||||
LocalDateTime.now(), null, PayEnums.CASH_PAY);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(noRollbackFor = PaySuccessException.class)
|
||||
public CzgResult<Object> vipPayOrder(OrderPayParamDTO payParam) {
|
||||
ShopInfo shopInfo = shopInfoService.getById(payParam.getShopId());
|
||||
AssertUtil.isNull(shopInfo, "店铺不存在");
|
||||
if (!shopInfo.getIsAccountPay().equals(1)) {
|
||||
return CzgResult.failure("支付失败,店铺暂未开启会员余额支付。");
|
||||
}
|
||||
ShopUser shopUser = new ShopUser();
|
||||
if ("scanCode".equals(payParam.getPayType())) {
|
||||
AssertUtil.isBlank(payParam.getAuthCode(), "会员码不能为空");
|
||||
Object o = redisService.get(RedisCst.SHOP_USER_DYNAMIC_CODE + payParam.getShopId() + ":" + payParam.getAuthCode());
|
||||
AssertUtil.isNull(o, "会员码已失效");
|
||||
shopUser = shopUserService.getById(o.toString());
|
||||
} else {
|
||||
if ("userPay".equals(payParam.getPayType())) {
|
||||
AssertUtil.isNull(payParam.getShopUserId(), "请选择付款人后重试");
|
||||
shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
} else if ("accountPay".equals(payParam.getPayType())) {
|
||||
shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "会员不存在");
|
||||
UserInfo userInfo = userInfoService.getById(shopUser.getUserId());
|
||||
AssertUtil.isNull(userInfo, "用户信息不存在");
|
||||
if (userInfo.getUsePayPwd() == 1) {
|
||||
AssertUtil.isBlank(payParam.getPwd(), "支付密码不能为空");
|
||||
if (userInfo.getPayPwd() == null || !userInfo.getPayPwd().equals(MD5.create().digestHex((payParam.getPwd())))) {
|
||||
return CzgResult.failure("支付密码错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (shopUser == null || shopUser.getId() == null) {
|
||||
AssertUtil.isNull(shopUser, "会员不存在");
|
||||
}
|
||||
payParam.getCheckOrderPay().setUserId(shopUser.getUserId());
|
||||
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
|
||||
if (shopInfo.getIsHeadShop().equals(1)) {
|
||||
if (!shopUser.getMainShopId().equals(orderInfo.getShopId())) {
|
||||
return CzgResult.failure("违规操作,请确认店铺后重试");
|
||||
}
|
||||
} else {
|
||||
boolean exists = shopInfoService.exists(QueryWrapper.create()
|
||||
.eq(ShopInfo::getMainId, shopInfo.getMainId())
|
||||
.eq(ShopInfo::getId, orderInfo.getShopId()));
|
||||
if (!exists) {
|
||||
return CzgResult.failure("违规操作,请确认店铺后重试");
|
||||
}
|
||||
}
|
||||
if (shopUser.getAmount().compareTo(orderInfo.getOrderAmount()) < 0) {
|
||||
return CzgResult.failure("会员余额不足");
|
||||
}
|
||||
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
|
||||
.setId(shopUser.getId())
|
||||
.setMoney(orderInfo.getOrderAmount())
|
||||
.setType(0)
|
||||
.setBizEnum(ShopUserFlowBizEnum.ORDER_PAY)
|
||||
.setRelationId(orderInfo.getId());
|
||||
//更新会员余额 并生成流水
|
||||
if (payParam.getCheckOrderPay() != null && StrUtil.isNotBlank(payParam.getCheckOrderPay().getRemark())) {
|
||||
orderInfo.setRemark(payParam.getCheckOrderPay().getRemark());
|
||||
}
|
||||
|
||||
Long flowId = shopUserService.updateMoney(shopUserMoneyEditDTO);
|
||||
orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
|
||||
LocalDateTime.now(), flowId, PayEnums.VIP_PAY);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgResult<Map<String, Object>> rechargePayOrder(String clintIp, OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
|
||||
ShopInfo shopInfo = shopInfoService.getById(payParam.getShopId());
|
||||
AssertUtil.isNull(shopInfo, "店铺不存在");
|
||||
AssertUtil.isNull(payParam.getShopUserId(), "请选择付款人后重试");
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "支付失败 该店铺用户不存在");
|
||||
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
||||
UserInfo userInfo = userInfoService.getById(shopUser.getUserId());
|
||||
AssertUtil.isNull(payParam.getRechargeId(), "请选择充值配置后重试");
|
||||
AssertUtil.isNull(payParam.getRechargeDetailId(), "请选择充值配置后重试");
|
||||
//查询活动Id 获取金额字段
|
||||
MkShopRechargeDetail rechargeDetail = shopRechargeDetailService.getOne(
|
||||
new QueryWrapper().eq(MkShopRechargeDetail::getId, payParam.getRechargeDetailId())
|
||||
.eq(MkShopRechargeDetail::getShopRechargeId, payParam.getRechargeId()));
|
||||
AssertUtil.isNull(rechargeDetail, "充值配置不存在");
|
||||
if (orderInfo.getOrderAmount().compareTo(rechargeDetail.getAmount()) >= 0) {
|
||||
log.info("充值金额小于订单金额,充值金额:{} 订单金额:{}", rechargeDetail.getAmount(), orderInfo.getOrderAmount());
|
||||
return CzgResult.failure("支付失败 充值金额必须大雨订单金额");
|
||||
}
|
||||
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
|
||||
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), PayTypeConstants.SourceType.MEMBER_IN, PayTypeConstants.PayType.PAY, payOrderNo,
|
||||
"", rechargeDetail.getAmount(), rechargeDetail.getId()));
|
||||
upOrderPayInfo(orderInfo.getId(), PayEnums.VIP_PAY, paymentId,
|
||||
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
|
||||
return payService.ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNo, rechargeDetail.getAmount().multiply(PayService.MONEY_RATE).longValue(),
|
||||
payParam.getPayType(), "充值并支付", "wechatPay".equals(payParam.getPayType()) ? userInfo.getWechatOpenId() : userInfo.getAlipayOpenId(),
|
||||
clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(noRollbackFor = PaySuccessException.class)
|
||||
public CzgResult<Map<String, Object>> h5PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
|
||||
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
|
||||
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
|
||||
PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.PAY, payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), PayEnums.H5_PAY, paymentId,
|
||||
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
|
||||
return payService.h5Pay(payParam.getShopId(), new CzgH5PayReq(payOrderNo, orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
|
||||
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(noRollbackFor = PaySuccessException.class)
|
||||
public CzgResult<Map<String, Object>> jsPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
|
||||
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
||||
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
|
||||
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
|
||||
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
|
||||
PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.PAY, payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId,
|
||||
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
|
||||
return payService.jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
|
||||
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(noRollbackFor = PaySuccessException.class)
|
||||
public CzgResult<Map<String, Object>> js2PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
|
||||
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
||||
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
|
||||
OrderInfo orderInfo;
|
||||
if (payParam.getCheckOrderPay().getOrderId() == null) {
|
||||
if (payParam.getCheckOrderPay().getOrderAmount() == null || payParam.getCheckOrderPay().getOrderAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new CzgException("支付金额不合法");
|
||||
}
|
||||
orderInfo = orderInfoCustomService.createPayOrder(payParam.getShopId(), payParam.getCheckOrderPay().getOrderAmount(),
|
||||
payParam.getCheckOrderPay().getRemark());
|
||||
} else {
|
||||
orderInfo = orderInfoService.getById(payParam.getCheckOrderPay().getOrderId());
|
||||
}
|
||||
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
|
||||
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
|
||||
PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.PAY, payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId,
|
||||
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
|
||||
return payService.jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
|
||||
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(noRollbackFor = PaySuccessException.class)
|
||||
public CzgResult<Map<String, Object>> ltPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
|
||||
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
||||
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
|
||||
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
|
||||
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
|
||||
PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.PAY, payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId,
|
||||
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
|
||||
return payService.ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
|
||||
payParam.getPayType(), "点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(noRollbackFor = PaySuccessException.class)
|
||||
public CzgResult<Map<String, Object>> scanPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
MkShopRechargeVO rechargeVO = shopRechargeService.detail(payParam.getShopId());
|
||||
if (payParam.getRechargeDetailId() == null && rechargeVO.getIsCustom() == 0) {
|
||||
throw new CzgException("未开启自定义充值金额");
|
||||
}
|
||||
Long mainShopId = shopInfoService.getMainIdByShopId(payParam.getShopId());
|
||||
BigDecimal amount = shopRechargeService.checkRecharge(mainShopId, payParam.getShopId(), shopUser.getUserId(), payParam.getRechargeDetailId(), payParam.getAmount());
|
||||
payParam.setAmount(amount);
|
||||
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
|
||||
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
|
||||
PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.PAY, payOrderNo, "", orderInfo.getOrderAmount()));
|
||||
upOrderPayInfo(orderInfo.getId(), PayEnums.MAIN_SCAN, paymentId,
|
||||
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
|
||||
return payService.scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
|
||||
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(noRollbackFor = PaySuccessException.class)
|
||||
public CzgResult<Map<String, Object>> microPayOrder(OrderPayParamDTO payParam) {
|
||||
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
|
||||
AssertUtil.isBlank(payParam.getAuthCode(), "扫描码不能为空");
|
||||
|
||||
|
||||
if (payParam.getShopUserId() != null) {
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
MkShopRechargeVO rechargeVO = shopRechargeService.detail(payParam.getShopId());
|
||||
if (payParam.getRechargeDetailId() == null && rechargeVO.getIsCustom() == 0) {
|
||||
throw new CzgException("未开启自定义充值金额");
|
||||
}
|
||||
Long mainShopId = shopInfoService.getMainIdByShopId(payParam.getShopId());
|
||||
BigDecimal amount = shopRechargeService.checkRecharge(mainShopId, payParam.getShopId(), shopUser.getUserId(), payParam.getRechargeDetailId(), payParam.getAmount());
|
||||
payParam.setAmount(amount);
|
||||
}
|
||||
|
||||
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
|
||||
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
|
||||
PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.PAY, payOrderNo, payParam.getAuthCode(), orderInfo.getOrderAmount()));
|
||||
CzgResult<Map<String, Object>> mapCzgResult = payService.microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
|
||||
"点餐支付", payParam.getAuthCode(), payParam.getBuyerRemark(), ""));
|
||||
if (mapCzgResult.getCode() == 200) {
|
||||
orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
|
||||
LocalDateTime.now(), paymentId, PayEnums.BACK_SCAN);
|
||||
} else {
|
||||
upOrderPayInfo(orderInfo.getId(), PayEnums.BACK_SCAN, paymentId,
|
||||
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
|
||||
}
|
||||
return mapCzgResult;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Object> refundOrderBefore(OrderInfoRefundDTO param) {
|
||||
OrderInfo orderInfo = orderInfoService.getById(param.getOrderId());
|
||||
if (orderInfo.getStatus().equals(OrderStatusEnums.CANCELLED.getCode())) {
|
||||
throw new CzgException("订单已过期不可退单");
|
||||
}
|
||||
boolean isFirstRefund = true;
|
||||
if (orderInfo.getRefundAmount().compareTo(BigDecimal.ZERO) != 0) {
|
||||
isFirstRefund = false;
|
||||
}
|
||||
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
|
||||
Map<String, BigDecimal> returnProMap = new HashMap<>();
|
||||
boolean isPay = true;
|
||||
String refPayOrderNo = "REFO" + IdUtil.getSnowflakeNextId();
|
||||
if (orderInfo.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) {
|
||||
isPay = false;
|
||||
refPayOrderNo = "";
|
||||
}
|
||||
if (isPay) {
|
||||
if (shopInfo.getIsReturnPwd().equals(1)) {
|
||||
AssertUtil.isBlank(shopInfo.getOperationPwd(), "请设置操作密码后使用");
|
||||
if (!SecureUtil.md5(param.getPwd()).equals(shopInfo.getOperationPwd())) {
|
||||
throw new CzgException("操作密码错误");
|
||||
}
|
||||
}
|
||||
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(param.getRefundAmount()));
|
||||
if (orderInfo.getRefundAmount().compareTo(orderInfo.getPayAmount()) > 0) {
|
||||
throw new CzgException("退单失败,可退金额不足");
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(param.getRefundDetails())) {
|
||||
for (OrderDetail refundDetail : param.getRefundDetails()) {
|
||||
AssertUtil.isNull(refundDetail.getNum(), "退单数量不能为空");
|
||||
//退款数量
|
||||
BigDecimal refNum = refundDetail.getNum();
|
||||
OrderDetail orderDetail = orderDetailService.getById(refundDetail.getId());
|
||||
//可退数量=订单数量-退单数量-退菜数量
|
||||
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() + "可退数量不足");
|
||||
}
|
||||
refundDetail.setReturnAmount(refundDetail.getNum().multiply(orderDetail.getUnitPrice()).setScale(2, RoundingMode.UP));
|
||||
if (isPay) {
|
||||
orderDetail.setRefundNum(orderDetail.getRefundNum().add(refNum));
|
||||
if (orderDetail.getNum().compareTo(orderDetail.getRefundNum().add(orderDetail.getReturnNum())) == 0) {
|
||||
orderDetail.setStatus(OrderStatusEnums.REFUND.getCode());
|
||||
} else {
|
||||
orderDetail.setStatus(OrderStatusEnums.PART_REFUND.getCode());
|
||||
}
|
||||
} else {
|
||||
orderDetail.setReturnNum(orderDetail.getReturnNum().add(refNum));
|
||||
if (orderDetail.getPackNumber().compareTo(BigDecimal.ZERO) > 0 && orderDetail.getPackNumber().compareTo(orderDetail.getNum().subtract(orderDetail.getReturnNum())) > 0) {
|
||||
orderDetail.setPackNumber(orderDetail.getNum().subtract(orderDetail.getReturnNum()));
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
// }
|
||||
orderDetailService.updateById(orderDetail);
|
||||
if (orderDetail.getProductId() != null && orderDetail.getProductId() > 0) {
|
||||
returnProMap.put(Convert.toStr(orderDetail.getProductId()), refundDetail.getNum());
|
||||
}
|
||||
}
|
||||
long count = orderDetailService.queryChain()
|
||||
.eq(OrderDetail::getOrderId, orderInfo.getId())
|
||||
.ne(OrderDetail::getStatus, OrderStatusEnums.REFUND.getCode()).count();
|
||||
if (count > 0 && isPay) {
|
||||
orderInfo.setStatus(OrderStatusEnums.PART_REFUND.getCode());
|
||||
} else if (isPay) {
|
||||
orderInfo.setStatus(OrderStatusEnums.REFUND.getCode());
|
||||
}
|
||||
} else {
|
||||
orderInfo.setStatus(OrderStatusEnums.REFUND.getCode());
|
||||
List<OrderDetail> orderDetails = orderDetailService.queryChain()
|
||||
.select(OrderDetail::getId, OrderDetail::getProductId, OrderDetail::getNum, OrderDetail::getReturnNum, OrderDetail::getPackAmount, OrderDetail::getReturnNum)
|
||||
.eq(OrderDetail::getOrderId, orderInfo.getId())
|
||||
.list();
|
||||
for (OrderDetail orderDetail : orderDetails) {
|
||||
if (isPay) {
|
||||
if (orderDetail.getProductId() != null && orderDetail.getProductId() > 0) {
|
||||
returnProMap.put(Convert.toStr(orderDetail.getProductId()), orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum()));
|
||||
}
|
||||
orderDetail.setReturnAmount(orderDetail.getPayAmount());
|
||||
orderDetail.setRefundNum(orderDetail.getNum().subtract(orderDetail.getReturnNum()));
|
||||
orderDetail.setStatus(OrderStatusEnums.REFUND.getCode());
|
||||
} else {
|
||||
if (orderDetail.getProductId() != null && orderDetail.getProductId() > 0) {
|
||||
returnProMap.put(Convert.toStr(orderDetail.getProductId()), orderDetail.getNum().subtract(orderDetail.getReturnNum()));
|
||||
}
|
||||
orderDetail.setReturnNum(orderDetail.getNum());
|
||||
orderDetail.setStatus(OrderStatusEnums.CANCELLED.getCode());
|
||||
}
|
||||
}
|
||||
orderDetailService.updateBatch(orderDetails);
|
||||
}
|
||||
//总退款金额
|
||||
//TODO 退款 券 未处理
|
||||
if (isPay) {
|
||||
orderInfo.setRefundType("cash");
|
||||
//非现金退款
|
||||
if (!param.isCash()) {
|
||||
if (orderInfo.getPayType().equals(PayEnums.VIP_PAY.getValue())) {
|
||||
ShopUser shopUser = shopUserService.getShopUserInfo(orderInfo.getShopId(), orderInfo.getUserId());
|
||||
//会员支付 退钱
|
||||
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
|
||||
.setId(shopUser.getId())
|
||||
.setMoney(param.getRefundAmount())
|
||||
.setType(1)
|
||||
.setRelationId(orderInfo.getId())
|
||||
.setBizEnum(ShopUserFlowBizEnum.ORDER_REFUND);
|
||||
shopUserService.updateMoney(shopUserMoneyEditDTO);
|
||||
} else if (orderInfo.getPayType().equals(PayEnums.CREDIT_PAY.getValue())) {
|
||||
AssertUtil.isNull(orderInfo.getCreditBuyerId(), "挂账单退款失败,未查询到挂账人");
|
||||
buyerOrderService.partRefund(orderInfo.getCreditBuyerId().toString(), orderInfo.getId(), param.getRefundAmount());
|
||||
} else if (!orderInfo.getPayType().equals(PayEnums.CASH_PAY.getValue())) {
|
||||
//退款 param.getRefundAmount()
|
||||
if (orderInfo.getPayOrderId() == null) {
|
||||
throw new CzgException("退款失败,支付记录不存在");
|
||||
}
|
||||
refundOrder(orderInfo.getShopId(), orderInfo.getId(), orderInfo.getPayOrderId(),
|
||||
refPayOrderNo, StrUtil.isBlank(param.getRefundReason()) ? "退款" : param.getRefundReason(), param.getRefundAmount());
|
||||
}
|
||||
orderInfo.setRefundType("payBack");
|
||||
}
|
||||
} else {
|
||||
orderInfo.setOrderAmount(orderInfo.getOrderAmount().subtract(param.getRefundAmount()));
|
||||
}
|
||||
orderInfo.setRefundRemark(orderInfo.getRefundRemark() + param.getRefundReason());
|
||||
orderInfoService.updateById(orderInfo);
|
||||
//退款后续
|
||||
//退款返还库存
|
||||
if (!returnProMap.isEmpty()) {
|
||||
rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap)));
|
||||
}
|
||||
refundOrderAfter(orderInfo.getId(), orderInfo.getShopId(), orderInfo.getUserId(), orderInfo.getOrderNo(),
|
||||
orderInfo.getPointsNum(), isFirstRefund, orderInfo.getStatus().equals(OrderStatusEnums.REFUND.getCode()));
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
private void refundOrder(@NonNull Long shopId, @NonNull Long orderId, @NonNull Long payOrderId, @NonNull String refPayOrderNo,
|
||||
@NonNull String refundReason, @NonNull BigDecimal refundAmount) {
|
||||
OrderPayment payment = paymentService.getById(payOrderId);
|
||||
AssertUtil.isNull(payment, "退款失败支付记录不存在");
|
||||
Long refundId = payService.initOrderPayment(new OrderPayment(shopId, orderId, PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.REFUND, refPayOrderNo, null, refundAmount, payment.getId()));
|
||||
CzgResult<CzgRefundResp> refund = payService.refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), ""));
|
||||
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getState())) {
|
||||
if (refund.getData() != null && refund.getData().getNote() != null) {
|
||||
throw new CzgException(refund.getData().getNote());
|
||||
}
|
||||
throw new CzgException(refund.getMsg());
|
||||
} 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()))
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
||||
//触发订单退款时 后续处理
|
||||
@Async
|
||||
public void refundOrderAfter(@NonNull Long orderId, @NonNull Long shopId, Long userId, String orderNo,
|
||||
Integer pointsNum, boolean isFirstRefund, boolean isAllRefund) {
|
||||
if (isFirstRefund) {
|
||||
// 退款分销还原
|
||||
FunUtils.safeRunVoid(() -> distributionUserService.refund(orderId, orderNo),
|
||||
"订单id:{} 退款,分销处理失败", orderId);
|
||||
if (userId == null) {
|
||||
return;
|
||||
}
|
||||
FunUtils.safeRunVoid(() -> consumerCouponService.removeConsumerCoupon(shopId, userId, orderId),
|
||||
"订单id:{} 退款,消费赠券回撤处理失败", orderId);
|
||||
FunUtils.safeRunVoid(() -> consumeCashbackService.removeCashback(shopId, userId, orderId, orderNo),
|
||||
"订单id:{} 退款,消费返现扣除处理失败", orderId);
|
||||
FunUtils.safeRunVoid(() -> pointsConfigService.removeConsumeAwardPoints(shopId, userId, orderId, orderNo),
|
||||
"订单id:{} 退款,赠送积分扣除失败", orderId);
|
||||
}
|
||||
if (isAllRefund && userId != null && pointsNum != null && pointsNum > 0) {
|
||||
FunUtils.safeRunVoid(() -> mkPointsUserService.alterPoints(userId, null, shopId, PointsConstant.ADD,
|
||||
pointsNum, orderId, StrUtil.format("订单退款返还{}积分", pointsNum)),
|
||||
"订单id:{} 退款,赠送积分扣除失败", orderId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void upOrderPayInfo(@NonNull Long orderId, @NonNull PayEnums payType, @NotBlank Long paymentId, String remark) {
|
||||
if (paymentId == null) {
|
||||
throw new CzgException("未获取到支付记录");
|
||||
}
|
||||
orderInfoCustomService.updatePayOrderId(orderId, paymentId, payType.getValue(), remark);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,27 +1,27 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.io.unit.DataSizeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.EntryManager;
|
||||
import com.czg.OcrUtils;
|
||||
import com.czg.PayCst;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
import com.czg.constants.ParamCodeCst;
|
||||
import com.czg.dto.req.*;
|
||||
import com.czg.service.order.dto.AggregateMerchantVO;
|
||||
import com.czg.utils.FunUtils;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.ShopDirectMerchant;
|
||||
import com.czg.service.order.service.ShopDirectMerchantService;
|
||||
import com.czg.service.order.dto.AggregateMerchantVO;
|
||||
import com.czg.service.order.mapper.ShopDirectMerchantMapper;
|
||||
import com.czg.service.order.service.ShopDirectMerchantService;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
import com.czg.utils.FunUtils;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
@@ -35,11 +35,21 @@ public class ShopDirectMerchantServiceImpl extends ServiceImpl<ShopDirectMerchan
|
||||
|
||||
@Resource
|
||||
private RabbitPublisher rabbitPublisher;
|
||||
@DubboReference
|
||||
private SysParamsService sysParamsService;
|
||||
|
||||
|
||||
// 全局原子计数器,按天重置(避免数值过大)
|
||||
private static final AtomicLong COUNTER = new AtomicLong(0);
|
||||
// 记录上一次的日期,用于重置计数器
|
||||
private static String LAST_DATE = DateUtil.format(new Date(), "yyyyMMdd");
|
||||
|
||||
@Override
|
||||
public JSONObject getInfoByImg(String url, String type) throws Exception {
|
||||
Map<String, String> aliOssKeys = sysParamsService.getParamsByMap("ali_oss_key_set", ParamCodeCst.ALI_OSS_KEY_SET);
|
||||
return OcrUtils.getInfoByImg(aliOssKeys.get(ParamCodeCst.AliYun.ALI_SMS_KEY), aliOssKeys.get(ParamCodeCst.AliYun.ALI_SMS_SECRET), url, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregateMerchantVO getEntry(Long shopId) {
|
||||
ShopDirectMerchant merchant = getById(shopId);
|
||||
@@ -121,9 +131,11 @@ public class ShopDirectMerchantServiceImpl extends ServiceImpl<ShopDirectMerchan
|
||||
// 设置其他字段
|
||||
vo.setCreateTime(entity.getCreateTime());
|
||||
vo.setUpdateTime(entity.getUpdateTime());
|
||||
vo.setWechatApplyId(entity.getWechatApplyId());
|
||||
vo.setWechatStatus(entity.getWechatStatus());
|
||||
vo.setWechatErrorMsg(entity.getWechatErrorMsg());
|
||||
vo.setWechatSignUrl(entity.getWechatSignUrl());
|
||||
vo.setAlipayOrderId(entity.getAlipayOrderId());
|
||||
vo.setAlipayStatus(entity.getAlipayStatus());
|
||||
vo.setAlipayErrorMsg(entity.getAlipayErrorMsg());
|
||||
vo.setAlipaySignUrl(entity.getAlipaySignUrl());
|
||||
|
||||
@@ -0,0 +1,360 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||
import com.czg.account.entity.*;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.constants.PayTypeConstants;
|
||||
import com.czg.entity.req.*;
|
||||
import com.czg.entity.resp.CzgRefundResp;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.market.dto.MemberOrderDTO;
|
||||
import com.czg.market.entity.MemberOrder;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.service.MemberOrderService;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.market.service.MkShopRechargeService;
|
||||
import com.czg.market.vo.MkShopRechargeVO;
|
||||
import com.czg.order.dto.CheckOrderPay;
|
||||
import com.czg.order.dto.LtPayOtherDTO;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.service.OrderInfoCustomService;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.order.dto.VipMemberPayParamDTO;
|
||||
import com.czg.service.order.dto.VipPayParamDTO;
|
||||
import com.czg.service.order.dto.VipRefundDTO;
|
||||
import com.czg.service.order.service.PayService;
|
||||
import com.czg.service.order.service.ShopUserPayService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.CzgRandomUtils;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
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;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
*/
|
||||
@Service
|
||||
public class ShopUserServiceImpl implements ShopUserPayService {
|
||||
@Resource
|
||||
private PayService payService;
|
||||
|
||||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
@DubboReference
|
||||
private UserInfoService userInfoService;
|
||||
@DubboReference
|
||||
private ShopInfoService shopInfoService;
|
||||
@DubboReference
|
||||
private FreeDineConfigService freeConfigService;
|
||||
@Resource
|
||||
private OrderInfoCustomService orderInfoCustomService;
|
||||
@DubboReference
|
||||
private MemberOrderService memberOrderService;
|
||||
@Resource
|
||||
private MkShopRechargeService shopRechargeService;
|
||||
@DubboReference
|
||||
private ShopUserFlowService userFlowService;
|
||||
@Resource
|
||||
private MkShopCouponRecordService recordService;
|
||||
@Resource
|
||||
private OrderPaymentService paymentService;
|
||||
|
||||
/**
|
||||
* 会员充值 校验
|
||||
*
|
||||
* @return 是否是霸王餐充值
|
||||
*/
|
||||
private boolean checkPayVip(VipPayParamDTO payParam) {
|
||||
if (payParam.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new CzgException("充值金额不正确");
|
||||
}
|
||||
if (payParam.getOrderId() != null) {
|
||||
FreeDineConfig freeConfig = freeConfigService.getById(shopInfoService.getMainIdByShopId(payParam.getShopId()));
|
||||
AssertUtil.isNull(freeConfig, "该店铺未启用霸王餐");
|
||||
if (!freeConfig.getEnable()) {
|
||||
throw new CzgException("该店铺未启用霸王餐");
|
||||
}
|
||||
CheckOrderPay checkOrderPay = payParam.getCheckOrderPay();
|
||||
OrderInfo orderInfo = orderInfoCustomService.checkOrderPay(checkOrderPay.setFreeDine(true).setWithCoupon(freeConfig.getWithCoupon()).setWithPoints(freeConfig.getWithPoints()));
|
||||
payParam.setAmount(orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(freeConfig.getRechargeTimes())));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Object> cashPayVip(VipPayParamDTO payParam) {
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
ShopInfo shopInfo = shopInfoService.getById(payParam.getShopId());
|
||||
AssertUtil.isNull(shopInfo, "店铺不存在");
|
||||
if (shopInfo.getIsMemberInPwd().equals(1)) {
|
||||
AssertUtil.isBlank(shopInfo.getOperationPwd(), "请设置操作密码后使用");
|
||||
AssertUtil.isBlank(payParam.getPwd(), "请输入操作密码后充值");
|
||||
if (!shopInfo.getOperationPwd().equals(SecureUtil.md5(payParam.getPwd()))) {
|
||||
return CzgResult.failure("支付密码错误");
|
||||
}
|
||||
}
|
||||
// if (shopUser.getIsVip().equals(0)) {
|
||||
// //更新会员
|
||||
// ShopUser updateInfo = new ShopUser();
|
||||
// updateInfo.setIsVip(1);
|
||||
// updateInfo.setJoinTime(LocalDateTime.now());
|
||||
// updateInfo.setId(payParam.getShopUserId());
|
||||
// shopUserService.updateById(updateInfo);
|
||||
// }
|
||||
shopRechargeService.recharge(shopUser.getMainShopId(), shopUser.getId(), payParam.getRechargeDetailId(),
|
||||
payParam.getAmount(), null, "cash", ShopUserFlowBizEnum.CASH_IN, true);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Map<String, Object>> jsPayVip(String clintIp, VipPayParamDTO payParam) {
|
||||
boolean isFree = checkPayVip(payParam);
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
|
||||
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
||||
String payOrderNo = payParam.getPlatformType() + CzgRandomUtils.snowflake();
|
||||
String payType = isFree ? PayTypeConstants.SourceType.FREE : PayTypeConstants.SourceType.MEMBER_IN;
|
||||
payService.initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), payType, PayTypeConstants.PayType.PAY, payOrderNo,
|
||||
"", payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId()));
|
||||
return payService.jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, payParam.getAmount().multiply(PayService.MONEY_RATE).longValue(),
|
||||
"会员充值", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CzgResult<Map<String, Object>> ltPayMember(String clientIP, VipMemberPayParamDTO payParam) {
|
||||
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getMainShopId, shopInfoService.getMainIdByShopId(payParam.getShopId())).eq(ShopUser::getId, payParam.getShopUserId()));
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
MemberOrder memberOrder = memberOrderService.createMemberOrder(new MemberOrderDTO().setName(payParam.getName())
|
||||
.setNum(1).setNickName(payParam.getNickName()).setOrderType(payParam.getOrderType())
|
||||
.setPlatformType(payParam.getPlatformType()).setSex(payParam.getSex()).setUserId(shopUser.getUserId())
|
||||
.setShopId(payParam.getShopId()).setBirthDay(payParam.getBirthDay()));
|
||||
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
|
||||
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
||||
|
||||
LtPayOtherDTO payParam1 = new LtPayOtherDTO()
|
||||
.setOpenId(payParam.getOpenId())
|
||||
.setPayType(payParam.getPayType())
|
||||
.setShopId(payParam.getShopId())
|
||||
.setRecordId(shopUser.getId())
|
||||
.setPrice(memberOrder.getAmount())
|
||||
.setIp(clientIP);
|
||||
return payService.ltPayOther(payParam1, PayTypeConstants.SourceType.MEMBER_PAY, "会员充值");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Map<String, Object>> ltPayVip(String clintIp, VipPayParamDTO payParam) {
|
||||
// 霸王餐校验
|
||||
boolean isFree = checkPayVip(payParam);
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
|
||||
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
|
||||
|
||||
MkShopRechargeVO rechargeVO = shopRechargeService.detail(payParam.getShopId());
|
||||
if (payParam.getRechargeDetailId() == null && rechargeVO.getIsCustom() == 0) {
|
||||
throw new CzgException("未开启自定义充值金额");
|
||||
}
|
||||
Long mainShopId = shopInfoService.getMainIdByShopId(payParam.getShopId());
|
||||
if (isFree) {
|
||||
BigDecimal amount = shopRechargeService.checkRecharge(mainShopId, payParam.getShopId(), shopUser.getUserId(), payParam.getRechargeDetailId(), payParam.getAmount());
|
||||
payParam.setAmount(amount);
|
||||
}
|
||||
|
||||
String payType = isFree ? PayTypeConstants.SourceType.FREE : PayTypeConstants.SourceType.MEMBER_IN;
|
||||
LtPayOtherDTO payParam1 = new LtPayOtherDTO()
|
||||
.setOpenId(payParam.getOpenId())
|
||||
.setPayType(payParam.getPayType())
|
||||
.setShopId(payParam.getShopId())
|
||||
.setRecordId(shopUser.getId())
|
||||
.setPrice(payParam.getAmount())
|
||||
.setIp(clintIp);
|
||||
return payService.ltPayOther(payParam1, payType, "会员充值");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgResult<Map<String, Object>> recharge(String clientIP, VipPayParamDTO rechargeDTO, Long shopUserId) {
|
||||
boolean isFree = checkPayVip(rechargeDTO);
|
||||
Long mainShopId = shopInfoService.getMainIdByShopId(rechargeDTO.getShopId());
|
||||
|
||||
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getMainShopId, mainShopId)
|
||||
.eq(ShopUser::getId, shopUserId));
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
MkShopRechargeVO rechargeVO = shopRechargeService.detail(rechargeDTO.getShopId());
|
||||
if (rechargeDTO.getRechargeDetailId() == null && rechargeVO.getIsCustom() == 0) {
|
||||
throw new CzgException("未开启自定义充值金额");
|
||||
}
|
||||
UserInfo userInfo = userInfoService.getById(shopUser.getUserId());
|
||||
BigDecimal amount = shopRechargeService.checkRecharge(mainShopId, rechargeDTO.getShopId(), shopUser.getUserId(), rechargeDTO.getRechargeDetailId(), rechargeDTO.getAmount());
|
||||
String payType = isFree ? PayTypeConstants.SourceType.FREE : PayTypeConstants.SourceType.MEMBER_IN;
|
||||
|
||||
LtPayOtherDTO payParam = new LtPayOtherDTO()
|
||||
.setOpenId("wechatPay".equals(rechargeDTO.getPayType()) ? userInfo.getWechatOpenId() : userInfo.getAlipayOpenId())
|
||||
.setPayType(rechargeDTO.getPayType())
|
||||
.setShopId(rechargeDTO.getShopId())
|
||||
.setRecordId(shopUser.getId())
|
||||
.setPrice(amount)
|
||||
.setIp(clientIP);
|
||||
return payService.ltPayOther(payParam, payType, "会员充值");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Map<String, Object>> scanPayVip(String clintIp, VipPayParamDTO payParam) {
|
||||
boolean isFree = checkPayVip(payParam);
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
String payOrderNo = payParam.getPlatformType() + CzgRandomUtils.snowflake();
|
||||
String payType = isFree ? PayTypeConstants.SourceType.FREE : PayTypeConstants.SourceType.MEMBER_IN;
|
||||
payService.initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), payType, PayTypeConstants.PayType.PAY, payOrderNo,
|
||||
"", payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId()));
|
||||
return payService.scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNo, payParam.getAmount().multiply(PayService.MONEY_RATE).longValue(),
|
||||
"会员充值", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Map<String, Object>> microPayVip(VipPayParamDTO payParam) {
|
||||
boolean isFree = checkPayVip(payParam);
|
||||
AssertUtil.isBlank(payParam.getAuthCode(), "扫描码不能为空");
|
||||
ShopUser shopUser = shopUserService.getById(payParam.getShopUserId());
|
||||
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
|
||||
String payOrderNo = payParam.getPlatformType() + CzgRandomUtils.snowflake();
|
||||
String payType = isFree ? PayTypeConstants.SourceType.FREE : PayTypeConstants.SourceType.MEMBER_IN;
|
||||
payService.initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), payType, PayTypeConstants.PayType.PAY, payOrderNo,
|
||||
payParam.getAuthCode(), payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId()));
|
||||
CzgResult<Map<String, Object>> mapCzgResult = payService.microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, payParam.getAmount().multiply(PayService.MONEY_RATE).longValue(),
|
||||
"会员充值", payParam.getAuthCode(), payParam.getBuyerRemark(), ""));
|
||||
mapCzgResult.setData(Map.of("payOrderNo", payOrderNo));
|
||||
return mapCzgResult;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CzgResult<Map<String, BigDecimal>> refundVipBefore(VipRefundDTO payParam) {
|
||||
Map<String, BigDecimal> resultMap = new HashMap<>(5);
|
||||
ShopUser shopUser = shopUserService.getShopUserInfo(payParam.getShopId(), payParam.getUserId());
|
||||
AssertUtil.isNull(shopUser, "该店铺用户不存在");
|
||||
ShopUserFlow inFlow = userFlowService.getById(payParam.getFlowId());
|
||||
AssertUtil.isNull(inFlow, "充值记录不存在");
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
queryWrapper.eq(ShopUserFlow::getRelationId, payParam.getFlowId());
|
||||
queryWrapper.eq(ShopUserFlow::getBizCode, ShopUserFlowBizEnum.AWARD_IN.getCode());
|
||||
ShopUserFlow giftFlow = userFlowService.getOne(queryWrapper);
|
||||
resultMap.put("amount", shopUser.getAmount());
|
||||
resultMap.put("inAmount", inFlow.getAmount());
|
||||
resultMap.put("inRefundAmount", inFlow.getRefundAmount());
|
||||
resultMap.put("giftAmount", giftFlow == null ? BigDecimal.ZERO : giftFlow.getAmount());
|
||||
resultMap.put("giftRefundAmount", giftFlow == null ? BigDecimal.ZERO : giftFlow.getRefundAmount());
|
||||
return CzgResult.success(resultMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<Object> refundVip(VipRefundDTO refPayParam) {
|
||||
ShopInfo shopInfo = shopInfoService.getById(refPayParam.getShopId());
|
||||
if (shopInfo.getIsReturnPwd().equals(1)) {
|
||||
AssertUtil.isBlank(shopInfo.getOperationPwd(), "请设置操作密码后使用");
|
||||
if (!SecureUtil.md5(refPayParam.getPwd()).equals(shopInfo.getOperationPwd())) {
|
||||
throw new CzgException("操作密码错误");
|
||||
}
|
||||
}
|
||||
ShopUser shopUser = shopUserService.getShopUserInfo(refPayParam.getShopId(), refPayParam.getUserId());
|
||||
ShopUserFlow inFlow = userFlowService.getById(refPayParam.getFlowId());
|
||||
AssertUtil.isNull(inFlow, "充值记录不存在");
|
||||
if ("cashIn".equals(inFlow.getBizCode()) || "adminIn".equals(inFlow.getBizCode())) {
|
||||
refPayParam.setCashRefund(true);
|
||||
}
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
queryWrapper.eq(ShopUserFlow::getRelationId, refPayParam.getFlowId());
|
||||
queryWrapper.eq(ShopUserFlow::getBizCode, ShopUserFlowBizEnum.AWARD_IN.getCode());
|
||||
ShopUserFlow giftFlow = userFlowService.getOne(queryWrapper);
|
||||
if ((inFlow.getAmount().subtract(inFlow.getRefundAmount())).compareTo(refPayParam.getRefAmount()) < 0) {
|
||||
return CzgResult.failure("退款失败,退款金额不可大于可退金额");
|
||||
}
|
||||
//用户余额减去赠送金额 小于 退款金额 则需要勾选 超额退款
|
||||
if (giftFlow != null) {
|
||||
if (shopUser.getAmount().subtract(giftFlow.getAmount().subtract(giftFlow.getRefundAmount())).compareTo(refPayParam.getRefAmount()) < 0 && !refPayParam.isOutOfRange()) {
|
||||
return CzgResult.failure("超额退款,请勾选 超额退款后重试");
|
||||
}
|
||||
} else {
|
||||
if (shopUser.getAmount().compareTo(refPayParam.getRefAmount()) < 0 && !refPayParam.isOutOfRange()) {
|
||||
return CzgResult.failure("超额退款,请勾选 超额退款后重试");
|
||||
}
|
||||
}
|
||||
Long refPaymentId = null;
|
||||
if (!refPayParam.isCashRefund()) {
|
||||
OrderPayment payment;
|
||||
if (inFlow.getRelationId() != null) {
|
||||
payment = paymentService.getById(inFlow.getRelationId());
|
||||
} else {
|
||||
return CzgResult.failure("退款失败,该充值记录不存在");
|
||||
}
|
||||
String refPayOrderNo = "REFVIP" + IdUtil.getSnowflakeNextId();
|
||||
refPaymentId = payService.initOrderPayment(new OrderPayment(refPayParam.getShopId(), shopUser.getId(),
|
||||
PayTypeConstants.SourceType.MEMBER_IN, PayTypeConstants.PayType.REFUND, refPayOrderNo, null, refPayParam.getRefAmount()));
|
||||
CzgResult<CzgRefundResp> refund = payService.refund(refPayParam.getShopId(), new CzgRefundReq(refPayOrderNo, refPayParam.getRemark(),
|
||||
refPayParam.getRefAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), ""));
|
||||
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getState())) {
|
||||
throw new CzgException(refund.getMsg());
|
||||
} else {
|
||||
paymentService.updateChain()
|
||||
.eq(OrderPayment::getId, refPaymentId)
|
||||
.set(OrderPayment::getPayTime, refund.getData().getRefundTime())
|
||||
.set(OrderPayment::getTradeNumber, refund.getData().getRefundOrderId())
|
||||
.set(OrderPayment::getPayStatus, PayTypeConstants.PayStatus.SUCCESS)
|
||||
.set(OrderPayment::getRespJson, JSONObject.toJSONString(refund.getData()))
|
||||
.update();
|
||||
}
|
||||
}
|
||||
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
|
||||
.setId(shopUser.getId())
|
||||
.setMoney(refPayParam.getRefAmount())
|
||||
.setType(0)
|
||||
.setRemark("退款")
|
||||
.setBizEnum(refPayParam.isCashRefund() ? ShopUserFlowBizEnum.RECHARGE_CASH_REFUND : ShopUserFlowBizEnum.RECHARGE_REFUND)
|
||||
.setRelationId(refPaymentId)
|
||||
.setRechargeId(inFlow.getId());
|
||||
//更新会员余额 并生成流水
|
||||
shopUserService.updateMoney(shopUserMoneyEditDTO);
|
||||
userFlowService.updateRefund(inFlow.getId(), refPayParam.getRefAmount());
|
||||
if (giftFlow != null && (giftFlow.getAmount().subtract(giftFlow.getRefundAmount())).compareTo(BigDecimal.ZERO) > 0) {
|
||||
ShopUserMoneyEditDTO giftFlowEdit = new ShopUserMoneyEditDTO()
|
||||
.setId(shopUser.getId())
|
||||
.setMoney(giftFlow.getAmount())
|
||||
.setType(0)
|
||||
.setRemark("退款")
|
||||
.setBizEnum(ShopUserFlowBizEnum.RECHARGE_REFUND)
|
||||
.setRelationId(refPaymentId)
|
||||
.setRechargeId(giftFlow.getId());
|
||||
//更新会员余额 并生成流水
|
||||
shopUserService.updateMoney(giftFlowEdit);
|
||||
userFlowService.updateRefund(giftFlow.getId(), giftFlow.getAmount());
|
||||
}
|
||||
//移除优惠券
|
||||
recordService.remove(QueryWrapper.create()
|
||||
.eq(MkShopCouponRecord::getSourceFlowId, inFlow.getId())
|
||||
.eq(MkShopCouponRecord::getSource, "activate")
|
||||
.eq(MkShopCouponRecord::getStatus, 0));
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user