兑换码优化
This commit is contained in:
@@ -8,6 +8,7 @@ import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
@@ -25,6 +26,7 @@ import com.czg.market.service.MkEnableConfigService;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.market.vo.MkRedemptionConfigVO;
|
||||
import com.czg.market.vo.MkRedemptionCodeVO;
|
||||
import com.czg.market.vo.URedemptionVO;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.MyQueryWrapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
@@ -282,16 +284,11 @@ public class MkRedemptionConfigServiceImpl extends ServiceImpl<MkCouponRedemptio
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void exchange(long userId, MkRedemptionDTO dto) {
|
||||
|
||||
MkRedemptionCode redemptionCode = codeService.getOne(new QueryWrapper().eq(MkRedemptionCode::getCode, dto.getCode()));
|
||||
private MkRedemptionConfigVO checkInfo(MkRedemptionCode redemptionCode) {
|
||||
AssertUtil.isNull(redemptionCode, "兑换码不存在");
|
||||
AssertUtil.isTrue(redemptionCode.getStatus() == 1, "兑换码已使用");
|
||||
Long mainShopId = redemptionCode.getMainShopId();
|
||||
enableConfigService.checkEnable(mainShopId, mainShopId, TableValueConstant.EnableConfig.Type.RECHARGE_REDEMPTION, true);
|
||||
ShopUser shopUserInfo = shopUserService.getShopUserInfo(mainShopId, userId);
|
||||
|
||||
|
||||
AssertUtil.isTrue(redemptionCode.getStatus() != 0, "兑换码不存在");
|
||||
@@ -305,6 +302,16 @@ public class MkRedemptionConfigServiceImpl extends ServiceImpl<MkCouponRedemptio
|
||||
if (config.getEndTime() != null) {
|
||||
AssertUtil.isTrue(config.getEndTime().isBefore(DateUtil.date().toLocalDateTime()), "兑换活动已结束");
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void exchange(long userId, MkRedemptionDTO dto) {
|
||||
MkRedemptionCode redemptionCode = codeService.getOne(new QueryWrapper().eq(MkRedemptionCode::getCode, dto.getCode()));
|
||||
MkRedemptionConfigVO config = checkInfo(redemptionCode);
|
||||
ShopUser shopUserInfo = shopUserService.getShopUserInfo(redemptionCode.getMainShopId(), userId);
|
||||
|
||||
|
||||
if (config.getType() == 0) {
|
||||
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
|
||||
@@ -319,7 +326,7 @@ public class MkRedemptionConfigServiceImpl extends ServiceImpl<MkCouponRedemptio
|
||||
if (config.getCouponInfoList() != null && !config.getCouponInfoList().isEmpty()) {
|
||||
config.getCouponInfoList().forEach(item -> {
|
||||
MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO().setCouponId(item.getId())
|
||||
.setShopId(mainShopId)
|
||||
.setShopId(redemptionCode.getMainShopId())
|
||||
.setSourceId(redemptionCode.getId())
|
||||
.setShopUserId(shopUserInfo.getId())
|
||||
.setSource("兑换码兑换");
|
||||
@@ -347,4 +354,13 @@ public class MkRedemptionConfigServiceImpl extends ServiceImpl<MkCouponRedemptio
|
||||
AssertUtil.isTrue(!update, "库存不足");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public URedemptionVO getInfo(String code) {
|
||||
MkRedemptionCode redemptionCode = codeService.getOne(new QueryWrapper().eq(MkRedemptionCode::getCode, code).eq(MkRedemptionCode::getStatus, 0));
|
||||
MkRedemptionConfigVO redemptionConfigVO = checkInfo(redemptionCode);
|
||||
ShopInfo shopInfo = shopInfoService.getById(redemptionConfigVO.getMainShopId());
|
||||
return new URedemptionVO().setShopName(shopInfo.getShopName())
|
||||
.setName(redemptionConfigVO.getName()).setCouponInfoList(redemptionConfigVO.getCouponInfoList()).setAmount(redemptionConfigVO.getAmount());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user