更新9.26
This commit is contained in:
parent
89e1f60ac7
commit
513f5ab42f
@ -96,6 +96,16 @@ public class IntegralSettings extends BaseEntity {
|
||||
*/
|
||||
private Integer chainStoreId;
|
||||
|
||||
/**
|
||||
* 适用规则 0-无限制 1-有限制
|
||||
*/
|
||||
private Integer signApplicableRules;
|
||||
|
||||
/**
|
||||
* 签到周期 0-一周 1-两周 2-一个月 只有适用规则为1时有值
|
||||
*/
|
||||
private Integer signCycle;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,5 +21,13 @@ public interface CardCouponMapper extends BaseMapper<CardCoupon> {
|
||||
IPage<CardCoupon> pageVo(Page page, @Param("cardCoupon") CardCoupon cardCoupon);
|
||||
|
||||
IPage<CardCouponUniVo> selectAllByPageAndStoreId(Page page, @Param("cardCoupon")CardCoupon cardCoupon);
|
||||
IPage<CardCouponUniVo> selectAllByPageAndIds(Page page,@Param("ids") List<Integer> ids);
|
||||
|
||||
/**
|
||||
* 根据店铺id查询优惠券今日领取数量
|
||||
* @param cardCouponUniVos
|
||||
* @return
|
||||
*/
|
||||
List<CardCouponUniVo> selectByStoreIdCount(CardCouponUniVo cardCouponUniVos);
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuint.business.marketingActivity.cardCoupon.entity.CardCouponUser;
|
||||
import com.fuint.business.marketingActivity.cardCoupon.vo.CardCouponUniVo;
|
||||
import com.fuint.business.marketingActivity.cardCoupon.vo.CardCouponUserVo;
|
||||
import com.fuint.business.marketingActivity.cardCoupon.vo.CardCouponVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@ -11,6 +12,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 用户优惠卷表2024(CardCouponUser)表数据库访问层
|
||||
@ -38,5 +40,7 @@ public interface CardCouponUserMapper extends BaseMapper<CardCouponUser> {
|
||||
* @return
|
||||
*/
|
||||
IPage<CardCouponUserVo> queryPage(Page page,@Param("entity") CardCouponUserVo cardCouponUserVo);
|
||||
|
||||
List<CardCouponUniVo> selectCouponCount(@Param("storeId") Integer storeId,@Param("userId") Integer userId);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
resultType="com.fuint.business.marketingActivity.cardCoupon.vo.CardCouponUniVo">
|
||||
SELECT
|
||||
cc.*,
|
||||
mt.NAME AS typeName,
|
||||
mt.NAME AS storeName,
|
||||
CASE
|
||||
cc.type
|
||||
WHEN 1 THEN
|
||||
@ -44,7 +44,7 @@
|
||||
'油品立减券'
|
||||
WHEN 5 THEN
|
||||
'单品代金券'
|
||||
END AS statusName
|
||||
END AS typeName
|
||||
FROM
|
||||
card_coupon cc
|
||||
LEFT JOIN mt_store mt ON mt.id = cc.store_id
|
||||
@ -66,5 +66,46 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectByStoreIdCount"
|
||||
resultType="com.fuint.business.marketingActivity.cardCoupon.vo.CardCouponUniVo">
|
||||
select cc.id id, count(cu.id) count
|
||||
from card_coupon cc
|
||||
left join card_coupon_user as cu on cc.id = cu.card_coupon_id
|
||||
<where>
|
||||
cc.store_id = #{storeId}
|
||||
<if test="startTime!=null and startTime!=''">
|
||||
and cu.create_time between #{startTime} and #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
group by cc.id
|
||||
</select>
|
||||
<select id="selectAllByPageAndIds"
|
||||
resultType="com.fuint.business.marketingActivity.cardCoupon.vo.CardCouponUniVo">
|
||||
SELECT
|
||||
cc.*,
|
||||
mt.NAME AS storeName,
|
||||
CASE
|
||||
cc.type
|
||||
WHEN 1 THEN
|
||||
'代金券'
|
||||
WHEN 2 THEN
|
||||
'兑换券'
|
||||
WHEN 3 THEN
|
||||
'折扣券'
|
||||
WHEN 4 THEN
|
||||
'油品立减券'
|
||||
WHEN 5 THEN
|
||||
'单品代金券'
|
||||
END AS typeName
|
||||
FROM
|
||||
card_coupon cc
|
||||
LEFT JOIN mt_store mt ON mt.id = cc.store_id
|
||||
<where>
|
||||
cc.id in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -29,4 +29,12 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectCouponCount" resultType="com.fuint.business.marketingActivity.cardCoupon.vo.CardCouponUniVo">
|
||||
SELECT
|
||||
card_coupon_id id,
|
||||
count(1) count
|
||||
FROM card_coupon_user
|
||||
WHERE store_id = #{storeId} AND mt_user_id = #{userId}
|
||||
group by card_coupon_id
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.fuint.business.marketingActivity.cardCoupon.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@ -8,6 +11,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fuint.business.marketingActivity.cardCoupon.entity.CardCoupon;
|
||||
import com.fuint.business.marketingActivity.cardCoupon.mapper.CardCouponMapper;
|
||||
import com.fuint.business.marketingActivity.cardCoupon.mapper.CardCouponUserMapper;
|
||||
import com.fuint.business.marketingActivity.cardCoupon.service.CardCouponService;
|
||||
import com.fuint.business.marketingActivity.cardCoupon.vo.CardCouponUniVo;
|
||||
import com.fuint.business.marketingActivity.cardCoupon.vo.CardCouponVO;
|
||||
@ -20,6 +24,8 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 油站优惠卷表2024(CardCoupon)表服务实现类
|
||||
@ -32,6 +38,9 @@ public class CardCouponServiceImpl extends ServiceImpl<CardCouponMapper, CardCou
|
||||
|
||||
@Autowired
|
||||
private MtStoreMapper mtStoreMapper;
|
||||
|
||||
@Autowired
|
||||
private CardCouponUserMapper cardCouponUserMapper;
|
||||
@Override
|
||||
public IPage<CardCoupon> pageVo(Page page, CardCoupon cardCoupon) {
|
||||
return baseMapper.pageVo( page, cardCoupon);
|
||||
@ -49,24 +58,64 @@ public class CardCouponServiceImpl extends ServiceImpl<CardCouponMapper, CardCou
|
||||
|
||||
@Override
|
||||
public IPage selectAllByPageAndStoreId(Page page, CardCoupon cardCoupon) {
|
||||
//获取今天开始与结束时间
|
||||
DateTime now = DateUtil.date();
|
||||
DateTime startTime = DateUtil.beginOfDay(now);
|
||||
DateTime endTime = DateUtil.endOfDay(now);
|
||||
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
|
||||
//首先查询该店铺所有的优惠券
|
||||
cardCoupon.setPutType("2");
|
||||
cardCoupon.setStatus("1");
|
||||
IPage<CardCouponUniVo> cardCouponUniVos = baseMapper.selectAllByPageAndStoreId(page, cardCoupon);
|
||||
|
||||
List<CardCouponUniVo> cardCouponVos = new ArrayList<>();
|
||||
//用户拥有的优惠券以及数量
|
||||
List<CardCouponUniVo> list= cardCouponUserMapper.selectCouponCount(cardCoupon.getStoreId(), nowAccountInfo.getId());
|
||||
Map<Integer, Integer> map = list.stream().collect(Collectors.toMap(CardCouponUniVo::getId, CardCouponUniVo::getCount));
|
||||
|
||||
CardCouponUniVo cardCouponUniVo1 = new CardCouponUniVo();
|
||||
cardCouponUniVo1.setStoreId(cardCoupon.getStoreId());
|
||||
cardCouponUniVo1.setStartTime(startTime.toString());
|
||||
cardCouponUniVo1.setEndTime(endTime.toString());
|
||||
//根据店铺id查询优惠券今日领取数量
|
||||
List<CardCouponUniVo> cardCouponUniVos1 = baseMapper.selectByStoreIdCount(cardCouponUniVo1);
|
||||
Map<Integer, Integer> cardCouponMap = cardCouponUniVos1.stream().collect(Collectors.toMap(CardCouponUniVo::getId, CardCouponUniVo::getCount));
|
||||
|
||||
|
||||
//存放最终可领取的优惠券id集合
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
//循环店铺优惠券
|
||||
for (CardCouponUniVo coupon : cardCouponUniVos.getRecords()) {
|
||||
//查询该优惠券是否已到达限制数量
|
||||
if (coupon.getTfGetNum() < coupon.getTfTotal()){
|
||||
CardCouponUniVo cardCouponUniVo = BeanUtil.copyProperties(coupon, CardCouponUniVo.class);
|
||||
//计算领取的比例
|
||||
double scale = (coupon.getTfGetNum() * 1.0 / coupon.getTfTotal()) * 100;
|
||||
cardCouponUniVo.setScale(scale + "%");
|
||||
if ((coupon.getTfGetNum() < coupon.getTfTotal())) {
|
||||
Integer count = 0;
|
||||
if (ObjectUtil.isNotEmpty(cardCouponMap.get(coupon.getId()))){
|
||||
count = cardCouponMap.get(coupon.getId());
|
||||
}
|
||||
if (count < coupon.getDayGetLimit()) {
|
||||
Integer getNumLimit = coupon.getGetNumLimit();
|
||||
Integer userCount = 0;
|
||||
if (ObjectUtil.isNotEmpty(map.get(coupon.getId()))){
|
||||
userCount = map.get(coupon.getId());
|
||||
}
|
||||
if (userCount < getNumLimit) {
|
||||
//查询当前用户所拥有的优惠券数量
|
||||
ids.add(coupon.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return cardCouponUniVos;
|
||||
IPage<CardCouponUniVo> cardCouponUniVoIPage = new Page<>(page.getCurrent(), page.getSize());
|
||||
if (CollUtil.isNotEmpty(ids)) {
|
||||
cardCouponUniVoIPage = baseMapper.selectAllByPageAndIds(page, ids);
|
||||
cardCouponUniVoIPage.getRecords().stream().forEach(coupon -> extracted(coupon));
|
||||
}
|
||||
return cardCouponUniVoIPage;
|
||||
}
|
||||
|
||||
private static void extracted(CardCouponUniVo coupon) {
|
||||
//计算领取的比例
|
||||
double scale = (coupon.getTfGetNum() * 1.0 / coupon.getTfTotal()) * 100;
|
||||
coupon.setScale(scale + "%");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.fuint.business.marketingActivity.cardCoupon.vo;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fuint.business.marketingActivity.cardCoupon.entity.CardCoupon;
|
||||
import lombok.Data;
|
||||
|
||||
@ -11,4 +13,12 @@ public class CardCouponUniVo extends CardCoupon {
|
||||
private String scale;
|
||||
//兑换券类型
|
||||
private String typeName;
|
||||
|
||||
private Integer count;
|
||||
|
||||
@JsonIgnore
|
||||
private String startTime;
|
||||
|
||||
@JsonIgnore
|
||||
private String endTime;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user