From 1d4963c548ebd9b8e60f572635e9f55b1a6ea143 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Sat, 20 Jul 2024 16:19:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=B7=E5=94=AE(=E5=BA=93=E5=AD=98=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C)=20=E8=AE=A2=E5=8D=95=E5=A4=87=E6=B3=A8=20=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=97=B6=E4=BC=A0=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserContoller.java | 86 ++++++++++--------- .../cashierservice/dao/TbShopUserMapper.java | 1 + .../cashierservice/service/CartService.java | 33 ++++--- .../cashierservice/service/LoginService.java | 3 - .../resources/mapper/TbShopUserMapper.xml | 13 +++ 5 files changed, 81 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java index a3f0cd3..56588d0 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -82,8 +82,8 @@ public class UserContoller { // return jsonObject; // } @GetMapping("/shopUserInfo") - public Result shopUserInfo(@RequestParam("userId") String userId ,@RequestHeader("openId") String openId,@RequestParam("shopId") String shopId ) throws Exception { - TbShopUser shopUser=new TbShopUser(); + public Result shopUserInfo(@RequestParam("userId") String userId, @RequestHeader("openId") String openId, @RequestParam("shopId") String shopId) throws Exception { + TbShopUser shopUser = new TbShopUser(); TbShopInfo tbShopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); if (StringUtils.isNotBlank(shopId) && !shopId.equals("null")) { shopUser = shopUserMapper.selectByUserIdAndShopId(userId, shopId); @@ -91,73 +91,77 @@ public class UserContoller { TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); // shopUser = shopUserMapper.selectByPhoneAndShopId(tbUserInfo.getTelephone(), shopId); // if(ObjectUtil.isEmpty(shopUser)){ - shopUser=new TbShopUser(); - shopUser.setName(tbUserInfo.getNickName()); - shopUser.setSex(tbUserInfo.getSex()); - shopUser.setBirthDay(tbUserInfo.getBirthDay()); - shopUser.setLevel(Byte.parseByte("1")); - String dynamicCode = RandomUtil.randomNumbers(8); - shopUser.setCode(dynamicCode); - shopUser.setTelephone(tbUserInfo.getTelephone()); - shopUser.setAmount(BigDecimal.ZERO); - shopUser.setIsVip(Byte.parseByte("0")); - shopUser.setCreditAmount(BigDecimal.ZERO); - shopUser.setConsumeAmount(BigDecimal.ZERO); - shopUser.setConsumeNumber(0); - shopUser.setLevelConsume(BigDecimal.ZERO); - shopUser.setStatus(Byte.parseByte("1")); - shopUser.setShopId(shopId); - shopUser.setUserId(userId); - shopUser.setMiniOpenId(openId); - shopUser.setCreatedAt(System.currentTimeMillis()); - shopUser.setUpdatedAt(System.currentTimeMillis()); - shopUserMapper.insert(shopUser); + shopUser = new TbShopUser(); + shopUser.setName(tbUserInfo.getNickName()); + shopUser.setSex(tbUserInfo.getSex()); + shopUser.setBirthDay(tbUserInfo.getBirthDay()); + shopUser.setLevel(Byte.parseByte("1")); + String dynamicCode = RandomUtil.randomNumbers(8); + shopUser.setCode(dynamicCode); + shopUser.setTelephone(tbUserInfo.getTelephone()); + shopUser.setAmount(BigDecimal.ZERO); + shopUser.setIsVip(Byte.parseByte("0")); + shopUser.setCreditAmount(BigDecimal.ZERO); + shopUser.setConsumeAmount(BigDecimal.ZERO); + shopUser.setConsumeNumber(0); + shopUser.setLevelConsume(BigDecimal.ZERO); + shopUser.setStatus(Byte.parseByte("1")); + shopUser.setShopId(shopId); + shopUser.setUserId(userId); + shopUser.setMiniOpenId(openId); + shopUser.setCreatedAt(System.currentTimeMillis()); + shopUser.setUpdatedAt(System.currentTimeMillis()); + shopUserMapper.insert(shopUser); // }else { // shopUser.setUserId(userId); // shopUser.setUpdatedAt(System.currentTimeMillis()); // shopUserMapper.updateByPrimaryKey(shopUser); // } } - }else { + } else { shopUser.setAmount(BigDecimal.ZERO); } - shopUser.setShopName(tbShopInfo.getShopName()); - return Result.success(CodeEnum.SUCCESS,shopUser); + if (tbShopInfo != null) { + shopUser.setShopName(tbShopInfo.getShopName()); + }else { + shopUser.setShopName(""); + } + return Result.success(CodeEnum.SUCCESS, shopUser); } @GetMapping("/userCoupon") - public Result userCoupon(@RequestParam("userId") String userId ,@RequestParam("orderNum") BigDecimal orderNum ) throws Exception { - int num = userService.userCoupon(userId,orderNum); - return Result.success(CodeEnum.SUCCESS,num); + public Result userCoupon(@RequestParam("userId") String userId, @RequestParam("orderNum") BigDecimal orderNum) throws Exception { + 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 { + 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); + return userService.modityIntegral(integralVo, userSign); } + @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); String userSign = jsonObject.getString("userSign"); - return userService.userIntegral(integralFlowVo,userSign); + return userService.userIntegral(integralFlowVo, userSign); } + @PostMapping("/userAllIntegral") - public JSONObject userAllIntegral(@RequestBody IntegralFlowVo integralFlowVo ) throws Exception { + public JSONObject userAllIntegral(@RequestBody IntegralFlowVo integralFlowVo) throws Exception { // JSONObject jsonObject = TokenUtil.parseParamFromToken(token); // String userSign = jsonObject.getString("userSign"); - return userService.userAllIntegral(integralFlowVo,"userSign"); + return userService.userAllIntegral(integralFlowVo, "userSign"); } + @PostMapping("/userAll") - public JSONObject userAll(@RequestBody IntegralFlowVo integralFlowVo ) throws Exception { + public JSONObject userAll(@RequestBody IntegralFlowVo integralFlowVo) throws Exception { // JSONObject jsonObject = TokenUtil.parseParamFromToken(token); // String userSign = jsonObject.getString("userSign"); - return userService.userAll(integralFlowVo,"userSign"); + return userService.userAll(integralFlowVo, "userSign"); } - - - - } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java index ab3069b..a87fe71 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopUserMapper.java @@ -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 selectAllByUserId(@Param("userId") String userId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index b63c266..c0e15e9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -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,18 +502,27 @@ public class CartService { } TbCashierCart cashierCart = new TbCashierCart(); if (productSku.getSuit() != null && productSku.getSuit() > 1) { - if (productSku.getSuit() > productSku.getStockNumber()) { - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "该商品" + productSku.getSuit() + "起售,现库存不足"); - jsonObject1.put("data", new ArrayList<>()); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true); - log.error("购物车添加商品异常,该商品起售库存不足:{}", productId); - throw new MsgException("该商品起售库存不足"); + 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", "该商品库存不足"); + 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 { + } else { cashierCart.setNumber(num); cashierCart.setTotalNumber(num); } @@ -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 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"))); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java index dee9506..6f5ff31 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -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); diff --git a/src/main/resources/mapper/TbShopUserMapper.xml b/src/main/resources/mapper/TbShopUserMapper.xml index 81b88c4..e13ffa6 100644 --- a/src/main/resources/mapper/TbShopUserMapper.xml +++ b/src/main/resources/mapper/TbShopUserMapper.xml @@ -51,6 +51,15 @@ where telephone = #{phone,jdbcType=VARCHAR} + + 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} + +