储值送积分

This commit is contained in:
谭凯凯
2024-11-09 09:59:01 +08:00
committed by Tankaikai
parent e9161dbda9
commit 5131c6bfb6
7 changed files with 66 additions and 16 deletions

View File

@@ -36,6 +36,8 @@ public interface TbActivateMapper {
TbActivate selectByAmount(@Param("shopId") String shopId,@Param("amount") BigDecimal amount); TbActivate selectByAmount(@Param("shopId") String shopId,@Param("amount") BigDecimal amount);
TbActivate selectByAmountScope(@Param("shopId") String shopId,@Param("amount") BigDecimal amount);
/** /**
* 新增数据 * 新增数据

View File

@@ -1,7 +1,7 @@
package com.chaozhanggui.system.cashierservice.entity; package com.chaozhanggui.system.cashierservice.entity;
import java.util.Date;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@@ -24,6 +24,10 @@ public class TbActivate implements Serializable {
* 赠送金额 * 赠送金额
*/ */
private Integer giftAmount; private Integer giftAmount;
/**
* 赠送积分
*/
private Integer giftPoints;
/** /**
* 是否使用优惠卷 0否 1是 * 是否使用优惠卷 0否 1是
*/ */
@@ -132,5 +136,13 @@ public class TbActivate implements Serializable {
public void setGives(List<String> gives) { public void setGives(List<String> gives) {
this.gives = gives; this.gives = gives;
} }
public Integer getGiftPoints() {
return giftPoints;
}
public void setGiftPoints(Integer giftPoints) {
this.giftPoints = giftPoints;
}
} }

View File

@@ -16,10 +16,12 @@ import com.chaozhanggui.system.cashierservice.entity.Enum.PlatformTypeEnum;
import com.chaozhanggui.system.cashierservice.entity.Enum.ShopWxMsgTypeEnum; import com.chaozhanggui.system.cashierservice.entity.Enum.ShopWxMsgTypeEnum;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.*; import com.chaozhanggui.system.cashierservice.entity.dto.*;
import com.chaozhanggui.system.cashierservice.entity.vo.ShopUserListVo;
import com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo; import com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.mapper.*; import com.chaozhanggui.system.cashierservice.mapper.MpCashierCartMapper;
import com.chaozhanggui.system.cashierservice.mapper.MpOrderInfoMapper;
import com.chaozhanggui.system.cashierservice.mapper.MpShopTableMapper;
import com.chaozhanggui.system.cashierservice.mapper.MpShopUserMapper;
import com.chaozhanggui.system.cashierservice.netty.PushToAppChannelHandlerAdapter; import com.chaozhanggui.system.cashierservice.netty.PushToAppChannelHandlerAdapter;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisCst;
@@ -918,7 +920,7 @@ public class CartService {
Long memberId = Long.valueOf(orderInfo.getMemberId()); Long memberId = Long.valueOf(orderInfo.getMemberId());
if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() != 0) { if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() != 0) {
memberPointsService.addPoints(memberId, orderInfo.getPointsNum(), "用户未支付订单积分返还: " + orderInfo.getPointsNum() + "积分", Long.valueOf(orderInfo.getId())); memberPointsService.addPoints(memberId, orderInfo.getPointsNum(), "用户未支付订单积分返还: " + orderInfo.getPointsNum() + "积分", Long.valueOf(orderInfo.getId()), orderInfo.getOrderNo());
} }
OrderDeductionPointsDTO memberUsablePoints = memberPointsService.getMemberUsablePoints(memberId, orderInfo.getOrderAmount()); OrderDeductionPointsDTO memberUsablePoints = memberPointsService.getMemberUsablePoints(memberId, orderInfo.getOrderAmount());

View File

@@ -1,10 +1,10 @@
package com.chaozhanggui.system.cashierservice.service; package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -13,7 +13,6 @@ import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.Enum.OrderUseTypeEnum; import com.chaozhanggui.system.cashierservice.entity.Enum.OrderUseTypeEnum;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.*; import com.chaozhanggui.system.cashierservice.entity.dto.*;
import com.chaozhanggui.system.cashierservice.entity.vo.ActivateInInfoVO;
import com.chaozhanggui.system.cashierservice.entity.vo.ShopUserListVo; import com.chaozhanggui.system.cashierservice.entity.vo.ShopUserListVo;
import com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo; import com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.exception.MsgException;
@@ -56,7 +55,6 @@ import java.math.RoundingMode;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Service @Service
@Slf4j @Slf4j
@@ -97,6 +95,9 @@ public class PayService {
@Autowired @Autowired
private TbShopSongOrderMapper tbShopSongOrderMapper; private TbShopSongOrderMapper tbShopSongOrderMapper;
@Autowired
private TbMemberPointsService tbMemberPointsService;
@Value("${ysk.url}") @Value("${ysk.url}")
private String url; private String url;
@@ -471,7 +472,7 @@ public class PayService {
// 设置优惠券信息 // 设置优惠券信息
OrderCouponInfoDTO couponInfoDTO = new OrderCouponInfoDTO(); OrderCouponInfoDTO couponInfoDTO = new OrderCouponInfoDTO();
couponInfoDTO.setFullReductionCouponMap(new HashMap<Integer, TbUserCouponVo>(){{ couponInfoDTO.setFullReductionCouponMap(new HashMap<Integer, TbUserCouponVo>() {{
put(userCouponVo.getId(), userCouponVo); put(userCouponVo.getId(), userCouponVo);
}}); }});
orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfoDTO)); orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfoDTO));
@@ -1491,6 +1492,12 @@ public class PayService {
//会员活动 //会员活动
giveActivate(tbShopUser, memberIn.getAmount(), flow.getId()); giveActivate(tbShopUser, memberIn.getAmount(), flow.getId());
//充值送积分
TbActivate activate = tbActivateMapper.selectByAmountScope(tbShopUser.getShopId(), memberIn.getAmount());
if (ObjectUtil.isNotNull(activate)) {
tbMemberPointsService.addPoints(Convert.toLong(tbShopUser.getId()), activate.getGiftAmount(), StrUtil.format("充值¥{}送{}积分", memberIn.getAmount(), activate.getGiftAmount()), null, memberIn.getOrderNo());
}
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("shopId", memberIn.getShopId()); jsonObject.put("shopId", memberIn.getShopId());
jsonObject.put("type", "wxMemberIn"); jsonObject.put("type", "wxMemberIn");
@@ -1684,6 +1691,12 @@ public class PayService {
//会员活动 //会员活动
BigDecimal awardAmount = giveActivate(tbShopUser, memberIn.getAmount(), flow.getId()); BigDecimal awardAmount = giveActivate(tbShopUser, memberIn.getAmount(), flow.getId());
//充值送积分
TbActivate activate = tbActivateMapper.selectByAmountScope(tbShopUser.getShopId(), memberIn.getAmount());
if (ObjectUtil.isNotNull(activate)) {
tbMemberPointsService.addPoints(Convert.toLong(tbShopUser.getId()), activate.getGiftAmount(), StrUtil.format("充值¥{}送{}积分", memberIn.getAmount(), activate.getGiftAmount()), null, memberIn.getOrderNo());
}
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("shopId", memberIn.getShopId()); jsonObject.put("shopId", memberIn.getShopId());
jsonObject.put("type", "wxMemberIn"); jsonObject.put("type", "wxMemberIn");
@@ -1700,6 +1713,7 @@ public class PayService {
baObj.put("time", flow.getCreateTime()); baObj.put("time", flow.getCreateTime());
producer.balance(baObj.toString()); producer.balance(baObj.toString());
return "SUCCESS"; return "SUCCESS";
} }

View File

@@ -93,9 +93,10 @@ public interface TbMemberPointsService extends IService<TbMemberPoints> {
* @param points 积分 * @param points 积分
* @param content 摘要信息(如:兑换积分商品/积分抵扣账单/消费赠送积分/新会员送积分/储值赠送积分) * @param content 摘要信息(如:兑换积分商品/积分抵扣账单/消费赠送积分/新会员送积分/储值赠送积分)
* @param orderId 订单id可以为空 * @param orderId 订单id可以为空
* @param orderNo 订单No可以为空
* @throws Exception * @throws Exception
*/ */
boolean addPoints(Long memberId, int points, String content, Long orderId); boolean addPoints(Long memberId, int points, String content, Long orderId, String orderNo);
/** /**
* 消费赠送积分 * 消费赠送积分

View File

@@ -239,7 +239,7 @@ public class TbMemberPointsServiceImpl extends ServiceImpl<TbMemberPointsMapper,
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean addPoints(Long memberId, int points, String content, Long orderId) { public boolean addPoints(Long memberId, int points, String content, Long orderId, String orderNo) {
TbMemberPoints entity = initMemberPoints(memberId); TbMemberPoints entity = initMemberPoints(memberId);
// 增加账户积分 // 增加账户积分
entity.setAccountPoints(entity.getAccountPoints() + points); entity.setAccountPoints(entity.getAccountPoints() + points);
@@ -256,6 +256,7 @@ public class TbMemberPointsServiceImpl extends ServiceImpl<TbMemberPointsMapper,
log.setFloatType("add"); log.setFloatType("add");
log.setFloatPoints(points); log.setFloatPoints(points);
log.setCreateTime(new Date()); log.setCreateTime(new Date());
log.setOrderNo(orderNo);
// 有关联订单的需要回置订单表的相关积分使用字段 // 有关联订单的需要回置订单表的相关积分使用字段
if (orderId != null) { if (orderId != null) {
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Convert.toInt(orderId)); TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Convert.toInt(orderId));
@@ -306,7 +307,7 @@ public class TbMemberPointsServiceImpl extends ServiceImpl<TbMemberPointsMapper,
return; return;
} }
BigDecimal awardPoints = NumberUtil.roundDown(NumberUtil.div(payAmount, consumeAmount), 0); BigDecimal awardPoints = NumberUtil.roundDown(NumberUtil.div(payAmount, consumeAmount), 0);
addPoints(memberId, awardPoints.intValue(), StrUtil.format("消费¥{}送{}积分", payAmount, awardPoints.intValue()), orderId); addPoints(memberId, awardPoints.intValue(), StrUtil.format("消费¥{}送{}积分", payAmount, awardPoints.intValue()), orderId, null);
} }
} }

View File

@@ -7,6 +7,7 @@
<result property="shopId" column="shop_id" jdbcType="INTEGER"/> <result property="shopId" column="shop_id" jdbcType="INTEGER"/>
<result property="amount" column="amount" jdbcType="INTEGER"/> <result property="amount" column="amount" jdbcType="INTEGER"/>
<result property="giftAmount" column="gift_amount" jdbcType="INTEGER"/> <result property="giftAmount" column="gift_amount" jdbcType="INTEGER"/>
<result property="giftPoints" column="gift_points" jdbcType="INTEGER"/>
<result property="isUseCoupon" column="is_use_coupon" jdbcType="INTEGER"/> <result property="isUseCoupon" column="is_use_coupon" jdbcType="INTEGER"/>
<result property="couponId" column="coupon_id" jdbcType="INTEGER"/> <result property="couponId" column="coupon_id" jdbcType="INTEGER"/>
<result property="num" column="num" jdbcType="INTEGER"/> <result property="num" column="num" jdbcType="INTEGER"/>
@@ -16,7 +17,7 @@
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id id
, shop_id, amount, gift_amount, is_use_coupon, coupon_id, num, create_time, update_time </sql> , shop_id, amount, gift_amount, gift_points, is_use_coupon, coupon_id, num, create_time, update_time </sql>
<!--查询单个--> <!--查询单个-->
<select id="selectByShopId" resultMap="TbActivateMap"> <select id="selectByShopId" resultMap="TbActivateMap">
@@ -46,6 +47,20 @@
limit 1 limit 1
</select> </select>
<select id="selectByAmountScope" resultMap="TbActivateMap">
select
<include refid="Base_Column_List"/>
from tb_activate
where shop_id = #{shopId}
<![CDATA[
and amount > 0
and amount <= #{amount}
]]>
order by amount desc,gift_points desc,id desc
limit 1
</select>
<!--查询指定行数据--> <!--查询指定行数据-->
<select id="queryAll" resultMap="TbActivateMap"> <select id="queryAll" resultMap="TbActivateMap">
@@ -87,15 +102,15 @@
<!--新增所有列--> <!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true"> <insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into tb_activate(shop_id, amount, gift_amount, is_use_coupon, coupon_id, num, create_time, update_time) insert into tb_activate(shop_id, amount, gift_amount, gift_points, is_use_coupon, coupon_id, num, create_time, update_time)
values (#{shopId}, #{amount}, #{giftAmount}, #{isUseCoupon}, #{couponId}, #{num}, #{createTime}, #{updateTime}) values (#{shopId}, #{amount}, #{giftAmount}, #{giftPoints}, #{isUseCoupon}, #{couponId}, #{num}, #{createTime}, #{updateTime})
</insert> </insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true"> <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into tb_activate(shop_id, amount, gift_amount, is_use_coupon, coupon_id, num, create_time, update_time) insert into tb_activate(shop_id, amount, gift_amount, gift_points, is_use_coupon, coupon_id, num, create_time, update_time)
values values
<foreach collection="entities" item="entity" separator=","> <foreach collection="entities" item="entity" separator=",">
(#{entity.shopId}, #{entity.amount}, #{entity.giftAmount}, #{entity.isUseCoupon}, #{entity.couponId}, (#{entity.shopId}, #{entity.amount}, #{entity.giftAmount}, #{entity.giftPoints}, #{entity.isUseCoupon}, #{entity.couponId},
#{entity.num}, #{entity.createTime}, #{entity.updateTime}) #{entity.num}, #{entity.createTime}, #{entity.updateTime})
</foreach> </foreach>
</insert> </insert>
@@ -113,6 +128,9 @@
<if test="giftAmount != null"> <if test="giftAmount != null">
gift_amount = #{giftAmount}, gift_amount = #{giftAmount},
</if> </if>
<if test="giftPoints != null">
gift_points = #{giftPoints},
</if>
<if test="isUseCoupon != null"> <if test="isUseCoupon != null">
is_use_coupon = #{isUseCoupon}, is_use_coupon = #{isUseCoupon},
</if> </if>