优惠券 find接口

This commit is contained in:
2024-10-29 18:25:51 +08:00
parent 270c274d63
commit a296718232
7 changed files with 58 additions and 44 deletions

View File

@@ -4,6 +4,7 @@ import com.chaozhanggui.system.cashierservice.entity.dto.CouponDto;
import com.chaozhanggui.system.cashierservice.service.TbShopCouponService;
import com.chaozhanggui.system.cashierservice.sign.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -29,7 +30,7 @@ public class TbShopCouponController {
* @return 查询结果
*/
@RequestMapping("find")
public Result find(@RequestBody CouponDto param) {
public Result find(@Validated @RequestBody CouponDto param) {
return tbShopCouponService.find(param);
}

View File

@@ -31,10 +31,9 @@ public interface TbActivateInRecordMapper {
List<TbActivateInRecord> queryAll(TbActivateInRecord tbActivateInRecord);
//未使用券
List<TbUserCouponVo> queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
List<TbActivateInRecord> queryByVipIdAndShopIdIn(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
List<TbUserCouponVo> queryByVipIdAndShopId(@Param("vipUserIds") List<Integer> vipUserIds, @Param("shopId") Integer shopId);
//过期券
List<TbUserCouponVo> queryByVipIdAndShopIdExpire(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
List<TbUserCouponVo> queryByVipIdAndShopIdExpire(@Param("vipUserIds") List<Integer> vipUserIds, @Param("shopId") Integer shopId);
int countCouponNum(@Param("userId") Integer userId);

View File

@@ -32,7 +32,7 @@ public interface TbActivateOutRecordMapper {
*/
List<TbActivateOutRecord> queryAll(TbActivateOutRecord tbActivateOutRecord, @Param("pageable") Pageable pageable);
List<TbUserCouponVo> queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
List<TbUserCouponVo> queryByVipIdAndShopId(@Param("vipUserIds") List<Integer> vipUserIds, @Param("shopId") Integer shopId);
/**
* 新增数据

View File

@@ -1,11 +1,15 @@
package com.chaozhanggui.system.cashierservice.entity.dto;
import lombok.Data;
import javax.validation.constraints.NotNull;
@Data
public class CouponDto {
private Integer shopId;
private Integer userId;
//-1已过期 1未使用 2已使用
@NotNull(message = "状态不允许为空")
private Integer status;
private Integer orderId;
}

View File

@@ -43,9 +43,10 @@ public class TbShopCouponServiceImpl implements TbShopCouponService {
@Resource
private TbActivateOutRecordMapper outRecordMapper;
@Override
public List<TbUserCouponVo> getActivateCouponByAmount(Integer shopId, String userId, BigDecimal amount) {
TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(userId, String.valueOf(shopId));
List<TbUserCouponVo> tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(Integer.valueOf(tbShopUser.getId()), shopId);
List<TbUserCouponVo> tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(Arrays.asList(Integer.valueOf(tbShopUser.getId())), shopId);
ArrayList<TbUserCouponVo> canUseCoupon = new ArrayList<>();
if (CollectionUtil.isNotEmpty(tbUserCouponVos)) {
String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("");
@@ -112,13 +113,13 @@ public class TbShopCouponServiceImpl implements TbShopCouponService {
@Override
public Result find(CouponDto param) {
TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(param.getUserId().toString(), param.getShopId().toString());
if (param.getOrderId() != null) {
TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(param.getUserId().toString(), param.getShopId().toString());
TbOrderInfo tbOrderInfo = orderInfoMapper.selectByPrimaryKey(param.getOrderId());
List<TbOrderDetail> tbOrderDetails = orderDetailMapper.selectAllByOrderId(param.getOrderId());
Set<Integer> pros = tbOrderDetails.stream().map(TbOrderDetail::getProductId).collect(Collectors.toSet());
if (CollectionUtil.isNotEmpty(tbOrderDetails)) {
List<TbUserCouponVo> tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(Integer.valueOf(tbShopUser.getId()), param.getShopId());
List<TbUserCouponVo> tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(Arrays.asList(Integer.valueOf(tbShopUser.getId())), param.getShopId());
if (CollectionUtil.isNotEmpty(tbUserCouponVos)) {
String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("");
LocalTime now = LocalTime.now();
@@ -145,12 +146,14 @@ public class TbShopCouponServiceImpl implements TbShopCouponService {
}
}
} else {
List<TbShopUser> tbShopUser = shopUserMapper.selectAllByUserId(param.getUserId().toString());
List<Integer> ids = tbShopUser.stream().map(TbShopUser::getId).map(Integer::valueOf).collect(Collectors.toList());
if (param.getStatus().equals(1)) {
return new Result(CodeEnum.SUCCESS, inRecordMapper.queryByVipIdAndShopId(Integer.valueOf(tbShopUser.getId()), param.getShopId()));
return new Result(CodeEnum.SUCCESS, inRecordMapper.queryByVipIdAndShopId(ids, param.getShopId()));
} else if (param.getStatus().equals(-1)) {
return new Result(CodeEnum.SUCCESS, inRecordMapper.queryByVipIdAndShopIdExpire(Integer.valueOf(tbShopUser.getId()), param.getShopId()));
return new Result(CodeEnum.SUCCESS, inRecordMapper.queryByVipIdAndShopIdExpire(ids, param.getShopId()));
} else if (param.getStatus().equals(2)) {
return new Result(CodeEnum.SUCCESS, outRecordMapper.queryByVipIdAndShopId(Integer.valueOf(tbShopUser.getId()), param.getShopId()));
return new Result(CodeEnum.SUCCESS, outRecordMapper.queryByVipIdAndShopId(ids, param.getShopId()));
}
}
return new Result(CodeEnum.SUCCESS);

View File

@@ -49,10 +49,18 @@ id, vip_user_id, coupon_id, name, type, pro_id, full_amount, discount_amount, nu
inRecord.use_end_time as endTime
FROM
tb_activate_in_record inRecord
LEFT JOIN tb_product pro ON inRecord.pro_id = pro.id and pro.shop_id = #{shopId}
LEFT JOIN tb_product pro ON inRecord.pro_id = pro.id
<if test="shopId != null and shopId != ''">
and pro.shop_id = #{shopId}
</if>
WHERE
inRecord.vip_user_id = #{vipUserId}
and inRecord.shop_id = #{shopId}
inRecord.vip_user_id in
<foreach item="item" index="index" collection="vipUserIds" open="(" separator="," close=")">
#{item}
</foreach>
<if test="shopId != null and shopId != ''">
and inRecord.shop_id = #{shopId}
</if>
and inRecord.over_num != 0
and inRecord.use_start_time &lt; now()
and inRecord.use_end_time &gt; now()
@@ -70,30 +78,20 @@ id, vip_user_id, coupon_id, name, type, pro_id, full_amount, discount_amount, nu
inRecord.use_end_time as endTime
FROM
tb_activate_in_record inRecord
LEFT JOIN tb_product pro ON inRecord.pro_id = pro.id and pro.shop_id = #{shopId}
LEFT JOIN tb_product pro ON inRecord.pro_id = pro.id
<if test="shopId != null and shopId != ''">
and pro.shop_id = #{shopId}
</if>
WHERE
inRecord.vip_user_id = #{vipUserId}
and inRecord.shop_id = #{shopId}
and inRecord.over_num != 0
and inRecord.use_end_time &lt; now()
order by inRecord.use_end_time asc
</select>
<select id="queryByVipIdAndShopIdIn" resultMap="TbActivateInRecordMap">
SELECT
<include refid="Base_Column_List"/>,
CASE
WHEN inRecord.type = 1 THEN inRecord.NAME
WHEN inRecord.type = 2 THEN pro.NAME
END AS `name`
FROM
tb_activate_in_record inRecord
LEFT JOIN tb_product pro ON inRecord.pro_id = pro.id and pro.shop_id = #{shopId}
WHERE
inRecord.vip_user_id = #{vipUserId}
and inRecord.shop_id = #{shopId}
and inRecord.over_num != 0
and inRecord.use_end_time &lt; now()
inRecord.vip_user_id in
<foreach item="item" index="index" collection="vipUserIds" open="(" separator="," close=")">
#{item}
</foreach>
<if test="shopId != null and shopId != ''">
and inRecord.shop_id = #{shopId}
</if>
and inRecord.over_num != 0
and inRecord.use_end_time &lt; now()
order by inRecord.use_end_time asc
</select>

View File

@@ -41,15 +41,24 @@
tb_activate_out_record outRecord
INNER JOIN tb_activate_in_record inRecord
on outRecord.give_id = inRecord.id
and inRecord.shop_id = #{shopId}
and inRecord.vip_user_id = #{vipUserId}
<if test="shopId != null and shopId != ''">
and inRecord.shop_id = #{shopId}
</if>
LEFT JOIN tb_product pro
ON inRecord.pro_id = pro.id and pro.shop_id = #{shopId}
ON inRecord.pro_id = pro.id
<if test="shopId != null and shopId != ''">
and pro.shop_id = #{shopId}
</if>
WHERE
outRecord.vip_user_id = #{vipUserId}
and outRecord.shop_id = #{shopId}
and outRecord.status = 'closed'
and outRecord.use_num-outRecord.ref_num >0
outRecord.vip_user_id in
<foreach item="item" index="index" collection="vipUserIds" open="(" separator="," close=")">
#{item}
</foreach>
<if test="shopId != null and shopId != ''">
and outRecord.shop_id = #{shopId}
</if>
and outRecord.status = 'closed'
and outRecord.use_num-outRecord.ref_num >0
order by outRecord.create_time desc
</select>