From 5e7b0ed4a154ad067cbcf4aa1a1c7cce32f9864c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 26 四月 2024 18:02:17 +0800
Subject: [PATCH] 唯品会链接解析升级

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralExchangeServiceImpl.java |  955 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 477 insertions(+), 478 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralExchangeServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralExchangeServiceImpl.java
index 863ed09..2893c38 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralExchangeServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralExchangeServiceImpl.java
@@ -1,478 +1,477 @@
-package com.yeshi.fanli.service.impl.user.integral;
-
-import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import org.springframework.core.task.TaskExecutor;
-import org.springframework.stereotype.Service;
-
-import com.yeshi.fanli.dao.mybatis.integral.IntegralExchangeMapper;
-import com.yeshi.fanli.dto.msg.MsgOtherExchangeContentDTO;
-import com.yeshi.fanli.entity.bus.user.HongBaoV2;
-import com.yeshi.fanli.entity.bus.user.UserInfo;
-import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
-import com.yeshi.fanli.entity.bus.user.UserSystemCoupon;
-import com.yeshi.fanli.entity.integral.CodePublishRecord;
-import com.yeshi.fanli.entity.integral.IntegralDetail;
-import com.yeshi.fanli.entity.integral.IntegralExchange;
-import com.yeshi.fanli.entity.integral.IntegralExchange.ExchangeTypeEnum;
-import com.yeshi.fanli.entity.money.UserMoneyDetail;
-import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
-import com.yeshi.fanli.exception.integral.IntegralExchangeException;
-import com.yeshi.fanli.log.LogHelper;
-import com.yeshi.fanli.service.inter.config.ConfigService;
-import com.yeshi.fanli.service.inter.money.UserMoneyDetailService;
-import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService;
-import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
-import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinOriginService;
-import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
-import com.yeshi.fanli.service.inter.user.UserInfoService;
-import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
-import com.yeshi.fanli.service.inter.user.integral.CodePublishRecordService;
-import com.yeshi.fanli.service.inter.user.integral.IntegralDetailService;
-import com.yeshi.fanli.service.inter.user.integral.IntegralExchangeRecordService;
-import com.yeshi.fanli.service.inter.user.integral.IntegralExchangeService;
-import com.yeshi.fanli.service.inter.user.invite.MsgInviteDetailService;
-import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
-import com.yeshi.fanli.vo.integral.ExchangeTipVO;
-import com.yeshi.fanli.vo.user.UserInfoExtraVO;
-
-@Service
-public class IntegralExchangeServiceImpl implements IntegralExchangeService {
-
-	@Resource(name = "taskExecutor")
-	private TaskExecutor executor;
-
-	@Resource
-	private IntegralExchangeMapper integralExchangeMapper;
-
-	@Resource
-	private ConfigService configService;
-
-	@Resource
-	private UserInfoExtraService userInfoExtraService;
-
-	@Resource
-	private UserSystemCouponService userSystemCouponService;
-
-	@Resource
-	private UserTaoLiJinOriginService userTaoLiJinOriginService;
-
-	@Resource
-	private HongBaoV2Service hongBaoV2Service;
-
-	@Resource
-	private UserMoneyDetailService userMoneyDetailService;
-
-	@Resource
-	private UserInfoService userInfoService;
-
-	@Resource
-	private CodePublishRecordService codePublishRecordService;
-
-	@Resource
-	private IntegralExchangeRecordService integralExchangeRecordService;
-
-	@Resource
-	private UserOtherMsgNotificationService userOtherMsgNotificationService;
-
-	@Resource
-	private MsgInviteDetailService msgInviteDetailService;
-
-	@Resource
-	private IntegralDetailService integralDetailService;
-
-	@Override
-	public IntegralExchange selectByPrimaryKey(Long id) {
-		return integralExchangeMapper.selectByPrimaryKey(id);
-	}
-
-	@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, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
-
-		Integer state = exchange.getState();
-		if (state == null || state != 1)
-			throw new IntegralExchangeException(1, "鍏戞崲娲诲姩鏈紑鍚�");
-
-		Integer goldCoin = exchange.getGoldCoin();
-
-		ExchangeTipVO exchangeTip = new ExchangeTipVO();
-		exchangeTip.setId(id);
-		ExchangeTypeEnum type = exchange.getType();
-		if (ExchangeTypeEnum.inviteCodeActivate == type) {
-			exchangeTip.setType(type.name());
-			return exchangeTip;
-		}
-
-		long exchangeCount = 0;
-		if (ExchangeTypeEnum.freeCouponBuy == type) {
-			exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid, null);
-			if (exchangeCount >= 1) {
-				throw new IntegralExchangeException(1, "鑷喘鍏嶅崟鍒革紝浠呰兘鍏戞崲涓�娆�");
-			}
-		}
-
-		Integer upperLimit = exchange.getUpperLimit();
-		if (upperLimit != null) { // 鏄惁鏈夐檺鍒舵瘡鏃ユ鏁�
-			Integer today = 1;
-			exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid, today);
-			if (exchangeCount >= upperLimit) {
-				throw new IntegralExchangeException(1, "浠婃棩鍏戞崲宸茶揪涓婇檺");
-			}
-		}
-
-		Integer goldCoinHas = extraVO.getGoldCoin();
-		if (goldCoin.intValue() > goldCoinHas.intValue()) {
-			exchangeTip.setType("notEnough");
-			exchangeTip.setTip("褰撳墠璐︽埛涓彲鐢ㄩ噾甯佷笉瓒筹紝鏃犳硶鍏戞崲璇ュ鍝侊紒");
-			exchangeTip.setGoldCoin((goldCoin.intValue() - goldCoinHas.intValue()) + "閲戝竵");
-			return exchangeTip;
-		}
-
-		if (ExchangeTypeEnum.freeCouponBuy == type) {
-			exchangeTip.setTip("鑷喘鍏嶅崟鍒镐粎鑳借嚜宸变娇鐢紝涓旀瘡涓敤鎴稩D鍙兘鍏戞崲涓�娆°�俓r\n娉�:鍏戞崲鎴愬姛鍚庤鍒扳�滄垜鐨�-绂忓埄涓績鈥濅腑鏌ョ湅");
-		} else if (ExchangeTypeEnum.freeCouponGive == type) {
-			exchangeTip.setTip("璧犻�佸厤鍗曞埜鍏戞崲娆℃暟涓嶉檺锛岃禒閫佹鏁颁笉闄愶紝鍙楄禒浜鸿嫢鏃犫�滈個璇蜂汉鈥濇垚鍔熼鍙栧悗灏嗘垚涓轰綘鐨勪竴绾ч槦鍛樸�俓r\n娉�:鍏戞崲鎴愬姛鍚庤鍒扳�滄垜鐨�-绂忓埄涓績鈥濅腑鏌ョ湅");
-		} else if (ExchangeTypeEnum.rebatePercentCoupon == type) {
-			exchangeTip.setTip("杩斿埄濂栧姳鍒稿厬鎹㈡鏁颁笉闄愶紝璧犻�佹鏁颁笉闄愶紝鍙楄禒浜鸿嫢鏃犫�滈個璇蜂汉鈥濇垚鍔熼鍙栧悗灏嗘垚涓轰綘鐨勪竴绾ч槦鍛樸�俓r\n娉�:鍏戞崲鎴愬姛鍚庤鍒扳�滄垜鐨�-绂忓埄涓績鈥濅腑鏌ョ湅");
-		} else if (ExchangeTypeEnum.inviteCodePublish == type) {
-			if (codePublishRecordService.countValidRecord(uid) > 0)
-				throw new IntegralExchangeException(1, "涓夊ぉ涔嬪唴涓嶅彲閲嶅鍏戞崲");
-			exchangeTip.setInviteCode(extraVO.getInviteCode());
-			exchangeTip.setTip("鍏戞崲鎴愬姛鍚庯紝灏嗗彂甯冧簬鈥滄縺娲婚個璇风爜鍏戞崲鍔熻兘涓�濓紝闇�婵�娲婚個璇风殑鐢ㄦ埛鍙敤閲戝竵鍏戞崲锛屾湰娆″睍绀烘湁鏁堟湡涓�3澶┿��");
-		} else if (ExchangeTypeEnum.taoLiJin == type) {
-			exchangeTip.setName(exchange.getAmount().setScale(0) + "鍏冩帹骞跨孩鍖�");
-			exchangeTip.setTip("娉�:鍏戞崲鎴愬姛鍚庤鍒扳�滄垜鐨�-鎺ㄥ箍绾㈠寘鈥濅腑鏌ョ湅");
-		} else if (ExchangeTypeEnum.cash == type) {
-			exchangeTip.setName(exchange.getAmount().setScale(0) + "鍏冪幇閲戠孩鍖�");
-			exchangeTip.setTip("娉細鍏戞崲鎴愬姛鍚庤鍒扳�滄垜鐨�-璐︽埛浣欓鈥濅腑鏌ョ湅");
-		} else {
-			throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
-		}
-
-		exchangeTip.setGoldCoin(goldCoin + "閲戝竵");
-		exchangeTip.setType(type.name());
-		return exchangeTip;
-	}
-
-	@Override
-	public IntegralExchange exchange(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涓嶆纭�");
-
-		UserInfoExtra extraVO = userInfoExtraService.getUserInfoExtra(uid);
-		if (extraVO == null)
-			throw new IntegralExchangeException(1, "鐢ㄦ埛鐩稿叧淇℃伅涓嶅瓨鍦�");
-
-		IntegralExchange exchange = integralExchangeMapper.selectByPrimaryKey(id);
-		if (exchange == null)
-			throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
-
-		Integer state = exchange.getState();
-		if (state == null || state != 1)
-			throw new IntegralExchangeException(1, "鍏戞崲娲诲姩鏈紑鍚�");
-
-		long exchangeCount = 0;
-		ExchangeTypeEnum type = exchange.getType();
-		if (ExchangeTypeEnum.freeCouponBuy == type) {
-			exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid, null);
-			if (exchangeCount >= 1) {
-				throw new IntegralExchangeException(1, "鑷喘鍏嶅崟鍒革紝浠呰兘鍏戞崲涓�娆�");
-			}
-		}
-
-		Integer upperLimit = exchange.getUpperLimit();
-		if (upperLimit != null) { // 鏄惁鏈夐檺鍒舵瘡鏃ユ鏁�
-			Integer today = 1;
-			exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid, today);
-			if (exchangeCount >= upperLimit) {
-				throw new IntegralExchangeException(1, "鍏戞崲宸茶揪涓婇檺");
-			}
-		}
-
-		Integer goldCoin = exchange.getGoldCoin();
-		Integer goldCoinHas = extraVO.getGoldCoin();
-		if (goldCoin.intValue() > goldCoinHas.intValue()) {
-			throw new IntegralExchangeException(1, "褰撳墠璐︽埛涓彲鐢ㄩ噾甯佷笉瓒筹紝鏃犳硶鍏戞崲璇ュ鍝侊紒");
-		}
-
-		String thing = "";
-		String thingNum = "";
-		int couponNews = 0;
-		boolean once = false; // 鍏戞崲涓�娆℃槸鍚︽秷澶�
-		try {
-			if (ExchangeTypeEnum.freeCouponBuy == type) {
-				List<UserSystemCoupon> listCoupon = userSystemCouponService.getFreeCouponByType(uid,
-						CouponTypeEnum.freeCouponBuy.name());
-				if (listCoupon != null && listCoupon.size() > 0)
-					throw new IntegralExchangeException(1, "鑷喘鍏嶅崟鍒革紝浠呰兘鍏戞崲涓�娆�");
-
-				thing = "鑷喘鍏嶅崟鍒�";
-				thingNum = "1寮�";
-				userSystemCouponService.exchangeCoupon(uid, CouponTypeEnum.freeCouponBuy.name(),
-						UserSystemCoupon.SOURCE_EXCHANGE, null);
-				once = true;
-				couponNews = 1;
-			} else if (ExchangeTypeEnum.freeCouponGive == type) {
-				thing = "璧犻�佸厤鍗曞埜";
-				thingNum = "1寮�";
-				userSystemCouponService.exchangeCoupon(uid, CouponTypeEnum.freeCouponGive.name(),
-						UserSystemCoupon.SOURCE_EXCHANGE, null);
-				couponNews = 1;
-			} else if (ExchangeTypeEnum.rebatePercentCoupon == type) {
-				thing = "杩斿埄濂栧姳鍒�";
-				thingNum = "1寮�";
-				String percent = configService.get("exchange_rebate_percent");
-				userSystemCouponService.exchangeCoupon(uid, CouponTypeEnum.rebatePercentCoupon.name(),
-						UserSystemCoupon.SOURCE_EXCHANGE, new BigDecimal(percent));
-				couponNews = 1;
-			} else if (ExchangeTypeEnum.inviteCodePublish == type) {
-				thing = "閭�璇风爜鍙戝竷鍗�";
-				thingNum = "3澶�";
-				if (codePublishRecordService.countValidRecord(uid) > 0)
-					throw new IntegralExchangeException(1, "涓夊ぉ涔嬪唴涓嶅彲閲嶅鍏戞崲");
-				codePublishRecordService.publishInviteCode(uid);
-
-				exchange.setNeedJump(true);
-				exchange.setBtnName("鍘绘煡鐪�");
-			} else if (ExchangeTypeEnum.taoLiJin == type) {
-				thing = "鎺ㄥ箍绾㈠寘";
-				thingNum = exchange.getAmount() + "鍏�";
-				userTaoLiJinOriginService.exchangeMoney(uid, exchange.getAmount());
-			} else if (ExchangeTypeEnum.cash == type) {
-				thing = "鐜伴噾绾㈠寘";
-				BigDecimal money = exchange.getAmount();
-				thingNum = money + "鍏�";
-
-				// 1銆佹彃鍏ョ孩鍖呮暟鎹�
-				HongBaoV2 hongBaoV2 = new HongBaoV2();
-				hongBaoV2.setMoney(money);
-				hongBaoV2.setType(HongBaoV2.TYPE_EXCHANGE);
-				hongBaoV2.setState(HongBaoV2.STATE_YILINGQU);
-				hongBaoV2.setVersion(2);
-				hongBaoV2.setCreateTime(new Date());
-				hongBaoV2.setUpdateTime(new Date());
-				hongBaoV2.setUserInfo(new UserInfo(uid));
-				hongBaoV2.setPreGetTime(new Date());
-				hongBaoV2.setGetTime(new Date());
-				hongBaoV2Service.insertSelective(hongBaoV2);
-
-				// 2.鎻掑叆璧勯噾鏄庣粏,鐢ㄦ埛浣欓
-				UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createScoreConvert(money, new UserInfo(uid));
-				userMoneyDetailService.addUserMoneyDetail(userMoneyDetail);
-				userInfoService.addMoney(new UserInfo(uid), money);
-			} else {
-				throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
-			}
-
-			exchangeCount++;
-			String progress = exchange.getProgress();
-			if (!StringUtil.isNullOrEmpty(progress))
-				progress = progress.replace("{宸插厬鎹", exchangeCount + "").replace("{涓婇檺鏁皚",
-						exchange.getUpperLimit() + "");
-			exchange.setProgress(progress);
-
-			// 鍓╀綑閲戝竵
-			int surplus = goldCoinHas.intValue() - goldCoin.intValue();
-			exchange.setUserGoldCoin(surplus + "鏋�");
-
-			// 鏇存柊閲戝竵 + 绂忓埄涓績娑堟伅鏁�
-			if (extraVO.getCouponNews() != null && extraVO.getCouponNews() > 0)
-				couponNews = couponNews + extraVO.getCouponNews();
-
-			UserInfoExtraVO extraUpdate = new UserInfoExtraVO();
-			extraUpdate.setId(extraVO.getId());
-			extraUpdate.setGoldCoin(surplus);
-			extraUpdate.setCouponNews(couponNews);
-			userInfoExtraService.saveUserInfoExtra(extraUpdate);
-
-			// 娣诲姞鍏戞崲璁板綍
-			integralExchangeRecordService.addExchangeRecord(id, uid);
-
-			// 鍔犲叆鏄庣粏
-			IntegralDetail detail = new IntegralDetail();
-			detail.setUid(uid);
-			detail.setTitle("閲戝竵鍏戞崲-" + thing + "-" + thingNum);
-			detail.setMoney(-goldCoin);
-			detail.setCreateTime(new Date());
-			integralDetailService.insertSelective(detail);
-
-			// 娑堟伅
-			final String things = thing;
-			executor.execute(new Runnable() {
-				@Override
-				public void run() {
-					MsgOtherExchangeContentDTO msgOther = new MsgOtherExchangeContentDTO();
-					msgOther.setState("閲戝竵鍏戞崲鎴愬姛");
-					msgOther.setExpend(goldCoin + "閲戝竵");
-					msgOther.setTotalGold(surplus + "閲戝竵");
-					msgOther.setThing(things);
-					userOtherMsgNotificationService.exchangeMsg(uid, "", msgOther);
-				}
-			});
-
-			if (once) // 鍏戞崲涔嬪悗娑堝け
-				exchange = null;
-
-			return exchange;
-		} catch (IntegralExchangeException e) {
-			throw new IntegralExchangeException(1, e.getMsg());
-		} catch (Exception e) {
-			LogHelper.errorDetailInfo(e);
-			throw new IntegralExchangeException(1, "鍏戞崲寮傚父");
-		}
-	}
-
-	@Override
-	public ExchangeTipVO verifyInviteCode(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涓嶆纭�");
-
-		UserInfoExtra extraVO = userInfoExtraService.getUserInfoExtra(uid);
-		if (extraVO == null)
-			throw new IntegralExchangeException(1, "鐢ㄦ埛鐩稿叧淇℃伅涓嶅瓨鍦�");
-
-		if (!StringUtil.isNullOrEmpty(extraVO.getInviteCode()))
-			throw new IntegralExchangeException(1, "閭�璇风爜宸叉縺娲伙紝鏃犻渶鍏戞崲");
-
-		CodePublishRecord record = codePublishRecordService.selectByPrimaryKey(id);
-		if (record == null)
-			throw new IntegralExchangeException(1, "鍏戞崲璁板綍涓嶅瓨鍦�");
-
-		IntegralExchange exchange = integralExchangeMapper.getValidByType(ExchangeTypeEnum.inviteCodeActivate.name());
-		if (exchange == null)
-			throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
-
-		ExchangeTipVO exchangeTip = new ExchangeTipVO();
-		exchangeTip.setId(id);
-		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;
-		}
-
-		exchangeTip.setTip("娉細鍏戞崲鎴愬姛鍚庤鍒扳�滄秷鎭�-绯荤粺娑堟伅鈥濇煡鐪�");
-		exchangeTip.setGoldCoin(goldCoin + "閲戝竵");
-		exchangeTip.setType(ExchangeTypeEnum.inviteCodeActivate.name());
-		return exchangeTip;
-	}
-
-	@Override
-	public String exchangeInviteCode(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涓嶆纭�");
-
-		UserInfoExtra extraVO = userInfoExtraService.getUserInfoExtra(uid);
-		if (extraVO == null)
-			throw new IntegralExchangeException(1, "鐢ㄦ埛鐩稿叧淇℃伅涓嶅瓨鍦�");
-
-		if (!StringUtil.isNullOrEmpty(extraVO.getInviteCode()))
-			throw new IntegralExchangeException(1, "閭�璇风爜宸叉縺娲伙紝鏃犻渶鍏戞崲");
-
-		CodePublishRecord record = codePublishRecordService.selectByPrimaryKey(id);
-		if (record == null)
-			throw new IntegralExchangeException(1, "鍏戞崲璁板綍涓嶅瓨鍦�");
-
-		IntegralExchange exchange = integralExchangeMapper.getValidByType(ExchangeTypeEnum.inviteCodeActivate.name());
-		if (exchange == null)
-			throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
-
-		Integer goldCoin = exchange.getGoldCoin();
-		Integer goldCoinHas = extraVO.getGoldCoin();
-		if (goldCoin.intValue() > goldCoinHas.intValue())
-			throw new IntegralExchangeException(1, "褰撳墠璐︽埛涓彲鐢ㄩ噾甯佷笉瓒筹紝鏃犳硶鍏戞崲璇ュ鍝侊紒");
-
-		try {
-			UserInfoExtraVO inviteExtra = userInfoExtraService.getInfoExtraVOByUid(record.getUid());
-			if (inviteExtra == null || StringUtil.isNullOrEmpty(inviteExtra.getInviteCode()))
-				throw new IntegralExchangeException(1, "鍏戞崲澶辫触锛岃鐢ㄦ埛閭�璇风爜涓嶅瓨鍦�");
-
-			String inviteCode = inviteExtra.getInviteCode();
-
-			// 鍓╀綑閲戝竵
-			int surplus = goldCoinHas.intValue() - goldCoin.intValue();
-
-			// 鏇存柊閲戝竵
-			UserInfoExtraVO extraUpdate = new UserInfoExtraVO();
-			extraUpdate.setId(extraVO.getId());
-			extraUpdate.setGoldCoin(surplus);
-			userInfoExtraService.saveUserInfoExtra(extraUpdate);
-
-			// 鍔犲叆鏄庣粏
-			IntegralDetail detail = new IntegralDetail();
-			detail.setUid(uid);
-			detail.setTitle("閲戝竵鍏戞崲-閭�璇风爜婵�娲诲崱-1缁�");
-			detail.setMoney(-goldCoin);
-			detail.setCreateTime(new Date());
-			integralDetailService.insertSelective(detail);
-
-			// 娣诲姞鍏戞崲璁板綍
-			integralExchangeRecordService.addExchangeRecord(exchange.getId(), uid);
-
-			// 娑堟伅
-			executor.execute(new Runnable() {
-				@Override
-				public void run() {
-					UserInfo userInfo = userInfoService.selectByPKey(record.getUid());
-					if (userInfo == null)
-						return;
-
-					String beizu = "閭�璇蜂汉锛�" + userInfo.getNickName() + "锛岄個璇风爜锛�" + inviteCode;
-
-					MsgOtherExchangeContentDTO msgOther = new MsgOtherExchangeContentDTO();
-					msgOther.setState("閲戝竵鍏戞崲鎴愬姛");
-					msgOther.setExpend(goldCoin + "閲戝竵");
-					msgOther.setTotalGold(surplus + "閲戝竵");
-					msgOther.setThing("閭�璇风爜婵�娲诲崱");
-
-					userOtherMsgNotificationService.exchangeMsg(uid, beizu, msgOther);
-				}
-			});
-
-			return inviteCode;
-		} catch (Exception e) {
-			LogHelper.errorDetailInfo(e);
-			throw new IntegralExchangeException(1, "鍏戞崲澶辫触");
-		}
-	}
-
-}
+package com.yeshi.fanli.service.impl.user.integral;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import com.yeshi.fanli.entity.SystemEnum;
+import org.springframework.core.task.TaskExecutor;
+import org.springframework.stereotype.Service;
+
+import com.yeshi.fanli.dao.mybatis.integral.IntegralExchangeMapper;
+import com.yeshi.fanli.dto.msg.MsgOtherExchangeContentDTO;
+import com.yeshi.fanli.entity.bus.user.HongBaoV2;
+import com.yeshi.fanli.entity.bus.user.UserInfo;
+import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
+import com.yeshi.fanli.entity.bus.user.UserSystemCoupon;
+import com.yeshi.fanli.entity.integral.CodePublishRecord;
+import com.yeshi.fanli.entity.integral.IntegralDetail;
+import com.yeshi.fanli.entity.integral.IntegralExchange;
+import com.yeshi.fanli.entity.integral.IntegralExchange.ExchangeTypeEnum;
+import com.yeshi.fanli.entity.money.UserMoneyDetail;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
+import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
+import com.yeshi.fanli.exception.integral.IntegralExchangeException;
+import com.yeshi.fanli.log.LogHelper;
+import com.yeshi.fanli.service.inter.config.ConfigService;
+import com.yeshi.fanli.service.inter.money.UserMoneyDetailService;
+import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService;
+import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
+import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinOriginService;
+import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
+import com.yeshi.fanli.service.inter.user.UserInfoService;
+import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
+import com.yeshi.fanli.service.inter.user.integral.CodePublishRecordService;
+import com.yeshi.fanli.service.inter.user.integral.IntegralDetailService;
+import com.yeshi.fanli.service.inter.user.integral.IntegralExchangeRecordService;
+import com.yeshi.fanli.service.inter.user.integral.IntegralExchangeService;
+import com.yeshi.fanli.service.inter.user.invite.MsgInviteDetailService;
+import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
+import com.yeshi.fanli.vo.integral.ExchangeTipVO;
+import com.yeshi.fanli.vo.user.UserInfoExtraVO;
+
+@Service
+public class IntegralExchangeServiceImpl implements IntegralExchangeService {
+
+	@Resource(name = "taskExecutor")
+	private TaskExecutor executor;
+
+	@Resource
+	private IntegralExchangeMapper integralExchangeMapper;
+
+	@Resource
+	private ConfigService configService;
+
+	@Resource
+	private UserInfoExtraService userInfoExtraService;
+
+	@Resource
+	private UserSystemCouponService userSystemCouponService;
+
+	@Resource
+	private UserTaoLiJinOriginService userTaoLiJinOriginService;
+
+	@Resource
+	private HongBaoV2Service hongBaoV2Service;
+
+	@Resource
+	private UserMoneyDetailService userMoneyDetailService;
+
+	@Resource
+	private UserInfoService userInfoService;
+
+	@Resource
+	private CodePublishRecordService codePublishRecordService;
+
+	@Resource
+	private IntegralExchangeRecordService integralExchangeRecordService;
+
+	@Resource
+	private UserOtherMsgNotificationService userOtherMsgNotificationService;
+
+	@Resource
+	private MsgInviteDetailService msgInviteDetailService;
+
+	@Resource
+	private IntegralDetailService integralDetailService;
+
+	@Override
+	public IntegralExchange selectByPrimaryKey(Long id) {
+		return integralExchangeMapper.selectByPrimaryKey(id);
+	}
+
+	@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, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
+
+		Integer state = exchange.getState();
+		if (state == null || state != 1)
+			throw new IntegralExchangeException(1, "鍏戞崲娲诲姩鏈紑鍚�");
+
+		Integer goldCoin = exchange.getGoldCoin();
+
+		ExchangeTipVO exchangeTip = new ExchangeTipVO();
+		exchangeTip.setId(id);
+		ExchangeTypeEnum type = exchange.getType();
+		if (ExchangeTypeEnum.inviteCodeActivate == type) {
+			exchangeTip.setType(type.name());
+			return exchangeTip;
+		}
+
+		long exchangeCount = 0;
+		if (ExchangeTypeEnum.freeCouponBuy == type) {
+			exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid, null);
+			if (exchangeCount >= 1) {
+				throw new IntegralExchangeException(1, "鑷喘鍏嶅崟鍒革紝浠呰兘鍏戞崲涓�娆�");
+			}
+		}
+
+		Integer upperLimit = exchange.getUpperLimit();
+		if (upperLimit != null) { // 鏄惁鏈夐檺鍒舵瘡鏃ユ鏁�
+			Integer today = 1;
+			exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid, today);
+			if (exchangeCount >= upperLimit) {
+				throw new IntegralExchangeException(1, "浠婃棩鍏戞崲宸茶揪涓婇檺");
+			}
+		}
+
+		Integer goldCoinHas = extraVO.getGoldCoin();
+		if (goldCoin.intValue() > goldCoinHas.intValue()) {
+			exchangeTip.setType("notEnough");
+			exchangeTip.setTip("褰撳墠璐︽埛涓彲鐢ㄩ噾甯佷笉瓒筹紝鏃犳硶鍏戞崲璇ュ鍝侊紒");
+			exchangeTip.setGoldCoin((goldCoin.intValue() - goldCoinHas.intValue()) + "閲戝竵");
+			return exchangeTip;
+		}
+
+		if (ExchangeTypeEnum.freeCouponBuy == type) {
+			exchangeTip.setTip("鑷喘鍏嶅崟鍒镐粎鑳借嚜宸变娇鐢紝涓旀瘡涓敤鎴稩D鍙兘鍏戞崲涓�娆°�俓r\n娉�:鍏戞崲鎴愬姛鍚庤鍒扳�滄垜鐨�-绂忓埄涓績鈥濅腑鏌ョ湅");
+		} else if (ExchangeTypeEnum.freeCouponGive == type) {
+			exchangeTip.setTip("璧犻�佸厤鍗曞埜鍏戞崲娆℃暟涓嶉檺锛岃禒閫佹鏁颁笉闄愶紝鍙楄禒浜鸿嫢鏃犫�滈個璇蜂汉鈥濇垚鍔熼鍙栧悗灏嗘垚涓轰綘鐨勭洿鎺ョ矇涓濄�俓r\n娉�:鍏戞崲鎴愬姛鍚庤鍒扳�滄垜鐨�-绂忓埄涓績鈥濅腑鏌ョ湅");
+		} else if (ExchangeTypeEnum.rebatePercentCoupon == type) {
+			exchangeTip.setTip("杩斿埄濂栧姳鍒稿厬鎹㈡鏁颁笉闄愶紝璧犻�佹鏁颁笉闄愶紝鍙楄禒浜鸿嫢鏃犫�滈個璇蜂汉鈥濇垚鍔熼鍙栧悗灏嗘垚涓轰綘鐨勭洿鎺ョ矇涓濄�俓r\n娉�:鍏戞崲鎴愬姛鍚庤鍒扳�滄垜鐨�-绂忓埄涓績鈥濅腑鏌ョ湅");
+		} else if (ExchangeTypeEnum.inviteCodePublish == type) {
+			if (codePublishRecordService.countValidRecord(uid) > 0)
+				throw new IntegralExchangeException(1, "涓夊ぉ涔嬪唴涓嶅彲閲嶅鍏戞崲");
+			
+			String inviteCode = null;
+			if (!StringUtil.isNullOrEmpty(extraVO.getInviteCodeVip())) {
+				inviteCode = extraVO.getInviteCodeVip();
+			} else {
+				inviteCode = extraVO.getInviteCode();
+			}
+			exchangeTip.setInviteCode(inviteCode);
+			exchangeTip.setTip("鍏戞崲鎴愬姛鍚庯紝灏嗗彂甯冧簬鈥滄縺娲婚個璇风爜鍏戞崲鍔熻兘涓�濓紝闇�婵�娲婚個璇风殑鐢ㄦ埛鍙敤閲戝竵鍏戞崲锛屾湰娆″睍绀烘湁鏁堟湡涓�3澶┿��");
+		} else if (ExchangeTypeEnum.taoLiJin == type) {
+			exchangeTip.setName(exchange.getAmount().setScale(0) + "鍏冩帹骞跨孩鍖�");
+			exchangeTip.setTip("娉�:鍏戞崲鎴愬姛鍚庤鍒扳�滄垜鐨�-鎺ㄥ箍绾㈠寘鈥濅腑鏌ョ湅");
+		} else if (ExchangeTypeEnum.cash == type) {
+			exchangeTip.setName(exchange.getAmount().setScale(0) + "鍏冪幇閲戠孩鍖�");
+			exchangeTip.setTip("娉細鍏戞崲鎴愬姛鍚庤鍒扳�滄垜鐨�-璐︽埛浣欓鈥濅腑鏌ョ湅");
+		} else {
+			throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
+		}
+
+		exchangeTip.setGoldCoin(goldCoin + "閲戝竵");
+		exchangeTip.setType(type.name());
+		return exchangeTip;
+	}
+
+	@Override
+	public IntegralExchange exchange(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涓嶆纭�");
+
+		UserInfoExtra extraVO = userInfoExtraService.getUserInfoExtra(uid);
+		if (extraVO == null)
+			throw new IntegralExchangeException(1, "鐢ㄦ埛鐩稿叧淇℃伅涓嶅瓨鍦�");
+
+		IntegralExchange exchange = integralExchangeMapper.selectByPrimaryKey(id);
+		if (exchange == null)
+			throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
+
+		Integer state = exchange.getState();
+		if (state == null || state != 1)
+			throw new IntegralExchangeException(1, "鍏戞崲娲诲姩鏈紑鍚�");
+
+		long exchangeCount = 0;
+		ExchangeTypeEnum type = exchange.getType();
+		if (ExchangeTypeEnum.freeCouponBuy == type) {
+			exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid, null);
+			if (exchangeCount >= 1) {
+				throw new IntegralExchangeException(1, "鑷喘鍏嶅崟鍒革紝浠呰兘鍏戞崲涓�娆�");
+			}
+		}
+
+		Integer upperLimit = exchange.getUpperLimit();
+		if (upperLimit != null) { // 鏄惁鏈夐檺鍒舵瘡鏃ユ鏁�
+			Integer today = 1;
+			exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid, today);
+			if (exchangeCount >= upperLimit) {
+				throw new IntegralExchangeException(1, "鍏戞崲宸茶揪涓婇檺");
+			}
+		}
+
+		Integer goldCoin = exchange.getGoldCoin();
+		Integer goldCoinHas = extraVO.getGoldCoin();
+		if (goldCoin.intValue() > goldCoinHas.intValue()) {
+			throw new IntegralExchangeException(1, "褰撳墠璐︽埛涓彲鐢ㄩ噾甯佷笉瓒筹紝鏃犳硶鍏戞崲璇ュ鍝侊紒");
+		}
+
+	SystemEnum system= userInfoService.getUserSystem(uid);
+
+		String thing = "";
+		String thingNum = "";
+		int couponNews = 0;
+		boolean once = false; // 鍏戞崲涓�娆℃槸鍚︽秷澶�
+		try {
+			if (ExchangeTypeEnum.freeCouponBuy == type) {
+				List<UserSystemCoupon> listCoupon = userSystemCouponService.getFreeCouponByType(uid,
+						CouponTypeEnum.freeCouponBuy.name());
+				if (listCoupon != null && listCoupon.size() > 0)
+					throw new IntegralExchangeException(1, "鑷喘鍏嶅崟鍒革紝浠呰兘鍏戞崲涓�娆�");
+
+				thing = "鑷喘鍏嶅崟鍒�";
+				thingNum = "1寮�";
+				userSystemCouponService.freeCouponWin(uid, CouponTypeEnum.freeCouponBuy, UserSystemCoupon.SOURCE_EXCHANGE,
+						1, true);
+				
+				once = true;
+				couponNews = 1;
+			} else if (ExchangeTypeEnum.freeCouponGive == type) {
+				thing = "璧犻�佸厤鍗曞埜";
+				thingNum = "1寮�";
+				userSystemCouponService.freeCouponWin(uid, CouponTypeEnum.freeCouponGive, UserSystemCoupon.SOURCE_EXCHANGE,
+						1, true);
+				
+				couponNews = 1;
+			} else if (ExchangeTypeEnum.rebatePercentCoupon == type) {
+				thing = "杩斿埄濂栧姳鍒�";
+				thingNum = "1寮�";
+				String percent = configService.getValue(ConfigKeyEnum.exchangeRebatePercent.getKey(),system);
+				userSystemCouponService.rewardCouponWin(uid, UserSystemCoupon.SOURCE_EXCHANGE, 1, 
+						true, new BigDecimal(percent));
+				couponNews = 1;
+			} else if (ExchangeTypeEnum.inviteCodePublish == type) {
+				thing = "閭�璇风爜鍙戝竷鍗�";
+				thingNum = "3澶�";
+				if (codePublishRecordService.countValidRecord(uid) > 0)
+					throw new IntegralExchangeException(1, "涓夊ぉ涔嬪唴涓嶅彲閲嶅鍏戞崲");
+				codePublishRecordService.publishInviteCode(uid);
+
+				exchange.setNeedJump(true);
+				exchange.setBtnName("鍘绘煡鐪�");
+			} else if (ExchangeTypeEnum.taoLiJin == type) {
+				throw new IntegralExchangeException(1, "鎺ㄥ箍绾㈠寘鐩稿叧鍔熻兘宸蹭笅绾匡紒");
+			} else if (ExchangeTypeEnum.cash == type) {
+				thing = "鐜伴噾绾㈠寘";
+				BigDecimal money = exchange.getAmount();
+				thingNum = money + "鍏�";
+
+				// 1銆佹彃鍏ョ孩鍖呮暟鎹�
+				HongBaoV2 hongBaoV2 = new HongBaoV2();
+				hongBaoV2.setMoney(money);
+				hongBaoV2.setType(HongBaoV2.TYPE_EXCHANGE);
+				hongBaoV2.setState(HongBaoV2.STATE_YILINGQU);
+				hongBaoV2.setVersion(2);
+				hongBaoV2.setCreateTime(new Date());
+				hongBaoV2.setUpdateTime(new Date());
+				hongBaoV2.setUserInfo(new UserInfo(uid));
+				hongBaoV2.setPreGetTime(new Date());
+				hongBaoV2.setGetTime(new Date());
+				hongBaoV2Service.insertSelective(hongBaoV2);
+
+				// 2.鎻掑叆璧勯噾鏄庣粏,鐢ㄦ埛浣欓
+				UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createScoreConvert(money, new UserInfo(uid));
+				userMoneyDetailService.addUserMoneyDetail(userMoneyDetail);
+				userInfoService.addMoney(new UserInfo(uid), money);
+			} else {
+				throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
+			}
+
+			exchangeCount++;
+			String progress = exchange.getProgress();
+			if (!StringUtil.isNullOrEmpty(progress))
+				progress = progress.replace("{宸插厬鎹", exchangeCount + "").replace("{涓婇檺鏁皚",
+						exchange.getUpperLimit() + "");
+			exchange.setProgress(progress);
+
+			// 鍓╀綑閲戝竵
+			int surplus = goldCoinHas.intValue() - goldCoin.intValue();
+			exchange.setUserGoldCoin(surplus + "鏋�");
+
+			// 鏇存柊閲戝竵 + 绂忓埄涓績娑堟伅鏁�
+			if (extraVO.getCouponNews() != null && extraVO.getCouponNews() > 0)
+				couponNews = couponNews + extraVO.getCouponNews();
+
+			UserInfoExtraVO extraUpdate = new UserInfoExtraVO();
+			extraUpdate.setId(extraVO.getId());
+			extraUpdate.setGoldCoin(surplus);
+			extraUpdate.setCouponNews(couponNews);
+			userInfoExtraService.saveUserInfoExtra(extraUpdate);
+
+			// 娣诲姞鍏戞崲璁板綍
+			integralExchangeRecordService.addExchangeRecord(id, uid);
+
+			// 鍔犲叆鏄庣粏
+			IntegralDetail detail = new IntegralDetail();
+			detail.setUid(uid);
+			detail.setTitle("閲戝竵鍏戞崲-" + thing + "-" + thingNum);
+			detail.setMoney(-goldCoin);
+			detail.setCreateTime(new Date());
+			integralDetailService.insertSelective(detail);
+
+			// 娑堟伅
+			final String things = thing;
+			final String exNum = thingNum;
+			executor.execute(new Runnable() {
+				@Override
+				public void run() {
+					if (ExchangeTypeEnum.inviteCodePublish == type) {
+						userOtherMsgNotificationService.goldCoinExChangeMsg(uid, goldCoin, surplus, things, "1寮�");
+					} else {
+						userOtherMsgNotificationService.goldCoinExChangeMsg(uid, goldCoin, surplus, things, exNum);
+					}
+				}
+			});
+
+			if (once) // 鍏戞崲涔嬪悗娑堝け
+				exchange = null;
+
+			return exchange;
+		} catch (IntegralExchangeException e) {
+			throw new IntegralExchangeException(1, e.getMsg());
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+			throw new IntegralExchangeException(1, "鍏戞崲寮傚父");
+		}
+	}
+
+	@Override
+	public ExchangeTipVO verifyInviteCode(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涓嶆纭�");
+
+		UserInfoExtra extraVO = userInfoExtraService.getUserInfoExtra(uid);
+		if (extraVO == null)
+			throw new IntegralExchangeException(1, "鐢ㄦ埛鐩稿叧淇℃伅涓嶅瓨鍦�");
+
+		if (!StringUtil.isNullOrEmpty(extraVO.getInviteCode()))
+			throw new IntegralExchangeException(1, "閭�璇风爜宸叉縺娲伙紝鏃犻渶鍏戞崲");
+
+		CodePublishRecord record = codePublishRecordService.selectByPrimaryKey(id);
+		if (record == null)
+			throw new IntegralExchangeException(1, "鍏戞崲璁板綍涓嶅瓨鍦�");
+
+		IntegralExchange exchange = integralExchangeMapper.getValidByType(ExchangeTypeEnum.inviteCodeActivate.name());
+		if (exchange == null)
+			throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
+
+		ExchangeTipVO exchangeTip = new ExchangeTipVO();
+		exchangeTip.setId(id);
+		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;
+		}
+
+		exchangeTip.setTip("娉細鍏戞崲鎴愬姛鍚庤鍒扳�滄秷鎭�-绯荤粺娑堟伅鈥濇煡鐪�");
+		exchangeTip.setGoldCoin(goldCoin + "閲戝竵");
+		exchangeTip.setType(ExchangeTypeEnum.inviteCodeActivate.name());
+		return exchangeTip;
+	}
+
+	@Override
+	public String exchangeInviteCode(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涓嶆纭�");
+
+		UserInfoExtra extraVO = userInfoExtraService.getUserInfoExtra(uid);
+		if (extraVO == null)
+			throw new IntegralExchangeException(1, "鐢ㄦ埛鐩稿叧淇℃伅涓嶅瓨鍦�");
+
+		if (!StringUtil.isNullOrEmpty(extraVO.getInviteCode()))
+			throw new IntegralExchangeException(1, "閭�璇风爜宸叉縺娲伙紝鏃犻渶鍏戞崲");
+
+		CodePublishRecord record = codePublishRecordService.selectByPrimaryKey(id);
+		if (record == null)
+			throw new IntegralExchangeException(1, "鍏戞崲璁板綍涓嶅瓨鍦�");
+
+		IntegralExchange exchange = integralExchangeMapper.getValidByType(ExchangeTypeEnum.inviteCodeActivate.name());
+		if (exchange == null)
+			throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�");
+
+		Integer goldCoin = exchange.getGoldCoin();
+		Integer goldCoinHas = extraVO.getGoldCoin();
+		if (goldCoin.intValue() > goldCoinHas.intValue())
+			throw new IntegralExchangeException(1, "褰撳墠璐︽埛涓彲鐢ㄩ噾甯佷笉瓒筹紝鏃犳硶鍏戞崲璇ュ鍝侊紒");
+
+		try {
+			UserInfoExtraVO inviteExtra = userInfoExtraService.getInfoExtraVOByUid(record.getUid());
+			if (inviteExtra == null || StringUtil.isNullOrEmpty(inviteExtra.getInviteCode()))
+				throw new IntegralExchangeException(1, "鍏戞崲澶辫触锛岃鐢ㄦ埛閭�璇风爜涓嶅瓨鍦�");
+
+			String inviteCode = inviteExtra.getInviteCode();
+
+			// 鍓╀綑閲戝竵
+			int surplus = goldCoinHas.intValue() - goldCoin.intValue();
+
+			// 鏇存柊閲戝竵
+			UserInfoExtraVO extraUpdate = new UserInfoExtraVO();
+			extraUpdate.setId(extraVO.getId());
+			extraUpdate.setGoldCoin(surplus);
+			userInfoExtraService.saveUserInfoExtra(extraUpdate);
+
+			// 鍔犲叆鏄庣粏
+			IntegralDetail detail = new IntegralDetail();
+			detail.setUid(uid);
+			detail.setTitle("閲戝竵鍏戞崲-閭�璇风爜婵�娲诲崱-1缁�");
+			detail.setMoney(-goldCoin);
+			detail.setCreateTime(new Date());
+			integralDetailService.insertSelective(detail);
+
+			// 娣诲姞鍏戞崲璁板綍
+			integralExchangeRecordService.addExchangeRecord(exchange.getId(), uid);
+
+			// 娑堟伅
+			executor.execute(new Runnable() {
+				@Override
+				public void run() {
+					userOtherMsgNotificationService.goldCoinExChangeMsg(uid, goldCoin, surplus, "閭�璇风爜婵�娲诲崱", "1寮�");
+				}
+			});
+
+			return inviteCode;
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e);
+			throw new IntegralExchangeException(1, "鍏戞崲澶辫触");
+		}
+	}
+
+}

--
Gitblit v1.8.0