Merge remote-tracking branch 'origin/master'

This commit is contained in:
Tankaikai 2025-02-28 15:48:05 +08:00
commit 5490169414
8 changed files with 159 additions and 17 deletions

View File

@ -1,15 +1,25 @@
package com.czg.controller;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import com.czg.order.dto.CheckOrderPay;
import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderInfoService;
import com.czg.resp.CzgResult;
import com.czg.service.order.dto.OrderPayParamDTO;
import com.czg.service.order.service.PayService;
import com.czg.system.enums.SysParamCodeEnum;
import com.czg.system.service.SysParamsService;
import com.czg.utils.AssertUtil;
import com.czg.utils.ServletUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
/**
@ -23,6 +33,10 @@ import java.util.Map;
public class OrderPayController {
@Resource
private PayService payService;
@Resource
private OrderInfoService orderService;
@DubboReference
private SysParamsService paramsService;
@PostMapping("/creditPay")
public CzgResult<Object> creditPayOrder(@RequestHeader Long shopId, @Validated @RequestBody OrderPayParamDTO payParam) {
@ -102,4 +116,44 @@ public class OrderPayController {
payParam.setShopId(shopId);
return payService.microPayOrder(payParam);
}
/**
* 获取店铺订单支付URL
*/
@PostMapping("/shopPayApi/orderPayUrl")
public CzgResult<String> getOrderPayUrl(Long shopId, Long orderId, @RequestParam(required = false) String extend,
@RequestParam(required = false) CheckOrderPay checkOrderPay) {
AssertUtil.isNull(shopId, "店铺id不能为空");
AssertUtil.isNull(orderId, "订单Id不能为空");
Map<String, Object> map = new HashMap<>();
map.put("shopId", shopId);
map.put("orderId", orderId);
map.put("payAmount", checkOrderPay.getOrderAmount());
map.put("extend", StrUtil.isEmpty(extend) ? "" : extend);
if (checkOrderPay.getOrderId() != null) {
OrderInfo orderInfo = orderService.checkOrderPay(checkOrderPay);
map.put("payAmount", orderInfo.getOrderAmount());
}
String baseUrl = paramsService.getSysParamValue(SysParamCodeEnum.SHOP_ORDER_PAY_BASE_URL.getCode());
String buildUrl = URLUtil.buildQuery(map, Charset.defaultCharset());
String fullUrl = baseUrl.concat("?").concat(buildUrl);
return CzgResult.success(fullUrl);
}
/**
* payType 必填 支付方式aliPay 支付宝wechatPay 微信
* openId 必填
* checkOrderPay.orderAmount 必填
*/
@PostMapping("/shopPayApi/js2Pay")
public CzgResult<Map<String, Object>> js2PayOrder(@RequestHeader Long shopId, HttpServletRequest request, @RequestBody OrderPayParamDTO payParam) {
payParam.setShopId(shopId);
return payService.js2PayOrder(ServletUtil.getClientIPByHeader(request), payParam);
}
@GetMapping("/queryOrderPay")
public CzgResult<Map<String, Object>> queryOrderPay(Long orderId){
return payService.queryPayOrder(orderId);
}
}

View File

@ -79,6 +79,8 @@ public class CheckOrderPay implements Serializable {
*/
private Integer pointsNum;
private String remark;
public Integer getSeatNum() {
return seatNum == null ? 0 : seatNum;

View File

@ -25,7 +25,9 @@ import java.time.LocalDateTime;
public interface OrderInfoService extends IService<OrderInfo> {
Page<OrderInfoVo> getOrderByPage(OrderInfoQueryDTO param);
HistoryOrderVo historyOrder(Long orderId,String tableCode);
HistoryOrderVo historyOrder(Long orderId, String tableCode);
OrderInfo createOrder(OrderInfoAddDTO param);
OrderInfo checkOrderPay(CheckOrderPay param);
@ -37,4 +39,9 @@ public interface OrderInfoService extends IService<OrderInfo> {
void upOrderInfo(OrderInfo orderInfo, BigDecimal payAmount, LocalDateTime payTime, Long payOrderId, PayEnums payType);
void expired(Long orderId);
OrderInfo createPayOrder(Long shopId, BigDecimal amount, String remark);
}

View File

@ -9,6 +9,7 @@ import lombok.Getter;
@Getter
public enum SysParamCodeEnum {
SHOP_ORDER_PAY_BASE_URL("shop_order_pay_base_url", "店铺订单支付BaseUrl"),
PAY_CZG_DOMAIN("pay_czg_domain", "超掌柜支付域名"),
PAY_CZG_NOTIFY_URL("pay_czg_notify_url", "超掌柜支付回调地址"),
PAY_CZG_REFUND_NOTIFY_URL("pay_czg_refund_notify_url", "超掌柜退款回调地址"),

View File

@ -41,14 +41,21 @@ public interface SysParamsService extends IService<SysParams> {
/**
* 根据参数编码获取参数
* {@link com.czg.system.enums.SysParamCodeEnum}
*
* @param code 参数编码
* @return 参数
*/
CzgResult<SysParamsDTO> getParamsByCode(String code);
/**
* {@link com.czg.system.enums.SysParamCodeEnum}
*/
SysParams getSysParam(String code);
/**
* {@link com.czg.system.enums.SysParamCodeEnum}
*/
String getSysParamValue(String code);
/**

View File

@ -7,6 +7,7 @@ import com.czg.resp.CzgResult;
import com.czg.service.order.dto.OrderPayParamDTO;
import com.czg.service.order.dto.VipPayParamDTO;
import com.czg.service.order.dto.VipRefundDTO;
import lombok.NonNull;
import java.math.BigDecimal;
import java.util.Map;
@ -43,6 +44,8 @@ public interface PayService {
*/
CzgResult<Map<String, Object>> jsPayOrder(String clintIp, OrderPayParamDTO payParam);
CzgResult<Map<String, Object>> js2PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam);
/**
* 小程序支付
*/
@ -102,6 +105,8 @@ public interface PayService {
CzgResult<Object> refundOrder(Long shopId, Long orderId, Long payOrderId, String refPayOrderNo, String refundReason, BigDecimal refundAmount);
CzgResult<Map<String, Object>> queryPayOrder(@NonNull Long orderId);
/**
* 支付查询
*

View File

@ -71,6 +71,10 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
private OrderPaymentService paymentService;
@Resource
private CashierCartService cartService;
@Resource
private RedisService redisService;
@Resource
private RabbitPublisher rabbitPublisher;
@DubboReference
private ShopInfoService shopInfoService;
@DubboReference
@ -89,10 +93,6 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
private ShopCouponService couponService;
@DubboReference
private ShopActivateCouponRecordService couponRecordService;
@Resource
private RedisService redisService;
@Resource
private RabbitPublisher rabbitPublisher;
@Override
public Page<OrderInfoVo> getOrderByPage(OrderInfoQueryDTO param) {
@ -115,7 +115,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
.eq(OrderInfo::getOrderNo, CzgStrUtils.getStrOrNull(param.getOrderNo()))
.gt(OrderInfo::getCreateTime, CzgStrUtils.getStrOrNull(param.getStartTime()))
.le(OrderInfo::getCreateTime, CzgStrUtils.getStrOrNull(param.getEndTime()))
.in(OrderInfo::getId, like);
.in(OrderInfo::getId, like)
.orderBy(OrderInfo::getId).desc();
Page<OrderInfoVo> orderInfoVoPage = pageAs(PageUtil.buildPage(), queryWrapper, OrderInfoVo.class);
orderInfoVoPage.getRecords().parallelStream().forEach(s -> {
List<OrderDetailSmallVO> orderDetails = orderDetailService.queryChain().select()
@ -132,8 +133,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if (orderId == null && StrUtil.isBlank(tableCode)) {
throw new ValidateException("订单id或台桌码不可为空");
}
HistoryOrderVo historyOrderVo = new HistoryOrderVo();
// OrderInfo orderInfo;
HistoryOrderVo historyOrderVo;
if (orderId == null) {
historyOrderVo = queryChain()
.select()
@ -197,11 +197,11 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
List<OrderDetail> orderDetails = cartService.getCartByTableCode(param.getTableCode(), param.isVipPrice() ? 1 : 0, param.getPlaceNum());
log.info("下单1 {}", JSONObject.toJSONString(orderDetails));
//总打包费
BigDecimal packAmount = BigDecimal.ZERO;
BigDecimalDTO packAmount = new BigDecimalDTO(BigDecimal.ZERO);
//总商品支付金额 不包含打包费 用来计算后续
BigDecimal totalAmount = processOrderDetails(orderDetails, packAmount);
log.info("下单2 总金额{} {}", totalAmount, JSONObject.toJSONString(orderDetails));
if (packAmount.compareTo(param.getPackFee()) != 0) {
if (packAmount.getPrice().compareTo(param.getPackFee()) != 0) {
throw new ValidateException("生成订单失败,打包费不正确");
}
log.info("下单3 打包费{} 金额{}", param.getPackFee(), param.getOriginAmount());
@ -337,11 +337,11 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
* @param orderDetails 订单详情 需要回填
* @param packAmount 打包费
*/
private BigDecimal processOrderDetails(List<OrderDetail> orderDetails, BigDecimal packAmount) {
private BigDecimal processOrderDetails(List<OrderDetail> orderDetails, BigDecimalDTO packAmount) {
BigDecimal totalAmount = BigDecimal.ZERO;
for (OrderDetail detail : orderDetails) {
if (detail.getPackNumber().compareTo(BigDecimal.ZERO) > 0 && detail.getPackAmount().compareTo(BigDecimal.ZERO) > 0) {
packAmount = packAmount.add(detail.getPackAmount().multiply(detail.getPackNumber()));
packAmount.setPrice(packAmount.getPrice().add(detail.getPackAmount().multiply(detail.getPackNumber())));
}
detail.setPayAmount(detail.getNum().multiply(detail.getPrice()));
totalAmount = totalAmount.add(detail.getPayAmount());
@ -564,6 +564,32 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
}
}
/**
* 支付使用的空订单
*/
@Override
public OrderInfo createPayOrder(Long shopId, BigDecimal amount, String remark) {
ShopInfo shopInfo = shopInfoService.getById(shopId);
OrderInfoAddDTO param = new OrderInfoAddDTO();
param.setShopId(shopInfo.getId());
param.setUserId(0L);
param.setStaffId(0L);
param.setSeatNum(0);
param.setOriginAmount(amount);
param.setTableCode("");
param.setOrderType("cash");
param.setPlatformType("H5");
param.setPayMode("no-table");
param.setDineMode("dine-in");
param.setRemark(remark);
param.setPlaceNum(1);
param.setCreditBuyerId(null);
param.setWaitCall(false);
param.setVipPrice(false);
param.setPackFee(BigDecimal.ZERO);
return initOrderInfo(param, shopInfo, null);
}
/**
* 初始化订单信息
*/
@ -627,7 +653,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderInfo.setFullCouponDiscountAmount(param.getFullCouponDiscountAmount());
orderInfo.setDiscountAmount(param.getDiscountAmount());
//优惠券
orderInfo.setCouponInfoList(JSONObject.toJSONString(param.getCouponList()));
orderInfo.setCouponInfoList(CollUtil.isEmpty(param.getCouponList()) ? "" : JSONObject.toJSONString(param.getCouponList()));
//折扣信息
orderInfo.setDiscountInfo(buildDiscountInfo(orderInfo));
//最终折扣

View File

@ -185,6 +185,26 @@ public class PayServiceImpl implements PayService {
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
}
@Override
@Transactional
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) {
orderInfo = orderInfoService.createPayOrder(payParam.getShopId(), payParam.getCheckOrderPay().getOrderAmount(),
payParam.getCheckOrderPay().getRemark());
}else {
orderInfo = orderInfoService.getById(payParam.getCheckOrderPay().getOrderId());
}
String payOrderNo = orderInfo.getPlatformType() + IdUtil.getSnowflakeNextId();
Long paymentId = initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
"order", payOrderNo, "", orderInfo.getOrderAmount()));
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId);
return jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(MONEY_RATE).longValue(),
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
}
@Override
@Transactional
public CzgResult<Map<String, Object>> ltPayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
@ -469,8 +489,8 @@ public class PayServiceImpl implements PayService {
throw new ValidateException("退单失败,可退金额不足");
}
//非现金退款
if(!param.isCash()){
if(orderInfo.getPayType().equals(PayEnums.VIP_PAY.getValue())){
if (!param.isCash()) {
if (orderInfo.getPayType().equals(PayEnums.VIP_PAY.getValue())) {
ShopUser shopUser = shopUserService.getShopUserInfo(orderInfo.getShopId(), orderInfo.getUserId());
//会员支付 退钱
ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder()
@ -480,8 +500,8 @@ public class PayServiceImpl implements PayService {
.relationId(orderInfo.getId())
.bizEnum(ShopUserFlowBizEnum.ORDER_REFUND)
.build();
shopUserService.updateMoney(orderInfo.getShopId(),shopUserMoneyEditDTO);
}else {
shopUserService.updateMoney(orderInfo.getShopId(), shopUserMoneyEditDTO);
} else {
//退款 param.getRefundAmount()
refundOrder(orderInfo.getShopId(), orderInfo.getId(), orderInfo.getPayOrderId(),
refPayOrderNo, param.getRefundReason(), param.getRefundAmount());
@ -522,6 +542,26 @@ public class PayServiceImpl implements PayService {
return CzgResult.success();
}
@Override
@Transactional
public CzgResult<Map<String, Object>> queryPayOrder(@NonNull Long orderId) {
OrderInfo orderInfo = orderInfoService.getById(orderId);
AssertUtil.isNull(orderInfo, "订单不存在");
OrderPayment payment = paymentService.getById(orderInfo.getPayOrderId());
AssertUtil.isNull(payment, "订单不存在");
CzgResult<CzgBaseResp> res = queryPayOrder(orderInfo.getShopId(), payment.getOrderNo(), null);
CzgResult<Map<String, Object>> result = CzgResult.success();
if (res.getCode() != 200 || res.getData() == null) {
result.setCode(500);
result.setMsg(res.getMsg());
return result;
}
Map<String, Object> map = new HashMap<>();
map.put("payOrderId", payment.getOrderNo());
result.setData(map);
return result;
}
@Override
@Transactional
public CzgResult<CzgBaseResp> queryPayOrder(@NonNull Long shopId, String payOrderId, String mchOrderNo) {