| | |
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMethod;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | | import org.yeshi.utils.taobao.TbImgUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | |
| | | 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.exception.share.UserShareGoodsRecordException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.config.SystemConfigService;
|
| | |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
| | | import com.yeshi.fanli.service.inter.user.ScanHistoryService;
|
| | | import com.yeshi.fanli.service.inter.user.TBPidService;
|
| | | import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
|
| | | import com.yeshi.fanli.util.AESUtil;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.ThreadUtil;
|
| | | import com.yeshi.fanli.util.Utils;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
| | |
|
| | | @Resource
|
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService;
|
| | |
|
| | | @Resource
|
| | | private UserShareGoodsGroupService userShareGoodsGroupService;
|
| | |
|
| | | /**
|
| | | *
|
| | |
| | | out.print(JsonUtil.loadFalseResult(1, "请上传id"));
|
| | | return;
|
| | | }
|
| | |
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_SHARE_GOODS);
|
| | | UserShareGoodsHistory shareHistory = null;
|
| | | String pid = configList.get(0).getDefaultPid();
|
| | | if (!StringUtil.isNullOrEmpty(uid)) {
|
| | | try {
|
| | | uid = AESUtil.decrypt(uid, Constant.UIDAESKEY);
|
| | | TBPid tbPid = tbPidService.getTBPid(Long.parseLong(uid), PidUser.TYPE_SHARE_GOODS);
|
| | | if (tbPid != null)
|
| | | pid = tbPid.getPid();
|
| | |
|
| | | // 查询该PID,UID,商品ID下是否有这个商品的信息
|
| | | // 判断这个产品是否从APP中分享而来
|
| | | try {
|
| | | shareHistory = shareGoodsService.getShareGoodsHistoryDetail(Long.parseLong(uid),
|
| | | Long.parseLong(id));
|
| | | } catch (Exception e) {
|
| | |
|
| | | }
|
| | |
|
| | | } catch (Exception e) {
|
| | |
|
| | | }
|
| | | uid = AESUtil.decrypt(uid, Constant.UIDAESKEY);
|
| | | }
|
| | |
|
| | | TaoBaoGoodsBrief goods = null;
|
| | | try {
|
| | | String token = null;
|
| | | if (!StringUtil.isNullOrEmpty(uid)) {
|
| | | // 查询是否有分享记录
|
| | | UserShareGoodsHistory shareHistory = null;
|
| | | try {
|
| | | shareHistory = shareGoodsService.getShareGoodsHistoryDetail(Long.parseLong(uid), Long.parseLong(id));
|
| | | } catch (NumberFormatException e) {
|
| | | e.printStackTrace();
|
| | | } catch (ShareGoodsException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | if (shareHistory != null) {// 有分享记录
|
| | | token = shareHistory.getTkCode();
|
| | | goods = redisManager.getTaoBaoGoodsTemp(Long.parseLong(id));
|
| | | if (goods == null)
|
| | | try {
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id));
|
| | | } catch (NumberFormatException e) {
|
| | | e.printStackTrace();
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | } else {// 没有分享记录,需要直接分享
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService
|
| | | .getConfigByTypeCache(PidUser.TYPE_SHARE_GOODS);
|
| | | String pid = null;
|
| | | TBPid tbPid = tbPidService.getTBPid(Long.parseLong(uid), PidUser.TYPE_SHARE_GOODS);
|
| | | if (tbPid != null)
|
| | | pid = tbPid.getPid();
|
| | | else {
|
| | | pid = configList.get(0).getDefaultPid();
|
| | | }
|
| | |
|
| | | // 获取
|
| | | TaoKeAppInfo app = new TaoKeAppInfo();
|
| | | app.setAdzoneId(pid.split("_")[3]);
|
| | | app.setAppKey(configList.get(0).getAppKey());
|
| | | app.setAppSecret(configList.get(0).getAppSecret());
|
| | | app.setPid(pid);
|
| | | try {
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id), app);
|
| | | } catch (NumberFormatException e) {
|
| | | e.printStackTrace();
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | if (goods != null) {
|
| | | String url = goods.getAuctionUrl();
|
| | | if (!StringUtil.isNullOrEmpty(goods.getCouponLink())) {
|
| | | url = goods.getCouponLink();
|
| | | }
|
| | | token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), url);
|
| | | }
|
| | | }
|
| | |
|
| | | } else {
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService
|
| | | .getConfigByTypeCache(PidUser.TYPE_SHARE_GOODS);
|
| | | String pid = configList.get(0).getDefaultPid();
|
| | | TaoKeAppInfo app = new TaoKeAppInfo();
|
| | | app.setAdzoneId(pid.split("_")[3]);
|
| | | app.setAppKey(configList.get(0).getAppKey());
|
| | | app.setAppSecret(configList.get(0).getAppSecret());
|
| | | app.setPid(pid);
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id), app);
|
| | | } catch (NumberFormatException e) {
|
| | | e.printStackTrace();
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | try {
|
| | | goods = TaoKeApiUtil.searchGoodsDetail(Long.parseLong(id), app);
|
| | | } catch (NumberFormatException e) {
|
| | | e.printStackTrace();
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | if (goods != null) {
|
| | | String url = goods.getAuctionUrl();
|
| | | if (!StringUtil.isNullOrEmpty(goods.getCouponLink())) {
|
| | | url = goods.getCouponLink();
|
| | | }
|
| | | token = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), url);
|
| | | }
|
| | | }
|
| | |
|
| | | if (goods == null) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("商品信息获取失败")));
|
| | | return;
|
| | | }
|
| | |
|
| | | // 券后价
|
| | | BigDecimal afterCouponPrice = TaoBaoUtil.getAfterUseCouplePrice(goods);
|
| | | TaoBaoLink link = null;
|
| | |
|
| | | if (shareHistory != null) {
|
| | | link = new TaoBaoLink();
|
| | | link.setTaoToken(shareHistory.getTkCode());
|
| | | } else {
|
| | | link = new TaoBaoLink();
|
| | | try {
|
| | | String url = goods.getCouponLink();
|
| | | if (StringUtil.isNullOrEmpty(url))
|
| | | url = goods.getAuctionUrl();
|
| | | String tbk = TaoKeApiUtil.getTKToken(goods.getPictUrl(), goods.getTitle(), url);
|
| | | link.setTaoToken(tbk);
|
| | | } catch (Exception e) {
|
| | | link = null;
|
| | | }
|
| | | }
|
| | | if (link == null) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("淘口令生成失败")));
|
| | | if (StringUtil.isNullOrEmpty(token)) {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("口令生成失败")));
|
| | | return;
|
| | | }
|
| | |
|
| | | // 券后价
|
| | | BigDecimal afterCouponPrice = TaoBaoUtil.getAfterUseCouplePrice(goods);
|
| | | TaoBaoLink link = new TaoBaoLink();
|
| | | link.setTaoToken(token);
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("title", goods.getTitle());
|
| | | if (goods.getImgList() == null)
|
| | | goods.setImgList(new ArrayList<>());
|
| | | goods.getImgList().add(0, goods.getPictUrl());
|
| | | goods.getImgList().add(0, TbImgUtil.getTBSizeImg(goods.getPictUrl(), 300));
|
| | | data.put("imgs", goods.getImgList());
|
| | | data.put("quanPrice", afterCouponPrice);
|
| | | data.put("zkPrice", goods.getZkPrice());
|
| | |
| | | data.put("reservePrice", goods.getReservePrice());
|
| | | data.put("shopType", goods.getUserType() == 1 ? 2 : 1);
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
|
| | |
|
| | | final String tempUid = uid;
|
| | | ThreadUtil.run(new Runnable() {
|
| | |
|
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | if (!StringUtil.isNullOrEmpty(tempUid))
|
| | | userShareGoodsGroupService.updateBrowseRecord(Long.parseLong(tempUid), Long.parseLong(id), 1);
|
| | | } catch (NumberFormatException e) {
|
| | | e.printStackTrace();
|
| | | } catch (UserShareGoodsRecordException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | });
|
| | | return;
|
| | | }
|
| | | }
|