From e9885f76cbdd4e581a20aca682d15a69a7d7716d Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 30 Oct 2024 14:37:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=9C=B8=E7=8E=8B=E9=A4=90=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=9B=9E=E8=B0=83=E4=BF=AE=E6=94=B9=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=9C=B8=E7=8E=8B=E9=A4=90=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/TableConstant.java | 31 ++++ .../entity/TbFreeDineRecord.java | 166 ++++++++++++++++++ .../mapper/TbFreeDineRecordMapper.java | 18 ++ .../cashierservice/service/PayService.java | 27 ++- .../service/TbFreeDineConfigService.java | 2 + .../service/TbFreeDineRecordService.java | 27 +++ .../impl/TbFreeDineConfigServiceImpl.java | 3 + .../impl/TbFreeDineRecordServiceImpl.java | 37 ++++ .../mapper/TbFreeDineRecordMapper.xml | 31 ++++ 9 files changed, 340 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbFreeDineRecord.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbFreeDineRecordMapper.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/service/TbFreeDineRecordService.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbFreeDineRecordServiceImpl.java create mode 100644 src/main/resources/mapper/TbFreeDineRecordMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/constant/TableConstant.java b/src/main/java/com/chaozhanggui/system/cashierservice/constant/TableConstant.java index 7a79b3d..34717e0 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/constant/TableConstant.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/constant/TableConstant.java @@ -1,5 +1,6 @@ package com.chaozhanggui.system.cashierservice.constant; +import io.netty.handler.codec.http2.Http2FrameStreamEvent; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -49,6 +50,36 @@ public interface TableConstant { } } + class FreeDineRecord { + @Getter + public enum State { + WAIT_PAY(0), + SUCCESS_PAY(1), + FAIL_PAY(2); + private final Integer value; + + State(Integer value) { + this.value = value; + } + } + + @Getter + public enum UseType { + TAKEOUT("takeout"), + DINE_IN_AFTER("dine-in-after"), + DINE_IN_BEFORE("dine-in-before"); + private final String value; + + UseType(String value) { + this.value = value; + } + + public boolean equalsVals(String value) { + return this.value.equals(value); + } + } + } + class ShopInfo { @Getter public enum EatModel { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbFreeDineRecord.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbFreeDineRecord.java new file mode 100644 index 0000000..bd64fc0 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbFreeDineRecord.java @@ -0,0 +1,166 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; +import lombok.Data; + +/** + * 霸王餐充值记录 + * @TableName tb_free_dine_record + */ +@TableName(value ="tb_free_dine_record") +@Data +public class TbFreeDineRecord implements Serializable { + /** + * + */ + @TableId(type = IdType.AUTO) + private Integer id; + + /** + * 0 已选择待消耗 1 已消耗 2 取消支付 + */ + private Integer state; + + /** + * 订单id + */ + private Integer orderId; + + /** + * 订单金额 + */ + private BigDecimal orderAmount; + + /** + * 充值金额 + */ + private BigDecimal rechargeAmount; + + /** + * 最终支付金额 + */ + private BigDecimal payAmount; + + /** + * 用户id + */ + private Integer userId; + + /** + * 会员id + */ + private Integer vipUserId; + + /** + * 店铺id + */ + private Integer shopId; + + /** + * 使用的优惠券信息 + */ + private String couponInfo; + + /** + * 使用的积分信息 + */ + private Integer pointsNum; + + /** + * 充值倍率 + */ + private Integer rechargeTimes; + + /** + * + */ + private BigDecimal rechargeThreshold; + + /** + * 创建时间 + */ + private Date createTime; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + TbFreeDineRecord other = (TbFreeDineRecord) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState())) + && (this.getOrderId() == null ? other.getOrderId() == null : this.getOrderId().equals(other.getOrderId())) + && (this.getOrderAmount() == null ? other.getOrderAmount() == null : this.getOrderAmount().equals(other.getOrderAmount())) + && (this.getRechargeAmount() == null ? other.getRechargeAmount() == null : this.getRechargeAmount().equals(other.getRechargeAmount())) + && (this.getPayAmount() == null ? other.getPayAmount() == null : this.getPayAmount().equals(other.getPayAmount())) + && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) + && (this.getVipUserId() == null ? other.getVipUserId() == null : this.getVipUserId().equals(other.getVipUserId())) + && (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId())) + && (this.getCouponInfo() == null ? other.getCouponInfo() == null : this.getCouponInfo().equals(other.getCouponInfo())) + && (this.getPointsNum() == null ? other.getPointsNum() == null : this.getPointsNum().equals(other.getPointsNum())) + && (this.getRechargeTimes() == null ? other.getRechargeTimes() == null : this.getRechargeTimes().equals(other.getRechargeTimes())) + && (this.getRechargeThreshold() == null ? other.getRechargeThreshold() == null : this.getRechargeThreshold().equals(other.getRechargeThreshold())) + && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getState() == null) ? 0 : getState().hashCode()); + result = prime * result + ((getOrderId() == null) ? 0 : getOrderId().hashCode()); + result = prime * result + ((getOrderAmount() == null) ? 0 : getOrderAmount().hashCode()); + result = prime * result + ((getRechargeAmount() == null) ? 0 : getRechargeAmount().hashCode()); + result = prime * result + ((getPayAmount() == null) ? 0 : getPayAmount().hashCode()); + result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); + result = prime * result + ((getVipUserId() == null) ? 0 : getVipUserId().hashCode()); + result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode()); + result = prime * result + ((getCouponInfo() == null) ? 0 : getCouponInfo().hashCode()); + result = prime * result + ((getPointsNum() == null) ? 0 : getPointsNum().hashCode()); + result = prime * result + ((getRechargeTimes() == null) ? 0 : getRechargeTimes().hashCode()); + result = prime * result + ((getRechargeThreshold() == null) ? 0 : getRechargeThreshold().hashCode()); + result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", state=").append(state); + sb.append(", orderId=").append(orderId); + sb.append(", orderAmount=").append(orderAmount); + sb.append(", rechargeAmount=").append(rechargeAmount); + sb.append(", payAmount=").append(payAmount); + sb.append(", userId=").append(userId); + sb.append(", vipUserId=").append(vipUserId); + sb.append(", shopId=").append(shopId); + sb.append(", couponInfo=").append(couponInfo); + sb.append(", pointsNum=").append(pointsNum); + sb.append(", rechargeTimes=").append(rechargeTimes); + sb.append(", rechargeThreshold=").append(rechargeThreshold); + sb.append(", createTime=").append(createTime); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbFreeDineRecordMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbFreeDineRecordMapper.java new file mode 100644 index 0000000..a411afa --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbFreeDineRecordMapper.java @@ -0,0 +1,18 @@ +package com.chaozhanggui.system.cashierservice.mapper; + +import com.chaozhanggui.system.cashierservice.entity.TbFreeDineRecord; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author Administrator +* @description 针对表【tb_free_dine_record(霸王餐充值记录)】的数据库操作Mapper +* @createDate 2024-10-30 09:48:31 +* @Entity com.chaozhanggui.system.cashierservice.entity.TbFreeDineRecord +*/ +public interface TbFreeDineRecordMapper extends BaseMapper { + +} + + + + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 20db318..1662b7b 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -199,13 +199,17 @@ public class PayService { private TbShopCouponMapper tbShopCouponMapper; @Autowired private MpShopCouponMapper mpShopCouponMapper; + @Autowired + private TbFreeDineRecordMapper tbFreeDineRecordMapper; + private final TbFreeDineRecordService freeDineRecordService; - public PayService(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService, MpShopTableService mpShopTableService, TbFreeDineConfigService freeDineConfigService, TbShopCouponService shopCouponService, MpMemberInMapper mpMemberInMapper) { + public PayService(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService, MpShopTableService mpShopTableService, TbFreeDineConfigService freeDineConfigService, TbShopCouponService shopCouponService, MpMemberInMapper mpMemberInMapper, TbFreeDineRecordService freeDineRecordService) { this.shopSongOrderService = shopSongOrderService; this.mpShopTableService = mpShopTableService; this.freeDineConfigService = freeDineConfigService; this.shopCouponService = shopCouponService; this.mpMemberInMapper = mpMemberInMapper; + this.freeDineRecordService = freeDineRecordService; } @Transactional(rollbackFor = Exception.class) @@ -411,6 +415,13 @@ public class PayService { } BigDecimal shouldPayAmount = orderInfo.getOriginAmount().multiply(BigDecimal.valueOf(freeDineConfig.getRechargeTimes())); + TbFreeDineRecord record = tbFreeDineRecordMapper.selectOne(new LambdaQueryWrapper().eq(TbFreeDineRecord::getOrderId, orderInfo.getId())); + if (record == null) { + record = new TbFreeDineRecord(); + } + record.setState(TableConstant.FreeDineRecord.State.WAIT_PAY.getValue()); + record.setOrderId(orderInfo.getId()); + record.setOrderAmount(orderInfo.getOrderAmount()); if (!payDTO.getUserCouponIds().isEmpty()) { List userCouponList = shopCouponService.getActivateCouponByAmount(Integer.valueOf(orderInfo.getShopId()), String.valueOf(payDTO.getUserId()), shouldPayAmount); if (userCouponList.isEmpty()) { @@ -440,12 +451,20 @@ public class PayService { // 设置优惠券信息 orderInfo.setActivateInInfoList(JSONObject.toJSONString(activateInInfoVOS)); orderInfo.setUserCouponAmount(BigDecimal.valueOf(tbShopCoupons.stream().map(TbShopCoupon::getDiscountAmount).reduce(0, Integer::sum))); + record.setCouponInfo(JSONObject.toJSONString(userCouponList)); } // TODO 霸王餐积分 if (payDTO.isUsePoints()) { } + record.setRechargeAmount(shouldPayAmount); + record.setVipUserId(payDTO.getUserId()); + record.setShopId(Integer.valueOf(orderInfo.getShopId())); + record.setRechargeTimes(freeDineConfig.getRechargeTimes()); + record.setRechargeThreshold(freeDineConfig.getRechargeThreshold()); + record.setCreateTime(DateUtil.date()); + mpOrderInfoMapper.updateById(orderInfo); return shouldPayAmount; } @@ -1544,7 +1563,7 @@ public class PayService { ArrayList activateOutRecords = new ArrayList<>(); JSONArray activateInfoList = JSONObject.parseArray(orderInfo.getActivateInInfoList()); activateInfoList.forEach(item -> { - ActivateInInfoVO infoVO = (ActivateInInfoVO) item; + ActivateInInfoVO infoVO = ((JSONObject)item).toJavaObject(ActivateInInfoVO.class); TbActivateOutRecord tbActivateOutRecord = new TbActivateOutRecord(); tbActivateOutRecord.setShopId(shopId); tbActivateOutRecord.setGiveId(infoVO.getId()); @@ -1559,6 +1578,10 @@ public class PayService { } // 更改订单状态 orderSuccessPay(orderInfo, payType, payOrderNo); + + // 更改霸王餐记录 +// TbFreeDineRecord freeDineRecord = freeDineRecordService.selectByOrderId(orderInfo.getId()); + freeDineRecordService.updateStateByOrderId(TableConstant.FreeDineRecord.State.SUCCESS_PAY, orderInfo.getId()); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbFreeDineConfigService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbFreeDineConfigService.java index 906dd53..a56498e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbFreeDineConfigService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbFreeDineConfigService.java @@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.service; import com.chaozhanggui.system.cashierservice.entity.TbFreeDineConfig; import com.baomidou.mybatisplus.extension.service.IService; +import com.chaozhanggui.system.cashierservice.entity.TbFreeDineRecord; /** * @author Administrator @@ -16,4 +17,5 @@ public interface TbFreeDineConfigService extends IService { * @return 霸王餐配置 */ TbFreeDineConfig getByShopId(String shopId); + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbFreeDineRecordService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbFreeDineRecordService.java new file mode 100644 index 0000000..551ff41 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbFreeDineRecordService.java @@ -0,0 +1,27 @@ +package com.chaozhanggui.system.cashierservice.service; + +import com.chaozhanggui.system.cashierservice.constant.TableConstant; +import com.chaozhanggui.system.cashierservice.entity.TbFreeDineRecord; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author Administrator +* @description 针对表【tb_free_dine_record(霸王餐充值记录)】的数据库操作Service +* @createDate 2024-10-30 09:48:31 +*/ +public interface TbFreeDineRecordService extends IService { + + + /** + * 根据订单id获取霸王餐记录 + * @param orderId 订单id + */ + TbFreeDineRecord selectByOrderId(Integer orderId); + + /** + * 根据订单id修改霸王餐记录 + * @param state 状态 + * @param orderId 订单id + */ + boolean updateStateByOrderId(TableConstant.FreeDineRecord.State state, Integer orderId); +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbFreeDineConfigServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbFreeDineConfigServiceImpl.java index e9853fe..cc6840f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbFreeDineConfigServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbFreeDineConfigServiceImpl.java @@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.chaozhanggui.system.cashierservice.entity.TbFreeDineConfig; +import com.chaozhanggui.system.cashierservice.entity.TbFreeDineRecord; import com.chaozhanggui.system.cashierservice.service.TbFreeDineConfigService; import com.chaozhanggui.system.cashierservice.mapper.TbFreeDineConfigMapper; import org.springframework.context.annotation.Primary; @@ -23,6 +24,8 @@ public class TbFreeDineConfigServiceImpl extends ServiceImpl() .eq(TbFreeDineConfig::getShopId, shopId)); } + + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbFreeDineRecordServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbFreeDineRecordServiceImpl.java new file mode 100644 index 0000000..043cec2 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbFreeDineRecordServiceImpl.java @@ -0,0 +1,37 @@ +package com.chaozhanggui.system.cashierservice.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.chaozhanggui.system.cashierservice.constant.TableConstant; +import com.chaozhanggui.system.cashierservice.entity.TbFreeDineRecord; +import com.chaozhanggui.system.cashierservice.service.TbFreeDineRecordService; +import com.chaozhanggui.system.cashierservice.mapper.TbFreeDineRecordMapper; +import org.springframework.stereotype.Service; + +/** +* @author Administrator +* @description 针对表【tb_free_dine_record(霸王餐充值记录)】的数据库操作Service实现 +* @createDate 2024-10-30 09:48:31 +*/ +@Service +public class TbFreeDineRecordServiceImpl extends ServiceImpl + implements TbFreeDineRecordService{ + + @Override + public TbFreeDineRecord selectByOrderId(Integer orderId) { + return getOne(new LambdaQueryWrapper() + .eq(TbFreeDineRecord::getOrderId, orderId)); + } + + @Override + public boolean updateStateByOrderId(TableConstant.FreeDineRecord.State state, Integer orderId) { + return update(new LambdaUpdateWrapper() + .eq(TbFreeDineRecord::getOrderId, orderId) + .set(TbFreeDineRecord::getState, state.getValue())); + } +} + + + + diff --git a/src/main/resources/mapper/TbFreeDineRecordMapper.xml b/src/main/resources/mapper/TbFreeDineRecordMapper.xml new file mode 100644 index 0000000..07ebb46 --- /dev/null +++ b/src/main/resources/mapper/TbFreeDineRecordMapper.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + id,state,order_id, + order_amount,recharge_amount,pay_amount, + user_id,vip_user_id,shop_id, + coupon_info,points_num,recharge_times, + recharge_threshold,create_time + +