优惠券弹窗
This commit is contained in:
@@ -177,6 +177,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
||||
record.setShopUserId(giftDTO.getShopUserId());
|
||||
record.setUserId(shopUser.getUserId());
|
||||
record.setCouponId(giftDTO.getCouponId());
|
||||
record.setCouponSyncId(coupon.getSyncId());
|
||||
record.setSourceId(giftDTO.getSourceId());
|
||||
record.setSourceFlowId(giftDTO.getSourceFlowId());
|
||||
record.setSource(giftDTO.getSource());
|
||||
|
||||
@@ -16,15 +16,21 @@ import com.czg.account.service.ShopUserService;
|
||||
import com.czg.account.vo.ShopInfoCouponVO;
|
||||
import com.czg.account.vo.UserCouponFoodVo;
|
||||
import com.czg.account.vo.UserCouponVo;
|
||||
import com.czg.market.dto.MkShopCouponGiftDTO;
|
||||
import com.czg.market.dto.ShopCouponDTO;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.service.MkCouponGiftService;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.market.service.ShopCouponService;
|
||||
import com.czg.market.vo.ShopCouponPopUp;
|
||||
import com.czg.market.vo.UserCouponVO;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.order.service.OrderInfoService;
|
||||
import com.czg.product.entity.Product;
|
||||
import com.czg.product.service.ProductService;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.czg.service.market.enums.OrderStatusEnums;
|
||||
import com.czg.service.market.mapper.MkShopCouponRecordMapper;
|
||||
import com.czg.service.market.mapper.ShopCouponMapper;
|
||||
import com.czg.utils.AssertUtil;
|
||||
@@ -40,6 +46,7 @@ import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
@@ -66,6 +73,8 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
||||
private ShopUserService shopUserService;
|
||||
@DubboReference
|
||||
private ProductService productService;
|
||||
@DubboReference
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
@Override
|
||||
public Page<ShopCouponDTO> getCouponPage(ShopCouponDTO param) {
|
||||
@@ -77,6 +86,86 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
||||
return pageAs(PageUtil.buildPage(), queryWrapper, ShopCouponDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ShopCouponPopUp> getPopUp(Long shopId, Long userId, String getMode) {
|
||||
ShopUser shopUser = shopUserService.getShopUserInfo(shopId, userId);
|
||||
AssertUtil.isNull(shopUser, "用户不存在");
|
||||
List<ShopCouponPopUp> result = new ArrayList<>();
|
||||
List<ShopCoupon> coupons = list(new QueryWrapper()
|
||||
.eq(ShopCoupon::getShopId, StpKit.USER.getShopId())
|
||||
.eq(ShopCoupon::getGetType, "yes")
|
||||
.eq(ShopCoupon::getGetMode, getMode)
|
||||
.eq(ShopCoupon::getStatus, 1)
|
||||
.eq(ShopCoupon::getIsDel, 0)
|
||||
);
|
||||
|
||||
for (ShopCoupon coupon : coupons) {
|
||||
if ("custom".equals(coupon.getValidType()) && coupon.getValidEndTime() != null && coupon.getValidEndTime().isBefore(LocalDateTime.now())) {
|
||||
continue;
|
||||
}
|
||||
if (coupon.getGiveNum() != -10086 && coupon.getLeftNum() <= 0) {
|
||||
continue;
|
||||
}
|
||||
boolean isNotNewUser = true;
|
||||
if (!"all".equals(coupon.getGetUserType())) {
|
||||
if ("new".equals(coupon.getGetUserType())) {
|
||||
isNotNewUser = false;
|
||||
long count = orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, userId)
|
||||
.eq(OrderInfo::getShopId, shopId).eq(OrderInfo::getStatus, OrderStatusEnums.DONE));
|
||||
if (count > 0) {
|
||||
continue;
|
||||
}
|
||||
long count1 = recordService.count(new QueryWrapper().eq(MkShopCouponRecord::getCouponSyncId, coupon.getSyncId()));
|
||||
if (count1 > 0) {
|
||||
continue;
|
||||
}
|
||||
} else if ("vip".equals(coupon.getGetUserType()) && shopUser.getIsVip() != 1) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (isNotNewUser && coupon.getGetLimit() != -10086) {
|
||||
if (coupon.getSyncId() != null) {
|
||||
long count = recordService.count(new QueryWrapper().eq(MkShopCouponRecord::getCouponSyncId, coupon.getSyncId()));
|
||||
if (count >= coupon.getGetLimit()) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
long count = recordService.count(new QueryWrapper().eq(MkShopCouponRecord::getCouponSyncId, coupon.getId()));
|
||||
if (count >= coupon.getGetLimit()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
result.add(BeanUtil.copyProperties(coupon, ShopCouponPopUp.class));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivePopUp(Long shopId, Long userId, String getMode) {
|
||||
ShopUser shopUser = null;
|
||||
List<ShopCouponPopUp> popUps = getPopUp(shopId, userId, getMode);
|
||||
if ("home".equals(getMode)) {
|
||||
getMode = "首页";
|
||||
} else if ("eat".equals(getMode)) {
|
||||
getMode = "用餐";
|
||||
} else if ("order".equals(getMode)) {
|
||||
getMode = "订单";
|
||||
}
|
||||
for (ShopCouponPopUp popUp : popUps) {
|
||||
MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO();
|
||||
giftDTO.setShopId(shopId);
|
||||
if (shopUser == null) {
|
||||
shopUser = shopUserService.getShopUserInfo(shopId, userId);
|
||||
}
|
||||
giftDTO.setShopUserId(shopUser.getId());
|
||||
giftDTO.setCouponId(popUp.getId());
|
||||
giftDTO.setSourceId(-1L);
|
||||
giftDTO.setSource(getMode + "弹窗领取");
|
||||
recordService.receiveCoupon(giftDTO, 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShopCouponDTO getCouponById(Long id) {
|
||||
AssertUtil.isNull(id, "优惠券ID不能为空");
|
||||
|
||||
Reference in New Issue
Block a user