From 3672aec5bf6c2c6da4cb7ab4a8b5f314a22c5831 Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期一, 19 八月 2019 17:32:00 +0800 Subject: [PATCH] 退回淘礼金 --- fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java | 119 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 96 insertions(+), 23 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java index 6ae6cf5..03f2e7d 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralExchangeServiceImpl.java @@ -6,9 +6,11 @@ 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; @@ -23,6 +25,8 @@ import com.yeshi.fanli.service.inter.integral.CodePublishRecordService; import com.yeshi.fanli.service.inter.integral.IntegralExchangeRecordService; import com.yeshi.fanli.service.inter.integral.IntegralExchangeService; +import com.yeshi.fanli.service.inter.msg.MsgInviteDetailService; +import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService; import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinOriginService; import com.yeshi.fanli.service.inter.user.UserInfoExtraService; import com.yeshi.fanli.service.inter.user.UserInfoService; @@ -36,6 +40,9 @@ @Service public class IntegralExchangeServiceImpl implements IntegralExchangeService { + @Resource(name = "taskExecutor") + private TaskExecutor executor; + @Resource private IntegralExchangeMapper integralExchangeMapper; @@ -62,6 +69,12 @@ @Resource private IntegralExchangeRecordService integralExchangeRecordService; + + @Resource + private UserOtherMsgNotificationService userOtherMsgNotificationService; + + @Resource + private MsgInviteDetailService msgInviteDetailService; @@ -104,13 +117,13 @@ return exchangeTip; } - int upperLimit = exchange.getUpperLimit(); - // 浠婃棩鍏戞崲鎯呭喌 - long exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid); - if (exchangeCount >= upperLimit) { - throw new IntegralExchangeException(1, "浠婃棩鍏戞崲宸茶揪涓婇檺"); + Integer upperLimit = exchange.getUpperLimit(); + if (upperLimit != null) { // 鏄惁鏈夐檺鍒舵瘡鏃ユ鏁� + long exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid); + if (exchangeCount >= upperLimit) { + throw new IntegralExchangeException(1, "浠婃棩鍏戞崲宸茶揪涓婇檺"); + } } - Integer goldCoinHas = extraVO.getGoldCoin(); if (goldCoin.intValue() > goldCoinHas.intValue()) { @@ -162,11 +175,13 @@ if (exchange == null) throw new IntegralExchangeException(1, "鍏戞崲鏂瑰紡涓嶅瓨鍦�"); - int upperLimit = exchange.getUpperLimit(); - // 浠婃棩鍏戞崲鎯呭喌 - long exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid); - if (exchangeCount >= upperLimit) { - throw new IntegralExchangeException(1, "浠婃棩鍏戞崲宸茶揪涓婇檺"); + long exchangeCount = 0; + Integer upperLimit = exchange.getUpperLimit(); + if (upperLimit != null) { // 鏄惁鏈夐檺鍒舵瘡鏃ユ鏁� + exchangeCount = integralExchangeRecordService.countRecordByUid(id, uid); + if (exchangeCount >= upperLimit) { + throw new IntegralExchangeException(1, "浠婃棩鍏戞崲宸茶揪涓婇檺"); + } } Integer goldCoin = exchange.getGoldCoin(); @@ -175,26 +190,29 @@ throw new IntegralExchangeException(1, "褰撳墠璐︽埛涓彲鐢ㄩ噾甯佷笉瓒筹紝鏃犳硶鍏戞崲璇ュ鍝侊紒"); } + String thing = ""; try { ExchangeTypeEnum type = exchange.getType(); - if (ExchangeTypeEnum.freeCouponBuy == type || ExchangeTypeEnum.freeCouponGive == type) { - // 鑷喘鍏嶅崟鍒搞�佽禒閫佸厤鍗曞埜 + if (ExchangeTypeEnum.freeCouponBuy == type) { + thing = "鑷喘鍏嶅崟鍒�"; + userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, null); + } else if (ExchangeTypeEnum.freeCouponGive == type) { + thing = "璧犻�佸厤鍗曞埜"; userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, null); } else if (ExchangeTypeEnum.rebatePercentCoupon == type) { - // 濂栧姳鍏嶅崟鍒� + thing = "濂栧姳鍏嶅崟鍒�"; userSystemCouponService.exchangeCoupon(uid, type.name(), UserSystemCoupon.SOURCE_EXCHANGE, new BigDecimal(10)); } else if (ExchangeTypeEnum.inviteCodePublish == type) { - // 閭�璇风爜鍙戝竷 + thing = "閭�璇风爜婵�娲诲崱"; if(codePublishRecordService.countValidRecord(uid) > 0) throw new IntegralExchangeException(1, "涓夊ぉ涔嬪唴涓嶅彲閲嶅鍏戞崲"); codePublishRecordService.publishInviteCode(uid); } else if (ExchangeTypeEnum.taoLiJin == type) { - // 鎺ㄥ箍绾㈠寘 + thing = "鎺ㄥ箍绾㈠寘"; userTaoLiJinOriginService.exchangeMoney(uid, exchange.getAmount()); } else if (ExchangeTypeEnum.cash == type) { - // 鐜伴噾绾㈠寘 + thing = "鐜伴噾绾㈠寘"; BigDecimal money = exchange.getAmount(); - // 1銆佹彃鍏ョ孩鍖呮暟鎹� HongBaoV2 hongBaoV2 = new HongBaoV2(); hongBaoV2.setMoney(money); @@ -222,13 +240,32 @@ progress = progress.replace("{宸插厬鎹",exchangeCount + "").replace("{涓婇檺鏁皚", exchange.getUpperLimit() + ""); exchange.setProgress(progress); + // 鍓╀綑閲戝竵 + int surplus = goldCoinHas.intValue() - goldCoin.intValue(); + exchange.setUserGoldCoin(surplus + "鏋�"); + // 鏇存柊閲戝竵 UserInfoExtraVO extraUpdate = new UserInfoExtraVO(); extraUpdate.setId(extraVO.getId()); - extraUpdate.setGoldCoin(goldCoinHas.intValue() - goldCoin.intValue()); + extraUpdate.setGoldCoin(surplus); userInfoExtraService.saveUserInfoExtra(extraUpdate); - exchange.setUserGoldCoin(extraUpdate.getGoldCoin() + "鏋�"); + // 娣诲姞鍏戞崲璁板綍 + integralExchangeRecordService.addExchangeRecord(id, uid); + + // 娑堟伅 + 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); + } + }); return exchange; } catch (Exception e) { @@ -305,19 +342,55 @@ Integer goldCoin = exchange.getGoldCoin(); Integer goldCoinHas = extraVO.getGoldCoin(); - if (goldCoin.intValue() > goldCoinHas.intValue()) { + 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(); userInfoExtraService.activateInviteCode(uid, inviteExtra.getInviteCode()); + + // 鍓╀綑閲戝竵 + int surplus = goldCoinHas.intValue() - goldCoin.intValue(); + + // 鏇存柊閲戝竵 + UserInfoExtraVO extraUpdate = new UserInfoExtraVO(); + extraUpdate.setId(extraVO.getId()); + extraUpdate.setGoldCoin(surplus); + userInfoExtraService.saveUserInfoExtra(extraUpdate); + + + // 娣诲姞鍏戞崲璁板綍 + integralExchangeRecordService.addExchangeRecord(id, 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); + } + }); } catch (Exception e) { LogHelper.errorDetailInfo(e); - throw new IntegralExchangeException(1, "鍏戞崲寮傚父"); + throw new IntegralExchangeException(1, "鍏戞崲澶辫触"); } + + } } -- Gitblit v1.8.0