起售(库存校验)

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

View File

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

View File

@@ -359,7 +359,7 @@ public class CartService {
if (cashierCart.getSkuId().equals(skuId)) {
cashierCart.setTotalNumber(cashierCart.getTotalNumber() + 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());
continue;
}
@@ -502,15 +502,24 @@ public class CartService {
}
TbCashierCart cashierCart = new TbCashierCart();
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();
jsonObject1.put("status", "fail");
jsonObject1.put("msg", "该商品" + productSku.getSuit() + "起售,现库存不足");
jsonObject1.put("msg", "该商品库存不足");
jsonObject1.put("data", new ArrayList<>());
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true);
log.error("购物车添加商品异常,该商品起售库存不足:{}", productId);
throw new MsgException("该商品起售库存不足");
}
}
cashierCart.setNumber(productSku.getSuit());
cashierCart.setTotalNumber(productSku.getSuit());
} else {
@@ -558,6 +567,7 @@ public class CartService {
try {
String shopId = jsonObject.getString("shopId");
String tableId = jsonObject.getString("tableId");
String remark = StringUtils.isBlank(jsonObject.getString("remark"))?"":jsonObject.getString("remark");
String key = tableId + "-" + shopId;
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
List<Integer> ids = new ArrayList<>();
@@ -752,7 +762,7 @@ public class CartService {
orderInfo.setProductAmount(saleAmount);
orderInfo.setIsBuyCoupon(isBuyYhq);
orderInfo.setIsUseCoupon(isuseYhq);
// orderInfo.setRemark(StringUtils.isBlank(jsonObject.getString("remark"))?"":jsonObject.getString("remark"));
orderInfo.setRemark(remark);
orderInfoMapper.updateByPrimaryKeySelective(orderInfo);
} else {
@@ -763,6 +773,7 @@ public class CartService {
orderInfo.setIsBuyCoupon(isBuyYhq);
orderInfo.setIsUseCoupon(isuseYhq);
orderInfo.setUserCouponAmount(couponAmount);
orderInfo.setRemark(remark);
JSONObject object = new JSONObject();
String outNumber = redisUtil.getMessage(RedisCst.OUT_NUMBER.concat(jsonObject.getString("shopId")));

View File

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

View File

@@ -51,6 +51,15 @@
where telephone = #{phone,jdbcType=VARCHAR}
</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 from tb_shop_user
where id = #{id,jdbcType=VARCHAR}
@@ -397,6 +406,10 @@
select * from tb_shop_user where telephone=#{phone} and shop_id=#{shopId}
</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 * from tb_shop_user where user_id=#{userId}
</select>