This commit is contained in:
zhouwentao 2024-04-17 10:04:26 +08:00
parent 1e9e919911
commit 071a98a032
1 changed files with 23 additions and 22 deletions

View File

@ -48,62 +48,63 @@ public class MiniVipController {
private IYxVipSkuService yxVipSkuService; private IYxVipSkuService yxVipSkuService;
@Autowired @Autowired
private MiniUserService miniUserService; private MiniUserService miniUserService;
@GetMapping(value = "/getVipInfo") @GetMapping(value = "/getVipInfo")
@ApiOperation(value = "获取vip信息") @ApiOperation(value = "获取vip信息")
public Result<?> vipInfo(){ public Result<?> vipInfo() {
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
AssertUtils.notNull(loginUser,"未获取到登录信息"); AssertUtils.notNull(loginUser, "未获取到登录信息");
VipDTO userVip = miniUserService.getUserVip(loginUser.getId()); VipDTO userVip = miniUserService.getUserVip(loginUser.getId());
return Result.OK(userVip); return Result.OK(userVip);
} }
@GetMapping(value = "/sku/all") @GetMapping(value = "/sku/all")
@ApiOperation(value = "获取全部商品信息") @ApiOperation(value = "获取全部商品信息")
public Result<?> skuAll(@RequestParam(defaultValue = "") String provider){ public Result<?> skuAll(@RequestParam(defaultValue = "") String provider) {
if (StringUtils.isNotBlank(provider) && "toutiao".equals(provider)) { /*if (StringUtils.isNotBlank(provider) && "toutiao".equals(provider)) {
LambdaQueryWrapper<YxVipSku> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<YxVipSku> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(YxVipSku::getSkuName,"测试体验卡"); queryWrapper.eq(YxVipSku::getSkuName,"测试体验卡");
queryWrapper.orderByDesc(YxVipSku::getSkuPrice); queryWrapper.orderByDesc(YxVipSku::getSkuPrice);
List<YxVipSku> list = yxVipSkuService.list(queryWrapper); List<YxVipSku> list = yxVipSkuService.list(queryWrapper);
return Result.OK(list); return Result.OK(list);
}else{ }else{*/
LambdaQueryWrapper<YxVipSku> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<YxVipSku> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(YxVipSku::getSaleable, "1"); queryWrapper.eq(YxVipSku::getSaleable, "1");
queryWrapper.orderByDesc(YxVipSku::getSkuPrice); queryWrapper.orderByDesc(YxVipSku::getSkuPrice);
queryWrapper.ne(YxVipSku::getSkuName,"测试体验卡"); queryWrapper.ne(YxVipSku::getSkuName, "测试体验卡");
List<YxVipSku> list = yxVipSkuService.list(queryWrapper); List<YxVipSku> list = yxVipSkuService.list(queryWrapper);
return Result.OK(list); return Result.OK(list);
} // }
} }
@PostMapping(value = "/card/activation") @PostMapping(value = "/card/activation")
@ApiOperation(value = "卡密激活") @ApiOperation(value = "卡密激活")
public Result<?> cardActivation(@RequestBody JSONObject jsonObject){ public Result<?> cardActivation(@RequestBody JSONObject jsonObject) {
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
SysUser user = sysUserService.getById(sysUser.getId()); SysUser user = sysUserService.getById(sysUser.getId());
AssertUtils.notNull(user,"获取用户信息失败,请联系管理员"); AssertUtils.notNull(user, "获取用户信息失败,请联系管理员");
String card = jsonObject.getString("card"); String card = jsonObject.getString("card");
AssertUtils.notNull(card,"请输入卡密"); AssertUtils.notNull(card, "请输入卡密");
//检查card是否有效 //检查card是否有效
boolean cardValid = yxVipCardService.cardIsValid(card); boolean cardValid = yxVipCardService.cardIsValid(card);
AssertUtils.isTrue(cardValid,"当前卡密无效或已被使用"); AssertUtils.isTrue(cardValid, "当前卡密无效或已被使用");
YxVipCard yxVipCard = yxVipCardService.getOne(new LambdaQueryWrapper<YxVipCard>().eq(YxVipCard::getCardNum, card)); YxVipCard yxVipCard = yxVipCardService.getOne(new LambdaQueryWrapper<YxVipCard>().eq(YxVipCard::getCardNum, card));
VipDTO userVip = miniUserService.getUserVip(user.getId()); VipDTO userVip = miniUserService.getUserVip(user.getId());
if (userVip!=null && userVip.getVipLevel()!=0) { if (userVip != null && userVip.getVipLevel() != 0) {
AssertUtils.notTrue(yxVipSkuService.convertVipLevel(yxVipCard.getSkuCode())<=userVip.getVipLevel(),"该权益您已激活!不可重复兑换"); AssertUtils.notTrue(yxVipSkuService.convertVipLevel(yxVipCard.getSkuCode()) <= userVip.getVipLevel(), "该权益您已激活!不可重复兑换");
} }
//使用卡密 //使用卡密
boolean exchange = yxVipCardService.exchange(card, user.getId()); boolean exchange = yxVipCardService.exchange(card, user.getId());
AssertUtils.isTrue(exchange,"当前卡密已被使用"); AssertUtils.isTrue(exchange, "当前卡密已被使用");
return Result.OK("激活成功"); return Result.OK("激活成功");
} }
@GetMapping(value = "/orderDetail") @GetMapping(value = "/orderDetail")
@ApiOperation(value = "获取订单详情") @ApiOperation(value = "获取订单详情")
public Result<?> buy(@RequestParam(value = "orderCode")String orderCode){ public Result<?> buy(@RequestParam(value = "orderCode") String orderCode) {
AssertUtils.notNull(orderCode,"订单编号为空!"); AssertUtils.notNull(orderCode, "订单编号为空!");
YxOrder yxOrder = yxOrderService.getOne(new LambdaQueryWrapper<YxOrder>().eq(YxOrder::getOrderCode, orderCode)); YxOrder yxOrder = yxOrderService.getOne(new LambdaQueryWrapper<YxOrder>().eq(YxOrder::getOrderCode, orderCode));
AssertUtils.notNull(yxOrder,"订单信息未找到!"); AssertUtils.notNull(yxOrder, "订单信息未找到!");
return Result.OK(yxOrder); return Result.OK(yxOrder);
} }
} }