From c9cbad5f5d18c6b2ac5a063e41007933d7028329 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 07 七月 2020 15:24:17 +0800 Subject: [PATCH] 返利配置文件加入系统区分 --- fanli/src/main/java/com/yeshi/fanli/service/impl/goods/ShareGoodsServiceImpl.java | 775 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 387 insertions(+), 388 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 1ec2af6..1bf96a6 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 @@ -73,455 +73,454 @@ @Service public class ShareGoodsServiceImpl implements ShareGoodsService { - @Resource - private TBPidService tbPidService; + @Resource + private TBPidService tbPidService; - @Resource - private UserShareGoodsHistoryMapper userShareGoodsHistoryMapper; + @Resource + private UserShareGoodsHistoryMapper userShareGoodsHistoryMapper; - @Resource - private UserInfoService userInfoService; + @Resource + private UserInfoService userInfoService; - @Resource - private RedisManager redisManager; + @Resource + private RedisManager redisManager; - @Resource - private ConfigService configService; + @Resource + private ConfigService configService; - @Resource - private TaoBaoUnionConfigService taoBaoUnionConfigService; + @Resource + private TaoBaoUnionConfigService taoBaoUnionConfigService; - @Resource - private UserAccountService userAccountService; + @Resource + private UserAccountService userAccountService; - @Resource - private HongBaoManageService hongBaoManageService; + @Resource + private HongBaoManageService hongBaoManageService; - @Resource - private UserTLJBuyHistoryService userTLJBuyHistoryService; + @Resource + private UserTLJBuyHistoryService userTLJBuyHistoryService; - @Resource - private TLJBuyGoodsService tljBuyGoodsService; + @Resource + private TLJBuyGoodsService tljBuyGoodsService; - @Resource - private BusinessEmergent110Service businessEmergent110Service; + @Resource + private BusinessEmergent110Service businessEmergent110Service; - @Resource - private UserTaoLiJinNewbiesService userTaoLiJinNewbiesService; + @Resource + private UserTaoLiJinNewbiesService userTaoLiJinNewbiesService; - @Resource - private ConvertLinkManager convertLinkManager; + @Resource + private ConvertLinkManager convertLinkManager; - @Resource - private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil; + @Resource + private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil; - @Resource - private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service; + @Resource + private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service; - @Override - public void addShareGoodsHistory(UserShareGoodsHistory history) { - UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper - .selectByUidAndAuctionId(history.getUser().getId(), history.getGoodsId()); - if (userShareGoodsHistory != null && !StringUtil.isNullOrEmpty(history.getTkCode())) { - UserShareGoodsHistory update = new UserShareGoodsHistory(); - update.setId(userShareGoodsHistory.getId()); - userShareGoodsHistory.setTkCode(history.getTkCode()); - userShareGoodsHistory.setCreateTime(new Date()); - userShareGoodsHistoryMapper.updateByPrimaryKeySelective(userShareGoodsHistory); - } else - userShareGoodsHistoryMapper.insertSelective(history); - } + @Override + public void addShareGoodsHistory(UserShareGoodsHistory history) { + UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper + .selectByUidAndAuctionId(history.getUser().getId(), history.getGoodsId()); + if (userShareGoodsHistory != null && !StringUtil.isNullOrEmpty(history.getTkCode())) { + UserShareGoodsHistory update = new UserShareGoodsHistory(); + update.setId(userShareGoodsHistory.getId()); + userShareGoodsHistory.setTkCode(history.getTkCode()); + userShareGoodsHistory.setCreateTime(new Date()); + userShareGoodsHistoryMapper.updateByPrimaryKeySelective(userShareGoodsHistory); + } else + userShareGoodsHistoryMapper.insertSelective(history); + } - @Override - public UserShareGoodsHistory addShareGoodsHistory(Long uid, Long auctionId) throws ShareGoodsException { - TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS); - if (tbPid == null) { - throw new ShareGoodsException(1, "鑾峰彇PID澶辫触"); - } - String appId = tbPid.getPid().split("_")[2]; - String adzoneId = tbPid.getPid().split("_")[3]; - TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId); + @Override + public UserShareGoodsHistory addShareGoodsHistory(Long uid, Long auctionId) throws ShareGoodsException { + TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS); + if (tbPid == null) { + throw new ShareGoodsException(1, "鑾峰彇PID澶辫触"); + } + String appId = tbPid.getPid().split("_")[2]; + String adzoneId = tbPid.getPid().split("_")[3]; + TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId); - TaoKeAppInfo info = new TaoKeAppInfo(); - info.setAdzoneId(adzoneId); - info.setAppKey(taoBaoUnionConfig.getAppKey()); - info.setAppSecret(taoBaoUnionConfig.getAppSecret()); - info.setPid(tbPid.getPid()); - TaoBaoGoodsBrief goods = null; - long startTime = System.currentTimeMillis(); - try { - goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info); - } catch (TaobaoGoodsDownException e) { - throw new ShareGoodsException(3, "鍟嗗搧宸蹭笅鏋�"); - } finally { - LogHelper.test(auctionId + "-鑾峰彇鍟嗗搧璇︽儏鑰楁椂涓�:" + (System.currentTimeMillis() - startTime)); - } - if (goods == null) { - throw new ShareGoodsException(3, "鍟嗗搧宸蹭笅鏋�"); - } + TaoKeAppInfo info = new TaoKeAppInfo(); + info.setAdzoneId(adzoneId); + info.setAppKey(taoBaoUnionConfig.getAppKey()); + info.setAppSecret(taoBaoUnionConfig.getAppSecret()); + info.setPid(tbPid.getPid()); + TaoBaoGoodsBrief goods = null; + long startTime = System.currentTimeMillis(); + try { + goods = TaoKeApiUtil.searchGoodsDetail(auctionId, info); + } catch (TaobaoGoodsDownException e) { + throw new ShareGoodsException(3, "鍟嗗搧宸蹭笅鏋�"); + } finally { + LogHelper.test(auctionId + "-鑾峰彇鍟嗗搧璇︽儏鑰楁椂涓�:" + (System.currentTimeMillis() - startTime)); + } + if (goods == null) { + throw new ShareGoodsException(3, "鍟嗗搧宸蹭笅鏋�"); + } - // 娌℃湁鑾峰彇鍒拌浆杩囬摼鐨勫晢鍝佽鎯� - if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) { - 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.getAuctionUrl()); - } - return addShareGoodsHistory(uid, goods); - } + // 娌℃湁鑾峰彇鍒拌浆杩囬摼鐨勫晢鍝佽鎯� + if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && !goods.getAuctionUrl().contains("s.click.taobao.com")) { + 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.getAuctionUrl()); + } + return addShareGoodsHistory(uid, goods); + } - @Override - public UserShareGoodsHistory addShareGoodsHistory(Long uid, TaoBaoGoodsBrief goods) throws ShareGoodsException { - if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && StringUtil.isNullOrEmpty(goods.getAuctionUrl())) { - throw new ShareGoodsException(10, "杞摼澶辫触"); - } + @Override + public UserShareGoodsHistory addShareGoodsHistory(Long uid, TaoBaoGoodsBrief goods) throws ShareGoodsException { + if (StringUtil.isNullOrEmpty(goods.getCouponLink()) && StringUtil.isNullOrEmpty(goods.getAuctionUrl())) { + throw new ShareGoodsException(10, "杞摼澶辫触"); + } - BigDecimal rate = hongBaoManageService.getShareRate(); + SystemEnum system = userInfoService.getUserSystem(uid); + BigDecimal rate = hongBaoManageService.getShareRate(system); - // 鍒涘缓娣樺彛浠� - TaoBaoLink tbLink = new TaoBaoLink(); // TaoBaoUtil.getTbLinkForShare(goods.getAuctionId(), - // tbPid.getPid(), - // config.get(0)); - tbLink.setAuctionId(goods.getAuctionId()); - tbLink.setClickUrl(goods.getAuctionUrl()); - tbLink.setCouponLink(goods.getCouponLink()); + // 鍒涘缓娣樺彛浠� + TaoBaoLink tbLink = new TaoBaoLink(); // TaoBaoUtil.getTbLinkForShare(goods.getAuctionId(), + // tbPid.getPid(), + // config.get(0)); + 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); - } - } + 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); + } + } - UserShareGoodsHistory history = new UserShareGoodsHistory(); - history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); - history.setLink(tbLink.getClickUrl()); - history.setQuanLink(tbLink.getCouponLink()); - history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); + UserShareGoodsHistory history = new UserShareGoodsHistory(); + history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); + history.setLink(tbLink.getClickUrl()); + history.setQuanLink(tbLink.getCouponLink()); + history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); - history.setCreateTime(new Date()); - history.setGoodsId(goods.getAuctionId()); - history.setGoodsType(UserShareGoodsHistory.TYPE_TAOBAO); - history.setHongbao(TaoBaoUtil.getShareGoodsHongBaoInfo(goods, rate)); - List<String> imgList = goods.getImgList(); - if (imgList == null) { - imgList = new ArrayList<>(); - } - history.setPictures(JsonUtil.getGson().toJson(imgList)); - history.setUser(new UserInfo(uid)); - history.setPostPicture(goods.getPictUrl()); - // 鐢熸垚浜岀淮鐮佷俊鎭� - // 鍖呭惈鐢ㄦ埛ID涓庡晢鍝両D - // 鏂扮増鍟嗗搧鍒嗕韩 + history.setCreateTime(new Date()); + history.setGoodsId(goods.getAuctionId()); + history.setGoodsType(UserShareGoodsHistory.TYPE_TAOBAO); + history.setHongbao(TaoBaoUtil.getShareGoodsHongBaoInfo(goods, rate)); + List<String> imgList = goods.getImgList(); + if (imgList == null) { + imgList = new ArrayList<>(); + } + history.setPictures(JsonUtil.getGson().toJson(imgList)); + history.setUser(new UserInfo(uid)); + history.setPostPicture(goods.getPictUrl()); + // 鐢熸垚浜岀淮鐮佷俊鎭� + // 鍖呭惈鐢ㄦ埛ID涓庡晢鍝両D + // 鏂扮増鍟嗗搧鍒嗕韩 - SystemEnum system= userInfoService.getUserSystem(uid); + String url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(system), + Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), + goods.getAuctionId() + ""); - String url = String.format("http://%s%s?uid=%s&id=%s", configService.getH5Host(system), - Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), - goods.getAuctionId() + ""); + String shortLink = HttpUtil.getShortLink(url); + if (!StringUtil.isNullOrEmpty(shortLink)) { + url = shortLink; + } + String destPath = FileUtil.getCacheDir() + "/ercode_" + uid + "_" + goods.getAuctionId() + ".jpg"; + String shareImgPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + goods.getAuctionId() + ".png"; + InputStream erCodeInputStream = null; - String shortLink = HttpUtil.getShortLink(url); - if (!StringUtil.isNullOrEmpty(shortLink)) { - url = shortLink; - } - String destPath = FileUtil.getCacheDir() + "/ercode_" + uid + "_" + goods.getAuctionId() + ".jpg"; - String shareImgPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + goods.getAuctionId() + ".png"; - InputStream erCodeInputStream = null; + try { + try { + erCodeInputStream = QRCodeUtil.getInstance(500).encode(url); + } catch (Exception e) { + e.printStackTrace(); + } - try { - try { - erCodeInputStream = QRCodeUtil.getInstance(500).encode(url); - } catch (Exception e) { - e.printStackTrace(); - } + // if (!new File(destPath).exists()) { + // throw new ShareGoodsException(4, "鐢熸垚浜岀淮鐮佸け璐�"); + // } + // 鑾峰彇鍒扮敤鎴风殑澶村儚 + UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid); + InputStream portrait = null; + if (!StringUtil.isNullOrEmpty(user.getPortrait())) { + try { + portrait = HttpUtil.downLoadImg(user.getPortrait()); + } catch (HttpException e) { + String portraitUrl = userAccountService.repairPortrait(uid); + if (StringUtil.isNullOrEmpty(portraitUrl)) + throw new ShareGoodsException(11, "鑾峰彇澶村儚鍑洪敊"); + else { + // 鍐嶆鑾峰彇澶村儚 + try { + portrait = HttpUtil.downLoadImg(portraitUrl); + } catch (HttpException e1) { + throw new ShareGoodsException(11, "鑾峰彇澶村儚鍑洪敊"); + } + } + } + } - // if (!new File(destPath).exists()) { - // throw new ShareGoodsException(4, "鐢熸垚浜岀淮鐮佸け璐�"); - // } - // 鑾峰彇鍒扮敤鎴风殑澶村儚 - UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid); - InputStream portrait = null; - if (!StringUtil.isNullOrEmpty(user.getPortrait())) { - try { - portrait = HttpUtil.downLoadImg(user.getPortrait()); - } catch (HttpException e) { - String portraitUrl = userAccountService.repairPortrait(uid); - if (StringUtil.isNullOrEmpty(portraitUrl)) - throw new ShareGoodsException(11, "鑾峰彇澶村儚鍑洪敊"); - else { - // 鍐嶆鑾峰彇澶村儚 - try { - portrait = HttpUtil.downLoadImg(portraitUrl); - } catch (HttpException e1) { - throw new ShareGoodsException(11, "鑾峰彇澶村儚鍑洪敊"); - } - } - } - } + InputStream shareImgInputStream = null; - InputStream shareImgInputStream = null; + try { + // 娴疯崏琛楃殑鍒嗕韩浜岀淮鐮佷笉涓�鏍� + if (Constant.systemCommonConfig.getProjectChineseName().contains("娴疯崏琛�")) { + try { + shareImgInputStream = ImageUtil.drawGoodsShareImgHCJ(new FileInputStream(new File(destPath)), + portrait, goods); + } catch (Exception e) { + try { + LogHelper.errorDetailInfo(e); + } catch (Exception e1) { + e1.printStackTrace(); + } + throw new ShareGoodsException(5, "鍒嗕韩鍥剧粯鍒跺け璐�"); + } + } else { + shareImgInputStream = ImageUtil.drawGoodsShareImg(erCodeInputStream, portrait, goods); + } + } catch (Exception e) { + try { + LogHelper.errorDetailInfo(e, "", "鍒嗕韩鍥炬棤娉曟壘鍒�"); + } catch (Exception e1) { + e1.printStackTrace(); + } + } - try { - // 娴疯崏琛楃殑鍒嗕韩浜岀淮鐮佷笉涓�鏍� - if (Constant.systemCommonConfig.getProjectChineseName().contains("娴疯崏琛�")) { - try { - shareImgInputStream = ImageUtil.drawGoodsShareImgHCJ(new FileInputStream(new File(destPath)), - portrait, goods); - } catch (Exception e) { - try { - LogHelper.errorDetailInfo(e); - } catch (Exception e1) { - e1.printStackTrace(); - } - throw new ShareGoodsException(5, "鍒嗕韩鍥剧粯鍒跺け璐�"); - } - } else { - shareImgInputStream = ImageUtil.drawGoodsShareImg(erCodeInputStream, portrait, goods); - } - } catch (Exception e) { - try { - LogHelper.errorDetailInfo(e, "", "鍒嗕韩鍥炬棤娉曟壘鍒�"); - } catch (Exception e1) { - e1.printStackTrace(); - } - } + try { + if (shareImgInputStream != null && shareImgInputStream.available() <= 0) { + throw new ShareGoodsException(5, "鐢熸垚鍒嗕韩鍥惧け璐�"); + } + } catch (IOException e) { + throw new ShareGoodsException(5, "璇诲彇鍒嗕韩鍥惧け璐�"); + } - try { - if (shareImgInputStream != null && shareImgInputStream.available() <= 0) { - throw new ShareGoodsException(5, "鐢熸垚鍒嗕韩鍥惧け璐�"); - } - } catch (IOException e) { - throw new ShareGoodsException(5, "璇诲彇鍒嗕韩鍥惧け璐�"); - } + FileUploadResult shareImgResult = COSManager.getInstance().uploadInputStream(shareImgInputStream, + FilePathEnum.shareGoods.getPath() + "share_" + uid + "_" + goods.getAuctionId() + "_" + + System.currentTimeMillis() + ".png"); - FileUploadResult shareImgResult = COSManager.getInstance().uploadInputStream(shareImgInputStream, - FilePathEnum.shareGoods.getPath() + "share_" + uid + "_" + goods.getAuctionId() + "_" - + System.currentTimeMillis() + ".png"); + if (shareImgResult == null || StringUtil.isNullOrEmpty(shareImgResult.getUrl())) { + throw new ShareGoodsException(6, "鍒嗕韩鍥剧墖淇濆瓨澶辫触"); + } - if (shareImgResult == null || StringUtil.isNullOrEmpty(shareImgResult.getUrl())) { - throw new ShareGoodsException(6, "鍒嗕韩鍥剧墖淇濆瓨澶辫触"); - } + history.setShareImg(shareImgResult.getUrl()); + history.setShareImgMD5(shareImgResult.getMd5()); - history.setShareImg(shareImgResult.getUrl()); - history.setShareImgMD5(shareImgResult.getMd5()); + // 鏌ヨ涔嬪墠鏄惁瀛樺湪锛屽瓨鍦ㄥ氨鏇挎崲鎺� - // 鏌ヨ涔嬪墠鏄惁瀛樺湪锛屽瓨鍦ㄥ氨鏇挎崲鎺� + UserShareGoodsHistory old = userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, history.getGoodsId()); + if (old != null) { + history.setId(old.getId()); + userShareGoodsHistoryMapper.updateByPrimaryKeySelective(history); + // 鍒犻櫎鍘熸潵鐨勫浘鐗� + COSManager.getInstance().deleteFile(old.getShareImg()); + } else { + userShareGoodsHistoryMapper.insertSelective(history); + } + history.setLink(url); + return history; + } finally { + if (new File(destPath).exists()) { + new File(destPath).delete(); + } + if (new File(shareImgPath).exists()) { + new File(shareImgPath).delete(); + } + } + } - UserShareGoodsHistory old = userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, history.getGoodsId()); - if (old != null) { - history.setId(old.getId()); - userShareGoodsHistoryMapper.updateByPrimaryKeySelective(history); - // 鍒犻櫎鍘熸潵鐨勫浘鐗� - COSManager.getInstance().deleteFile(old.getShareImg()); - } else { - userShareGoodsHistoryMapper.insertSelective(history); - } - history.setLink(url); - return history; - } finally { - if (new File(destPath).exists()) { - new File(destPath).delete(); - } - if (new File(shareImgPath).exists()) { - new File(shareImgPath).delete(); - } - } - } + @Override + public UserShareGoodsHistory getShareGoodsHistoryDetail(Long uid, Long auctionId) throws ShareGoodsException { + UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, + auctionId); + if (userShareGoodsHistory == null) + throw new ShareGoodsException(10, "鍒嗕韩涓嶅瓨鍦�"); - @Override - public UserShareGoodsHistory getShareGoodsHistoryDetail(Long uid, Long auctionId) throws ShareGoodsException { - UserShareGoodsHistory userShareGoodsHistory = userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, - auctionId); - if (userShareGoodsHistory == null) - throw new ShareGoodsException(10, "鍒嗕韩涓嶅瓨鍦�"); + // 娣樺彛浠や笉瀛樺湪 + if (StringUtil.isNullOrEmpty(userShareGoodsHistory.getTkCode())) { + TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS); + if (tbPid == null) + throw new ShareGoodsException(1, "鑾峰彇PID澶辫触"); - // 娣樺彛浠や笉瀛樺湪 - if (StringUtil.isNullOrEmpty(userShareGoodsHistory.getTkCode())) { - TBPid tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_SHARE_GOODS); - if (tbPid == null) - throw new ShareGoodsException(1, "鑾峰彇PID澶辫触"); + List<TaoBaoUnionConfig> config = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_SHARE_GOODS); + // 鍒涘缓娣樺彛浠� + TaoBaoLink tbLink = TaoBaoUtil.getTbLink(auctionId, tbPid.getPid(), config.get(0)); + if (tbLink == null) { + TaoBaoGoodsBrief goods = null; + try { + goods = TaoKeApiUtil.searchGoodsDetail(auctionId); + } catch (TaobaoGoodsDownException e) { + throw new ShareGoodsException(4, "鍟嗗搧宸蹭笅鏋�"); + } + tbLink = TaoBaoUtil.getTbLinkWithCoupon(goods.getPictUrl(), goods.getTitle(), + goods.getCouponActivityId(), auctionId, tbPid.getPid()); + if (tbLink == null || StringUtil.isNullOrEmpty(tbLink.getTaoToken())) + throw new ShareGoodsException(2, "鑾峰彇娣樺彛浠ゅけ璐ワ紝璇风◢鍚庨噸璇�"); + } + // 鏇存柊娣樺彛浠� - List<TaoBaoUnionConfig> config = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_SHARE_GOODS); - // 鍒涘缓娣樺彛浠� - TaoBaoLink tbLink = TaoBaoUtil.getTbLink(auctionId, tbPid.getPid(), config.get(0)); - if (tbLink == null) { - TaoBaoGoodsBrief goods = null; - try { - goods = TaoKeApiUtil.searchGoodsDetail(auctionId); - } catch (TaobaoGoodsDownException e) { - throw new ShareGoodsException(4, "鍟嗗搧宸蹭笅鏋�"); - } - tbLink = TaoBaoUtil.getTbLinkWithCoupon(goods.getPictUrl(), goods.getTitle(), - goods.getCouponActivityId(), auctionId, tbPid.getPid()); - if (tbLink == null || StringUtil.isNullOrEmpty(tbLink.getTaoToken())) - throw new ShareGoodsException(2, "鑾峰彇娣樺彛浠ゅけ璐ワ紝璇风◢鍚庨噸璇�"); - } - // 鏇存柊娣樺彛浠� + UserShareGoodsHistory history = new UserShareGoodsHistory(); + history.setId(userShareGoodsHistory.getId()); + history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); + history.setLink(tbLink.getClickUrl()); + history.setQuanLink(tbLink.getCouponLink()); + history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); + userShareGoodsHistoryMapper.updateByPrimaryKeySelective(history); - UserShareGoodsHistory history = new UserShareGoodsHistory(); - history.setId(userShareGoodsHistory.getId()); - history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); - history.setLink(tbLink.getClickUrl()); - history.setQuanLink(tbLink.getCouponLink()); - history.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); - userShareGoodsHistoryMapper.updateByPrimaryKeySelective(history); + userShareGoodsHistory.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); + userShareGoodsHistory.setLink(tbLink.getClickUrl()); + userShareGoodsHistory.setQuanLink(tbLink.getCouponLink()); + userShareGoodsHistory.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); + } - userShareGoodsHistory.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); - userShareGoodsHistory.setLink(tbLink.getClickUrl()); - userShareGoodsHistory.setQuanLink(tbLink.getCouponLink()); - userShareGoodsHistory.setTkCode(TaoBaoUtil.filterTaoToken(tbLink.getTaoToken())); - } + return userShareGoodsHistory; + } - return userShareGoodsHistory; - } + @Override + public String createTaoBaoToken(Long uid, TaoBaoGoodsBrief goods) { + String quanToken = ""; + if (!StringUtil.isNullOrEmpty(goods.getCouponLink())) {// 閫氳繃绔嬪嵆鎺ㄥ箍鏂瑰紡鑾峰彇娣樺彛浠ゆ垚鍔� + quanToken = convertLinkManager.createTaoBaoToken(uid, goods.getPictUrl(), goods.getTitle(), + goods.getCouponLink()); + } else if (!StringUtil.isNullOrEmpty(goods.getAuctionUrl())) { + quanToken = convertLinkManager.createTaoBaoToken(uid, goods.getPictUrl(), goods.getTitle(), + goods.getAuctionUrl()); + } + return quanToken; + } - @Override - public String createTaoBaoToken(Long uid, TaoBaoGoodsBrief goods) { - String quanToken = ""; - if (!StringUtil.isNullOrEmpty(goods.getCouponLink())) {// 閫氳繃绔嬪嵆鎺ㄥ箍鏂瑰紡鑾峰彇娣樺彛浠ゆ垚鍔� - quanToken = convertLinkManager.createTaoBaoToken(uid, goods.getPictUrl(), goods.getTitle(), - goods.getCouponLink()); - } else if (!StringUtil.isNullOrEmpty(goods.getAuctionUrl())) { - quanToken = convertLinkManager.createTaoBaoToken(uid, goods.getPictUrl(), goods.getTitle(), - goods.getAuctionUrl()); - } - return quanToken; - } + @Override + public TaoBaoLink getTaoBaoLink(Long uid, Long auctionId, String pid) throws ShareGoodsException { - @Override - public TaoBaoLink getTaoBaoLink(Long uid, Long auctionId, String pid) throws ShareGoodsException { + if (uid == null || uid <= 0) { + throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); + } - if (uid == null || uid <= 0) { - throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); - } + if (auctionId == null || auctionId <= 0) { + throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖"); + } - if (auctionId == null || auctionId <= 0) { - throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖"); - } + if (StringUtil.isNullOrEmpty(pid)) { + throw new ShareGoodsException(3, "鏃犳帹骞夸綅"); + } - if (StringUtil.isNullOrEmpty(pid)) { - throw new ShareGoodsException(3, "鏃犳帹骞夸綅"); - } + String appId = pid.split("_")[2]; + String adzoneId = pid.split("_")[3]; + TaoBaoUnionConfig taoBaoUnionConfig = taoBaoUnionConfigService.getConfigByAppIdCache(appId); - 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 { - 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 (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(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; + } - // 鍒涘缓娣樺彛浠� - TaoBaoLink tbLink = new TaoBaoLink(); - tbLink.setAuctionId(goods.getAuctionId()); - tbLink.setClickUrl(goods.getAuctionUrl()); - tbLink.setCouponLink(goods.getCouponLink()); - return tbLink; - } + @Override + public UserShareGoodsHistory getShareGoodsHistory(Long uid, Long auctionId) { + return userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, auctionId); + } - @Override - public UserShareGoodsHistory getShareGoodsHistory(Long uid, Long auctionId) { - return userShareGoodsHistoryMapper.selectByUidAndAuctionId(uid, auctionId); - } + @Override + public TaoBaoLink getTaoLiJinLinkForBuyWithOutFanLi(Long uid, Long auctionId, TaoKeAppInfo app) + throws ShareGoodsException, TaoLiJinCreateException { + if (uid == null || uid <= 0) { + throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); + } - @Override - public TaoBaoLink getTaoLiJinLinkForBuyWithOutFanLi(Long uid, Long auctionId, TaoKeAppInfo app) - throws ShareGoodsException, TaoLiJinCreateException { - if (uid == null || uid <= 0) { - throw new ShareGoodsException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖"); - } + if (auctionId == null || auctionId <= 0) { + throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖"); + } - if (auctionId == null || auctionId <= 0) { - throw new ShareGoodsException(2, "鍟嗗搧ID涓嶈兘涓虹┖"); - } + boolean canBuy = userTLJBuyHistoryService.canBuy(uid, auctionId); + if (!canBuy) { + throw new ShareGoodsException(3, "绔嬪噺绾㈠寘宸叉姠鍏夛紝璇风◢鍚庡啀璇�"); + } - boolean canBuy = userTLJBuyHistoryService.canBuy(uid, auctionId); - if (!canBuy) { - throw new ShareGoodsException(3, "绔嬪噺绾㈠寘宸叉姠鍏夛紝璇风◢鍚庡啀璇�"); - } + SystemEnum system = userInfoService.getUserSystem(uid); - SystemEnum system= userInfoService.getUserSystem(uid); + 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.searchGoodsDetail(auctionId); + } catch (TaobaoGoodsDownException e) { + throw new ShareGoodsException(4, "鍟嗗搧宸蹭笅鏋�"); + } - 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.searchGoodsDetail(auctionId); - } catch (TaobaoGoodsDownException e) { - throw new ShareGoodsException(4, "鍟嗗搧宸蹭笅鏋�"); - } + BigDecimal perface = TaoBaoUtil.getGoodsHongBaoMoney(goods, new BigDecimal(70), false); + 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(), system); + } else if (e1.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) {// 鍟嗗搧涓嶅厑璁稿垱寤烘窐绀奸噾 + tljBuyGoodsService.removeGoods(auctionId); + } + LogHelper.errorDetailInfo(e1, e1.getMessage(), null); + } catch (TaoKeApiException e) { + LogHelper.errorDetailInfo(e, e.getMessage(), null); + throw new ShareGoodsException(5, "鐢熸垚鎺ㄥ箍閾炬帴澶辫触"); + } - BigDecimal perface = TaoBaoUtil.getGoodsHongBaoMoney(goods, new BigDecimal(70), false); - 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(),system); - } else if (e1.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) {// 鍟嗗搧涓嶅厑璁稿垱寤烘窐绀奸噾 - tljBuyGoodsService.removeGoods(auctionId); - } - LogHelper.errorDetailInfo(e1, e1.getMessage(), null); - } catch (TaoKeApiException e) { - LogHelper.errorDetailInfo(e, e.getMessage(), null); - throw new ShareGoodsException(5, "鐢熸垚鎺ㄥ箍閾炬帴澶辫触"); - } + if (taoLiJinDTO == null) + throw new ShareGoodsException(5, "鐢熸垚鎺ㄥ箍閾炬帴澶辫触"); - if (taoLiJinDTO == null) - throw new ShareGoodsException(5, "鐢熸垚鎺ㄥ箍閾炬帴澶辫触"); + // 鍑忓幓鍓╀綑涓暟(闅忔満鍑忓幓8鍒�10涓�) + tljBuyGoodsService.subHongBaoLeftCount(auctionId, TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"), + 8 + (int) (3 * Math.random())); - // 鍑忓幓鍓╀綑涓暟(闅忔満鍑忓幓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); + } - // 鎻掑叆璁板綍 - 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; - } + TaoBaoLink taoBaoLink = new TaoBaoLink(); + taoBaoLink.setAuctionId(auctionId); + taoBaoLink.setClickUrl(goods.getAuctionUrl()); + taoBaoLink.setCouponLink(taoLiJinDTO.getSendUrl()); + taoBaoLink.setGoods(goods); + return taoBaoLink; + } } -- Gitblit v1.8.0