| | |
| | | import org.yeshi.utils.entity.DateInfo; |
| | | import org.yeshi.utils.taobao.TbImgUtil; |
| | | |
| | | import com.aliyun.openservices.ons.api.Message; |
| | | import com.aliyun.openservices.ons.api.Producer; |
| | | import com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper; |
| | | import com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper; |
| | | import com.yeshi.fanli.dao.mybatis.order.CommonOrderTradeIdMapMapper; |
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper; |
| | | import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum; |
| | | import com.yeshi.fanli.dto.mq.order.body.OrderConfirmMQMsg; |
| | | import com.yeshi.fanli.dto.order.CommonOrderAddResultDTO; |
| | | import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; |
| | | import com.yeshi.fanli.entity.accept.AcceptData; |
| | |
| | | import com.yeshi.fanli.util.jd.JDApiUtil; |
| | | import com.yeshi.fanli.util.jd.JDUtil; |
| | | import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil; |
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory; |
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName; |
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil; |
| | | import com.yeshi.fanli.util.user.UserLevelUtil; |
| | |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | @Resource(name = "producer") |
| | | private Producer orderProducer; |
| | | |
| | | // 奖励订单图片 |
| | | public final static String PIC_REWARD = "http://img.flqapp.com/resource/order/order_state_reward.png"; |
| | |
| | | for (TaoBaoOrder taoBaoOrder : taoBaoOrders) { |
| | | CommonOrder newCommonOrder = CommonOrderFactory.create(taoBaoOrder); |
| | | CommonOrderGoods cog = new CommonOrderGoods(); |
| | | cog.setGoodsId(taoBaoOrder.getAuctionId() + ""); |
| | | cog.setGoodsType(Constant.SOURCE_TYPE_TAOBAO); |
| | | newCommonOrder.setCommonOrderGoods(cog); |
| | | |
| | | if ("饿了么".equalsIgnoreCase(taoBaoOrder.getOrderType())) { |
| | | cog.setGoodsId(taoBaoOrder.getTradeId() + ""); |
| | | cog.setGoodsType(Constant.SOURCE_TYPE_ELME); |
| | | cog.setPicture("http://img.flqapp.com/resource/goods/elme_picture_demo.png"); |
| | | cog.setTitle(taoBaoOrder.getTitle()); |
| | | newCommonOrder.setCommonOrderGoods(cog); |
| | | } else { |
| | | cog.setGoodsId(taoBaoOrder.getAuctionId() + ""); |
| | | cog.setGoodsType(Constant.SOURCE_TYPE_TAOBAO); |
| | | newCommonOrder.setCommonOrderGoods(cog); |
| | | } |
| | | newCommonOrder.setStateWholeOrder(wholeOrderState); |
| | | // 订单商品插入 |
| | | List<CommonOrderGoods> commonGoodsList = commonOrderGoodsMapper.listByGoodsIdAndGoodsType(cog.getGoodsId(), |
| | |
| | | if (commonGoodsList.size() <= 0)// 不存在就插入商品 |
| | | { |
| | | TaoBaoGoodsBrief taoBaoGoods = null; |
| | | try { |
| | | taoBaoGoods = TaoKeApiUtil.getSimpleGoodsInfo(taoBaoOrder.getAuctionId()); |
| | | LogManager.getLogger(LogType.taobaoGoods).info(String.format("订单商品分类:%s#%s#%s", |
| | | taoBaoGoods.getAuctionId(), taoBaoGoods.getRootCategoryName(), taoBaoGoods.getLeafName())); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | LogHelper.errorDetailInfo(e, "AUCTIONID:" + taoBaoOrder.getAuctionId(), ""); |
| | | if (cog.getGoodsType() != Constant.SOURCE_TYPE_ELME) { |
| | | try { |
| | | taoBaoGoods = TaoBaoUtil.getSimpleGoodsBrief(taoBaoOrder.getAuctionId()); |
| | | // 记录商品分类 |
| | | taoBaoGoods = TaoKeApiUtil.getSimpleGoodsInfo(taoBaoOrder.getAuctionId()); |
| | | LogManager.getLogger(LogType.taobaoGoods) |
| | | .info(String.format("订单商品分类:%s#%s#%s", taoBaoGoods.getAuctionId(), |
| | | taoBaoGoods.getRootCategoryName(), taoBaoGoods.getLeafName())); |
| | | } catch (TaobaoGoodsDownException e) { |
| | | e.printStackTrace(); |
| | | LogHelper.errorDetailInfo(e, "AUCTIONID:" + taoBaoOrder.getAuctionId(), ""); |
| | | try { |
| | | taoBaoGoods = TaoBaoUtil.getSimpleGoodsBrief(taoBaoOrder.getAuctionId()); |
| | | // 记录商品分类 |
| | | |
| | | } catch (Exception e1) { |
| | | CommonGoods commonGoods = commonGoodsService.getCommonGoodsByGoodsIdAndGoodsType( |
| | | taoBaoOrder.getAuctionId(), Constant.SOURCE_TYPE_TAOBAO); |
| | | if (commonGoods != null) |
| | | taoBaoGoods = TaoBaoUtil.convert(commonGoods); |
| | | } catch (Exception e1) { |
| | | CommonGoods commonGoods = commonGoodsService.getCommonGoodsByGoodsIdAndGoodsType( |
| | | taoBaoOrder.getAuctionId(), Constant.SOURCE_TYPE_TAOBAO); |
| | | if (commonGoods != null) |
| | | taoBaoGoods = TaoBaoUtil.convert(commonGoods); |
| | | } |
| | | } |
| | | } |
| | | if (taoBaoGoods != null) { |
| | |
| | | newCommonOrder.setUserInfo(new UserInfo(uid)); |
| | | commonOrderList.add(addCommonOrder(newCommonOrder)); |
| | | } |
| | | addConfirmMQMsg(commonOrderList); |
| | | return commonOrderList; |
| | | } |
| | | |
| | |
| | | newCommonOrder.setUserInfo(new UserInfo(uid)); |
| | | commonOrderList.add(addCommonOrder(newCommonOrder)); |
| | | } |
| | | addConfirmMQMsg(commonOrderList); |
| | | return commonOrderList; |
| | | } |
| | | |
| | | private void addConfirmMQMsg(List<CommonOrderAddResultDTO> resultList) { |
| | | |
| | | // 订单是否新增或者更新过 |
| | | boolean isAddOrUpdate = false; |
| | | for (CommonOrderAddResultDTO dto : resultList) |
| | | if (dto.getType() == CommonOrderAddResultDTO.TYPE_ADD |
| | | || dto.getType() == CommonOrderAddResultDTO.TYPE_UPDATE) { |
| | | isAddOrUpdate = true; |
| | | break; |
| | | } |
| | | boolean hasSettleOrder = false; |
| | | // 查询是否有结算的订单 |
| | | if (isAddOrUpdate) { |
| | | for (CommonOrderAddResultDTO dto : resultList) { |
| | | if (dto.getCommonOrder().getSettleTime() != null && dto.getCommonOrder().getSettlement() != null) { |
| | | hasSettleOrder = true; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | // 有结算的订单 |
| | | if (hasSettleOrder) { |
| | | if (!Constant.IS_TEST) { |
| | | // 统计结算金额 |
| | | BigDecimal settlement = new BigDecimal("0"); |
| | | CommonOrder firstOrder = null; |
| | | for (CommonOrderAddResultDTO dto : resultList) |
| | | if (dto.getCommonOrder().getSettlement() != null) { |
| | | settlement = settlement.add(dto.getCommonOrder().getSettlement()); |
| | | if (firstOrder == null) |
| | | firstOrder = dto.getCommonOrder(); |
| | | } |
| | | if (firstOrder != null) { |
| | | Date placeDate = firstOrder.getThirdCreateTime(); |
| | | OrderConfirmMQMsg mqMsg = new OrderConfirmMQMsg(firstOrder.getOrderNo(), firstOrder.getSourceType(), |
| | | settlement, firstOrder.getUserInfo().getId(), placeDate, new Date()); |
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderConfirm, |
| | | mqMsg); |
| | | orderProducer.send(msg); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | newCommonOrder.setUserInfo(new UserInfo(uid)); |
| | | commonOrderList.add(addCommonOrder(newCommonOrder)); |
| | | } |
| | | addConfirmMQMsg(commonOrderList); |
| | | return commonOrderList; |
| | | } |
| | | |