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

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