diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbUserCouponsController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbUserCouponsController.java new file mode 100644 index 0000000..508867a --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/TbUserCouponsController.java @@ -0,0 +1,32 @@ +package com.chaozhanggui.system.cashierservice.controller; + +import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto; +import com.chaozhanggui.system.cashierservice.service.TbUserCouponsService; +import com.chaozhanggui.system.cashierservice.sign.Result; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +@RequestMapping("userConpons") +public class TbUserCouponsController { + /** + * 服务对象 + */ + @Autowired + private TbUserCouponsService tbUserCouponsService; + + /** + * 查询优惠卷 + * @param conponDto + * @return + */ + @RequestMapping("find") + public Result queryByPage(@RequestBody UserCouponDto conponDto) { + return tbUserCouponsService.queryByPage(conponDto); + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java index 7a5a8f8..86ad0ee 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateInRecordMapper.java @@ -2,6 +2,8 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbActivateInRecord; import com.chaozhanggui.system.cashierservice.entity.TbProduct; +import com.chaozhanggui.system.cashierservice.entity.TbUserCoupons; +import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -31,6 +33,7 @@ public interface TbActivateInRecordMapper { List queryAll(TbActivateInRecord tbActivateInRecord); List queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId); + List queryVipPro(@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); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java index b2b9dcd..23c1983 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbActivateOutRecordMapper.java @@ -1,6 +1,7 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbActivateOutRecord; +import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -29,6 +30,8 @@ public interface TbActivateOutRecordMapper { */ List queryAll(TbActivateOutRecord tbActivateOutRecord); + List queryVipPro(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId); + /** * 新增数据 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java index 192a2e3..8306b65 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbUserCouponsMapper.java @@ -1,6 +1,8 @@ package com.chaozhanggui.system.cashierservice.dao; import com.chaozhanggui.system.cashierservice.entity.TbUserCoupons; +import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto; +import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Component; @@ -18,6 +20,7 @@ public interface TbUserCouponsMapper { int insertSelective(TbUserCoupons record); TbUserCoupons selectByPrimaryKey(Integer id); + List queryAllSelective(UserCouponDto record); int updateByPrimaryKeySelective(TbUserCoupons record); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java index 6f59527..13d7029 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbUserCoupons.java @@ -7,10 +7,11 @@ import java.math.BigDecimal; import java.util.Date; @Data -public class TbUserCoupons implements Serializable { +public class TbUserCoupons implements Serializable{ private Integer id; private String userId; + private String detail; private Integer orderId; private BigDecimal couponsPrice; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/UserCouponDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/UserCouponDto.java new file mode 100644 index 0000000..b53d03f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/UserCouponDto.java @@ -0,0 +1,11 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + +import lombok.Data; + +@Data +public class UserCouponDto extends BasePageDto{ + private Integer userId; + private Integer status; + private Integer shopId; + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/UserCouponVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/UserCouponVo.java new file mode 100644 index 0000000..553002f --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/UserCouponVo.java @@ -0,0 +1,33 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +import java.math.BigDecimal; + +@Data +public class UserCouponVo { + /** + * 2 会员商品卷 + */ + private Integer type; + /** + * 卷描述 + */ + private String detail; + /** + * 优惠金额 + */ + private BigDecimal couponsPrice = BigDecimal.ZERO; + /** + * 多少可用 + */ + private BigDecimal couponsAmount = BigDecimal.ZERO; + /** + * 数量 + */ + private Integer num; + /** + * 卷状态 0 未使用 + */ + 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 2e65900..63b6d84 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -654,28 +654,7 @@ public class CartService { couponAmount = userCoupons.getCouponsAmount(); } else { TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(couponsId); - if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "优惠券已使用"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } - if (N.gt(userCoupons.getCouponsAmount(), totalAmount)) { - log.info("开始处理订单"); - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("status", "fail"); - jsonObject1.put("msg", "订单金额小于优惠价金额"); - jsonObject1.put("type", jsonObject.getString("type")); - jsonObject1.put("data", ""); - PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true); - log.info("消息推送"); - return; - } + totalAmount = totalAmount.subtract(userCoupons.getCouponsAmount()); userCoupons.setStatus("1"); userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 5, 30)); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/TbUserCouponsService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbUserCouponsService.java new file mode 100644 index 0000000..c687d0a --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/TbUserCouponsService.java @@ -0,0 +1,22 @@ +package com.chaozhanggui.system.cashierservice.service; + +import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto; +import com.chaozhanggui.system.cashierservice.sign.Result; + +/** + * (TbUserCoupons)表服务接口 + * + * @author ww + * @since 2024-09-02 13:38:20 + */ +public interface TbUserCouponsService { + + /** + * 分页查询 + * + * @param tbUserCoupons 筛选条件 + * @return 查询结果 + */ + Result queryByPage(UserCouponDto tbUserCoupons); + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbUserCouponsServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbUserCouponsServiceImpl.java new file mode 100644 index 0000000..41744c4 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbUserCouponsServiceImpl.java @@ -0,0 +1,70 @@ +package com.chaozhanggui.system.cashierservice.service.impl; + +import com.chaozhanggui.system.cashierservice.dao.TbActivateInRecordMapper; +import com.chaozhanggui.system.cashierservice.dao.TbActivateOutRecordMapper; +import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper; +import com.chaozhanggui.system.cashierservice.dao.TbUserCouponsMapper; +import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto; +import com.chaozhanggui.system.cashierservice.entity.vo.ShopUserListVo; +import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo; +import com.chaozhanggui.system.cashierservice.service.TbUserCouponsService; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; +import com.chaozhanggui.system.cashierservice.sign.Result; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * (TbUserCoupons)表服务实现类 + * + * @author ww + * @since 2024-09-02 13:38:20 + */ +@Primary +@Service +public class TbUserCouponsServiceImpl implements TbUserCouponsService { + @Resource + private TbUserCouponsMapper tbUserCouponsMapper; + @Resource + private TbActivateInRecordMapper inRecordMapper; + @Resource + private TbActivateOutRecordMapper outRecordMapper; + @Autowired + private TbShopUserMapper tbShopUserMapper; + + + /** + * 分页查询 + * @return 查询结果 + */ + @Override + public Result queryByPage(UserCouponDto couponDto) { +// PageHelper.startPage(couponDto.getPage(), couponDto.getSize()); +// List result = tbUserCouponsMapper.queryAllSelective(couponDto); +// return new Result(CodeEnum.SUCCESS, new PageInfo<>(result)); +// List result = tbUserCouponsMapper.queryAllSelective(couponDto); + List result = new ArrayList<>(); + List tbShopUsers = tbShopUserMapper.selectByUserId(couponDto.getUserId().toString(), couponDto.getShopId()==null?null:couponDto.getShopId().toString()); + if (!CollectionUtils.isEmpty(tbShopUsers)) { + tbShopUsers.forEach(s -> { + if (couponDto.getStatus()==null || (couponDto.getStatus() != null && couponDto.getStatus() != 0)) { + List unuseCoupon = inRecordMapper.queryVipPro(s.getMemberId().intValue(), s.getShopId().intValue()); + result.addAll(unuseCoupon); + } + if (couponDto.getStatus()==null || (couponDto.getStatus() != null && couponDto.getStatus() != 1)) { + List useCoupon = outRecordMapper.queryVipPro(s.getMemberId().intValue(), s.getShopId().intValue()); + result.addAll(useCoupon); + } + }); + } + + return new Result(CodeEnum.SUCCESS, result); + } + +} + diff --git a/src/main/resources/mapper/TbActivateInRecordMapper.xml b/src/main/resources/mapper/TbActivateInRecordMapper.xml index aa51b93..d5e9e89 100644 --- a/src/main/resources/mapper/TbActivateInRecordMapper.xml +++ b/src/main/resources/mapper/TbActivateInRecordMapper.xml @@ -39,6 +39,19 @@ group by tb_activate_in_record.pro_id + + + + + + + diff --git a/src/main/resources/mapper/TbUserCouponsMapper.xml b/src/main/resources/mapper/TbUserCouponsMapper.xml index b746d3c..cd27c4b 100644 --- a/src/main/resources/mapper/TbUserCouponsMapper.xml +++ b/src/main/resources/mapper/TbUserCouponsMapper.xml @@ -4,6 +4,7 @@ + @@ -13,7 +14,7 @@ - id, user_id, coupons_price, coupons_amount, status, create_time, update_time, end_time,is_double + id, user_id, detail, coupons_price, coupons_amount, status, create_time, update_time, end_time,is_double + + +