fix: 霸王餐支付回调修改 增加霸王餐记录

This commit is contained in:
2024-10-30 14:37:29 +08:00
parent 9055607154
commit e9885f76cb
9 changed files with 340 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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();
}
}

View File

@@ -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<TbFreeDineRecord> {
}

View File

@@ -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<TbFreeDineRecord>().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<TbUserCouponVo> 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<TbActivateOutRecord> 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());
}
}

View File

@@ -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<TbFreeDineConfig> {
* @return 霸王餐配置
*/
TbFreeDineConfig getByShopId(String shopId);
}

View File

@@ -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<TbFreeDineRecord> {
/**
* 根据订单id获取霸王餐记录
* @param orderId 订单id
*/
TbFreeDineRecord selectByOrderId(Integer orderId);
/**
* 根据订单id修改霸王餐记录
* @param state 状态
* @param orderId 订单id
*/
boolean updateStateByOrderId(TableConstant.FreeDineRecord.State state, Integer orderId);
}

View File

@@ -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<TbFreeDineConfigMap
return getOne(new LambdaQueryWrapper<TbFreeDineConfig>()
.eq(TbFreeDineConfig::getShopId, shopId));
}
}

View File

@@ -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<TbFreeDineRecordMapper, TbFreeDineRecord>
implements TbFreeDineRecordService{
@Override
public TbFreeDineRecord selectByOrderId(Integer orderId) {
return getOne(new LambdaQueryWrapper<TbFreeDineRecord>()
.eq(TbFreeDineRecord::getOrderId, orderId));
}
@Override
public boolean updateStateByOrderId(TableConstant.FreeDineRecord.State state, Integer orderId) {
return update(new LambdaUpdateWrapper<TbFreeDineRecord>()
.eq(TbFreeDineRecord::getOrderId, orderId)
.set(TbFreeDineRecord::getState, state.getValue()));
}
}

View File

@@ -0,0 +1,31 @@
<?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.chaozhanggui.system.cashierservice.mapper.TbFreeDineRecordMapper">
<resultMap id="BaseResultMap" type="com.chaozhanggui.system.cashierservice.entity.TbFreeDineRecord">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="state" column="state" jdbcType="INTEGER"/>
<result property="orderId" column="order_id" jdbcType="INTEGER"/>
<result property="orderAmount" column="order_amount" jdbcType="DECIMAL"/>
<result property="rechargeAmount" column="recharge_amount" jdbcType="DECIMAL"/>
<result property="payAmount" column="pay_amount" jdbcType="DECIMAL"/>
<result property="userId" column="user_id" jdbcType="INTEGER"/>
<result property="vipUserId" column="vip_user_id" jdbcType="INTEGER"/>
<result property="shopId" column="shop_id" jdbcType="INTEGER"/>
<result property="couponInfo" column="coupon_info" jdbcType="VARCHAR"/>
<result property="pointsNum" column="points_num" jdbcType="INTEGER"/>
<result property="rechargeTimes" column="recharge_times" jdbcType="INTEGER"/>
<result property="rechargeThreshold" column="recharge_threshold" jdbcType="DECIMAL"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
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
</sql>
</mapper>