1.代客下单 会员支付,支付修改台桌状态

This commit is contained in:
2024-08-23 17:07:43 +08:00
parent baf91df968
commit abdefe6932
6 changed files with 108 additions and 12 deletions

View File

@@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.controller;
import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit; import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit;
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail; import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto; import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
import com.chaozhanggui.system.cashierservice.entity.dto.VipPayDTO;
import com.chaozhanggui.system.cashierservice.model.PaymentReq; import com.chaozhanggui.system.cashierservice.model.PaymentReq;
import com.chaozhanggui.system.cashierservice.service.PayService; import com.chaozhanggui.system.cashierservice.service.PayService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
@@ -185,17 +186,26 @@ public class PayController {
* @param token * @param token
* @param loginName * @param loginName
* @param clientType * @param clientType
* @param orderId
* @return * @return
*/ */
@GetMapping("vipPay") @PostMapping("vipPay")
@LimitSubmit(key = "vipPay:%s") @LimitSubmit(key = "vipPay:%s")
public Result vipPay(@RequestHeader("token") String token, public Result vipPay(@RequestHeader("token") String token,
@RequestHeader("loginName") String loginName, @RequestHeader("loginName") String loginName,
@RequestHeader("clientType") String clientType, @RequestHeader("clientType") String clientType,
@RequestParam("orderId") String orderId, @RequestBody VipPayDTO vipPayDTO
@RequestParam("vipUserId") Integer vipUserId){ ){
return payService.vipPay(orderId,token, vipUserId); if (vipPayDTO.getOrderId() == null || vipPayDTO.getVipUserId() == null) {
return Result.fail("参数缺失");
}
if (
(vipPayDTO.getPayAmount() != null && vipPayDTO.getPayAmount().compareTo(BigDecimal.ZERO) <= 0) ||
(vipPayDTO.getDiscountAmount() != null && vipPayDTO.getDiscountAmount().compareTo(BigDecimal.ZERO) <= 0)
) {
return Result.fail("折扣金额必须大于0");
}
return payService.vipPay(vipPayDTO.getOrderId(),token, vipPayDTO.getVipUserId(), vipPayDTO.getPayAmount(), vipPayDTO.getDiscountAmount());
} }

View File

@@ -0,0 +1,14 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class VipPayDTO {
private Integer orderId;
private Integer vipUserId;
private BigDecimal payAmount;
private BigDecimal discountAmount;
}

View File

@@ -8,6 +8,6 @@ import org.apache.ibatis.annotations.Update;
import java.math.BigDecimal; import java.math.BigDecimal;
public interface MpShopUserMapper extends BaseMapper<TbShopUser> { public interface MpShopUserMapper extends BaseMapper<TbShopUser> {
@Update("update tb_shop_user set amount=amount-#{orderAmount}, consume_amount=consume_amount+#{orderAmount} where id=#{vipUserId} and amount >= 0") @Update("update tb_shop_user set amount=amount-#{orderAmount}, consume_amount=consume_amount+#{orderAmount} where id=#{vipUserId} and amount-#{orderAmount} >= 0")
long decrBalance(@Param("vipUserId") Integer vipUserId, @Param("orderAmount") BigDecimal orderAmount); long decrBalance(@Param("vipUserId") Integer vipUserId, @Param("orderAmount") BigDecimal orderAmount);
} }

View File

@@ -3,10 +3,13 @@ package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.chaozhanggui.system.cashierservice.bean.TableStateEnum;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.model.ScanPayReq; import com.chaozhanggui.system.cashierservice.model.ScanPayReq;
import com.chaozhanggui.system.cashierservice.model.TradeQueryReq; import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopTableMapper;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
@@ -20,6 +23,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -76,6 +80,9 @@ public class MemberService {
@Autowired @Autowired
TbmerchantAccountMapper tbmerchantAccountMapper; TbmerchantAccountMapper tbmerchantAccountMapper;
@Qualifier("tbOrderInfoMapper")
@Autowired
private TbOrderInfoMapper tbOrderInfoMapper;
public Result queryMember(String shopId, String phone, int page, int pageSize) { public Result queryMember(String shopId, String phone, int page, int pageSize) {
@@ -549,6 +556,9 @@ public class MemberService {
String shopId = String.valueOf(map.get("shopId")); String shopId = String.valueOf(map.get("shopId"));
Integer orderId = Integer.parseInt(String.valueOf(map.get("orderId")));
TbOrderInfo orderInfo = tbOrderInfoMapper.selectById(orderId);
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
if (ObjectUtil.isEmpty(shopInfo) || shopInfo == null) { if (ObjectUtil.isEmpty(shopInfo) || shopInfo == null) {
@@ -633,10 +643,18 @@ public class MemberService {
producer.putOrderCollect(jsonObject.toJSONString()); producer.putOrderCollect(jsonObject.toJSONString());
// 修改台桌状态
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
private MpShopTableMapper mpShopTableMapper;
public Result queryMemberAccount(String memberId, int page, int pageSize) { public Result queryMemberAccount(String memberId, int page, int pageSize) {
if (ObjectUtil.isEmpty(memberId)) { if (ObjectUtil.isEmpty(memberId)) {

View File

@@ -494,7 +494,6 @@ public class OrderService {
.eq(TbCashierCart::getShopId, orderVo.getShopId()) .eq(TbCashierCart::getShopId, orderVo.getShopId())
.eq(TbCashierCart::getStatus, "create"); .eq(TbCashierCart::getStatus, "create");
// 普通点单 // 普通点单
if (StrUtil.isBlank(orderVo.getTableId())) { if (StrUtil.isBlank(orderVo.getTableId())) {
queryWrapper.eq(TbCashierCart::getMasterId, orderVo.getMasterId()) queryWrapper.eq(TbCashierCart::getMasterId, orderVo.getMasterId())

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.chaozhanggui.system.cashierservice.bean.TableStateEnum;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto; import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
@@ -13,6 +14,7 @@ import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.model.ReturnOrderReq; import com.chaozhanggui.system.cashierservice.model.ReturnOrderReq;
import com.chaozhanggui.system.cashierservice.model.ScanPayReq; import com.chaozhanggui.system.cashierservice.model.ScanPayReq;
import com.chaozhanggui.system.cashierservice.model.TradeQueryReq; import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopTableMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopUserFlowMapper; import com.chaozhanggui.system.cashierservice.mybatis.MpShopUserFlowMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopUserMapper; import com.chaozhanggui.system.cashierservice.mybatis.MpShopUserMapper;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
@@ -126,6 +128,8 @@ public class PayService {
private MpShopUserMapper mpShopUserMapper; private MpShopUserMapper mpShopUserMapper;
@Autowired @Autowired
private MpShopUserFlowMapper mpShopUserFlowMapper; private MpShopUserFlowMapper mpShopUserFlowMapper;
@Autowired
private MpShopTableMapper mpShopTableMapper;
public static void main(String[] args) { public static void main(String[] args) {
@@ -297,6 +301,13 @@ public class PayService {
producer.printMechine(orderId); producer.printMechine(orderId);
// 修改台桌状态
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data")); return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data"));
} else { } else {
String status = ObjectUtil.isNotEmpty(object.getJSONObject("data")) ? object.getJSONObject("data").getString("status") : null; String status = ObjectUtil.isNotEmpty(object.getJSONObject("data")) ? object.getJSONObject("data").getString("status") : null;
@@ -309,6 +320,13 @@ public class PayService {
payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString()); payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString());
payment.setUpdatedAt(System.currentTimeMillis()); payment.setUpdatedAt(System.currentTimeMillis());
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
// 修改台桌状态
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
return Result.success(CodeEnum.PAYING); return Result.success(CodeEnum.PAYING);
} }
// orderInfo.setStatus("fail"); // orderInfo.setStatus("fail");
@@ -357,6 +375,11 @@ public class PayService {
producer.putOrderCollect(jsonObject.toJSONString()); producer.putOrderCollect(jsonObject.toJSONString());
producer.printMechine(orderId); producer.printMechine(orderId);
// 修改台桌状态
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
return Result.success(CodeEnum.SUCCESS, mainScanResp); return Result.success(CodeEnum.SUCCESS, mainScanResp);
} else if ("TRADE_AWAIT".equals(mainScanResp.getState())) { } else if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
@@ -367,6 +390,12 @@ public class PayService {
payment.setTradeNumber(mainScanResp.getPayOrderId()); payment.setTradeNumber(mainScanResp.getPayOrderId());
payment.setUpdatedAt(System.currentTimeMillis()); payment.setUpdatedAt(System.currentTimeMillis());
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
// 修改台桌状态
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
return Result.success(CodeEnum.PAYING); return Result.success(CodeEnum.PAYING);
} }
} }
@@ -718,7 +747,7 @@ public class PayService {
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
public Result vipPay(String orderId, String token, Integer vipUserId) { public Result vipPay(Integer orderId, String token, Integer vipUserId, BigDecimal payAmount, BigDecimal discountAmount) {
if (ObjectUtil.isEmpty(orderId)) { if (ObjectUtil.isEmpty(orderId)) {
return Result.fail(CodeEnum.PARAM); return Result.fail(CodeEnum.PARAM);
} }
@@ -739,6 +768,11 @@ public class PayService {
return Result.fail(CodeEnum.PAYTYPENOEXIST); return Result.fail(CodeEnum.PAYTYPENOEXIST);
} }
if (payAmount != null && discountAmount != null && payAmount.add(discountAmount).compareTo(orderInfo.getOrderAmount()) != 0) {
return Result.fail("优惠金额 + 支付金额不等于订单金额");
}
// 扣减会员余额 // 扣减会员余额
TbShopUser shopUser = mpShopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>() TbShopUser shopUser = mpShopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>()
.eq(TbShopUser::getStatus, 1) .eq(TbShopUser::getStatus, 1)
@@ -764,13 +798,19 @@ public class PayService {
mpShopUserFlowMapper.insert(userFlow); mpShopUserFlowMapper.insert(userFlow);
orderInfo.setPayAmount(orderInfo.getOrderAmount()); if (payAmount != null && discountAmount != null) {
orderInfo.setPayAmount(payAmount);
orderInfo.setDiscountAmount(discountAmount);
}else {
orderInfo.setPayAmount(orderInfo.getOrderAmount());
}
orderInfo.setPayType("cash"); orderInfo.setPayType("cash");
orderInfo.setStatus("closed"); orderInfo.setStatus("closed");
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo())); orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
//更新购物车状态 //更新购物车状态
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final"); int cartCount = tbCashierCartMapper.updateByOrderId(String.valueOf(orderId), "final");
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed"); tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed");
log.info("更新购物车:{}", cartCount); log.info("更新购物车:{}", cartCount);
@@ -783,14 +823,17 @@ public class PayService {
producer.putOrderCollect(jsonObject.toJSONString()); producer.putOrderCollect(jsonObject.toJSONString());
producer.printMechine(orderId); producer.printMechine(String.valueOf(orderId));
// 发送库存记录mq消息 // 发送库存记录mq消息
JSONObject mqData = new JSONObject(); JSONObject mqData = new JSONObject();
mqData.put("orderId", orderId); mqData.put("orderId", orderId);
mqData.put("type", "pc"); mqData.put("type", "pc");
producer.sendStockSaleMsg(mqData); producer.sendStockSaleMsg(mqData);
// 修改台桌状态
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
@@ -869,6 +912,10 @@ public class PayService {
redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId")); redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
// 修改台桌状态
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
@@ -946,6 +993,10 @@ public class PayService {
redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId")); redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
// 修改台桌状态
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
@@ -1248,6 +1299,10 @@ public class PayService {
} }
redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId")); redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
// 修改台桌状态
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }