1.代客下单 加入购物车同步保存小程序缓存
This commit is contained in:
parent
3e3a23becd
commit
f3ad47f0f3
|
|
@ -9,6 +9,7 @@ import com.chaozhanggui.system.cashierservice.service.PayService;
|
|||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.IpUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.RedisCst;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -56,7 +57,6 @@ public class PayController {
|
|||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestBody PaymentReq paymentReq
|
||||
|
||||
) {
|
||||
return payService.scanPay(paymentReq.getOrderId(),paymentReq.getAuthCode(), IpUtil.getIpAddr(request),token,paymentReq.getPayAmount(),paymentReq.getDiscountAmount());
|
||||
}
|
||||
|
|
@ -177,7 +177,8 @@ public class PayController {
|
|||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestBody PaymentReq paymentReq){
|
||||
return payService.cashPay(paymentReq.getOrderId(),token,paymentReq.getPayAmount(),paymentReq.getDiscountAmount());
|
||||
Result result = payService.cashPay(paymentReq.getOrderId(), token, paymentReq.getPayAmount(), paymentReq.getDiscountAmount());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -711,6 +711,7 @@ public class MemberService {
|
|||
producer.balance(baObj.toString());
|
||||
|
||||
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import java.util.*;
|
|||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.CARTEXIST;
|
||||
|
||||
|
|
@ -214,6 +215,7 @@ public class OrderService {
|
|||
}
|
||||
}
|
||||
|
||||
setRedisTableCartInfo(tableId, shopId, Collections.singletonList(cart), false);
|
||||
return Result.success(CodeEnum.SUCCESS, masterId);
|
||||
}
|
||||
|
||||
|
|
@ -280,7 +282,26 @@ public class OrderService {
|
|||
}
|
||||
} else {
|
||||
List<TbCashierCart> list = cashierCartMapper.selectALlByMasterId(masterId, "create");
|
||||
TbCashierCart cashierCart = cashierCartMapper.selectByDetail(masterId, productId, shopId, skuId.toString(), DateUtils.getDay(), uuid, tableId);
|
||||
// TbCashierCart cashierCart = cashierCartMapper.selectByDetail(masterId, productId, shopId, skuId.toString(), DateUtils.getDay(), uuid, tableId);
|
||||
|
||||
String finalMasterId = masterId;
|
||||
TbCashierCart cashierCart = mpCashierCartMapper.selectOne(new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, shopId)
|
||||
.eq(TbCashierCart::getSkuId, shopId)
|
||||
.eq(TbCashierCart::getProductId, productId)
|
||||
.eq(TbCashierCart::getTableId, tableId)
|
||||
.in(TbCashierCart::getStatus, "create")
|
||||
.and(query2 -> {
|
||||
query2.and(query3 -> {
|
||||
query3.eq(TbCashierCart::getTradeDay, DateUtils.getDay())
|
||||
.eq(TbCashierCart::getMasterId, finalMasterId);
|
||||
})
|
||||
.or((query4 -> {
|
||||
query4.isNull(TbCashierCart::getTradeDay)
|
||||
.eq(TbCashierCart::getMasterId, "");
|
||||
}));
|
||||
}));
|
||||
|
||||
if (number > 0) {
|
||||
if (Objects.isNull(cashierCart)) {
|
||||
cashierCart = new TbCashierCart();
|
||||
|
|
@ -363,9 +384,32 @@ public class OrderService {
|
|||
}
|
||||
});
|
||||
|
||||
setRedisTableCartInfo(tableId, shopId, Collections.singletonList(cart), true);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, masterId);
|
||||
}
|
||||
|
||||
private void setRedisTableCartInfo(String tableId, String shopId, List<TbCashierCart> tbCashierCartList, boolean isAdd) {
|
||||
String tableCartKey = RedisCst.getTableCartKey(tableId, shopId);
|
||||
String tableCart = redisUtil.getMessage(tableCartKey);
|
||||
|
||||
List<TbCashierCart> cartArrayList = new ArrayList<>();
|
||||
if (tableCart != null) {
|
||||
cartArrayList = JSONObject.parseArray(tableCart, TbCashierCart.class);
|
||||
}
|
||||
|
||||
for (TbCashierCart cashierCart : tbCashierCartList) {
|
||||
cartArrayList = cartArrayList.stream().filter(d -> !d.getId().equals(cashierCart.getId())).collect(Collectors.toList());
|
||||
if (isAdd) {
|
||||
cartArrayList.add(cashierCart);
|
||||
}
|
||||
}
|
||||
|
||||
List<TbCashierCart> finalCartArrayList = cartArrayList;
|
||||
redisUtil.saveMessage(tableCartKey,
|
||||
JSONObject.toJSONString(finalCartArrayList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验商品库存警戒线并通知商户
|
||||
*
|
||||
|
|
@ -574,6 +618,11 @@ public class OrderService {
|
|||
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(cashierCart.getTableId())) {
|
||||
setRedisTableCartInfo(cashierCart.getTableId(), cashierCart.getShopId(), Collections.singletonList(cashierCart), false);
|
||||
}
|
||||
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
|
|
@ -582,6 +631,11 @@ public class OrderService {
|
|||
String day = DateUtils.getDay();
|
||||
TbShopTable shopTable = null;
|
||||
|
||||
String currentOrderKey = RedisCst.getCurrentOrderKey(orderVo.getTableId(),
|
||||
orderVo.getShopId().toString());
|
||||
String orderIdValue = redisUtil.getMessage(currentOrderKey);
|
||||
Integer orderId = orderIdValue == null ? 0 : Integer.parseInt(orderIdValue);
|
||||
|
||||
LambdaQueryWrapper<TbCashierCart> queryWrapper = new LambdaQueryWrapper<TbCashierCart>()
|
||||
.eq(TbCashierCart::getShopId, orderVo.getShopId())
|
||||
.eq(TbCashierCart::getStatus, "create");
|
||||
|
|
@ -649,7 +703,6 @@ public class OrderService {
|
|||
Map<Integer, TbProduct> productMap = new HashMap<>();
|
||||
List<TbOrderDetail> orderDetails = new ArrayList<>();
|
||||
String masterId = "";
|
||||
int orderId = 0;
|
||||
if (list.size()<1 || list.isEmpty()){
|
||||
return Result.fail(CARTEXIST);
|
||||
}
|
||||
|
|
@ -691,10 +744,14 @@ public class OrderService {
|
|||
String orderNo = generateOrderNumber();
|
||||
TbToken tbToken = tokenMapper.selectByToken(token);
|
||||
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(orderId);
|
||||
if (orderInfo == null || !"unpaid".equals(orderInfo.getStatus())) {
|
||||
redisUtil.deleteByKey(currentOrderKey);
|
||||
}
|
||||
if (orderId > 0 && orderInfo != null) {
|
||||
// if (!orderInfo.getStatus().equals("unpaid")){
|
||||
// return Result.fail(CodeEnum.ORDERCREATE);
|
||||
// }
|
||||
|
||||
orderDetailMapper.deleteByOUrderId(orderId);
|
||||
// orderInfo = tbOrderInfoMapper.selectByPrimaryKey(orderId);
|
||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
|
|
@ -754,6 +811,7 @@ public class OrderService {
|
|||
redisUtil.saveMessage(RedisCst.OUT_NUMBER.concat(orderInfo.getShopId()),object.toString());
|
||||
orderId = orderInfo.getId();
|
||||
|
||||
redisUtil.saveMessage(currentOrderKey, orderInfo.getId().toString());
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -852,6 +910,12 @@ public class OrderService {
|
|||
}
|
||||
});
|
||||
|
||||
// 删除小程序购物车缓存
|
||||
if (StrUtil.isNotBlank(orderInfo.getTableId())) {
|
||||
String tableCartKey = RedisCst.getTableCartKey(orderVo.getTableId(), orderVo.getShopId().toString());
|
||||
redisUtil.deleteByKey(tableCartKey);
|
||||
}
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, orderInfo);
|
||||
}
|
||||
|
||||
|
|
@ -1247,6 +1311,9 @@ public class OrderService {
|
|||
printMechineConsumer.printReturnTicket(finalOrderId, null);
|
||||
});
|
||||
|
||||
|
||||
setRedisTableCartInfo(cartVo.getTableId(), cartVo.getShopId(), list, false);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -300,6 +300,9 @@ public class PayService {
|
|||
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||
|
||||
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
|
||||
orderInfo.getShopId());
|
||||
redisUtil.del(tableCartKey);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data"));
|
||||
} else {
|
||||
|
|
@ -320,7 +323,9 @@ public class PayService {
|
|||
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||
// 打印结算单
|
||||
producer.printMechine(orderId);
|
||||
|
||||
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
|
||||
orderInfo.getShopId());
|
||||
redisUtil.del(tableCartKey);
|
||||
return Result.success(CodeEnum.PAYING);
|
||||
}
|
||||
// orderInfo.setStatus("fail");
|
||||
|
|
@ -374,7 +379,9 @@ public class PayService {
|
|||
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||
// 打印结算单
|
||||
|
||||
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
|
||||
orderInfo.getShopId());
|
||||
redisUtil.del(tableCartKey);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, mainScanResp);
|
||||
} else if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
|
||||
|
|
@ -391,7 +398,9 @@ public class PayService {
|
|||
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||
// 打印结算单
|
||||
producer.printMechine(orderId);
|
||||
|
||||
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
|
||||
orderInfo.getShopId());
|
||||
redisUtil.del(tableCartKey);
|
||||
return Result.success(CodeEnum.PAYING);
|
||||
}
|
||||
}
|
||||
|
|
@ -638,6 +647,10 @@ public class PayService {
|
|||
baObj.put("time",flow.getCreateTime());
|
||||
producer.balance(baObj.toString());
|
||||
|
||||
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
|
||||
orderInfo.getShopId());
|
||||
redisUtil.del(tableCartKey);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
|
|
@ -857,6 +870,9 @@ public class PayService {
|
|||
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||
|
||||
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
|
||||
orderInfo.getShopId());
|
||||
redisUtil.del(tableCartKey);
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
|
|
@ -940,6 +956,10 @@ public class PayService {
|
|||
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
|
||||
|
||||
// 小程序购物车缓存
|
||||
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
|
||||
orderInfo.getShopId());
|
||||
redisUtil.del(tableCartKey);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,4 +22,17 @@ public class RedisCst {
|
|||
public static final String ORDER_CART_EXISTS = "ORDER_CART_EXISTS:";
|
||||
public static final String ORDER_PRINT = "ORDER_PRINT:";
|
||||
public static final String ORDER_PRINT_PRO = "ORDER_PRINT_PRODUCT:";
|
||||
|
||||
static String CURRENT_TABLE_ORDER = "CURRENT_TABLE_ORDER:";
|
||||
public static String TABLE_CART = "TABLE:CART:";
|
||||
|
||||
|
||||
|
||||
public static String getCurrentOrderKey(String tableId, String shopId) {
|
||||
return CURRENT_TABLE_ORDER + shopId + ":" + tableId;
|
||||
}
|
||||
|
||||
public static String getTableCartKey(String tableId, String shopId) {
|
||||
return TABLE_CART + tableId + "-" + shopId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue