| | |
| | | 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.pdd.PDDGoodsDetail;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserSystemCouponRecord;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.jd.JDGoods;
|
| | | import com.yeshi.fanli.entity.jd.JDOrder;
|
| | | import com.yeshi.fanli.entity.jd.JDOrderItem;
|
| | | import com.yeshi.fanli.entity.order.CommonOrder;
|
| | | import com.yeshi.fanli.entity.order.CommonOrderGoods;
|
| | | import com.yeshi.fanli.entity.order.CommonOrderTradeIdMap;
|
| | | import com.yeshi.fanli.entity.order.HongBaoOrder;
|
| | | import com.yeshi.fanli.entity.pdd.PDDOrder;
|
| | | import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
|
| | |
| | | import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
|
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.factory.CommonOrderGoodsFactory;
|
| | | import com.yeshi.fanli.util.factory.goods.CommonOrderFactory;
|
| | | import com.yeshi.fanli.util.jd.JDApiUtil;
|
| | | import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
| | |
|
| | | @Resource
|
| | | private CommonGoodsService commonGoodsService;
|
| | |
|
| | | @Resource
|
| | | private HongBaoOrderService hongBaoOrderService;
|
| | |
|
| | | // 奖励订单图片
|
| | | public final static String PIC_REWARD = "http://img.flqapp.com/resource/order/order_state_reward.png";
|
| | |
| | | wholeOrderState = CommonOrder.STATE_WHOLE_ORDER_BUFENYOUXIAO;
|
| | |
|
| | | for (TaoBaoOrder taoBaoOrder : taoBaoOrders) {
|
| | | CommonOrder commonOrder = commonOrderMapper.selectByOrderNoAndOrderTypeAndOrderBy(taoBaoOrder.getOrderId(),
|
| | | Constant.SOURCE_TYPE_TAOBAO, taoBaoOrder.getOrderBy());
|
| | | if (commonOrder == null)// 新增
|
| | | CommonOrder newCommonOrder = TaoBaoOrderUtil.convert(taoBaoOrder);
|
| | | CommonOrderGoods cog = new CommonOrderGoods();
|
| | | cog.setGoodsId(taoBaoOrder.getAuctionId() + "");
|
| | | cog.setGoodsType(Constant.SOURCE_TYPE_TAOBAO);
|
| | | newCommonOrder.setCommonOrderGoods(cog);
|
| | | newCommonOrder.setStateWholeOrder(wholeOrderState);
|
| | | // 订单商品插入
|
| | | List<CommonOrderGoods> commonGoodsList = commonOrderGoodsMapper.listByGoodsIdAndGoodsType(cog.getGoodsId(),
|
| | | cog.getGoodsType());
|
| | | if (commonGoodsList.size() <= 0)// 不存在就插入商品
|
| | | {
|
| | | commonOrder = TaoBaoOrderUtil.convert(taoBaoOrder);
|
| | | CommonOrderGoods goods = new CommonOrderGoods();
|
| | | goods.setGoodsId(taoBaoOrder.getAuctionId() + "");
|
| | | goods.setGoodsType(Constant.SOURCE_TYPE_TAOBAO);
|
| | |
|
| | | // 商品是否已经插入
|
| | | List<CommonOrderGoods> commonGoodsList = commonOrderGoodsMapper
|
| | | .listByGoodsIdAndGoodsType(goods.getGoodsId(), goods.getGoodsType());
|
| | | if (commonGoodsList.size() <= 0)// 不存在就插入商品
|
| | | {
|
| | | TaoBaoGoodsBrief taoBaoGoods = null;
|
| | | TaoBaoGoodsBrief taoBaoGoods = null;
|
| | | try {
|
| | | taoBaoGoods = TaoKeApiUtil.getSimpleGoodsInfo(taoBaoOrder.getAuctionId());
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | LogHelper.errorDetailInfo(e, "AUCTIONID:" + taoBaoOrder.getAuctionId(), "");
|
| | | try {
|
| | | taoBaoGoods = TaoKeApiUtil.getSimpleGoodsInfo(taoBaoOrder.getAuctionId());
|
| | | } 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);
|
| | | }
|
| | | 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);
|
| | | }
|
| | | if (taoBaoGoods != null) {
|
| | | goods = CommonOrderGoodsFactory.create(taoBaoGoods);
|
| | | }
|
| | | goods.setCreateTime(new Date());
|
| | | goods.setUpdateTime(new Date());
|
| | | commonOrderGoodsMapper.insertSelective(goods);
|
| | | } else
|
| | | goods.setId(commonGoodsList.get(commonGoodsList.size() - 1).getId());
|
| | | commonOrder.setCommonOrderGoods(goods);
|
| | | commonOrder.setUserInfo(new UserInfo(uid));
|
| | | commonOrder.setCreateTime(new Date());
|
| | | commonOrder.setStateWholeOrder(wholeOrderState);
|
| | | commonOrderMapper.insertSelective(commonOrder);
|
| | |
|
| | | // 插入映射,保证交易ID的完整性
|
| | | commonOrderTradeIdMapMapper.insertSelective(new CommonOrderTradeIdMap(commonOrder.getId(),
|
| | | commonOrder.getTradeId(), new Date(), commonOrder.getSourceType()));
|
| | |
|
| | | commonOrderList.add(commonOrder);
|
| | | continue;
|
| | | } else {// 修改
|
| | | // 已经结算或者已经失效的订单不处理
|
| | | if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_SX) {
|
| | | commonOrderList.add(commonOrder);
|
| | | continue;
|
| | | }
|
| | | CommonOrder newCommonOrder = TaoBaoOrderUtil.convert(taoBaoOrder);
|
| | |
|
| | | // 交易ID一致才修改
|
| | | if (commonOrder.getTradeId() != null
|
| | | && commonOrder.getTradeId().equalsIgnoreCase(newCommonOrder.getTradeId())) {
|
| | |
|
| | | CommonOrder updateCommonOrder = new CommonOrder(commonOrder.getId());
|
| | | updateCommonOrder.seteIncome(newCommonOrder.geteIncome());
|
| | | updateCommonOrder.setEstimate(newCommonOrder.getEstimate());
|
| | | updateCommonOrder.setPayment(newCommonOrder.getPayment());
|
| | | updateCommonOrder.setSettlement(newCommonOrder.getSettlement());
|
| | | updateCommonOrder.setSettleTime(newCommonOrder.getSettleTime());
|
| | | updateCommonOrder.setState(newCommonOrder.getState());
|
| | | updateCommonOrder.setStateWholeOrder(wholeOrderState);
|
| | | updateCommonOrder.setUpdateTime(new Date());
|
| | | updateCommonOrder.setTradeId(newCommonOrder.getTradeId());
|
| | | commonOrderMapper.updateByPrimaryKeySelective(updateCommonOrder);
|
| | | commonOrderList.add(commonOrderMapper.selectByPrimaryKey(updateCommonOrder.getId()));
|
| | | } else
|
| | | commonOrderList.add(commonOrder);
|
| | | if (taoBaoGoods != null) {
|
| | | cog = CommonOrderGoodsFactory.create(taoBaoGoods);
|
| | | }
|
| | | cog.setCreateTime(new Date());
|
| | | cog.setUpdateTime(new Date());
|
| | | commonOrderGoodsMapper.insertSelective(cog);
|
| | | }
|
| | | newCommonOrder.setUserInfo(new UserInfo(uid));
|
| | | commonOrderList.add(addCommonOrder(newCommonOrder));
|
| | | }
|
| | | return commonOrderList;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public List<CommonOrder> addPDDOrder(List<PDDOrder> pddOrderList, Long uid) throws CommonOrderException {
|
| | | List<CommonOrder> commonOrderList = new ArrayList<>();
|
| | | // 判断所有的订单状态
|
| | | int invalidCount = 0;
|
| | | for (PDDOrder order : pddOrderList) {
|
| | | if (order.getOrderStatus() == -1 || order.getOrderStatus() == 4 || order.getOrderStatus() == 8) {
|
| | | invalidCount++;
|
| | | }
|
| | | }
|
| | | // 获取整体订单的状态
|
| | | int wholeOrderState = 0;
|
| | | if (pddOrderList.size() == invalidCount)
|
| | | wholeOrderState = CommonOrder.STATE_WHOLE_ORDER_SHIXIAO;
|
| | | else if (invalidCount == 0)
|
| | | wholeOrderState = CommonOrder.STATE_WHOLE_ORDER_YOUXIAO;
|
| | | else
|
| | | wholeOrderState = CommonOrder.STATE_WHOLE_ORDER_BUFENYOUXIAO;
|
| | |
|
| | | for (PDDOrder pddOrder : pddOrderList) {
|
| | | CommonOrder newCommonOrder = CommonOrderFactory.create(pddOrder);
|
| | | CommonOrderGoods cog = new CommonOrderGoods();
|
| | | cog.setGoodsId(pddOrder.getGoodsId() + "");
|
| | | cog.setGoodsType(Constant.SOURCE_TYPE_PDD);
|
| | | newCommonOrder.setCommonOrderGoods(cog);
|
| | | newCommonOrder.setStateWholeOrder(wholeOrderState);
|
| | | // 订单商品插入
|
| | | List<CommonOrderGoods> commonGoodsList = commonOrderGoodsMapper.listByGoodsIdAndGoodsType(cog.getGoodsId(),
|
| | | cog.getGoodsType());
|
| | | if (commonGoodsList.size() <= 0)// 不存在就插入商品
|
| | | {
|
| | | PDDGoodsDetail pddGoods = null;
|
| | | pddGoods = PinDuoDuoApiUtil.getGoodsDetail(Long.parseLong(cog.getGoodsId()));
|
| | | if (pddGoods != null) {
|
| | | cog = CommonOrderGoodsFactory.create(pddGoods);
|
| | | }
|
| | | cog.setCreateTime(new Date());
|
| | | cog.setUpdateTime(new Date());
|
| | | commonOrderGoodsMapper.insertSelective(cog);
|
| | | newCommonOrder.setCommonOrderGoods(cog);
|
| | | }
|
| | | newCommonOrder.setUserInfo(new UserInfo(uid));
|
| | | commonOrderList.add(addCommonOrder(newCommonOrder));
|
| | | }
|
| | | return commonOrderList;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public List<CommonOrder> addJDOrder(JDOrder jdOrder, Long uid) throws CommonOrderException {
|
| | | List<CommonOrder> commonOrderList = new ArrayList<>();
|
| | | // 判断所有的订单状态
|
| | | int invalidCount = 0;
|
| | | for (JDOrderItem tb : jdOrder.getOrderItemList()) {
|
| | | if (tb.getValidCode() < 16) {
|
| | | invalidCount++;
|
| | | }
|
| | | }
|
| | |
|
| | | // 获取整体订单的状态
|
| | | int wholeOrderState = 0;
|
| | | if (jdOrder.getOrderItemList().size() == invalidCount)
|
| | | wholeOrderState = CommonOrder.STATE_WHOLE_ORDER_SHIXIAO;
|
| | | else if (invalidCount == 0)
|
| | | wholeOrderState = CommonOrder.STATE_WHOLE_ORDER_YOUXIAO;
|
| | | else
|
| | | wholeOrderState = CommonOrder.STATE_WHOLE_ORDER_BUFENYOUXIAO;
|
| | |
|
| | | List<JDOrderItem> orderItemList = jdOrder.getOrderItemList();
|
| | | jdOrder.setOrderItemList(null);
|
| | |
|
| | | for (JDOrderItem itemOrder : orderItemList) {
|
| | | itemOrder.setOrder(jdOrder);
|
| | | CommonOrder newCommonOrder = CommonOrderFactory.create(itemOrder);
|
| | | CommonOrderGoods cog = new CommonOrderGoods();
|
| | | cog.setGoodsId(itemOrder.getSkuId() + "");
|
| | | cog.setGoodsType(Constant.SOURCE_TYPE_JD);
|
| | | newCommonOrder.setCommonOrderGoods(cog);
|
| | | newCommonOrder.setStateWholeOrder(wholeOrderState);
|
| | | // 订单商品插入
|
| | | List<CommonOrderGoods> commonGoodsList = commonOrderGoodsMapper.listByGoodsIdAndGoodsType(cog.getGoodsId(),
|
| | | cog.getGoodsType());
|
| | | if (commonGoodsList.size() <= 0)// 不存在就插入商品
|
| | | {
|
| | | JDGoods goods = JDApiUtil.getGoodsDetail(itemOrder.getSkuId());
|
| | |
|
| | | if (goods != null) {
|
| | | cog = CommonOrderGoodsFactory.create(goods);
|
| | | }
|
| | | cog.setCreateTime(new Date());
|
| | | cog.setUpdateTime(new Date());
|
| | | commonOrderGoodsMapper.insertSelective(cog);
|
| | | }
|
| | | newCommonOrder.setUserInfo(new UserInfo(uid));
|
| | | commonOrderList.add(addCommonOrder(newCommonOrder));
|
| | | }
|
| | | return commonOrderList;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 添加订单
|
| | | * |
| | | * @param commonOrder
|
| | | */
|
| | | @Transactional
|
| | | private CommonOrder addCommonOrder(CommonOrder commonOrder) throws CommonOrderException {
|
| | | // 判断商品是否存在
|
| | | if (commonOrder == null)
|
| | | throw new CommonOrderException(1, "订单为空");
|
| | | if (commonOrder.getUserInfo() == null)
|
| | | throw new CommonOrderException(2, "订单用户为空");
|
| | |
|
| | | if (commonOrder.getCommonOrderGoods() == null || commonOrder.getCommonOrderGoods().getGoodsId() == null
|
| | | || commonOrder.getCommonOrderGoods().getGoodsType() == null)
|
| | | throw new CommonOrderException(3, "订单商品为空");
|
| | | // 不存在就插入,存在就不管
|
| | | CommonOrderGoods goods = commonOrder.getCommonOrderGoods();
|
| | |
|
| | | // 之前不存在于数据库
|
| | | if (commonOrder.getCommonOrderGoods().getId() == null) {
|
| | | List<CommonOrderGoods> commonGoodsList = commonOrderGoodsMapper
|
| | | .listByGoodsIdAndGoodsType(goods.getGoodsId(), goods.getGoodsType());
|
| | |
|
| | | if (commonGoodsList == null || commonGoodsList.size() < 1) {// 不存在
|
| | | commonOrderGoodsMapper.insertSelective(goods);
|
| | | } else {// 存在
|
| | | goods = commonGoodsList.get(0);
|
| | | }
|
| | | if (goods.getId() == null)
|
| | | throw new CommonOrderException(4, "商品插入失败");
|
| | | commonOrder.setCommonOrderGoods(goods);
|
| | | }
|
| | |
|
| | | CommonOrder oldCommonOrder = null;
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(commonOrder.getTradeId()))
|
| | | oldCommonOrder = commonOrderMapper.selectBySourceTypeAndTradeId(commonOrder.getSourceType(),
|
| | | commonOrder.getTradeId());
|
| | | else
|
| | | oldCommonOrder = commonOrderMapper.selectByOrderNoAndOrderTypeAndOrderBy(commonOrder.getOrderNo(),
|
| | | commonOrder.getSourceType(), commonOrder.getOrderBy());
|
| | |
|
| | | if (oldCommonOrder == null)// 新增
|
| | | {
|
| | | commonOrder.setCreateTime(new Date());
|
| | | commonOrderMapper.insertSelective(commonOrder);
|
| | | // 插入映射,保证交易ID的完整性
|
| | | commonOrderTradeIdMapMapper.insertSelective(new CommonOrderTradeIdMap(commonOrder.getId(),
|
| | | commonOrder.getTradeId(), new Date(), commonOrder.getSourceType()));
|
| | | return commonOrder;
|
| | | } else {// 修改
|
| | | // 已经结算,已经失效,状态未改变的订单不处理
|
| | | if (oldCommonOrder.getState() == CommonOrder.STATE_JS || oldCommonOrder.getState() == CommonOrder.STATE_SX
|
| | | || (oldCommonOrder.getState().intValue() == commonOrder.getState())) {
|
| | | return oldCommonOrder;
|
| | | }
|
| | | // 交易ID一致才修改
|
| | | if (commonOrder.getTradeId() != null
|
| | | && commonOrder.getTradeId().equalsIgnoreCase(oldCommonOrder.getTradeId())) {
|
| | | CommonOrder updateCommonOrder = new CommonOrder(oldCommonOrder.getId());
|
| | | updateCommonOrder.seteIncome(commonOrder.geteIncome());
|
| | | updateCommonOrder.setEstimate(commonOrder.getEstimate());
|
| | | updateCommonOrder.setPayment(commonOrder.getPayment());
|
| | | updateCommonOrder.setSettlement(commonOrder.getSettlement());
|
| | | updateCommonOrder.setSettleTime(commonOrder.getSettleTime());
|
| | | updateCommonOrder.setState(commonOrder.getState());
|
| | | updateCommonOrder.setStateWholeOrder(commonOrder.getStateWholeOrder());
|
| | | updateCommonOrder.setUpdateTime(new Date());
|
| | | updateCommonOrder.setTradeId(commonOrder.getTradeId());
|
| | | commonOrderMapper.updateByPrimaryKeySelective(updateCommonOrder);
|
| | | return commonOrderMapper.selectByPrimaryKey(updateCommonOrder.getId());
|
| | | } else
|
| | | return oldCommonOrder;
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | |
|
| | | return commonOrderMapper.selectBySourceTypeAndTradeId(sourceType, tradeId);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void deleteErrorCommonOrder(Long coId) {
|
| | | // 查询是否返利到账
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(coId);
|
| | | if (hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_YILINGQU)
|
| | | return;
|
| | | List<HongBaoV2> hongBaoList = hongBaoV2Service.listChildrenById(hongBaoOrder.getHongBaoV2().getId());
|
| | | boolean canDelete = true;
|
| | | for (HongBaoV2 child : hongBaoList)
|
| | | if (child.getState() == HongBaoV2.STATE_YILINGQU) {
|
| | | canDelete = false;
|
| | | break;
|
| | | }
|
| | | // 不能删除
|
| | | if (!canDelete)
|
| | | return;
|
| | |
|
| | | // 删除child
|
| | | for (HongBaoV2 child : hongBaoList)
|
| | | hongBaoV2Service.deleteByPrimaryKey(child.getId());
|
| | | // 删除主红包
|
| | | hongBaoV2Service.deleteByPrimaryKey(hongBaoOrder.getHongBaoV2().getId());
|
| | | // 删除hongbaoOrder
|
| | | hongBaoOrderService.deleteByPrimaryKey(hongBaoOrder.getId());
|
| | | // 删除CommonOrder
|
| | | commonOrderMapper.deleteByPrimaryKey(hongBaoOrder.getCommonOrder().getId());
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<CommonOrder> listBySourceTypeAndTradeId(int sourceType, String tradeId) {
|
| | | return commonOrderMapper.listBySourceTypeAndTradeId(sourceType, tradeId);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<CommonOrder> listBySourceTypeAndStateAndThirdCrateTime(int sourceType, Integer state, Long minTime,
|
| | | Long maxTime, int page, int pageSize) {
|
| | | return commonOrderMapper.listBySourceTypeAndStateAndThirdCrateTime(sourceType, state, minTime, maxTime,
|
| | | (page - 1) * pageSize, pageSize);
|
| | | }
|
| | |
|
| | | }
|