package com.yeshi.fanli.service.impl.integral;
|
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
|
import com.yeshi.fanli.dao.mybatis.integral.IntegralExchangeMapper;
|
import com.yeshi.fanli.entity.integral.IntegralExchange;
|
import com.yeshi.fanli.entity.integral.IntegralExchange.ExchangeTypeEnum;
|
import com.yeshi.fanli.exception.integral.IntegralExchangeException;
|
import com.yeshi.fanli.service.inter.integral.IntegralExchangeService;
|
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.vo.integral.ExchangeTipVO;
|
import com.yeshi.fanli.vo.user.UserInfoExtraVO;
|
|
@Service
|
public class IntegralExchangeServiceImpl implements IntegralExchangeService {
|
|
@Resource
|
private IntegralExchangeMapper integralExchangeMapper;
|
|
@Resource
|
private UserInfoExtraService userInfoExtraService;
|
|
|
@Override
|
public List<IntegralExchange> listValidCache(long start, int count){
|
return integralExchangeMapper.listValid(start, count);
|
}
|
|
@Override
|
public Long countValid(){
|
return integralExchangeMapper.countValid();
|
}
|
|
|
@Override
|
public ExchangeTipVO verifyExchange(Long uid, Long id) throws IntegralExchangeException{
|
if (uid == null || uid <= 0)
|
throw new IntegralExchangeException(1, "用户未登录");
|
|
if (id == null || id <= 0)
|
throw new IntegralExchangeException(1, "兑换id不正确");
|
|
UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid);
|
if (extraVO == null)
|
throw new IntegralExchangeException(1, "用户相关信息不存在");
|
|
IntegralExchange exchange = integralExchangeMapper.selectByPrimaryKey(id);
|
if (exchange == null)
|
throw new IntegralExchangeException(1, "兑换方式不存在");
|
|
|
ExchangeTipVO exchangeTip = new ExchangeTipVO();
|
Integer goldCoin = exchange.getGoldCoin();
|
Integer goldCoinHas = extraVO.getGoldCoin();
|
if (goldCoin.intValue() > goldCoinHas.intValue()) {
|
exchangeTip.setType("notEnough");
|
exchangeTip.setTip("当前账户中可用金币不足,无法兑换该奖品!");
|
exchangeTip.setGoldCoin((goldCoin.intValue() - goldCoinHas.intValue()) + "金币");
|
return exchangeTip;
|
}
|
|
ExchangeTypeEnum type = exchange.getType();
|
if (ExchangeTypeEnum.freeCouponBuy == type) {
|
exchangeTip.setTip("自购免单券仅能自己使用,且每个用户ID只能兑换一次。\r\n注:兑换成功后请到“我的-福利中心”中查看");
|
} else if (ExchangeTypeEnum.freeCouponGive == type) {
|
exchangeTip.setTip("赠送免单券兑换次数不限,赠送次数不限,受赠人若无“邀请人”成功领取后将成为你的一级队员。\r\n注:兑换成功后请到“我的-福利中心”中查看");
|
} else if (ExchangeTypeEnum.rebateCoupon == type) {
|
exchangeTip.setTip("返利奖励券兑换次数不限,赠送次数不限,受赠人若无“邀请人”成功领取后将成为你的一级队员。\r\n注:兑换成功后请到“我的-福利中心”中查看");
|
} else if (ExchangeTypeEnum.inviteCodeActivate == type) {
|
exchangeTip.setTip("注:兑换成功后请到“消息-系统消息”查看");
|
} else if (ExchangeTypeEnum.inviteCodePublish == type) {
|
exchangeTip.setInviteCode(extraVO.getInviteCode());
|
exchangeTip.setTip("兑换成功后,将发布于“激活邀请码兑换功能中”,需激活邀请的用户可用金币兑换,本次展示有效期为3天。");
|
} else if (ExchangeTypeEnum.taoLiJin == type) {
|
exchangeTip.setName(exchange.getAmount() + "元推广红包");
|
exchangeTip.setTip("注:兑换成功后请到“我的-推广红包”中查看");
|
} else if (ExchangeTypeEnum.cash == type) {
|
exchangeTip.setName(exchange.getAmount() + "元现金红包");
|
exchangeTip.setTip("注:兑换成功后请到“我的-账户余额”中查看");
|
} else {
|
throw new IntegralExchangeException(1, "兑换方式不存在");
|
}
|
|
exchangeTip.setGoldCoin(goldCoin + "金币");
|
exchangeTip.setType(type.name());
|
return exchangeTip;
|
}
|
|
|
@Override
|
public void exchange(Long uid, Long id, Long inviteId) throws IntegralExchangeException{
|
if (uid == null || uid <= 0)
|
throw new IntegralExchangeException(1, "用户未登录");
|
|
if (id == null || id <= 0)
|
throw new IntegralExchangeException(1, "兑换id不正确");
|
|
UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid);
|
if (extraVO == null)
|
throw new IntegralExchangeException(1, "用户相关信息不存在");
|
|
IntegralExchange exchange = integralExchangeMapper.selectByPrimaryKey(id);
|
if (exchange == null)
|
throw new IntegralExchangeException(1, "兑换方式不存在");
|
|
Integer goldCoin = exchange.getGoldCoin();
|
Integer goldCoinHas = extraVO.getGoldCoin();
|
if (goldCoin.intValue() > goldCoinHas.intValue()) {
|
throw new IntegralExchangeException(1, "当前账户中可用金币不足,无法兑换该奖品!");
|
}
|
|
ExchangeTypeEnum type = exchange.getType();
|
if (ExchangeTypeEnum.freeCouponBuy == type) {
|
// 自购免单券
|
|
|
} else if (ExchangeTypeEnum.freeCouponGive == type) {
|
// 赠送免单券
|
|
|
} else if (ExchangeTypeEnum.rebateCoupon == type) {
|
// 奖励免单券
|
|
|
} else if (ExchangeTypeEnum.inviteCodeActivate == type) {
|
if (inviteId == null || inviteId <= 0)
|
throw new IntegralExchangeException(1, "传递参数不正确");
|
|
// 激活邀请码
|
UserInfoExtraVO inviteExtra = userInfoExtraService.getInfoExtraVOByUid(inviteId);
|
if (inviteExtra == null || StringUtil.isNullOrEmpty(inviteExtra.getInviteCode()))
|
throw new IntegralExchangeException(1, "兑换失败,该用户邀请码不存在");
|
|
} else if (ExchangeTypeEnum.inviteCodePublish == type) {
|
// 邀请码发布
|
|
|
} else if (ExchangeTypeEnum.taoLiJin == type) {
|
// 推广红包
|
|
|
} else if (ExchangeTypeEnum.cash == type) {
|
// 现金红包
|
|
} else {
|
throw new IntegralExchangeException(1, "兑换方式不存在");
|
}
|
}
|
}
|