扫码点餐部分

This commit is contained in:
2024-08-05 14:19:57 +08:00
parent cf62b19179
commit 4c71d54ec4

View File

@@ -69,8 +69,8 @@ public class ProductService {
@Autowired @Autowired
private TbUserInfoMapper tbUserInfoMapper; private TbUserInfoMapper tbUserInfoMapper;
public Result queryShopIdByTableCode(String userId,String openId,String code,String lat,String lng) { public Result queryShopIdByTableCode(String userId, String openId, String code, String lat, String lng) {
if(StringUtils.isBlank(code)) return Result.fail("桌码信息为空"); if (StringUtils.isBlank(code)) return Result.fail("桌码信息为空");
if (StringUtils.isBlank(lat) || lat.equals("undefined")) { if (StringUtils.isBlank(lat) || lat.equals("undefined")) {
lat = "34.343207"; lat = "34.343207";
lng = "108.939645"; lng = "108.939645";
@@ -88,43 +88,43 @@ public class ProductService {
concurrentMap.put("storeInfo", shopInfo); concurrentMap.put("storeInfo", shopInfo);
concurrentMap.put("distance", distance); concurrentMap.put("distance", distance);
TbShopUser shopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, tbShopTable.getShopId().toString()); TbShopUser shopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, tbShopTable.getShopId().toString());
try{ try {
if (ObjectUtil.isEmpty(shopUser)) { if (ObjectUtil.isEmpty(shopUser)) {
TbUserInfo tbUserInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); TbUserInfo tbUserInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
// shopUser = tbShopUserMapper.selectByPhoneAndShopId(tbUserInfo.getTelephone(), shopId); // shopUser = tbShopUserMapper.selectByPhoneAndShopId(tbUserInfo.getTelephone(), shopId);
// if(ObjectUtil.isEmpty(shopUser)){ // if(ObjectUtil.isEmpty(shopUser)){
shopUser=new TbShopUser(); shopUser = new TbShopUser();
shopUser.setName(tbUserInfo.getNickName()); shopUser.setName(tbUserInfo.getNickName());
shopUser.setSex(tbUserInfo.getSex()); shopUser.setSex(tbUserInfo.getSex());
shopUser.setBirthDay(tbUserInfo.getBirthDay()); shopUser.setBirthDay(tbUserInfo.getBirthDay());
shopUser.setLevel(Byte.parseByte("1")); shopUser.setLevel(Byte.parseByte("1"));
String dynamicCode = RandomUtil.randomNumbers(8); String dynamicCode = RandomUtil.randomNumbers(8);
shopUser.setCode(dynamicCode); shopUser.setCode(dynamicCode);
shopUser.setTelephone(tbUserInfo.getTelephone()); shopUser.setTelephone(tbUserInfo.getTelephone());
shopUser.setAmount(BigDecimal.ZERO); shopUser.setAmount(BigDecimal.ZERO);
shopUser.setIsVip(Byte.parseByte("0")); shopUser.setIsVip(Byte.parseByte("0"));
shopUser.setCreditAmount(BigDecimal.ZERO); shopUser.setCreditAmount(BigDecimal.ZERO);
shopUser.setConsumeAmount(BigDecimal.ZERO); shopUser.setConsumeAmount(BigDecimal.ZERO);
shopUser.setConsumeNumber(0); shopUser.setConsumeNumber(0);
shopUser.setLevelConsume(BigDecimal.ZERO); shopUser.setLevelConsume(BigDecimal.ZERO);
shopUser.setStatus(Byte.parseByte("1")); shopUser.setStatus(Byte.parseByte("1"));
shopUser.setShopId(tbShopTable.getShopId().toString()); shopUser.setShopId(tbShopTable.getShopId().toString());
shopUser.setUserId(userId); shopUser.setUserId(userId);
shopUser.setMiniOpenId(openId); shopUser.setMiniOpenId(openId);
shopUser.setCreatedAt(System.currentTimeMillis()); shopUser.setCreatedAt(System.currentTimeMillis());
shopUser.setUpdatedAt(System.currentTimeMillis()); shopUser.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.insert(shopUser); tbShopUserMapper.insert(shopUser);
// }else { // }else {
// shopUser.setUserId(userId); // shopUser.setUserId(userId);
// shopUser.setUpdatedAt(System.currentTimeMillis()); // shopUser.setUpdatedAt(System.currentTimeMillis());
// tbShopUserMapper.updateByPrimaryKey(shopUser); // tbShopUserMapper.updateByPrimaryKey(shopUser);
// } // }
}else { } else {
shopUser.setUpdatedAt(System.currentTimeMillis()); shopUser.setUpdatedAt(System.currentTimeMillis());
tbShopUserMapper.updateByPrimaryKey(shopUser); tbShopUserMapper.updateByPrimaryKey(shopUser);
} }
}catch (Exception e){ } catch (Exception e) {
log.info("通过桌码获取shopId 进行用户绑定错误:{}",e.getMessage()); log.info("通过桌码获取shopId 进行用户绑定错误:{}", e.getMessage());
e.printStackTrace(); e.printStackTrace();
} }
return Result.success(CodeEnum.SUCCESS, concurrentMap); return Result.success(CodeEnum.SUCCESS, concurrentMap);
@@ -138,7 +138,7 @@ public class ProductService {
if (ObjectUtil.isNotEmpty(tbProducts) && tbProducts.size() > 0) { if (ObjectUtil.isNotEmpty(tbProducts) && tbProducts.size() > 0) {
tbProducts.parallelStream().forEach(it -> { tbProducts.parallelStream().forEach(it -> {
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId())); TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
it.setUnitSnap(tbShopUnit!=null?tbShopUnit.getName():""); it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : "");
it.setCartNumber("0"); it.setCartNumber("0");
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId()); List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId()); TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
@@ -148,7 +148,9 @@ public class ProductService {
AtomicDouble sum = new AtomicDouble(0.0); AtomicDouble sum = new AtomicDouble(0.0);
BigDecimal lowerPrice = null; BigDecimal lowerPrice = null;
for (TbProductSku item : tbProductSkus) { for (TbProductSku item : tbProductSkus) {
sum.addAndGet(item.getStockNumber()); if (item.getRealSalesNumber() != null) {
sum.addAndGet(item.getRealSalesNumber());
}
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) { if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
lowerPrice = item.getSalePrice(); lowerPrice = item.getSalePrice();
} }
@@ -195,12 +197,12 @@ public class ProductService {
List<TbProductGroup> groupList = tbProductGroupMapper.selectByShopId(shopId, id); List<TbProductGroup> groupList = tbProductGroupMapper.selectByShopId(shopId, id);
if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) { if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) {
//热销 //热销
TbProductGroup hot =new TbProductGroup(); TbProductGroup hot = new TbProductGroup();
hot.setName("热销"); hot.setName("热销");
List<TbProduct> hots = tbProductMapper.selectHot(shopId); List<TbProduct> hots = tbProductMapper.selectHot(shopId);
hots.parallelStream().forEach(it -> { hots.parallelStream().forEach(it -> {
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId())); TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
it.setUnitSnap(tbShopUnit!=null?tbShopUnit.getName():""); it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : "");
it.setCartNumber("0"); it.setCartNumber("0");
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId()); List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId()); TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
@@ -210,7 +212,9 @@ public class ProductService {
AtomicDouble sum = new AtomicDouble(0.0); AtomicDouble sum = new AtomicDouble(0.0);
BigDecimal lowerPrice = null; BigDecimal lowerPrice = null;
for (TbProductSku item : tbProductSkus) { for (TbProductSku item : tbProductSkus) {
sum.addAndGet(item.getStockNumber()); if (item.getRealSalesNumber() != null) {
sum.addAndGet(item.getRealSalesNumber());
}
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) { if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
lowerPrice = item.getSalePrice(); lowerPrice = item.getSalePrice();
} }
@@ -260,7 +264,6 @@ public class ProductService {
it.setProductSkuResult(skuResult); it.setProductSkuResult(skuResult);
}); });
hot.setProducts(hots); hot.setProducts(hots);
//商品 //商品
groupList.parallelStream().forEach(g -> { groupList.parallelStream().forEach(g -> {
String in = g.getProductIds().substring(1, g.getProductIds().length() - 1); String in = g.getProductIds().substring(1, g.getProductIds().length() - 1);
@@ -272,7 +275,7 @@ public class ProductService {
if (ObjectUtil.isNotEmpty(products) && products.size() > 0) { if (ObjectUtil.isNotEmpty(products) && products.size() > 0) {
products.parallelStream().forEach(it -> { products.parallelStream().forEach(it -> {
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId())); TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
it.setUnitSnap(tbShopUnit!=null?tbShopUnit.getName():""); it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : "");
it.setCartNumber("0"); it.setCartNumber("0");
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId()); List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId()); TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
@@ -282,7 +285,9 @@ public class ProductService {
AtomicDouble sum = new AtomicDouble(0.0); AtomicDouble sum = new AtomicDouble(0.0);
BigDecimal lowerPrice = null; BigDecimal lowerPrice = null;
for (TbProductSku item : tbProductSkus) { for (TbProductSku item : tbProductSkus) {
sum.addAndGet(item.getStockNumber()); if (item.getRealSalesNumber() != null) {
sum.addAndGet(item.getRealSalesNumber());
}
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) { if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
lowerPrice = item.getSalePrice(); lowerPrice = item.getSalePrice();
} }
@@ -340,7 +345,7 @@ public class ProductService {
g.setProducts(new ArrayList<>()); g.setProducts(new ArrayList<>());
} }
}); });
groupList.add(0, hot);
concurrentMap.put("productInfo", groupList); concurrentMap.put("productInfo", groupList);
} }
@@ -348,13 +353,13 @@ public class ProductService {
} }
public Result queryProductSku(String code,String shopId, String productId, String spec_tag) { public Result queryProductSku(String code, String shopId, String productId, String spec_tag) {
if (ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(productId)) { if (ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(productId)) {
return Result.fail("参数错误"); return Result.fail("参数错误");
} }
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId, productId, spec_tag); TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId, productId, spec_tag);
if(StringUtils.isNotBlank(code)) { if (StringUtils.isNotBlank(code)) {
Integer sum = tbProductMapper.selectByCodeAndSkuId(code, tbProductSkuWithBLOBs.getId(), shopId); Integer sum = tbProductMapper.selectByCodeAndSkuId(code, tbProductSkuWithBLOBs.getId(), shopId);
tbProductSkuWithBLOBs.setNumber(sum); tbProductSkuWithBLOBs.setNumber(sum);
} }
@@ -394,13 +399,13 @@ public class ProductService {
stTime = enTime - 3600000L * 2; stTime = enTime - 3600000L * 2;
} }
shopGroupInfoVos = tbProductMapper.selHotGroups( shopGroupInfoVos = tbProductMapper.selHotGroups(
homeDto.getProName(),homeDto.getType(), homeDto.getProName(), homeDto.getType(),
// DateUtils.getStrTime(new Date(stTime)), DateUtils.getStrTime(new Date(enTime)), // DateUtils.getStrTime(new Date(stTime)), DateUtils.getStrTime(new Date(enTime)),
null, null, null, null,
homeDto.getAddress(), homeDto.getOrderBy().toString(), homeDto.getLng(), homeDto.getLat()); homeDto.getAddress(), homeDto.getOrderBy().toString(), homeDto.getLng(), homeDto.getLat());
} else { } else {
shopGroupInfoVos = tbProductMapper.selGroups( shopGroupInfoVos = tbProductMapper.selGroups(
homeDto.getProName(),homeDto.getType(), homeDto.getProName(), homeDto.getType(),
topAndBottomMap.get("rightTopPoint")[1], topAndBottomMap.get("rightTopPoint")[0], topAndBottomMap.get("rightTopPoint")[1], topAndBottomMap.get("rightTopPoint")[0],
topAndBottomMap.get("leftBottomPoint")[1], topAndBottomMap.get("leftBottomPoint")[0], topAndBottomMap.get("leftBottomPoint")[1], topAndBottomMap.get("leftBottomPoint")[0],
homeDto.getAddress(), homeDto.getOrderBy().toString(), homeDto.getLng(), homeDto.getLat()); homeDto.getAddress(), homeDto.getOrderBy().toString(), homeDto.getLng(), homeDto.getLat());
@@ -546,7 +551,7 @@ public class ProductService {
productInfo.setPhone(tbShopInfo.getPhone()); productInfo.setPhone(tbShopInfo.getPhone());
productInfo.setLat(tbShopInfo.getLat()); productInfo.setLat(tbShopInfo.getLat());
productInfo.setLng(tbShopInfo.getLng()); productInfo.setLng(tbShopInfo.getLng());
if(StringUtils.isNotBlank(tbShopInfo.getBusinessStartDay())){ if (StringUtils.isNotBlank(tbShopInfo.getBusinessStartDay())) {
productInfo.setBusinessTime(tbShopInfo.getBusinessStartDay() + "" + tbShopInfo.getBusinessEndDay() + " " + tbShopInfo.getBusinessTime()); productInfo.setBusinessTime(tbShopInfo.getBusinessStartDay() + "" + tbShopInfo.getBusinessEndDay() + " " + tbShopInfo.getBusinessTime());
} }
String distance = LocationUtils.getDistanceString( String distance = LocationUtils.getDistanceString(
@@ -627,16 +632,16 @@ public class ProductService {
/** /**
* 库存修改 * 库存修改
* *
* @param tbProduct 商品 * @param tbProduct 商品
* @param tbProductSkuWithBLOBs sku * @param tbProductSkuWithBLOBs sku
* @param buyNum 购买数量 * @param buyNum 购买数量
*/ */
public void updateStock(TbProduct tbProduct, TbProductSkuWithBLOBs tbProductSkuWithBLOBs, Integer buyNum) { public void updateStock(TbProduct tbProduct, TbProductSkuWithBLOBs tbProductSkuWithBLOBs, Integer buyNum) {
if (tbProduct.getIsDistribute() == 1) { if (tbProduct.getIsDistribute() == 1) {
if (tbProductMapper.decrStock(String.valueOf(tbProduct.getId()), buyNum) < 1) { if (tbProductMapper.decrStock(String.valueOf(tbProduct.getId()), buyNum) < 1) {
throw new MsgException("库存修改失败,请稍后再试"); throw new MsgException("库存修改失败,请稍后再试");
} }
}else { } else {
if (tbProductSkuMapper.decrStock(String.valueOf(tbProductSkuWithBLOBs.getId()), buyNum) < 1) { if (tbProductSkuMapper.decrStock(String.valueOf(tbProductSkuWithBLOBs.getId()), buyNum) < 1) {
throw new MsgException("库存修改失败,请稍后再试"); throw new MsgException("库存修改失败,请稍后再试");
} }
@@ -648,7 +653,7 @@ public class ProductService {
if (tbProductMapper.decrStock(String.valueOf(id), buyNum) < 1) { if (tbProductMapper.decrStock(String.valueOf(id), buyNum) < 1) {
throw new MsgException("库存不足,下单失败"); throw new MsgException("库存不足,下单失败");
} }
}else { } else {
if (tbProductSkuMapper.decrStock(String.valueOf(skuId), buyNum) < 1) { if (tbProductSkuMapper.decrStock(String.valueOf(skuId), buyNum) < 1) {
throw new MsgException("库存不足,下单失败"); throw new MsgException("库存不足,下单失败");
} }
@@ -660,7 +665,7 @@ public class ProductService {
if (tbProductMapper.decrStockUnCheck(String.valueOf(id), buyNum) < 1) { if (tbProductMapper.decrStockUnCheck(String.valueOf(id), buyNum) < 1) {
throw new MsgException("库存不足,下单失败"); throw new MsgException("库存不足,下单失败");
} }
}else { } else {
if (tbProductSkuMapper.decrStockUnCheck(String.valueOf(skuId), buyNum) < 1) { if (tbProductSkuMapper.decrStockUnCheck(String.valueOf(skuId), buyNum) < 1) {
throw new MsgException("库存不足,下单失败"); throw new MsgException("库存不足,下单失败");
} }