霸王餐相关接口

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

@@ -16,4 +16,19 @@ public interface TableConstant {
} }
} }
} }
class OrderInfo {
@Getter
public enum Status {
REFUNDING("refunding"), REFUND("refund"), CLOSED("closed"), CREATE("create"),
UNPAID("unpaid"), PAYING("paying"), RETURN("return");
private final String value;
Status(String value) {
this.value = value;
}
}
}
} }

View File

@@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit; import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit;
import com.chaozhanggui.system.cashierservice.entity.dto.MemberInDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.OrderPayDTO; import com.chaozhanggui.system.cashierservice.entity.dto.OrderPayDTO;
import com.chaozhanggui.system.cashierservice.service.PayService; import com.chaozhanggui.system.cashierservice.service.PayService;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
@@ -11,10 +12,12 @@ import com.chaozhanggui.system.cashierservice.util.TokenUtil;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@@ -49,7 +52,6 @@ public class PayController {
} }
/** /**
* 储值卡支付 * 储值卡支付
* *
@@ -64,7 +66,7 @@ public class PayController {
@RequestParam("memberId") String memberId, @RequestParam("memberId") String memberId,
@RequestParam("pwd") String pwd @RequestParam("pwd") String pwd
) { ) {
return payService.accountPay(orderId, memberId, token,pwd); return payService.accountPay(orderId, memberId, token, pwd);
} }
@RequestMapping("groupOrderPay") @RequestMapping("groupOrderPay")
@@ -78,7 +80,7 @@ public class PayController {
String userId = ""; String userId = "";
if (environment.equals("wx") && payType.equals("wechatPay")) { if (environment.equals("wx") && payType.equals("wechatPay")) {
userId = TokenUtil.parseParamFromToken(token).getString("openId"); userId = TokenUtil.parseParamFromToken(token).getString("openId");
} else if("aliPay".equals(payType)){ } else if ("aliPay".equals(payType)) {
userId = TokenUtil.parseParamFromToken(token).getString("openId"); userId = TokenUtil.parseParamFromToken(token).getString("openId");
} else { } else {
userId = TokenUtil.parseParamFromToken(token).getString("userId"); userId = TokenUtil.parseParamFromToken(token).getString("userId");
@@ -139,16 +141,22 @@ public class PayController {
* *
* @param request * @param request
* @param openId * @param openId
* @param map
* @return
*/ */
@RequestMapping("memeberIn") @RequestMapping("memeberIn")
@LimitSubmit(key = "memeberIn:%s") @LimitSubmit(key = "memeberIn:%s")
public Result memeberIn(HttpServletRequest request, @RequestHeader("openId") String openId, @RequestHeader("id") String id, public Result memeberIn(HttpServletRequest request,
@RequestBody Map<String, Object> map @RequestHeader("openId") String openId, @RequestHeader("id") String id,
) { @RequestBody @Validated MemberInDTO memberInDTO) {
try { try {
return payService.memberIn(openId, id, map.get("amount").toString(), map.get("shopId").toString(), IpUtil.getIpAddr(request)); if (memberInDTO.getOrderId() == null && memberInDTO.getAmount() == null) {
return Result.fail("金额和订单id不能同时为空");
}
if(memberInDTO.getAmount() != null && memberInDTO.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
return Result.fail("充值金额不能小于等于0");
}
return payService.memberIn(memberInDTO, IpUtil.getIpAddr(request));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -162,7 +170,7 @@ public class PayController {
@RequestParam("userId") String userId, @RequestParam("userId") String userId,
@RequestParam("shopId") String shopId @RequestParam("shopId") String shopId
) { ) {
return payService.getShopByMember(userId,shopId,page,pageSize); return payService.getShopByMember(userId, shopId, page, pageSize);
} }
@RequestMapping("queryMemberAccount") @RequestMapping("queryMemberAccount")

View File

@@ -1,9 +1,12 @@
package com.chaozhanggui.system.cashierservice.entity; package com.chaozhanggui.system.cashierservice.entity;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
@Data
public class TbMemberIn implements Serializable { public class TbMemberIn implements Serializable {
private Integer id; private Integer id;
@@ -27,93 +30,9 @@ public class TbMemberIn implements Serializable {
private Integer shopId; private Integer shopId;
private Integer orderId;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public Integer getId() {
return id;
}
public void setId(Integer id) { }
this.id = id;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Integer getMerchantId() {
return merchantId;
}
public void setMerchantId(Integer merchantId) {
this.merchantId = merchantId;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code == null ? null : code.trim();
}
public BigDecimal getAmount() {
return amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status == null ? null : status.trim();
}
public String getOrderNo() {
return orderNo;
}
public void setOrderNo(String orderNo) {
this.orderNo = orderNo == null ? null : orderNo.trim();
}
public String getTradeNo() {
return tradeNo;
}
public void setTradeNo(String tradeNo) {
this.tradeNo = tradeNo == null ? null : tradeNo.trim();
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Integer getShopId() {
return shopId;
}
public void setShopId(Integer shopId) {
this.shopId = shopId;
}
}

View File

@@ -123,6 +123,10 @@ public class TbOrderInfo implements Serializable {
private Integer seatCount; private Integer seatCount;
private BigDecimal seatAmount; private BigDecimal seatAmount;
private BigDecimal pointsDiscountAmount;
private Integer pointsNum;
private String couponIdList;
private BigDecimal couponDiscountAmount;
//根据状态返回 需付款 已付款 未付款 已退 //根据状态返回 需付款 已付款 未付款 已退

View File

@@ -0,0 +1,26 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;
@Data
public class MemberInDTO {
@NotNull
private Integer shopId;
@NotNull(message = "用户信息不允许为空")
private Integer userId;
@NotBlank(message = "用户信息不允许为空")
private String openId;
private BigDecimal amount;
private Integer orderId;
// 使用的优惠券
private List<Integer> couponIds;
// 是否使用积分抵扣
private Boolean usePoints;
}

View File

@@ -14,10 +14,5 @@ public class OrderPayDTO {
private Integer orderId; private Integer orderId;
@NotBlank(message = "支付类型不允许为空") @NotBlank(message = "支付类型不允许为空")
private String payType; private String payType;
@NotNull
private Boolean isFreeDine;
// 使用的优惠券
private Integer couponId;
// 是否使用积分抵扣
private Boolean usePoints;
} }

View File

@@ -0,0 +1,19 @@
package com.chaozhanggui.system.cashierservice.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
import com.chaozhanggui.system.cashierservice.entity.TbShopCoupon;
/**
* @author Administrator
* @description 针对表【tb_call_queue】的数据库操作Mapper
* @createDate 2024-09-13 13:44:26
* @Entity com.chaozhanggui.system.cashierservice.entity.TbCallQueue
*/
public interface MpShopCouponMapper extends BaseMapper<TbShopCoupon> {
}

View File

@@ -12,6 +12,7 @@ import com.chaozhanggui.system.cashierservice.constant.TableConstant;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.Enum.OrderUseTypeEnum; import com.chaozhanggui.system.cashierservice.entity.Enum.OrderUseTypeEnum;
import com.chaozhanggui.system.cashierservice.entity.*; 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.OrderPayDTO;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto; import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO; 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.MpCashierCartMapper;
import com.chaozhanggui.system.cashierservice.mapper.MpOrderDetailMapper; import com.chaozhanggui.system.cashierservice.mapper.MpOrderDetailMapper;
import com.chaozhanggui.system.cashierservice.mapper.MpOrderInfoMapper; 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.PayReq;
import com.chaozhanggui.system.cashierservice.model.TradeQueryReq; import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
import com.chaozhanggui.system.cashierservice.mpservice.MpShopTableService; import com.chaozhanggui.system.cashierservice.mpservice.MpShopTableService;
@@ -190,6 +192,13 @@ public class PayService {
private final MpShopTableService mpShopTableService; private final MpShopTableService mpShopTableService;
private final TbFreeDineConfigService freeDineConfigService; private final TbFreeDineConfigService freeDineConfigService;
private final TbShopCouponService shopCouponService; 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) { public PayService(@Qualifier("tbShopSongOrderServiceImpl") TbShopSongOrderService shopSongOrderService, MpShopTableService mpShopTableService, TbFreeDineConfigService freeDineConfigService, TbShopCouponService shopCouponService) {
this.shopSongOrderService = shopSongOrderService; this.shopSongOrderService = shopSongOrderService;
@@ -367,7 +376,14 @@ public class PayService {
throw new MsgException("支付失败"); 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()); TbFreeDineConfig freeDineConfig = freeDineConfigService.getById(orderInfo.getShopId());
if (freeDineConfig == null || freeDineConfig.getEnable() == null || freeDineConfig.getEnable() == 0) { 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("当前店铺未开启与优惠券同享"); throw new MsgException("当前店铺未开启与优惠券同享");
} }
@@ -389,18 +405,40 @@ public class PayService {
} }
BigDecimal shouldPayAmount = orderInfo.getOriginAmount().multiply(BigDecimal.valueOf(freeDineConfig.getRechargeTimes())); BigDecimal shouldPayAmount = orderInfo.getOriginAmount().multiply(BigDecimal.valueOf(freeDineConfig.getRechargeTimes()));
if (payDTO.getCouponId() != null) { if (!payDTO.getCouponIds().isEmpty()) {
List<TbUserCouponVo> couponList = shopCouponService.getActivateCouponByAmount(Integer.valueOf(orderInfo.getShopId()), userId, shouldPayAmount); List<TbUserCouponVo> userCouponList = shopCouponService.getActivateCouponByAmount(Integer.valueOf(orderInfo.getShopId()), String.valueOf(payDTO.getUserId()), shouldPayAmount);
if (couponList.stream().noneMatch(item -> item.getCouponId().equals(payDTO.getCouponId()))) { if (userCouponList.isEmpty()) {
throw new MsgException("此优惠券不可用"); 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 霸王餐积分 // TODO 霸王餐积分
if (payDTO.getUsePoints()) { if (payDTO.getUsePoints()) {
} }
TbShopInfo shopInfo = mpsh.selectById(orderInfo.getShopId()); mpOrderInfoMapper.updateById(orderInfo);
return shouldPayAmount;
}
private void createFreeDineOrder(TbOrderInfo orderInfo) {
} }
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@@ -961,34 +999,37 @@ public class PayService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result memberIn(String openId, String userId, String amount, String shopId, String ip) throws JsonProcessingException { public Result memberIn(MemberInDTO memberInDTO, String ip) throws JsonProcessingException {
if (ObjectUtil.isEmpty(openId) || ObjectUtil.isEmpty(userId)) {
return Result.fail("用户信息允许为空");
}
TbUserInfo userInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); TbUserInfo userInfo = tbUserInfoMapper.selectByPrimaryKey(memberInDTO.getUserId());
if (ObjectUtil.isEmpty(userInfo)) { if (ObjectUtil.isEmpty(userInfo)) {
return Result.fail("用户基本信息不存在"); 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)) { if (ObjectUtil.isEmpty(tbShopUser)) {
return Result.fail("对应的用户信息不存在"); return Result.fail("对应的用户信息不存在");
} }
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(memberInDTO.getShopId());
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
if (ObjectUtil.isEmpty(shopInfo)) { if (ObjectUtil.isEmpty(shopInfo)) {
return Result.fail("对应的店铺信息不存在"); return Result.fail("对应的店铺信息不存在");
} }
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(shopInfo.getMerchantId())); TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(shopInfo.getMerchantId()));
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
return Result.fail("支付通道不存在"); 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(); TbMemberIn memberIn = new TbMemberIn();
memberIn.setAmount(payAmount); memberIn.setAmount(payAmount);
@@ -998,6 +1039,7 @@ public class PayService {
memberIn.setStatus("7"); memberIn.setStatus("7");
memberIn.setMerchantId(Integer.valueOf(shopInfo.getMerchantId())); memberIn.setMerchantId(Integer.valueOf(shopInfo.getMerchantId()));
memberIn.setCreateTime(new Date()); memberIn.setCreateTime(new Date());
memberIn.setOrderId(memberInDTO.getOrderId());
tbMemberInMapper.insert(memberIn); tbMemberInMapper.insert(memberIn);
@@ -1009,11 +1051,11 @@ public class PayService {
req.setIp(ip); req.setIp(ip);
req.setMercOrderNo(SnowFlakeUtil.generateOrderNo()); req.setMercOrderNo(SnowFlakeUtil.generateOrderNo());
req.setNotifyUrl(callBackIn); req.setNotifyUrl(callBackIn);
req.setPayAmt(amount); req.setPayAmt(payAmount.toPlainString());
req.setPayType("03"); req.setPayType("03");
req.setPayWay("WXZF"); req.setPayWay("WXZF");
req.setSubject("充值"); req.setSubject("充值");
req.setUserId(openId); req.setUserId(String.valueOf(memberInDTO.getUserId()));
Map<String, Object> map = BeanUtil.transBeanMap(req); Map<String, Object> map = BeanUtil.transBeanMap(req);
@@ -1036,7 +1078,10 @@ public class PayService {
String orderNo = DateUtils.getsdfTimesSS(); String orderNo = DateUtils.getsdfTimesSS();
PublicResp<WxScanPayResp> publicResp = thirdPayService PublicResp<WxScanPayResp> publicResp = thirdPayService
.scanpay(thirdUrl, thirdApply.getAppId(), .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 (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
if ("000000".equals(publicResp.getCode())) { if ("000000".equals(publicResp.getCode())) {
WxScanPayResp wxScanPayResp = publicResp.getObjData(); WxScanPayResp wxScanPayResp = publicResp.getObjData();
@@ -1045,6 +1090,7 @@ public class PayService {
memberIn.setOrderNo(orderNo); memberIn.setOrderNo(orderNo);
memberIn.setTradeNo(wxScanPayResp.getPayOrderId()); memberIn.setTradeNo(wxScanPayResp.getPayOrderId());
memberIn.setUpdateTime(new Date()); memberIn.setUpdateTime(new Date());
memberIn.setOrderId(memberIn.getOrderId());
tbMemberInMapper.updateByPrimaryKeySelective(memberIn); tbMemberInMapper.updateByPrimaryKeySelective(memberIn);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
return Result.success(CodeEnum.SUCCESS, mapper.readTree(wxScanPayResp.getPayInfo())); return Result.success(CodeEnum.SUCCESS, mapper.readTree(wxScanPayResp.getPayInfo()));