1.代客下单相关接口

This commit is contained in:
2024-08-09 16:07:00 +08:00
parent c300f61def
commit 86df7addd6
21 changed files with 576 additions and 59 deletions

View File

@@ -1,12 +1,13 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.bean.ShopWxMsgTypeEnum;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.po.*;
@@ -25,7 +26,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
@@ -92,7 +92,7 @@ public class OrderService {
@Transactional(rollbackFor = Exception.class)
public Result createCart(String masterId, String productId, String shopId, Integer skuId, Integer number,
String userId, String clientType, Integer cartId, String isGift, String isPack, String uuid, String type) {
String userId, String clientType, Integer cartId, String isGift, String isPack, String uuid, String type, String qrcode) {
if (Objects.isNull(number) || number < 0) {
return Result.fail(CodeEnum.NUMBER);
}
@@ -121,8 +121,6 @@ public class OrderService {
return Result.fail(CodeEnum.PRODUCTSKUERROR);
}
String exists = redisUtil.getMessage(RedisCst.ORDER_CART_EXISTS + cartId);
// 首次加入购物车,并且拥有起售数,设置为起售数
@@ -131,7 +129,7 @@ public class OrderService {
// 低于起售,删除商品
}else if (exists != null && skuWithBLOBs.getSuit() != null && skuWithBLOBs.getSuit() != 0 && number < skuWithBLOBs.getSuit()){
redisUtil.deleteByKey(RedisCst.ORDER_CART_EXISTS + cartId);
delCart(masterId, cartId);
delCart(masterId, cartId, qrcode);
return Result.success(CodeEnum.SUCCESS, masterId);
}
@@ -147,7 +145,7 @@ public class OrderService {
}
}
if (StringUtils.isEmpty(masterId)) {
if (qrcode == null && StringUtils.isEmpty(masterId)) {
boolean flag = redisUtil.exists("SHOP:CODE:" + clientType + ":" + shopId);
if (flag) {
String code = redisUtil.getMessage("SHOP:CODE:" + clientType + ":" + shopId).toString();
@@ -160,6 +158,8 @@ public class OrderService {
masterId = "#" + String.format("%03d", 1);
}
}
TbCashierCart cart = cashierCartMapper.selectByPrimaryKey(cartId);
if (Objects.nonNull(cart)) {
cart.setSkuId(skuId.toString());
@@ -182,15 +182,23 @@ public class OrderService {
cashierCartMapper.updateByPrimaryKeySelective(cart);
} else {
List<TbCashierCart> list = cashierCartMapper.selectALlByMasterId(masterId, "create");
TbCashierCart cashierCart = cashierCartMapper.selectByDetail(masterId, productId, shopId, skuId.toString(), DateUtils.getDay(), uuid);
List<TbCashierCart> list = StrUtil.isNotBlank(masterId) ? cashierCartMapper.selectALlByMasterId(masterId, "create")
: cashierCartMapper.selectActivateByQrcode(qrcode, Integer.valueOf(shopId));
TbCashierCart cashierCart = StrUtil.isNotBlank(masterId) ? cashierCartMapper.selectByDetail(masterId, productId, shopId, skuId.toString(), DateUtils.getDay(), uuid)
: cashierCartMapper.selectDetailByQrcode(qrcode, productId, shopId, skuId.toString(), uuid);
if (number > 0) {
if (Objects.isNull(cashierCart)) {
cashierCart = new TbCashierCart();
cashierCart.setCoverImg(product.getCoverImg());
cashierCart.setCreatedAt(System.currentTimeMillis());
cashierCart.setIsSku(product.getTypeEnum());
cashierCart.setMasterId(masterId);
if (qrcode != null) {
cashierCart.setTableId(qrcode);
}else {
cashierCart.setMasterId(masterId);
}
cashierCart.setUuid(uuid);
cashierCart.setMerchantId(userId);
cashierCart.setName(product.getName());
@@ -252,7 +260,9 @@ public class OrderService {
skuWithBLOBs.setUpdatedAt(System.currentTimeMillis());
tbProductSkuMapper.updateByPrimaryKey(skuWithBLOBs);
redisUtil.saveMessage("SHOP:CODE:SET" + clientType + ":" + shopId + ":" + DateUtils.getDay(),masterId.substring(1,masterId.length()));
if (StrUtil.isNotBlank(masterId)) {
redisUtil.saveMessage("SHOP:CODE:SET" + clientType + ":" + shopId + ":" + DateUtils.getDay(), masterId.substring(1,masterId.length()));
}
@@ -285,7 +295,7 @@ public class OrderService {
(product.getIsDistribute() == 1 && product.getStockNumber() - num <= productSku.getWarnLine())
|| (product.getIsDistribute() != 1) && productSku.getStockNumber() - num <= productSku.getWarnLine()
) {
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectByShopId(Integer.valueOf(product.getShopId()));
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectStateByShopIdAndType(product.getShopId(), ShopWxMsgTypeEnum.STOCK_MSG.getType());
shopOpenIds.forEach(item -> {
wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
product.getIsDistribute() == 1 ? product.getStockNumber()-num : (int) (productSku.getStockNumber() - num), item.getOpenId());
@@ -293,16 +303,22 @@ public class OrderService {
}
}
public Result queryCart(String masterId, String shopId) {
public Result queryCart(String masterId, String shopId, String qrcode) {
if (StringUtils.isEmpty(shopId)) {
return Result.fail(CodeEnum.SHOPINFONOEXIST);
}
String day = DateUtils.getDay();
List<TbCashierCart> list = cashierCartMapper.selectByMaskerId(masterId, Integer.valueOf(shopId),"create",day);
if (list.size() < 1){
List<TbCashierCart> list;
if (StrUtil.isBlank(masterId)) {
list = cashierCartMapper.selectActivateByQrcode(qrcode, Integer.valueOf(shopId));
}else {
list = cashierCartMapper.selectByMaskerId(masterId, Integer.valueOf(shopId),"create",day);
}
if (StrUtil.isNotBlank(masterId) && list.isEmpty()){
list = cashierCartMapper.selectByMaskerId(masterId, Integer.valueOf(shopId), "refund",day);
if (list.size() > 0){
if (list.size() < 1) {
if (!list.isEmpty()){
if (list.isEmpty()) {
return Result.fail(CodeEnum.CARTJH);
}
int orderId = 0;
@@ -344,7 +360,13 @@ public class OrderService {
}
// TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPr imaryKey(Integer.valueOf(cashierCart.getProductId()));
}
QueryCartPo queryCartPo = cashierCartMapper.selectProductNumByMarketId(day, shopId, masterId);
QueryCartPo queryCartPo;
if (StrUtil.isNotBlank(masterId)) {
queryCartPo = cashierCartMapper.selectProductNumByMarketId(day, shopId, masterId);
}else {
queryCartPo = cashierCartMapper.selectProductNumByQrcode(qrcode, Integer.valueOf(shopId));
}
queryCartPo.setPackAmount(packAmount);
queryCartPo.setTotalAmount(totalAmount);
// queryCartPo.setTotalAmount(totalAmount.add(packAmount));
@@ -355,7 +377,7 @@ public class OrderService {
}
@Transactional(rollbackFor = Exception.class)
public Result delCart(String masterId, Integer cartId) {
public Result delCart(String masterId, Integer cartId, String qrcode) {
TbCashierCart cashierCart=cashierCartMapper.selectByPrimaryKey(cartId);
@@ -387,7 +409,7 @@ public class OrderService {
List<String> skuIds=new ArrayList<>();
skuIds.add(cashierCart.getSkuId());
cashierCartMapper.deleteByCartId(masterId, cartId);
cashierCartMapper.deleteByCartIdOrTableId(masterId, cartId, qrcode);
return Result.success(CodeEnum.SUCCESS);
}

View File

@@ -1,6 +1,8 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
@@ -33,6 +35,11 @@ public class ShopInfoService {
ShopUserDutyMapper shopUserDutyMapper;
@Autowired
ShopUserDutyDetailMapper shopUserDutyDetailMapper;
private final TbOrderInfoMapper orderInfoMapper;
public ShopInfoService(TbOrderInfoMapper orderInfoMapper) {
this.orderInfoMapper = orderInfoMapper;
}
public Result queryShopArea(String shopId){
List<TbShopArea> list= tbShopAreaMapper.selectByShopId(shopId);
@@ -48,6 +55,7 @@ public class ShopInfoService {
PageHelperUtil.startPage(page, pageSize);
List<TbShopTable> shopTables=tbShopTableMapper.selectByShopIdAndStatus(shopId,areaId,status);
PageInfo pageInfo=new PageInfo(shopTables);
return Result.success(CodeEnum.SUCCESS,pageInfo);
}