兑换码优化
This commit is contained in:
parent
598ed3c4de
commit
08b7e66bac
|
|
@ -2,6 +2,7 @@ package com.czg.controller.user;
|
|||
|
||||
import com.czg.market.dto.MkRedemptionDTO;
|
||||
import com.czg.market.service.MkRedemptionConfigService;
|
||||
import com.czg.market.vo.URedemptionVO;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import jakarta.annotation.Resource;
|
||||
|
|
@ -17,17 +18,25 @@ import org.springframework.web.bind.annotation.*;
|
|||
@RequestMapping("/user/redemption")
|
||||
public class URedemptionController {
|
||||
@Resource
|
||||
private MkRedemptionConfigService couponRedemptionConfigService;
|
||||
private MkRedemptionConfigService redemptionConfigService;
|
||||
|
||||
/**
|
||||
* 使用券码
|
||||
*/
|
||||
@PostMapping("/exchange")
|
||||
public CzgResult<Boolean> exchange(@Validated @RequestBody MkRedemptionDTO dto) {
|
||||
couponRedemptionConfigService.exchange(StpKit.USER.getLoginIdAsLong(), dto);
|
||||
|
||||
redemptionConfigService.exchange(StpKit.USER.getLoginIdAsLong(), dto);
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 兑换码详细信息
|
||||
* @param code 兑换码
|
||||
*/
|
||||
@GetMapping
|
||||
public CzgResult<URedemptionVO> get(@RequestParam String code) {
|
||||
return CzgResult.success(redemptionConfigService.getInfo(code));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.czg.market.dto.MkRedemptionConfigDTO;
|
|||
import com.czg.market.dto.MkRedemptionDTO;
|
||||
import com.czg.market.vo.MkRedemptionCodeVO;
|
||||
import com.czg.market.vo.MkRedemptionConfigVO;
|
||||
import com.czg.market.vo.URedemptionVO;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.czg.market.entity.MkRedemptionConfig;
|
||||
|
|
@ -30,4 +31,6 @@ public interface MkRedemptionConfigService extends IService<MkRedemptionConfig>
|
|||
void exportCodeList(Long mainShopId, Long redemptionId, String code, Integer status, HttpServletResponse response, HttpServletRequest request, boolean isRecharge);
|
||||
|
||||
void exchange(long userId, MkRedemptionDTO dto);
|
||||
|
||||
URedemptionVO getInfo(String code);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package com.czg.market.vo;
|
||||
|
||||
import com.czg.market.dto.CouponInfoDTO;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 兑换码明细 实体类。
|
||||
*
|
||||
* @author zs
|
||||
* @since 2025-10-21
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class URedemptionVO implements Serializable {
|
||||
|
||||
private String shopName;
|
||||
private String name;
|
||||
private List<CouponInfoDTO> couponInfoList;
|
||||
private BigDecimal amount;
|
||||
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue