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 b36d7d9..a52d21c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java @@ -50,12 +50,13 @@ public class ProductController { * @return */ @RequestMapping("queryProduct") - public Result queryProduct(@RequestBody Map map) { + public Result queryProduct(@RequestHeader("id") String userId,@RequestBody Map map) { if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("shopId")) { return Result.fail("参数错误"); } return productService.queryProduct( + userId, map.get("shopId").toString(), (map.containsKey("productGroupId") && ObjectUtil.isNotEmpty(map.get("productGroupId"))) ? map.get("productGroupId").toString() : ""); } @@ -81,9 +82,10 @@ public class ProductController { @RequestParam(value = "code", required = false) String code, @RequestParam("shopId") String shopId, @RequestParam("productId") String productId, - @RequestParam("spec_tag") String spec_tag + @RequestParam("spec_tag") String spec_tag, + @RequestParam("isVip") Integer isVip ) { - return productService.queryProductSku(code,shopId, productId, spec_tag); + return productService.queryProductSku(code,shopId, productId, spec_tag,isVip); } @PostMapping("addCart") diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateGiveRecordMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateGiveRecordMapper.java deleted file mode 100644 index 96709b7..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateGiveRecordMapper.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.chaozhanggui.system.cashierservice.dao; - -import com.chaozhanggui.system.cashierservice.entity.TbActivateGiveRecord; -import org.apache.ibatis.annotations.Param; - -import java.util.List; - -/** - * 活动商品赠送表(TbActivateGiveRecord)表数据库访问层 - * - * @author ww - * @since 2024-08-20 15:20:43 - */ -public interface TbActivateGiveRecordMapper { - - /** - * 通过ID查询单条数据 - * - * @param id 主键 - * @return 实例对象 - */ - TbActivateGiveRecord queryById(Integer id); - - /** - * 查询数据 - * - * @param tbActivateGiveRecord 查询条件 - * @return 对象列表 - */ - List queryAll(TbActivateGiveRecord tbActivateGiveRecord); - - - /** - * 新增数据 - * - * @param tbActivateGiveRecord 实例对象 - * @return 影响行数 - */ - int insert(TbActivateGiveRecord tbActivateGiveRecord); - - /** - * 批量新增数据(MyBatis原生foreach方法) - * - * @param entities List 实例对象列表 - * @return 影响行数 - */ - int insertBatch(@Param("entities") List entities); - - /** - * 修改数据 - * - * @param tbActivateGiveRecord 实例对象 - * @return 影响行数 - */ - int update(TbActivateGiveRecord tbActivateGiveRecord); - - /** - * 通过主键删除数据 - * - * @param id 主键 - * @return 影响行数 - */ - int deleteById(Integer id); - -} - diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java new file mode 100644 index 0000000..7a5a8f8 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java @@ -0,0 +1,72 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbActivateInRecord; +import com.chaozhanggui.system.cashierservice.entity.TbProduct; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 活动商品赠送表(TbActivateInRecord)表数据库访问层 + * + * @author ww + * @since 2024-08-22 11:13:40 + */ +public interface TbActivateInRecordMapper { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TbActivateInRecord queryById(Integer id); + + /** + * 查询数据 + * + * @param tbActivateInRecord 查询条件 + * @return 对象列表 + */ + List queryAll(TbActivateInRecord tbActivateInRecord); + + List queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId); + int queryByVipIdAndShopIdAndProId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId,@Param("productId") Integer productId); + List queryAllByVipIdAndShopIdAndProId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId,@Param("productId") Integer productId); + + /** + * 新增数据 + * + * @param tbActivateInRecord 实例对象 + * @return 影响行数 + */ + int insert(TbActivateInRecord tbActivateInRecord); + + /** + * 批量新增数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertBatch(@Param("entities") List entities); + + /** + * 修改数据 + * + * @param tbActivateInRecord 实例对象 + * @return 影响行数 + */ + int update(TbActivateInRecord tbActivateInRecord); + + int updateOverNumById(@Param("id")Integer id,@Param("overNum")Integer overNum); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 影响行数 + */ + int deleteById(Integer id); + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java new file mode 100644 index 0000000..b2b9dcd --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java @@ -0,0 +1,74 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbActivateOutRecord; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 活动赠送商品使用记录表(TbActivateOutRecord)表数据库访问层 + * + * @author ww + * @since 2024-08-22 11:21:56 + */ +public interface TbActivateOutRecordMapper { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TbActivateOutRecord queryById(Integer id); + + /** + * 查询数据 + * + * @param tbActivateOutRecord 查询条件 + * @return 对象列表 + */ + List queryAll(TbActivateOutRecord tbActivateOutRecord); + + + /** + * 新增数据 + * + * @param tbActivateOutRecord 实例对象 + * @return 影响行数 + */ + int insert(TbActivateOutRecord tbActivateOutRecord); + + /** + * 批量新增数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertBatch(@Param("entities") List entities); + + /** + * 修改数据 + * + * @param tbActivateOutRecord 实例对象 + * @return 影响行数 + */ + int update(TbActivateOutRecord tbActivateOutRecord); + + /** + * 根据订单id 将数据状态变为 + * @param orderId 订单Id + * @param status 状态 + * @return + */ + int updateByOrderIdAndStatus(@Param("orderId")Integer orderId,@Param("status")String status); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 影响行数 + */ + int deleteById(Integer id); + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateProductMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateProductMapper.java index 59077ab..6240a16 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateProductMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateProductMapper.java @@ -29,6 +29,7 @@ public interface TbActivateProductMapper { List queryAll(TbActivateProduct tbActivateProduct); List queryAllByActivateId(Integer activateId); + List queryProsByActivateId(Integer activateId); /** 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 3968f0d..dc3920a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java @@ -26,7 +26,7 @@ public interface TbProductMapper { 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 selectByCodeAndSkuId(@Param("code") String code,@Param("skuId") Integer skuId,@Param("shopId") String shopId,@Param("isVip") Integer isVip); 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/TbActivate.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivate.java index 480d9b3..a2d5246 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivate.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivate.java @@ -1,7 +1,11 @@ package com.chaozhanggui.system.cashierservice.entity; +import org.springframework.util.CollectionUtils; + import java.io.Serializable; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; public class TbActivate implements Serializable { private Integer id; @@ -20,6 +24,7 @@ public class TbActivate implements Serializable { //是否赠送商品 0否 1是 private Integer isGiftPro; + private List gives; private static final long serialVersionUID = 1L; @@ -86,4 +91,16 @@ public class TbActivate implements Serializable { public void setIsGiftPro(Integer isGiftPro) { this.isGiftPro = isGiftPro; } + + public List getGives() { + return gives; + } + + public void setGives(List gives) { + if(CollectionUtils.isEmpty(gives)){ + this.gives = new ArrayList<>(); + }else { + this.gives = gives; + } + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivateGiveRecord.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivateInRecord.java similarity index 78% rename from src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivateGiveRecord.java rename to src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivateInRecord.java index e643810..afc81af 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivateGiveRecord.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivateInRecord.java @@ -4,13 +4,13 @@ import java.util.Date; import java.io.Serializable; /** - * 活动商品赠送表(TbActivateGiveRecord)实体类 + * 活动商品赠送表(TbActivateInRecord)实体类 * * @author ww - * @since 2024-08-20 15:20:43 + * @since 2024-08-22 11:13:40 */ -public class TbActivateGiveRecord implements Serializable { - private static final long serialVersionUID = -53463432636369401L; +public class TbActivateInRecord implements Serializable { + private static final long serialVersionUID = -35515830201618782L; private Integer id; /** @@ -25,30 +25,37 @@ public class TbActivateGiveRecord implements Serializable { * 赠送数量 */ private Integer num; + /** + * 未使用数量 + */ + private Integer overNum; /** * 店铺id */ private Integer shopId; - private Integer sourceFlowId; /** * 来源活动id */ private Integer sourceActId; + private Integer sourceFlowId; + private Date createTime; private Date updateTime; - public TbActivateGiveRecord(Integer vipUserId, Integer proId, Integer num, Integer shopId, Integer sourceActId,Integer sourceFlowId) { + public TbActivateInRecord(Integer vipUserId, Integer proId, Integer num, Integer shopId, Integer sourceActId,Integer sourceFlowId) { this.vipUserId = vipUserId; this.proId = proId; this.num = num; + this.overNum = num; this.shopId = shopId; this.sourceActId = sourceActId; this.sourceFlowId = sourceFlowId; this.createTime=new Date(); } + public Integer getId() { return id; } @@ -81,6 +88,14 @@ public class TbActivateGiveRecord implements Serializable { this.num = num; } + public Integer getOverNum() { + return overNum; + } + + public void setOverNum(Integer overNum) { + this.overNum = overNum; + } + public Integer getShopId() { return shopId; } @@ -89,6 +104,13 @@ public class TbActivateGiveRecord implements Serializable { this.shopId = shopId; } + public Integer getSourceActId() { + return sourceActId; + } + + public void setSourceActId(Integer sourceActId) { + this.sourceActId = sourceActId; + } public Integer getSourceFlowId() { return sourceFlowId; @@ -98,14 +120,6 @@ public class TbActivateGiveRecord implements Serializable { this.sourceFlowId = sourceFlowId; } - public Integer getSourceActId() { - return sourceActId; - } - - public void setSourceActId(Integer sourceActId) { - this.sourceActId = sourceActId; - } - public Date getCreateTime() { return createTime; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivateOutRecord.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivateOutRecord.java new file mode 100644 index 0000000..dd5d295 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbActivateOutRecord.java @@ -0,0 +1,125 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.util.Date; +import java.io.Serializable; + +/** + * 活动赠送商品使用记录表(TbActivateOutRecord)实体类 + * + * @author ww + * @since 2024-08-22 11:21:56 + */ +public class TbActivateOutRecord implements Serializable { + private static final long serialVersionUID = -54399746948905097L; + + private Integer id; + /** + * 商品赠送Id + */ + private Integer giveId; + /** + * 商品id + */ + private Integer proId; + /** + * 使用数量 + */ + private Integer useNum; + /** + * 退单量 + */ + private Integer refNum; + /** + * 订单id + */ + private String orderId; + //新建: create, 完成: closed, 取消:cancel, + private String status; + + private Date createTime; + + private Date updateTime; + + public TbActivateOutRecord(Integer giveId, Integer proId, Integer useNum, String orderId, String status) { + this.giveId = giveId; + this.proId = proId; + this.useNum = useNum; + this.orderId = orderId; + this.status = status; + this.createTime = new Date(); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getGiveId() { + return giveId; + } + + public void setGiveId(Integer giveId) { + this.giveId = giveId; + } + + public Integer getProId() { + return proId; + } + + public void setProId(Integer proId) { + this.proId = proId; + } + + public Integer getUseNum() { + return useNum; + } + + public void setUseNum(Integer useNum) { + this.useNum = useNum; + } + + public Integer getRefNum() { + return refNum; + } + + public void setRefNum(Integer refNum) { + this.refNum = refNum; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getOrderId() { + return orderId; + } + + public void setOrderId(String orderId) { + this.orderId = orderId; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java index 0c99e3a..b74eb9a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java @@ -58,6 +58,7 @@ public class TbCashierCart implements Serializable { private Long updatedAt; private Integer userId; private String tableId; + private Byte isVip; private TbProductSpec tbProductSpec; private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java index 3d97089..2b95fe1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java @@ -20,6 +20,8 @@ public class TbOrderDetail implements Serializable { private Integer num; + private Byte isVip; + private String productName; private String status; 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 1985f1a..cb5e0c6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -29,6 +29,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import javax.annotation.Resource; import java.io.IOException; import java.math.BigDecimal; import java.time.Instant; @@ -57,6 +58,9 @@ public class CartService { private TbMerchantAccountMapper merchantAccountMapper; @Autowired private TbUserInfoMapper userInfoMapper; + @Autowired + private TbShopUserMapper shopUserMapper; + @Autowired private TbOrderDetailMapper orderDetailMapper; @Autowired @@ -71,6 +75,10 @@ public class CartService { private final WxAccountUtil wxAccountUtil; private final TbShopOpenIdMapper shopOpenIdMapper; + @Resource + private TbActivateInRecordService activateInRecordService; + @Autowired + private TbActivateOutRecordMapper outRecordMapper; @Autowired private RabbitProducer producer; @@ -122,6 +130,7 @@ public class CartService { if (!CollectionUtils.isEmpty(tbCashierCarts)) { for (TbCashierCart cashierCart : tbCashierCarts) { array.add(cashierCart); + if(cashierCart.getIsVip().equals((byte) 1)) continue; amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); } redisUtil.saveMessage(RedisCst.TABLE_CART.concat(key), array.toString()); @@ -148,8 +157,9 @@ public class CartService { String skuId = jsonObject.getString("skuId"); Integer type = jsonObject.getInteger("type"); Integer buyNum = jsonObject.getInteger("num"); + Integer isVip = jsonObject.getInteger("isVip"); if (StringUtils.isBlank(tableId) || StringUtils.isBlank(shopId) || StringUtils.isBlank(productId) - || StringUtils.isBlank(skuId) || type==null || buyNum == null) { + || StringUtils.isBlank(skuId) || type == null || buyNum == null) { return Result.fail("参数缺失"); } String key = tableId + "-" + shopId; @@ -160,42 +170,38 @@ public class CartService { } // 判断商品是否已下架 TbProductSkuWithBLOBs tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId)); - if (tbProductSkuWithBLOBs ==null || tbProductSkuWithBLOBs.getIsGrounding().equals(0)) { - rmCart(jsonObject,skuId,key); + if (tbProductSkuWithBLOBs == null || tbProductSkuWithBLOBs.getIsGrounding().equals(0)) { + rmCart(jsonObject, skuId, key); return Result.fail("商品已下架"); } if (tbProduct.getIsStock() == 1) { // 1:共享库存 0:独立库存 if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) { if (tbProduct.getIsPauseSale() == 1) {//是否售罄 - rmCart(jsonObject,skuId,key); + rmCart(jsonObject, skuId, key); return Result.fail("该商品已售罄"); } } else { if (tbProductSkuWithBLOBs.getIsPauseSale() == 1) {//是否售罄 - rmCart(jsonObject,skuId,key); + rmCart(jsonObject, skuId, key); return Result.fail("该商品已售罄"); } } } - - - List proskuConList= tbProskuConMapper.selectByShopIdAndSkuIdAndProductId(Integer.valueOf(skuId),Integer.valueOf(shopId),Integer.valueOf(productId)); - if(Objects.nonNull(proskuConList)&&proskuConList.size()>0){ - for (TbProskuCon proskuCon : proskuConList) { - if("1".equals(proskuCon.getStatus())){ - TbConsInfo consInfo= tbConsInfoMapper.selectByPrimaryKey(proskuCon.getConInfoId()); - if("1".equals(consInfo.getIsCheck())){ - if(N.gt(proskuCon.getSurplusStock(),consInfo.getStockNumber().abs().subtract(consInfo.getStockConsume().abs()))){ - return Result.fail("商品:".concat(tbProduct.getName()).concat("对应的:").concat(consInfo.getConName()).concat("耗材不足")); + List proskuConList = tbProskuConMapper.selectByShopIdAndSkuIdAndProductId(Integer.valueOf(skuId), Integer.valueOf(shopId), Integer.valueOf(productId)); + if (Objects.nonNull(proskuConList) && proskuConList.size() > 0) { + for (TbProskuCon proskuCon : proskuConList) { + if ("1".equals(proskuCon.getStatus())) { + TbConsInfo consInfo = tbConsInfoMapper.selectByPrimaryKey(proskuCon.getConInfoId()); + if ("1".equals(consInfo.getIsCheck())) { + if (N.gt(proskuCon.getSurplusStock(), consInfo.getStockNumber().abs().subtract(consInfo.getStockConsume().abs()))) { + return Result.fail("商品:".concat(tbProduct.getName()).concat("对应的:").concat(consInfo.getConName()).concat("耗材不足")); + } } } } } - } - - JSONArray jsonArray = new JSONArray(); BigDecimal amount = BigDecimal.ZERO; @@ -205,7 +211,7 @@ public class CartService { if (Objects.isNull(array) || array.isEmpty()) { if (type == 1) { TbCashierCart cashierCart = addCart(productId, skuId, - jsonObject.getInteger("userId"), buyNum, tableId, shopId); + jsonObject.getInteger("userId"), buyNum, tableId, shopId,isVip); jsonArray.add(cashierCart); amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); } @@ -214,7 +220,8 @@ public class CartService { 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)) { + + if (cashierCart.getSkuId().equals(skuId) && cashierCart.getIsVip().intValue() == isVip) { cashierCart.setTotalNumber(buyNum); cashierCart.setNumber(buyNum); if (type == 0 && tbProductSkuWithBLOBs.getSuit() != null && tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() < tbProductSkuWithBLOBs.getSuit()) { @@ -222,7 +229,11 @@ public class CartService { continue; } if (cashierCart.getNumber() > 0) { - cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + if (isVip == 1) { + cashierCart.setTotalAmount(BigDecimal.ZERO); + } else { + cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + } cashierCart.setUpdatedAt(Instant.now().toEpochMilli()); cashierCartMapper.updateByPrimaryKeySelective(cashierCart); } else { @@ -236,7 +247,7 @@ public class CartService { } if (flag && type == 1) { TbCashierCart cashierCart = addCart(productId, skuId, - jsonObject.getInteger("userId"), buyNum, tableId, shopId); + jsonObject.getInteger("userId"), buyNum, tableId, shopId,isVip); jsonArray.add(cashierCart); amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); } @@ -244,9 +255,11 @@ public class CartService { } else { if (type == 1) { TbCashierCart cashierCart = addCart(productId, skuId, - jsonObject.getInteger("userId"), buyNum, tableId, shopId); + jsonObject.getInteger("userId"), buyNum, tableId, shopId,isVip); jsonArray.add(cashierCart); - amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + if (isVip != 1) { + amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee()))); + } } } }catch (MsgException e){ @@ -264,7 +277,7 @@ public class CartService { jsonObject1.put("reqData", jsonObject); PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, "", false); } catch (Exception e) { - log.error("长链接错误 createCart{}", e.getMessage()); + log.error("长链接错误 createCart {}", e.getMessage()); } return Result.success(CodeEnum.SUCCESS); } @@ -379,7 +392,7 @@ public class CartService { } } - private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId) throws Exception{ + private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId,Integer isVip) throws Exception{ try { TbProduct product = productMapper.selectById(Integer.valueOf(productId)); String key = tableId + "-" + shopId; @@ -435,7 +448,14 @@ public class CartService { cashierCart.setUpdatedAt(Instant.now().toEpochMilli()); cashierCart.setPackFee(BigDecimal.ZERO); cashierCart.setRefundNumber(0); - cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(productSku.getSalePrice().add(cashierCart.getPackFee()))); + if(isVip==1){ + cashierCart.setIsVip(Byte.parseByte("1")); + cashierCart.setTotalAmount(BigDecimal.ZERO); + cashierCart.setSalePrice(BigDecimal.ZERO); + }else { + cashierCart.setIsVip(Byte.parseByte("0")); + cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(productSku.getSalePrice().add(cashierCart.getPackFee()))); + } cashierCartMapper.insert(cashierCart); @@ -448,7 +468,7 @@ public class CartService { return cashierCart; } catch (Exception e) { - log.error("长链接错误 addCart{}", e.getMessage()); + log.error("长链接错误 addCart {}", e.getMessage()); throw e; } } @@ -479,9 +499,36 @@ public class CartService { if (tbUserInfo == null) { MsgException.throwException("生成订单失败"); } + TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(userId, shopId); + boolean isVip= false; + if (tbShopUser != null && tbShopUser.getIsVip().equals((byte) 1)) { + isVip=true; + } + //校验 库存 耗材 for (int i = 0; i < array.size(); i++) { JSONObject object = array.getJSONObject(i); TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); + if (cashierCart.getIsVip().equals((byte) 1)) { + if (isVip) { + int i1 = activateInRecordService.queryByVipIdAndShopIdAndProId( + Integer.valueOf(tbShopUser.getId()), Integer.valueOf(shopId), Integer.valueOf(cashierCart.getProductId())); + if (i1 < cashierCart.getTotalNumber()) { + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("status", "fail"); + jsonObject1.put("msg", "会员商品[" + cashierCart.getName() + "],可下单数量为" + i1); + jsonObject1.put("data", new ArrayList<>()); + PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); + return; + } + } else { + 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); + return; + } + } TbProductSkuWithBLOBs tbProduct = productSkuMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getSkuId())); TbProduct tbProduct1 = tbProductMapper.selectById(Integer.valueOf(tbProduct.getProductId())); @@ -540,6 +587,7 @@ public class CartService { orderDetail.setPackAmount(cashierCart.getPackFee()); orderDetail.setProductImg(cashierCart.getCoverImg()); orderDetail.setStatus("unpaid"); + orderDetail.setIsVip(cashierCart.getIsVip()); if (StringUtils.isNotEmpty(cashierCart.getOrderId())) { orderId = Integer.valueOf(cashierCart.getOrderId()); } @@ -553,6 +601,8 @@ public class CartService { TbShopTable shopTable = shopTableMapper.selectQRcode(jsonObject.getString("tableId")); //生成订单 TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId); + + //优惠卷 String isBuyYhq = "false"; String isuseYhq = "false"; if (jsonObject.containsKey("isYhq") && jsonObject.getString("isYhq").equals("1")) { @@ -697,9 +747,29 @@ public class CartService { orderDetail.setOrderId(orderId); orderDetailMapper.insert(orderDetail); } + List outRecords = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JSONObject object = array.getJSONObject(i); TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class); + if (cashierCart.getIsVip().equals((byte) 1)) { + List actInRecords = activateInRecordService.queryAllByVipIdAndShopIdAndProId( + Integer.valueOf(tbShopUser.getId()), Integer.valueOf(orderInfo.getShopId()), Integer.valueOf(cashierCart.getProductId())); + Integer totalNumber = cashierCart.getTotalNumber(); + for (TbActivateInRecord actInRecord : actInRecords) { + if (totalNumber > 0) { + if (actInRecord.getOverNum() > totalNumber) { + TbActivateOutRecord outRecord = new TbActivateOutRecord(actInRecord.getId(), actInRecord.getProId(), totalNumber, orderInfo.getId().toString(), "create"); + outRecords.add(outRecord); + activateInRecordService.updateOverNumById(actInRecord.getId(), actInRecord.getOverNum() - totalNumber); + } else { + TbActivateOutRecord outRecord = new TbActivateOutRecord(actInRecord.getId(), actInRecord.getProId(), actInRecord.getOverNum(), orderInfo.getId().toString(), "create"); + outRecords.add(outRecord); + activateInRecordService.updateOverNumById(actInRecord.getId(), 0); + totalNumber = totalNumber - actInRecord.getOverNum(); + } + } + } + } cashierCart.setUpdatedAt(System.currentTimeMillis()); cashierCart.setOrderId(orderId + ""); cashierCart.setStatus("closed"); @@ -709,7 +779,7 @@ public class CartService { } - + if(!CollectionUtils.isEmpty(outRecords)) outRecordMapper.insertBatch(outRecords); // 发送mq消息 JSONObject jsonObject2 = new JSONObject(); jsonObject2.put("orderId", orderInfo.getId()); @@ -751,7 +821,7 @@ public class CartService { } catch (Exception e) { - log.info("长链接错误 addCart{}", e.getMessage()); + log.info("长链接错误 createOrder{}", e.getMessage()); e.printStackTrace(); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index f765809..2e54784 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -34,6 +34,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; @@ -73,8 +74,8 @@ public class PayService { TbShopPayTypeMapper tbShopPayTypeMapper; @Autowired private TbActivateProductMapper actProductMapper; - @Autowired - private TbActivateGiveRecordMapper actGiveRecordMapper; + @Resource + private TbActivateInRecordMapper activateInRecordMapper; @Autowired private TbShopSongOrderMapper tbShopSongOrderMapper; @@ -115,6 +116,10 @@ public class PayService { @Autowired TbShopUserFlowMapper tbShopUserFlowMapper; + @Resource + private TbActivateInRecordService activateInRecordService; + @Autowired + private TbActivateOutRecordMapper outRecordMapper; @Value("${thirdPay.payType}") private String thirdPayType; @@ -365,6 +370,10 @@ public class PayService { // return Result.failCode("会员卡余额不足","2"); return Result.success(CodeEnum.SUCCESS, "2"); } + List cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, null); + if (ObjectUtil.isEmpty(cashierCarts) || ObjectUtil.isNull(cashierCarts)) { + return Result.fail("购物车信息不存在"); + } user.setAmount(user.getAmount().subtract(orderInfo.getOrderAmount())); user.setConsumeAmount(user.getConsumeAmount().add(orderInfo.getPayAmount())); @@ -872,7 +881,7 @@ public class PayService { //更新子单状态 tbOrderDetailMapper.updateStatusByOrderIdAndStatus(orderInfo.getId(), "closed"); - + outRecordMapper.updateByOrderIdAndStatus(orderInfo.getId(),"closed"); //修改主单状态 orderInfo.setStatus("closed"); orderInfo.setPayType("wx_lite"); @@ -926,7 +935,7 @@ public class PayService { orderInfo.setPayOrderNo(payOrderNO); orderInfo.setPayAmount(orderInfo.getOrderAmount()); tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); - + outRecordMapper.updateByOrderIdAndStatus(orderInfo.getId(),"closed"); JSONObject jsonObject = new JSONObject(); jsonObject.put("token", 0); @@ -987,6 +996,11 @@ public class PayService { public Result getActivate(String shopId, int page, int pageSize) { PageHelper.startPage(page, pageSize); List list = tbActivateMapper.selectByShopId(shopId); + for (TbActivate tbActivate : list) { + if (tbActivate.getIsGiftPro() == 1) { + tbActivate.setGives(actProductMapper.queryProsByActivateId(tbActivate.getId())); + } + } PageInfo pageInfo = new PageInfo(list); return Result.success(CodeEnum.SUCCESS, pageInfo); } @@ -1099,12 +1113,12 @@ public class PayService { if (ObjectUtil.isNotEmpty(activate) && ObjectUtil.isNotNull(activate)) { if (activate.getIsGiftPro() != null && activate.getIsGiftPro() == 1) { List tbActivateProducts = actProductMapper.queryAllByActivateId(activate.getId()); - List actGiveRecords = new ArrayList<>(); + List actGiveRecords = new ArrayList<>(); for (TbActivateProduct actPro : tbActivateProducts) { - TbActivateGiveRecord record = new TbActivateGiveRecord(Integer.valueOf(tbShopUser.getId()), actPro.getProductId(), actPro.getNum(), Integer.valueOf(tbShopUser.getShopId()), activate.getId(),flowId); + TbActivateInRecord record = new TbActivateInRecord(Integer.valueOf(tbShopUser.getId()), actPro.getProductId(), actPro.getNum(), Integer.valueOf(tbShopUser.getShopId()), activate.getId(),flowId); actGiveRecords.add(record); } - actGiveRecordMapper.insertBatch(actGiveRecords); + activateInRecordMapper.insertBatch(actGiveRecords); } BigDecimal amount = BigDecimal.ZERO; switch (activate.getHandselType()) { 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 97c6826..a1934bd 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -80,6 +80,8 @@ public class ProductService { @Autowired private TbConsInfoMapper tbConsInfoMapper; + @Resource + private TbActivateInRecordService activateInRecordService; public Result queryShopIdByTableCode(String userId, String openId, String code, String lat, String lng) { if (StringUtils.isBlank(code)) return Result.fail("桌码信息为空"); @@ -142,32 +144,41 @@ public class ProductService { return Result.success(CodeEnum.SUCCESS, concurrentMap); } - public Result queryProduct(String shopId, String productGroupId) { + public Result queryProduct(String userId,String shopId, String productGroupId) { ConcurrentMap concurrentMap = new ConcurrentHashMap<>(); Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null; //招牌菜 List tbProducts = tbProductMapper.selectIsSpecialty(Integer.valueOf(shopId)); - concurrentMap.put("hots", handleDate(tbProducts,true,1)); + concurrentMap.put("hots", handleDate(tbProducts,true,1,false)); 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,1)); + hot.setProducts(handleDate(hots,true,1,false)); //商品 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,false,g.getIsSale())); + g.setProducts(handleDate(products,false,g.getIsSale(),false)); } else { g.setProducts(new ArrayList<>()); } }); groupList.sort(Comparator.comparingInt(TbProductGroup::getIsSale).reversed()); + TbShopUser tbShopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, shopId); + if (tbShopUser != null) { + TbProductGroup vipProGroup = new TbProductGroup(); + vipProGroup.setName("会员商品"); + List vipPros = activateInRecordService.queryByVipIdAndShopId(Integer.valueOf(tbShopUser.getId()), Integer.valueOf(shopId)); + if(!CollectionUtils.isEmpty(vipPros)){ + vipProGroup.setProducts(handleDate(vipPros, true, 1, true)); + groupList.add(0, vipProGroup); + } + } groupList.add(0, hot); concurrentMap.put("productInfo", groupList); } @@ -353,7 +364,7 @@ public class ProductService { * @param check 是否校验可售 * @return */ - public List handleDate(List products,boolean check,Integer isSale){ + public List handleDate(List products,boolean check,Integer isSale,boolean isVip){ if (!CollectionUtils.isEmpty(products)) { products.parallelStream().forEach(it -> { if(check){ @@ -396,6 +407,10 @@ public class ProductService { //售价 it.setLowPrice(lowerPrice); it.setProductSkuResult(skuResult); + if (isVip) { + it.setLowPrice(BigDecimal.ZERO); + it.setIsVip(Byte.parseByte("1")); + } }); return products; }else { @@ -449,8 +464,8 @@ public class ProductService { } - public Result queryProductSku(String code, String shopId, String productId, String spec_tag) { - if (ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(productId)) { + public Result queryProductSku(String code, String shopId, String productId, String spec_tag,Integer isVip) { + if (ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(productId) || ObjectUtil.isEmpty(isVip)) { return Result.fail("参数错误"); } TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId, productId, spec_tag); @@ -463,7 +478,7 @@ public class ProductService { tbProductSkuWithBLOBs.setId(null); }else { if (StringUtils.isNotBlank(code)) { - Integer sum = tbProductMapper.selectByCodeAndSkuId(code, tbProductSkuWithBLOBs.getId(), shopId); + Integer sum = tbProductMapper.selectByCodeAndSkuId(code, tbProductSkuWithBLOBs.getId(), shopId,isVip); tbProductSkuWithBLOBs.setNumber(sum); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbActivateGiveRecordService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbActivateGiveRecordService.java deleted file mode 100644 index d10894b..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbActivateGiveRecordService.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.chaozhanggui.system.cashierservice.service; - -import com.chaozhanggui.system.cashierservice.entity.TbActivateGiveRecord; - -/** - * 活动商品赠送表(TbActivateGiveRecord)表服务接口 - * - * @author ww - * @since 2024-08-20 15:20:43 - */ -public interface TbActivateGiveRecordService { - - /** - * 通过ID查询单条数据 - * - * @param id 主键 - * @return 实例对象 - */ - TbActivateGiveRecord queryById(Integer id); - - /** - * 新增数据 - * - * @param tbActivateGiveRecord 实例对象 - * @return 实例对象 - */ - TbActivateGiveRecord insert(TbActivateGiveRecord tbActivateGiveRecord); - - /** - * 修改数据 - * - * @param tbActivateGiveRecord 实例对象 - * @return 实例对象 - */ - TbActivateGiveRecord update(TbActivateGiveRecord tbActivateGiveRecord); - - /** - * 通过主键删除数据 - * - * @param id 主键 - * @return 是否成功 - */ - boolean deleteById(Integer id); - -} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbActivateInRecordService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbActivateInRecordService.java new file mode 100644 index 0000000..01c3a7d --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbActivateInRecordService.java @@ -0,0 +1,56 @@ +package com.chaozhanggui.system.cashierservice.service; + +import com.chaozhanggui.system.cashierservice.entity.TbActivateInRecord; +import com.chaozhanggui.system.cashierservice.entity.TbProduct; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + +import java.util.List; + +/** + * 活动商品赠送表(TbActivateInRecord)表服务接口 + * + * @author ww + * @since 2024-08-22 11:13:40 + */ +public interface TbActivateInRecordService { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TbActivateInRecord queryById(Integer id); + + List queryByVipIdAndShopId(Integer vipUserId, Integer shopId); + int queryByVipIdAndShopIdAndProId(Integer vipUserId, Integer shopId,Integer productId); + List queryAllByVipIdAndShopIdAndProId(Integer vipUserId, Integer shopId,Integer productId); + + /** + * 新增数据 + * + * @param tbActivateInRecord 实例对象 + * @return 实例对象 + */ + TbActivateInRecord insert(TbActivateInRecord tbActivateInRecord); + + /** + * 修改数据 + * + * @param tbActivateInRecord 实例对象 + * @return 实例对象 + */ + TbActivateInRecord update(TbActivateInRecord tbActivateInRecord); + + int updateOverNumById(Integer id,Integer overNum); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + boolean deleteById(Integer id); + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbActivateOutRecordService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbActivateOutRecordService.java new file mode 100644 index 0000000..e8be3aa --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbActivateOutRecordService.java @@ -0,0 +1,45 @@ +package com.chaozhanggui.system.cashierservice.service; + +import com.chaozhanggui.system.cashierservice.entity.TbActivateOutRecord; + +/** + * 活动赠送商品使用记录表(TbActivateOutRecord)表服务接口 + * + * @author ww + * @since 2024-08-22 11:21:56 + */ +public interface TbActivateOutRecordService { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TbActivateOutRecord queryById(Integer id); + + /** + * 新增数据 + * + * @param tbActivateOutRecord 实例对象 + * @return 实例对象 + */ + TbActivateOutRecord insert(TbActivateOutRecord tbActivateOutRecord); + + /** + * 修改数据 + * + * @param tbActivateOutRecord 实例对象 + * @return 实例对象 + */ + TbActivateOutRecord update(TbActivateOutRecord tbActivateOutRecord); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + boolean deleteById(Integer id); + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateGiveRecordServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateGiveRecordServiceImpl.java deleted file mode 100644 index c690e62..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateGiveRecordServiceImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.chaozhanggui.system.cashierservice.service.impl; - -import com.chaozhanggui.system.cashierservice.entity.TbActivateGiveRecord; -import com.chaozhanggui.system.cashierservice.dao.TbActivateGiveRecordMapper; -import com.chaozhanggui.system.cashierservice.service.TbActivateGiveRecordService; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; - -/** - * 活动商品赠送表(TbActivateGiveRecord)表服务实现类 - * - * @author ww - * @since 2024-08-20 15:20:43 - */ -@Service -public class TbActivateGiveRecordServiceImpl implements TbActivateGiveRecordService { - @Resource - private TbActivateGiveRecordMapper tbActivateGiveRecordMapper; - - /** - * 通过ID查询单条数据 - * - * @param id 主键 - * @return 实例对象 - */ - @Override - public TbActivateGiveRecord queryById(Integer id) { - return this.tbActivateGiveRecordMapper.queryById(id); - } - - - /** - * 新增数据 - * - * @param tbActivateGiveRecord 实例对象 - * @return 实例对象 - */ - @Override - public TbActivateGiveRecord insert(TbActivateGiveRecord tbActivateGiveRecord) { - this.tbActivateGiveRecordMapper.insert(tbActivateGiveRecord); - return tbActivateGiveRecord; - } - - /** - * 修改数据 - * - * @param tbActivateGiveRecord 实例对象 - * @return 实例对象 - */ - @Override - public TbActivateGiveRecord update(TbActivateGiveRecord tbActivateGiveRecord) { - this.tbActivateGiveRecordMapper.update(tbActivateGiveRecord); - return this.queryById(tbActivateGiveRecord.getId()); - } - - /** - * 通过主键删除数据 - * - * @param id 主键 - * @return 是否成功 - */ - @Override - public boolean deleteById(Integer id) { - return this.tbActivateGiveRecordMapper.deleteById(id) > 0; - } -} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateInRecordServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateInRecordServiceImpl.java new file mode 100644 index 0000000..a3cb707 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateInRecordServiceImpl.java @@ -0,0 +1,91 @@ +package com.chaozhanggui.system.cashierservice.service.impl; + +import com.chaozhanggui.system.cashierservice.dao.TbActivateInRecordMapper; +import com.chaozhanggui.system.cashierservice.entity.TbActivateInRecord; +import com.chaozhanggui.system.cashierservice.entity.TbProduct; +import com.chaozhanggui.system.cashierservice.service.TbActivateInRecordService; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 活动商品赠送表(TbActivateInRecord)表服务实现类 + * + * @author ww + * @since 2024-08-22 11:13:40 + */ +@Service +@Primary +public class TbActivateInRecordServiceImpl implements TbActivateInRecordService { + @Resource + private TbActivateInRecordMapper tbActivateInRecordMapper; + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + @Override + public TbActivateInRecord queryById(Integer id) { + return this.tbActivateInRecordMapper.queryById(id); + } + + @Override + public List queryByVipIdAndShopId(Integer vipUserId, Integer shopId) { + return tbActivateInRecordMapper.queryByVipIdAndShopId(vipUserId, shopId); + } + + @Override + public int queryByVipIdAndShopIdAndProId(Integer vipUserId, Integer shopId,Integer productId){ + return tbActivateInRecordMapper.queryByVipIdAndShopIdAndProId(vipUserId,shopId,productId); + } + + @Override + public List queryAllByVipIdAndShopIdAndProId(Integer vipUserId, Integer shopId,Integer productId){ + return tbActivateInRecordMapper.queryAllByVipIdAndShopIdAndProId(vipUserId,shopId,productId); + } + + + /** + * 新增数据 + * + * @param tbActivateInRecord 实例对象 + * @return 实例对象 + */ + @Override + public TbActivateInRecord insert(TbActivateInRecord tbActivateInRecord) { + this.tbActivateInRecordMapper.insert(tbActivateInRecord); + return tbActivateInRecord; + } + + /** + * 修改数据 + * + * @param tbActivateInRecord 实例对象 + * @return 实例对象 + */ + @Override + public TbActivateInRecord update(TbActivateInRecord tbActivateInRecord) { + this.tbActivateInRecordMapper.update(tbActivateInRecord); + return this.queryById(tbActivateInRecord.getId()); + } + + @Override + public int updateOverNumById(Integer id,Integer overNum){ + return tbActivateInRecordMapper.updateOverNumById(id,overNum); + } + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + @Override + public boolean deleteById(Integer id) { + return this.tbActivateInRecordMapper.deleteById(id) > 0; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateOutRecordServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateOutRecordServiceImpl.java new file mode 100644 index 0000000..493603d --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateOutRecordServiceImpl.java @@ -0,0 +1,69 @@ +package com.chaozhanggui.system.cashierservice.service.impl; + +import com.chaozhanggui.system.cashierservice.entity.TbActivateOutRecord; +import com.chaozhanggui.system.cashierservice.dao.TbActivateOutRecordMapper; +import com.chaozhanggui.system.cashierservice.service.TbActivateOutRecordService; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * 活动赠送商品使用记录表(TbActivateOutRecord)表服务实现类 + * + * @author ww + * @since 2024-08-22 11:21:56 + */ +@Service +@Primary +public class TbActivateOutRecordServiceImpl implements TbActivateOutRecordService { + @Resource + private TbActivateOutRecordMapper tbActivateOutRecordMapper; + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + @Override + public TbActivateOutRecord queryById(Integer id) { + return this.tbActivateOutRecordMapper.queryById(id); + } + + /** + * 新增数据 + * + * @param tbActivateOutRecord 实例对象 + * @return 实例对象 + */ + @Override + public TbActivateOutRecord insert(TbActivateOutRecord tbActivateOutRecord) { + this.tbActivateOutRecordMapper.insert(tbActivateOutRecord); + return tbActivateOutRecord; + } + + /** + * 修改数据 + * + * @param tbActivateOutRecord 实例对象 + * @return 实例对象 + */ + @Override + public TbActivateOutRecord update(TbActivateOutRecord tbActivateOutRecord) { + this.tbActivateOutRecordMapper.update(tbActivateOutRecord); + return this.queryById(tbActivateOutRecord.getId()); + } + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + @Override + public boolean deleteById(Integer id) { + return this.tbActivateOutRecordMapper.deleteById(id) > 0; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateProductServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateProductServiceImpl.java index 4803729..66e033e 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateProductServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbActivateProductServiceImpl.java @@ -4,6 +4,7 @@ package com.chaozhanggui.system.cashierservice.service.impl; import com.chaozhanggui.system.cashierservice.dao.TbActivateProductMapper; import com.chaozhanggui.system.cashierservice.entity.TbActivateProduct; import com.chaozhanggui.system.cashierservice.service.TbActivateProductService; +import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -15,6 +16,7 @@ import javax.annotation.Resource; * @since 2024-08-20 15:15:02 */ @Service +@Primary public class TbActivateProductServiceImpl implements TbActivateProductService { @Resource private TbActivateProductMapper tbActivateProductMapper; diff --git a/src/main/resources/mapper/TbActivateGiveRecordMapper.xml b/src/main/resources/mapper/TbActivateInRecordMapper.xml similarity index 57% rename from src/main/resources/mapper/TbActivateGiveRecordMapper.xml rename to src/main/resources/mapper/TbActivateInRecordMapper.xml index 63320d2..aa51b93 100644 --- a/src/main/resources/mapper/TbActivateGiveRecordMapper.xml +++ b/src/main/resources/mapper/TbActivateInRecordMapper.xml @@ -1,12 +1,13 @@ - + - + + @@ -16,23 +17,55 @@ id - , vip_user_id, pro_id, num, shop_id, source_flow_id,source_act_id, create_time, update_time + , vip_user_id, pro_id, num, over_num, shop_id, source_act_id, source_flow_id, create_time, update_time - select - from tb_activate_give_record + from tb_activate_in_record where id = #{id} + + + + + + - select - from tb_activate_give_record + from tb_activate_in_record and id = #{id} @@ -46,6 +79,9 @@ and num = #{num} + + and over_num = #{overNum} + and shop_id = #{shopId} @@ -67,22 +103,25 @@ - insert into tb_activate_give_record(vip_user_id, pro_id, num, shop_id, source_act_id, source_flow_id, create_time, update_time) - values (#{vipUserId}, #{proId}, #{num}, #{shopId}, #{sourceActId}, #{sourceFlowId}, #{createTime}, #{updateTime}) + insert into tb_activate_in_record(vip_user_id, pro_id, num, over_num, shop_id, source_act_id, source_flow_id, + create_time, update_time) + values (#{vipUserId}, #{proId}, #{num}, #{overNum}, #{shopId}, #{sourceActId}, #{sourceFlowId}, #{createTime}, + #{updateTime}) - insert into tb_activate_give_record(vip_user_id, pro_id, num, shop_id, source_act_id, source_flow_id, create_time, update_time) + insert into tb_activate_in_record(vip_user_id, pro_id, num, over_num, shop_id, source_act_id, source_flow_id, + create_time, update_time) values - (#{entity.vipUserId}, #{entity.proId}, #{entity.num}, #{entity.shopId}, #{entity.sourceActId}, - #{entity.sourceFlowId},#{entity.createTime}, #{entity.updateTime}) + (#{entity.vipUserId}, #{entity.proId}, #{entity.num}, #{entity.overNum}, #{entity.shopId}, + #{entity.sourceActId}, #{entity.sourceFlowId}, #{entity.createTime}, #{entity.updateTime}) - update tb_activate_give_record + update tb_activate_in_record vip_user_id = #{vipUserId}, @@ -93,6 +132,9 @@ num = #{num}, + + over_num = #{overNum}, + shop_id = #{shopId}, @@ -111,11 +153,18 @@ where id = #{id} + + update tb_activate_in_record + set + over_num = #{overNum} + where id = #{id}; + + delete - from tb_activate_give_record + from tb_activate_in_record where id = #{id} diff --git a/src/main/resources/mapper/TbActivateOutRecordMapper.xml b/src/main/resources/mapper/TbActivateOutRecordMapper.xml new file mode 100644 index 0000000..ba0d537 --- /dev/null +++ b/src/main/resources/mapper/TbActivateOutRecordMapper.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + id + , give_id, pro_id, use_num, ref_num, order_id,status, create_time, update_time + + + + + + + + + + + insert into tb_activate_out_record(give_id, pro_id, use_num, ref_num, order_id, status, create_time, update_time) + values (#{giveId}, #{proId}, #{useNum}, #{refNum}, #{orderId}, #{status} #{createTime}, #{updateTime}) + + + + insert into tb_activate_out_record(give_id, pro_id, use_num, ref_num, order_id, status, create_time, update_time) + values + + (#{entity.giveId}, #{entity.proId}, #{entity.useNum}, #{entity.refNum}, #{entity.orderId}, + #{entity.status}, #{entity.createTime}, #{entity.updateTime}) + + + + + + update tb_activate_out_record + + + give_id = #{giveId}, + + + pro_id = #{proId}, + + + use_num = #{useNum}, + + + ref_num = #{refNum}, + + + order_id = #{orderId}, + + + status = #{status}, + + + create_time = #{createTime}, + + + update_time = #{updateTime}, + + + where id = #{id} + + + update tb_activate_out_record + set + status = 'closed' + where order_id = #{orderId} + + + + + + delete + from tb_activate_out_record + where id = #{id} + + + + diff --git a/src/main/resources/mapper/TbActivateProductMapper.xml b/src/main/resources/mapper/TbActivateProductMapper.xml index 56eefa7..ac6356a 100644 --- a/src/main/resources/mapper/TbActivateProductMapper.xml +++ b/src/main/resources/mapper/TbActivateProductMapper.xml @@ -58,6 +58,15 @@ id, activate_id, product_id, num, create_time, update_time activate_id = #{activateId} + + diff --git a/src/main/resources/mapper/TbCashierCartMapper.xml b/src/main/resources/mapper/TbCashierCartMapper.xml index 0674893..50c4e1a 100644 --- a/src/main/resources/mapper/TbCashierCartMapper.xml +++ b/src/main/resources/mapper/TbCashierCartMapper.xml @@ -33,11 +33,12 @@ + id, master_id, order_id, ref_order_id, total_amount, product_id, cover_img, is_sku,pack_fee,is_pack,is_gift,pending_at, sku_id, name, sale_price, number, total_number, refund_number, category_id, status, - type, merchant_id, shop_id, created_at, updated_at, user_id, table_id,pack_fee,trade_day,uuid,sku_name + type, merchant_id, shop_id, created_at, updated_at, user_id, table_id,pack_fee,trade_day,uuid,sku_name,is_vip select @@ -43,12 +44,12 @@ product_id, product_sku_id, num, product_name, product_sku_name, product_img, create_time, update_time, price, - price_amount,pack_amount,status) + price_amount,pack_amount,status,is_vip) values (#{id,jdbcType=INTEGER}, #{orderId,jdbcType=INTEGER}, #{shopId,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, #{productSkuId,jdbcType=INTEGER}, #{num,jdbcType=INTEGER}, #{productName,jdbcType=VARCHAR}, #{productSkuName,jdbcType=VARCHAR}, #{productImg,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{price,jdbcType=DECIMAL}, - #{priceAmount,jdbcType=DECIMAL},#{packAmount,jdbcType=DECIMAL},#{status,jdbcType=VARCHAR}) + #{priceAmount,jdbcType=DECIMAL},#{packAmount,jdbcType=DECIMAL},#{status,jdbcType=VARCHAR},#{isVip,jdbcType=TINYINT}) insert into tb_order_detail @@ -92,6 +93,9 @@ price_amount, + + is_vip, + @@ -133,6 +137,9 @@ #{priceAmount,jdbcType=DECIMAL}, + + #{isVip,jdbcType=TINYINT}, + num = #{num,jdbcType=INTEGER}, + + is_vip = #{isVip,jdbcType=TINYINT}, + product_name = #{productName,jdbcType=VARCHAR}, @@ -197,6 +207,7 @@ create_time = #{createTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP}, price = #{price,jdbcType=DECIMAL}, + is_vip= #{isVip,jdbcType=TINYINT}, price_amount = #{priceAmount,jdbcType=DECIMAL} where id = #{id,jdbcType=INTEGER} diff --git a/src/main/resources/mapper/TbProductMapper.xml b/src/main/resources/mapper/TbProductMapper.xml index 66fee1f..4946725 100644 --- a/src/main/resources/mapper/TbProductMapper.xml +++ b/src/main/resources/mapper/TbProductMapper.xml @@ -1009,6 +1009,7 @@ AND t.sku_id = #{skuId} AND t.`status` = 'create' AND t.table_id = #{code} + AND t.is_vip = #{isVip}