From cdd852f8e8eff7eb2e8f7c3fceaa955b9fc3f9d3 Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期一, 29 七月 2019 10:46:32 +0800 Subject: [PATCH] 订单商品类型处理 --- fanli/src/main/java/com/yeshi/fanli/controller/client/v1/GoodsController.java | 262 +++++++++++++--------------------------------------- 1 files changed, 66 insertions(+), 196 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v1/GoodsController.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v1/GoodsController.java index c6f232f..ed7f834 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v1/GoodsController.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v1/GoodsController.java @@ -19,6 +19,7 @@ import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.entity.taobao.TaoBaoLink; import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig; +import com.yeshi.fanli.exception.ShareGoodsException; import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.goods.ShareGoodsService; @@ -27,8 +28,10 @@ import com.yeshi.fanli.service.inter.monitor.MonitorService; import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService; import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService; +import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinRecordService; import com.yeshi.fanli.service.inter.user.TBPidService; import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService; +import com.yeshi.fanli.service.inter.user.UserInfoExtraService; import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; @@ -69,6 +72,30 @@ @Resource private RecommendGoodsDeleteHistoryService recommendGoodsDeleteHistoryService; + @Resource + private UserInfoExtraService userInfoExtraService; + + @Resource + private UserTaoLiJinRecordService userTaoLiJinRecordService; + + private void doTaoLiJinBuy(Long uid, Long auctionId, PrintWriter out) { + JSONObject data = new JSONObject(); + TaoBaoLink taoBaoLink; + try { + taoBaoLink = shareGoodsService.getTaoLiJinLinkForBuyWithOutFanLi(uid, auctionId); + } catch (ShareGoodsException e) { + out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage())); + return; + } + data.put("native", true); + JSONObject link = new JSONObject(); + link.put("clickUrl", taoBaoLink.getClickUrl()); + link.put("couponUrl", taoBaoLink.getCouponLink()); + data.put("type", 1); + data.put("link", link); + out.print(JsonUtil.loadTrueResult(data)); + } + /** * 鑾峰彇娣樺疂鐨勫垎浜摼鎺� * @@ -80,7 +107,7 @@ */ @RequestMapping(value = "gettaobaolink") public void getTaoBaoLink(AcceptData acceptData, Long uid, Long auctionId, String from, String source, - HttpServletRequest request, PrintWriter out) { + HttpServletRequest request, PrintWriter out) { if (uid == null || uid <= 0) { out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛ID涓嶈兘涓虹┖")); return; @@ -110,6 +137,11 @@ } catch (Exception e1) { e1.printStackTrace(); } + } + + if ("taolijin_buy".equalsIgnoreCase(source)) { + doTaoLiJinBuy(uid, auctionId, out); + return; } JSONObject data = new JSONObject(); @@ -150,202 +182,26 @@ pidType = PidUser.TYPE_FANLI_IOS; try { TaoBaoLink taoBaoLink = null; + // 鏄繑鍒╁晢鍝佸簱鐨勫晢鍝� if (specialConvert) { if (!StringUtil.isNullOrEmpty(specialId)) { - taoBaoLink = shareGoodsService.getTaoBaoLinkForBuyWithSpecial(uid, specialId, auctionId); - data.put("native", true); - } else { - if (!specialConvert && !isNative) { - if (pidType == PidUser.TYPE_FANLI_ANDROID) - taoBaoLink = shareGoodsService.getTaoBaoLink(uid, auctionId, - tbPidService.getAndroidDefault().getPid()); - else - taoBaoLink = shareGoodsService.getTaoBaoLink(uid, auctionId, - tbPidService.getIOSDefault().getPid()); + if (source != null && "taolijin".equals(source)) { + boolean isNewUser = userInfoExtraService.isNewUser(uid); + if (isNewUser) { + // 鍒ゅ畾涓鸿�佺敤鎴凤細 + // 鏂颁汉鍙浣跨敤浜嗘柊浜虹孩鍖咃紝涔熷氨鏄偅1鍧楅挶锛岄偅涔堬紝浠栫湅鍒扮殑鍒嗕韩鐖嗘涓殑鍟嗗搧-灏卞彧鑳藉垎浜�� + long countRecord = userTaoLiJinRecordService.countRecordByUid(uid); + if (countRecord == 0) { + taoBaoLink = shareGoodsService.getTaoLiJinLinkForBuy(uid, specialId, auctionId, null); + } + } + } - } else - taoBaoLink = shareGoodsService.getTaoBaoLinkForBuy(uid, auctionId, pidType); - LogHelper.test("璐拱杞摼:榛樿PID杞摼-" + uid + "锛�" + auctionId); - } - } else {// 涓嶆槸杩斿埄搴撶殑鍟嗗搧锛岀敤鐗规畩PID鏇夸唬 - try { - relationId = taoBaoBuyRelationMapService.getRelationId(uid); - } catch (Exception e) { - LogHelper.errorDetailInfo(e, "uid:" + uid, null); - } - if (!StringUtil.isNullOrEmpty(relationId)) {// - taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, auctionId, relationId, - TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID); - data.put("native", true); - } else { - if (pidType == PidUser.TYPE_FANLI_ANDROID) - taoBaoLink = shareGoodsService.getTaoBaoLink(uid, auctionId, - tbPidService.getAndroidDefault().getPid()); - else - taoBaoLink = shareGoodsService.getTaoBaoLink(uid, auctionId, - tbPidService.getIOSDefault().getPid()); - - LogHelper.test("璐拱杞摼:榛樿PID杞摼-闈炶繑鍒╁簱鍟嗗搧-" + uid + "锛�" + auctionId); - } - } - JSONObject link = new JSONObject(); - link.put("clickUrl", taoBaoLink.getClickUrl()); - link.put("couponUrl", taoBaoLink.getCouponLink()); - data.put("type", 1); - data.put("link", link); - out.print(JsonUtil.loadTrueResult(data)); - - } catch (Exception e) { - isNative = false; - try { - monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, 0, 0, "璐拱娣樺疂鍟嗗搧杞摼鍑洪敊")); - } catch (Exception e1) { - e1.printStackTrace(); - } - - TBPid tbPid = null; - if (acceptData.getPlatform().equalsIgnoreCase("android")) { - tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_FANLI_ANDROID); - } else { - tbPid = tbPidService.getTBPid(uid, PidUser.TYPE_FANLI_IOS); - } - - LogHelper.test("璐拱杞摼:榛樿PID杞摼-寮傚父鍟嗗搧-" + uid + "锛�" + auctionId); - - data.put("native", isNative); - - if (tbPid != null) { - - try { - TaoBaoLink taoBaoLink = null; - if (pidType == PidUser.TYPE_FANLI_ANDROID) - taoBaoLink = shareGoodsService.getTaoBaoLink(uid, auctionId, - tbPidService.getAndroidDefault().getPid()); - else - taoBaoLink = shareGoodsService.getTaoBaoLink(uid, auctionId, - tbPidService.getIOSDefault().getPid()); - - JSONObject link = new JSONObject(); - link.put("clickUrl", taoBaoLink.getClickUrl()); - link.put("couponUrl", taoBaoLink.getCouponLink()); - data.put("type", 1); - data.put("link", link); - data.put("native", true); - - } catch (Exception e1) { - String siteId = tbPid.getPid().split("_")[2]; - String adzoneId = tbPid.getPid().split("_")[3]; - TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppIdCache(siteId); - ClientTBPid clientTBPid = new ClientTBPid(config.getAppKey(), tbPid.getPid(), siteId, adzoneId); - data.put("type", 2); - data.put("tbPidInfo", clientTBPid); - data.put("native", true); - } - - out.print(JsonUtil.loadTrueResult(data)); - } else { - out.print(JsonUtil.loadFalseResult(1, "璇锋眰澶辫触")); - } - - businessEmergent110Service.buyTaoBaoGoodsError(StringUtil.Md5(auctionId + "")); - } - - } - - - - /** - * 鑾峰彇娣樺疂鐨勫垎浜摼鎺� 锛堟窐绀奸噾鏂板缓锛� - * - * @param acceptData - * @param uid - * -鐢ㄦ埛ID - * @param auctionId-鍟嗗搧ID - * @param out - */ - @RequestMapping(value = "getTaoBaoGoodsLink") - public void getTaoBaoGoodsLink(AcceptData acceptData, Long uid, Long auctionId, String from, HttpServletRequest request, - PrintWriter out) { - if (uid == null || uid <= 0) { - out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛ID涓嶈兘涓虹┖")); - return; - } - - UserInfo user = userInfoService.getUserByIdWithMybatis(uid); - if (user != null && user.getState() != UserInfo.STATE_NORMAL) { - out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC)); - return; - } - - if (auctionId == null || auctionId <= 0) { - out.print(JsonUtil.loadFalseResult(2, "鍟嗗搧ID涓嶈兘涓虹┖")); - return; - } - - TaoBaoGoodsBrief goods = null; - - try { - goods = TaoKeApiUtil.getSimpleGoodsInfo(auctionId); - } catch (TaobaoGoodsDownException e) { - out.print(JsonUtil.loadFalseResult(3, "鍟嗗搧宸蹭笅鏋�")); - return; - } catch (Exception e) { - try { - LogHelper.errorDetailInfo(e, "鑾峰彇鍟嗗搧绠�鐗堣鎯呭嚭閿�", auctionId + ""); - } catch (Exception e1) { - e1.printStackTrace(); - } - } - - JSONObject data = new JSONObject(); - boolean isNative = false; - String pid = null; - - boolean specialConvert = false; - - if (goods.getMaterialLibType() != null && goods.getMaterialLibType() == 1) { - specialConvert = true; - } else - specialConvert = false; - - String specialId = null; - String relationId = null; - // 鏌ヨ鐢ㄦ埛ID鏄惁缁戝畾浜嗕細鍛樿繍钀D - UserExtraTaoBaoInfo userInfo = userExtraTaoBaoInfoService.getByUid(uid); - if (userInfo != null && !StringUtil.isNullOrEmpty(userInfo.getSpecialId()) && userInfo.getSpecialValid() != null - && userInfo.getSpecialValid() == true) { - specialId = userInfo.getSpecialId(); - relationId = userInfo.getRelationId(); - // 宸茬粡缁戝畾 - if (specialConvert) { - isNative = true; - } else - isNative = false; - - pid = TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT; - - } else {// 灏氭湭缁戝畾 - isNative = true; - } - - data.put("native", isNative); - - int pidType = PidUser.TYPE_FANLI_ANDROID; - if (acceptData.getPlatform().equalsIgnoreCase("ios")) - pidType = PidUser.TYPE_FANLI_IOS; - try { - TaoBaoLink taoBaoLink = null; - // 鏄繑鍒╁晢鍝佸簱鐨勫晢鍝� - if (specialConvert) { - if (!StringUtil.isNullOrEmpty(specialId)) { - - if (from != null && from.equals("taolijin")) { - taoBaoLink = shareGoodsService.getTaoLiJinLinkForBuy(uid, specialId, auctionId); - } else { + if (taoBaoLink == null) { taoBaoLink = shareGoodsService.getTaoBaoLinkForBuyWithSpecial(uid, specialId, auctionId); } - + data.put("native", true); } else { if (!specialConvert && !isNative) { @@ -367,8 +223,22 @@ LogHelper.errorDetailInfo(e, "uid:" + uid, null); } if (!StringUtil.isNullOrEmpty(relationId)) {// - taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, auctionId, relationId, - TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID); + if (source != null && "taolijin".equals(source)) { + boolean isNewUser = userInfoExtraService.isNewUser(uid); + if (isNewUser) { + // 鍒ゅ畾涓鸿�佺敤鎴凤細 + // 鏂颁汉鍙浣跨敤浜嗘柊浜虹孩鍖咃紝涔熷氨鏄偅1鍧楅挶锛岄偅涔堬紝浠栫湅鍒扮殑鍒嗕韩鐖嗘涓殑鍟嗗搧-灏卞彧鑳藉垎浜�� + long countRecord = userTaoLiJinRecordService.countRecordByUid(uid); + if (countRecord == 0) { + taoBaoLink = shareGoodsService.getTaoLiJinLinkForBuy(uid, specialId, auctionId, + TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID); + } + } + } else { + taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, auctionId, relationId, + TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID); + } + data.put("native", true); } else { if (pidType == PidUser.TYPE_FANLI_ANDROID) @@ -389,6 +259,9 @@ out.print(JsonUtil.loadTrueResult(data)); } catch (Exception e) { + + LogHelper.errorDetailInfo(e); + isNative = false; try { monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, 0, 0, "璐拱娣樺疂鍟嗗搧杞摼鍑洪敊")); @@ -424,7 +297,6 @@ data.put("type", 1); data.put("link", link); data.put("native", true); - } catch (Exception e1) { String siteId = tbPid.getPid().split("_")[2]; String adzoneId = tbPid.getPid().split("_")[3]; @@ -442,9 +314,7 @@ businessEmergent110Service.buyTaoBaoGoodsError(StringUtil.Md5(auctionId + "")); } - } - /** * 鏄惁鍦ㄥ弬涓庢帹骞� -- Gitblit v1.8.0