Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
2024-08-22 09:38:56 +08:00
12 changed files with 223 additions and 16 deletions

View File

@@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.chaozhanggui.system.cashierservice.bean.ShopWxMsgTypeEnum;
import com.chaozhanggui.system.cashierservice.bean.TableStateEnum;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.UpdateVipDTO;
@@ -274,6 +275,7 @@ public class OrderService {
cashierCart.setNumber(number);
cashierCart.setUuid(uuid);
cashierCart.setCategoryId(product.getCategoryId());
cashierCart.setTableId(tableId);
list.add(cashierCart);
cashierCartMapper.insert(cashierCart);
cart=cashierCart;
@@ -364,9 +366,10 @@ public class OrderService {
queryWrapper.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "");
// 台桌点单
}else if (StrUtil.isNotBlank(tableId)) {
String finalMasterId = masterId;
queryWrapper.eq(TbCashierCart::getTableId, tableId)
.and(query -> {
query.eq(TbCashierCart::getMasterId, masterId)
query.eq(TbCashierCart::getMasterId, finalMasterId)
.or()
.isNull(TbCashierCart::getMasterId);
});
@@ -405,10 +408,12 @@ public class OrderService {
}
Map<String, Object> map = new HashMap<>();
map.put("list", list);
map.put("masterId", masterId);
BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal packAmount = BigDecimal.ZERO;
for (TbCashierCart cashierCart : list) {
if (StrUtil.isNotBlank(cashierCart.getMasterId())) {
masterId = cashierCart.getMasterId();
}
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
if (cashierCart.getIsPack().equals("true")) {
packAmount = packAmount.add(cashierCart.getPackFee());
@@ -427,6 +432,9 @@ public class OrderService {
}
// TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPr imaryKey(Integer.valueOf(cashierCart.getProductId()));
}
map.put("masterId", masterId);
QueryCartPo queryCartPo = cashierCartMapper.selectProductNumByMarketId(day, shopId, masterId);
queryCartPo.setPackAmount(packAmount);
queryCartPo.setTotalAmount(totalAmount);
@@ -557,7 +565,7 @@ public class OrderService {
String orderNo = generateOrderNumber();
TbToken tbToken = tokenMapper.selectByToken(token);
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(orderId);
if (orderId > 0) {
if (orderId > 0 && orderInfo != null) {
// if (!orderInfo.getStatus().equals("unpaid")){
// return Result.fail(CodeEnum.ORDERCREATE);
// }
@@ -583,6 +591,9 @@ public class OrderService {
orderInfo.setMasterId(masterId);
orderInfo.setRemark(orderVo.getRemark());
orderInfo.setUserId(orderVo.getUserId());
if (StrUtil.isNotBlank(orderVo.getTableId())) {
orderInfo.setTableId(orderVo.getTableId());
}
if (Objects.nonNull(tbToken)){
orderInfo.setTokenId(tbToken.getId());
}
@@ -651,6 +662,13 @@ public class OrderService {
}
if (flag) {
redisUtil.deleteByKey("SHOP:CODE:USER:" + clientType + ":" + orderVo.getShopId() + ":" + day + orderVo.getUserId());
// 代课下单
if (!StrUtil.isBlank(orderVo.getTableId())) {
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.USING.getState()));
producer.printMechine(String.valueOf(orderInfo.getId()));
}
}
JSONObject object=new JSONObject();
@@ -673,8 +691,6 @@ public class OrderService {
redisUtil.saveMessage(RedisCst.OUT_NUMBER.concat(orderInfo.getShopId().toString()),object.toString());
log.info("创建订单发送更新耗材消息订单id{}", orderInfo.getId());
//修改耗材数据
JSONObject jsonObject=new JSONObject();
@@ -696,6 +712,16 @@ public class OrderService {
return Result.success(CodeEnum.SUCCESS, orderInfo);
}
public synchronized void addGlobalCode(String day, String clientType, String shopId) {
String code = redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId + ":" + day);
if (StrUtil.isBlank(code)) {
redisUtil.saveMessage("SHOP:CODE:" + clientType + ":" + shopId + ":" + day, "1");
}else {
redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId + ":" + (Integer.parseInt(code) + 1));
}
redisUtil.execsSet("SHOP:CODE:SET" + clientType + ":" + shopId + ":" + day, "1");
}
public synchronized String generateOrderCode(String day, String clientType, String shopId) {
String code = redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId + ":" + day)+"";
// 使用顺序递增的计数器生成取餐码
@@ -900,6 +926,11 @@ public class OrderService {
if (flag) {
redisUtil.deleteByKey("SHOP:CODE:USER:" + clientType + ":" + shopId + ":" + day + userId);
}
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, tableId)
.set(TbShopTable::getStatus, TableStateEnum.PENDING.getState()));
} else {
List<TbCashierCart> list = mpCashierCartMapper.selectList(queryWrapper
.eq(TbCashierCart::getStatus, "refund"));

View File

@@ -1,8 +1,10 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
@@ -11,6 +13,8 @@ import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.model.ReturnOrderReq;
import com.chaozhanggui.system.cashierservice.model.ScanPayReq;
import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopUserFlowMapper;
import com.chaozhanggui.system.cashierservice.mybatis.MpShopUserMapper;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
@@ -118,6 +122,10 @@ public class PayService {
@Autowired
TbPlussShopStaffMapper tbPlussShopStaffMapper;
@Autowired
private MpShopUserMapper mpShopUserMapper;
@Autowired
private MpShopUserFlowMapper mpShopUserFlowMapper;
public static void main(String[] args) {
@@ -710,6 +718,82 @@ public class PayService {
return Result.success(CodeEnum.SUCCESS);
}
public Result vipPay(String orderId, String token, Integer vipUserId) {
if (ObjectUtil.isEmpty(orderId)) {
return Result.fail(CodeEnum.PARAM);
}
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
if (ObjectUtil.isEmpty(orderInfo)) {
return Result.fail(CodeEnum.ORDERNOEXIST);
}
if (!"unpaid".equals(orderInfo.getStatus())) {
return Result.fail(CodeEnum.ORDERSTATUSERROR);
}
int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(orderInfo.getShopId(), "cash");
if (count < 1) {
return Result.fail(CodeEnum.PAYTYPENOEXIST);
}
// 扣减会员余额
TbShopUser shopUser = mpShopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>()
.eq(TbShopUser::getStatus, 1)
.eq(TbShopUser::getId, vipUserId));
if (shopUser == null) {
return Result.fail("用户不存在或已被禁用");
}
long flag = mpShopUserMapper.decrBalance(vipUserId, orderInfo.getOrderAmount());
if (flag < 1) {
return Result.fail("余额不足或扣除余额失败");
}
TbShopUserFlow userFlow = new TbShopUserFlow();
userFlow.setAmount(orderInfo.getOrderAmount());
userFlow.setBalance(shopUser.getAmount());
userFlow.setShopUserId(shopUser.getId());
userFlow.setBizCode("vipCardCash");
userFlow.setBizName("代客下单会员余额支付");
userFlow.setCreateTime(DateUtil.date());
userFlow.setType("-");
mpShopUserFlowMapper.insert(userFlow);
orderInfo.setPayAmount(orderInfo.getOrderAmount());
orderInfo.setPayType("cash");
orderInfo.setStatus("closed");
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
//更新购物车状态
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed");
log.info("更新购物车:{}", cartCount);
JSONObject jsonObject = new JSONObject();
jsonObject.put("token", token);
jsonObject.put("type", "create");
jsonObject.put("orderId", orderId);
producer.putOrderCollect(jsonObject.toJSONString());
producer.printMechine(orderId);
// 发送库存记录mq消息
JSONObject mqData = new JSONObject();
mqData.put("orderId", orderId);
mqData.put("type", "pc");
producer.sendStockSaleMsg(mqData);
return Result.success(CodeEnum.SUCCESS);
}
@Transactional(rollbackFor = Exception.class)
public Result cashPay(String orderId, String token,BigDecimal payAmount,BigDecimal discountAmount) {
if (ObjectUtil.isEmpty(orderId)) {
@@ -782,6 +866,10 @@ public class PayService {
mqData.put("type", "pc");
producer.sendStockSaleMsg(mqData);
redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
return Result.success(CodeEnum.SUCCESS);
}
@@ -856,6 +944,8 @@ public class PayService {
mqData.put("type", "pc");
producer.sendStockSaleMsg(mqData);
redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
return Result.success(CodeEnum.SUCCESS);
}
@@ -1156,6 +1246,7 @@ public class PayService {
productStockDetailMapper.insert(tbProductStockDetail);
}
redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + orderInfo.getShopId() + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
return Result.success(CodeEnum.SUCCESS);
}
@@ -1254,6 +1345,8 @@ public class PayService {
}
redisUtil.del("SHOP:CODE:USER:" + "pc" + ":" + shopId + ":" + DateUtils.getDay() + TokenUtil.parseParamFromToken(token).getString("accountId"));
return Result.fail(CodeEnum.FAIL);
@@ -1310,6 +1403,7 @@ public class PayService {
}
}
return Result.success(CodeEnum.SUCCESS, tbQuickPay);
}