|
|
@@ -22,6 +22,7 @@ import shop.alien.util.common.constant.DiscountCouponEnum;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
@@ -48,6 +49,8 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
|
|
|
|
|
|
private final LifeDiscountCouponMapper lifeDiscountCouponMapper;
|
|
|
|
|
|
+ private final LifeCouponMapper lifeCouponMapper;
|
|
|
+
|
|
|
private final LifeDiscountCouponStoreFriendMapper lifeDiscountCouponStoreFriendMapper;
|
|
|
|
|
|
private final LifeDiscountCouponUserMapper lifeDiscountCouponUserMapper;
|
|
|
@@ -137,109 +140,152 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
|
|
|
*/
|
|
|
public boolean setFriendCoupon(UserLoginInfo userLoginInfo, LifeDiscountCouponStoreFriendDto lifeDiscountCouponStoreFriendDto) {
|
|
|
try {
|
|
|
- // 从传入的 DTO 对象中获取要处理的优惠券列表
|
|
|
List<LifeDiscountCouponStoreFriendDto> coupons = lifeDiscountCouponStoreFriendDto.getCouponIds();
|
|
|
- // 遍历优惠券列表,对每个优惠券进行处理
|
|
|
+ if (CollectionUtils.isEmpty(coupons)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
for (LifeDiscountCouponStoreFriendDto couponDto : coupons) {
|
|
|
- // 根据优惠券 ID 从数据库中查询对应的优惠券信息
|
|
|
- LifeDiscountCoupon lifeDiscountCoupon = lifeDiscountCouponMapper.selectById(couponDto.getCouponId());
|
|
|
- // 检查优惠券的库存数量是否足够发放,如果库存数小于要发放的数量,则拦截操作并返回 false
|
|
|
- if ((lifeDiscountCoupon.getSingleQty() - couponDto.getSingleQty()) < 0) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- // 根据优惠券所属店铺 ID 从数据库中查询对应的店铺用户信息
|
|
|
- StoreUser storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, lifeDiscountCoupon.getStoreId()));
|
|
|
- // 检查该优惠券是否已经发放给指定的好友,如果发放过则获取发放记录
|
|
|
- LifeDiscountCouponStoreFriend lifeDiscountCouponStoreFriend = lifeDiscountCouponStoreFriendMapper.selectOne(
|
|
|
- new LambdaQueryWrapper<LifeDiscountCouponStoreFriend>()
|
|
|
- // 匹配优惠券 ID
|
|
|
- .eq(LifeDiscountCouponStoreFriend::getCouponId, couponDto.getCouponId())
|
|
|
- // 匹配店铺用户 ID
|
|
|
- .eq(LifeDiscountCouponStoreFriend::getStoreUserId, lifeDiscountCouponStoreFriendDto.getFriendStoreUserId())
|
|
|
- // 匹配好友店铺用户 ID
|
|
|
- .eq(LifeDiscountCouponStoreFriend::getFriendStoreUserId, userLoginInfo.getUserId())
|
|
|
- );
|
|
|
-
|
|
|
- if (lifeDiscountCouponStoreFriend == null) {
|
|
|
- // 如果该优惠券还没有发放给指定的好友,创建一个新的发放记录
|
|
|
- lifeDiscountCouponStoreFriend = new LifeDiscountCouponStoreFriend();
|
|
|
- // 将传入的 DTO 对象的属性复制到新的发放记录对象中
|
|
|
- BeanUtils.copyProperties(lifeDiscountCouponStoreFriendDto, lifeDiscountCouponStoreFriend);
|
|
|
- // 设置优惠券 ID
|
|
|
- lifeDiscountCouponStoreFriend.setCouponId(couponDto.getCouponId());
|
|
|
- // 设置优惠券的过期日期
|
|
|
- lifeDiscountCouponStoreFriend.setExpirationDate(lifeDiscountCoupon.getExpirationDate());
|
|
|
- // 设置优惠券的开始日期
|
|
|
- lifeDiscountCouponStoreFriend.setStartDate(lifeDiscountCoupon.getStartDate());
|
|
|
- // 设置优惠券的结束日期
|
|
|
- lifeDiscountCouponStoreFriend.setEndDate(lifeDiscountCoupon.getEndDate());
|
|
|
- // 设置好友店铺用户 ID
|
|
|
- lifeDiscountCouponStoreFriend.setFriendStoreUserId(storeUser.getId());
|
|
|
- // 设置要发放的优惠券数量
|
|
|
- lifeDiscountCouponStoreFriend.setSingleQty(couponDto.getSingleQty());
|
|
|
- // 设置店铺用户 ID
|
|
|
- lifeDiscountCouponStoreFriend.setStoreUserId(lifeDiscountCouponStoreFriendDto.getFriendStoreUserId());
|
|
|
- // 设置优惠券的发布状态
|
|
|
- lifeDiscountCouponStoreFriend.setReleaseType(1);
|
|
|
- // 将新的发放记录插入到数据库中
|
|
|
- lifeDiscountCouponStoreFriendMapper.insert(lifeDiscountCouponStoreFriend);
|
|
|
- } else {
|
|
|
- // 如果该优惠券已经发放给指定的好友,增加发放记录中的优惠券数量
|
|
|
- lifeDiscountCouponStoreFriend.setSingleQty(lifeDiscountCouponStoreFriend.getSingleQty() + couponDto.getSingleQty());
|
|
|
- // 更新数据库中的发放记录
|
|
|
- lifeDiscountCouponStoreFriendMapper.updateById(lifeDiscountCouponStoreFriend);
|
|
|
- }
|
|
|
- // 减少优惠券的库存数量
|
|
|
- lifeDiscountCoupon.setSingleQty(lifeDiscountCoupon.getSingleQty() - couponDto.getSingleQty());
|
|
|
- // 更新数据库中的优惠券库存信息
|
|
|
- lifeDiscountCouponMapper.updateById(lifeDiscountCoupon);
|
|
|
-
|
|
|
- int friendStoreId = lifeDiscountCouponStoreFriendDto.getFriendStoreUserId();
|
|
|
- LambdaQueryWrapper<StoreUser> storeUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- storeUserLambdaQueryWrapper.eq(StoreUser::getStoreId, friendStoreId);
|
|
|
- List<StoreUser> storeUserList = storeUserMapper.selectList(storeUserLambdaQueryWrapper);
|
|
|
-
|
|
|
- if(CollectionUtils.isNotEmpty(storeUserList)){
|
|
|
- StoreUser friendStoreUser = storeUserList.get(0);
|
|
|
- String friendPhone = friendStoreUser.getPhone();
|
|
|
- if(StringUtils.isNotEmpty(friendPhone)){
|
|
|
- // 获取发送优惠券的店铺名称
|
|
|
- String storeName = userLoginInfo.getUserName(); // 默认使用用户名
|
|
|
- // 根据当前登录用户ID查询店铺用户信息
|
|
|
- StoreUser currentStoreUser = storeUserMapper.selectById(userLoginInfo.getUserId());
|
|
|
- if (currentStoreUser != null && currentStoreUser.getStoreId() != null) {
|
|
|
- // 根据storeId查询店铺信息,获取店铺名称
|
|
|
- StoreInfo currentStoreInfo = storeInfoMapper.selectById(currentStoreUser.getStoreId());
|
|
|
- if (currentStoreInfo != null && currentStoreInfo.getStoreName() != null) {
|
|
|
- storeName = currentStoreInfo.getStoreName();
|
|
|
- }
|
|
|
- }
|
|
|
- // 发送好友优惠券通知
|
|
|
- LifeNotice lifeMessage = new LifeNotice();
|
|
|
- String text = "您的好友"+storeName+"送了您"+couponDto.getSingleQty()+"张店铺优惠券,快去使用吧!";
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("message", text);
|
|
|
- lifeMessage.setReceiverId("store_"+friendPhone);
|
|
|
- lifeMessage.setTitle("赠券通知");
|
|
|
- lifeMessage.setContext(jsonObject.toJSONString());
|
|
|
- lifeMessage.setNoticeType(1);
|
|
|
- lifeMessage.setIsRead(0);
|
|
|
- lifeMessage.setDeleteFlag(0);
|
|
|
- lifeMessage.setSenderId("system");
|
|
|
- lifeNoticeMapper.insert(lifeMessage);
|
|
|
+ if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotEmpty(couponDto.getVoucherId())) {
|
|
|
+ // 代金券:入参为 voucherId,对应 life_coupon 表
|
|
|
+ if (!handleVoucherFriendCoupon(userLoginInfo, lifeDiscountCouponStoreFriendDto, couponDto)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } else if (couponDto.getCouponId() != null) {
|
|
|
+ // 优惠券:入参为 couponId,对应 life_discount_coupon 表
|
|
|
+ if (!handleDiscountFriendCoupon(userLoginInfo, lifeDiscountCouponStoreFriendDto, couponDto)) {
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- // 如果所有优惠券都成功处理,返回 true
|
|
|
return true;
|
|
|
} catch (BeansException e) {
|
|
|
- // 捕获 Bean 复制过程中可能出现的异常,并打印异常堆栈信息
|
|
|
e.printStackTrace();
|
|
|
- // 出现异常时返回 false
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** 处理代金券(life_coupon)发放好友 */
|
|
|
+ private boolean handleVoucherFriendCoupon(UserLoginInfo userLoginInfo, LifeDiscountCouponStoreFriendDto dto, LifeDiscountCouponStoreFriendDto couponDto) {
|
|
|
+ LifeCoupon lifeCoupon = lifeCouponMapper.selectById(couponDto.getVoucherId());
|
|
|
+ if (lifeCoupon == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ int qty = couponDto.getSingleQty() != null ? couponDto.getSingleQty() : 0;
|
|
|
+ if (lifeCoupon.getSingleQty() == null || (lifeCoupon.getSingleQty() - qty) < 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ StoreUser storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, lifeCoupon.getStoreId()));
|
|
|
+ if (storeUser == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<LifeDiscountCouponStoreFriend> wrapper = new LambdaQueryWrapper<LifeDiscountCouponStoreFriend>()
|
|
|
+ .eq(LifeDiscountCouponStoreFriend::getVoucherId, couponDto.getVoucherId())
|
|
|
+ .eq(LifeDiscountCouponStoreFriend::getStoreUserId, dto.getFriendStoreUserId())
|
|
|
+ .eq(LifeDiscountCouponStoreFriend::getFriendStoreUserId, userLoginInfo.getUserId());
|
|
|
+ LifeDiscountCouponStoreFriend friend = lifeDiscountCouponStoreFriendMapper.selectOne(wrapper);
|
|
|
+
|
|
|
+ if (friend == null) {
|
|
|
+ friend = new LifeDiscountCouponStoreFriend();
|
|
|
+ friend.setVoucherId(couponDto.getVoucherId());
|
|
|
+ friend.setCouponId(null);
|
|
|
+ friend.setExpirationDate(lifeCoupon.getExpirationDate());
|
|
|
+ if (lifeCoupon.getStartDate() != null) {
|
|
|
+ friend.setStartDate(lifeCoupon.getStartDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
|
|
|
+ }
|
|
|
+ if (lifeCoupon.getEndDate() != null) {
|
|
|
+ friend.setEndDate(lifeCoupon.getEndDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
|
|
|
+ }
|
|
|
+ friend.setFriendStoreUserId(storeUser.getId());
|
|
|
+ friend.setSingleQty(qty);
|
|
|
+ friend.setStoreUserId(dto.getFriendStoreUserId());
|
|
|
+ friend.setReleaseType(1);
|
|
|
+ lifeDiscountCouponStoreFriendMapper.insert(friend);
|
|
|
+ } else {
|
|
|
+ friend.setSingleQty(friend.getSingleQty() + qty);
|
|
|
+ lifeDiscountCouponStoreFriendMapper.updateById(friend);
|
|
|
+ }
|
|
|
+ lifeCoupon.setSingleQty(lifeCoupon.getSingleQty() - qty);
|
|
|
+ lifeCouponMapper.updateById(lifeCoupon);
|
|
|
+ sendFriendCouponNotice(dto.getFriendStoreUserId(), userLoginInfo, qty, true);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 处理优惠券(life_discount_coupon)发放好友 */
|
|
|
+ private boolean handleDiscountFriendCoupon(UserLoginInfo userLoginInfo, LifeDiscountCouponStoreFriendDto lifeDiscountCouponStoreFriendDto, LifeDiscountCouponStoreFriendDto couponDto) {
|
|
|
+ LifeDiscountCoupon lifeDiscountCoupon = lifeDiscountCouponMapper.selectById(couponDto.getCouponId());
|
|
|
+ if (lifeDiscountCoupon == null || (lifeDiscountCoupon.getSingleQty() - couponDto.getSingleQty()) < 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ StoreUser storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, lifeDiscountCoupon.getStoreId()));
|
|
|
+ LifeDiscountCouponStoreFriend lifeDiscountCouponStoreFriend = lifeDiscountCouponStoreFriendMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<LifeDiscountCouponStoreFriend>()
|
|
|
+ .eq(LifeDiscountCouponStoreFriend::getCouponId, couponDto.getCouponId())
|
|
|
+ .eq(LifeDiscountCouponStoreFriend::getStoreUserId, lifeDiscountCouponStoreFriendDto.getFriendStoreUserId())
|
|
|
+ .eq(LifeDiscountCouponStoreFriend::getFriendStoreUserId, userLoginInfo.getUserId())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (lifeDiscountCouponStoreFriend == null) {
|
|
|
+ lifeDiscountCouponStoreFriend = new LifeDiscountCouponStoreFriend();
|
|
|
+ BeanUtils.copyProperties(lifeDiscountCouponStoreFriendDto, lifeDiscountCouponStoreFriend);
|
|
|
+ lifeDiscountCouponStoreFriend.setCouponId(couponDto.getCouponId());
|
|
|
+ lifeDiscountCouponStoreFriend.setVoucherId(null);
|
|
|
+ lifeDiscountCouponStoreFriend.setExpirationDate(lifeDiscountCoupon.getExpirationDate());
|
|
|
+ lifeDiscountCouponStoreFriend.setStartDate(lifeDiscountCoupon.getStartDate());
|
|
|
+ lifeDiscountCouponStoreFriend.setEndDate(lifeDiscountCoupon.getEndDate());
|
|
|
+ lifeDiscountCouponStoreFriend.setFriendStoreUserId(storeUser.getId());
|
|
|
+ lifeDiscountCouponStoreFriend.setSingleQty(couponDto.getSingleQty());
|
|
|
+ lifeDiscountCouponStoreFriend.setStoreUserId(lifeDiscountCouponStoreFriendDto.getFriendStoreUserId());
|
|
|
+ lifeDiscountCouponStoreFriend.setReleaseType(1);
|
|
|
+ lifeDiscountCouponStoreFriendMapper.insert(lifeDiscountCouponStoreFriend);
|
|
|
+ } else {
|
|
|
+ lifeDiscountCouponStoreFriend.setSingleQty(lifeDiscountCouponStoreFriend.getSingleQty() + couponDto.getSingleQty());
|
|
|
+ lifeDiscountCouponStoreFriendMapper.updateById(lifeDiscountCouponStoreFriend);
|
|
|
+ }
|
|
|
+ lifeDiscountCoupon.setSingleQty(lifeDiscountCoupon.getSingleQty() - couponDto.getSingleQty());
|
|
|
+ lifeDiscountCouponMapper.updateById(lifeDiscountCoupon);
|
|
|
+ sendFriendCouponNotice(lifeDiscountCouponStoreFriendDto.getFriendStoreUserId(), userLoginInfo, couponDto.getSingleQty(), false);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 发送赠券通知:isVoucher true=代金券,false=优惠券 */
|
|
|
+ private void sendFriendCouponNotice(Integer friendStoreUserId, UserLoginInfo userLoginInfo, int qty, boolean isVoucher) {
|
|
|
+ if (friendStoreUserId == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<StoreUser> storeUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ storeUserLambdaQueryWrapper.eq(StoreUser::getStoreId, friendStoreUserId);
|
|
|
+ List<StoreUser> storeUserList = storeUserMapper.selectList(storeUserLambdaQueryWrapper);
|
|
|
+ if (CollectionUtils.isEmpty(storeUserList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ StoreUser friendStoreUser = storeUserList.get(0);
|
|
|
+ String friendPhone = friendStoreUser.getPhone();
|
|
|
+ if (friendPhone == null || friendPhone.trim().isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String storeName = userLoginInfo.getUserName();
|
|
|
+ StoreUser currentStoreUser = storeUserMapper.selectById(userLoginInfo.getUserId());
|
|
|
+ if (currentStoreUser != null && currentStoreUser.getStoreId() != null) {
|
|
|
+ StoreInfo currentStoreInfo = storeInfoMapper.selectById(currentStoreUser.getStoreId());
|
|
|
+ if (currentStoreInfo != null && currentStoreInfo.getStoreName() != null) {
|
|
|
+ storeName = currentStoreInfo.getStoreName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LifeNotice lifeMessage = new LifeNotice();
|
|
|
+ String couponTypeName = isVoucher ? "代金券" : "优惠券";
|
|
|
+ String text = "您的好友" + storeName + "送了您" + qty + "张" + couponTypeName + ",快去使用吧!";
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("message", text);
|
|
|
+ lifeMessage.setReceiverId("store_" + friendPhone);
|
|
|
+ lifeMessage.setTitle("赠券通知");
|
|
|
+ lifeMessage.setContext(jsonObject.toJSONString());
|
|
|
+ lifeMessage.setNoticeType(1);
|
|
|
+ lifeMessage.setIsRead(0);
|
|
|
+ lifeMessage.setDeleteFlag(0);
|
|
|
+ lifeMessage.setSenderId("system");
|
|
|
+ lifeNoticeMapper.insert(lifeMessage);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 为当前用户发放店铺为好友设定的可用优惠券。
|
|
|
*
|
|
|
@@ -432,20 +478,35 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
|
|
|
|
|
|
@Override
|
|
|
public LifeDiscountCouponFriendRuleVo saveFriendCouponRule(LifeDiscountCouponFriendRule lifeDiscountCouponFriendRule) {
|
|
|
+ List<LifeDiscountCouponFriendRuleDetail> details = lifeDiscountCouponFriendRule.getDetails();
|
|
|
+ // 按列表中是否传入代金券id区分:有 voucherId 走代金券逻辑,否则走优惠券逻辑
|
|
|
+ if (ObjectUtils.isNotEmpty(details)) {
|
|
|
+ for (LifeDiscountCouponFriendRuleDetail detail : details) {
|
|
|
+ if (detail.getVoucherId() != null && !detail.getVoucherId().trim().isEmpty()) {
|
|
|
+ detail.setCouponId(null);
|
|
|
+ } else {
|
|
|
+ detail.setVoucherId(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
if (ObjectUtils.isNotEmpty(lifeDiscountCouponFriendRule.getId())) {
|
|
|
- List<LifeDiscountCouponFriendRuleDetail> details = lifeDiscountCouponFriendRule.getDetails();
|
|
|
lifeDiscountCouponFriendRuleDetailMapper.delete(new LambdaQueryWrapper<LifeDiscountCouponFriendRuleDetail>().eq(LifeDiscountCouponFriendRuleDetail::getRuleId, lifeDiscountCouponFriendRule.getId()));
|
|
|
- for (LifeDiscountCouponFriendRuleDetail detail : details) {
|
|
|
- detail.setRuleId(lifeDiscountCouponFriendRule.getId());
|
|
|
- detail.setStoreId(lifeDiscountCouponFriendRule.getStoreId());
|
|
|
+ if (ObjectUtils.isNotEmpty(details)) {
|
|
|
+ for (LifeDiscountCouponFriendRuleDetail detail : details) {
|
|
|
+ detail.setRuleId(lifeDiscountCouponFriendRule.getId());
|
|
|
+ detail.setStoreId(lifeDiscountCouponFriendRule.getStoreId());
|
|
|
+ }
|
|
|
+ lifeDiscountCouponFriendRuleDetailMapper.insertList(details);
|
|
|
}
|
|
|
- lifeDiscountCouponFriendRuleDetailMapper.insertList(details);
|
|
|
lifeDiscountCouponFriendRuleMapper.updateById(lifeDiscountCouponFriendRule);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
lifeDiscountCouponFriendRuleMapper.insert(lifeDiscountCouponFriendRule);
|
|
|
- if (ObjectUtils.isNotEmpty(lifeDiscountCouponFriendRule.getDetails())) {
|
|
|
- lifeDiscountCouponFriendRule.getDetails().forEach(detail -> detail.setRuleId(lifeDiscountCouponFriendRule.getId()));
|
|
|
- lifeDiscountCouponFriendRuleDetailMapper.insertList(lifeDiscountCouponFriendRule.getDetails());
|
|
|
+ if (ObjectUtils.isNotEmpty(details)) {
|
|
|
+ details.forEach(detail -> {
|
|
|
+ detail.setRuleId(lifeDiscountCouponFriendRule.getId());
|
|
|
+ detail.setStoreId(lifeDiscountCouponFriendRule.getStoreId());
|
|
|
+ });
|
|
|
+ lifeDiscountCouponFriendRuleDetailMapper.insertList(details);
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
@@ -465,17 +526,24 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
|
|
|
* @return 领取的优惠券列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<LifeDiscountCouponFriendRuleDetailVo> getReceivedFriendCouponList(String storeId,String friendStoreUserId) {
|
|
|
+ public List<LifeDiscountCouponFriendRuleDetailVo> getReceivedFriendCouponList(String storeId, String friendStoreUserId, Integer type) {
|
|
|
QueryWrapper<LifeDiscountCouponFriendRuleDetailVo> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("ldcsf.store_user_id", storeId);
|
|
|
queryWrapper.eq("ldcsf.delete_flag", 0);
|
|
|
queryWrapper.eq("ldcsf.release_type", 1);
|
|
|
- //查询送过优惠券的店铺
|
|
|
+ if (Integer.valueOf(4).equals(type)) {
|
|
|
+ queryWrapper.isNotNull("ldcsf.voucher_id");
|
|
|
+ if (StringUtils.isEmpty(friendStoreUserId)) {
|
|
|
+ queryWrapper.groupBy("ldcsf.friend_store_user_id").orderByDesc("couponNum");
|
|
|
+ } else {
|
|
|
+ queryWrapper.eq("ldcsf.friend_store_user_id", friendStoreUserId).groupBy("ldcsf.voucher_id").orderByDesc("couponNum");
|
|
|
+ }
|
|
|
+ return lifeDiscountCouponFriendRuleDetailMapper.getReceivedFriendVoucherList(queryWrapper);
|
|
|
+ }
|
|
|
+ queryWrapper.isNotNull("ldcsf.coupon_id");
|
|
|
if (StringUtils.isEmpty(friendStoreUserId)) {
|
|
|
queryWrapper.groupBy("ldcsf.friend_store_user_id").orderByDesc("couponNum");
|
|
|
- }
|
|
|
- //查询选中店铺送的优惠券
|
|
|
- else {
|
|
|
+ } else {
|
|
|
queryWrapper.eq("ldcsf.friend_store_user_id", friendStoreUserId).groupBy("ldcsf.coupon_id").orderByDesc("couponNum");
|
|
|
}
|
|
|
return lifeDiscountCouponFriendRuleDetailMapper.getReceivedFriendCouponList(queryWrapper);
|
|
|
@@ -483,15 +551,34 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
|
|
|
|
|
|
@Override
|
|
|
public List<LifeDiscountCouponFriendRuleVo> getRuleList(String storeId, String acName, String status) {
|
|
|
+ if (StringUtils.isEmpty(storeId)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
List<LifeDiscountCouponFriendRuleVo> ruleList = lifeDiscountCouponFriendRuleDetailMapper.getRuleList(storeId);
|
|
|
+ if (ruleList == null) {
|
|
|
+ ruleList = new ArrayList<>();
|
|
|
+ }
|
|
|
if (ObjectUtils.isNotEmpty(ruleList)) {
|
|
|
- ruleList.forEach(i -> i.setStatus(i.getEndDate().after(new Date()) ? "0" : "1"));
|
|
|
+ Date now = new Date();
|
|
|
+ ruleList.forEach(i -> {
|
|
|
+ if (i.getEndDate() != null) {
|
|
|
+ i.setStatus(i.getEndDate().after(now) ? "0" : "1");
|
|
|
+ } else {
|
|
|
+ i.setStatus(null);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(acName)) {
|
|
|
- ruleList = ruleList.stream().filter(i -> i.getAcName().contains(acName)).collect(Collectors.toList());
|
|
|
+ String name = acName;
|
|
|
+ ruleList = ruleList.stream()
|
|
|
+ .filter(i -> i.getAcName() != null && i.getAcName().contains(name))
|
|
|
+ .collect(Collectors.toList());
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(status)) {
|
|
|
- ruleList = ruleList.stream().filter(i -> i.getStatus().equals(status)).collect(Collectors.toList());
|
|
|
+ String s = status;
|
|
|
+ ruleList = ruleList.stream()
|
|
|
+ .filter(i -> i.getStatus() != null && i.getStatus().equals(s))
|
|
|
+ .collect(Collectors.toList());
|
|
|
}
|
|
|
return ruleList;
|
|
|
}
|