优惠券领取 来源字段 区分是充值活动还是邀请或者奖励
优惠券 使用数量
This commit is contained in:
@@ -21,6 +21,7 @@ public interface TbActivateInRecordMapper {
|
||||
* @return 实例对象
|
||||
*/
|
||||
TbActivateInRecord queryById(Integer id);
|
||||
Integer isUseCoupon(@Param("vipUserId") Integer vipUserId, @Param("couponId") Integer couponId,@Param("sourceFlowId") Integer sourceFlowId);
|
||||
|
||||
/**
|
||||
* 查询数据
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 优惠券(TbShopCoupon)表数据库访问层
|
||||
@@ -40,6 +41,8 @@ public interface TbShopCouponMapper {
|
||||
*/
|
||||
int insert(TbShopCoupon tbShopCoupon);
|
||||
|
||||
int upUseNumber(@Param("ids") Set<Integer> ids);
|
||||
|
||||
/**
|
||||
* 批量新增数据(MyBatis原生foreach方法)
|
||||
*
|
||||
|
||||
@@ -1545,6 +1545,7 @@ public class PayService {
|
||||
record.setSourceFlowId(flowId);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
record.setSource("activate");
|
||||
record.setCouponJson(activateInRecordService.getCouponJson(activate, tbShopCoupon, null));
|
||||
actGiveRecords.add(record);
|
||||
} else if (tbShopCoupon.getType() == 2) {
|
||||
@@ -1564,6 +1565,7 @@ public class PayService {
|
||||
record.setSourceFlowId(flowId);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
record.setSource("activate");
|
||||
record.setCouponJson(activateInRecordService.getCouponJson(activate, tbShopCoupon, actPro));
|
||||
actGiveRecords.add(record);
|
||||
}
|
||||
|
||||
@@ -173,8 +173,15 @@ public class TbShopCouponServiceImpl implements TbShopCouponService {
|
||||
*/
|
||||
@Override
|
||||
public boolean use(Integer shopId, Integer orderId, Integer vipUserId, List<TbActivateOutRecord> param) {
|
||||
Set<Integer> couponIds = new HashSet<>();
|
||||
for (TbActivateOutRecord outRecord : param) {
|
||||
TbActivateInRecord inRecord = inRecordMapper.queryById(outRecord.getGiveId());
|
||||
if (!couponIds.contains(inRecord.getCouponId())) {
|
||||
Integer useCoupon = inRecordMapper.isUseCoupon(inRecord.getVipUserId(), inRecord.getCouponId(), inRecord.getSourceFlowId());
|
||||
if (useCoupon == null || useCoupon == 0) {
|
||||
couponIds.add(inRecord.getCouponId());
|
||||
}
|
||||
}
|
||||
if (inRecord.getSource().equals("invited")) {
|
||||
TbShopShareRecord shareRecord = shareRecordMapper.queryById(inRecord.getSourceActId());
|
||||
if (shareRecord.getMethod().equals("use")) {
|
||||
@@ -194,6 +201,9 @@ public class TbShopCouponServiceImpl implements TbShopCouponService {
|
||||
outRecord.setCreateTime(new Date());
|
||||
}
|
||||
outRecordMapper.insertBatch(param);
|
||||
if (CollectionUtil.isNotEmpty(couponIds)) {
|
||||
couponMapper.upUseNumber(couponIds);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -222,13 +222,13 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService {
|
||||
TbShopShare shopShare = tbShopShareMapper.queryById(shareRecord.getShareId());
|
||||
TbShopUser tbShopUser = getShopUserInfo(userId, shareRecord.getShopId());
|
||||
if (userId.equals(shareRecord.getInvitedId())) {
|
||||
giveCoupon(shopShare, tbShopUser, shopShare.getRewardCoupons());
|
||||
giveCoupon(shopShare, tbShopUser, shopShare.getRewardCoupons(),shareRecord.getId(), true);
|
||||
} else if (userId.equals(shareRecord.getBeInvitedId())) {
|
||||
giveCoupon(shopShare, tbShopUser, shopShare.getNewCoupons());
|
||||
giveCoupon(shopShare, tbShopUser, shopShare.getNewCoupons(),shareRecord.getId(),false);
|
||||
}
|
||||
}
|
||||
|
||||
public void giveCoupon(TbShopShare shopShare, TbShopUser tbShopUser, List<TbShopShare.ShareCoupons> coupons) {
|
||||
public void giveCoupon(TbShopShare shopShare, TbShopUser tbShopUser, List<TbShopShare.ShareCoupons> coupons ,Integer flowId, boolean isReward) {
|
||||
for (TbShopShare.ShareCoupons newCoupon : coupons) {
|
||||
TbShopCoupon tbShopCoupon = couponMapper.queryById(newCoupon.getCouponId());
|
||||
Date start = new Date();
|
||||
@@ -257,9 +257,14 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService {
|
||||
record.setShopId(Integer.valueOf(tbShopUser.getShopId()));
|
||||
record.setCreateTime(new Date());
|
||||
record.setSourceActId(shopShare.getId());
|
||||
record.setSourceFlowId(flowId);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
record.setSource("invited");
|
||||
if(isReward){
|
||||
record.setSource("invited-reward");
|
||||
}else {
|
||||
record.setSource("invited");
|
||||
}
|
||||
actGiveRecords.add(record);
|
||||
} else if (tbShopCoupon.getType() == 2) {
|
||||
//商品券
|
||||
@@ -275,16 +280,23 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService {
|
||||
record.setOverNum(actPro.getNum() * tbShopCoupon.getNumber());
|
||||
record.setShopId(Integer.valueOf(tbShopUser.getShopId()));
|
||||
record.setSourceActId(shopShare.getId());
|
||||
record.setSourceFlowId(flowId);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
record.setCreateTime(new Date());
|
||||
record.setSource("invited");
|
||||
if(isReward){
|
||||
record.setSource("invited-reward");
|
||||
}else {
|
||||
record.setSource("invited");
|
||||
}
|
||||
actGiveRecords.add(record);
|
||||
}
|
||||
}
|
||||
activateInRecordMapper.insertBatch(actGiveRecords);
|
||||
tbShopCoupon.setLeftNumber(tbShopCoupon.getLeftNumber()-newCoupon.getCouponNum());
|
||||
couponMapper.update(tbShopCoupon);
|
||||
if(!isReward){
|
||||
tbShopCoupon.setLeftNumber(tbShopCoupon.getLeftNumber()-newCoupon.getCouponNum());
|
||||
couponMapper.update(tbShopCoupon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,22 @@ id, vip_user_id, coupon_id, name, type, pro_id, full_amount, discount_amount, nu
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="isUseCoupon" resultType="int">
|
||||
SELECT count(1)
|
||||
FROM `tb_activate_in_record`
|
||||
WHERE source != 'invited-reward'
|
||||
and vip_user_id = #{vipUserId}
|
||||
and coupon_id = #{couponId}
|
||||
and source_flow_id = #{sourceFlowId}
|
||||
GROUP BY
|
||||
vip_user_id,
|
||||
coupon_id,
|
||||
source_flow_id
|
||||
HAVING
|
||||
sum (num) != sum (over_num)
|
||||
</select>
|
||||
|
||||
|
||||
<select id="queryByVipIdAndShopId" resultType="com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo">
|
||||
SELECT
|
||||
inRecord.shop_id as shopId,
|
||||
|
||||
@@ -147,6 +147,16 @@
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="upUseNumber">
|
||||
update tb_shop_coupon
|
||||
set
|
||||
use_number = use_number+1,
|
||||
where `id` in
|
||||
<foreach collection="ids" item="id" separator=",">
|
||||
(#{id})
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!--通过主键修改数据-->
|
||||
<update id="update">
|
||||
update tb_shop_coupon
|
||||
|
||||
Reference in New Issue
Block a user