霸王餐相关接口

This commit is contained in:
2024-10-26 14:26:20 +08:00
parent 3573f6a0d6
commit ca28f90260
8 changed files with 155 additions and 123 deletions

View File

@@ -12,6 +12,7 @@ import com.chaozhanggui.system.cashierservice.constant.TableConstant;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.Enum.OrderUseTypeEnum;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.MemberInDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.OrderPayDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
@@ -21,6 +22,7 @@ import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.mapper.MpCashierCartMapper;
import com.chaozhanggui.system.cashierservice.mapper.MpOrderDetailMapper;
import com.chaozhanggui.system.cashierservice.mapper.MpOrderInfoMapper;
import com.chaozhanggui.system.cashierservice.mapper.MpShopCouponMapper;
import com.chaozhanggui.system.cashierservice.model.PayReq;
import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
import com.chaozhanggui.system.cashierservice.mpservice.MpShopTableService;
@@ -190,6 +192,13 @@ public class PayService {
private final MpShopTableService mpShopTableService;
private final TbFreeDineConfigService freeDineConfigService;
private final TbShopCouponService shopCouponService;
@Qualifier("tbShopCouponService")
@Autowired
private TbShopCouponService tbShopCouponService;
@Autowired
private TbShopCouponMapper tbShopCouponMapper;
@Autowired
private MpShopCouponMapper mpShopCouponMapper;
public PayService(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService, MpShopTableService mpShopTableService, TbFreeDineConfigService freeDineConfigService, TbShopCouponService shopCouponService) {
this.shopSongOrderService = shopSongOrderService;
@@ -367,7 +376,14 @@ public class PayService {
throw new MsgException("支付失败");
}
private void freeDinePay(OrderPayDTO payDTO, String productName, TbOrderInfo orderInfo, TbMerchantThirdApply thirdApply, String userId) {
private BigDecimal getFreeDineOrderInfo(MemberInDTO payDTO) {
TbOrderInfo orderInfo = mpOrderInfoMapper.selectOne(new LambdaQueryWrapper<TbOrderInfo>()
.eq(TbOrderInfo::getId, payDTO.getOrderId())
.in(TbOrderInfo::getStatus, TableConstant.OrderInfo.Status.UNPAID.getValue(), TableConstant.OrderInfo.Status.PAYING.getValue()));
if (orderInfo == null) {
throw new MsgException("订单不存在或不处于待支付状态");
}
// 获取店铺霸王餐配置
TbFreeDineConfig freeDineConfig = freeDineConfigService.getById(orderInfo.getShopId());
if (freeDineConfig == null || freeDineConfig.getEnable() == null || freeDineConfig.getEnable() == 0) {
@@ -380,7 +396,7 @@ public class PayService {
}
// 校验优惠券积分同享
if (payDTO.getCouponId() != null && freeDineConfig.getWithCoupon() == 0) {
if (!payDTO.getCouponIds().isEmpty() && freeDineConfig.getWithCoupon() == 0) {
throw new MsgException("当前店铺未开启与优惠券同享");
}
@@ -389,18 +405,40 @@ public class PayService {
}
BigDecimal shouldPayAmount = orderInfo.getOriginAmount().multiply(BigDecimal.valueOf(freeDineConfig.getRechargeTimes()));
if (payDTO.getCouponId() != null) {
List<TbUserCouponVo> couponList = shopCouponService.getActivateCouponByAmount(Integer.valueOf(orderInfo.getShopId()), userId, shouldPayAmount);
if (couponList.stream().noneMatch(item -> item.getCouponId().equals(payDTO.getCouponId()))) {
throw new MsgException("此优惠券不可用");
if (!payDTO.getCouponIds().isEmpty()) {
List<TbUserCouponVo> userCouponList = shopCouponService.getActivateCouponByAmount(Integer.valueOf(orderInfo.getShopId()), String.valueOf(payDTO.getUserId()), shouldPayAmount);
if (userCouponList.isEmpty()) {
throw new MsgException("存在不可用优惠券");
}
ArrayList<Integer> couponIdList = new ArrayList<>();
for (Integer couponId : payDTO.getCouponIds()) {
TbUserCouponVo userCouponVo = userCouponList.stream().filter(item -> item.getCouponId().equals(couponId)).findFirst().orElse(null);
if (userCouponVo == null) {
throw new MsgException("存在不可用优惠券");
}
couponIdList.add(userCouponVo.getCouponId());
}
List<TbShopCoupon> tbShopCoupons = mpShopCouponMapper.selectBatchIds(couponIdList);
if (tbShopCoupons.size() != payDTO.getCouponIds().size()) {
throw new MsgException("存在不可用优惠券");
}
// 设置优惠券信息
orderInfo.setCouponIdList(JSONObject.toJSONString(couponIdList));
orderInfo.setUserCouponAmount(BigDecimal.valueOf(tbShopCoupons.stream().map(TbShopCoupon::getDiscountAmount).reduce(0, Integer::sum)));
}
// TODO 霸王餐积分
if (payDTO.getUsePoints()) {
}
TbShopInfo shopInfo = mpsh.selectById(orderInfo.getShopId());
mpOrderInfoMapper.updateById(orderInfo);
return shouldPayAmount;
}
private void createFreeDineOrder(TbOrderInfo orderInfo) {
}
@Transactional(rollbackFor = Exception.class)
@@ -961,34 +999,37 @@ public class PayService {
@Transactional(rollbackFor = Exception.class)
public Result memberIn(String openId, String userId, String amount, String shopId, String ip) throws JsonProcessingException {
if (ObjectUtil.isEmpty(openId) || ObjectUtil.isEmpty(userId)) {
return Result.fail("用户信息允许为空");
}
public Result memberIn(MemberInDTO memberInDTO, String ip) throws JsonProcessingException {
TbUserInfo userInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
TbUserInfo userInfo = tbUserInfoMapper.selectByPrimaryKey(memberInDTO.getUserId());
if (ObjectUtil.isEmpty(userInfo)) {
return Result.fail("用户基本信息不存在");
}
TbShopUser tbShopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, shopId);
TbShopUser tbShopUser = tbShopUserMapper.selectByUserIdAndShopId(String.valueOf(memberInDTO.getUserId()), String.valueOf(memberInDTO.getShopId()));
if (ObjectUtil.isEmpty(tbShopUser)) {
return Result.fail("对应的用户信息不存在");
}
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(memberInDTO.getShopId());
if (ObjectUtil.isEmpty(shopInfo)) {
return Result.fail("对应的店铺信息不存在");
}
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(shopInfo.getMerchantId()));
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
return Result.fail("支付通道不存在");
}
BigDecimal payAmount = new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN);
// 霸王餐活动充值
BigDecimal payAmount;
if (memberInDTO.getOrderId() != null) {
payAmount = memberInDTO.getAmount().setScale(2, RoundingMode.DOWN);
// 会员充值
}else {
payAmount = getFreeDineOrderInfo(memberInDTO);
}
TbMemberIn memberIn = new TbMemberIn();
memberIn.setAmount(payAmount);
@@ -998,6 +1039,7 @@ public class PayService {
memberIn.setStatus("7");
memberIn.setMerchantId(Integer.valueOf(shopInfo.getMerchantId()));
memberIn.setCreateTime(new Date());
memberIn.setOrderId(memberInDTO.getOrderId());
tbMemberInMapper.insert(memberIn);
@@ -1009,11 +1051,11 @@ public class PayService {
req.setIp(ip);
req.setMercOrderNo(SnowFlakeUtil.generateOrderNo());
req.setNotifyUrl(callBackIn);
req.setPayAmt(amount);
req.setPayAmt(payAmount.toPlainString());
req.setPayType("03");
req.setPayWay("WXZF");
req.setSubject("充值");
req.setUserId(openId);
req.setUserId(String.valueOf(memberInDTO.getUserId()));
Map<String, Object> map = BeanUtil.transBeanMap(req);
@@ -1036,7 +1078,10 @@ public class PayService {
String orderNo = DateUtils.getsdfTimesSS();
PublicResp<WxScanPayResp> publicResp = thirdPayService
.scanpay(thirdUrl, thirdApply.getAppId(),
"会员充值", "会员充值", new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(), "WECHAT", thirdApply.getSmallAppid(), openId, ip, orderNo, thirdApply.getStoreId(), callInBack, null, thirdApply.getAppToken());
"会员充值", "会员充值", new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN)
.multiply(new BigDecimal(100)).longValue(), "WECHAT",
thirdApply.getSmallAppid(), memberInDTO.getOpenId(), ip, orderNo, thirdApply.getStoreId(),
callInBack, null, thirdApply.getAppToken());
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
if ("000000".equals(publicResp.getCode())) {
WxScanPayResp wxScanPayResp = publicResp.getObjData();
@@ -1045,6 +1090,7 @@ public class PayService {
memberIn.setOrderNo(orderNo);
memberIn.setTradeNo(wxScanPayResp.getPayOrderId());
memberIn.setUpdateTime(new Date());
memberIn.setOrderId(memberIn.getOrderId());
tbMemberInMapper.updateByPrimaryKeySelective(memberIn);
ObjectMapper mapper = new ObjectMapper();
return Result.success(CodeEnum.SUCCESS, mapper.readTree(wxScanPayResp.getPayInfo()));