From b59fef5c00b15fdfdfa9d4be26e5bf6b41c75458 Mon Sep 17 00:00:00 2001 From: admin <2780501319@qq.com> Date: 星期日, 23 二月 2020 00:16:52 +0800 Subject: [PATCH] 2.0.7相关服务端功能添加 --- fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java | 526 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 422 insertions(+), 104 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java index f474455..3f23d1e 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java @@ -19,10 +19,9 @@ import org.yeshi.utils.exception.HttpException; import org.yeshi.utils.tencentcloud.COSManager; -import com.yeshi.fanli.dao.mybatis.HongBaoManageMapper; import com.yeshi.fanli.dao.mybatis.UserInfoMapper; import com.yeshi.fanli.dao.mybatis.UserShareGoodsHistoryMapper; -import com.yeshi.fanli.dao.mybatis.share.PidUserMapper; +import com.yeshi.fanli.dto.taobao.TaoLiJinDTO; import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.entity.taobao.PidUser; @@ -31,31 +30,42 @@ import com.yeshi.fanli.entity.taobao.TaoBaoLink; import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig; import com.yeshi.fanli.entity.taobao.TaoKeAppInfo; -import com.yeshi.fanli.exception.ShareGoodsException; +import com.yeshi.fanli.entity.taobao.UserTLJBuyHistory; +import com.yeshi.fanli.exception.share.ShareGoodsException; +import com.yeshi.fanli.exception.taobao.TaoKeApiException; import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; +import com.yeshi.fanli.exception.tlj.TaoLiJinCreateException; +import com.yeshi.fanli.exception.tlj.UserTaoLiJinNewbiesException; import com.yeshi.fanli.log.LogHelper; +import com.yeshi.fanli.log.LogManager; +import com.yeshi.fanli.log.LogType; import com.yeshi.fanli.service.inter.config.ConfigService; -import com.yeshi.fanli.service.inter.goods.CommonGoodsService; import com.yeshi.fanli.service.inter.goods.ShareGoodsService; -import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; +import com.yeshi.fanli.service.inter.monitor.BusinessEmergent110Service; +import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; +import com.yeshi.fanli.service.inter.redpack.UserTaoLiJinNewbiesService; +import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService; import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService; +import com.yeshi.fanli.service.inter.taobao.UserTLJBuyHistoryService; import com.yeshi.fanli.service.inter.user.TBPidService; import com.yeshi.fanli.service.inter.user.UserAccountService; -import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService; +import com.yeshi.fanli.service.manger.goods.ConvertLinkManager; import com.yeshi.fanli.util.AESUtil; import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.FilePathEnum; import com.yeshi.fanli.util.FileUtil; import com.yeshi.fanli.util.ImageUtil; import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.StringUtil; +import com.yeshi.fanli.util.TaoBaoConstant; +import com.yeshi.fanli.util.TimeUtil; import com.yeshi.fanli.util.taobao.TaoBaoUtil; import com.yeshi.fanli.util.taobao.TaoKeApiUtil; @Service public class ShareGoodsServiceImpl implements ShareGoodsService { - @Resource - private PidUserMapper pidUserMapper; + @Resource private TBPidService tbPidService; @@ -63,8 +73,6 @@ @Resource private UserShareGoodsHistoryMapper userShareGoodsHistoryMapper; - @Resource - private HongBaoManageMapper hongBaoManageMapper; @Resource private UserInfoMapper userinfoMapper; @@ -84,11 +92,21 @@ @Resource private HongBaoManageService hongBaoManageService; - @Resource - private UserShareGoodsRecordService userShareGoodsRecordService; @Resource - private CommonGoodsService commonGoodsService; + private UserTLJBuyHistoryService userTLJBuyHistoryService; + + @Resource + private TLJBuyGoodsService tljBuyGoodsService; + + @Resource + private BusinessEmergent110Service businessEmergent110Service; + + @Resource + private UserTaoLiJinNewbiesService userTaoLiJinNewbiesService; + + @Resource + private ConvertLinkManager convertLinkManager; @Override public void addShareGoodsHistory(UserShareGoodsHistory history) { @@ -98,10 +116,10 @@ UserShareGoodsHistory update = new UserShareGoodsHistory(); update.setId(userShareGoodsHistory.getId()); userShareGoodsHistory.setTkCode(history.getTkCode()); + userShareGoodsHistory.setCreateTime(new Date()); userShareGoodsHistoryMapper.updateByPrimaryKeySelective(userShareGoodsHistory); } else userShareGoodsHistoryMapper.insertSelective(history); - } @Override @@ -134,12 +152,14 @@ // 娌℃湁鑾峰彇鍒拌浆杩囬摼鐨勫晢鍝佽鎯� if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) { - TaoBaoLink taoBaoLink = TaoBaoUtil.getTbLinkForShare(auctionId, tbPid.getPid(), taoBaoUnionConfig); + TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info); // TaoBaoUtil.getTbLinkForShare(auctionId, + // tbPid.getPid(), + // taoBaoUnionConfig); if (taoBaoLink == null) { throw new ShareGoodsException(201, "杞摼澶辫触"); } goods.setCouponLink(taoBaoLink.getCouponLink()); - goods.setAuctionUrl(taoBaoLink.getClickUrl()); + goods.setAuctionUrl(taoBaoLink.getAuctionUrl()); } return addShareGoodsHistory(uid, goods); } @@ -173,10 +193,10 @@ } UserShareGoodsHistory history = new UserShareGoodsHistory(); - history.setTkCode(tbLink.getTaoToken()); + history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); history.setLink(tbLink.getClickUrl()); history.setQuanLink(tbLink.getCouponLink()); - history.setTkCode(tbLink.getTaoToken()); + history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); history.setCreateTime(new Date()); history.setGoodsId(goods.getAuctionId()); @@ -215,7 +235,7 @@ // throw new ShareGoodsException(4, "鐢熸垚浜岀淮鐮佸け璐�"); // } // 鑾峰彇鍒扮敤鎴风殑澶村儚 - UserInfo user = userinfoMapper.selectByPrimaryKey(uid); + UserInfo user = userinfoMapper.selectAvailableByPrimaryKey(uid); InputStream portrait = null; if (!StringUtil.isNullOrEmpty(user.getPortrait())) { try { @@ -271,7 +291,8 @@ } FileUploadResult shareImgResult = COSManager.getInstance().uploadInputStream(shareImgInputStream, - "sharegoods/share_" + uid + "_" + goods.getAuctionId() + "_" + System.currentTimeMillis() + ".png"); + FilePathEnum.shareGoods.getPath() + "share_" + uid + "_" + goods.getAuctionId() + "_" + + System.currentTimeMillis() + ".png"); if (shareImgResult == null || StringUtil.isNullOrEmpty(shareImgResult.getUrl())) { throw new ShareGoodsException(6, "鍒嗕韩鍥剧墖淇濆瓨澶辫触"); @@ -335,16 +356,16 @@ UserShareGoodsHistory history = new UserShareGoodsHistory(); history.setId(userShareGoodsHistory.getId()); - history.setTkCode(tbLink.getTaoToken()); + history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); history.setLink(tbLink.getClickUrl()); history.setQuanLink(tbLink.getCouponLink()); - history.setTkCode(tbLink.getTaoToken()); + history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); userShareGoodsHistoryMapper.updateByPrimaryKeySelective(history); - userShareGoodsHistory.setTkCode(tbLink.getTaoToken()); + userShareGoodsHistory.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); userShareGoodsHistory.setLink(tbLink.getClickUrl()); userShareGoodsHistory.setQuanLink(tbLink.getCouponLink()); - userShareGoodsHistory.setTkCode(tbLink.getTaoToken()); + userShareGoodsHistory.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); } return userShareGoodsHistory; @@ -364,7 +385,335 @@ TaoKeAppInfo info = new TaoKeAppInfo(); if (!StringUtil.isNullOrEmpty(relationId)) { - String pid = Constant.TAOBAO_RELATION_PID_DEFAULT; + String pid = TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT; + String appId = pid.split("_")[2]; + String adzoneId = pid.split("_")[3]; + TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId); + info.setAdzoneId(adzoneId); + info.setAppKey(taoBaoUnionConfig.getAppKey()); + info.setAppSecret(taoBaoUnionConfig.getAppSecret()); + info.setPid(pid); + } else { + TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS); + if (tbPid == null) { + throw new ShareGoodsException(3, "鑾峰彇鎺ㄥ箍浣嶅け璐�"); + } + String appId = tbPid.getPid().split("_")[2]; + TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId); + String adzoneId = tbPid.getPid().split("_")[3]; + info.setAdzoneId(adzoneId); + info.setAppKey(taoBaoUnionConfig.getAppKey()); + info.setAppSecret(taoBaoUnionConfig.getAppSecret()); + info.setPid(tbPid.getPid()); + } + TaoBaoGoodsBrief goods = null; + try { + goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info); + } catch (TaobaoGoodsDownException e) { + throw new ShareGoodsException(4, "鍟嗗搧宸蹭笅鏋�"); + } finally { + } + if (goods == null) { + throw new ShareGoodsException(5, "鑾峰彇鍟嗗搧璇︽儏澶辫触"); + } + + if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) { + TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info); + if (taoBaoLink == null) { + throw new ShareGoodsException(201, "鍟嗗搧杞摼澶辫触"); + } + goods.setCouponLink(taoBaoLink.getCouponLink()); + goods.setAuctionUrl(taoBaoLink.getAuctionUrl()); + } + + if (!StringUtil.isNullOrEmpty(relationId)) { + if (!StringUtil.isNullOrEmpty(goods.getAuctionUrl())) + goods.setAuctionUrl(goods.getAuctionUrl() + "&relationId=" + relationId); + if (!StringUtil.isNullOrEmpty(goods.getCouponLink())) + goods.setCouponLink(goods.getCouponLink() + "&relationId=" + relationId); + } + + // 淇濆瓨鍟嗗搧璇︽儏 + + // 鍒涘缓娣樺彛浠� + TaoBaoLink tbLink = new TaoBaoLink(); + tbLink.setAuctionId(goods.getAuctionId()); + tbLink.setClickUrl(goods.getAuctionUrl()); + tbLink.setCouponLink(goods.getCouponLink()); + + if (!StringUtil.isNullOrEmpty(tbLink.getCouponLink())) {// 閫氳繃绔嬪嵆鎺ㄥ箍鏂瑰紡鑾峰彇娣樺彛浠ゆ垚鍔� + String quanToken = convertLinkManager.createTaoBaoToken(uid, goods.getPictUrl(), goods.getTitle(), tbLink.getCouponLink()); + if (!StringUtil.isNullOrEmpty(quanToken)) { + tbLink.setTaoToken(quanToken); + } + } else if (!StringUtil.isNullOrEmpty(tbLink.getClickUrl())) { + String quanToken = convertLinkManager.createTaoBaoToken(uid,goods.getPictUrl(), goods.getTitle(), tbLink.getClickUrl()); + if (!StringUtil.isNullOrEmpty(quanToken)) { + tbLink.setTaoToken(quanToken); + } + } + + tbLink.setGoods(goods); + + // 瀛樺偍鍒嗕韩鍟嗗搧鐨勪俊鎭紝鐢ㄤ簬鍔犲揩鍒嗕韩缃戦〉鎺ュ彛璇锋眰閫熷害 + if (Constant.IS_OUTNET) + redisManager.saveTaoBaoGoodsBriefTemp(goods); + + LogManager.getLogger(LogType.taobaoTrade) + .info(String.format("娣樺疂鍟嗗搧鍒嗕韩\n UID:%s \n 鍟嗗搧ID:%s \n 鍒搁摼鎺�%s \n鍟嗗搧閾炬帴:%s \n 鍙d护:%s ", uid, auctionId, + tbLink.getCouponLink(), tbLink.getClickUrl(), tbLink.getTaoToken())); + + return tbLink; + } + + @Override + public TaoBaoLink getTaoBaoLinkForBuy(Long uid, Long auctionId, int pidType) throws ShareGoodsException { + + if (uid == null || uid <= 0) { + throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); + } + + if (auctionId == null || auctionId <= 0) { + throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖"); + } + + TBPid tbPid = tbPidService.getTBPid(uid, pidType); + if (tbPid == null) { + throw new ShareGoodsException(3, "鑾峰彇鎺ㄥ箍浣嶅け璐�"); + } + return getTaoBaoLink(uid, auctionId, tbPid.getPid()); + } + + @Override + public TaoBaoLink getTaoBaoLink(Long uid, Long auctionId, String pid) throws ShareGoodsException { + + if (uid == null || uid <= 0) { + throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); + } + + if (auctionId == null || auctionId <= 0) { + throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖"); + } + + if (StringUtil.isNullOrEmpty(pid)) { + throw new ShareGoodsException(3, "鏃犳帹骞夸綅"); + } + + String appId = pid.split("_")[2]; + String adzoneId = pid.split("_")[3]; + TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId); + + TaoKeAppInfo info = new TaoKeAppInfo(); + info.setAdzoneId(adzoneId); + info.setAppKey(taoBaoUnionConfig.getAppKey()); + info.setAppSecret(taoBaoUnionConfig.getAppSecret()); + info.setPid(pid); + TaoBaoGoodsBrief goods = null; + try { + goods = TaoKeApiUtil.searchGoodsDetailForConvert(auctionId, info); + } catch (TaobaoGoodsDownException e) { + throw new ShareGoodsException(4, "鍟嗗搧宸蹭笅鏋�"); + } finally { + + } + if (goods == null) { + throw new ShareGoodsException(5, "鑾峰彇鍟嗗搧璇︽儏澶辫触"); + } + + if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) { + TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info); + if (taoBaoLink == null) { + throw new ShareGoodsException(201, "鍟嗗搧杞摼澶辫触"); + } + goods.setCouponLink(taoBaoLink.getCouponLink()); + goods.setAuctionUrl(taoBaoLink.getAuctionUrl()); + } + + // 鍒涘缓娣樺彛浠� + TaoBaoLink tbLink = new TaoBaoLink(); + tbLink.setAuctionId(goods.getAuctionId()); + tbLink.setClickUrl(goods.getAuctionUrl()); + tbLink.setCouponLink(goods.getCouponLink()); + return tbLink; + } + + @Override + public TaoBaoLink getTaoBaoLinkForBuyWithSpecial(Long uid, String specialId, Long auctionId) + throws ShareGoodsException { + if (uid == null || uid <= 0) { + throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); + } + + if (auctionId == null || auctionId <= 0) { + throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖"); + } + + TaoKeAppInfo app = new TaoKeAppInfo(); + app.setAppKey(TaoBaoConstant.TAOBAO_AUTH_APPKEY); + app.setAppSecret(TaoBaoConstant.TAOBAO_AUTH_APPSECRET); + app.setPid(TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT); + TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(auctionId, app); + if (goods == null) { + throw new ShareGoodsException(1, ""); + } + + TaoBaoLink taoBaoLink = new TaoBaoLink(); + taoBaoLink.setAuctionId(auctionId); + taoBaoLink.setClickUrl(goods.getAuctionUrl()); + taoBaoLink.setCouponLink(goods.getCouponLink()); + if (!StringUtil.isNullOrEmpty(goods.getYsylClickUrl())) + taoBaoLink.setCouponLink(goods.getYsylClickUrl()); + taoBaoLink.setGoods(goods); + return taoBaoLink; + } + + @Override + public UserShareGoodsHistory getShareGoodsHistory(Long uid, Long auctionId) { + return userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, auctionId); + } + + @Override + public TaoBaoLink getTaoBaoLinkForShare(Long uid, Long auctionId, String relationId, String pid) + throws ShareGoodsException { + if (uid == null || uid <= 0) { + throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); + } + + if (auctionId == null || auctionId <= 0) { + throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖"); + } + + TaoKeAppInfo info = new TaoKeAppInfo(); + + if (!StringUtil.isNullOrEmpty(relationId)) { + String appId = pid.split("_")[2]; + String adzoneId = pid.split("_")[3]; + TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId); + info.setAdzoneId(adzoneId); + info.setAppKey(taoBaoUnionConfig.getAppKey()); + info.setAppSecret(taoBaoUnionConfig.getAppSecret()); + info.setPid(pid); + } else { + TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS); + if (tbPid == null) { + throw new ShareGoodsException(3, "鑾峰彇鎺ㄥ箍浣嶅け璐�"); + } + String appId = tbPid.getPid().split("_")[2]; + TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId); + String adzoneId = tbPid.getPid().split("_")[3]; + info.setAdzoneId(adzoneId); + info.setAppKey(taoBaoUnionConfig.getAppKey()); + info.setAppSecret(taoBaoUnionConfig.getAppSecret()); + info.setPid(tbPid.getPid()); + } + TaoBaoGoodsBrief goods = null; + try { + goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info); + } catch (TaobaoGoodsDownException e) { + throw new ShareGoodsException(4, "鍟嗗搧宸蹭笅鏋�"); + } finally { + } + if (goods == null) { + throw new ShareGoodsException(5, "鑾峰彇鍟嗗搧璇︽儏澶辫触"); + } + + if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) { + TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info); + if (taoBaoLink == null) { + throw new ShareGoodsException(201, "鍟嗗搧杞摼澶辫触"); + } + goods.setCouponLink(taoBaoLink.getCouponLink()); + goods.setAuctionUrl(taoBaoLink.getAuctionUrl()); + } + + if (!StringUtil.isNullOrEmpty(relationId)) { + if (!StringUtil.isNullOrEmpty(goods.getAuctionUrl())) + goods.setAuctionUrl(goods.getAuctionUrl() + "&relationId=" + relationId); + if (!StringUtil.isNullOrEmpty(goods.getCouponLink())) + goods.setCouponLink(goods.getCouponLink() + "&relationId=" + relationId); + } + + // 淇濆瓨鍟嗗搧璇︽儏 + + // 鍒涘缓娣樺彛浠� + TaoBaoLink tbLink = new TaoBaoLink(); + tbLink.setAuctionId(goods.getAuctionId()); + tbLink.setClickUrl(goods.getAuctionUrl()); + tbLink.setCouponLink(goods.getCouponLink()); + if (!StringUtil.isNullOrEmpty(goods.getYsylClickUrl())) + tbLink.setCouponLink(goods.getYsylClickUrl()); + + if (!StringUtil.isNullOrEmpty(tbLink.getCouponLink())) {// 閫氳繃绔嬪嵆鎺ㄥ箍鏂瑰紡鑾峰彇娣樺彛浠ゆ垚鍔� + String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getCouponLink()); + if (!StringUtil.isNullOrEmpty(quanToken)) { + tbLink.setTaoToken(quanToken); + } + } else if (!StringUtil.isNullOrEmpty(tbLink.getClickUrl())) { + String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getClickUrl()); + if (!StringUtil.isNullOrEmpty(quanToken)) { + tbLink.setTaoToken(quanToken); + } + } + + tbLink.setGoods(goods); + + // 瀛樺偍鍒嗕韩鍟嗗搧鐨勪俊鎭紝鐢ㄤ簬鍔犲揩鍒嗕韩缃戦〉鎺ュ彛璇锋眰閫熷害 + if (Constant.IS_OUTNET) + redisManager.saveTaoBaoGoodsBriefTemp(goods); + + return tbLink; + } + + @Override + public TaoBaoLink getTaoLiJinLinkForBuy(Long uid, String specialId, Long auctionId, String pid) + throws ShareGoodsException { + if (uid == null || uid <= 0) + throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); + + if (auctionId == null || auctionId <= 0) + throw new ShareGoodsException(1, "鍟嗗搧ID涓嶈兘涓虹┖"); + + TaoBaoGoodsBrief goods = null; + try { + goods = TaoKeApiUtil.searchGoodsDetail(auctionId); + } catch (TaobaoGoodsDownException e) { + throw new ShareGoodsException(1, "璇ュ晢鍝佸凡涓嬫灦"); + } + + if (goods == null) + throw new ShareGoodsException(1, "璇ュ晢鍝佸凡涓嬫灦"); + + String taoLiJinLink = null; + try { + goods.setAuctionId(auctionId); + taoLiJinLink = userTaoLiJinNewbiesService.createTaoLiJinForBuy(goods, uid); + } catch (UserTaoLiJinNewbiesException e1) { + throw new ShareGoodsException(e1.getCode(), e1.getMsg()); + } + + TaoBaoLink taoBaoLink = new TaoBaoLink(); + taoBaoLink.setAuctionId(auctionId); + taoBaoLink.setClickUrl(goods.getAuctionUrl()); + taoBaoLink.setCouponLink(taoLiJinLink); + taoBaoLink.setGoods(goods); + return taoBaoLink; + } + + @Override + public TaoBaoLink getTaoLiJinLinkForShare(Long uid, Long auctionId, String relationId) throws ShareGoodsException { + + if (uid == null || uid <= 0) { + throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); + } + + if (auctionId == null || auctionId <= 0) { + throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖"); + } + + TaoKeAppInfo info = new TaoKeAppInfo(); + + if (!StringUtil.isNullOrEmpty(relationId)) { + String pid = TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT; String appId = pid.split("_")[2]; String adzoneId = pid.split("_")[3]; TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId); @@ -399,12 +748,12 @@ if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) { TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService .getConfigByAppIdCache(info.getPid().split("_")[2]); - TaoBaoLink taoBaoLink = TaoBaoUtil.getTbLinkForShare(auctionId, info.getPid(), taoBaoUnionConfig); + TaoBaoGoodsBrief taoBaoLink = TaoKeApiUtil.specialConvertCoupon(auctionId, info); if (taoBaoLink == null) { throw new ShareGoodsException(201, "鍟嗗搧杞摼澶辫触"); } goods.setCouponLink(taoBaoLink.getCouponLink()); - goods.setAuctionUrl(taoBaoLink.getClickUrl()); + goods.setAuctionUrl(taoBaoLink.getAuctionUrl()); } if (!StringUtil.isNullOrEmpty(relationId)) { @@ -414,26 +763,11 @@ goods.setCouponLink(goods.getCouponLink() + "&relationId=" + relationId); } - // 淇濆瓨鍟嗗搧璇︽儏 - // 鍒涘缓娣樺彛浠� TaoBaoLink tbLink = new TaoBaoLink(); tbLink.setAuctionId(goods.getAuctionId()); tbLink.setClickUrl(goods.getAuctionUrl()); tbLink.setCouponLink(goods.getCouponLink()); - - if (!StringUtil.isNullOrEmpty(tbLink.getCouponLink())) {// 閫氳繃绔嬪嵆鎺ㄥ箍鏂瑰紡鑾峰彇娣樺彛浠ゆ垚鍔� - String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getCouponLink()); - if (!StringUtil.isNullOrEmpty(quanToken)) { - tbLink.setTaoToken(quanToken); - } - } else if (!StringUtil.isNullOrEmpty(tbLink.getClickUrl())) { - String quanToken = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), tbLink.getClickUrl()); - if (!StringUtil.isNullOrEmpty(quanToken)) { - tbLink.setTaoToken(quanToken); - } - } - tbLink.setGoods(goods); // 瀛樺偍鍒嗕韩鍟嗗搧鐨勪俊鎭紝鐢ㄤ簬鍔犲揩鍒嗕韩缃戦〉鎺ュ彛璇锋眰閫熷害 @@ -444,8 +778,8 @@ } @Override - public TaoBaoLink getTaoBaoLinkForBuy(Long uid, Long auctionId, int pidType) throws ShareGoodsException { - + public TaoBaoLink getTaoLiJinLinkForBuyWithOutFanLi(Long uid, Long auctionId, TaoKeAppInfo app) + throws ShareGoodsException, TaoLiJinCreateException { if (uid == null || uid <= 0) { throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); } @@ -454,76 +788,60 @@ throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖"); } - TBPid tbPid = tbPidService.getTBPid(uid, pidType); - if (tbPid == null) { - throw new ShareGoodsException(3, "鑾峰彇鎺ㄥ箍浣嶅け璐�"); - } - return getTaoBaoLink(uid, auctionId, tbPid.getPid()); - } - - public TaoBaoLink getTaoBaoLink(Long uid, Long auctionId, String pid) throws ShareGoodsException { - - if (uid == null || uid <= 0) { - throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); + boolean canBuy = userTLJBuyHistoryService.canBuy(uid, auctionId); + if (!canBuy) { + throw new ShareGoodsException(3, "绔嬪噺绾㈠寘宸叉姠鍏夛紝璇风◢鍚庡啀璇�"); } - if (auctionId == null || auctionId <= 0) { - throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖"); - } - - if (StringUtil.isNullOrEmpty(pid)) { - throw new ShareGoodsException(3, "鏃犳帹骞夸綅"); - } - - String appId = pid.split("_")[2]; - String adzoneId = pid.split("_")[3]; - TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId); - - TaoKeAppInfo info = new TaoKeAppInfo(); - info.setAdzoneId(adzoneId); - info.setAppKey(taoBaoUnionConfig.getAppKey()); - info.setAppSecret(taoBaoUnionConfig.getAppSecret()); - info.setPid(pid); + long currentTime = System.currentTimeMillis(); + Date sendEndTime = new Date(TimeUtil.convertToTimeTemp( + TimeUtil.getGernalTime(currentTime + 1000 * 60 * 60 * 24L, "yyyy-MM-dd"), "yyyy-MM-dd")); TaoBaoGoodsBrief goods = null; try { - goods = TaoKeApiUtil.searchGoodsDetailForConvert(auctionId, info); + goods = TaoKeApiUtil.searchGoodsDetail(auctionId); } catch (TaobaoGoodsDownException e) { throw new ShareGoodsException(4, "鍟嗗搧宸蹭笅鏋�"); - } finally { - } - if (goods == null) { - throw new ShareGoodsException(5, "鑾峰彇鍟嗗搧璇︽儏澶辫触"); } - if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) { - TaoBaoLink taoBaoLink = TaoBaoUtil.getTbLinkForShare(auctionId, pid, taoBaoUnionConfig); - if (taoBaoLink == null) { - throw new ShareGoodsException(201, "鍟嗗搧杞摼澶辫触"); + BigDecimal perface = TaoBaoUtil.getGoodsHongBaoMoney(goods, new BigDecimal(70)); + TaoLiJinDTO taoLiJinDTO = null; + try { + taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, "鑷喘绔嬪噺", perface, 1, + new Date(currentTime - 1000 * 60 * 10L), sendEndTime, new Date(currentTime - 1000 * 60 * 10L), + sendEndTime, app); + } catch (TaoLiJinCreateException e1) { + if (e1.getCode() == TaoLiJinCreateException.CODE_TLJ_NO_MONEY) {// 璧勯噾涓嶈冻 + TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppKeyCache(app.getAppKey()); + businessEmergent110Service.tljNoMoney(config.getAccount()); + } else if (e1.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) {// 鍟嗗搧涓嶅厑璁稿垱寤烘窐绀奸噾 + tljBuyGoodsService.removeGoods(auctionId); } - goods.setCouponLink(taoBaoLink.getCouponLink()); - goods.setAuctionUrl(taoBaoLink.getClickUrl()); + LogHelper.errorDetailInfo(e1, e1.getMessage(), null); + } catch (TaoKeApiException e) { + LogHelper.errorDetailInfo(e, e.getMessage(), null); + throw new ShareGoodsException(5, "鐢熸垚鎺ㄥ箍閾炬帴澶辫触"); } - // 鍒涘缓娣樺彛浠� - TaoBaoLink tbLink = new TaoBaoLink(); - tbLink.setAuctionId(goods.getAuctionId()); - tbLink.setClickUrl(goods.getAuctionUrl()); - tbLink.setCouponLink(goods.getCouponLink()); - return tbLink; + if (taoLiJinDTO == null) + throw new ShareGoodsException(5, "鐢熸垚鎺ㄥ箍閾炬帴澶辫触"); + + // 鍑忓幓鍓╀綑涓暟(闅忔満鍑忓幓8鍒�10涓�) + tljBuyGoodsService.subHongBaoLeftCount(auctionId, TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"), + 8 + (int) (3 * Math.random())); + + // 鎻掑叆璁板綍 + try { + userTLJBuyHistoryService.addHistory(new UserTLJBuyHistory(null, uid, auctionId, + TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"), taoLiJinDTO.getRightsId(), new Date())); + } catch (Exception e) { + LogHelper.errorDetailInfo(e); + } + + TaoBaoLink taoBaoLink = new TaoBaoLink(); + taoBaoLink.setAuctionId(auctionId); + taoBaoLink.setClickUrl(goods.getAuctionUrl()); + taoBaoLink.setCouponLink(taoLiJinDTO.getSendUrl()); + taoBaoLink.setGoods(goods); + return taoBaoLink; } - - @Override - public TaoBaoLink getTaoBaoLinkForBuyWithSpecial(Long uid, String specialId, Long auctionId) - throws ShareGoodsException { - if (uid == null || uid <= 0) { - throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); - } - - if (auctionId == null || auctionId <= 0) { - throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖"); - } - - return getTaoBaoLink(uid, auctionId, Constant.TAOBAO_SPECIAL_PID_DEFAULT); - } - } -- Gitblit v1.8.0