fanli/src/main/java/com/yeshi/fanli/dao/taobao/ShareHotGoodsDao.java
@@ -22,4 +22,19 @@ return mongoTemplate.find(query, ShareHotGoods.class); } public void deleteByGoodsId(Long goodsId) { Query query = new Query(); Criteria ca = Criteria.where("goods.auctionId").is(goodsId); query.addCriteria(ca); List<ShareHotGoods> list = mongoTemplate.find(query, ShareHotGoods.class); if (list == null || list.size() == 0) { return; } for (ShareHotGoods shareHotGoods: list) { mongoTemplate.remove(shareHotGoods); } } } fanli/src/main/java/com/yeshi/fanli/exception/taobao/TaoKeApiException.java
@@ -17,6 +17,12 @@ public static final int CODE_API_ERROR = 3; // 其他错误 public static final int CODE_OTHER = 4; // 商品支持创建红包 public static final int CODE_TLJ_FORBIDDEN = 101; // 官方账户余额不足 public static final int CODE_TLJ_NO_MONEY = 102; private int code; private String msg; fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/ShareHotGoodsServiceImpl.java
@@ -36,4 +36,11 @@ public void deleteById(String id) { shareHotGoodsDao.delete(id); } @Override public void deleteByGoodsId(Long goodsId) { shareHotGoodsDao.deleteByGoodsId(goodsId); } } fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinRecordServiceImpl.java
@@ -24,11 +24,13 @@ import com.yeshi.fanli.entity.bus.user.UserMoneyExtra; import com.yeshi.fanli.entity.goods.CommonGoods; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.exception.taobao.TaoKeApiException; import com.yeshi.fanli.exception.tlj.UserTaoLiJinRecordException; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.goods.CommonGoodsService; import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService; import com.yeshi.fanli.service.inter.taobao.ShareHotGoodsService; import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService; import com.yeshi.fanli.service.inter.tlj.ConfigTaoLiJinService; import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinDetailService; @@ -93,6 +95,9 @@ @Resource private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService; @Resource private ShareHotGoodsService shareHotGoodsService; @Override public UserTaoLiJinRecord selectByPrimaryKey(Long id) { return userTaoLiJinRecordMapper.selectByPrimaryKey(id); @@ -232,22 +237,39 @@ if (origin == 1) { BigDecimal tljSelf = userMoneyExtra.getTljSelf(); if (tljSelf == null || tljSelf.compareTo(totalMoney) < 0) { throw new UserTaoLiJinRecordException(101, "红包余额不足"); throw new UserTaoLiJinRecordException(101, "自购红包余额不足"); } } // 分享时的红包余额 BigDecimal tlj = userMoneyExtra.getTlj(); if (tlj == null || tlj.compareTo(totalMoney) < 0) { throw new UserTaoLiJinRecordException(101, "红包余额不足"); throw new UserTaoLiJinRecordException(101, "分享红包余额不足"); } // 创建淘礼金红包 TaoLiJinDTO taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, name, perface, totalNum, sendStartTime, sendEndTime, useStartTime, useEndTime, pid); TaoLiJinDTO taoLiJinDTO = null; try { taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, name, perface, totalNum, sendStartTime, sendEndTime, useStartTime, useEndTime, pid); } catch (TaoKeApiException e) { LogHelper.errorDetailInfo(e); executor.execute(new Runnable() { @Override public void run() { if (e.getCode() == TaoKeApiException.CODE_TLJ_FORBIDDEN) { // 该商品不支持创建淘礼金红包 shareHotGoodsService.deleteByGoodsId(auctionId); } else if (e.getCode() == TaoKeApiException.CODE_TLJ_NO_MONEY) { // 官方玩法钱包余额不足 TODO } } }); } if (taoLiJinDTO == null) { throw new UserTaoLiJinRecordException(101, "红包创建失败"); throw new UserTaoLiJinRecordException(101, "淘宝API推广红包创建失败"); } // 保存记录 fanli/src/main/java/com/yeshi/fanli/service/inter/taobao/ShareHotGoodsService.java
@@ -28,4 +28,10 @@ */ public void deleteById(String id); /** * 根据商品id删除 * @param goodsId */ public void deleteByGoodsId(Long goodsId); } fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeApiUtil.java
@@ -1948,7 +1948,7 @@ // 淘礼金创建 public static TaoLiJinDTO createTaoLiJin(Long auctionId, String name, BigDecimal perface, int totalNum, Date sendStartTime, Date sendEndTime, Date useStartTime, Date useEndTime,String pid) { Date sendStartTime, Date sendEndTime, Date useStartTime, Date useEndTime,String pid) throws TaoKeApiException{ Map<String, String> map = new HashMap<>(); map.put("method", "taobao.tbk.dg.vegas.tlj.create"); map.put("adzone_id", pid.split("_")[3]); @@ -1981,6 +1981,7 @@ System.out.println(json); JSONObject root = json.optJSONObject("tbk_dg_vegas_tlj_create_response"); if (root != null && root.optJSONObject("result") != null) { if (root.optJSONObject("result").optBoolean("success")) { JSONObject modelJson = root.optJSONObject("result").optJSONObject("model"); TaoLiJinDTO dto = new TaoLiJinDTO(); @@ -1988,7 +1989,22 @@ dto.setSendUrl(modelJson.optString("send_url")); return dto; } // 接口返回异常 String msgCode = root.optJSONObject("result").optString("msg_code"); if (!StringUtil.isNullOrEmpty(msgCode)) { switch(msgCode){ case "FAIL_BIZ_ITEM_FORBIDDEN": throw new TaoKeApiException(TaoKeApiException.CODE_TLJ_FORBIDDEN, "该商品不支持创建淘礼金红包"); case "2": throw new TaoKeApiException(TaoKeApiException.CODE_TLJ_NO_MONEY, "官方玩法钱包余额不足"); default: return null; } } } } catch (TaoKeApiException e) { throw e; } catch (Exception e) { LogHelper.errorDetailInfo(e); }