优惠券重构
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.czg.service.order.mapper;
|
||||
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.order.entity.CashierCart;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 购物车 映射层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-20
|
||||
*/
|
||||
public interface CashierCartMapper extends BaseMapper<CashierCart> {
|
||||
|
||||
|
||||
List<OrderDetail> getCartByTableCode(String tableCode);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.order.entity.CashierCart;
|
||||
import com.czg.order.service.CashierCartService;
|
||||
import com.czg.service.order.mapper.CashierCartMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 购物车 服务层实现。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-02-20
|
||||
*/
|
||||
@Service
|
||||
public class CashierCartServiceImpl extends ServiceImpl<CashierCartMapper, CashierCart> implements CashierCartService{
|
||||
|
||||
@Override
|
||||
public List<OrderDetail> getCartByTableCode(String tableCode) {
|
||||
return getMapper().getCartByTableCode(tableCode);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,33 @@
|
||||
package com.czg.service.order.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.exceptions.ValidateException;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
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.account.entity.*;
|
||||
import com.czg.account.service.*;
|
||||
import com.czg.config.RabbitPublisher;
|
||||
import com.czg.entity.notify.CzgPayNotifyDTO;
|
||||
import com.czg.entity.notify.CzgRefundNotifyDTO;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.order.dto.OrderInfoAddDTO;
|
||||
import com.czg.order.dto.OrderInfoQueryDTO;
|
||||
import com.czg.order.entity.OrderDetail;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.enums.PayEnums;
|
||||
import com.czg.order.service.CashierCartService;
|
||||
import com.czg.order.service.OrderDetailService;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.order.vo.OrderDetailSmallVO;
|
||||
import com.czg.order.vo.OrderInfoCreateVo;
|
||||
import com.czg.order.vo.OrderInfoVo;
|
||||
import com.czg.service.order.enums.OrderStatusEnums;
|
||||
import com.czg.service.order.mapper.OrderInfoMapper;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.CzgStrUtils;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
@@ -59,9 +63,21 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
private OrderPaymentService paymentService;
|
||||
@Resource
|
||||
private RabbitPublisher rabbitPublisher;
|
||||
@Resource
|
||||
private CashierCartService cartService;
|
||||
@Resource
|
||||
private OrderDetailService detailService;
|
||||
@DubboReference
|
||||
private ShopTableService shopTableService;
|
||||
@DubboReference
|
||||
private ShopInfoService shopInfoService;
|
||||
@DubboReference
|
||||
private PointsBasicSettingService pointsBasicService;
|
||||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
@DubboReference
|
||||
private UserInfoService userInfoService;
|
||||
@DubboReference
|
||||
private ShopActivateService activateService;
|
||||
|
||||
@Override
|
||||
@@ -97,6 +113,41 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
return orderInfoVoPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderInfoCreateVo createOrder(OrderInfoAddDTO param) {
|
||||
ShopInfo shopInfo = shopInfoService.getById(param.getShopId());
|
||||
AssertUtil.isNull(shopInfo, "生成订单失败,店铺信息不存在");
|
||||
if (shopInfo.getIsTableFee().equals(0) && param.getSeatNum() == 0) {
|
||||
throw new ValidateException("生成订单失败,请选择用餐人数后下单");
|
||||
}
|
||||
if (!shopInfo.getEatModel().contains(param.getEatModel())) {
|
||||
throw new ValidateException("生成订单失败,店铺不支持该用餐模式");
|
||||
}
|
||||
if ("afterPay".equals(param.getPayMode()) && !"restaurant".equals(shopInfo.getRegisterType())) {
|
||||
throw new ValidateException("生成订单失败,该店铺不支持后付费");
|
||||
}
|
||||
if (param.isVipPrice() && !shopInfo.getIsMemberPrice().equals(1)) {
|
||||
throw new ValidateException("生成订单失败,该店铺不支持使用会员价");
|
||||
}
|
||||
PointsBasicSetting pointSetting = pointsBasicService.getById(shopInfo.getId());
|
||||
if (param.getPointsNum().compareTo(BigDecimal.ZERO) > 0 && !pointSetting.getEnableDeduction().equals(1)) {
|
||||
throw new ValidateException("生成订单失败,该店铺未开启积分抵扣");
|
||||
}
|
||||
UserInfo userInfo = userInfoService.getById(param.getUserId());
|
||||
AssertUtil.isNull(userInfo, "生成订单失败,用户信息不存在");
|
||||
ShopUser shopUser = shopUserService.getShopUserInfo(param.getShopId(), param.getUserId());
|
||||
if (!shopUser.getIsVip().equals(1) && pointSetting.getDeductionGroup().contains("vip")) {
|
||||
throw new ValidateException("生成订单失败,该店铺仅会员可使用积分抵扣");
|
||||
}
|
||||
ShopTable table = shopTableService.getOneByTableCode(param.getShopId(), param.getTableCode());
|
||||
AssertUtil.isNull(table, "生成订单失败,桌台信息不存在");
|
||||
|
||||
// List<CashierCart> cashierCarts = cartService.
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void payCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson) {
|
||||
|
||||
@@ -63,7 +63,7 @@ public class PayServiceImpl implements PayService {
|
||||
@DubboReference
|
||||
private ShopUserFlowService userFlowService;
|
||||
@DubboReference
|
||||
private ShopActivateInRecordService inRecordService;
|
||||
private ShopActivateCouponRecordService inRecordService;
|
||||
@Resource
|
||||
private RabbitPublisher rabbitPublisher;
|
||||
@Resource
|
||||
@@ -309,7 +309,7 @@ public class PayServiceImpl implements PayService {
|
||||
.eq(ShopUserFlow::getBizCode, ShopUserFlowBizEnum.AWARD_IN.getCode())
|
||||
.one();
|
||||
resultMap.put("amount", shopUser.getAmount());
|
||||
resultMap.put("inAmount", inFlow.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());
|
||||
@@ -356,34 +356,34 @@ public class PayServiceImpl implements PayService {
|
||||
if (res.getCode() != 200 || res.getData() == null) {
|
||||
return CzgResult.failure(res.getMsg());
|
||||
}
|
||||
} else {
|
||||
ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder()
|
||||
.id(shopUser.getId())
|
||||
.money(refPayParam.getRefAmount())
|
||||
.type(0)
|
||||
.remark("退款")
|
||||
.bizEnum(ShopUserFlowBizEnum.RECHARGE_REFUND)
|
||||
.relationId(refPaymentId)
|
||||
.rechargeId(inFlow.getId())
|
||||
.build();
|
||||
//更新会员余额 并生成流水
|
||||
shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
|
||||
}
|
||||
ShopUserMoneyEditDTO shopUserMoneyEditDTO = ShopUserMoneyEditDTO.builder()
|
||||
.id(shopUser.getId())
|
||||
.money(refPayParam.getRefAmount())
|
||||
.type(0)
|
||||
.remark("退款")
|
||||
.bizEnum(ShopUserFlowBizEnum.RECHARGE_REFUND)
|
||||
.relationId(refPaymentId)
|
||||
.rechargeId(inFlow.getId())
|
||||
.build();
|
||||
//更新会员余额 并生成流水
|
||||
shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
|
||||
|
||||
userFlowService.updateChain()
|
||||
.setRaw(ShopUserFlow::getRefundAmount, "refund_amount" + refPayParam.getRefAmount())
|
||||
.eq(ShopUserFlow::getId, inFlow.getId())
|
||||
.update();
|
||||
if (giftFlow != null) {
|
||||
userFlowService.updateChain()
|
||||
.setRaw(ShopUserFlow::getRefundAmount, "refund_amount" + refPayParam.getRefAmount())
|
||||
.eq(ShopUserFlow::getId, inFlow.getId())
|
||||
.update();
|
||||
if (giftFlow != null) {
|
||||
userFlowService.updateChain()
|
||||
.setRaw(ShopUserFlow::getRefundAmount, "refund_amount" + giftFlow.getAmount())
|
||||
.eq(ShopUserFlow::getId, giftFlow.getId())
|
||||
.update();
|
||||
}
|
||||
inRecordService.updateChain()
|
||||
.set(ShopActivateInRecord::getOverNum, 0)
|
||||
.eq(ShopActivateInRecord::getId, inFlow.getId())
|
||||
.setRaw(ShopUserFlow::getRefundAmount, "refund_amount" + giftFlow.getAmount())
|
||||
.eq(ShopUserFlow::getId, giftFlow.getId())
|
||||
.update();
|
||||
}
|
||||
inRecordService.updateChain()
|
||||
.set(ShopActivateCouponRecord::getStatus, "not_used")
|
||||
.eq(ShopActivateCouponRecord::getSourceFlowId, inFlow.getId())
|
||||
.update();
|
||||
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.order.mapper.CashierCartMapper">
|
||||
|
||||
<select id="getCartByTableCode" resultType="com.czg.order.entity.OrderDetail">
|
||||
select cart.shop_id as shopId,
|
||||
cart.product_id as productId,
|
||||
pros.product_name as productName,
|
||||
cart.sku_id as skuId,
|
||||
skus.spec_info as skuName,
|
||||
cart.number as number,
|
||||
from tb_cashier_cart cart
|
||||
left join tb_product pros on cart.product_id = pros.id
|
||||
left join tb_prod_sku skus on cart.sku_id = skus.id
|
||||
where table_code = #{tableCode}
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user