From d8359ddb48dab5cc797a9d552e11fde571f4920c Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期二, 27 八月 2019 12:32:46 +0800 Subject: [PATCH] Merge branch 'div' of ssh://193.112.35.168:29418/fanli-server into div --- fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinRecordServiceImpl.java | 154 ++++++++++++++++++++------------------------------ 1 files changed, 62 insertions(+), 92 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 ce6ae73..1f541db 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 @@ -30,6 +30,7 @@ import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.entity.taobao.TaoKeAppInfo; import com.yeshi.fanli.exception.taobao.TaoKeApiException; +import com.yeshi.fanli.exception.tlj.TaoLiJinCreateException; import com.yeshi.fanli.exception.tlj.UserTaoLiJinRecordException; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.config.ConfigService; @@ -53,7 +54,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.TokenUtil; import com.yeshi.fanli.util.factory.CommonGoodsFactory; import com.yeshi.fanli.util.taobao.TaoKeApiUtil; import com.yeshi.fanli.util.taobao.TaoLiJinUtil; @@ -116,14 +117,12 @@ @Resource private UserTaoLiJinGiveRecordService userTaoLiJinGiveRecordService; - - + @Override public UserTaoLiJinRecord selectByPrimaryKey(Long id) { return userTaoLiJinRecordMapper.selectByPrimaryKey(id); } - @Transactional @Override public UserTaoLiJinRecord createSelfBuyTaoLiJin(Long uid, int totalNum, TaoBaoGoodsBrief goods) @@ -165,7 +164,7 @@ UserTaoLiJinRecord record = createUserTaoLiJin(1, uid, goods.getAuctionId(), perface, 1, name, sendStartTime, sendEndTime, null, useEndTime, TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID); record.setSendUrl(record.getSendUrl() + "&relationId=" + relationId); - UserTaoLiJinRecord updateRecoed=new UserTaoLiJinRecord(); + UserTaoLiJinRecord updateRecoed = new UserTaoLiJinRecord(); updateRecoed.setId(record.getId()); updateRecoed.setSendUrl(record.getSendUrl()); userTaoLiJinRecordMapper.updateByPrimaryKeySelective(record); @@ -220,7 +219,7 @@ perface = new BigDecimal(1); } else { // 璁$畻鎺ㄥ箍绾㈠寘 - String warningRate = configTaoLiJinService.getValueByKey("warning_value",new Date()); + String warningRate = configTaoLiJinService.getValueByKey("warning_value", new Date()); perface = TaoLiJinUtil.getSpreadMoney(warningRate, goods); } @@ -228,7 +227,7 @@ sendStartTime, sendEndTime, null, useEndTime, TaoBaoConstant.TAOBAO_TLJ_RELATION_PID_DEFAULT); String sendUrl = record.getSendUrl() + "&relationId=" + relationId; record.setSendUrl(sendUrl); - UserTaoLiJinRecord updateRecoed=new UserTaoLiJinRecord(); + UserTaoLiJinRecord updateRecoed = new UserTaoLiJinRecord(); updateRecoed.setId(record.getId()); updateRecoed.setSendUrl(sendUrl); userTaoLiJinRecordMapper.updateByPrimaryKeySelective(record); @@ -249,45 +248,46 @@ // 杩囨湡 -鍙栨秷鏀跺洖 // userTaoLiJinOriginService.overdueHongBao(uid); - + // 鎬绘帹骞跨孩鍖� BigDecimal totalMoney = MoneyBigDecimalUtil.mul(perface, new BigDecimal(totalNum)); - + // 鑷喘鏃剁殑绾㈠寘浣欓 if (origin == 1) { BigDecimal tljSelf = userMoneyExtra.getTljSelf(); if (tljSelf == null || tljSelf.compareTo(totalMoney) < 0) { throw new UserTaoLiJinRecordException(101, "鑷喘绾㈠寘浣欓涓嶈冻"); } - } - + } + // 鍒嗕韩鏃剁殑绾㈠寘浣欓 BigDecimal tlj = userMoneyExtra.getTlj(); if (tlj == null || tlj.compareTo(totalMoney) < 0) { throw new UserTaoLiJinRecordException(101, "鍒嗕韩绾㈠寘浣欓涓嶈冻"); } - // 鍒涘缓娣樼ぜ閲戠孩鍖� TaoLiJinDTO taoLiJinDTO = null; try { - taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, name, perface, totalNum, sendStartTime, - sendEndTime, useStartTime, useEndTime, new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, pid)); - } catch (TaoKeApiException e) { + taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, name, perface, totalNum, sendStartTime, sendEndTime, + useStartTime, useEndTime, + new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, pid)); + } catch (TaoLiJinCreateException e) { LogHelper.errorDetailInfo(e); executor.execute(new Runnable() { @Override public void run() { - if (e.getCode() == TaoKeApiException.CODE_TLJ_FORBIDDEN) { + if (e.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) { // 璇ュ晢鍝佷笉鏀寔鍒涘缓娣樼ぜ閲戠孩鍖� shareHotGoodsService.deleteByGoodsId(auctionId); - } else if (e.getCode() == TaoKeApiException.CODE_TLJ_NO_MONEY) { - // 瀹樻柟鐜╂硶閽卞寘浣欓涓嶈冻 TODO + } else if (e.getCode() == TaoLiJinCreateException.CODE_TLJ_NO_MONEY) { + // 瀹樻柟鐜╂硶閽卞寘浣欓涓嶈冻 TODO } } }); + } catch (TaoKeApiException e1) { } - + if (taoLiJinDTO == null) { throw new UserTaoLiJinRecordException(101, "娣樺疂API鎺ㄥ箍绾㈠寘鍒涘缓澶辫触"); } @@ -306,21 +306,21 @@ record.setRightsId(taoLiJinDTO.getRightsId()); record.setSendUrl(taoLiJinDTO.getSendUrl()); record.setCreateTime(new Date()); - if (origin == 1) { // 鑷喘 + if (origin == 1) { // 鑷喘 record.setUseType(1); - } else { // 鍒嗕韩 + } else { // 鍒嗕韩 record.setUseType(2); } - + userTaoLiJinRecordMapper.insertSelective(record); - BigDecimal surplusTlj = MoneyBigDecimalUtil.sub(tlj, totalMoney); - + BigDecimal surplusTlj = MoneyBigDecimalUtil.sub(tlj, totalMoney); + UserMoneyExtra updateExtra = new UserMoneyExtra(); updateExtra.setUid(uid); if (origin == 1) { // 鍓╀綑娣樼ぜ閲�-- 鑷喘 updateExtra.setTljSelf(MoneyBigDecimalUtil.sub(userMoneyExtra.getTljSelf(), totalMoney)); - } + } updateExtra.setTlj(surplusTlj); updateExtra.setUpdateTime(new Date()); userMoneyExtraService.updateByPrimaryKeySelective(updateExtra); @@ -384,17 +384,15 @@ } catch (Exception e) { LogHelper.errorDetailInfo(e); } - - - if (origin == 1) { - return; // 鑷喘涓嶆帹閫佹秷鎭� + + if (origin == 1) { + return; // 鑷喘涓嶆帹閫佹秷鎭� } - - + // 浣跨敤鎴愬姛娑堟伅 try { String beizhu = "鏈棰嗗彇鎴栭鍙栧悗鏈娇鐢ㄩ儴鍒嗛��鍥�"; - SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH.mm"); + SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm"); String time = sd.format(new Date()); MsgOtherTaoLiJinContentDTO content = new MsgOtherTaoLiJinContentDTO(); content.setState("绾㈠寘鎵i櫎"); @@ -476,7 +474,8 @@ BigDecimal commission = userTaoLiJinRecordVO.getCommission(); if (commission != null && commission.compareTo(shareMoney) > 0) { BigDecimal shareRate = hongBaoManageService.getShareRate(); - shareMoney = MoneyBigDecimalUtil.mul(commission, MoneyBigDecimalUtil.div(shareRate, new BigDecimal(100))); + shareMoney = MoneyBigDecimalUtil.mul(commission, + MoneyBigDecimalUtil.div(shareRate, new BigDecimal(100))); shareMoney = BigDecimalUtil.getWithNoZera(shareMoney); } @@ -498,8 +497,7 @@ public long countShareRecordByUid(Long uid) { return userTaoLiJinRecordMapper.countShareRecordByUid(uid); } - - + @Override public long countTodayNum(Long uid) { return userTaoLiJinRecordMapper.countTodayNum(uid); @@ -533,73 +531,45 @@ if (amount.compareTo(tlj) > 0) throw new UserTaoLiJinRecordException(1, "绾㈠寘浣欓涓嶈冻"); - Long giveId = null; Date nowDate = new Date(); - try { - String endDay = DateUtil.plusDay(Constant.GIVE_DAYS - 1, nowDate); - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - Date endTime = format.parse(endDay); - - // 璧犻�佽褰� - UserTaoLiJinGiveRecord giveRecord = new UserTaoLiJinGiveRecord(); - giveRecord.setAmount(amount); - giveRecord.setGiveUid(uid); - giveRecord.setState(UserTaoLiJinGiveRecord.STATE_INIT); - giveRecord.setGiveTime(nowDate); - giveRecord.setEndTime(endTime); - userTaoLiJinGiveRecordService.insertSelective(giveRecord); - - giveId = giveRecord.getId(); - } catch (Exception e) { - LogHelper.errorDetailInfo(e); - throw new UserTaoLiJinRecordException(1, "璧犻�佽褰曞垱寤哄け璐�"); - } + // 璧犻�佽褰� + UserTaoLiJinGiveRecord giveRecord = new UserTaoLiJinGiveRecord(); + giveRecord.setAmount(amount); + giveRecord.setGiveUid(uid); + giveRecord.setState(UserTaoLiJinGiveRecord.STATE_INIT); + giveRecord.setGiveTime(nowDate); + giveRecord.setEndTime(DateUtil.plusDayDate(Constant.GIVE_DAYS, new Date())); + 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); - - String endDay = DateUtil.plusDay(Constant.TOKEN_DAYS - 1,nowDate); - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - Date endTime = format.parse(endDay); - - TokenRecord tokenRecord = new TokenRecord(); - tokenRecord.setUid(uid); - tokenRecord.setIdentify(giveId + ""); // 璁板綍id - tokenRecord.setType(TokenTypeEnum.taoLiJin); - tokenRecord.setStartTime(nowDate); - tokenRecord.setEndTime(endTime); - tokenRecord.setToken(token); - tokenRecord.setState(0); - tokenRecordService.insertSelective(tokenRecord); - } catch (Exception e) { - LogHelper.errorDetailInfo(e); - token = null; - } - - if(!StringUtil.isNullOrEmpty(token)) { - break; - } - } + // 鍙d护璁板綍 + TokenRecord tokenRecord = new TokenRecord(); + tokenRecord.setUid(uid); + tokenRecord.setIdentify(giveRecord.getId() + ""); + tokenRecord.setType(TokenTypeEnum.taoLiJin); + tokenRecord.setStartTime(nowDate); + tokenRecord.setEndTime(DateUtil.plusDayDate(Constant.TOKEN_DAYS, new Date())); + tokenRecord.setState(0); + tokenRecordService.insertSelective(tokenRecord); - if(StringUtil.isNullOrEmpty(token)) - throw new UserTaoLiJinRecordException(1, "鍙d护鐢熸垚澶辫触"); + // 鍒涘缓鍙d护 + String token = TokenUtil.createToken(tokenRecord.getId()); + tokenRecord.setToken(token); + tokenRecordService.updateByPrimaryKeySelective(tokenRecord); + // 鏇存柊浣欓 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")); + String tips = configTaoLiJinService.getValueByKey("give_taolijin_tips"); + String projectChineseName = Constant.systemCommonConfig.getProjectChineseName(); + while(tips.contains("{APP鍚嶇О}")) { + tips = tips.replace("{APP鍚嶇О}", projectChineseName); + } + tips = tips.replace("{鍙d护}", token).replace("{涓嬭浇閾炬帴}", configService.get("app_down_link")) + .replace("{闈㈤}", amount.setScale(0).toString()); executor.execute(new Runnable() { @Override -- Gitblit v1.8.0