From 5ad0eea8541725bab6ae82becad90b408abac2f7 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Mon, 5 Aug 2024 09:51:33 +0800 Subject: [PATCH 01/28] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81=E7=94=9F=E6=88=90=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/CommonController.java | 5 +++-- .../system/cashierservice/wxUtil/WxAccountUtil.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index e0f3a47..79ca76c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -208,7 +208,6 @@ public class CommonController { redisUtil.getIncrNum(key, "2"); } - /** * 订阅消息 * @param wxMsgSubDTO @@ -220,7 +219,9 @@ public class CommonController { if (wxMsgSubDTO.getOpenId() == null || wxMsgSubDTO.getShopId() == null) { return Result.fail("shopId或openId缺失"); } - loginService.addShopId(wxMsgSubDTO.getOpenId(), wxMsgSubDTO.getShopId(), wxMsgSubDTO.getType()); + String msg = wxMsgSubDTO.getShopId().replace("msg", ""); + String[] split = msg.split(","); + loginService.addShopId(wxMsgSubDTO.getOpenId(), split[0], split.length > 1 ? Integer.valueOf(split[1]) : null); return Result.success(CodeEnum.SUCCESS); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java index 62349d0..35e9098 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java @@ -53,7 +53,7 @@ public class WxAccountUtil { req.put("action_name", "QR_STR_SCENE"); HashMap actionInfo = new HashMap<>(); HashMap scene = new HashMap<>(); - scene.put("scene_str", "msg" + shopId + ":" + type); + scene.put("scene_str", "msg" + shopId + "," + type); actionInfo.put("scene", scene); req.put("action_info", actionInfo); log.info("开始获取公众号二维码, 请求数据: {}", req); From cf62b1917946cb3f24a72ea8477a2e0cd8a3ac8d Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Mon, 5 Aug 2024 11:40:49 +0800 Subject: [PATCH 02/28] =?UTF-8?q?=E6=89=AB=E7=A0=81=E7=82=B9=E9=A4=90?= =?UTF-8?q?=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ProductController.java | 36 +- .../cashierservice/dao/TbProductMapper.java | 4 + .../entity/TbProductSkuWithBLOBs.java | 10 + .../cashierservice/rabbit/CartConsumer.java | 20 +- .../cashierservice/service/CartService.java | 416 ++++++------------ .../service/ProductService.java | 189 ++++++-- .../resources/mapper/TbProductGroupMapper.xml | 4 +- src/main/resources/mapper/TbProductMapper.xml | 47 +- 8 files changed, 389 insertions(+), 337 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java index 3602a64..8392851 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java @@ -3,11 +3,11 @@ package com.chaozhanggui.system.cashierservice.controller; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; +import com.chaozhanggui.system.cashierservice.service.CartService; import com.chaozhanggui.system.cashierservice.service.ProductService; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; -import com.chaozhanggui.system.cashierservice.util.TokenUtil; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -22,6 +22,8 @@ public class ProductController { @Autowired private ProductService productService; + @Autowired + private CartService cartService; /** * 通过桌码获取shopId @@ -29,12 +31,15 @@ public class ProductController { * @param code * @return shopid */ - @RequestMapping("queryShopIdByTableCode") + @RequestMapping("queryShop") public Result queryShopIdByTableCode( @RequestHeader("openId") String openId, @RequestHeader("id") String userId, - @RequestParam("code") String code) { - return productService.queryShopIdByTableCode(userId, openId, code); + @RequestParam String lat, + @RequestParam String lng, + @RequestParam("code") String code + ) { + return productService.queryShopIdByTableCode(userId, openId, code,lat,lng); } /** @@ -46,24 +51,39 @@ public class ProductController { @RequestMapping("queryProduct") public Result queryProduct(@RequestBody Map map) { - if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("code")) { + if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("shopId")) { return Result.fail("参数错误"); } return productService.queryProduct( - map.get("code").toString(), + map.get("shopId").toString(), (map.containsKey("productGroupId") && ObjectUtil.isNotEmpty(map.get("productGroupId"))) ? map.get("productGroupId").toString() : ""); } @GetMapping("queryProductSku") public Result queryProductSku( + @RequestParam(value = "code", required = false) String code, @RequestParam("shopId") String shopId, @RequestParam("productId") String productId, @RequestParam("spec_tag") String spec_tag ) { - return productService.queryProductSku(shopId, productId, spec_tag); + return productService.queryProductSku(code,shopId, productId, spec_tag); } + @PostMapping("addCart") + public Result addCart(@RequestBody JSONObject jsonObject) { + log.info("添加购物车数据:{}", jsonObject); + return cartService.createCart(jsonObject); + } + + @PostMapping("cleanCart") + public Result cleanCart(@RequestBody JSONObject jsonObject) { + log.info("清空购物车数据:{}", jsonObject); + cartService.clearCart(jsonObject); + return Result.success(CodeEnum.SUCCESS); + } + + /** * 团购商品详情/商品类型为 套餐商品 */ diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java index 491fdce..3968f0d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java @@ -20,9 +20,13 @@ public interface TbProductMapper { List selectByIdIn(@Param("ids") String ids); List selectByIdInAndCheck(@Param("ids") String ids); + List selectHot(@Param("shopId") String shopId); + + List selectIsSpecialty(@Param("shopId") Integer shopId); List selectByIds(@Param("list") List ids); Integer selectByQcode(@Param("code") String code,@Param("productId") Integer productId,@Param("shopId") String shopId); + Integer selectByCodeAndSkuId(@Param("code") String code,@Param("skuId") Integer skuId,@Param("shopId") String shopId); Integer selectByNewQcode(@Param("code") String code,@Param("productId") Integer productId,@Param("shopId") String shopId,@Param("list") List list); List selGroups(@Param("proName") String proName,@Param("type") String type, diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductSkuWithBLOBs.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductSkuWithBLOBs.java index f2af49c..ee7e414 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductSkuWithBLOBs.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductSkuWithBLOBs.java @@ -7,8 +7,18 @@ public class TbProductSkuWithBLOBs extends TbProductSku implements Serializable private String specSnap; + private Integer number; + private static final long serialVersionUID = 1L; + public Integer getNumber() { + return number; + } + + public void setNumber(Integer number) { + this.number = number; + } + public String getSpecInfo() { return specInfo; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java index fc41fcd..c3c1d16 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java @@ -36,12 +36,14 @@ public class CartConsumer { String shopId = jsonObject.getString("shopId"); if (jsonObject.getString("type").equals("initCart") ) { cartService.initCart(jsonObject); - }else if (jsonObject.getString("type").equals("addcart") ) { - if (!jsonObject.containsKey("num")) { - throw new MsgException("商品数量错误"); - } - cartService.createCart(jsonObject); - }else if (jsonObject.getString("type").equals("queryCart") ) { + } +// else if (jsonObject.getString("type").equals("addcart") ) { +// if (!jsonObject.containsKey("num")) { +// throw new MsgException("商品数量错误"); +// } +// cartService.createCart(jsonObject); +// } + else if (jsonObject.getString("type").equals("queryCart") ) { cartService.queryCart(jsonObject); } else if(jsonObject.getString("type").equals("createOrder")){ String cartDetail = redisUtil.getMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId)); @@ -54,9 +56,9 @@ public class CartConsumer { cartService.createOrder(jsonObject); } } - else if(jsonObject.getString("type").equals("clearCart")){ - cartService.clearCart(jsonObject); - } +// else if(jsonObject.getString("type").equals("clearCart")){ +// cartService.clearCart(jsonObject); +// } } catch (Exception e) { log.info("数据处理失败:{}",e.getMessage()); e.printStackTrace(); 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 54f1cea..a967298 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -11,6 +11,8 @@ import com.chaozhanggui.system.cashierservice.netty.PushToAppChannelHandlerAdapt import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisUtil; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; +import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.JSONUtil; import com.chaozhanggui.system.cashierservice.util.LockUtils; @@ -130,300 +132,150 @@ public class CartService { * 加入购物车 * @param jsonObject 商品信息 */ - // @Transactional(rollbackFor = Exception.class) -// public void createCart(JSONObject jsonObject) { -// try { -// String tableId = jsonObject.getString("tableId"); -// String shopId = jsonObject.getString("shopId"); -// String productId = jsonObject.getString("productId"); -// -// String key = tableId + "-" + shopId; -// TbProduct tbProduct = productMapper.selectById(Integer.valueOf(productId)); -// if (tbProduct == null) { -// JSONObject jsonObject1 = new JSONObject(); -// jsonObject1.put("status", "fail"); -// jsonObject1.put("msg", "该商品不存在"); -// jsonObject1.put("data", new ArrayList<>()); -// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); -// log.error("该商品不存在 productId:{}", productId); -// throw new MsgException("该商品不存在"); -// } -// -// String skuId = jsonObject.getString("skuId"); -// JSONArray jsonArray = new JSONArray(); -// BigDecimal amount = BigDecimal.ZERO; -// TbProductSkuWithBLOBs tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId)); -// -// -// -// -// JSONObject objectMsg=new JSONObject(); -// objectMsg.put("skuId",tbProductSkuWithBLOBs.getId()); -// objectMsg.put("shopId",Integer.valueOf(shopId)); -// -// -// producer.con_msg(objectMsg.toString()); -// -// -// if (Integer.valueOf(tbProduct.getIsPauseSale()).equals(1)) { -// JSONObject jsonObject1 = new JSONObject(); -// jsonObject1.put("status", "fail"); -// jsonObject1.put("msg", "该商品已售罄"); -// jsonObject1.put("data", new ArrayList<>()); -// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); -// log.error("该商品已售罄 productId:{}", productId); -// throw new MsgException("该商品已售罄"); -// } -// -// String skuNum; -// -// // 1:共享库存 0:独立库存 -// if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) { -// boolean exist = redisUtil.exists(RedisCst.PRODUCT + shopId + ":product" + productId); -// if (!exist) { -// redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":product" + productId, tbProduct.getStockNumber() + ""); -// } -// skuNum = redisUtil.getMessage(RedisCst.PRODUCT + shopId + ":product" + productId); -// -// if (!skuNum.equals(tbProduct.getStockNumber() + "")) { -// skuNum = tbProduct.getStockNumber() + ""; -// redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":product" + productId, skuNum); -// } -// } else { -// boolean exist = redisUtil.exists(RedisCst.PRODUCT + shopId + ":" + skuId); -// if (!exist) { -// Double stock = tbProductSkuWithBLOBs.getStockNumber(); -// redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":" + skuId, Math.round(stock) + ""); -// } -// skuNum = redisUtil.getMessage(RedisCst.PRODUCT + shopId + ":" + skuId); -// -// if (!skuNum.equals(Math.round(tbProductSkuWithBLOBs.getStockNumber()) + "")) { -// skuNum = Math.round(tbProductSkuWithBLOBs.getStockNumber()) + ""; -// redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":product" + productId, skuNum); -// } -// } -// -// Integer buyNum = jsonObject.getInteger("num"); -// if (tbProduct.getIsStock() == 1) { -// boolean flag = false; -// -// String id = skuId; -// if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) { -// if (tbProduct.getStockNumber() < 1 && buyNum > 0) { -// flag = true; -// id = productId; -// } -// } else { -// if (tbProductSkuWithBLOBs.getIsPauseSale().equals(1)) { -// flag = true; -// } else if (Integer.valueOf(skuNum) < 1 && buyNum > 0) { -// flag = true; -// } -// } -// -// if (flag) { -// JSONObject jsonObject1 = new JSONObject(); -// jsonObject1.put("status", "fail"); -// jsonObject1.put("msg", "该商品库存已售罄"); -// jsonObject1.put("data", new ArrayList<>()); -// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); -// log.error("该商品库存已售罄 skuId:{}", id); -// throw new MsgException("该商品库存已售罄"); -// } -// } -// -// if (redisUtil.exists(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)))); -// if (Objects.isNull(array) || array.isEmpty()) { -// if (buyNum > 0) { -// TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId, -// jsonObject.getInteger("userId"), buyNum, tableId, shopId); -// jsonArray.add(cashierCart); -// amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); -// -// updateProductStock(tbProduct, tbProductSkuWithBLOBs, buyNum); -// } -// } else { -// boolean flag = true; -// for (int i = 0; i < array.size(); i++) { -// JSONObject object = array.getJSONObject(i); -// TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); -// if (cashierCart.getSkuId().equals(skuId)) { -// cashierCart.setTotalNumber(cashierCart.getTotalNumber() + buyNum); -// cashierCart.setNumber(cashierCart.getNumber() + buyNum); -// updateProductStock(tbProduct, tbProductSkuWithBLOBs, buyNum); -// if (cashierCart.getNumber() > 0) { -// cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); -// cashierCart.setUpdatedAt(Instant.now().toEpochMilli()); -// cashierCartMapper.updateByPrimaryKeySelective(cashierCart); -// } else { -// cashierCartMapper.deleteByPrimaryKey(cashierCart.getId()); -// continue; -// } -// flag = false; -// } -// jsonArray.add(cashierCart); -// amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); -// } -// if (flag && buyNum > 0) { -// TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId, -// jsonObject.getInteger("userId"), buyNum, tableId, jsonObject.getString("shopId")); -// jsonArray.add(cashierCart); -// amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); -// updateProductStock(tbProduct, tbProductSkuWithBLOBs, buyNum); -// } -// } -// } else { -// if (buyNum > 0) { -// TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId, -// jsonObject.getInteger("userId"), buyNum, tableId, jsonObject.getString("shopId")); -// jsonArray.add(cashierCart); -// amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); -// updateProductStock(tbProduct, tbProductSkuWithBLOBs, buyNum); -// } -// } -// redisUtil.saveMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId), jsonArray.toJSONString()); -// JSONObject jsonObject1 = new JSONObject(); -// jsonObject1.put("status", "success"); -// jsonObject1.put("msg", "成功"); -// jsonObject1.put("type", jsonObject.getString("type")); -// jsonObject1.put("data", jsonArray); -// jsonObject1.put("amount", amount); -// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false); -// } catch (Exception e) { -// log.error("长链接错误 createCart{}", e.getMessage()); -// } -// } - public void createCart(JSONObject jsonObject) { + public Result createCart(JSONObject jsonObject) { try { String tableId = jsonObject.getString("tableId"); String shopId = jsonObject.getString("shopId"); String productId = jsonObject.getString("productId"); + String skuId = jsonObject.getString("skuId"); + Integer type = jsonObject.getInteger("type"); + Integer buyNum = jsonObject.getInteger("num"); + if (StringUtils.isBlank(tableId) || StringUtils.isBlank(shopId) || StringUtils.isBlank(productId) + || StringUtils.isBlank(skuId) || type==null || buyNum == null) { + return Result.fail("参数缺失"); + } String key = tableId + "-" + shopId; TbProduct tbProduct = productMapper.selectById(Integer.valueOf(productId)); if (tbProduct == null) { - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "该商品不存在"); - jsonObject1.put("data", new ArrayList<>()); - jsonObject1.put("reqData", jsonObject); - - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); log.error("该商品不存在 productId:{}", productId); - throw new MsgException("该商品不存在"); + return Result.fail("该商品不存在"); } - - Integer buyNum = jsonObject.getInteger("num"); - - String skuId = jsonObject.getString("skuId"); // 判断商品是否已下架 TbProductSkuWithBLOBs tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId)); if (tbProductSkuWithBLOBs ==null || tbProductSkuWithBLOBs.getIsGrounding().equals(0)) { - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "此商品已下架"); - jsonObject1.put("data", new ArrayList<>()); - jsonObject1.put("reqData", jsonObject); - - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.error("商品已下架 skuId:{}", skuId); - return; + rmCart(jsonObject,skuId,key); + return Result.fail("商品已下架"); } - if (tbProduct.getIsStock() == 1) { // 1:共享库存 0:独立库存 if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) { - if (tbProduct.getIsPauseSale() == 1 || tbProduct.getStockNumber() < buyNum ) {//是否售罄 - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "该商品已售罄"); - jsonObject1.put("data", new ArrayList<>()); - jsonObject1.put("reqData", jsonObject); - - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.error("该商品已售罄 productId:{}", productId); - throw new MsgException("该商品已售罄"); + if (tbProduct.getIsPauseSale() == 1) {//是否售罄 + rmCart(jsonObject,skuId,key); + return Result.fail("该商品已售罄"); } } else { - if (tbProductSkuWithBLOBs.getIsPauseSale() == 1 || tbProductSkuWithBLOBs.getStockNumber() < buyNum ) {//是否售罄 - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "该商品已售罄"); - jsonObject1.put("data", new ArrayList<>()); - jsonObject1.put("reqData", jsonObject); - - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.error("该商品已售罄 productId:{}", productId); - throw new MsgException("该商品已售罄"); + if (tbProductSkuWithBLOBs.getIsPauseSale() == 1) {//是否售罄 + rmCart(jsonObject,skuId,key); + return Result.fail("该商品已售罄"); } } } JSONArray jsonArray = new JSONArray(); BigDecimal amount = BigDecimal.ZERO; - - if (redisUtil.exists(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)))); - if (Objects.isNull(array) || array.isEmpty()) { - if (buyNum > 0) { - TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId, - jsonObject.getInteger("userId"), buyNum, tableId, shopId); - jsonArray.add(cashierCart); - amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + try{ + if (redisUtil.exists(RedisCst.TABLE_CART.concat(key))) { + JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(key))); + if (Objects.isNull(array) || array.isEmpty()) { + if (type == 1) { + TbCashierCart cashierCart = addCart(productId, skuId, + jsonObject.getInteger("userId"), buyNum, tableId, shopId); + jsonArray.add(cashierCart); + amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + } + } else { + boolean flag = true; + for (int i = 0; i < array.size(); i++) { + JSONObject object = array.getJSONObject(i); + TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); + if (cashierCart.getSkuId().equals(skuId)) { + cashierCart.setTotalNumber(buyNum); + cashierCart.setNumber(buyNum); + if (type == 0 && tbProductSkuWithBLOBs.getSuit() != null && tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() < tbProductSkuWithBLOBs.getSuit()) { + cashierCartMapper.deleteByPrimaryKey(cashierCart.getId()); + continue; + } + if (cashierCart.getNumber() > 0) { + cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + cashierCart.setUpdatedAt(Instant.now().toEpochMilli()); + cashierCartMapper.updateByPrimaryKeySelective(cashierCart); + } else { + cashierCartMapper.deleteByPrimaryKey(cashierCart.getId()); + continue; + } + flag = false; + } + jsonArray.add(cashierCart); + amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + } + if (flag && type == 1) { + TbCashierCart cashierCart = addCart(productId, skuId, + jsonObject.getInteger("userId"), buyNum, tableId, shopId); + jsonArray.add(cashierCart); + amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + } } } else { - boolean flag = true; - for (int i = 0; i < array.size(); i++) { - JSONObject object = array.getJSONObject(i); - TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); - 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()) { - cashierCartMapper.deleteByPrimaryKey(cashierCart.getId()); - continue; - } - if (cashierCart.getNumber() > 0) { - cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); - cashierCart.setUpdatedAt(Instant.now().toEpochMilli()); - cashierCartMapper.updateByPrimaryKeySelective(cashierCart); - } else { - cashierCartMapper.deleteByPrimaryKey(cashierCart.getId()); - continue; - } - flag = false; - } - jsonArray.add(cashierCart); - amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); - } - if (flag && buyNum > 0) { - TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId, - jsonObject.getInteger("userId"), buyNum, tableId, jsonObject.getString("shopId")); + if (type == 1) { + TbCashierCart cashierCart = addCart(productId, skuId, + jsonObject.getInteger("userId"), buyNum, tableId, shopId); jsonArray.add(cashierCart); amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); } } - } else { - if (buyNum > 0) { - TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId, - jsonObject.getInteger("userId"), buyNum, tableId, jsonObject.getString("shopId")); - jsonArray.add(cashierCart); - amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + }catch (MsgException e){ + if(e.getMessage().equals("商品起售库存不足")){ + return Result.fail("商品起售库存不足"); } } - redisUtil.saveMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId), jsonArray.toJSONString()); + redisUtil.saveMessage(RedisCst.TABLE_CART.concat(key), jsonArray.toJSONString()); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "success"); jsonObject1.put("msg", "成功"); - jsonObject1.put("type", jsonObject.getString("type")); + jsonObject1.put("type", "addcart"); jsonObject1.put("data", jsonArray); jsonObject1.put("amount", amount); jsonObject1.put("reqData", jsonObject); - - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false); + PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, "", false); } catch (Exception e) { log.error("长链接错误 createCart{}", e.getMessage()); } + return Result.success(CodeEnum.SUCCESS); } + + private void rmCart(JSONObject jsonObject,String skuId, String key) { + JSONArray jsonArray = new JSONArray(); + BigDecimal amount = BigDecimal.ZERO; + if (redisUtil.exists(RedisCst.TABLE_CART.concat(key))) { + JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(key))); + if (!Objects.isNull(array) && !array.isEmpty()) { + boolean flag = false; + for (int i = 0; i < array.size(); i++) { + JSONObject object = array.getJSONObject(i); + TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); + if (cashierCart.getSkuId().equals(skuId)) { + cashierCartMapper.deleteByPrimaryKey(cashierCart.getId()); + flag = true; + continue; + } + jsonArray.add(cashierCart); + amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + } + redisUtil.saveMessage(RedisCst.TABLE_CART.concat(key), jsonArray.toJSONString()); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "success"); + jsonObject1.put("msg", "成功"); + jsonObject1.put("type", "addcart"); + jsonObject1.put("data", jsonArray); + jsonObject1.put("amount", amount); + jsonObject1.put("reqData", jsonObject); + if(flag){ + PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, "", false); + } + } + } + } + + /** * 修改库存并根据警告线发送消息 * @@ -500,51 +352,40 @@ public class CartService { } } - private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId) throws RuntimeException { + private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId) throws Exception{ try { TbProduct product = productMapper.selectById(Integer.valueOf(productId)); String key = tableId + "-" + shopId; - if (Objects.isNull(product)) { - 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("该商品不存在"); - } TbProductSkuWithBLOBs productSku = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId)); - if (Objects.isNull(productSku)) { - 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("购物车添加商品异常,该商品sku不存在:{}", productId); - throw new MsgException("该商品规格不存在"); - } TbCashierCart cashierCart = new TbCashierCart(); if (productSku.getSuit() != null && productSku.getSuit() > 1) { if (product.getIsStock() == 1) { boolean isSale = false; // 1:共享库存 0:独立库存 if (Integer.valueOf(product.getIsDistribute()).equals(1)) { - if (productSku.getSuit() > product.getStockNumber()) isSale = true; + if (num > productSku.getSuit()) { + if (num > product.getStockNumber()) isSale = true; + }else { + if (productSku.getSuit() > product.getStockNumber()) isSale = true; + } } else { - if (productSku.getSuit() > productSku.getStockNumber()) isSale = true; + if (num > productSku.getSuit()) { + if (num > productSku.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("该商品起售库存不足"); + throw new MsgException("商品起售库存不足"); } } - cashierCart.setNumber(productSku.getSuit()); - cashierCart.setTotalNumber(productSku.getSuit()); + if(num > productSku.getSuit()){ + cashierCart.setNumber(num); + cashierCart.setTotalNumber(num); + }else { + cashierCart.setNumber(productSku.getSuit()); + cashierCart.setTotalNumber(productSku.getSuit()); + } } else { cashierCart.setNumber(num); cashierCart.setTotalNumber(num); @@ -592,8 +433,7 @@ public class CartService { 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<>(); + JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(key))); BigDecimal totalAmount = BigDecimal.ZERO; BigDecimal packAMount = BigDecimal.ZERO; BigDecimal originAmount = BigDecimal.ZERO; @@ -602,7 +442,7 @@ public class CartService { BigDecimal couponAmount = BigDecimal.ZERO; List orderDetails = new ArrayList<>(); Integer orderId = 0; - TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(jsonObject.getString("shopId")); + TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(shopId); if (tbMerchantAccount == null) { MsgException.throwException("生成订单错误"); } @@ -643,7 +483,7 @@ public class CartService { } catch (Exception e) { JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "商品库存不足" + tbProduct1.getName()); + jsonObject1.put("msg", tbProduct1.getName() + "库存不足"); jsonObject1.put("data", new ArrayList<>()); PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); return; @@ -949,7 +789,7 @@ public class CartService { JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("status", "success"); jsonObject1.put("msg", "成功"); - jsonObject1.put("type", "clearCart"); + jsonObject1.put("type", "addcart"); jsonObject1.put("amount", BigDecimal.ZERO); jsonObject1.put("data", new ArrayList<>()); // //修改耗材数据 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index fb14ee6..0b08f50 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -16,6 +16,7 @@ import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.*; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.google.common.util.concurrent.AtomicDouble; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -68,13 +69,25 @@ public class ProductService { @Autowired private TbUserInfoMapper tbUserInfoMapper; - public Result queryShopIdByTableCode(String userId,String openId,String code) { - String shopId = tbShopTableMapper.queryShopIdByTableCode(code); - if (StringUtils.isBlank(shopId)) { + public Result queryShopIdByTableCode(String userId,String openId,String code,String lat,String lng) { + if(StringUtils.isBlank(code)) return Result.fail("桌码信息为空"); + if (StringUtils.isBlank(lat) || lat.equals("undefined")) { + lat = "34.343207"; + lng = "108.939645"; + } + TbShopTable tbShopTable = tbShopTableMapper.selectQRcode(code); + if (tbShopTable == null) { return Result.fail("台桌信息不存在"); } - - TbShopUser shopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, shopId); + TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(tbShopTable.getShopId()); + String distance = LocationUtils.getDistanceString( + Double.parseDouble(lng), Double.parseDouble(lat), + Double.parseDouble(shopInfo.getLng()), Double.parseDouble(shopInfo.getLat())); + ConcurrentMap concurrentMap = new ConcurrentHashMap<>(); + concurrentMap.put("shopTableInfo", tbShopTable); + concurrentMap.put("storeInfo", shopInfo); + concurrentMap.put("distance", distance); + TbShopUser shopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, tbShopTable.getShopId().toString()); try{ if (ObjectUtil.isEmpty(shopUser)) { TbUserInfo tbUserInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); @@ -95,7 +108,7 @@ public class ProductService { shopUser.setConsumeNumber(0); shopUser.setLevelConsume(BigDecimal.ZERO); shopUser.setStatus(Byte.parseByte("1")); - shopUser.setShopId(shopId); + shopUser.setShopId(tbShopTable.getShopId().toString()); shopUser.setUserId(userId); shopUser.setMiniOpenId(openId); shopUser.setCreatedAt(System.currentTimeMillis()); @@ -114,27 +127,141 @@ public class ProductService { log.info("通过桌码获取shopId 进行用户绑定错误:{}",e.getMessage()); e.printStackTrace(); } - return Result.success(CodeEnum.SUCCESS, shopId); + return Result.success(CodeEnum.SUCCESS, concurrentMap); } - public Result queryProduct(String code, String productGroupId) { - + public Result queryProduct(String shopId, String productGroupId) { ConcurrentMap concurrentMap = new ConcurrentHashMap<>(); - - TbShopTable tbShopTable = tbShopTableMapper.selectQRcode(code); - if (ObjectUtil.isEmpty(tbShopTable) || ObjectUtil.isNull(tbShopTable)) { - return Result.fail("台桌信息不存在"); - } - - Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null; - List groupList = tbProductGroupMapper.selectByQrcode(code, id); - if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) { + //招牌菜 + List tbProducts = tbProductMapper.selectIsSpecialty(Integer.valueOf(shopId)); + if (ObjectUtil.isNotEmpty(tbProducts) && tbProducts.size() > 0) { + tbProducts.parallelStream().forEach(it -> { + TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId())); + it.setUnitSnap(tbShopUnit!=null?tbShopUnit.getName():""); + it.setCartNumber("0"); + List tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId()); + TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId()); - TbProductGroup group = groupList.get(0); - TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(group.getShopId()); - concurrentMap.put("shopTableInfo", tbShopTable); - concurrentMap.put("storeInfo", shopInfo); + // 上下架对应的sku + HashSet specSet = new HashSet<>(); + AtomicDouble sum = new AtomicDouble(0.0); + BigDecimal lowerPrice = null; + for (TbProductSku item : tbProductSkus) { + sum.addAndGet(item.getStockNumber()); + if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) { + lowerPrice = item.getSalePrice(); + } + + String specSnap = item.getSpecSnap(); + if (specSnap != null) { + specSet.addAll(Arrays.asList(specSnap.split(","))); + } + } + it.setStockNumber(sum.intValue()); + if (lowerPrice == null) { + lowerPrice = BigDecimal.ZERO; + } + it.setLowPrice(lowerPrice); + String tagSnap = skuResult != null ? skuResult.getTagSnap() : null; + if (tagSnap != null) { + JSONArray tagSnaps = JSONObject.parseArray(tagSnap); + JSONObject snapJSON; + JSONArray finalSnap = new JSONArray(); + for (Object snap : tagSnaps) { + snapJSON = (JSONObject) snap; + String values = snapJSON.getString("value"); + String finalValues = ""; + if (StrUtil.isNotBlank(values)) { + String[] valueList = values.split(","); + for (String value : valueList) { + if (specSet.contains(value)) { + finalValues = finalValues + (value) + ","; + } + } + if (StrUtil.isNotBlank(finalValues)) { + finalValues = StrUtil.removeSuffix(finalValues, ","); + snapJSON.put("value", finalValues); + finalSnap.add(snapJSON); + } + } + } + skuResult.setTagSnap(finalSnap.toJSONString()); + } + it.setProductSkuResult(skuResult); + }); + } + concurrentMap.put("hots", tbProducts); + List groupList = tbProductGroupMapper.selectByShopId(shopId, id); + if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) { + //热销 + TbProductGroup hot =new TbProductGroup(); + hot.setName("热销"); + List hots = tbProductMapper.selectHot(shopId); + hots.parallelStream().forEach(it -> { + TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId())); + it.setUnitSnap(tbShopUnit!=null?tbShopUnit.getName():""); + it.setCartNumber("0"); + List tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId()); + TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId()); + + // 上下架对应的sku + HashSet specSet = new HashSet<>(); + AtomicDouble sum = new AtomicDouble(0.0); + BigDecimal lowerPrice = null; + for (TbProductSku item : tbProductSkus) { + sum.addAndGet(item.getStockNumber()); + if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) { + lowerPrice = item.getSalePrice(); + } + + String specSnap = item.getSpecSnap(); + if (specSnap != null) { + specSet.addAll(Arrays.asList(specSnap.split(","))); + } + } + it.setStockNumber(sum.intValue()); + if (lowerPrice == null) { + lowerPrice = BigDecimal.ZERO; + } + it.setLowPrice(lowerPrice); + String tagSnap = skuResult != null ? skuResult.getTagSnap() : null; + if (tagSnap != null) { + JSONArray tagSnaps = JSONObject.parseArray(tagSnap); + JSONObject snapJSON; + + JSONArray finalSnap = new JSONArray(); + + for (Object snap : tagSnaps) { + snapJSON = (JSONObject) snap; + String values = snapJSON.getString("value"); + String finalValues = ""; + + if (StrUtil.isNotBlank(values)) { + String[] valueList = values.split(","); + for (String value : valueList) { + if (specSet.contains(value)) { + finalValues = finalValues + (value) + ","; + } + } + + if (StrUtil.isNotBlank(finalValues)) { + finalValues = StrUtil.removeSuffix(finalValues, ","); + snapJSON.put("value", finalValues); + finalSnap.add(snapJSON); + } + + } + } + + skuResult.setTagSnap(finalSnap.toJSONString()); + } + + it.setProductSkuResult(skuResult); + }); + hot.setProducts(hots); + + //商品 groupList.parallelStream().forEach(g -> { String in = g.getProductIds().substring(1, g.getProductIds().length() - 1); @@ -144,16 +271,18 @@ public class ProductService { List products = tbProductMapper.selectByIdInAndCheck(in); if (ObjectUtil.isNotEmpty(products) && products.size() > 0) { products.parallelStream().forEach(it -> { - Integer sum = tbProductMapper.selectByQcode(code, it.getId(), it.getShopId()); - it.setCartNumber(sum == null ? "0" : String.valueOf(sum)); + TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId())); + it.setUnitSnap(tbShopUnit!=null?tbShopUnit.getName():""); + it.setCartNumber("0"); List tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId()); TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId()); // 上下架对应的sku HashSet specSet = new HashSet<>(); - + AtomicDouble sum = new AtomicDouble(0.0); BigDecimal lowerPrice = null; for (TbProductSku item : tbProductSkus) { + sum.addAndGet(item.getStockNumber()); if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) { lowerPrice = item.getSalePrice(); } @@ -163,13 +292,11 @@ public class ProductService { specSet.addAll(Arrays.asList(specSnap.split(","))); } } - + it.setStockNumber(sum.intValue()); if (lowerPrice == null) { lowerPrice = BigDecimal.ZERO; } - it.setLowPrice(lowerPrice); - String tagSnap = skuResult != null ? skuResult.getTagSnap() : null; if (tagSnap != null) { JSONArray tagSnaps = JSONObject.parseArray(tagSnap); @@ -221,12 +348,16 @@ public class ProductService { } - public Result queryProductSku(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)) { return Result.fail("参数错误"); } TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId, productId, spec_tag); + if(StringUtils.isNotBlank(code)) { + Integer sum = tbProductMapper.selectByCodeAndSkuId(code, tbProductSkuWithBLOBs.getId(), shopId); + tbProductSkuWithBLOBs.setNumber(sum); + } return Result.success(CodeEnum.SUCCESS, tbProductSkuWithBLOBs); } diff --git a/src/main/resources/mapper/TbProductGroupMapper.xml b/src/main/resources/mapper/TbProductGroupMapper.xml index a9bb7b2..5082065 100644 --- a/src/main/resources/mapper/TbProductGroupMapper.xml +++ b/src/main/resources/mapper/TbProductGroupMapper.xml @@ -229,9 +229,9 @@ FROM tb_product_group where shop_id=#{shopId} and is_show=1 - + and id = #{groupId} - order by g.sort asc + order by sort asc \ No newline at end of file diff --git a/src/main/resources/mapper/TbProductMapper.xml b/src/main/resources/mapper/TbProductMapper.xml index f37e11e..ae3ff8f 100644 --- a/src/main/resources/mapper/TbProductMapper.xml +++ b/src/main/resources/mapper/TbProductMapper.xml @@ -932,11 +932,45 @@ select min( sku.suit ) as suit,tb.* from tb_product tb LEFT JOIN tb_product_sku sku ON tb.id = sku.product_id - where tb.id in (${ids}) and is_show_mall =1 and sku.is_del = 0 and sku.is_grounding=1 + where tb.id in (${ids}) and is_show_mall =1 and sku.is_del = 0 and sku.is_grounding=1 and tb.status = 1 group by tb.id order by tb.sort asc + + + + + + + @@ -963,6 +997,17 @@ t.shop_id, t.product_id + - select * from tb_product_sku where shop_id=#{shopId} and product_id=#{productId} and is_del = 0 - + select * from tb_product_sku where shop_id=#{shopId} and product_id=#{productId} and is_del = 0 and is_grounding=1 and spec_snap = #{spec} + limit 1 @@ -948,6 +948,7 @@ ORDER BY SUM(real_sales_number) DESC LIMIT 3) AS top_products ON tb.id = top_products.product_id where is_show_mall = 1 and tb.status = 1 + and tb.type_enum != 'group' and sku.is_del = 0 and sku.is_grounding = 1 group by tb.id @@ -965,6 +966,7 @@ and tb.status = 1 and sku.is_del = 0 and sku.is_grounding = 1 + and tb.type_enum != 'group' group by tb.id order by tb.sort asc From f4af3a279fa9f55841bbae28bc5c46174b247c84 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 8 Aug 2024 16:57:24 +0800 Subject: [PATCH 09/28] =?UTF-8?q?=E5=BA=97=E9=93=BA=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=8D=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserContoller.java | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 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 2908836..fcd72ad 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -64,39 +64,44 @@ public class UserContoller { @GetMapping("/shopUserInfo") 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)); + TbShopInfo tbShopInfo = new TbShopInfo(); if (StringUtils.isNotBlank(shopId) && !shopId.equals("null")) { - shopUser = shopUserMapper.selectByUserIdAndShopId(userId, shopId); - if (ObjectUtil.isEmpty(shopUser)) { - TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId)); + tbShopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId)); + if(tbShopInfo!=null){ + shopUser = shopUserMapper.selectByUserIdAndShopId(userId, shopId); + if (ObjectUtil.isEmpty(shopUser)) { + 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 { + return Result.fail("店铺信息不存在"); } } else { shopUser.setAmount(BigDecimal.ZERO); From 7f8a658143f8e10585dd8e4ffd7ae661060b10b4 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Fri, 9 Aug 2024 14:37:53 +0800 Subject: [PATCH 10/28] =?UTF-8?q?1.=E4=B8=8B=E6=9E=B6=E8=A7=84=E6=A0=BC?= =?UTF-8?q?=E6=9C=AA=E6=9F=A5=E8=AF=A2=E5=87=BA=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ProductService.java | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 4cf1087..491aea6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -242,8 +242,10 @@ public class ProductService { // 提取所有 value 的列表 for (int i = 0; i < tagSnaps.size(); i++) { JSONObject jsonObject = tagSnaps.getJSONObject(i); - String[] values = jsonObject.getString("value").split(","); - valuesList.add(Arrays.asList(values)); + if (jsonObject.containsKey("value")) { + String[] values = jsonObject.getString("value").split(","); + valuesList.add(Arrays.asList(values)); + } } // 生成所有可能的排列组合 generateCombinations(valuesList, 0, new ArrayList<>(), result); @@ -305,7 +307,7 @@ public class ProductService { TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId()); // 上下架对应的sku - HashSet specSet = new HashSet<>(); +// HashSet specSet = new HashSet<>(); AtomicDouble sum = new AtomicDouble(0.0); BigDecimal lowerPrice = null; for (TbProductSku item : tbProductSkus) { @@ -317,9 +319,9 @@ public class ProductService { } String specSnap = item.getSpecSnap(); - if (specSnap != null) { - specSet.addAll(Arrays.asList(specSnap.split(","))); - } +// if (specSnap != null) { +// specSet.addAll(Arrays.asList(specSnap.split(","))); +// } } //销量 it.setStockNumber(sum.intValue()); @@ -328,32 +330,32 @@ public class ProductService { } //售价 it.setLowPrice(lowerPrice); - String tagSnap = skuResult != null ? skuResult.getTagSnap() : null; - if (tagSnap != null) { - JSONArray tagSnaps = JSONObject.parseArray(tagSnap); - JSONObject snapJSON; - JSONArray finalSnap = new JSONArray(); - for (Object snap : tagSnaps) { - snapJSON = (JSONObject) snap; - String values = snapJSON.getString("value"); - String finalValues = ""; - if (StrUtil.isNotBlank(values)) { - String[] valueList = values.split(","); - for (String value : valueList) { - if (specSet.contains(value)) { - finalValues = finalValues + (value) + ","; - } - } - if (StrUtil.isNotBlank(finalValues)) { - finalValues = StrUtil.removeSuffix(finalValues, ","); - snapJSON.put("value", finalValues); - finalSnap.add(snapJSON); - } - } - } - //sku Result - skuResult.setTagSnap(finalSnap.toJSONString()); - } +// String tagSnap = skuResult != null ? skuResult.getTagSnap() : null; +// if (tagSnap != null) { +// JSONArray tagSnaps = JSONObject.parseArray(tagSnap); +// JSONObject snapJSON; +// JSONArray finalSnap = new JSONArray(); +// for (Object snap : tagSnaps) { +// snapJSON = (JSONObject) snap; +// String values = snapJSON.getString("value"); +// String finalValues = ""; +// if (StrUtil.isNotBlank(values)) { +// String[] valueList = values.split(","); +// for (String value : valueList) { +// if (specSet.contains(value)) { +// finalValues = finalValues + (value) + ","; +// } +// } +// if (StrUtil.isNotBlank(finalValues)) { +// finalValues = StrUtil.removeSuffix(finalValues, ","); +// snapJSON.put("value", finalValues); +// finalSnap.add(snapJSON); +// } +// } +// } +// //sku Result +// skuResult.setTagSnap(finalSnap.toJSONString()); +// } it.setProductSkuResult(skuResult); }); return products; From dc291231eed95890be780cb46a7aee518b801933 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Fri, 9 Aug 2024 16:42:17 +0800 Subject: [PATCH 11/28] =?UTF-8?q?1.=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CommonController.java | 4 +- .../controller/UserContoller.java | 4 +- .../dao/TbShopOpenIdMapper.java | 12 ++++ .../entity/Enum/ShopWxMsgTypeEnum.java | 17 +++++ .../cashierservice/service/CartService.java | 5 +- .../cashierservice/service/LoginService.java | 62 ++++++++++++++----- .../cashierservice/service/UserService.java | 15 ++--- 7 files changed, 86 insertions(+), 33 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/ShopWxMsgTypeEnum.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index 1c0f114..83211ee 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -220,9 +220,7 @@ public class CommonController { if (wxMsgSubDTO.getOpenId() == null || wxMsgSubDTO.getShopId() == null) { return Result.fail("shopId或openId缺失"); } - String msg = wxMsgSubDTO.getShopId().replace("msg", ""); - String[] split = msg.split(","); - loginService.addShopId(wxMsgSubDTO.getOpenId(), split[0], split.length > 1 ? Integer.valueOf(split[1]) : null, wxMsgSubDTO.getNickname(), wxMsgSubDTO.getAvatar()); + loginService.addShopId(wxMsgSubDTO.getOpenId(), wxMsgSubDTO.getShopId(), null, wxMsgSubDTO.getNickname(), wxMsgSubDTO.getAvatar()); return Result.success(CodeEnum.SUCCESS); } } 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 fcd72ad..28cce38 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -156,7 +156,9 @@ public class UserContoller { * @return */ @GetMapping("/subQrCode") - public Result getSubQrCode(String shopId) throws Exception { + public Result getSubQrCode( + @RequestParam String shopId + ) throws Exception { String url = userService.getSubQrCode(shopId); return Result.successWithData(url); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java index 8d875e1..8e6a0f1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java @@ -38,4 +38,16 @@ public interface TbShopOpenIdMapper { @Update("update tb_shop_open_id set nickname=#{nickName}, avatar=#{avatar} where open_id=#{openId} and status=1 ") int updateBaseInfoByOpenId(@Param("openId") String openId, @Param("nickName") String nickName, @Param("avatar") String avatar); + + @Select("select count(*) from tb_shop_open_id where shop_id=#{shopId} and status=1;") + int selectStateByShopId(@Param("shopId") String shopId); + + @Select("select count(*) from tb_shop_open_id where shop_id=#{shopId} and status=1 and type=#{type};") + int countStateByShopIdAndType(@Param("shopId") String shopId, @Param("type") int type); + + @Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1 and (type=#{type} or type=-1);") + List selectStateByShopIdAndType(@Param("shopId") String shopId, @Param("type") int type); + + @Select("select * from tb_shop_open_id where shop_id=#{shopId} and open_id=#{openId};") + List selectStateByShopIdAndOpenId(@Param("openId") String openId, @Param("shopId") String shopId); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/ShopWxMsgTypeEnum.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/ShopWxMsgTypeEnum.java new file mode 100644 index 0000000..766e548 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/ShopWxMsgTypeEnum.java @@ -0,0 +1,17 @@ +package com.chaozhanggui.system.cashierservice.entity.Enum; + +public enum ShopWxMsgTypeEnum { + ALL_MSG(-1), + STOCK_MSG(0), + CONSUMABLES_MSG(1), + OPERATION_MSG(2); + private final Integer type; + + ShopWxMsgTypeEnum(Integer type) { + this.type = type; + } + + public Integer getType() { + return type; + } +} 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 a967298..81409f7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.entity.Enum.ShopWxMsgTypeEnum; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.netty.PushToAppChannelHandlerAdapter; import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; @@ -336,11 +337,11 @@ public class CartService { (product.getIsDistribute() == 1 && product.getStockNumber() - num <= productSku.getWarnLine()) || (product.getIsDistribute() != 1) && productSku.getStockNumber() - num <= productSku.getWarnLine() ) { - List shopOpenIds = shopOpenIdMapper.selectByShopId(Integer.valueOf(product.getShopId())); + List shopOpenIds = shopOpenIdMapper.selectStateByShopIdAndType(product.getShopId(), ShopWxMsgTypeEnum.STOCK_MSG.getType()); shopOpenIds.forEach(item -> { String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId()); if (message == null) { - wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(), + WxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(), product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num) , item.getOpenId()); redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L); 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 ada1443..c9194ed 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -1,6 +1,7 @@ package com.chaozhanggui.system.cashierservice.service; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; @@ -60,32 +61,61 @@ public class LoginService { private final TbShopOpenIdMapper shopOpenIdMapper; + private final static int[] MSG_TYPE_LIST = new int[] {0, 1, 2}; + public LoginService(TbShopOpenIdMapper shopOpenIdMapper) { this.shopOpenIdMapper = shopOpenIdMapper; } - public void addShopId(String openId, String shopId, Integer type, String nickName, String avatar) { + public void addShopId(String openId, String shopId, Integer type1, String nickName, String avatar) { // 为商家绑定openid - TbShopOpenId tbShopOpenId = shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), type); - if (tbShopOpenId == null) { - TbShopOpenId shopOpenId = new TbShopOpenId(); - shopOpenId.setOpenId(openId); - shopOpenId.setCreateTime(DateUtil.date()); - shopOpenId.setShopId(Integer.valueOf(shopId)); - shopOpenId.setStatus(1); - shopOpenId.setNickname(nickName); - shopOpenId.setAvatar(avatar); - shopOpenId.setType(type == null ? -1 : type); - shopOpenIdMapper.insert(shopOpenId); +// TbShopOpenId tbShopOpenId = shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), null); + List shopOpenIdList = shopOpenIdMapper.selectStateByShopIdAndOpenId(openId, shopId); + int openCount = shopOpenIdMapper.selectStateByShopId(shopId); + + if (shopOpenIdList.isEmpty()) { + for (int type : MSG_TYPE_LIST) { + addShopOpenId(openId, shopId, nickName, avatar, openCount, type); + } + } else { - tbShopOpenId.setUpdateTime(DateUtil.date()); - tbShopOpenId.setNickname(nickName); - tbShopOpenId.setAvatar(avatar); - shopOpenIdMapper.updateByPrimaryKeySelective(tbShopOpenId); + boolean fullSize = shopOpenIdList.size() == MSG_TYPE_LIST.length; + HashMap typeMap = new HashMap<>(); + for (TbShopOpenId tbShopOpenId : shopOpenIdList) { + typeMap.put(tbShopOpenId.getType().toString(), tbShopOpenId.getOpenId()); + tbShopOpenId.setType(null); + tbShopOpenId.setUpdateTime(DateUtil.date()); + tbShopOpenId.setNickname(nickName); + tbShopOpenId.setAvatar(avatar); + shopOpenIdMapper.updateByPrimaryKeySelective(tbShopOpenId); + } + + if (fullSize) { + return; + } + for (int type : MSG_TYPE_LIST) { + if (typeMap.get(String.valueOf(type)) == null) { + addShopOpenId(openId, shopId, nickName, avatar, openCount, type); + } + } + } } + private void addShopOpenId(String openId, String shopId, String nickName, String avatar, int openCount, int type) { + int count = shopOpenIdMapper.countStateByShopIdAndType(shopId, type); + TbShopOpenId shopOpenId = new TbShopOpenId(); + shopOpenId.setOpenId(openId); + shopOpenId.setCreateTime(DateUtil.date()); + shopOpenId.setShopId(Integer.valueOf(shopId)); + shopOpenId.setStatus(openCount > 0 ? count > 0 ? 1 : 0 : 0); + shopOpenId.setNickname(nickName); + shopOpenId.setAvatar(avatar); + shopOpenId.setType(type); + shopOpenIdMapper.insert(shopOpenId); + } + public Result wxBusinessLogin(String openId, String shopId) { TbUserShopMsg shopMsg = tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId), openId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java index 0c11041..47dbcff 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java @@ -1,11 +1,8 @@ package com.chaozhanggui.system.cashierservice.service; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.RandomUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.extra.qrcode.QrConfig; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; @@ -13,9 +10,6 @@ import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.redis.RedisCst; -import com.chaozhanggui.system.cashierservice.redis.RedisUtil; -import com.chaozhanggui.system.cashierservice.sign.CodeEnum; -import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.*; import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil; import com.github.pagehelper.PageHelper; @@ -23,14 +17,11 @@ import com.github.pagehelper.PageInfo; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; @@ -264,7 +255,9 @@ public class UserService { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Resource resource = resourceLoader.getResource("classpath:/static/logo.jpg"); InputStream inputStream = resource.getInputStream(); - QrCodeUtil.generate(wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId), -1), new QrConfig(500, 500). +// String url = wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId), -1); + String url = StrUtil.format("https://invoice.sxczgkj.cn/index/wechat/weuserk?shopId={}", shopId); + QrCodeUtil.generate(url, new QrConfig(500, 500). setImg(ImageIO.read(inputStream)).setErrorCorrection(ErrorCorrectionLevel.H).setRatio(4), "png", outputStream); From 538fc8f91b56b2f25310f8c894b03f6567a11e4c Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Fri, 9 Aug 2024 16:45:53 +0800 Subject: [PATCH 12/28] =?UTF-8?q?1.=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/service/LoginService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 ada1443..0f02095 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -65,6 +65,17 @@ public class LoginService { } public void addShopId(String openId, String shopId, Integer type, String nickName, String avatar) { + TbUserShopMsg shopMsg = tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId), openId); + if (Objects.isNull(shopMsg)) { + shopMsg = new TbUserShopMsg(); + shopMsg.setShopId(Integer.valueOf(shopId)); + shopMsg.setOpenId(openId); + shopMsg.setCreateTime(new Date()); + shopMsg.setStatus("1"); + tbUserShopMsgMapper.insert(shopMsg); + } + + // 为商家绑定openid TbShopOpenId tbShopOpenId = shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), type); if (tbShopOpenId == null) { From bee86bbb738b194d6df15cb85e1c4392c87685a7 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Tue, 13 Aug 2024 09:44:39 +0800 Subject: [PATCH 13/28] =?UTF-8?q?1.=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=BA=97=E9=93=BA=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/entity/TbShopMsgState.java | 94 +++++++++++++++++++ .../mapper/TbShopMsgStateMapper.java | 28 ++++++ .../cashierservice/service/CartService.java | 4 +- .../cashierservice/wxUtil/WxAccountUtil.java | 13 ++- .../resources/mapper/TbShopMsgStateMapper.xml | 91 ++++++++++++++++++ 5 files changed, 227 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopMsgState.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbShopMsgStateMapper.java create mode 100644 src/main/resources/mapper/TbShopMsgStateMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopMsgState.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopMsgState.java new file mode 100644 index 0000000..7afb82e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopMsgState.java @@ -0,0 +1,94 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + +/** + * + * @TableName tb_shop_msg_state + */ +@Data +public class TbShopMsgState implements Serializable { + /** + * + */ + private Integer id; + + /** + * + */ + private Integer shopId; + + /** + * + */ + private Integer type; + + /** + * + */ + private Integer state; + + /** + * + */ + private Date createTime; + + /** + * + */ + private Date updateTime; + + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + TbShopMsgState other = (TbShopMsgState) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId())) + && (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType())) + && (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState())) + && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) + && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode()); + result = prime * result + ((getType() == null) ? 0 : getType().hashCode()); + result = prime * result + ((getState() == null) ? 0 : getState().hashCode()); + result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); + result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", shopId=").append(shopId); + sb.append(", type=").append(type); + sb.append(", state=").append(state); + sb.append(", createTime=").append(createTime); + sb.append(", updateTime=").append(updateTime); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbShopMsgStateMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbShopMsgStateMapper.java new file mode 100644 index 0000000..10f7430 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbShopMsgStateMapper.java @@ -0,0 +1,28 @@ +package com.chaozhanggui.system.cashierservice.mapper; + +import com.chaozhanggui.system.cashierservice.entity.TbShopMsgState; +import org.apache.ibatis.annotations.Select; + +/** +* @author Administrator +* @description 针对表【tb_shop_msg_state】的数据库操作Mapper +* @createDate 2024-08-12 14:38:33 +* @Entity com.chaozhanggui.system.cashierservice.entity.TbShopMsgState +*/ +public interface TbShopMsgStateMapper { + + int deleteByPrimaryKey(Long id); + + int insert(TbShopMsgState record); + + int insertSelective(TbShopMsgState record); + + TbShopMsgState selectByPrimaryKey(Long id); + + int updateByPrimaryKeySelective(TbShopMsgState record); + + int updateByPrimaryKey(TbShopMsgState record); + + @Select("select * from tb_shop_msg_state where shop_id=#{shopId} and type=#{type};") + TbShopMsgState selectByType(Integer type, Integer shopId); +} 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 81409f7..2bdda19 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -341,9 +341,9 @@ public class CartService { shopOpenIds.forEach(item -> { String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId()); if (message == null) { - WxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(), + wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(), product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num) - , item.getOpenId()); + , item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopInfo.getId()); redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L); }else { log.info("{}已在30分钟内推送过消息,跳过发送", item.getOpenId()); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java index 35e9098..245130e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java @@ -6,7 +6,10 @@ import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSONObject; +import com.chaozhanggui.system.cashierservice.entity.Enum.ShopWxMsgTypeEnum; +import com.chaozhanggui.system.cashierservice.entity.TbShopMsgState; import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.mapper.TbShopMsgStateMapper; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -27,6 +30,8 @@ public class WxAccountUtil { @Value("${wx.ysk.warnMsgTmpId}") private static String msgTmpId = "C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0"; + private final TbShopMsgStateMapper shopMsgStateMapper; + static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); static { @@ -98,7 +103,13 @@ public class WxAccountUtil { throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); } - public static JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId) { + public JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId, ShopWxMsgTypeEnum typeEnum, Integer shopId) { + TbShopMsgState shopMsgState = shopMsgStateMapper.selectByType(typeEnum.getType(), shopId); + if (shopMsgState == null || shopMsgState.getState().equals(0)) { + log.info("店铺未开启推送:{}", shopMsgState); + return null; + } + stock = stock < 0 ? 0 : stock; Integer finalStock = stock; Map data = new HashMap() {{ diff --git a/src/main/resources/mapper/TbShopMsgStateMapper.xml b/src/main/resources/mapper/TbShopMsgStateMapper.xml new file mode 100644 index 0000000..cd820c5 --- /dev/null +++ b/src/main/resources/mapper/TbShopMsgStateMapper.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + id,shop_id,type, + state,create_time,update_time + + + + + + delete from tb_shop_msg_state + where id = #{id,jdbcType=INTEGER} + + + insert into tb_shop_msg_state + ( id,shop_id,type + ,state,create_time,update_time + ) + values (#{id,jdbcType=INTEGER},#{shopId,jdbcType=INTEGER},#{type,jdbcType=INTEGER} + ,#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP} + ) + + + insert into tb_shop_msg_state + + id, + shop_id, + type, + state, + create_time, + update_time, + + + #{id,jdbcType=INTEGER}, + #{shopId,jdbcType=INTEGER}, + #{type,jdbcType=INTEGER}, + #{state,jdbcType=INTEGER}, + #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP}, + + + + update tb_shop_msg_state + + + shop_id = #{shopId,jdbcType=INTEGER}, + + + type = #{type,jdbcType=INTEGER}, + + + state = #{state,jdbcType=INTEGER}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_shop_msg_state + set + shop_id = #{shopId,jdbcType=INTEGER}, + type = #{type,jdbcType=INTEGER}, + state = #{state,jdbcType=INTEGER}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + From 8281c2b9bc682b51e0c9418eadc2d8ac5fcc1583 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 14 Aug 2024 09:46:28 +0800 Subject: [PATCH 14/28] =?UTF-8?q?=E5=BC=80=E9=80=9A=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LoginContoller.java | 9 ++--- .../controller/UserContoller.java | 7 ++++ .../cashierservice/entity/TbShopUser.java | 30 +++++++++++++++- .../entity/vo/OpenMemberVo.java | 15 ++++++++ .../exception/DefaultExceptionAdvice.java | 3 +- .../cashierservice/service/UserService.java | 36 +++++++++++++------ 6 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OpenMemberVo.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index cbdcdb2..3fced4d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -201,11 +201,11 @@ public class LoginContoller { String data = WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr); try { if (ObjectUtil.isNotEmpty(data) && JSONObject.parseObject(data).containsKey("phoneNumber")) { - if (!map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId"))) { +// if (!map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId"))) { return Result.success(CodeEnum.SUCCESS, JSONObject.parseObject(data).get("phoneNumber")); - } - log.info("登录传参 获取手机号成功 sessionKey:{}\n encryptedData:{} \nivStr:{} \n data:{},",sessionKey,encryptedData,ivStr,JSONObject.parseObject(data).get("phoneNumber")); - return loginService.upPhone(openId,JSONObject.parseObject(data).get("phoneNumber").toString(),map.get("shopId").toString()); +// } +// log.info("登录传参 获取手机号成功 sessionKey:{}\n encryptedData:{} \nivStr:{} \n data:{},",sessionKey,encryptedData,ivStr,JSONObject.parseObject(data).get("phoneNumber")); +// return loginService.upPhone(openId,JSONObject.parseObject(data).get("phoneNumber").toString(),map.get("shopId").toString()); } } catch (Exception e){ // e.printStackTrace(); @@ -277,6 +277,7 @@ public class LoginContoller { String userId = TokenUtil.parseParamFromToken(token).getString("userId"); userInfo.setId(Integer.valueOf(userId)); userInfo.setUpdatedAt(System.currentTimeMillis()); +// log.info("更新用户信息 param,{}",JSONObject.toJSONString(userInfo)); return loginService.upUserInfo(userInfo); } 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 fcd72ad..05b5db6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -12,6 +12,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbShopUser; import com.chaozhanggui.system.cashierservice.entity.TbUserInfo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; +import com.chaozhanggui.system.cashierservice.entity.vo.OpenMemberVo; import com.chaozhanggui.system.cashierservice.service.UserService; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; @@ -61,6 +62,12 @@ public class UserContoller { // jsonObject.put("data",object); // return jsonObject; // } + + @PostMapping("/openMember") + public Result openMember(@RequestBody OpenMemberVo memberVo){ + return userService.openMember(memberVo); + } + @GetMapping("/shopUserInfo") public Result shopUserInfo(@RequestParam("userId") String userId, @RequestHeader("openId") String openId, @RequestParam("shopId") String shopId) throws Exception { TbShopUser shopUser = new TbShopUser(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java index 9531fdf..1621a49 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java @@ -63,7 +63,10 @@ public class TbShopUser implements Serializable { private Long updatedAt; private String miniOpenId; - private String shopName; + private String shopName=""; + private String lat=""; + private String lng=""; + private String address=""; private static final long serialVersionUID = 1L; @@ -307,4 +310,29 @@ public class TbShopUser implements Serializable { public void setMiniOpenId(String miniOpenId) { this.miniOpenId = miniOpenId == null ? null : miniOpenId.trim(); } + + + public String getLat() { + return lat; + } + + public void setLat(String lat) { + this.lat = lat; + } + + public String getLng() { + return lng; + } + + public void setLng(String lng) { + this.lng = lng; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OpenMemberVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OpenMemberVo.java new file mode 100644 index 0000000..b08c50e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OpenMemberVo.java @@ -0,0 +1,15 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +@Data +public class OpenMemberVo { + private Integer id; + private Integer shopId; + private String headImg; + + private String nickName; + + private String telephone; + private String birthDay; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java index b68db15..02b7c10 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java @@ -146,7 +146,8 @@ public class DefaultExceptionAdvice { @ResponseStatus(HttpStatus.OK) @ExceptionHandler(MsgException.class) public ResponseEntity handleException(MsgException e) { - LOGGER.error("业务异常", e); + // LOGGER.error("业务异常", e); + LOGGER.error("业务异常", e.getMessage()); Result response = Result.fail(e.getMessage()); response.setMsg(e.getMessage()); return new ResponseEntity<>(response, HttpStatus.OK); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java index 0c11041..3b2dca0 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java @@ -1,19 +1,18 @@ package com.chaozhanggui.system.cashierservice.service; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.RandomUtil; import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.extra.qrcode.QrConfig; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; -import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.entity.TbReleaseFlow; +import com.chaozhanggui.system.cashierservice.entity.TbShopInfo; +import com.chaozhanggui.system.cashierservice.entity.TbShopUser; +import com.chaozhanggui.system.cashierservice.entity.TbUserInfo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; +import com.chaozhanggui.system.cashierservice.entity.vo.OpenMemberVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.redis.RedisCst; -import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.*; @@ -23,19 +22,18 @@ import com.github.pagehelper.PageInfo; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.math.BigDecimal; -import java.util.*; +import java.util.Date; +import java.util.List; +import java.util.Objects; import java.util.concurrent.TimeUnit; @Service @@ -270,4 +268,22 @@ public class UserService { return fileService.uploadFileByInputStream("png", new ByteArrayInputStream(outputStream.toByteArray())); } + + public Result openMember(OpenMemberVo memberVo) { +// TbUserInfo userInfo = new TbUserInfo(); +// userInfo.setId(memberVo.getId()); +// userInfo.setHeadImg(memberVo.getHeadImg()); +// userInfo.setNickName(memberVo.getNickName()); +// userInfo.setTelephone(memberVo.getTelephone()); +// userInfo.setBirthDay(memberVo.getBirthDay()); +// userInfoMapper.updateByPrimaryKeySelective(userInfo); + TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(memberVo.getId().toString(), memberVo.getShopId().toString()); + tbShopUser.setName(memberVo.getNickName()); + tbShopUser.setHeadImg(memberVo.getHeadImg()); + tbShopUser.setTelephone(memberVo.getTelephone()); + tbShopUser.setBirthDay(memberVo.getBirthDay()); + tbShopUser.setIsVip(Byte.parseByte("1")); + shopUserMapper.updateByPrimaryKey(tbShopUser); + return Result.success(CodeEnum.SUCCESS); + } } From a9b32b4e576bc4e80dc866bf694b08772e0a6cb0 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 14 Aug 2024 09:55:18 +0800 Subject: [PATCH 15/28] =?UTF-8?q?1.=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/dao/TbShopOpenIdMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java index 8e6a0f1..478c8d2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java @@ -45,7 +45,7 @@ public interface TbShopOpenIdMapper { @Select("select count(*) from tb_shop_open_id where shop_id=#{shopId} and status=1 and type=#{type};") int countStateByShopIdAndType(@Param("shopId") String shopId, @Param("type") int type); - @Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1 and (type=#{type} or type=-1);") + @Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1 and (type=#{type} or type=-1) group by open_id;") List selectStateByShopIdAndType(@Param("shopId") String shopId, @Param("type") int type); @Select("select * from tb_shop_open_id where shop_id=#{shopId} and open_id=#{openId};") From 68d12fe2ed69ec8c874c688d8fb77d0c15c2a719 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 14 Aug 2024 11:34:51 +0800 Subject: [PATCH 16/28] =?UTF-8?q?=E5=95=86=E5=93=81=20=E5=8F=AF=E5=94=AE?= =?UTF-8?q?=E6=97=B6=E9=97=B4=20=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/TbProductGroupMapper.java | 13 ++-- .../cashierservice/entity/TbProduct.java | 11 +++ .../cashierservice/entity/TbProductGroup.java | 43 ++++++++++++ .../service/ProductService.java | 70 +++++++++++++++++-- .../resources/mapper/TbProductGroupMapper.xml | 10 ++- 5 files changed, 136 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductGroupMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductGroupMapper.java index 13d89fd..1609ea7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductGroupMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductGroupMapper.java @@ -10,23 +10,24 @@ import java.util.List; @Component @Mapper public interface TbProductGroupMapper { - int deleteByPrimaryKey(Integer id); +// int deleteByPrimaryKey(Integer id); - int insert(TbProductGroup record); +// int insert(TbProductGroup record); - int insertSelective(TbProductGroup record); +// int insertSelective(TbProductGroup record); TbProductGroup selectByPrimaryKey(Integer id); - int updateByPrimaryKeySelective(TbProductGroup record); +// int updateByPrimaryKeySelective(TbProductGroup record); - int updateByPrimaryKeyWithBLOBs(TbProductGroup record); +// int updateByPrimaryKeyWithBLOBs(TbProductGroup record); - int updateByPrimaryKey(TbProductGroup record); +// int updateByPrimaryKey(TbProductGroup record); List selectByIdAndShopId(@Param("code") String code); List selectByQrcode(@Param("qrCode") String qrCode,@Param("groupId") Integer groupId); List selectByShopId(@Param("shopId") String shopId,@Param("groupId") Integer groupId); + List selectByProductId(@Param("shopId") String shopId,@Param("productId") String productId); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java index ed6e8bf..ba7404d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java @@ -137,6 +137,9 @@ public class TbProduct implements Serializable { private Integer stockNumber; private Integer suit; + //是否可售 1 可售 0非可售 + private Integer isSale = 1; + public String getImages() { return images; @@ -672,4 +675,12 @@ public class TbProduct implements Serializable { public void setSuit(Integer suit) { this.suit = suit; } + + public Integer getIsSale() { + return isSale; + } + + public void setIsSale(Integer isSale) { + this.isSale = isSale; + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java index 9460370..d06a9bb 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java @@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.entity; import org.springframework.data.annotation.Transient; +import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.List; @@ -31,6 +32,15 @@ public class TbProductGroup implements Serializable { private String productIds; + //是否可售 1 可售 0非可售 + private Integer isSale = 1; + //是否使用时间管控 0不使用 1使用 + private Integer useTime = 0; + + private String saleStartTime; + + private String saleEndTime; + @Transient @@ -144,4 +154,37 @@ public class TbProductGroup implements Serializable { public void setProductIds(String productIds) { this.productIds = productIds == null ? null : productIds.trim(); } + + + public Integer getUseTime() { + return useTime; + } + + public void setUseTime(Integer useTime) { + this.useTime = useTime; + } + + public String getSaleStartTime() { + return saleStartTime; + } + + public void setSaleStartTime(String saleStartTime) { + this.saleStartTime = saleStartTime; + } + + public String getSaleEndTime() { + return saleEndTime; + } + + public void setSaleEndTime(String saleEndTime) { + this.saleEndTime = saleEndTime; + } + + public Integer getIsSale() { + return isSale; + } + + public void setIsSale(Integer isSale) { + this.isSale = isSale; + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 491aea6..f16e026 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -18,6 +18,7 @@ import com.chaozhanggui.system.cashierservice.util.*; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.google.common.util.concurrent.AtomicDouble; +import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -26,6 +27,10 @@ import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; @@ -136,32 +141,72 @@ public class ProductService { Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null; //招牌菜 List tbProducts = tbProductMapper.selectIsSpecialty(Integer.valueOf(shopId)); - concurrentMap.put("hots", handleDate(tbProducts)); + concurrentMap.put("hots", handleDate(tbProducts,true)); List groupList = tbProductGroupMapper.selectByShopId(shopId, id); if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) { //热销 TbProductGroup hot = new TbProductGroup(); hot.setName("热销"); List hots = tbProductMapper.selectHot(shopId); - hot.setProducts(handleDate(hots)); + hot.setProducts(handleDate(hots,true)); //商品 groupList.parallelStream().forEach(g -> { + if (g.getUseTime()==1) g.setIsSale(getIsSale(g.getSaleStartTime(),g.getSaleEndTime())); String in = g.getProductIds().substring(1, g.getProductIds().length() - 1); if (ObjectUtil.isNotEmpty(in) && ObjectUtil.isNotNull(in)) { // List products = tbProductMapper.selectByIdIn(in); List products = tbProductMapper.selectByIdInAndCheck(in); - g.setProducts(handleDate(products)); + g.setProducts(handleDate(products,false)); } else { g.setProducts(new ArrayList<>()); } }); groupList.add(0, hot); + groupList.sort(Comparator.comparingInt(TbProductGroup::getIsSale)); concurrentMap.put("productInfo", groupList); } return Result.success(CodeEnum.SUCCESS, concurrentMap); } + /** + * 判断是否在可售时间内 + * @param startTimeStr HH:mm + * @param endTimeStr HH:mm + * @return 1 可售 0 不可售 + */ + public Integer getIsSale(String startTimeStr,String endTimeStr) { + // 定义时间格式 + DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm"); + // 解析时间字符串为 LocalTime 对象 + LocalTime startTime = LocalTime.parse(startTimeStr, timeFormatter); + LocalTime endTime = LocalTime.parse(endTimeStr, timeFormatter); + // 获取当前日期 + LocalDate today = LocalDate.now(); + // 创建 LocalDateTime 对象 + LocalDateTime startDateTime = LocalDateTime.of(today, startTime); + LocalDateTime endDateTime = LocalDateTime.of(today, endTime); + // 如果结束时间早于开始时间,说明时间段跨日 + if (endDateTime.isBefore(startDateTime)) { + endDateTime = endDateTime.plusDays(1); + } + // 获取当前日期时间 + LocalDateTime now = LocalDateTime.now(); + if (now.isBefore(startDateTime)) { + // 将当前时间加上24小时(一天),进行比较 + LocalDateTime nowPlus24 = now.plusHours(24); + //当前时间 小于开始时间,且结束时间小于开始时间 + if (nowPlus24.isBefore(endDateTime)) { + return 1; + } + } else { + if (now.isBefore(endDateTime)) { + return 1; + } + } + return 0; + } + public Object querySpec(QuerySpecDTO querySpecDTO) { TbProduct tbProduct = tbProductMapper.selectById(querySpecDTO.getProductId()); if (tbProduct == null) { @@ -296,9 +341,26 @@ public class ProductService { } } - public List handleDate(List products){ + /** + * 组装商品 + * @param products 商品列表 + * @param check 是否校验可售 + * @return + */ + public List handleDate(List products,boolean check){ if (!CollectionUtils.isEmpty(products)) { products.parallelStream().forEach(it -> { + if(check){ + List tbProductGroups = tbProductGroupMapper.selectByProductId(it.getShopId(), it.getId().toString()); + for (TbProductGroup g : tbProductGroups) { + if (g.getUseTime()==1) { + if (getIsSale(g.getSaleStartTime(), g.getSaleEndTime()) == 0) { + it.setIsSale(0); + return; + } + } + } + } TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId())); it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : ""); //购物车数量 diff --git a/src/main/resources/mapper/TbProductGroupMapper.xml b/src/main/resources/mapper/TbProductGroupMapper.xml index 5082065..a8f0112 100644 --- a/src/main/resources/mapper/TbProductGroupMapper.xml +++ b/src/main/resources/mapper/TbProductGroupMapper.xml @@ -11,6 +11,9 @@ + + + @@ -18,7 +21,7 @@ - id, name, merchant_id, shop_id, pic, is_show, detail, style, sort, created_at, updated_at + id, name, merchant_id, shop_id, pic, is_show, detail, style, sort, created_at, updated_at , use_time, sale_start_time, sale_end_time product_ids @@ -234,4 +237,9 @@ order by sort asc + + \ No newline at end of file From 3ab16294367fbfec9b485b6ffabfff7d72d044ae Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Fri, 9 Aug 2024 16:42:17 +0800 Subject: [PATCH 17/28] =?UTF-8?q?1.=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CommonController.java | 4 +- .../controller/UserContoller.java | 4 +- .../dao/TbShopOpenIdMapper.java | 12 +++ .../entity/Enum/ShopWxMsgTypeEnum.java | 17 +++++ .../cashierservice/service/CartService.java | 5 +- .../cashierservice/service/LoginService.java | 73 ++++++++++++------- .../cashierservice/service/UserService.java | 15 +--- 7 files changed, 86 insertions(+), 44 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/ShopWxMsgTypeEnum.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index 1c0f114..83211ee 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -220,9 +220,7 @@ public class CommonController { if (wxMsgSubDTO.getOpenId() == null || wxMsgSubDTO.getShopId() == null) { return Result.fail("shopId或openId缺失"); } - String msg = wxMsgSubDTO.getShopId().replace("msg", ""); - String[] split = msg.split(","); - loginService.addShopId(wxMsgSubDTO.getOpenId(), split[0], split.length > 1 ? Integer.valueOf(split[1]) : null, wxMsgSubDTO.getNickname(), wxMsgSubDTO.getAvatar()); + loginService.addShopId(wxMsgSubDTO.getOpenId(), wxMsgSubDTO.getShopId(), null, wxMsgSubDTO.getNickname(), wxMsgSubDTO.getAvatar()); return Result.success(CodeEnum.SUCCESS); } } 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 fcd72ad..28cce38 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -156,7 +156,9 @@ public class UserContoller { * @return */ @GetMapping("/subQrCode") - public Result getSubQrCode(String shopId) throws Exception { + public Result getSubQrCode( + @RequestParam String shopId + ) throws Exception { String url = userService.getSubQrCode(shopId); return Result.successWithData(url); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java index 8d875e1..8e6a0f1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java @@ -38,4 +38,16 @@ public interface TbShopOpenIdMapper { @Update("update tb_shop_open_id set nickname=#{nickName}, avatar=#{avatar} where open_id=#{openId} and status=1 ") int updateBaseInfoByOpenId(@Param("openId") String openId, @Param("nickName") String nickName, @Param("avatar") String avatar); + + @Select("select count(*) from tb_shop_open_id where shop_id=#{shopId} and status=1;") + int selectStateByShopId(@Param("shopId") String shopId); + + @Select("select count(*) from tb_shop_open_id where shop_id=#{shopId} and status=1 and type=#{type};") + int countStateByShopIdAndType(@Param("shopId") String shopId, @Param("type") int type); + + @Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1 and (type=#{type} or type=-1);") + List selectStateByShopIdAndType(@Param("shopId") String shopId, @Param("type") int type); + + @Select("select * from tb_shop_open_id where shop_id=#{shopId} and open_id=#{openId};") + List selectStateByShopIdAndOpenId(@Param("openId") String openId, @Param("shopId") String shopId); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/ShopWxMsgTypeEnum.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/ShopWxMsgTypeEnum.java new file mode 100644 index 0000000..766e548 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/Enum/ShopWxMsgTypeEnum.java @@ -0,0 +1,17 @@ +package com.chaozhanggui.system.cashierservice.entity.Enum; + +public enum ShopWxMsgTypeEnum { + ALL_MSG(-1), + STOCK_MSG(0), + CONSUMABLES_MSG(1), + OPERATION_MSG(2); + private final Integer type; + + ShopWxMsgTypeEnum(Integer type) { + this.type = type; + } + + public Integer getType() { + return type; + } +} 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 a967298..81409f7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.entity.Enum.ShopWxMsgTypeEnum; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.netty.PushToAppChannelHandlerAdapter; import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; @@ -336,11 +337,11 @@ public class CartService { (product.getIsDistribute() == 1 && product.getStockNumber() - num <= productSku.getWarnLine()) || (product.getIsDistribute() != 1) && productSku.getStockNumber() - num <= productSku.getWarnLine() ) { - List shopOpenIds = shopOpenIdMapper.selectByShopId(Integer.valueOf(product.getShopId())); + List shopOpenIds = shopOpenIdMapper.selectStateByShopIdAndType(product.getShopId(), ShopWxMsgTypeEnum.STOCK_MSG.getType()); shopOpenIds.forEach(item -> { String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId()); if (message == null) { - wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(), + WxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(), product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num) , item.getOpenId()); redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L); 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 0f02095..c9194ed 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/LoginService.java @@ -1,6 +1,7 @@ package com.chaozhanggui.system.cashierservice.service; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; @@ -60,43 +61,61 @@ public class LoginService { private final TbShopOpenIdMapper shopOpenIdMapper; + private final static int[] MSG_TYPE_LIST = new int[] {0, 1, 2}; + public LoginService(TbShopOpenIdMapper shopOpenIdMapper) { this.shopOpenIdMapper = shopOpenIdMapper; } - public void addShopId(String openId, String shopId, Integer type, String nickName, String avatar) { - TbUserShopMsg shopMsg = tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId), openId); - if (Objects.isNull(shopMsg)) { - shopMsg = new TbUserShopMsg(); - shopMsg.setShopId(Integer.valueOf(shopId)); - shopMsg.setOpenId(openId); - shopMsg.setCreateTime(new Date()); - shopMsg.setStatus("1"); - tbUserShopMsgMapper.insert(shopMsg); - } - - + public void addShopId(String openId, String shopId, Integer type1, String nickName, String avatar) { // 为商家绑定openid - TbShopOpenId tbShopOpenId = shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), type); - if (tbShopOpenId == null) { - TbShopOpenId shopOpenId = new TbShopOpenId(); - shopOpenId.setOpenId(openId); - shopOpenId.setCreateTime(DateUtil.date()); - shopOpenId.setShopId(Integer.valueOf(shopId)); - shopOpenId.setStatus(1); - shopOpenId.setNickname(nickName); - shopOpenId.setAvatar(avatar); - shopOpenId.setType(type == null ? -1 : type); - shopOpenIdMapper.insert(shopOpenId); +// TbShopOpenId tbShopOpenId = shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), null); + List shopOpenIdList = shopOpenIdMapper.selectStateByShopIdAndOpenId(openId, shopId); + int openCount = shopOpenIdMapper.selectStateByShopId(shopId); + + if (shopOpenIdList.isEmpty()) { + for (int type : MSG_TYPE_LIST) { + addShopOpenId(openId, shopId, nickName, avatar, openCount, type); + } + } else { - tbShopOpenId.setUpdateTime(DateUtil.date()); - tbShopOpenId.setNickname(nickName); - tbShopOpenId.setAvatar(avatar); - shopOpenIdMapper.updateByPrimaryKeySelective(tbShopOpenId); + boolean fullSize = shopOpenIdList.size() == MSG_TYPE_LIST.length; + HashMap typeMap = new HashMap<>(); + for (TbShopOpenId tbShopOpenId : shopOpenIdList) { + typeMap.put(tbShopOpenId.getType().toString(), tbShopOpenId.getOpenId()); + tbShopOpenId.setType(null); + tbShopOpenId.setUpdateTime(DateUtil.date()); + tbShopOpenId.setNickname(nickName); + tbShopOpenId.setAvatar(avatar); + shopOpenIdMapper.updateByPrimaryKeySelective(tbShopOpenId); + } + + if (fullSize) { + return; + } + for (int type : MSG_TYPE_LIST) { + if (typeMap.get(String.valueOf(type)) == null) { + addShopOpenId(openId, shopId, nickName, avatar, openCount, type); + } + } + } } + private void addShopOpenId(String openId, String shopId, String nickName, String avatar, int openCount, int type) { + int count = shopOpenIdMapper.countStateByShopIdAndType(shopId, type); + TbShopOpenId shopOpenId = new TbShopOpenId(); + shopOpenId.setOpenId(openId); + shopOpenId.setCreateTime(DateUtil.date()); + shopOpenId.setShopId(Integer.valueOf(shopId)); + shopOpenId.setStatus(openCount > 0 ? count > 0 ? 1 : 0 : 0); + shopOpenId.setNickname(nickName); + shopOpenId.setAvatar(avatar); + shopOpenId.setType(type); + shopOpenIdMapper.insert(shopOpenId); + } + public Result wxBusinessLogin(String openId, String shopId) { TbUserShopMsg shopMsg = tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId), openId); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java index 0c11041..47dbcff 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java @@ -1,11 +1,8 @@ package com.chaozhanggui.system.cashierservice.service; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.RandomUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.extra.qrcode.QrConfig; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; @@ -13,9 +10,6 @@ import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.redis.RedisCst; -import com.chaozhanggui.system.cashierservice.redis.RedisUtil; -import com.chaozhanggui.system.cashierservice.sign.CodeEnum; -import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.*; import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil; import com.github.pagehelper.PageHelper; @@ -23,14 +17,11 @@ import com.github.pagehelper.PageInfo; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; @@ -264,7 +255,9 @@ public class UserService { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Resource resource = resourceLoader.getResource("classpath:/static/logo.jpg"); InputStream inputStream = resource.getInputStream(); - QrCodeUtil.generate(wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId), -1), new QrConfig(500, 500). +// String url = wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId), -1); + String url = StrUtil.format("https://invoice.sxczgkj.cn/index/wechat/weuserk?shopId={}", shopId); + QrCodeUtil.generate(url, new QrConfig(500, 500). setImg(ImageIO.read(inputStream)).setErrorCorrection(ErrorCorrectionLevel.H).setRatio(4), "png", outputStream); From efd0d80dc36d8f2bdc37140a4e2dbf50bba4adcd Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Tue, 13 Aug 2024 09:44:39 +0800 Subject: [PATCH 18/28] =?UTF-8?q?1.=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=BA=97=E9=93=BA=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/entity/TbShopMsgState.java | 94 +++++++++++++++++++ .../mapper/TbShopMsgStateMapper.java | 28 ++++++ .../cashierservice/service/CartService.java | 4 +- .../cashierservice/wxUtil/WxAccountUtil.java | 13 ++- .../resources/mapper/TbShopMsgStateMapper.xml | 91 ++++++++++++++++++ 5 files changed, 227 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopMsgState.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbShopMsgStateMapper.java create mode 100644 src/main/resources/mapper/TbShopMsgStateMapper.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopMsgState.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopMsgState.java new file mode 100644 index 0000000..7afb82e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopMsgState.java @@ -0,0 +1,94 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + +/** + * + * @TableName tb_shop_msg_state + */ +@Data +public class TbShopMsgState implements Serializable { + /** + * + */ + private Integer id; + + /** + * + */ + private Integer shopId; + + /** + * + */ + private Integer type; + + /** + * + */ + private Integer state; + + /** + * + */ + private Date createTime; + + /** + * + */ + private Date updateTime; + + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + TbShopMsgState other = (TbShopMsgState) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId())) + && (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType())) + && (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState())) + && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) + && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode()); + result = prime * result + ((getType() == null) ? 0 : getType().hashCode()); + result = prime * result + ((getState() == null) ? 0 : getState().hashCode()); + result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); + result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", shopId=").append(shopId); + sb.append(", type=").append(type); + sb.append(", state=").append(state); + sb.append(", createTime=").append(createTime); + sb.append(", updateTime=").append(updateTime); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbShopMsgStateMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbShopMsgStateMapper.java new file mode 100644 index 0000000..10f7430 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/mapper/TbShopMsgStateMapper.java @@ -0,0 +1,28 @@ +package com.chaozhanggui.system.cashierservice.mapper; + +import com.chaozhanggui.system.cashierservice.entity.TbShopMsgState; +import org.apache.ibatis.annotations.Select; + +/** +* @author Administrator +* @description 针对表【tb_shop_msg_state】的数据库操作Mapper +* @createDate 2024-08-12 14:38:33 +* @Entity com.chaozhanggui.system.cashierservice.entity.TbShopMsgState +*/ +public interface TbShopMsgStateMapper { + + int deleteByPrimaryKey(Long id); + + int insert(TbShopMsgState record); + + int insertSelective(TbShopMsgState record); + + TbShopMsgState selectByPrimaryKey(Long id); + + int updateByPrimaryKeySelective(TbShopMsgState record); + + int updateByPrimaryKey(TbShopMsgState record); + + @Select("select * from tb_shop_msg_state where shop_id=#{shopId} and type=#{type};") + TbShopMsgState selectByType(Integer type, Integer shopId); +} 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 81409f7..2bdda19 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -341,9 +341,9 @@ public class CartService { shopOpenIds.forEach(item -> { String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId()); if (message == null) { - WxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(), + wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(), product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num) - , item.getOpenId()); + , item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopInfo.getId()); redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L); }else { log.info("{}已在30分钟内推送过消息,跳过发送", item.getOpenId()); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java index 35e9098..245130e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java @@ -6,7 +6,10 @@ import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSONObject; +import com.chaozhanggui.system.cashierservice.entity.Enum.ShopWxMsgTypeEnum; +import com.chaozhanggui.system.cashierservice.entity.TbShopMsgState; import com.chaozhanggui.system.cashierservice.exception.MsgException; +import com.chaozhanggui.system.cashierservice.mapper.TbShopMsgStateMapper; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -27,6 +30,8 @@ public class WxAccountUtil { @Value("${wx.ysk.warnMsgTmpId}") private static String msgTmpId = "C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0"; + private final TbShopMsgStateMapper shopMsgStateMapper; + static LinkedHashMap linkedHashMap=new LinkedHashMap<>(); static { @@ -98,7 +103,13 @@ public class WxAccountUtil { throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误")); } - public static JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId) { + public JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId, ShopWxMsgTypeEnum typeEnum, Integer shopId) { + TbShopMsgState shopMsgState = shopMsgStateMapper.selectByType(typeEnum.getType(), shopId); + if (shopMsgState == null || shopMsgState.getState().equals(0)) { + log.info("店铺未开启推送:{}", shopMsgState); + return null; + } + stock = stock < 0 ? 0 : stock; Integer finalStock = stock; Map data = new HashMap() {{ diff --git a/src/main/resources/mapper/TbShopMsgStateMapper.xml b/src/main/resources/mapper/TbShopMsgStateMapper.xml new file mode 100644 index 0000000..cd820c5 --- /dev/null +++ b/src/main/resources/mapper/TbShopMsgStateMapper.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + id,shop_id,type, + state,create_time,update_time + + + + + + delete from tb_shop_msg_state + where id = #{id,jdbcType=INTEGER} + + + insert into tb_shop_msg_state + ( id,shop_id,type + ,state,create_time,update_time + ) + values (#{id,jdbcType=INTEGER},#{shopId,jdbcType=INTEGER},#{type,jdbcType=INTEGER} + ,#{state,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP} + ) + + + insert into tb_shop_msg_state + + id, + shop_id, + type, + state, + create_time, + update_time, + + + #{id,jdbcType=INTEGER}, + #{shopId,jdbcType=INTEGER}, + #{type,jdbcType=INTEGER}, + #{state,jdbcType=INTEGER}, + #{createTime,jdbcType=TIMESTAMP}, + #{updateTime,jdbcType=TIMESTAMP}, + + + + update tb_shop_msg_state + + + shop_id = #{shopId,jdbcType=INTEGER}, + + + type = #{type,jdbcType=INTEGER}, + + + state = #{state,jdbcType=INTEGER}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=INTEGER} + + + update tb_shop_msg_state + set + shop_id = #{shopId,jdbcType=INTEGER}, + type = #{type,jdbcType=INTEGER}, + state = #{state,jdbcType=INTEGER}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + From dae3a75e0ce7f7237f9664b7a02c0488f5b7a13e Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 14 Aug 2024 09:55:18 +0800 Subject: [PATCH 19/28] =?UTF-8?q?1.=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/dao/TbShopOpenIdMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java index 8e6a0f1..478c8d2 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopOpenIdMapper.java @@ -45,7 +45,7 @@ public interface TbShopOpenIdMapper { @Select("select count(*) from tb_shop_open_id where shop_id=#{shopId} and status=1 and type=#{type};") int countStateByShopIdAndType(@Param("shopId") String shopId, @Param("type") int type); - @Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1 and (type=#{type} or type=-1);") + @Select("select * from tb_shop_open_id where shop_id=#{shopId} and status=1 and (type=#{type} or type=-1) group by open_id;") List selectStateByShopIdAndType(@Param("shopId") String shopId, @Param("type") int type); @Select("select * from tb_shop_open_id where shop_id=#{shopId} and open_id=#{openId};") From 8ea20b8394fb607fff01adddc860781cae6b8ae4 Mon Sep 17 00:00:00 2001 From: SongZhang <2064194730@qq.com> Date: Wed, 14 Aug 2024 14:56:39 +0800 Subject: [PATCH 20/28] =?UTF-8?q?1.=E9=81=BF=E5=85=8D=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/wxUtil/WxAccountUtil.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java index 245130e..73baaa9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/wxUtil/WxAccountUtil.java @@ -104,6 +104,11 @@ public class WxAccountUtil { } public JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId, ShopWxMsgTypeEnum typeEnum, Integer shopId) { + TbShopMsgState allState = shopMsgStateMapper.selectByType(ShopWxMsgTypeEnum.ALL_MSG.getType(), shopId); + if (allState == null || allState.getState().equals(0)) { + log.info("店铺未开启全局推送:{}", allState); + return null; + } TbShopMsgState shopMsgState = shopMsgStateMapper.selectByType(typeEnum.getType(), shopId); if (shopMsgState == null || shopMsgState.getState().equals(0)) { log.info("店铺未开启推送:{}", shopMsgState); From 57472bdf003ce1f0f339e04f3b53737a76dea67c Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 14 Aug 2024 09:46:28 +0800 Subject: [PATCH 21/28] =?UTF-8?q?=E5=BC=80=E9=80=9A=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LoginContoller.java | 9 +++--- .../controller/UserContoller.java | 7 +++++ .../cashierservice/entity/TbShopUser.java | 30 ++++++++++++++++++- .../entity/vo/OpenMemberVo.java | 15 ++++++++++ .../exception/DefaultExceptionAdvice.java | 3 +- .../cashierservice/service/UserService.java | 26 +++++++++++++++- 6 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OpenMemberVo.java diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java index cbdcdb2..3fced4d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/LoginContoller.java @@ -201,11 +201,11 @@ public class LoginContoller { String data = WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr); try { if (ObjectUtil.isNotEmpty(data) && JSONObject.parseObject(data).containsKey("phoneNumber")) { - if (!map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId"))) { +// if (!map.containsKey("shopId") || ObjectUtil.isEmpty(map.get("shopId"))) { return Result.success(CodeEnum.SUCCESS, JSONObject.parseObject(data).get("phoneNumber")); - } - log.info("登录传参 获取手机号成功 sessionKey:{}\n encryptedData:{} \nivStr:{} \n data:{},",sessionKey,encryptedData,ivStr,JSONObject.parseObject(data).get("phoneNumber")); - return loginService.upPhone(openId,JSONObject.parseObject(data).get("phoneNumber").toString(),map.get("shopId").toString()); +// } +// log.info("登录传参 获取手机号成功 sessionKey:{}\n encryptedData:{} \nivStr:{} \n data:{},",sessionKey,encryptedData,ivStr,JSONObject.parseObject(data).get("phoneNumber")); +// return loginService.upPhone(openId,JSONObject.parseObject(data).get("phoneNumber").toString(),map.get("shopId").toString()); } } catch (Exception e){ // e.printStackTrace(); @@ -277,6 +277,7 @@ public class LoginContoller { String userId = TokenUtil.parseParamFromToken(token).getString("userId"); userInfo.setId(Integer.valueOf(userId)); userInfo.setUpdatedAt(System.currentTimeMillis()); +// log.info("更新用户信息 param,{}",JSONObject.toJSONString(userInfo)); return loginService.upUserInfo(userInfo); } 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 28cce38..e90bfe9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -12,6 +12,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbShopUser; import com.chaozhanggui.system.cashierservice.entity.TbUserInfo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; +import com.chaozhanggui.system.cashierservice.entity.vo.OpenMemberVo; import com.chaozhanggui.system.cashierservice.service.UserService; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; @@ -61,6 +62,12 @@ public class UserContoller { // jsonObject.put("data",object); // return jsonObject; // } + + @PostMapping("/openMember") + public Result openMember(@RequestBody OpenMemberVo memberVo){ + return userService.openMember(memberVo); + } + @GetMapping("/shopUserInfo") public Result shopUserInfo(@RequestParam("userId") String userId, @RequestHeader("openId") String openId, @RequestParam("shopId") String shopId) throws Exception { TbShopUser shopUser = new TbShopUser(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java index 9531fdf..1621a49 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopUser.java @@ -63,7 +63,10 @@ public class TbShopUser implements Serializable { private Long updatedAt; private String miniOpenId; - private String shopName; + private String shopName=""; + private String lat=""; + private String lng=""; + private String address=""; private static final long serialVersionUID = 1L; @@ -307,4 +310,29 @@ public class TbShopUser implements Serializable { public void setMiniOpenId(String miniOpenId) { this.miniOpenId = miniOpenId == null ? null : miniOpenId.trim(); } + + + public String getLat() { + return lat; + } + + public void setLat(String lat) { + this.lat = lat; + } + + public String getLng() { + return lng; + } + + public void setLng(String lng) { + this.lng = lng; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OpenMemberVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OpenMemberVo.java new file mode 100644 index 0000000..b08c50e --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OpenMemberVo.java @@ -0,0 +1,15 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +@Data +public class OpenMemberVo { + private Integer id; + private Integer shopId; + private String headImg; + + private String nickName; + + private String telephone; + private String birthDay; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java index b68db15..02b7c10 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/exception/DefaultExceptionAdvice.java @@ -146,7 +146,8 @@ public class DefaultExceptionAdvice { @ResponseStatus(HttpStatus.OK) @ExceptionHandler(MsgException.class) public ResponseEntity handleException(MsgException e) { - LOGGER.error("业务异常", e); + // LOGGER.error("业务异常", e); + LOGGER.error("业务异常", e.getMessage()); Result response = Result.fail(e.getMessage()); response.setMsg(e.getMessage()); return new ResponseEntity<>(response, HttpStatus.OK); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java index 47dbcff..cd72a41 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java @@ -5,11 +5,17 @@ import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.extra.qrcode.QrConfig; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; -import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.entity.TbReleaseFlow; +import com.chaozhanggui.system.cashierservice.entity.TbShopInfo; +import com.chaozhanggui.system.cashierservice.entity.TbShopUser; +import com.chaozhanggui.system.cashierservice.entity.TbUserInfo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo; import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo; +import com.chaozhanggui.system.cashierservice.entity.vo.OpenMemberVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.redis.RedisCst; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; +import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.*; import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil; import com.github.pagehelper.PageHelper; @@ -263,4 +269,22 @@ public class UserService { return fileService.uploadFileByInputStream("png", new ByteArrayInputStream(outputStream.toByteArray())); } + + public Result openMember(OpenMemberVo memberVo) { +// TbUserInfo userInfo = new TbUserInfo(); +// userInfo.setId(memberVo.getId()); +// userInfo.setHeadImg(memberVo.getHeadImg()); +// userInfo.setNickName(memberVo.getNickName()); +// userInfo.setTelephone(memberVo.getTelephone()); +// userInfo.setBirthDay(memberVo.getBirthDay()); +// userInfoMapper.updateByPrimaryKeySelective(userInfo); + TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(memberVo.getId().toString(), memberVo.getShopId().toString()); + tbShopUser.setName(memberVo.getNickName()); + tbShopUser.setHeadImg(memberVo.getHeadImg()); + tbShopUser.setTelephone(memberVo.getTelephone()); + tbShopUser.setBirthDay(memberVo.getBirthDay()); + tbShopUser.setIsVip(Byte.parseByte("1")); + shopUserMapper.updateByPrimaryKey(tbShopUser); + return Result.success(CodeEnum.SUCCESS); + } } From a4601fac99114b828e77baddf77e007b2656b319 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 14 Aug 2024 11:34:51 +0800 Subject: [PATCH 22/28] =?UTF-8?q?=E5=95=86=E5=93=81=20=E5=8F=AF=E5=94=AE?= =?UTF-8?q?=E6=97=B6=E9=97=B4=20=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/TbProductGroupMapper.java | 13 ++-- .../cashierservice/entity/TbProduct.java | 11 +++ .../cashierservice/entity/TbProductGroup.java | 43 ++++++++++++ .../service/ProductService.java | 70 +++++++++++++++++-- .../resources/mapper/TbProductGroupMapper.xml | 10 ++- 5 files changed, 136 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductGroupMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductGroupMapper.java index 13d89fd..1609ea7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductGroupMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductGroupMapper.java @@ -10,23 +10,24 @@ import java.util.List; @Component @Mapper public interface TbProductGroupMapper { - int deleteByPrimaryKey(Integer id); +// int deleteByPrimaryKey(Integer id); - int insert(TbProductGroup record); +// int insert(TbProductGroup record); - int insertSelective(TbProductGroup record); +// int insertSelective(TbProductGroup record); TbProductGroup selectByPrimaryKey(Integer id); - int updateByPrimaryKeySelective(TbProductGroup record); +// int updateByPrimaryKeySelective(TbProductGroup record); - int updateByPrimaryKeyWithBLOBs(TbProductGroup record); +// int updateByPrimaryKeyWithBLOBs(TbProductGroup record); - int updateByPrimaryKey(TbProductGroup record); +// int updateByPrimaryKey(TbProductGroup record); List selectByIdAndShopId(@Param("code") String code); List selectByQrcode(@Param("qrCode") String qrCode,@Param("groupId") Integer groupId); List selectByShopId(@Param("shopId") String shopId,@Param("groupId") Integer groupId); + List selectByProductId(@Param("shopId") String shopId,@Param("productId") String productId); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java index ed6e8bf..ba7404d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java @@ -137,6 +137,9 @@ public class TbProduct implements Serializable { private Integer stockNumber; private Integer suit; + //是否可售 1 可售 0非可售 + private Integer isSale = 1; + public String getImages() { return images; @@ -672,4 +675,12 @@ public class TbProduct implements Serializable { public void setSuit(Integer suit) { this.suit = suit; } + + public Integer getIsSale() { + return isSale; + } + + public void setIsSale(Integer isSale) { + this.isSale = isSale; + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java index 9460370..d06a9bb 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java @@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.entity; import org.springframework.data.annotation.Transient; +import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.List; @@ -31,6 +32,15 @@ public class TbProductGroup implements Serializable { private String productIds; + //是否可售 1 可售 0非可售 + private Integer isSale = 1; + //是否使用时间管控 0不使用 1使用 + private Integer useTime = 0; + + private String saleStartTime; + + private String saleEndTime; + @Transient @@ -144,4 +154,37 @@ public class TbProductGroup implements Serializable { public void setProductIds(String productIds) { this.productIds = productIds == null ? null : productIds.trim(); } + + + public Integer getUseTime() { + return useTime; + } + + public void setUseTime(Integer useTime) { + this.useTime = useTime; + } + + public String getSaleStartTime() { + return saleStartTime; + } + + public void setSaleStartTime(String saleStartTime) { + this.saleStartTime = saleStartTime; + } + + public String getSaleEndTime() { + return saleEndTime; + } + + public void setSaleEndTime(String saleEndTime) { + this.saleEndTime = saleEndTime; + } + + public Integer getIsSale() { + return isSale; + } + + public void setIsSale(Integer isSale) { + this.isSale = isSale; + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 491aea6..f16e026 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -18,6 +18,7 @@ import com.chaozhanggui.system.cashierservice.util.*; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.google.common.util.concurrent.AtomicDouble; +import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -26,6 +27,10 @@ import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; @@ -136,32 +141,72 @@ public class ProductService { Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null; //招牌菜 List tbProducts = tbProductMapper.selectIsSpecialty(Integer.valueOf(shopId)); - concurrentMap.put("hots", handleDate(tbProducts)); + concurrentMap.put("hots", handleDate(tbProducts,true)); List groupList = tbProductGroupMapper.selectByShopId(shopId, id); if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) { //热销 TbProductGroup hot = new TbProductGroup(); hot.setName("热销"); List hots = tbProductMapper.selectHot(shopId); - hot.setProducts(handleDate(hots)); + hot.setProducts(handleDate(hots,true)); //商品 groupList.parallelStream().forEach(g -> { + if (g.getUseTime()==1) g.setIsSale(getIsSale(g.getSaleStartTime(),g.getSaleEndTime())); String in = g.getProductIds().substring(1, g.getProductIds().length() - 1); if (ObjectUtil.isNotEmpty(in) && ObjectUtil.isNotNull(in)) { // List products = tbProductMapper.selectByIdIn(in); List products = tbProductMapper.selectByIdInAndCheck(in); - g.setProducts(handleDate(products)); + g.setProducts(handleDate(products,false)); } else { g.setProducts(new ArrayList<>()); } }); groupList.add(0, hot); + groupList.sort(Comparator.comparingInt(TbProductGroup::getIsSale)); concurrentMap.put("productInfo", groupList); } return Result.success(CodeEnum.SUCCESS, concurrentMap); } + /** + * 判断是否在可售时间内 + * @param startTimeStr HH:mm + * @param endTimeStr HH:mm + * @return 1 可售 0 不可售 + */ + public Integer getIsSale(String startTimeStr,String endTimeStr) { + // 定义时间格式 + DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm"); + // 解析时间字符串为 LocalTime 对象 + LocalTime startTime = LocalTime.parse(startTimeStr, timeFormatter); + LocalTime endTime = LocalTime.parse(endTimeStr, timeFormatter); + // 获取当前日期 + LocalDate today = LocalDate.now(); + // 创建 LocalDateTime 对象 + LocalDateTime startDateTime = LocalDateTime.of(today, startTime); + LocalDateTime endDateTime = LocalDateTime.of(today, endTime); + // 如果结束时间早于开始时间,说明时间段跨日 + if (endDateTime.isBefore(startDateTime)) { + endDateTime = endDateTime.plusDays(1); + } + // 获取当前日期时间 + LocalDateTime now = LocalDateTime.now(); + if (now.isBefore(startDateTime)) { + // 将当前时间加上24小时(一天),进行比较 + LocalDateTime nowPlus24 = now.plusHours(24); + //当前时间 小于开始时间,且结束时间小于开始时间 + if (nowPlus24.isBefore(endDateTime)) { + return 1; + } + } else { + if (now.isBefore(endDateTime)) { + return 1; + } + } + return 0; + } + public Object querySpec(QuerySpecDTO querySpecDTO) { TbProduct tbProduct = tbProductMapper.selectById(querySpecDTO.getProductId()); if (tbProduct == null) { @@ -296,9 +341,26 @@ public class ProductService { } } - public List handleDate(List products){ + /** + * 组装商品 + * @param products 商品列表 + * @param check 是否校验可售 + * @return + */ + public List handleDate(List products,boolean check){ if (!CollectionUtils.isEmpty(products)) { products.parallelStream().forEach(it -> { + if(check){ + List tbProductGroups = tbProductGroupMapper.selectByProductId(it.getShopId(), it.getId().toString()); + for (TbProductGroup g : tbProductGroups) { + if (g.getUseTime()==1) { + if (getIsSale(g.getSaleStartTime(), g.getSaleEndTime()) == 0) { + it.setIsSale(0); + return; + } + } + } + } TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId())); it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : ""); //购物车数量 diff --git a/src/main/resources/mapper/TbProductGroupMapper.xml b/src/main/resources/mapper/TbProductGroupMapper.xml index 5082065..a8f0112 100644 --- a/src/main/resources/mapper/TbProductGroupMapper.xml +++ b/src/main/resources/mapper/TbProductGroupMapper.xml @@ -11,6 +11,9 @@ + + + @@ -18,7 +21,7 @@ - id, name, merchant_id, shop_id, pic, is_show, detail, style, sort, created_at, updated_at + id, name, merchant_id, shop_id, pic, is_show, detail, style, sort, created_at, updated_at , use_time, sale_start_time, sale_end_time product_ids @@ -234,4 +237,9 @@ order by sort asc + + \ No newline at end of file From 48a6628acbc7d03e96a12e5531de50c5a8bc73f5 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 14 Aug 2024 16:07:38 +0800 Subject: [PATCH 23/28] =?UTF-8?q?=E5=95=86=E5=93=81=20=E5=8F=AF=E5=94=AE?= =?UTF-8?q?=E6=97=B6=E9=97=B4=20=E5=A4=84=E7=90=86=20=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/service/ProductService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index f16e026..252048f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -141,14 +141,14 @@ public class ProductService { Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null; //招牌菜 List tbProducts = tbProductMapper.selectIsSpecialty(Integer.valueOf(shopId)); - concurrentMap.put("hots", handleDate(tbProducts,true)); + concurrentMap.put("hots", handleDate(tbProducts,true,1)); List groupList = tbProductGroupMapper.selectByShopId(shopId, id); if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) { //热销 TbProductGroup hot = new TbProductGroup(); hot.setName("热销"); List hots = tbProductMapper.selectHot(shopId); - hot.setProducts(handleDate(hots,true)); + hot.setProducts(handleDate(hots,true,1)); //商品 groupList.parallelStream().forEach(g -> { if (g.getUseTime()==1) g.setIsSale(getIsSale(g.getSaleStartTime(),g.getSaleEndTime())); @@ -156,7 +156,7 @@ public class ProductService { if (ObjectUtil.isNotEmpty(in) && ObjectUtil.isNotNull(in)) { // List products = tbProductMapper.selectByIdIn(in); List products = tbProductMapper.selectByIdInAndCheck(in); - g.setProducts(handleDate(products,false)); + g.setProducts(handleDate(products,false,g.getIsSale())); } else { g.setProducts(new ArrayList<>()); } @@ -347,7 +347,7 @@ public class ProductService { * @param check 是否校验可售 * @return */ - public List handleDate(List products,boolean check){ + public List handleDate(List products,boolean check,Integer isSale){ if (!CollectionUtils.isEmpty(products)) { products.parallelStream().forEach(it -> { if(check){ @@ -360,6 +360,8 @@ public class ProductService { } } } + }else { + it.setIsSale(isSale); } TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId())); it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : ""); From 878cc895d44f547c2f33fb07f9cb55194ef35754 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 16 Aug 2024 09:27:58 +0800 Subject: [PATCH 24/28] =?UTF-8?q?=E5=95=86=E5=93=81=20=E5=8F=AF=E5=94=AE?= =?UTF-8?q?=E6=97=B6=E9=97=B4=20=E5=88=86=E7=BB=84=20=E6=8E=92=E5=BA=8F=20?= =?UTF-8?q?=E4=BC=9A=E5=91=98=E4=BF=A1=E6=81=AF=20=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/entity/TbProductGroup.java | 1 - .../system/cashierservice/service/ProductService.java | 2 +- src/main/resources/mapper/TbShopUserFlowMapper.xml | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java index d06a9bb..1c5b0b6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProductGroup.java @@ -3,7 +3,6 @@ package com.chaozhanggui.system.cashierservice.entity; import org.springframework.data.annotation.Transient; -import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.List; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 252048f..8e844ad 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -161,8 +161,8 @@ public class ProductService { g.setProducts(new ArrayList<>()); } }); + groupList.sort(Comparator.comparingInt(TbProductGroup::getIsSale).reversed()); groupList.add(0, hot); - groupList.sort(Comparator.comparingInt(TbProductGroup::getIsSale)); concurrentMap.put("productInfo", groupList); } diff --git a/src/main/resources/mapper/TbShopUserFlowMapper.xml b/src/main/resources/mapper/TbShopUserFlowMapper.xml index 9e02f10..9d7b16f 100644 --- a/src/main/resources/mapper/TbShopUserFlowMapper.xml +++ b/src/main/resources/mapper/TbShopUserFlowMapper.xml @@ -130,6 +130,7 @@ SELECT f.*, + u.`head_img`, u.`name` FROM tb_shop_user_flow f From 605b1778a41fef63e86dd233e6802f3f2137f960 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 16 Aug 2024 14:07:01 +0800 Subject: [PATCH 25/28] =?UTF-8?q?=E4=BC=9A=E5=91=98=E5=92=8C=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=89=8B=E6=9C=BA=E5=8F=B7=20=E4=BF=9D=E6=8C=81?= =?UTF-8?q?=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/service/UserService.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java index 3b2dca0..716ea72 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/UserService.java @@ -270,13 +270,18 @@ public class UserService { } public Result openMember(OpenMemberVo memberVo) { -// TbUserInfo userInfo = new TbUserInfo(); -// userInfo.setId(memberVo.getId()); -// userInfo.setHeadImg(memberVo.getHeadImg()); -// userInfo.setNickName(memberVo.getNickName()); -// userInfo.setTelephone(memberVo.getTelephone()); -// userInfo.setBirthDay(memberVo.getBirthDay()); -// userInfoMapper.updateByPrimaryKeySelective(userInfo); + TbUserInfo userInfo = new TbUserInfo(); + userInfo.setId(memberVo.getId()); + userInfo.setHeadImg(memberVo.getHeadImg()); + userInfo.setNickName(memberVo.getNickName()); + userInfo.setTelephone(memberVo.getTelephone()); + userInfo.setBirthDay(memberVo.getBirthDay()); + userInfoMapper.updateByPrimaryKeySelective(userInfo); + List tbShopUsers = shopUserMapper.selectAllByUserId(memberVo.getId().toString()); + for (TbShopUser tbShopUser : tbShopUsers) { + tbShopUser.setTelephone(memberVo.getTelephone()); + shopUserMapper.updateByPrimaryKey(tbShopUser); + } TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(memberVo.getId().toString(), memberVo.getShopId().toString()); tbShopUser.setName(memberVo.getNickName()); tbShopUser.setHeadImg(memberVo.getHeadImg()); From 82b4f773e4b74ca697bf467cc19451cf992e1966 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 16 Aug 2024 14:28:43 +0800 Subject: [PATCH 26/28] =?UTF-8?q?shopUser=E8=BF=94=E5=9B=9E=20=E5=BA=97?= =?UTF-8?q?=E9=93=BA=E7=BB=8F=E7=BA=AC=E5=BA=A6=20=E5=8F=8A=20=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/UserContoller.java | 5 +++-- 1 file changed, 3 insertions(+), 2 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 e90bfe9..57a7608 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -115,8 +115,9 @@ public class UserContoller { } if (tbShopInfo != null) { shopUser.setShopName(tbShopInfo.getShopName()); - }else { - shopUser.setShopName(""); + shopUser.setLng(tbShopInfo.getLng()); + shopUser.setLat(tbShopInfo.getLat()); + shopUser.setAddress(tbShopInfo.getAddress()); } return Result.success(CodeEnum.SUCCESS, shopUser); } From 952a6181752ef9a8d5ca431142dda8367ff7e833 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 16 Aug 2024 15:31:07 +0800 Subject: [PATCH 27/28] =?UTF-8?q?shopId=20undefined=20=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/cashierservice/controller/UserContoller.java | 3 +++ 1 file changed, 3 insertions(+) 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 57a7608..b32adf4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/UserContoller.java @@ -70,6 +70,9 @@ public class UserContoller { @GetMapping("/shopUserInfo") public Result shopUserInfo(@RequestParam("userId") String userId, @RequestHeader("openId") String openId, @RequestParam("shopId") String shopId) throws Exception { + if(shopId.equals("undefined")){ + return Result.fail("店铺信息错误,请联系管理员!"); + } TbShopUser shopUser = new TbShopUser(); TbShopInfo tbShopInfo = new TbShopInfo(); if (StringUtils.isNotBlank(shopId) && !shopId.equals("null")) { From 22c04c61f5b928e80f527fcbcaa8c69b211e9ebb Mon Sep 17 00:00:00 2001 From: GYJ <1157756119@qq.com> Date: Mon, 19 Aug 2024 15:30:14 +0800 Subject: [PATCH 28/28] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BC=B9=E7=AA=97=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TbShopAdController.java | 40 ++++++++++++ .../cashierservice/dao/TbShopAdDao.java | 23 +++++++ .../cashierservice/entity/TbShopAd.java | 63 +++++++++++++++++++ .../entity/dto/TbShopAdDto.java | 61 ++++++++++++++++++ .../service/TbShopAdService.java | 20 ++++++ .../service/impl/TbShopAdServiceImpl.java | 27 ++++++++ src/main/resources/mapper/TbShopAdDao.xml | 22 +++++++ 7 files changed, 256 insertions(+) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/controller/TbShopAdController.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopAdDao.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopAd.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/TbShopAdDto.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopAdService.java create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopAdServiceImpl.java create mode 100644 src/main/resources/mapper/TbShopAdDao.xml diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbShopAdController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbShopAdController.java new file mode 100644 index 0000000..faabacf --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbShopAdController.java @@ -0,0 +1,40 @@ +package com.chaozhanggui.system.cashierservice.controller; + +import com.chaozhanggui.system.cashierservice.entity.TbShopAd; +import com.chaozhanggui.system.cashierservice.entity.dto.TbShopAdDto; +import com.chaozhanggui.system.cashierservice.service.TbShopAdService; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; +import com.chaozhanggui.system.cashierservice.sign.Result; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * (TbShopAd)表控制层 + * + * @author GYJ + * @since 2024-08-19 14:25:09 + */ +@RestController +@RequestMapping("tbShopAd") +public class TbShopAdController { + + private final TbShopAdService tbShopAdService; + + public TbShopAdController(@Qualifier("tbShopAdServiceImpl") TbShopAdService tbShopAdService) { + this.tbShopAdService = tbShopAdService; + } + + + @GetMapping("/list") + public Result list(@RequestParam(value = "shopId") Integer shopId) { + List tbShopAds = tbShopAdService.shopAdList(shopId); + return Result.success(CodeEnum.ENCRYPT, TbShopAdDto.convertShopAdDoToDtoList(tbShopAds)); + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopAdDao.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopAdDao.java new file mode 100644 index 0000000..3030d0f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbShopAdDao.java @@ -0,0 +1,23 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbShopAd; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * (TbShopAd)表数据库访问层 + * + * @author GYJ + * @since 2024-08-19 14:25:09 + */ +public interface TbShopAdDao { + /** + * 查询指定行数据 + * + * @return 对象列表 + */ + @Select("select * from fycashier.tb_shop_ad where (shop_id = #{songId} or shop_id = 1) and status=1") + List shopAdList(Integer shopId); +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopAd.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopAd.java new file mode 100644 index 0000000..ffb7e8d --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopAd.java @@ -0,0 +1,63 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import lombok.Data; + +import java.util.Date; +import java.io.Serializable; + +/** + * (TbShopAd)实体类 + * + * @author GYJ + * @since 2024-08-19 14:25:09 + */ +@Data +public class TbShopAd implements Serializable { + private static final long serialVersionUID = -34028307481923067L; +/** + * 自增id + */ + private Integer id; +/** + * 店铺id,如果是通用广告则为0 + */ + private Integer shopId; +/** + * 广告图片地址 + */ + private String imgUrl; +/** + * 跳转页面路径 + */ + private String linkPath; +/** + * 广告展示圆角 + */ + private Integer borderRadius; +/** + * 弹窗展示位置:home首页,make_order点餐页 + */ + private String showPosition; +/** + * 显示频率:only_one 仅首次展示, every_show 每次打开都展示,every_day 每天展示一次,three_day 每三天展示一次, seven_day 每七天展示一次, thirty_day 没30天展示一次 + */ + private String frequency; +/** + * 广告状态:0未启用,1已启用 + */ + private Integer status; +/** + * 排序 + */ + private Integer sort; +/** + * 创建时间 + */ + private Date createTime; +/** + * 更新时间 + */ + private Date updateTime; + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/TbShopAdDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/TbShopAdDto.java new file mode 100644 index 0000000..006ce6f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/TbShopAdDto.java @@ -0,0 +1,61 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + +import com.chaozhanggui.system.cashierservice.entity.TbShopAd; +import lombok.Data; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author GYJ + */ +@Data +public class TbShopAdDto { + private Integer id; + /** + * 店铺id,如果是通用广告则为0 + */ + private Integer shopId; + /** + * 广告图片地址 + */ + private String imgUrl; + /** + * 跳转页面路径 + */ + private String linkPath; + /** + * 广告展示圆角 + */ + private Integer borderRadius; + /** + * 弹窗展示位置:home首页,make_order点餐页 + */ + private String showPosition; + /** + * 显示频率:only_one 仅首次展示, every_show 每次打开都展示,every_day 每天展示一次,three_day 每三天展示一次, seven_day 每七天展示一次, thirty_day 没30天展示一次 + */ + private String frequency; + + /** + * 更新时间 + */ + private Long updateTime; + + public static List convertShopAdDoToDtoList(List adList) { + return adList.stream().map(TbShopAdDto::convertShopAdDoToDto).collect(Collectors.toList()); + } + + public static TbShopAdDto convertShopAdDoToDto(TbShopAd ad) { + TbShopAdDto dto = new TbShopAdDto(); + dto.setId(ad.getId()); + dto.setShopId(ad.getShopId()); + dto.setImgUrl(ad.getImgUrl()); + dto.setLinkPath(ad.getLinkPath()); + dto.setBorderRadius(ad.getBorderRadius()); + dto.setShowPosition(ad.getShowPosition()); + dto.setFrequency(ad.getFrequency()); + dto.setUpdateTime(ad.getUpdateTime().getTime()); + return dto; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopAdService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopAdService.java new file mode 100644 index 0000000..9cad181 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbShopAdService.java @@ -0,0 +1,20 @@ +package com.chaozhanggui.system.cashierservice.service; + +import com.chaozhanggui.system.cashierservice.entity.TbShopAd; + +import java.util.List; + +/** + * (TbShopAd)表服务接口 + * + * @author GYJ + * @since 2024-08-19 14:25:17 + */ +public interface TbShopAdService { + /** + * 分页查询 + * + * @return 查询结果 + */ + List shopAdList(Integer shopId); +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopAdServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopAdServiceImpl.java new file mode 100644 index 0000000..ad9ebb7 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopAdServiceImpl.java @@ -0,0 +1,27 @@ +package com.chaozhanggui.system.cashierservice.service.impl; + +import com.chaozhanggui.system.cashierservice.dao.TbShopAdDao; +import com.chaozhanggui.system.cashierservice.entity.TbShopAd; +import com.chaozhanggui.system.cashierservice.service.TbShopAdService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * (TbShopAd)表服务实现类 + * + * @author GYJ + * @since 2024-08-19 14:25:17 + */ +@Service +public class TbShopAdServiceImpl implements TbShopAdService { + @Autowired + private TbShopAdDao tbShopAdDao; + + @Override + public List shopAdList(Integer shopId) { + System.out.println("shopId = " + shopId); + return tbShopAdDao.shopAdList(shopId); + } +} diff --git a/src/main/resources/mapper/TbShopAdDao.xml b/src/main/resources/mapper/TbShopAdDao.xml new file mode 100644 index 0000000..799d46a --- /dev/null +++ b/src/main/resources/mapper/TbShopAdDao.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +