| | |
| | | package com.yeshi.fanli.controller.client.v1;
|
| | |
|
| | | import java.io.PrintWriter;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | |
|
| | | import com.yeshi.fanli.service.manger.goods.TaoBaoLinkManager;
|
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.goods.recommend.RecommendGoodsDeleteHistory;
|
| | | import com.yeshi.fanli.entity.taobao.ClientTBPid;
|
| | | import com.yeshi.fanli.entity.taobao.PidUser;
|
| | | import com.yeshi.fanli.entity.taobao.TBPid;
|
| | | import com.yeshi.fanli.entity.taobao.TLJBuyGoods;
|
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoLink;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.common.entity.taobao.TaoKeAppInfo;
|
| | | import com.yeshi.fanli.exception.share.ShareGoodsException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.exception.tlj.TaoLiJinCreateException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.log.TaoKeLogHelper;
|
| | | import com.yeshi.fanli.service.inter.goods.ShareGoodsService;
|
| | | import com.yeshi.fanli.service.inter.goods.recommend.RecommendGoodsDeleteHistoryService;
|
| | | import com.yeshi.fanli.service.inter.monitor.BusinessEmergent110Service;
|
| | | import com.yeshi.fanli.service.inter.monitor.MonitorService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService;
|
| | | 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.UserInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralGetService;
|
| | | import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TaoBaoConstant;
|
| | | import org.yeshi.utils.TimeUtil;
|
| | | import com.yeshi.fanli.util.factory.MonitorFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Controller
|
| | | @RequestMapping(value = "api/v1/goods")
|
| | | public class GoodsController {
|
| | |
|
| | | @Resource
|
| | | private ShareGoodsService shareGoodsService;
|
| | |
|
| | | @Resource
|
| | | private TBPidService tbPidService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService;
|
| | |
|
| | | @Resource
|
| | | private MonitorService monitorService;
|
| | |
|
| | | @Resource
|
| | | private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService;
|
| | |
|
| | | @Resource
|
| | | private BusinessEmergent110Service businessEmergent110Service;
|
| | |
|
| | | @Resource
|
| | | private RecommendGoodsDeleteHistoryService recommendGoodsDeleteHistoryService;
|
| | |
|
| | |
|
| | | @Resource
|
| | | private TLJBuyGoodsService tljBuyGoodsService;
|
| | |
|
| | | @Resource
|
| | | private IntegralGetService integralGetService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoLinkManager taoBaoLinkManager;
|
| | |
|
| | | private void doTaoLiJinBuy(AcceptData acceptData, Long uid, Long auctionId, PrintWriter out) {
|
| | | JSONObject data = new JSONObject();
|
| | | TaoBaoLink taoBaoLink = null;
|
| | | try {
|
| | | // 根据日期与商品ID查询
|
| | | TLJBuyGoods tljBuyGoods = tljBuyGoodsService.selectByAuctionIdAndDay(auctionId,
|
| | | TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd"));
|
| | | if (tljBuyGoods == null) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "商品不存在"));
|
| | | return;
|
| | | }
|
| | | String appKey = tljBuyGoods.getAppKey();
|
| | | TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppKeyCache(appKey);
|
| | | if (config == null) {
|
| | | out.print(JsonUtil.loadFalseResult(2, "生成推广链接失败"));
|
| | | return;
|
| | | }
|
| | | TaoKeAppInfo app = new TaoKeAppInfo(config.getAppKey(), config.getAppSecret(), config.getDefaultPid());
|
| | | taoBaoLink = shareGoodsService.getTaoLiJinLinkForBuyWithOutFanLi(uid, auctionId, app);
|
| | | } catch (TaoLiJinCreateException e1) {
|
| | | out.print(JsonUtil.loadFalseResult(e1.getCode(), "淘礼金红包创建失败"));
|
| | | return;
|
| | | } 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));
|
| | |
|
| | | integralGetService.addTaoLiJinBuy(uid, auctionId);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取淘宝的分享链接
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * -用户ID
|
| | | * @param auctionId-商品ID
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "gettaobaolink")
|
| | | public void getTaoBaoLink(AcceptData acceptData, Long uid, Long auctionId, String from, String source,
|
| | | 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;
|
| | | }
|
| | |
|
| | | try {
|
| | | // 日志记录
|
| | | String info = String.format("type=buy&uid=%s&goodsId=%s&source=%s&goodsType=%s", uid, auctionId, source,
|
| | | Constant.SOURCE_TYPE_TAOBAO);
|
| | | LogHelper.orderInfo(info);
|
| | | } catch (Exception e) {
|
| | | }
|
| | |
|
| | | 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();
|
| | | }
|
| | | }
|
| | |
|
| | | if ("taolijin_buy".equalsIgnoreCase(source)) {
|
| | | doTaoLiJinBuy(acceptData, uid, auctionId, out);
|
| | | return;
|
| | | }
|
| | |
|
| | | ClientTBPid clientTBPid = null;
|
| | |
|
| | | String dpid = null;
|
| | | if (TaoBaoUtil.isSpecialGoods(goods.getMaterialLibType())) {
|
| | | dpid = TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT;
|
| | | } else {
|
| | | dpid = TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID;
|
| | | }
|
| | | String psiteId = dpid.split("_")[2];
|
| | | String padzoneId = dpid.split("_")[3];
|
| | | TaoBaoUnionConfig config1 = taoBaoUnionConfigService.getConfigByAppIdCache(psiteId);
|
| | | clientTBPid = new ClientTBPid(config1.getAppKey(), dpid, psiteId, padzoneId);
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | boolean isNative = false;
|
| | | String pid = null;
|
| | |
|
| | | boolean specialConvert = false;
|
| | |
|
| | | if (TaoBaoUtil.isSpecialGoods(goods.getMaterialLibType())) {
|
| | | 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();
|
| | | // 已经绑定
|
| | | 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 (source != null && "taolijin_free_buy".equals(source)) {
|
| | | taoBaoLink = taoBaoLinkManager.getTaoLiJinLinkForBuy(uid, auctionId, null);
|
| | | }
|
| | |
|
| | | if (taoBaoLink == null) {
|
| | | taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForBuy(uid, auctionId,specialId,null);
|
| | | if(taoBaoLink!=null)
|
| | | clientTBPid=null;
|
| | | }
|
| | |
|
| | | 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 = taoBaoLinkManager.getTaoBaoLinkForBuy(uid, auctionId, specialId,null);
|
| | | 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)) {//
|
| | | if (source != null && "taolijin_free_buy".equals(source)) {
|
| | | taoBaoLink = taoBaoLinkManager.getTaoLiJinLinkForBuy(uid, auctionId,
|
| | | TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID);
|
| | | } else {
|
| | | taoBaoLink = taoBaoLinkManager.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);
|
| | | if (clientTBPid != null)
|
| | | data.put("tbPidInfo", clientTBPid);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | |
|
| | | TaoKeLogHelper.convertLinkInfo(
|
| | | String.format("uid:%s auctionId:%s 输出结果:", uid, auctionId + "") + data.toString());
|
| | |
|
| | | // 获得金币
|
| | | integralGetService.addCouponRebate(uid);
|
| | |
|
| | | } catch (ShareGoodsException e) {
|
| | | if (e.getCode() == 1001 || e.getCode() == 1002) {
|
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
| | | } else {
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | }
|
| | | } catch (Exception e) {
|
| | |
|
| | | LogHelper.errorDetailInfo(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 clientTBPid1 = new ClientTBPid(config.getAppKey(), tbPid.getPid(), siteId, adzoneId);
|
| | | data.put("type", 2);
|
| | | data.put("tbPidInfo", clientTBPid1);
|
| | | data.put("native", true);
|
| | | }
|
| | |
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } else {
|
| | | out.print(JsonUtil.loadFalseResult(1, "请求失败"));
|
| | | }
|
| | |
|
| | | businessEmergent110Service.buyTaoBaoGoodsError(StringUtil.Md5(auctionId + ""),acceptData.getSystem());
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 是否在参与推广
|
| | | */
|
| | |
|
| | | /**
|
| | | * 是否在参与推广
|
| | | * |
| | | * @param goodsId
|
| | | * -商品ID
|
| | | * @param goodsType
|
| | | * -TB/JD
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "isGoodsExtend")
|
| | | public void isGoodsExtend(AcceptData acceptData, String goodsId, String goodsType, PrintWriter out) {
|
| | | if (StringUtil.isNullOrEmpty(goodsId)) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "未参与推广"));
|
| | | return;
|
| | | }
|
| | | if (StringUtil.isNullOrEmpty(goodsType)) {
|
| | | out.print(JsonUtil.loadFalseResult(2, "缺少goodsType"));
|
| | | return;
|
| | | }
|
| | | if ("TB".equalsIgnoreCase(goodsType)) {
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | try {
|
| | | goods = TaoKeApiUtil.getSimpleGoodsInfo(Long.parseLong(goodsId));
|
| | | } catch (NumberFormatException e) {
|
| | | e.printStackTrace();
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | |
|
| | | if (goods == null) {
|
| | | data.put("extend", false);
|
| | | data.put("url", "https://h5.m.taobao.com/awp/core/detail.htm?id=" + goodsId);
|
| | | } else {
|
| | | data.put("extend", true);
|
| | | }
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } else {
|
| | | out.print(JsonUtil.loadFalseResult(3, "暂不支持其他商品类型"));
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除推荐商品
|
| | | * |
| | | * @param acceptData
|
| | | * @param goodsId
|
| | | * @param source
|
| | | * @param uid
|
| | | * @param reason
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "deleteRecommendGoods")
|
| | | public void deleteRecommendGoods(AcceptData acceptData, Long goodsId, Integer source, Long uid, String reason,
|
| | | PrintWriter out) {
|
| | | if (goodsId == null) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "请上传商品"));
|
| | | return;
|
| | | }
|
| | |
|
| | | RecommendGoodsDeleteHistory history = new RecommendGoodsDeleteHistory();
|
| | | history.setDevice(acceptData.getDevice());
|
| | | history.setReason(reason);
|
| | | history.setUid(uid);
|
| | | history.setGoodsSource(source == null ? Constant.SOURCE_TYPE_TAOBAO : source);
|
| | | history.setGoodsId(goodsId);
|
| | | recommendGoodsDeleteHistoryService.addRecommendGoodsDeleteHistory(history);
|
| | | out.print(JsonUtil.loadTrueResult(""));
|
| | |
|
| | | // 获得金币
|
| | | integralGetService.addCloseRecommendGoods(uid);
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.controller.client.v1; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.util.Date; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.SystemFunction; |
| | | import com.yeshi.fanli.entity.SystemPIDInfo; |
| | | import com.yeshi.fanli.exception.taobao.TaoBaoConvertLinkException; |
| | | import com.yeshi.fanli.lijin.manager.UserLijinMnager; |
| | | import com.yeshi.fanli.service.inter.user.UserFunctionsLimitService; |
| | | import com.yeshi.fanli.service.manger.PIDManager; |
| | | import com.yeshi.fanli.service.manger.goods.TaoBaoLinkManager; |
| | | import com.yeshi.fanli.util.SystemInfoUtil; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.yeshi.utils.JsonUtil; |
| | | |
| | | import com.yeshi.fanli.entity.accept.AcceptData; |
| | | import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.entity.goods.recommend.RecommendGoodsDeleteHistory; |
| | | import com.yeshi.fanli.entity.taobao.ClientTBPid; |
| | | import com.yeshi.fanli.entity.taobao.PidUser; |
| | | import com.yeshi.fanli.entity.taobao.TBPid; |
| | | import com.yeshi.fanli.entity.taobao.TLJBuyGoods; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoLink; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig; |
| | | import com.yeshi.common.entity.taobao.TaoKeAppInfo; |
| | | import com.yeshi.fanli.exception.share.ShareGoodsException; |
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; |
| | | import com.yeshi.fanli.exception.tlj.TaoLiJinCreateException; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.log.TaoKeLogHelper; |
| | | import com.yeshi.fanli.service.inter.goods.ShareGoodsService; |
| | | import com.yeshi.fanli.service.inter.goods.recommend.RecommendGoodsDeleteHistoryService; |
| | | import com.yeshi.fanli.service.inter.monitor.BusinessEmergent110Service; |
| | | import com.yeshi.fanli.service.inter.monitor.MonitorService; |
| | | import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService; |
| | | 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.UserInfoService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralGetService; |
| | | import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.TaoBaoConstant; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import com.yeshi.fanli.util.factory.MonitorFactory; |
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil; |
| | | |
| | | import net.sf.json.JSONObject; |
| | | |
| | | @Controller |
| | | @RequestMapping(value = "api/v1/goods") |
| | | public class GoodsController { |
| | | |
| | | @Resource |
| | | private ShareGoodsService shareGoodsService; |
| | | |
| | | @Resource |
| | | private TBPidService tbPidService; |
| | | |
| | | @Resource |
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService; |
| | | |
| | | @Resource |
| | | private MonitorService monitorService; |
| | | |
| | | @Resource |
| | | private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService; |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | @Resource |
| | | private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService; |
| | | |
| | | @Resource |
| | | private BusinessEmergent110Service businessEmergent110Service; |
| | | |
| | | @Resource |
| | | private RecommendGoodsDeleteHistoryService recommendGoodsDeleteHistoryService; |
| | | |
| | | |
| | | @Resource |
| | | private TLJBuyGoodsService tljBuyGoodsService; |
| | | |
| | | @Resource |
| | | private IntegralGetService integralGetService; |
| | | |
| | | @Resource |
| | | private TaoBaoLinkManager taoBaoLinkManager; |
| | | |
| | | @Resource |
| | | private PIDManager pidManager; |
| | | |
| | | @Resource |
| | | private UserLijinMnager userLijinMnager; |
| | | |
| | | @Resource |
| | | private UserFunctionsLimitService userFunctionsLimitService; |
| | | |
| | | private void doTaoLiJinBuy(AcceptData acceptData, Long uid, String auctionId, PrintWriter out) { |
| | | JSONObject data = new JSONObject(); |
| | | TaoBaoLink taoBaoLink = null; |
| | | try { |
| | | // 根据日期与商品ID查询 |
| | | TLJBuyGoods tljBuyGoods = tljBuyGoodsService.selectByAuctionIdAndDay(auctionId, |
| | | TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd")); |
| | | if (tljBuyGoods == null) { |
| | | out.print(JsonUtil.loadFalseResult(1, "商品不存在")); |
| | | return; |
| | | } |
| | | String appKey = tljBuyGoods.getAppKey(); |
| | | TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppKeyCache(appKey); |
| | | if (config == null) { |
| | | out.print(JsonUtil.loadFalseResult(2, "生成推广链接失败")); |
| | | return; |
| | | } |
| | | TaoKeAppInfo app = new TaoKeAppInfo(config.getAppKey(), config.getAppSecret(), config.getDefaultPid()); |
| | | taoBaoLink = shareGoodsService.getTaoLiJinLinkForBuyWithOutFanLi(uid, auctionId, app); |
| | | } catch (TaoLiJinCreateException e1) { |
| | | out.print(JsonUtil.loadFalseResult(e1.getCode(), "淘礼金红包创建失败")); |
| | | return; |
| | | } 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)); |
| | | |
| | | integralGetService.addTaoLiJinBuy(uid, auctionId); |
| | | } |
| | | |
| | | |
| | | private void getTaoBaoLinkWithoutFanLi(AcceptData acceptData, String auctionId, String from, String source, |
| | | HttpServletRequest request, PrintWriter out) { |
| | | |
| | | try { |
| | | String pid = pidManager.getPidCache(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.coupon); |
| | | |
| | | TaoBaoLink taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForRecieveCoupon(acceptData.getSystem(), auctionId, null, pid); |
| | | JSONObject data = new JSONObject(); |
| | | 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); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } catch (TaoBaoConvertLinkException e) { |
| | | e.printStackTrace(); |
| | | out.print(JsonUtil.loadFalseResult("领券出错")); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取淘宝的分享链接 |
| | | * |
| | | * @param acceptData |
| | | * @param uid -用户ID |
| | | * @param auctionId-商品ID |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "gettaobaolink") |
| | | public void getTaoBaoLink(AcceptData acceptData, Long uid, String auctionId, String from, String source, |
| | | HttpServletRequest request, PrintWriter out) { |
| | | |
| | | if (StringUtil.isNullOrEmpty(auctionId)) { |
| | | out.print(JsonUtil.loadFalseResult(2, "商品ID不能为空")); |
| | | return; |
| | | } |
| | | |
| | | if (!SystemInfoUtil.hasFunctions(acceptData.getSystem(), SystemFunction.fanli)) { |
| | | getTaoBaoLinkWithoutFanLi(acceptData, auctionId, from, source, request, out); |
| | | return; |
| | | } |
| | | |
| | | //领券 |
| | | if (uid == null) { |
| | | getTaoBaoLinkWithoutFanLi(acceptData, auctionId, from, source, request, out); |
| | | return; |
| | | } |
| | | |
| | | 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 (userFunctionsLimitService.isLimit(uid, SystemFunction.fanli, new Date())) { |
| | | out.print(JsonUtil.loadFalseResult(1, "该功能限制使用")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | // 日志记录 |
| | | String info = String.format("type=buy&uid=%s&goodsId=%s&source=%s&goodsType=%s", uid, auctionId, source, |
| | | Constant.SOURCE_TYPE_TAOBAO); |
| | | LogHelper.orderInfo(info); |
| | | } catch (Exception e) { |
| | | } |
| | | |
| | | TaoBaoGoodsBrief goods = null; |
| | | |
| | | try { |
| | | goods = TaoKeApiUtil.getSimpleGoodsInfoForOwnBuy(auctionId); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | out.print(JsonUtil.loadFalseResult(3, "商品已下架")); |
| | | return; |
| | | } catch (Exception e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "获取商品简版详情出错", auctionId + ""); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | if ("taolijin_buy".equalsIgnoreCase(source)) { |
| | | doTaoLiJinBuy(acceptData, uid, auctionId, out); |
| | | return; |
| | | } |
| | | |
| | | ClientTBPid clientTBPid = null; |
| | | |
| | | String dpid = null; |
| | | if (TaoBaoUtil.isSpecialGoods(goods.getMaterialLibType())) { |
| | | dpid = pidManager.getPid(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli); |
| | | } else { |
| | | dpid = pidManager.getPid(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel); |
| | | } |
| | | String psiteId = dpid.split("_")[2]; |
| | | String padzoneId = dpid.split("_")[3]; |
| | | TaoBaoUnionConfig config1 = taoBaoUnionConfigService.getConfigByAppIdCache(psiteId); |
| | | clientTBPid = new ClientTBPid(config1.getAppKey(), dpid, psiteId, padzoneId); |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | boolean isNative = false; |
| | | String pid = null; |
| | | |
| | | boolean specialConvert = false; |
| | | |
| | | if (TaoBaoUtil.isSpecialGoods(goods.getMaterialLibType())) { |
| | | 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(); |
| | | // 已经绑定 |
| | | if (specialConvert) { |
| | | isNative = true; |
| | | } else |
| | | isNative = false; |
| | | |
| | | pid = pidManager.getPid(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli); |
| | | |
| | | } 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 (source != null && "taolijin_free_buy".equals(source)) { |
| | | taoBaoLink = taoBaoLinkManager.getTaoLiJinLinkForBuy(uid, auctionId, null); |
| | | } |
| | | |
| | | if (taoBaoLink == null) { |
| | | taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForBuy(acceptData.getSystem(), uid, auctionId, specialId, null); |
| | | if (taoBaoLink != null) |
| | | clientTBPid = null; |
| | | } |
| | | |
| | | 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 = taoBaoLinkManager.getTaoBaoLinkForBuy(acceptData.getSystem(), uid, auctionId, specialId, null); |
| | | 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)) {// |
| | | if (source != null && "taolijin_free_buy".equals(source)) { |
| | | taoBaoLink = taoBaoLinkManager.getTaoLiJinLinkForBuy(uid, auctionId, |
| | | pidManager.getPid(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel)); |
| | | } else { |
| | | taoBaoLink = taoBaoLinkManager.getTaoBaoLinkForShare(acceptData.getSystem(), uid, auctionId, relationId, |
| | | pidManager.getPid(acceptData.getSystem(), Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel)); |
| | | } |
| | | |
| | | 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); |
| | | if (clientTBPid != null) |
| | | data.put("tbPidInfo", clientTBPid); |
| | | |
| | | data.put("userLevel", userLijinMnager.getUserLevelInfo(uid, acceptData.getSystem())); |
| | | |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | |
| | | TaoKeLogHelper.convertLinkInfo( |
| | | String.format("uid:%s auctionId:%s 输出结果:", uid, auctionId + "") + data.toString()); |
| | | |
| | | // 获得金币 |
| | | integralGetService.addCouponRebate(uid); |
| | | |
| | | } catch (ShareGoodsException e) { |
| | | if (e.getCode() == 1001 || e.getCode() == 1002) { |
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg())); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg())); |
| | | } |
| | | } catch (Exception e) { |
| | | |
| | | LogHelper.errorDetailInfo(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 clientTBPid1 = new ClientTBPid(config.getAppKey(), tbPid.getPid(), siteId, adzoneId); |
| | | data.put("type", 2); |
| | | data.put("tbPidInfo", clientTBPid1); |
| | | data.put("native", true); |
| | | } |
| | | |
| | | data.put("userLevel", userLijinMnager.getUserLevelInfo(uid, acceptData.getSystem())); |
| | | |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseResult(1, "请求失败")); |
| | | } |
| | | |
| | | businessEmergent110Service.buyTaoBaoGoodsError(StringUtil.Md5(auctionId + ""), acceptData.getSystem()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 是否在参与推广 |
| | | */ |
| | | |
| | | /** |
| | | * 是否在参与推广 |
| | | * |
| | | * @param goodsId -商品ID |
| | | * @param goodsType -TB/JD |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "isGoodsExtend") |
| | | public void isGoodsExtend(AcceptData acceptData, String goodsId, String goodsType, PrintWriter out) { |
| | | if (StringUtil.isNullOrEmpty(goodsId)) { |
| | | out.print(JsonUtil.loadFalseResult(1, "未参与推广")); |
| | | return; |
| | | } |
| | | if (StringUtil.isNullOrEmpty(goodsType)) { |
| | | out.print(JsonUtil.loadFalseResult(2, "缺少goodsType")); |
| | | return; |
| | | } |
| | | if ("TB".equalsIgnoreCase(goodsType)) { |
| | | TaoBaoGoodsBrief goods = null; |
| | | try { |
| | | goods = TaoKeApiUtil.getSimpleGoodsInfo(goodsId); |
| | | } catch (NumberFormatException e) { |
| | | e.printStackTrace(); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | |
| | | if (goods == null) { |
| | | data.put("extend", false); |
| | | data.put("url", "https://h5.m.taobao.com/awp/core/detail.htm?id=" + goodsId); |
| | | } else { |
| | | data.put("extend", true); |
| | | } |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseResult(3, "暂不支持其他商品类型")); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除推荐商品 |
| | | * |
| | | * @param acceptData |
| | | * @param goodsId |
| | | * @param source |
| | | * @param uid |
| | | * @param reason |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "deleteRecommendGoods") |
| | | public void deleteRecommendGoods(AcceptData acceptData, String goodsId, Integer source, Long uid, String reason, |
| | | PrintWriter out) { |
| | | if (goodsId == null) { |
| | | out.print(JsonUtil.loadFalseResult(1, "请上传商品")); |
| | | return; |
| | | } |
| | | |
| | | RecommendGoodsDeleteHistory history = new RecommendGoodsDeleteHistory(); |
| | | history.setDevice(acceptData.getDevice()); |
| | | history.setReason(reason); |
| | | history.setUid(uid); |
| | | history.setGoodsSource(source == null ? Constant.SOURCE_TYPE_TAOBAO : source); |
| | | history.setGoodsId(goodsId); |
| | | recommendGoodsDeleteHistoryService.addRecommendGoodsDeleteHistory(history); |
| | | out.print(JsonUtil.loadTrueResult("")); |
| | | |
| | | // 获得金币 |
| | | integralGetService.addCloseRecommendGoods(uid); |
| | | } |
| | | |
| | | } |