From d28bed1a1275131a5ca37f7da37961e2b518ac07 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 26 八月 2019 13:44:00 +0800 Subject: [PATCH] 淘礼金创建异常处理 --- fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinRecordServiceImpl.java | 108 ++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 81 insertions(+), 27 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 07b8e9f..7bc334f 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 @@ -24,11 +24,15 @@ import com.yeshi.fanli.entity.bus.user.UserMoneyExtra; import com.yeshi.fanli.entity.goods.CommonGoods; 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.goods.CommonGoodsService; import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService; +import com.yeshi.fanli.service.inter.taobao.ShareHotGoodsService; import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService; import com.yeshi.fanli.service.inter.tlj.ConfigTaoLiJinService; import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinDetailService; @@ -38,6 +42,7 @@ import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService; import com.yeshi.fanli.service.inter.user.UserInfoExtraService; import com.yeshi.fanli.service.inter.user.UserMoneyExtraService; +import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.MoneyBigDecimalUtil; import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.StringUtil; @@ -93,12 +98,14 @@ @Resource private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService; + @Resource + private ShareHotGoodsService shareHotGoodsService; + @Override public UserTaoLiJinRecord selectByPrimaryKey(Long id) { return userTaoLiJinRecordMapper.selectByPrimaryKey(id); } - @Transactional @Override public UserTaoLiJinRecord createSelfBuyTaoLiJin(Long uid, int totalNum, TaoBaoGoodsBrief goods) @@ -140,7 +147,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); @@ -195,15 +202,15 @@ perface = new BigDecimal(1); } else { // 璁$畻鎺ㄥ箍绾㈠寘 - String warningRate = configTaoLiJinService.getValueByKey("warning_value"); + String warningRate = configTaoLiJinService.getValueByKey("warning_value", new Date()); perface = TaoLiJinUtil.getSpreadMoney(warningRate, goods); } UserTaoLiJinRecord record = createUserTaoLiJin(2, uid, goods.getAuctionId(), perface, totalNum, name, - sendStartTime, sendEndTime, null, useEndTime, TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT); + 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); @@ -222,20 +229,50 @@ throw new UserTaoLiJinRecordException(101, "绾㈠寘浣欓涓嶈冻"); } - // 杩囨湡 - userTaoLiJinOriginService.overdueHongBao(uid); + // 杩囨湡 -鍙栨秷鏀跺洖 + // userTaoLiJinOriginService.overdueHongBao(uid); - BigDecimal tlj = userMoneyExtra.getTlj(); + // 鎬绘帹骞跨孩鍖� BigDecimal totalMoney = MoneyBigDecimalUtil.mul(perface, new BigDecimal(totalNum)); - if (totalMoney.compareTo(tlj) > 0) { - throw new UserTaoLiJinRecordException(101, "绾㈠寘浣欓涓嶈冻"); + + // 鑷喘鏃剁殑绾㈠寘浣欓 + 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 = TaoKeApiUtil.createTaoLiJin(auctionId, name, perface, totalNum, sendStartTime, - sendEndTime, useStartTime, useEndTime, pid); + 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 (TaoLiJinCreateException e) { + LogHelper.errorDetailInfo(e); + executor.execute(new Runnable() { + @Override + public void run() { + if (e.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) { + // 璇ュ晢鍝佷笉鏀寔鍒涘缓娣樼ぜ閲戠孩鍖� + shareHotGoodsService.deleteByGoodsId(auctionId); + } else if (e.getCode() == TaoLiJinCreateException.CODE_TLJ_NO_MONEY) { + // 瀹樻柟鐜╂硶閽卞寘浣欓涓嶈冻 TODO + } + } + }); + } catch (TaoKeApiException e1) { + } + if (taoLiJinDTO == null) { - throw new UserTaoLiJinRecordException(101, "绾㈠寘鍒涘缓澶辫触"); + throw new UserTaoLiJinRecordException(101, "娣樺疂API鎺ㄥ箍绾㈠寘鍒涘缓澶辫触"); } // 淇濆瓨璁板綍 @@ -252,12 +289,21 @@ record.setRightsId(taoLiJinDTO.getRightsId()); record.setSendUrl(taoLiJinDTO.getSendUrl()); record.setCreateTime(new Date()); + if (origin == 1) { // 鑷喘 + record.setUseType(1); + } else { // 鍒嗕韩 + record.setUseType(2); + } + userTaoLiJinRecordMapper.insertSelective(record); - // 鍓╀綑娣樼ぜ閲� 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); @@ -315,11 +361,21 @@ LogHelper.errorDetailInfo(e); } + // 鍒涘缓鎶ュ憡 + try { + userTaoLiJinReportService.insertDefault(rightsId); + } catch (Exception e) { + LogHelper.errorDetailInfo(e); + } + + if (origin == 1) { + return; // 鑷喘涓嶆帹閫佹秷鎭� + } + // 浣跨敤鎴愬姛娑堟伅 try { - String beizhu = "鏈棰嗗彇/浣跨敤鐨勯儴鍒嗗皢浼氶��鍥�"; - - SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd hh.mm"); + String beizhu = "鏈棰嗗彇鎴栭鍙栧悗鏈娇鐢ㄩ儴鍒嗛��鍥�"; + SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH.mm"); String time = sd.format(new Date()); MsgOtherTaoLiJinContentDTO content = new MsgOtherTaoLiJinContentDTO(); content.setState("绾㈠寘鎵i櫎"); @@ -327,13 +383,6 @@ content.setMoney(totalMoney); userOtherMsgNotificationService.taoLiJinMsg(uid, beizhu, content); - } catch (Exception e) { - LogHelper.errorDetailInfo(e); - } - - // 鍒涘缓鎶ュ憡 - try { - userTaoLiJinReportService.insertDefault(rightsId); } catch (Exception e) { LogHelper.errorDetailInfo(e); } @@ -373,7 +422,7 @@ return null; } - List<CommonGoods> listGoods = commonGoodsService.getByListGoodsId(listGoodsId); + List<CommonGoods> listGoods = commonGoodsService.getByListGoodsId(listGoodsId, Constant.SOURCE_TYPE_TAOBAO); if (listGoods == null || listGoods.size() == 0) { return null; } @@ -406,9 +455,9 @@ // 璁$畻鍒嗕韩濂栭噾 BigDecimal shareMoney = new BigDecimal(0); BigDecimal commission = userTaoLiJinRecordVO.getCommission(); - if (commission != null && commission.compareTo(shareMoney) > 1) { + if (commission != null && commission.compareTo(shareMoney) > 0) { BigDecimal shareRate = hongBaoManageService.getShareRate(); - shareMoney = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.mul(commission, new BigDecimal("0.01")), + shareMoney = MoneyBigDecimalUtil.mul(commission, MoneyBigDecimalUtil.div(shareRate, new BigDecimal(100))); shareMoney = BigDecimalUtil.getWithNoZera(shareMoney); } @@ -428,6 +477,11 @@ } @Override + public long countShareRecordByUid(Long uid) { + return userTaoLiJinRecordMapper.countShareRecordByUid(uid); + } + + @Override public long countTodayNum(Long uid) { return userTaoLiJinRecordMapper.countTodayNum(uid); } -- Gitblit v1.8.0