admin
2019-05-08 c5410b7f48a774e4ecd50019b46bc9173f2483ae
fanli/src/main/java/com/yeshi/fanli/controller/client/GoodsController.java
@@ -22,12 +22,14 @@
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
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.user.TBPidService;
import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.factory.MonitorFactory;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
@@ -55,6 +57,9 @@
   @Resource
   private UserInfoService userInfoService;
   @Resource
   private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService;
   /**
    * 获取淘宝的分享链接
    * 
@@ -65,7 +70,7 @@
    * @param out
    */
   @RequestMapping(value = "gettaobaolink")
   public void getTaobaoShareLink(AcceptData acceptData, Long uid, Long auctionId, HttpServletRequest request,
   public void getTaoBaoLink(AcceptData acceptData, Long uid, Long auctionId,String from, HttpServletRequest request,
         PrintWriter out) {
      if (uid == null || uid <= 0) {
         out.print(JsonUtil.loadFalseResult(1, "用户ID不能为空"));
@@ -83,64 +88,95 @@
         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是否绑定了会员运营ID
      UserExtraTaoBaoInfo userInfo = userExtraTaoBaoInfoService.getByUid(uid);
      if (userInfo != null && !StringUtil.isNullOrEmpty(userInfo.getSpecialId()) && userInfo.getSpecialValid() != null
            && userInfo.getSpecialValid() == true) {
         specialId = userInfo.getSpecialId();
         relationId = userInfo.getRelationId();
         // 已经绑定
         try {
            TaoBaoGoodsBrief goods = TaoKeApiUtil.getSimpleGoodsInfo(auctionId);
            if (goods.getMaterialLibType() != null && goods.getMaterialLibType() == 1) {
               isNative = true;
               specialConvert = true;
            } else
               isNative = false;
         } catch (TaobaoGoodsDownException e) {
            out.print(JsonUtil.loadFalseResult(3, "商品已下架"));
            return;
         } catch (Exception e) {
            try {
               LogHelper.errorDetailInfo(e, "获取商品简版详情出错", auctionId + "");
            } catch (Exception e1) {
               e1.printStackTrace();
            }
         }
         if (specialConvert) {
            isNative = true;
         } else
            isNative = false;
         pid = Constant.TAOBAO_SPECIAL_PID_DEFAULT;
         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 {
         int pidType = PidUser.TYPE_FANLI_ANDROID;
         if (acceptData.getPlatform().equalsIgnoreCase("ios"))
            pidType = PidUser.TYPE_FANLI_IOS;
         TaoBaoLink taoBaoLink = null;
         if (!StringUtil.isNullOrEmpty(specialId) && specialConvert) {
            taoBaoLink = shareGoodsService.getTaoBaoLinkForBuyWithSpecial(uid, specialId, auctionId);
         } else {
            if (!specialConvert && !isNative) {
         // 是返利商品库的商品
         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());
               } else
                  taoBaoLink = shareGoodsService.getTaoBaoLinkForBuy(uid, auctionId, pidType);
            }
         } 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());
            } else
               taoBaoLink = shareGoodsService.getTaoBaoLinkForBuy(uid, auctionId, pidType);
            }
         }
         JSONObject link = new JSONObject();
         link.put("clickUrl", taoBaoLink.getClickUrl());
         link.put("couponUrl", taoBaoLink.getCouponLink());
@@ -194,7 +230,7 @@
    * @param out
    */
   @RequestMapping(value = "isGoodsExtend")
   public void isGoodsExtend(String goodsId, String goodsType, PrintWriter out) {
   public void isGoodsExtend(AcceptData acceptData, String goodsId, String goodsType, PrintWriter out) {
      if (StringUtil.isNullOrEmpty(goodsId)) {
         out.print(JsonUtil.loadFalseResult(1, "未参与推广"));
         return;