From 1db61f9479d537ecf2c030d8b9cb45b1e0bf0eec Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期五, 16 八月 2019 11:59:39 +0800 Subject: [PATCH] 口令 --- fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinRecordServiceImpl.java | 143 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 143 insertions(+), 0 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinRecordServiceImpl.java index 712136c..71d1031 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinRecordServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinRecordServiceImpl.java @@ -13,14 +13,18 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.yeshi.utils.BigDecimalUtil; +import org.yeshi.utils.DateUtil; import com.yeshi.fanli.dao.mybatis.tlj.UserTaoLiJinRecordMapper; import com.yeshi.fanli.dto.msg.MsgOtherTaoLiJinContentDTO; import com.yeshi.fanli.dto.taobao.TaoLiJinDTO; import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail; import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail.TaoLiJinDetailTypeEnum; +import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinGiveRecord; import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinOrigin; import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinRecord; +import com.yeshi.fanli.entity.bus.user.TokenRecord; +import com.yeshi.fanli.entity.bus.user.TokenRecord.TokenTypeEnum; import com.yeshi.fanli.entity.bus.user.UserMoneyExtra; import com.yeshi.fanli.entity.goods.CommonGoods; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; @@ -28,6 +32,7 @@ import com.yeshi.fanli.exception.taobao.TaoKeApiException; import com.yeshi.fanli.exception.tlj.UserTaoLiJinRecordException; import com.yeshi.fanli.log.LogHelper; +import com.yeshi.fanli.service.inter.config.ConfigService; import com.yeshi.fanli.service.inter.goods.CommonGoodsService; import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService; @@ -35,9 +40,11 @@ import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService; import com.yeshi.fanli.service.inter.tlj.ConfigTaoLiJinService; import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinDetailService; +import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinGiveRecordService; import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinOriginService; import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinRecordService; import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinReportService; +import com.yeshi.fanli.service.inter.user.TokenRecordService; import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService; import com.yeshi.fanli.service.inter.user.UserInfoExtraService; import com.yeshi.fanli.service.inter.user.UserMoneyExtraService; @@ -46,6 +53,7 @@ import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.TaoBaoConstant; +import com.yeshi.fanli.util.account.UserUtil; import com.yeshi.fanli.util.factory.CommonGoodsFactory; import com.yeshi.fanli.util.taobao.TaoKeApiUtil; import com.yeshi.fanli.util.taobao.TaoLiJinUtil; @@ -60,6 +68,9 @@ @Resource private RedisManager redisManager; + + @Resource + private ConfigService configService; @Resource private UserTaoLiJinRecordMapper userTaoLiJinRecordMapper; @@ -99,6 +110,13 @@ @Resource private ShareHotGoodsService shareHotGoodsService; + + @Resource + private TokenRecordService tokenRecordService; + + @Resource + private UserTaoLiJinGiveRecordService userTaoLiJinGiveRecordService; + @Override public UserTaoLiJinRecord selectByPrimaryKey(Long id) { @@ -496,5 +514,130 @@ public UserTaoLiJinRecord getByRightsId(String rightsId) { return userTaoLiJinRecordMapper.getByRightsId(rightsId); } + + @Override + public String giveTaolijin(Long uid, BigDecimal amount) throws UserTaoLiJinRecordException{ + if (uid == null || amount == null) + throw new UserTaoLiJinRecordException(1,"鍙傛暟涓嶆纭�"); + + String giveMin = configTaoLiJinService.getValueByKey("give_min_amount"); + if (amount.compareTo(new BigDecimal(giveMin)) < 0) + throw new UserTaoLiJinRecordException(1,"璧犻�佹帹骞跨孩鍖呴噾棰濊嚦灏�" + giveMin + "鍏�"); + + // 鐢ㄦ埛鍓╀綑鍙互娣樼ぜ閲戦獙璇� + UserMoneyExtra userMoneyExtra = userMoneyExtraService.selectByPrimaryKey(uid); + if (userMoneyExtra == null || userMoneyExtra.getTlj() == null) + throw new UserTaoLiJinRecordException(1, "绾㈠寘浣欓涓嶈冻"); + + BigDecimal tlj = userMoneyExtra.getTlj(); + if (amount.compareTo(tlj) > 0) + throw new UserTaoLiJinRecordException(1, "绾㈠寘浣欓涓嶈冻"); + + + Date nowDate = new Date(); + + // 璧犻�佽褰� + UserTaoLiJinGiveRecord giveRecord = new UserTaoLiJinGiveRecord(); + giveRecord.setAmount(amount); + giveRecord.setGiveUid(uid); + giveRecord.setState(UserTaoLiJinGiveRecord.STATE_INIT); + giveRecord.setGiveTime(nowDate); + userTaoLiJinGiveRecordService.insertSelective(giveRecord); + + String token = null; + for (int i = 0; i < 5; i++) { + try { + // TODO 鍙d护鐢熸垚瑙勫垯寰呭畾 + long num = 10000 + (long) (Math.random() * 10000); + token = UserUtil.getInviteCode(num); + + TokenRecord tokenRecord = new TokenRecord(); + tokenRecord.setUid(uid); + tokenRecord.setIdentify(giveRecord.getId()+""); // 璁板綍id + tokenRecord.setType(TokenTypeEnum.taoLiJin); + tokenRecord.setStartTime(nowDate); + tokenRecord.setEndTime(DateUtil.plusDayDate(3, nowDate)); + tokenRecord.setToken(token); + tokenRecord.setState(0); + tokenRecordService.insertSelective(tokenRecord); + } catch (Exception e) { + LogHelper.errorDetailInfo(e); + token = null; + } + + if(!StringUtil.isNullOrEmpty(token)) { + break; + } + } + + if(StringUtil.isNullOrEmpty(token)) + throw new UserTaoLiJinRecordException(1, "鍙d护鐢熸垚澶辫触"); + + UserMoneyExtra updateExtra = new UserMoneyExtra(); + updateExtra.setUid(uid); + updateExtra.setTlj(MoneyBigDecimalUtil.sub(tlj, amount)); + updateExtra.setUpdateTime(new Date()); + userMoneyExtraService.updateByPrimaryKeySelective(updateExtra); + + String tips = "閫佺粰浣燵%s]鍏冩帹骞跨孩鍖呭揩鍘婚鍙栧惂锛屽鍒舵湰鏉℃秷鎭痆&%s&]锛屾墦寮�[杩斿埄鍒竇App棰嗗彇锛岀敤鎺ㄥ箍鍒嗕韩鐖嗘鍟嗗搧锛屾垚鍗曠巼鏇撮珮鍝︺�俓r\n" + + "----------------------------\r\n" + + "涓嬭浇[杩斿埄鍒竇App閾炬帴:%s\r\n" + + "PS锛氬彛浠ゅ皢浼�24灏忔椂鍐呭け鏁堬紝璇峰強鏃堕鍙栥��"; + + tips = String.format(tips, amount, token, configService.get("app_down_link")); + + executor.execute(new Runnable() { + @Override + public void run() { + try { + // 鎻掑叆鏄庣粏 + UserTaoLiJinDetail detail = new UserTaoLiJinDetail(); + detail.setUid(uid); + detail.setMoney(new BigDecimal("-" + amount)); + detail.setTitle(TaoLiJinDetailTypeEnum.give.getDesc()); + detail.setType(TaoLiJinDetailTypeEnum.give); + detail.setCreateTime(new Date()); + userTaoLiJinDetailService.insertSelective(detail); + } catch (Exception e) { + LogHelper.errorDetailInfo(e); + } + + // 鎴愬姛浣跨敤绾㈠寘 + try { + BigDecimal total = amount; + BigDecimal lastMoney = null; + BigDecimal zero = new BigDecimal(0); + // 淇敼浣欓 + List<UserTaoLiJinOrigin> list = userTaoLiJinOriginService.getSurplusLiJin(uid); + if (list != null && list.size() > 0) { + for (UserTaoLiJinOrigin taoLiJinOrigin : list) { + if (total.compareTo(zero) < 1) { + break; + } + BigDecimal moneySurplus = taoLiJinOrigin.getMoneySurplus(); + lastMoney = total; + total = MoneyBigDecimalUtil.sub(total, moneySurplus); + if (total.compareTo(zero) >= 0) { + moneySurplus = zero; + } else { + moneySurplus = MoneyBigDecimalUtil.sub(moneySurplus, lastMoney); + } + + UserTaoLiJinOrigin usertlj = new UserTaoLiJinOrigin(); + usertlj.setId(taoLiJinOrigin.getId()); + usertlj.setMoneySurplus(moneySurplus); + usertlj.setUpdateTime(new Date()); + userTaoLiJinOriginService.updateByPrimaryKeySelective(usertlj); + } + } + } catch (Exception e) { + LogHelper.errorDetailInfo(e); + } + } + }); + + return tips; + } + } -- Gitblit v1.8.0