起售(库存校验)

订单备注
登录时传参
This commit is contained in:
2024-07-20 16:19:33 +08:00
parent 90c834a37d
commit 5593670348
5 changed files with 81 additions and 55 deletions

View File

@@ -121,7 +121,11 @@ public class UserContoller {
} else { } else {
shopUser.setAmount(BigDecimal.ZERO); shopUser.setAmount(BigDecimal.ZERO);
} }
if (tbShopInfo != null) {
shopUser.setShopName(tbShopInfo.getShopName()); shopUser.setShopName(tbShopInfo.getShopName());
}else {
shopUser.setShopName("");
}
return Result.success(CodeEnum.SUCCESS, shopUser); return Result.success(CodeEnum.SUCCESS, shopUser);
} }
@@ -130,24 +134,28 @@ public class UserContoller {
int num = userService.userCoupon(userId, orderNum); int num = userService.userCoupon(userId, orderNum);
return Result.success(CodeEnum.SUCCESS, num); return Result.success(CodeEnum.SUCCESS, num);
} }
@PostMapping("/modityIntegral") @PostMapping("/modityIntegral")
public JSONObject modityIntegral(@RequestHeader String token, @RequestBody IntegralVo integralVo) throws Exception { public JSONObject modityIntegral(@RequestHeader String token, @RequestBody IntegralVo integralVo) throws Exception {
JSONObject jsonObject = TokenUtil.parseParamFromToken(token); JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
String userSign = jsonObject.getString("userSign"); String userSign = jsonObject.getString("userSign");
return userService.modityIntegral(integralVo, userSign); return userService.modityIntegral(integralVo, userSign);
} }
@PostMapping("/userIntegral") @PostMapping("/userIntegral")
public JSONObject userIntegral(@RequestHeader String token, @RequestBody IntegralFlowVo integralFlowVo) throws Exception { public JSONObject userIntegral(@RequestHeader String token, @RequestBody IntegralFlowVo integralFlowVo) throws Exception {
JSONObject jsonObject = TokenUtil.parseParamFromToken(token); JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
String userSign = jsonObject.getString("userSign"); String userSign = jsonObject.getString("userSign");
return userService.userIntegral(integralFlowVo, userSign); return userService.userIntegral(integralFlowVo, userSign);
} }
@PostMapping("/userAllIntegral") @PostMapping("/userAllIntegral")
public JSONObject userAllIntegral(@RequestBody IntegralFlowVo integralFlowVo) throws Exception { public JSONObject userAllIntegral(@RequestBody IntegralFlowVo integralFlowVo) throws Exception {
// JSONObject jsonObject = TokenUtil.parseParamFromToken(token); // JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
// String userSign = jsonObject.getString("userSign"); // String userSign = jsonObject.getString("userSign");
return userService.userAllIntegral(integralFlowVo, "userSign"); return userService.userAllIntegral(integralFlowVo, "userSign");
} }
@PostMapping("/userAll") @PostMapping("/userAll")
public JSONObject userAll(@RequestBody IntegralFlowVo integralFlowVo) throws Exception { public JSONObject userAll(@RequestBody IntegralFlowVo integralFlowVo) throws Exception {
// JSONObject jsonObject = TokenUtil.parseParamFromToken(token); // JSONObject jsonObject = TokenUtil.parseParamFromToken(token);
@@ -156,8 +164,4 @@ public class UserContoller {
} }
} }

View File

@@ -30,6 +30,7 @@ public interface TbShopUserMapper {
TbShopUser selectByUserIdAndShopId(@Param("userId") String userId,@Param("shopId") String shopId); TbShopUser selectByUserIdAndShopId(@Param("userId") String userId,@Param("shopId") String shopId);
TbShopUser selectByPhoneAndShopId(@Param("phone") String phone,@Param("shopId") String shopId); TbShopUser selectByPhoneAndShopId(@Param("phone") String phone,@Param("shopId") String shopId);
TbShopUser selectPCByPhoneAndShopId(@Param("phone") String phone,@Param("shopId") String shopId);
List<TbShopUser> selectAllByUserId(@Param("userId") String userId); List<TbShopUser> selectAllByUserId(@Param("userId") String userId);

View File

@@ -372,7 +372,7 @@ public class CartService {
if (cashierCart.getSkuId().equals(skuId)) { if (cashierCart.getSkuId().equals(skuId)) {
cashierCart.setTotalNumber(cashierCart.getTotalNumber() + buyNum); cashierCart.setTotalNumber(cashierCart.getTotalNumber() + buyNum);
cashierCart.setNumber(cashierCart.getNumber() + buyNum); cashierCart.setNumber(cashierCart.getNumber() + buyNum);
if (buyNum < 0 && tbProductSkuWithBLOBs.getSuit() != null && tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() <= tbProductSkuWithBLOBs.getSuit()) { if (buyNum < 0 && tbProductSkuWithBLOBs.getSuit() != null && tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() < tbProductSkuWithBLOBs.getSuit()) {
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId()); cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
continue; continue;
} }
@@ -515,15 +515,24 @@ public class CartService {
} }
TbCashierCart cashierCart = new TbCashierCart(); TbCashierCart cashierCart = new TbCashierCart();
if (productSku.getSuit() != null && productSku.getSuit() > 1) { if (productSku.getSuit() != null && productSku.getSuit() > 1) {
if (productSku.getSuit() > productSku.getStockNumber()) { if (product.getIsStock() == 1) {
boolean isSale = false;
// 1:共享库存 0:独立库存
if (Integer.valueOf(product.getIsDistribute()).equals(1)) {
if (productSku.getSuit() > product.getStockNumber()) isSale = true;
} else {
if (productSku.getSuit() > productSku.getStockNumber()) isSale = true;
}
if (isSale) {
JSONObject jsonObject1 = new JSONObject(); JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("status", "fail"); jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品" + productSku.getSuit() + "起售,现库存不足"); jsonObject1.put("msg", "该商品库存不足");
jsonObject1.put("data", new ArrayList<>()); jsonObject1.put("data", new ArrayList<>());
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true); PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true);
log.error("购物车添加商品异常,该商品起售库存不足:{}", productId); log.error("购物车添加商品异常,该商品起售库存不足:{}", productId);
throw new MsgException("该商品起售库存不足"); throw new MsgException("该商品起售库存不足");
} }
}
cashierCart.setNumber(productSku.getSuit()); cashierCart.setNumber(productSku.getSuit());
cashierCart.setTotalNumber(productSku.getSuit()); cashierCart.setTotalNumber(productSku.getSuit());
} else { } else {
@@ -571,6 +580,7 @@ public class CartService {
try { try {
String shopId = jsonObject.getString("shopId"); String shopId = jsonObject.getString("shopId");
String tableId = jsonObject.getString("tableId"); String tableId = jsonObject.getString("tableId");
String remark = StringUtils.isBlank(jsonObject.getString("remark"))?"":jsonObject.getString("remark");
String key = tableId + "-" + shopId; String key = tableId + "-" + shopId;
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))); JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
List<Integer> ids = new ArrayList<>(); List<Integer> ids = new ArrayList<>();
@@ -775,7 +785,7 @@ public class CartService {
orderInfo.setProductAmount(saleAmount); orderInfo.setProductAmount(saleAmount);
orderInfo.setIsBuyCoupon(isBuyYhq); orderInfo.setIsBuyCoupon(isBuyYhq);
orderInfo.setIsUseCoupon(isuseYhq); orderInfo.setIsUseCoupon(isuseYhq);
// orderInfo.setRemark(StringUtils.isBlank(jsonObject.getString("remark"))?"":jsonObject.getString("remark")); orderInfo.setRemark(remark);
orderInfoMapper.updateByPrimaryKeySelective(orderInfo); orderInfoMapper.updateByPrimaryKeySelective(orderInfo);
} else { } else {
@@ -786,6 +796,7 @@ public class CartService {
orderInfo.setIsBuyCoupon(isBuyYhq); orderInfo.setIsBuyCoupon(isBuyYhq);
orderInfo.setIsUseCoupon(isuseYhq); orderInfo.setIsUseCoupon(isuseYhq);
orderInfo.setUserCouponAmount(couponAmount); orderInfo.setUserCouponAmount(couponAmount);
orderInfo.setRemark(remark);
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
String outNumber = redisUtil.getMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId"))); String outNumber = redisUtil.getMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId")));

View File

@@ -119,9 +119,6 @@ public class LoginService {
userInfo.setUpdatedAt(System.currentTimeMillis()); userInfo.setUpdatedAt(System.currentTimeMillis());
tbUserInfoMapper.insert(userInfo); tbUserInfoMapper.insert(userInfo);
}else { }else {
userInfo.setHeadImg(ObjectUtil.isNotNull(headImage)?headImage:"");
userInfo.setNickName(ObjectUtil.isNotNull(nickName)?nickName:"微信用户");
userInfo.setTelephone(ObjectUtil.isNotNull(telephone)?telephone:"");
userInfo.setUpdatedAt(System.currentTimeMillis()); userInfo.setUpdatedAt(System.currentTimeMillis());
userInfo.setLastLogInAt(System.currentTimeMillis()); userInfo.setLastLogInAt(System.currentTimeMillis());
tbUserInfoMapper.updateByPrimaryKeySelective(userInfo); tbUserInfoMapper.updateByPrimaryKeySelective(userInfo);

View File

@@ -51,6 +51,15 @@
where telephone = #{phone,jdbcType=VARCHAR} where telephone = #{phone,jdbcType=VARCHAR}
</select> </select>
<select id="selectByShopIdAndPhone" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tb_shop_user
where
shop_id=#{shopId}
and telephone = #{phone,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String"> <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from tb_shop_user delete from tb_shop_user
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
@@ -397,6 +406,10 @@
select * from tb_shop_user where telephone=#{phone} and shop_id=#{shopId} select * from tb_shop_user where telephone=#{phone} and shop_id=#{shopId}
</select> </select>
<select id="selectPCByPhoneAndShopId" resultMap="BaseResultMap">
select * from tb_shop_user where telephone=#{phone} and shop_id=#{shopId} and user_id is null
</select>
<select id="selectAllByUserId" resultMap="BaseResultMap"> <select id="selectAllByUserId" resultMap="BaseResultMap">
select * from tb_shop_user where user_id=#{userId} select * from tb_shop_user where user_id=#{userId}
</select> </select>