| | |
| | | package com.yeshi.fanli.service.impl.order;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.HashSet;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.AccountDetailsMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.AccountMessageMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.HongBaoManageMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.MoneyRecordMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.PidOrderMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.ThreeSaleGiftMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.hongbao.HongBaoMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.OrderItemMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.OrderMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.share.PidUserMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.AccountDetails;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBao;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoExtra;
|
| | | import com.yeshi.fanli.entity.bus.user.MoneyRecord;
|
| | | import com.yeshi.fanli.entity.bus.user.Order;
|
| | | import com.yeshi.fanli.entity.bus.user.OrderItem;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.taobao.PidOrder;
|
| | | import com.yeshi.fanli.entity.taobao.PidUser;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
|
| | | import com.yeshi.fanli.entity.taobao.TaobaoOrderHongBao;
|
| | | import com.yeshi.fanli.exception.HongBaoException;
|
| | | import com.yeshi.fanli.exception.ObjectStateException;
|
| | | import com.yeshi.fanli.exception.OrderItemException;
|
| | | import com.yeshi.fanli.exception.TaoBaoWeiQuanException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.hongbao.AccountDetailsHongBaoMapService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
|
| | | import com.yeshi.fanli.service.inter.order.LostOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderItemServcie;
|
| | | import com.yeshi.fanli.service.inter.order.OrderProcessService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderService;
|
| | | import com.yeshi.fanli.service.inter.order.PidOrderService;
|
| | | import com.yeshi.fanli.service.inter.push.PushService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoOrderService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoWeiQuanDrawBackService;
|
| | | import com.yeshi.fanli.service.inter.user.UserNotificationService;
|
| | | import com.yeshi.fanli.util.CMQManager;
|
| | | import com.yeshi.fanli.util.HongBaoUtil;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.factory.AccountDetailsFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
|
| | |
|
| | | @Service
|
| | | public class OrderProcessServiceImpl implements OrderProcessService {
|
| | |
|
| | | @Resource
|
| | | private PidOrderMapper pidOrderMapper;
|
| | |
|
| | | @Resource
|
| | | private OrderMapper orderMapper;
|
| | |
|
| | | @Resource
|
| | | private PidUserMapper pidUserMapper;
|
| | |
|
| | | @Resource
|
| | | private HongBaoService hongBaoService;
|
| | |
|
| | | @Resource
|
| | | private OrderItemServcie orderItemService;
|
| | |
|
| | | @Resource
|
| | | private PidOrderService pidOrderService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoMapper userInfoMapper;
|
| | |
|
| | | @Resource
|
| | | private OrderItemMapper orderItemMapper;
|
| | |
|
| | | @Resource
|
| | | private HongBaoMapper hongBaoMapper;
|
| | |
|
| | | @Resource
|
| | | private HongBaoManageMapper hongBaoManageMapper;
|
| | |
|
| | | @Resource
|
| | | private AccountDetailsMapper accountDetailsMapper;
|
| | |
|
| | | @Resource
|
| | | private AccountMessageMapper accountMessageMapper;
|
| | |
|
| | | @Resource
|
| | | private MoneyRecordMapper moneyRecordMapper;
|
| | |
|
| | | @Resource
|
| | | private ThreeSaleGiftMapper threeSaleGiftMapper;
|
| | |
|
| | | @Resource
|
| | | private OrderService orderService;
|
| | |
|
| | | @Resource
|
| | | private PushService pushService;
|
| | |
|
| | | @Resource
|
| | | private UserNotificationService userNotificationService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoWeiQuanDrawBackService taoBaoWeiQuanDrawBackService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoOrderService taoBaoOrderService;
|
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
|
| | | @Resource
|
| | | private LostOrderService lostOrderService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoWeiQuanOrderMapper taoBaoWeiQuanOrderMapper;
|
| | |
|
| | | @Resource
|
| | | private HongBaoManageService hongBaoManageService;
|
| | |
|
| | | @Resource
|
| | | private AccountDetailsHongBaoMapService accountDetailsHongBaoMapService;
|
| | |
|
| | | @Override
|
| | | public void processOrder(Map<String, List<TaoBaoOrder>> orders) {
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | |
|
| | | // 分离出返利订单与分享赚订单
|
| | | Iterator<String> its = orders.keySet().iterator();
|
| | | Map<String, List<TaoBaoOrder>> fanliOrderMap = new HashMap<>();
|
| | | Map<String, List<PidOrder>> shareOrderMap = new HashMap<>();
|
| | | while (its.hasNext()) {
|
| | | String orderId = its.next();
|
| | | if (orders.get(orderId) != null && orders.get(orderId).size() > 0) {
|
| | | List<TaoBaoOrder> list = orders.get(orderId);
|
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(),
|
| | | list.get(0).getSourceMediaId(), list.get(0).getAdPositionId());
|
| | | PidUser pidUser = pidUserMapper.selectByPid(pid);
|
| | | if (pidUser != null && pidUser.getType() == PidUser.TYPE_SHARE_GOODS) {// 商品分享订单
|
| | | List<PidOrder> pidOrderList = new ArrayList<>();
|
| | | for (TaoBaoOrder order : list) {
|
| | | pidOrderList.add(TaoBaoOrderUtil.convertToPidOrder(order));
|
| | | }
|
| | | shareOrderMap.put(orderId, pidOrderList);
|
| | | } else {// 普通返利订单
|
| | | fanliOrderMap.put(orderId, list);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // 处理返利订单
|
| | | processShopingFanliOrder(fanliOrderMap);
|
| | | // 处理分享赚订单
|
| | | processShareGoodsOrder(shareOrderMap);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 利用redis的原子性将订单号锁住,不让其他处理
|
| | | * |
| | | * @param orderId
|
| | | */
|
| | | private void redisLockOrder(String orderId) {
|
| | | String key = "doorder-" + orderId;
|
| | | redisManager.cacheCommonString(key, "1");
|
| | | }
|
| | |
|
| | | /**
|
| | | * 订单解锁
|
| | | * |
| | | * @param orderId
|
| | | */
|
| | | private void redisUnlockOrder(String orderId) {
|
| | | String key = "doorder-" + orderId;
|
| | | redisManager.removeCommonString(key);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 订单是否被锁住了
|
| | | * |
| | | * @param orderId
|
| | | * @return
|
| | | */
|
| | | private boolean isRedisLockOrder(String orderId) {
|
| | | String key = "doorder-" + orderId;
|
| | | String doing = redisManager.getCommonString(key);
|
| | | if (!StringUtil.isNullOrEmpty(doing))
|
| | | return true;
|
| | | else
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void processShopingFanliOrder(Map<String, List<TaoBaoOrder>> orders) {
|
| | | // 查询在Order中是否存在该订单号
|
| | | Iterator<String> its = orders.keySet().iterator();
|
| | | while (its.hasNext()) {
|
| | | try {
|
| | | String orderId = its.next();
|
| | | // 处理红包与子红包
|
| | | // if (isRedisLockOrder(orderId))
|
| | | // continue;
|
| | | // redisLockOrder(orderId);
|
| | | processShopingFanliOrder(orderId, orders.get(orderId));
|
| | | // redisUnlockOrder(orderId);
|
| | | // 出错了就不处理该订单了,需要定期检查
|
| | |
|
| | | // 更改丢失订单的状态
|
| | | lostOrderService.processSuceess(orderId);
|
| | |
|
| | | } catch (HongBaoException e1) {
|
| | | e1.printStackTrace();
|
| | | } catch (OrderItemException e2) {
|
| | | e2.printStackTrace();
|
| | | } catch (Exception e) {
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void processShareGoodsOrder(Map<String, List<PidOrder>> orders) {
|
| | | pidOrderService.addPidOrderFromTaoBao(orders);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取最大的创建时间与最小的创建时间
|
| | | * |
| | | * @param hongBaoList
|
| | | * @return
|
| | | */
|
| | | private Map<String, Long> getMaxAndMinCreateTime(List<HongBao> hongBaoList) {
|
| | | if (hongBaoList.size() > 0) {
|
| | | Map<String, Long> map = new HashMap<>();
|
| | | long min = hongBaoList.get(0).getCreatetime();
|
| | | long max = hongBaoList.get(0).getCreatetime();
|
| | | for (HongBao hb : hongBaoList) {
|
| | | if (hb.getCreatetime() > max)
|
| | | max = hb.getCreatetime();
|
| | | if (hb.getCreatetime() < min)
|
| | | min = hb.getCreatetime();
|
| | | }
|
| | | map.put("max", max);
|
| | | map.put("min", min);
|
| | | return map;
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void fanli() {
|
| | | // 获取主红包
|
| | | List<HongBao> hongBaoList = hongBaoMapper.selectCanBalanceHongBaoByType(HongBao.TYPE_TAOBAO, 100);
|
| | | //
|
| | | // /**
|
| | | // * 需要实时更新待返利的订单
|
| | | // */
|
| | | //
|
| | | // // 计算最大的创建时间与最小的创建时间
|
| | | // Map<String, Long> map = getMaxAndMinCreateTime(hongBaoList);
|
| | | // if (map != null) {
|
| | | // long max = map.get("max");
|
| | | // long min = map.get("min");
|
| | | // // 最小时间提前10分钟
|
| | | // min = min - 1000 * 60 * 10L;
|
| | | // // 更新该段时间的订单
|
| | | // List<TaoBaoOrder> orderList = new ArrayList<>();
|
| | | // try {
|
| | | // orderList = TaoBaoOrderUtil.getOrderList(min, max);
|
| | | // } catch (TaoBaoOrderException e) {
|
| | | // e.printStackTrace();
|
| | | // }
|
| | | // // try {
|
| | | // if (orderList != null)
|
| | | // processOrder(TaoBaoOrderUtil.classifyTaoBaoOrderByOrderId(orderList));
|
| | | // // } catch (Exception e) {
|
| | | // // e.printStackTrace();
|
| | | // // try {
|
| | | // // LogHelper.errorDetailInfo(e);
|
| | | // // } catch (Exception e1) {
|
| | | // // e1.printStackTrace();
|
| | | // // }
|
| | | // // }
|
| | | // }
|
| | |
|
| | | /**
|
| | | * 开始返利
|
| | | */
|
| | | for (HongBao hb : hongBaoList) {
|
| | | //
|
| | | if (hb.getState() == HongBao.STATE_SHIXIAO || hb.getState() == HongBao.STATE_YILINGQU)
|
| | | continue;
|
| | |
|
| | | if (hb.getPreGettime() == null || hb.getPreGettime() == 0
|
| | | || hb.getPreGettime() > System.currentTimeMillis())
|
| | | continue;
|
| | | try {
|
| | | CMQManager.getInstance().addFanLiMsg(hb);
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 判断订单是否失效 全部订单失效才判断为失效
|
| | | * |
| | | * @param list
|
| | | * @return
|
| | | */
|
| | | private boolean isOrderValid(List<TaoBaoOrder> list) {
|
| | | int validCount = 0;
|
| | | for (TaoBaoOrder order : list) {
|
| | | if (order.getOrderState().equalsIgnoreCase("订单失效"))
|
| | | validCount++;
|
| | | }
|
| | | return validCount >= list.size();
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void processShopingFanliOrder(String orderId, List<TaoBaoOrder> orderList)
|
| | | throws HongBaoException, OrderItemException {
|
| | |
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | |
|
| | | Order oldOrder = orderMapper.selectOrderByOrderId(orderId);
|
| | | // 原来不存在订单
|
| | | if (oldOrder == null && orderList.size() > 0) {
|
| | | // 获取产生订单的PID
|
| | | String mediaId = orderList.get(0).getSourceMediaId();
|
| | | String adzoneId = orderList.get(0).getAdPositionId();
|
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), mediaId, adzoneId);
|
| | | // 查询该PID是否有对应的用户
|
| | | PidUser pidUser = pidUserMapper.selectByPid(pid);
|
| | | // 判断是否属于返利的PID
|
| | | if (pidUser != null && (pidUser.getType() == PidUser.TYPE_FANLI_ANDROID
|
| | | || pidUser.getType() == PidUser.TYPE_FANLI_IOS)) {
|
| | | // 如果是订单失效就不处理
|
| | | // 2018-08-02开始生效
|
| | | if (isOrderValid(orderList))
|
| | | if (TimeUtil.convertToTimeTemp(orderList.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss") < TimeUtil
|
| | | .convertToTimeTemp("2018-08-02", "yyyy-MM-dd"))
|
| | | return;
|
| | |
|
| | | // 添加到订单中去
|
| | | Order order = new Order();
|
| | | order.setBeizhu("PID返利订单");
|
| | | order.setCreatetime(System.currentTimeMillis());
|
| | | order.setOrderId(orderId);
|
| | | order.setOrderType(1);
|
| | | order.setState(Order.STATE_YIZHIFU);
|
| | | order.setUserInfo(new UserInfo(pidUser.getUid()));
|
| | | order.setVersion(2);
|
| | |
|
| | | // 加入到订单表
|
| | | orderMapper.insertSelective(order);
|
| | | oldOrder = order;
|
| | | }
|
| | | }
|
| | |
|
| | | if (oldOrder != null) {// 该订单号可以返利
|
| | | // 原来失效的订单不再处理
|
| | | // if (oldOrder.getState() == Order.STATE_SHIXIAO)
|
| | | // return;
|
| | | // 更新订单的状态
|
| | | Order updateOrder = new Order();
|
| | | updateOrder.setId(oldOrder.getId());
|
| | | updateOrder.setThirdCreateTime(
|
| | | new Date(TimeUtil.convertToTimeTemp(orderList.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss")));
|
| | |
|
| | | if (isOrderValid(orderList)) {
|
| | | // 处理订单失效
|
| | | updateOrder.setState(Order.STATE_SHIXIAO);
|
| | | if (oldOrder.getState() == Order.STATE_YIZHIFU)
|
| | | updateOrder.setDrawbackTime(System.currentTimeMillis());
|
| | | updateOrder.setThirdState("订单失效");
|
| | | } else// 计算订单的总金额
|
| | | {
|
| | | BigDecimal money = new BigDecimal(0);
|
| | | for (TaoBaoOrder o : orderList) {
|
| | | if (o.getOrderState().equalsIgnoreCase("订单结算"))
|
| | | money = money.add(o.getSettlement());
|
| | | else {
|
| | | money = money.add(o.getPayment());
|
| | | }
|
| | | }
|
| | | updateOrder.setMoney(money);
|
| | | String thirdState = null;
|
| | | for (TaoBaoOrder o : orderList)
|
| | | if (!o.getOrderState().equalsIgnoreCase("订单失效")) {
|
| | | thirdState = o.getOrderState();
|
| | | break;
|
| | | }
|
| | | updateOrder.setThirdState(thirdState);
|
| | | }
|
| | | orderMapper.updateByPrimaryKeySelective(updateOrder);
|
| | | Order order = oldOrder;
|
| | | // 订单返利比例
|
| | | BigDecimal rate = hongBaoManageService.getFanLiRate();
|
| | |
|
| | | // 查找是否存在红包
|
| | | List<HongBao> hongBaoList = hongBaoMapper.selectByOid(order.getId());
|
| | | // 还没有加入有效的订单
|
| | | if ((hongBaoList == null || hongBaoList.size() == 0)) {
|
| | | for (TaoBaoOrder taoBaoOrder : orderList) {
|
| | | // 创建OrderItem;
|
| | | OrderItem orderItem = orderItemService.addOrderItem(taoBaoOrder, order, rate);
|
| | | hongBaoService.addHongBao(order, taoBaoOrder, orderItem.getId());
|
| | | }
|
| | | } else if (hongBaoList.size() > 0)// 原来已经存在订单了
|
| | | {
|
| | | List<TaobaoOrderHongBao> sortList = HongBaoUtil.sortHongBaoAndTaoBaoOrder(orderList, hongBaoList);
|
| | | orderList = new ArrayList<>();
|
| | | hongBaoList = new ArrayList<>();
|
| | | if (sortList != null)
|
| | | for (TaobaoOrderHongBao tb : sortList) {
|
| | | orderList.add(tb.taoBaoOrder);
|
| | | hongBaoList.add(tb.hongBao);
|
| | | }
|
| | |
|
| | | if (orderList.size() != hongBaoList.size()) {
|
| | | LogHelper.userOrder("红包数和订单数不对等:" + orderId);
|
| | | return;
|
| | | }
|
| | |
|
| | | for (int i = 0; i < orderList.size(); i++) {
|
| | | hongBaoService.updateHongBao(hongBaoList.get(i), orderList.get(i));
|
| | | orderItemService.updateOrderItem(orderList.get(i), hongBaoList.get(i).getOrderItemId(), rate);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void fanli(HongBao hb) throws TaoBaoWeiQuanException {
|
| | | // 查询最新的红包数据
|
| | | hb = hongBaoMapper.selectByPrimaryKeyForUpdate(hb.getId());
|
| | | // 维权中的不返利
|
| | | List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper
|
| | | .selectListByOrderIdAndState(hb.getOrderId(), "维权创建");
|
| | | if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
|
| | | return;
|
| | |
|
| | | taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper.selectListByOrderIdAndState(hb.getOrderId(), "等待处理");
|
| | | if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
|
| | | return;
|
| | |
|
| | | long currentTimeMillis = System.currentTimeMillis();
|
| | | if (hb.getState() != HongBao.STATE_SHIXIAO) {
|
| | | // 设置为已返利
|
| | | // 处理主红包
|
| | | if (hb.getState() != HongBao.STATE_SHIXIAO && hb.getState() != HongBao.STATE_YILINGQU
|
| | | && hb.getType() == HongBao.TYPE_TAOBAO) {
|
| | | OrderItem orderItem = null;
|
| | | if (hb.getOrderItemId() != null) {
|
| | | orderItem = orderItemMapper.selectByPrimaryKey(hb.getOrderItemId());
|
| | | OrderItem updateOrderItem = new OrderItem();
|
| | | updateOrderItem.setId(orderItem.getId());
|
| | | updateOrderItem.setFanTime(currentTimeMillis);
|
| | | updateOrderItem.setState(OrderItem.STATE_DAOZHANG);
|
| | | orderItemMapper.updateByPrimaryKeySelective(updateOrderItem);
|
| | | }
|
| | | // 如果红包没被领取
|
| | | HongBao updateHongBao = new HongBao();
|
| | | updateHongBao.setId(hb.getId());
|
| | | updateHongBao.setState(HongBao.STATE_YILINGQU);
|
| | | updateHongBao.setGetTime(currentTimeMillis);
|
| | | hongBaoMapper.updateByPrimaryKeySelective(updateHongBao);
|
| | | userInfoMapper.addHongBaoByUid(hb.getUserInfo().getId(), hb.getMoney());
|
| | |
|
| | | // ...消息、明细
|
| | | HongBaoExtra hongBaoExtra = HongBaoUtil.convert(hb);
|
| | | // 明细操作(如果服务器性好了后,可改成异步)
|
| | | MoneyRecord moneyRecord = new MoneyRecord(hb.getUserInfo(), hb, hb.getMoney(), hongBaoExtra.getTitle(),
|
| | | "", currentTimeMillis, 1);
|
| | | moneyRecordMapper.insertSelective(moneyRecord);
|
| | | AccountDetails accountDetails = AccountDetailsFactory.create("+" + hb.getMoney(),
|
| | | AccountDetailsFactory.FANLI, orderItem, null, hb.getUserInfo());
|
| | | accountDetailsMapper.insertSelective(accountDetails);
|
| | |
|
| | | // 添加资金明细与红包的映射关系
|
| | | accountDetailsHongBaoMapService.saveAccountDetailsHongBaoMap(hb.getId(), accountDetails.getId());
|
| | |
|
| | | // 维权扣款(2018-08-05后开始实行)
|
| | | if (hb.getBalanceTime() != null
|
| | | && hb.getBalanceTime().getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanFanli(hb.getOrderId());
|
| | | }
|
| | |
|
| | | // 站内信+推送
|
| | | try {
|
| | | userNotificationService.orderFanliRecieved(hb.getUserInfo().getId(), orderItem.getOrderId(),
|
| | | orderItem.getFanMoney());
|
| | | } catch (Exception e) {
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void weiQuanOrder(List<TaoBaoWeiQuanOrder> orderList) {
|
| | | if (orderList != null)
|
| | | for (TaoBaoWeiQuanOrder order : orderList) {
|
| | | if (order.getState().equalsIgnoreCase("维权成功")) {
|
| | | CMQManager.getInstance().addWeiQuanOrderMsg(order);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void weiQuanOrder(TaoBaoWeiQuanOrder order) {
|
| | | // 订单结算时间在2018-08-05后就不处理维权了
|
| | |
|
| | | List<TaoBaoOrder> orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(order.getOrderId());
|
| | | if (orderList != null && orderList.size() > 0 & !StringUtil.isNullOrEmpty(orderList.get(0).getSettlementTime()))
|
| | | order.setJieSuanTime(
|
| | | new Date(TimeUtil.convertToTimeTemp(orderList.get(0).getSettlementTime(), "yyyy-MM-dd HH:mm:ss")));
|
| | | if (order.getJieSuanTime().getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
|
| | | return;
|
| | | }
|
| | | try {
|
| | | orderService.failureOrderWithWeiQuan(order.getOrderId(), Order.ORDER_TYPE_TAOBAO);
|
| | | } catch (ObjectStateException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | pidOrderService.weiQuan(order.getOrderId());
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void fanliInvaiteAndShare() {
|
| | | // 查出邀请赚与分享赚该返利的用户ID
|
| | | List<Long> shareUids = pidOrderMapper.getUidCanBalanceList();
|
| | | List<Long> inviteUids = hongBaoMapper.selectUidCanBalanceHongBaoByChildHongBao();
|
| | | Set<Long> uidSets = new HashSet<>();
|
| | | if (shareUids != null)
|
| | | for (Long uid : shareUids)
|
| | | uidSets.add(uid);
|
| | | if (inviteUids != null)
|
| | | for (Long uid : inviteUids)
|
| | | uidSets.add(uid);
|
| | | // 根据用户ID
|
| | | Iterator<Long> its = uidSets.iterator();
|
| | | while (its.hasNext()) {
|
| | | Long uid = its.next();
|
| | | try {
|
| | | CMQManager.getInstance().addFanLiTiChengMsg(uid);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | LogHelper.error(e);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private HongBao filterWeiQuanINGHongBao(HongBao hongBao) {
|
| | |
|
| | | List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper
|
| | | .selectListByOrderIdAndState(hongBao.getOrderId(), "维权创建");
|
| | |
|
| | | List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList1 = taoBaoWeiQuanOrderMapper
|
| | | .selectListByOrderIdAndState(hongBao.getOrderId(), "等待处理");
|
| | | if ((taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
|
| | | || (taoBaoWeiQuanList1 != null && taoBaoWeiQuanList1.size() > 0)) {
|
| | | return null;
|
| | | }
|
| | | return hongBao;
|
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void fanliInvaiteAndShare(Long uid) throws TaoBaoWeiQuanException {
|
| | | /**
|
| | | * 处理邀请赚订单
|
| | | */
|
| | | // 查询UID的邀请赚订单
|
| | | List<HongBao> hongBaoList = hongBaoMapper.selectCanBalanceHongBaoByChildHongBaoAndUid(uid);
|
| | |
|
| | | List<Long> hbIdList = new ArrayList<>();
|
| | |
|
| | | BigDecimal money = new BigDecimal(0);
|
| | | // 需要判断退款的订单号
|
| | | Set<String> drawBackOrders = new HashSet<String>();
|
| | | for (HongBao hongBao : hongBaoList) {
|
| | | hongBao = filterWeiQuanINGHongBao(hongBao);
|
| | | if (hongBao == null)
|
| | | continue;
|
| | |
|
| | | hongBao = hongBaoMapper.selectByPrimaryKeyForUpdate(hongBao.getId());
|
| | | if (hongBao.getState() == HongBao.STATE_BUKELINGQU || hongBao.getState() == HongBao.STATE_KELINGQU) {
|
| | | money = money.add(hongBao.getMoney());
|
| | | HongBao updateHongBao = new HongBao();
|
| | | updateHongBao.setId(hongBao.getId());
|
| | | updateHongBao.setGetTime(System.currentTimeMillis());
|
| | | updateHongBao.setState(HongBao.STATE_YILINGQU);
|
| | | hongBaoMapper.updateByPrimaryKeySelective(updateHongBao);
|
| | | // 添加到红包返利记录集合
|
| | | hbIdList.add(hongBao.getId());
|
| | | // 2018-08-05 过后的订单才处理维权
|
| | | Date balanceTime = null;
|
| | | if (hongBao.getParent() != null)
|
| | | balanceTime = hongBao.getParent().getBalanceTime();
|
| | | else
|
| | | balanceTime = hongBao.getBalanceTime();
|
| | | if (balanceTime != null
|
| | | && balanceTime.getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
|
| | | if (!StringUtil.isNullOrEmpty(hongBao.getOrderId()))
|
| | | drawBackOrders.add(hongBao.getOrderId());
|
| | | else if (hongBao.getParent() != null && !StringUtil.isNullOrEmpty(hongBao.getParent().getOrderId()))
|
| | | drawBackOrders.add(hongBao.getParent().getOrderId());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 处理顶级分享赚
|
| | | */
|
| | |
|
| | | // 查询UID的分享赚订单
|
| | | List<PidOrder> pidOrderList = pidOrderMapper.getCanBalanceListByUid(uid);
|
| | | for (PidOrder pidOrder : pidOrderList) {
|
| | | HongBao hongBao = hongBaoMapper.selectByPrimaryKeyForUpdate(pidOrder.getHongBao().getId());
|
| | | hongBao = filterWeiQuanINGHongBao(hongBao);
|
| | | if (hongBao == null)
|
| | | continue;
|
| | | if (hongBao.getState() == HongBao.STATE_BUKELINGQU || hongBao.getState() == HongBao.STATE_KELINGQU) {
|
| | | money = money.add(hongBao.getMoney());
|
| | | HongBao updateHongBao = new HongBao();
|
| | | updateHongBao.setId(hongBao.getId());
|
| | | updateHongBao.setGetTime(System.currentTimeMillis());
|
| | | updateHongBao.setState(HongBao.STATE_YILINGQU);
|
| | | hongBaoMapper.updateByPrimaryKeySelective(updateHongBao);
|
| | | // 添加到红包返利记录集合
|
| | | hbIdList.add(hongBao.getId());
|
| | | // 2018-08-05 过后的订单才处理维权
|
| | | Date balanceTime = null;
|
| | | if (hongBao.getParent() != null)
|
| | | balanceTime = hongBao.getParent().getBalanceTime();
|
| | | else
|
| | | balanceTime = hongBao.getBalanceTime();
|
| | | if (balanceTime != null
|
| | | && balanceTime.getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
|
| | | drawBackOrders.add(pidOrder.getOrderId());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 处理一级二级分享赚
|
| | | */
|
| | |
|
| | | List<HongBao> totalHongBaoList = new ArrayList<>();
|
| | | // 查询UID的二级或者三级分享赚订单
|
| | | // TODO 暂时查询10000条数据,后面再做分页
|
| | | List<HongBao> hbList = hongBaoMapper.selectCanBalanceHongBaoByTypeAndUid(HongBao.TYPE_SHARE_YIJI, uid, 10000);
|
| | |
|
| | | if (hbList != null && hbList.size() > 0)
|
| | | totalHongBaoList.addAll(hbList);
|
| | |
|
| | | hbList = hongBaoMapper.selectCanBalanceHongBaoByTypeAndUid(HongBao.TYPE_SHARE_ERJI, uid, 10000);
|
| | | if (hbList != null && hbList.size() > 0)
|
| | | totalHongBaoList.addAll(hbList);
|
| | |
|
| | | for (HongBao hb : totalHongBaoList) {
|
| | | if (hb.getState() == HongBao.STATE_BUKELINGQU || hb.getState() == HongBao.STATE_KELINGQU) {
|
| | | hb = filterWeiQuanINGHongBao(hb);
|
| | | if (hb == null)
|
| | | continue;
|
| | | money = money.add(hb.getMoney());
|
| | | HongBao updateHongBao = new HongBao();
|
| | | updateHongBao.setId(hb.getId());
|
| | | updateHongBao.setGetTime(System.currentTimeMillis());
|
| | | updateHongBao.setState(HongBao.STATE_YILINGQU);
|
| | | hongBaoMapper.updateByPrimaryKeySelective(updateHongBao);
|
| | | // 添加到红包返利记录集合
|
| | | hbIdList.add(hb.getId());
|
| | | if (!StringUtil.isNullOrEmpty(hb.getOrderId()))
|
| | | drawBackOrders.add(hb.getOrderId());
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 增加用户资金记录
|
| | | */
|
| | |
|
| | | if (money.compareTo(new BigDecimal(0)) > 0) {
|
| | | userInfoMapper.addHongBaoByUid(uid, money);
|
| | | // 添加记录
|
| | | AccountDetails accountDetails = AccountDetailsFactory.create("+" + money, AccountDetailsFactory.TICHENG,
|
| | | null, null, new UserInfo(uid));
|
| | | accountDetailsMapper.insertSelective(accountDetails);
|
| | | // 记录返利红包与资金详情的对应关系
|
| | |
|
| | | // 添加到红包返利记录集合
|
| | | accountDetailsHongBaoMapService.saveAccountDetailsHongBaoMap(hbIdList, accountDetails.getId());
|
| | |
|
| | | // 发送推送
|
| | | try {
|
| | | // 提成到账消息通知
|
| | | userNotificationService.tiChengRecieved(uid, money);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | for (String orderId : drawBackOrders)
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanShare(orderId);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.order; |
| | | |
| | | import com.aliyun.openservices.ons.api.Message; |
| | | import com.aliyun.openservices.ons.api.transaction.LocalTransactionExecuter; |
| | | import com.aliyun.openservices.ons.api.transaction.TransactionProducer; |
| | | import com.aliyun.openservices.ons.api.transaction.TransactionStatus; |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper; |
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper; |
| | | import com.yeshi.fanli.dao.mybatis.order.HongBaoOrderMapper; |
| | | import com.yeshi.fanli.dao.mybatis.order.OrderMapper; |
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper; |
| | | import com.yeshi.fanli.dto.mq.UidDateDTO; |
| | | import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum; |
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMQMsg; |
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg; |
| | | import com.yeshi.fanli.dto.order.CommonOrderAddResultDTO; |
| | | import com.yeshi.fanli.dto.order.HongBaoAddResult; |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.SystemPIDInfo; |
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2; |
| | | import com.yeshi.fanli.entity.bus.user.Order; |
| | | import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.entity.dy.DYOrder; |
| | | import com.yeshi.fanli.entity.elme.ElmeHongBaoOrderMap; |
| | | import com.yeshi.fanli.entity.elme.ElmeOrder; |
| | | import com.yeshi.fanli.entity.jd.JDOrder; |
| | | import com.yeshi.fanli.entity.jd.JDOrderItem; |
| | | import com.yeshi.fanli.entity.money.UserMoneyDetail; |
| | | import com.yeshi.fanli.entity.order.CommonOrder; |
| | | import com.yeshi.fanli.entity.order.HongBaoOrder; |
| | | import com.yeshi.fanli.entity.pdd.PDDOrder; |
| | | import com.yeshi.fanli.entity.suning.SuningOrderInfo; |
| | | import com.yeshi.fanli.entity.taobao.*; |
| | | import com.yeshi.fanli.entity.vipshop.VipShopOrder; |
| | | import com.yeshi.fanli.entity.vipshop.VipShopOrderDetail; |
| | | import com.yeshi.fanli.exception.elme.ElmeOrderException; |
| | | import com.yeshi.fanli.exception.money.OrderMoneySettleException; |
| | | import com.yeshi.fanli.exception.money.UserMoneyDetailException; |
| | | import com.yeshi.fanli.exception.order.CommonOrderException; |
| | | import com.yeshi.fanli.exception.order.HongBaoException; |
| | | import com.yeshi.fanli.exception.order.OrderItemException; |
| | | import com.yeshi.fanli.exception.order.TaoBaoWeiQuanException; |
| | | import com.yeshi.fanli.exception.user.UserAccountException; |
| | | import com.yeshi.fanli.log.LogHelper; |
| | | import com.yeshi.fanli.log.OrderLogHelper; |
| | | import com.yeshi.fanli.service.inter.elme.ElmeHongBaoOrderMapService; |
| | | import com.yeshi.fanli.service.inter.elme.ElmeOrderProcessService; |
| | | import com.yeshi.fanli.service.inter.elme.ElmeOrderService; |
| | | import com.yeshi.fanli.service.inter.money.UserMoneyService; |
| | | import com.yeshi.fanli.service.inter.money.tb.TaoBaoWeiQuanDrawBackService; |
| | | import com.yeshi.fanli.service.inter.order.*; |
| | | import com.yeshi.fanli.service.inter.order.jd.JDOrderService; |
| | | import com.yeshi.fanli.service.inter.order.msg.UserOrderMsgNotificationService; |
| | | import com.yeshi.fanli.service.inter.order.pdd.PDDOrderService; |
| | | import com.yeshi.fanli.service.inter.order.tb.TaoBaoOrderService; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService; |
| | | import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService; |
| | | import com.yeshi.fanli.service.manger.PIDManager; |
| | | import com.yeshi.fanli.service.manger.msg.RocketMQManager; |
| | | import com.yeshi.fanli.service.manger.order.HongBaoV2AddManager; |
| | | import com.yeshi.fanli.service.manger.order.TeamRewardManager; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.TaoBaoConstant; |
| | | import com.yeshi.fanli.util.factory.UserMoneyDetailFactory; |
| | | import com.yeshi.fanli.util.goods.douyin.DYUtil; |
| | | import com.yeshi.fanli.util.mq.cmq.order.PlaceOrderCMQManager; |
| | | import com.yeshi.fanli.util.mq.cmq.order.TeamOrderCMQManager; |
| | | import com.yeshi.fanli.util.mq.rabbit.RabbitmqManager; |
| | | import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil; |
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory; |
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName; |
| | | import com.yeshi.fanli.util.vipshop.VipShopUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.MoneyBigDecimalUtil; |
| | | import org.yeshi.utils.NumberUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | |
| | | @Service |
| | | public class OrderProcessServiceImpl implements OrderProcessService { |
| | | |
| | | @Resource |
| | | private OrderMapper orderMapper; |
| | | |
| | | @Resource |
| | | private UserInfoMapper userInfoMapper; |
| | | |
| | | @Resource |
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService; |
| | | |
| | | @Resource |
| | | private TaoBaoWeiQuanDrawBackService taoBaoWeiQuanDrawBackService; |
| | | |
| | | @Resource |
| | | private TaoBaoOrderService taoBaoOrderService; |
| | | |
| | | @Resource |
| | | private LostOrderService lostOrderService; |
| | | |
| | | @Resource |
| | | private TaoBaoWeiQuanOrderMapper taoBaoWeiQuanOrderMapper; |
| | | |
| | | @Resource |
| | | private HongBaoV2Mapper hongBaoV2Mapper; |
| | | |
| | | @Resource |
| | | private UserOrderMsgNotificationService userOrderMsgNotificationService; |
| | | |
| | | @Resource |
| | | private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService; |
| | | |
| | | @Resource |
| | | private UserMoneyService userMoneyService; |
| | | |
| | | @Resource |
| | | private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService; |
| | | |
| | | @Resource |
| | | private CommonOrderService commonOrderService; |
| | | |
| | | @Resource |
| | | private HongBaoV2Service hongBaoV2Service; |
| | | |
| | | @Resource |
| | | private JDOrderService jdOrderService; |
| | | |
| | | @Resource |
| | | private PDDOrderService pddOrderService; |
| | | |
| | | @Resource(name = "orderTransactionProducer") |
| | | private TransactionProducer orderTransactionProducer; |
| | | |
| | | @Resource |
| | | private RocketMQManager rocketMQManager; |
| | | |
| | | @Resource |
| | | private OrderMoneySettleService orderMoneySettleService; |
| | | |
| | | @Resource |
| | | private HongBaoV2AddManager hongBaoV2AddManager; |
| | | |
| | | @Resource |
| | | private TeamRewardManager teamRewardManager; |
| | | |
| | | @Resource |
| | | private PIDManager pidManager; |
| | | |
| | | @Resource |
| | | private RabbitmqManager rabbitmqManager; |
| | | |
| | | @Resource |
| | | private TeamOrderCMQManager teamOrderCMQManager; |
| | | |
| | | @Resource |
| | | private PlaceOrderCMQManager placeOrderCMQManager; |
| | | |
| | | /** |
| | | * 是否是分享订单 |
| | | * |
| | | * @param order |
| | | * @return |
| | | */ |
| | | private boolean isShareOrder(SystemEnum system, TaoBaoOrder order) { |
| | | |
| | | String specialRelationId = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel); |
| | | |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID); |
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), order.getSourceMediaId(), |
| | | order.getAdPositionId()); |
| | | if (!StringUtil.isNullOrEmpty(order.getSpecialId()) |
| | | || pid.equalsIgnoreCase(specialRelationId)) {// 设置渠道ID当做会员运营ID的位置ID |
| | | return false; |
| | | } else if (!StringUtil.isNullOrEmpty(order.getRelationId())) { |
| | | return true; |
| | | } else { |
| | | // 通过红包查询 |
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, |
| | | order.getTradeId()); |
| | | |
| | | if (commonOrder != null) { |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null |
| | | && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | //获取推广位类型 |
| | | private SystemPIDInfo.PidType getPidType(int sourceType, String pid) { |
| | | List<SystemPIDInfo> pidInfoList = pidManager.listPidInfoByPidCache(pid, sourceType); |
| | | if ((pidInfoList == null || pidInfoList.size() == 0) && sourceType == Constant.SOURCE_TYPE_TAOBAO) { |
| | | pidInfoList = pidManager.listPidInfoByPidCache(pid, Constant.SOURCE_TYPE_ELME); |
| | | } |
| | | |
| | | SystemPIDInfo.PidType pidType = null; |
| | | if (pidInfoList != null && pidInfoList.size() > 0) { |
| | | pidType = pidInfoList.get(0).getPidType(); |
| | | } |
| | | return pidType; |
| | | } |
| | | |
| | | //根据PID获取系统 |
| | | private List<SystemEnum> getPidSystems(String pid) { |
| | | List<SystemEnum> systemList = new ArrayList<>(); |
| | | List<SystemPIDInfo> pidInfoList = pidManager.listPidInfoByPidCache(pid, null); |
| | | |
| | | if (pidInfoList != null) { |
| | | for (SystemPIDInfo pidInfo : pidInfoList) { |
| | | systemList.add(pidInfo.getSystem()); |
| | | } |
| | | } |
| | | return systemList; |
| | | } |
| | | |
| | | private Set<Integer> getPidSourceTypes(String pid) { |
| | | Set<Integer> sourceTypes = new HashSet<>(); |
| | | List<SystemPIDInfo> pidInfoList = pidManager.listPidInfoByPidCache(pid, null); |
| | | if (pidInfoList != null) { |
| | | for (SystemPIDInfo pidInfo : pidInfoList) { |
| | | sourceTypes.add(pidInfo.getSourceType()); |
| | | } |
| | | } |
| | | return sourceTypes; |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void processOrder(Map<String, List<TaoBaoOrder>> orders) { |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID); |
| | | |
| | | // 分离出返利订单与分享赚订单 |
| | | Iterator<String> its = orders.keySet().iterator(); |
| | | Map<String, List<TaoBaoOrder>> fanliOrderMap = new HashMap<>(); |
| | | Map<String, List<TaoBaoOrder>> shareOrderMap = new HashMap<>(); |
| | | Map<String, List<TaoBaoOrder>> elmeOrderMap = new HashMap<>(); |
| | | while (its.hasNext()) { |
| | | String orderId = its.next(); |
| | | |
| | | if (orders.get(orderId) != null && orders.get(orderId).size() > 0) { |
| | | List<TaoBaoOrder> list = orders.get(orderId); |
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), |
| | | list.get(0).getSourceMediaId(), list.get(0).getAdPositionId()); |
| | | |
| | | |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_TAOBAO, pid); |
| | | |
| | | //--------分离自购,分享,饿了么订单类型------- |
| | | if (pidType != null) { |
| | | if ("饿了么".equalsIgnoreCase(list.get(0).getOrderType()) |
| | | && pidType != SystemPIDInfo.PidType.share) { |
| | | // 饿了么订单开始归入到淘宝订单 |
| | | if (TimeUtil.convertToTimeTemp(list.get(0).getCreateTime(), |
| | | "yyyy-MM-dd HH:mm:ss") >= Constant.NEW_ORDER_FANLI_RULE_TIME) { |
| | | fanliOrderMap.put(orderId, list); |
| | | } else { |
| | | elmeOrderMap.put(orderId, list); |
| | | } |
| | | } else { |
| | | if (!StringUtil.isNullOrEmpty(list.get(0).getSpecialId()) |
| | | || pidType == SystemPIDInfo.PidType.fanliChannel) {// 设置渠道ID当做会员运营ID的位置ID |
| | | fanliOrderMap.put(orderId, list); |
| | | } else if (!StringUtil.isNullOrEmpty(list.get(0).getRelationId())) { |
| | | shareOrderMap.put(orderId, list); |
| | | } else { |
| | | // 通过红包查询 |
| | | CommonOrder commonOrder = commonOrderService |
| | | .selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, list.get(0).getTradeId()); |
| | | |
| | | if (commonOrder != null) { |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null |
| | | && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) { |
| | | shareOrderMap.put(orderId, list); |
| | | continue; |
| | | } |
| | | } |
| | | fanliOrderMap.put(orderId, list); |
| | | } |
| | | } |
| | | } else { |
| | | if ("口碑".equalsIgnoreCase(list.get(0).getOrderType()) |
| | | && pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_KOUBEI_PID)) {// 口碑自购 |
| | | fanliOrderMap.put(orderId, list); |
| | | } else { |
| | | fanliOrderMap.put(orderId, list); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 处理返利订单 |
| | | processShopingFanliOrder(fanliOrderMap); |
| | | // 处理分享赚订单 |
| | | processShareGoodsOrder(shareOrderMap); |
| | | // 处理饿了么订单 |
| | | processElemeOrder(elmeOrderMap); |
| | | } |
| | | |
| | | private ElmeOrder createElmeOrder(TaoBaoOrder taoBaoOrder) { |
| | | ElmeOrder elmeOrder = new ElmeOrder(); |
| | | elmeOrder.setChannelId(""); |
| | | elmeOrder.setCreateTime(new Date()); |
| | | elmeOrder |
| | | .setOrderDate(new Date(TimeUtil.convertToTimeTemp(taoBaoOrder.getCreateTime(), "yyyy-MM-dd HH:mm:ss"))); |
| | | elmeOrder.setOrderId(taoBaoOrder.getOrderId()); |
| | | elmeOrder.setPayMoney(taoBaoOrder.getPayment()); |
| | | elmeOrder.setRid(taoBaoOrder.getRelationId()); |
| | | if (taoBaoOrder.getOrderState().equalsIgnoreCase("订单结算")) |
| | | elmeOrder.setIsSettle(true); |
| | | else |
| | | elmeOrder.setIsSettle(false); |
| | | |
| | | if (!taoBaoOrder.getOrderState().equalsIgnoreCase("订单失效")) |
| | | elmeOrder.setState(1); |
| | | else { |
| | | elmeOrder.setState(0); |
| | | elmeOrder.setPayMoney(new BigDecimal(0)); |
| | | } |
| | | elmeOrder.setTrackPid( |
| | | String.format("mm_124933865_%s_%s", taoBaoOrder.getSourceMediaId(), taoBaoOrder.getAdPositionId())); |
| | | if (!StringUtil.isNullOrEmpty(taoBaoOrder.getRelationId())) { |
| | | UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByRelationId(taoBaoOrder.getRelationId(), null); |
| | | if (extraInfo != null) |
| | | elmeOrder.setUid(extraInfo.getUser().getId()); |
| | | } |
| | | return elmeOrder; |
| | | } |
| | | |
| | | private void processElemeOrder(Map<String, List<TaoBaoOrder>> orders) { |
| | | for (Iterator<String> its = orders.keySet().iterator(); its.hasNext(); ) { |
| | | String orderId = its.next(); |
| | | List<TaoBaoOrder> orderList = orders.get(orderId); |
| | | for (TaoBaoOrder taoBaoOrder : orderList) { |
| | | ElmeOrder elmeOrder = createElmeOrder(taoBaoOrder); |
| | | try { |
| | | elmeOrderProcessService.processOrder(elmeOrder); |
| | | } catch (ElmeOrderException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void processShopingFanliOrder(Map<String, List<TaoBaoOrder>> orders) { |
| | | // 查询在Order中是否存在该订单号 |
| | | Iterator<String> its = orders.keySet().iterator(); |
| | | String tempOrderId = ""; |
| | | while (its.hasNext()) { |
| | | try { |
| | | String orderId = its.next(); |
| | | tempOrderId = orderId; |
| | | // 处理红包与子红包 |
| | | // if (isRedisLockOrder(orderId)) |
| | | // continue; |
| | | // redisLockOrder(orderId); |
| | | processShopingFanliOrderNew(orderId, orders.get(orderId)); |
| | | // redisUnlockOrder(orderId); |
| | | // 出错了就不处理该订单了,需要定期检查 |
| | | |
| | | // 更改丢失订单的状态 |
| | | lostOrderService.processSuceess(orderId, Constant.SOURCE_TYPE_TAOBAO); |
| | | |
| | | } catch (HongBaoException e1) { |
| | | e1.printStackTrace(); |
| | | } catch (OrderItemException e2) { |
| | | e2.printStackTrace(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | try { |
| | | LogHelper.errorDetailInfo(e, null, tempOrderId); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void processShareGoodsOrder(Map<String, List<TaoBaoOrder>> orders) { |
| | | // pidOrderService.addPidOrderFromTaoBao(orders); |
| | | if (orders != null) { |
| | | Iterator<String> its = orders.keySet().iterator(); |
| | | while (its.hasNext()) { |
| | | String orderId = its.next(); |
| | | try { |
| | | processShareGoodsOrderNew(orderId, orders.get(orderId)); |
| | | } catch (Exception e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "processShareGoodsOrderNew出错", "订单号:" + orderId); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void fanli() { |
| | | LogHelper.test("处理返利到账"); |
| | | // 获取主红包 |
| | | List<HongBaoV2> hongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByType(HongBaoV2.TYPE_ZIGOU, 1000); |
| | | // |
| | | // /** |
| | | // * 需要实时更新待返利的订单 |
| | | // */ |
| | | // |
| | | // // 计算最大的创建时间与最小的创建时间 |
| | | // Map<String, Long> map = getMaxAndMinCreateTime(hongBaoList); |
| | | // if (map != null) { |
| | | // long max = map.get("max"); |
| | | // long min = map.get("min"); |
| | | // // 最小时间提前10分钟 |
| | | // min = min - 1000 * 60 * 10L; |
| | | // // 更新该段时间的订单 |
| | | // List<TaoBaoOrder> orderList = new ArrayList<>(); |
| | | // try { |
| | | // orderList = TaoBaoOrderUtil.getOrderList(min, max); |
| | | // } catch (TaoBaoOrderException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // // try { |
| | | // if (orderList != null) |
| | | // processOrder(TaoBaoOrderUtil.classifyTaoBaoOrderByOrderId(orderList)); |
| | | // // } catch (Exception e) { |
| | | // // e.printStackTrace(); |
| | | // // try { |
| | | // // LogHelper.errorDetailInfo(e); |
| | | // // } catch (Exception e1) { |
| | | // // e1.printStackTrace(); |
| | | // // } |
| | | // // } |
| | | // } |
| | | |
| | | /** |
| | | * 开始返利 |
| | | */ |
| | | for (HongBaoV2 hb : hongBaoList) { |
| | | // |
| | | if (hb.getState() == HongBaoV2.STATE_SHIXIAO || hb.getState() == HongBaoV2.STATE_YILINGQU) |
| | | continue; |
| | | |
| | | if (hb.getPreGetTime() == null || hb.getPreGetTime().getTime() == 0 |
| | | || hb.getPreGetTime().getTime() > System.currentTimeMillis()) |
| | | continue; |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | rabbitmqManager.addFanLiMsgNew(hb); |
| | | } catch (Exception e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Resource |
| | | private HongBaoOrderMapper hongBaoOrderMapper; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void fanli(HongBaoV2 hb1) throws TaoBaoWeiQuanException { |
| | | // 查询最新的红包数据 |
| | | hb1 = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hb1.getId()); |
| | | |
| | | if (hb1 == null || hb1.getState() != HongBaoV2.STATE_KELINGQU || hb1.getPreGetTime() == null |
| | | || hb1.getPreGetTime().getTime() > System.currentTimeMillis()) |
| | | return; |
| | | |
| | | // 正常用户才能到账 |
| | | UserInfo mainUser = userInfoMapper.selectAvailableByPrimaryKey(hb1.getUserInfo().getId()); |
| | | if (mainUser == null || mainUser.getState() != UserInfo.STATE_NORMAL) { |
| | | return; |
| | | } |
| | | // 查询红包相关联的订单 |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hb1.getId()); |
| | | if (hongBaoOrder == null) { |
| | | LogHelper.error("返利失败:" + hb1.getId()); |
| | | return; |
| | | } |
| | | |
| | | if (hongBaoOrder.getCommonOrder() == null) { |
| | | return; |
| | | } |
| | | |
| | | // 如果是拼多多/京东维权则返回,不需要返利 |
| | | if ((hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_PDD |
| | | || hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_JD) |
| | | && hongBaoOrder.getCommonOrder().getState() == CommonOrder.STATE_WQ) |
| | | return; |
| | | |
| | | if (hongBaoOrder.getCommonOrder() != null |
| | | && hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_TAOBAO) { |
| | | // 维权中的不返利 |
| | | List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper |
| | | .selectListByOrderIdAndState(hongBaoOrder.getCommonOrder().getOrderNo(), "维权创建"); |
| | | if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0) |
| | | return; |
| | | |
| | | taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper |
| | | .selectListByOrderIdAndState(hongBaoOrder.getCommonOrder().getOrderNo(), "等待处理"); |
| | | if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0) |
| | | return; |
| | | } |
| | | |
| | | // 查询该订单之前是否有到账 |
| | | List<HongBaoOrder> list = hongBaoOrderMapper.listByOrderIdAndSourceType( |
| | | hongBaoOrder.getCommonOrder().getOrderNo(), hongBaoOrder.getCommonOrder().getSourceType()); |
| | | List<Long> hongBaoIdList = new ArrayList<>(); |
| | | if (list != null) { |
| | | for (HongBaoOrder ho : list) { |
| | | hongBaoIdList.add(ho.getHongBaoV2().getId()); |
| | | } |
| | | } |
| | | |
| | | List<HongBaoV2> allHongBaoList = hongBaoV2Mapper.listByIds(hongBaoIdList); |
| | | boolean first = true; |
| | | for (HongBaoV2 v2 : allHongBaoList) |
| | | if (v2.getState() == HongBaoV2.STATE_YILINGQU) { |
| | | first = false; |
| | | break; |
| | | } |
| | | |
| | | // 自购到账事务消息 |
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_ZIGOU, |
| | | mainUser.getId(), hongBaoOrder.getCommonOrder().getSourceType(), |
| | | hongBaoOrder.getCommonOrder().getOrderNo(), null, new Date(), 0); |
| | | mqMsg.setOrderFirst(first); |
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg); |
| | | String key = mainUser.getId() + "-" + UUID.randomUUID().toString(); |
| | | msg.setKey(key); |
| | | try { |
| | | if (!Constant.IS_TEST) |
| | | orderTransactionProducer.send(msg, new LocalTransactionExecuter() { |
| | | @Override |
| | | public TransactionStatus execute(Message arg0, Object arg1) { |
| | | try { |
| | | orderMoneySettleService.ziGouSettle(hongBaoOrder.getCommonOrder().getOrderNo(), |
| | | hongBaoOrder.getCommonOrder().getSourceType(), key); |
| | | return TransactionStatus.CommitTransaction; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return TransactionStatus.RollbackTransaction; |
| | | } |
| | | } |
| | | }, null); |
| | | else { |
| | | try { |
| | | orderMoneySettleService.ziGouSettle(hongBaoOrder.getCommonOrder().getOrderNo(), |
| | | hongBaoOrder.getCommonOrder().getSourceType(), key); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | LogHelper.mqError(e.getMessage(), msg.getTopic(), msg.getTag(), new Gson().toJson(mqMsg)); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void weiQuanOrder(List<TaoBaoWeiQuanOrder> orderList) { |
| | | if (orderList != null) |
| | | for (TaoBaoWeiQuanOrder order : orderList) { |
| | | try { |
| | | if (order.getState().contains("维权成功")) { |
| | | if (Constant.ENABLE_MQ) |
| | | rabbitmqManager.addWeiQuanOrderMsg(order); |
| | | } |
| | | } catch (Exception e) { |
| | | LogHelper.error("维权订单加入到队列出错:" + order != null ? new Gson().toJson(order) : null); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void weiQuanOrder(TaoBaoWeiQuanOrder order) { |
| | | // 订单结算时间在2018-08-05后就不处理维权了 |
| | | |
| | | List<TaoBaoOrder> orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(order.getOrderId()); |
| | | if (orderList != null && orderList.size() > 0 & !StringUtil.isNullOrEmpty(orderList.get(0).getSettlementTime())) |
| | | order.setJieSuanTime( |
| | | new Date(TimeUtil.convertToTimeTemp(orderList.get(0).getSettlementTime(), "yyyy-MM-dd HH:mm:ss"))); |
| | | |
| | | // 处理维权成功但是已到账的订单 |
| | | if (order.getJieSuanTime().getTime() > TimeUtil.convertToTimeTemp("2019-01-01", "yyyy-MM-dd")) {// 结算时间在1月1号的开始处理已到账但是维权的 |
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, |
| | | order.getOrderItemId()); |
| | | if (commonOrder != null && !StringUtil.isNullOrEmpty(commonOrder.getTradeId())) { |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null |
| | | && hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_YILINGQU) {// 已经到账的看是否需要扣款 |
| | | TaoBaoWeiQuanDrawBack drawBack = taoBaoWeiQuanDrawBackService |
| | | .selectByOrderItemId(order.getOrderItemId()); |
| | | if (drawBack == null) {// 还未扣款 |
| | | OrderLogHelper.taoBaoWeiQuan("已到账未扣款处理:子订单号:" + order.getOrderItemId()); |
| | | try { |
| | | taoBaoWeiQuanDrawBackService.doWeiQuanFanli(order.getOrderId(), true); |
| | | taoBaoWeiQuanDrawBackService.doWeiQuanShare(order.getOrderId()); |
| | | teamRewardManager.weiQuan(order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, order.getOrderItemId()); |
| | | } catch (Exception e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "到账后处理维权扣款出错", "订单号:" + order.getOrderId()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } else { |
| | | try { |
| | | // taoBaoWeiQuanDrawBackService.doWeiQuanInvite(order.getOrderId()); |
| | | teamRewardManager.weiQuan(order.getOrderId(), Constant.SOURCE_TYPE_TAOBAO, order.getOrderItemId()); |
| | | } catch (Exception e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "到账后处理维权扣款出错", "订单号:" + order.getOrderId()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void fanliPreInvaite(Date maxTime) { |
| | | // 查出邀请赚的用户ID |
| | | List<Integer> typeList = new ArrayList<>(); |
| | | typeList.add(HongBaoV2.TYPE_YIJI); |
| | | typeList.add(HongBaoV2.TYPE_ERJI); |
| | | typeList.add(HongBaoV2.TYPE_SHARE_YIJI); |
| | | typeList.add(HongBaoV2.TYPE_SHARE_ERJI); |
| | | |
| | | long count = hongBaoV2Mapper.countUidCanBanlanceByTypeAndMaxTime(typeList, maxTime); |
| | | int pageSize = 1000; |
| | | int page = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); |
| | | Set<Long> uidSets = new HashSet<>(); |
| | | for (int i = 0; i < page; i++) { |
| | | List<Long> inviteAndShareUids = hongBaoV2Mapper.listUidCanBanlanceByTypeAndMaxTime(typeList, maxTime, |
| | | i * pageSize, pageSize); |
| | | if (inviteAndShareUids != null) |
| | | for (Long uid : inviteAndShareUids) { |
| | | if (userInfoMapper.selectAvailableByPrimaryKey(uid) != null) |
| | | uidSets.add(uid); |
| | | } |
| | | } |
| | | // 根据用户ID |
| | | Iterator<Long> its = uidSets.iterator(); |
| | | while (its.hasNext()) { |
| | | Long uid = its.next(); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | teamOrderCMQManager.addFanLiTeamIncomePreMsg(new UidDateDTO(uid, maxTime)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | LogHelper.error(e); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public int fanliShare(Date maxTime) { |
| | | // 查出邀请赚的用户ID |
| | | List<Integer> typeList = new ArrayList<>(); |
| | | typeList.add(HongBaoV2.TYPE_SHARE_GOODS); |
| | | |
| | | long count = hongBaoV2Mapper.countUidCanBanlanceByTypeAndMaxTime(typeList, maxTime); |
| | | int pageSize = 1000; |
| | | int page = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); |
| | | Set<Long> uidSets = new HashSet<>(); |
| | | for (int i = 0; i < page; i++) { |
| | | List<Long> inviteAndShareUids = hongBaoV2Mapper.listUidCanBanlanceByTypeAndMaxTime(typeList, maxTime, |
| | | i * pageSize, pageSize); |
| | | if (inviteAndShareUids != null) |
| | | for (Long uid : inviteAndShareUids) { |
| | | if (userInfoMapper.selectAvailableByPrimaryKey(uid) != null) |
| | | uidSets.add(uid); |
| | | } |
| | | } |
| | | // 根据用户ID |
| | | Iterator<Long> its = uidSets.iterator(); |
| | | while (its.hasNext()) { |
| | | Long uid = its.next(); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | rabbitmqManager.addFanLiShareMsg(new UidDateDTO(uid, maxTime)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | LogHelper.error(e); |
| | | } |
| | | } |
| | | |
| | | return uidSets.size(); |
| | | } |
| | | |
| | | @Override |
| | | // @Transactional(rollbackFor = Exception.class) |
| | | public void fanliPreInvaite(Long uid, Date maxPreGetTime) { |
| | | // 邀请赚到账 |
| | | try { |
| | | orderMoneySettleService.inviteSettleTB(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.inviteSettleJD(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.inviteSettlePDD(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.inviteSettleVipShop(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.inviteSettleSuning(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.inviteSettleDY(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void fanliShare(Long uid, Date maxPreGetTime) { |
| | | // 邀请赚到账 |
| | | try { |
| | | orderMoneySettleService.shareSettleTB(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.shareSettleJD(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.shareSettlePDD(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.shareSettleVipShop(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.shareSettleSuning(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | try { |
| | | orderMoneySettleService.shareSettleDY(uid, maxPreGetTime); |
| | | } catch (OrderMoneySettleException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
| | | @Override |
| | | public void processShopingFanliOrderNew(String orderId, List<TaoBaoOrder> orderList) |
| | | throws HongBaoException, OrderItemException { |
| | | |
| | | LogHelper.test(String.format("订单处理:订单号-%s 订单数量-%s", orderId, orderList.size() + "")); |
| | | if (orderList.size() == 1) |
| | | LogHelper.test("订单排序值:" + orderList.get(0).getOrderBy()); |
| | | |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID); |
| | | |
| | | if (orderList != null && orderList.size() > 0) { |
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), |
| | | orderList.get(0).getSourceMediaId(), orderList.get(0).getAdPositionId()); |
| | | |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_TAOBAO, pid); |
| | | List<SystemEnum> systemList = getPidSystems(pid); |
| | | Set<Integer> sourceTypes = getPidSourceTypes(pid); |
| | | |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(orderId, Constant.SOURCE_TYPE_TAOBAO); |
| | | // 原来不存在订单 |
| | | Long uid = null; |
| | | if (oldOrder == null) { |
| | | Long targetUid = null; |
| | | if (pidType != null && pidType == SystemPIDInfo.PidType.fanliChannel |
| | | && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {// 处理非返利商品库的商品 |
| | | targetUid = taoBaoBuyRelationMapService.selectUidByRelationId(orderList.get(0).getRelationId()); |
| | | |
| | | } else if ((sourceTypes.contains(Constant.SOURCE_TYPE_ELME) |
| | | || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_KOUBEI_PID)) |
| | | && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {// 处理饿了么,口碑的订单 |
| | | UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService |
| | | .getByRelationId(orderList.get(0).getRelationId(), systemList); |
| | | if (extraInfo != null) { |
| | | targetUid = extraInfo.getUser().getId(); |
| | | } |
| | | } else if (!StringUtil.isNullOrEmpty(orderList.get(0).getSpecialId())) { |
| | | UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService |
| | | .getBySpecialId(orderList.get(0).getSpecialId(), systemList); |
| | | if (info != null && info.getUser() != null) |
| | | targetUid = info.getUser().getId(); |
| | | } |
| | | |
| | | if (targetUid != null) { |
| | | uid = targetUid; |
| | | // 插入到Order中 |
| | | // 添加到订单中去 |
| | | Order order = new Order(); |
| | | order.setBeizhu("PID返利订单"); |
| | | order.setCreatetime(System.currentTimeMillis()); |
| | | order.setOrderId(orderId); |
| | | order.setOrderType(1); |
| | | order.setState(Order.STATE_YIZHIFU); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | order.setVersion(2); |
| | | // 加入到订单表 |
| | | orderMapper.insertSelective(order); |
| | | oldOrder = order; |
| | | } |
| | | |
| | | } else { |
| | | uid = oldOrder.getUserInfo().getId(); |
| | | } |
| | | // 尚未找到和PID对应的用户 |
| | | if (uid == null) |
| | | return; |
| | | |
| | | // 计算订单总额度 |
| | | Order updateOrder = new Order(); |
| | | updateOrder.setId(oldOrder.getId()); |
| | | BigDecimal money = new BigDecimal(0); |
| | | for (TaoBaoOrder o : orderList) { |
| | | if (o.getOrderState().equalsIgnoreCase("订单结算")) |
| | | money = money.add(o.getSettlement()); |
| | | else { |
| | | money = money.add(o.getPayment()); |
| | | } |
| | | } |
| | | updateOrder.setMoney(money); |
| | | String thirdState = null; |
| | | for (TaoBaoOrder o : orderList) |
| | | if (!o.getOrderState().equalsIgnoreCase("订单失效")) { |
| | | thirdState = o.getOrderState(); |
| | | break; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(thirdState)) |
| | | thirdState = "订单失效"; |
| | | updateOrder.setThirdState(thirdState); |
| | | updateOrder.setThirdCreateTime( |
| | | new Date(TimeUtil.convertToTimeTemp(orderList.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss"))); |
| | | orderMapper.updateByPrimaryKeySelective(updateOrder); |
| | | |
| | | // 用第一个子订单锁定用户 |
| | | List<CommonOrderAddResultDTO> commonOrderList = null; |
| | | try { |
| | | commonOrderList = commonOrderService.addTaoBaoOrder(orderList, uid); |
| | | addHongBaoWithMQ(commonOrderList, orderId, uid, Constant.SOURCE_TYPE_TAOBAO, HongBaoV2.TYPE_ZIGOU); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(orderId); |
| | | order.setOrderType(Constant.SOURCE_TYPE_TAOBAO); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | placeOrderCMQManager.addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addTaoBaoOrder或addHongBao出错", "订单号:" + orderId); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void processShareGoodsOrderNew(String orderId, List<TaoBaoOrder> orderList) { |
| | | if (orderList != null && orderList.size() > 0) { |
| | | // 原来不存在订单 |
| | | Long uid = null; |
| | | UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService.getByRelationId(orderList.get(0).getRelationId(), null); |
| | | if (info != null && info.getUser() != null) |
| | | uid = info.getUser().getId(); |
| | | // 尚未找到和PID对应的用户 |
| | | if (uid == null) { |
| | | // 通过红包查询 |
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, |
| | | orderList.get(0).getTradeId()); |
| | | |
| | | if (commonOrder != null) { |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null |
| | | && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) { |
| | | uid = hongBaoOrder.getHongBaoV2().getUserInfo().getId(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (uid == null) |
| | | return; |
| | | |
| | | // 用第一个子订单锁定用户 |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrders = commonOrderService.addTaoBaoOrder(orderList, uid); |
| | | addHongBaoWithMQ(commonOrders, orderId, uid, Constant.SOURCE_TYPE_TAOBAO, HongBaoV2.TYPE_SHARE_GOODS); |
| | | if (isCommonOrderAllAdd(commonOrders)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(orderId); |
| | | order.setOrderType(Constant.SOURCE_TYPE_TAOBAO); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | placeOrderCMQManager.addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 是否为分享订单 |
| | | * |
| | | * @param order |
| | | * @return |
| | | */ |
| | | private boolean isShareOrder(JDOrder order) { |
| | | if (order == null || order.getOrderItemList() == null || order.getOrderItemList().size() == 0) |
| | | return false; |
| | | Long positionId = order.getOrderItemList().get(0).getPositionId(); |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_JD, positionId + ""); |
| | | if (pidType != null && pidType == SystemPIDInfo.PidType.share) {// 分享订单 |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public void processJDOrder(JDOrder order) { |
| | | if (order == null || order.getOrderItemList() == null || order.getOrderItemList().size() == 0) |
| | | return; |
| | | // 拆单且不在commonorder中的不做处理 |
| | | if (order.getValidCode() == 2) { |
| | | List<CommonOrder> list= commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_JD,order.getOrderId()+""); |
| | | if(list==null||list.size()==0) { |
| | | return; |
| | | } |
| | | } |
| | | // 根据ext1与subUnionId跟单 |
| | | String uidStr = order.getExt1(); |
| | | if (StringUtil.isNullOrEmpty(uidStr)) |
| | | uidStr = order.getOrderItemList().get(0).getSubUnionId(); |
| | | |
| | | Long uid = null; |
| | | if (!StringUtil.isNullOrEmpty(uidStr) && NumberUtil.isNumeric(uidStr)) |
| | | uid = Long.parseLong(uidStr); |
| | | Long positionId = order.getOrderItemList().get(0).getPositionId(); |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_JD, positionId + ""); |
| | | |
| | | if (pidType != null) { |
| | | if (pidType == SystemPIDInfo.PidType.fanli)// 返利订单 |
| | | { |
| | | processFanLiJDOrder(order, uid); |
| | | lostOrderService.processSuceess(order.getOrderId() + "", Constant.SOURCE_TYPE_JD); |
| | | } else if (pidType == SystemPIDInfo.PidType.share) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processShareJDOrder(order, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiJDOrder(order, null); |
| | | } |
| | | } else { |
| | | processFanLiJDOrder(order, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理京东返利订单 |
| | | * |
| | | * @param jdOrder |
| | | * @param uid |
| | | */ |
| | | private void processFanLiJDOrder(JDOrder jdOrder, Long uid) { |
| | | int invalidCount = 0; |
| | | BigDecimal totalMoney = new BigDecimal(0); |
| | | // 订单状态判断 |
| | | for (JDOrderItem item : jdOrder.getOrderItemList()) { |
| | | if (item.getEstimateCosPrice() != null) |
| | | totalMoney = totalMoney.add(item.getEstimateCosPrice()); |
| | | |
| | | if (item.getValidCode() == 16 || item.getValidCode() == 17 || item.getValidCode() == 18) {// 已付款 |
| | | |
| | | } else if (item.getValidCode() == 15) {// 未支付 |
| | | |
| | | } else { |
| | | invalidCount++; |
| | | } |
| | | } |
| | | |
| | | // 加入订单 |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(jdOrder.getOrderId() + "", |
| | | Constant.SOURCE_TYPE_JD); |
| | | if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("补单")) |
| | | uid = oldOrder.getUserInfo().getId(); |
| | | |
| | | if (uid == null) |
| | | return; |
| | | |
| | | if (oldOrder == null)// 新增 |
| | | { |
| | | Order order = new Order(); |
| | | order.setBeizhu("京东返利订单"); |
| | | order.setCreatetime(System.currentTimeMillis()); |
| | | order.setOrderId(jdOrder.getOrderId() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_JD); |
| | | order.setState( |
| | | invalidCount == jdOrder.getOrderItemList().size() ? Order.STATE_SHIXIAO : Order.STATE_YIZHIFU); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | order.setVersion(2); |
| | | order.setThirdCreateTime(new Date(jdOrder.getOrderTime())); |
| | | order.setMoney(totalMoney); |
| | | // 加入到订单表 |
| | | orderMapper.insertSelective(order); |
| | | } else { |
| | | Order updateOrder = new Order(); |
| | | updateOrder.setId(oldOrder.getId()); |
| | | updateOrder.setMoney(totalMoney); |
| | | orderMapper.updateByPrimaryKeySelective(updateOrder); |
| | | } |
| | | |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addJDOrder(jdOrder, uid); |
| | | addHongBaoWithMQ(commonOrderList, jdOrder.getOrderId() + "", uid, Constant.SOURCE_TYPE_JD, |
| | | HongBaoV2.TYPE_ZIGOU); |
| | | |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(jdOrder.getOrderId() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_JD); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | placeOrderCMQManager.addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + jdOrder.getOrderId()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理京东分享订单 |
| | | * |
| | | * @param jdOrder |
| | | * @param uid |
| | | */ |
| | | private void processShareJDOrder(JDOrder jdOrder, Long uid) { |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addJDOrder(jdOrder, uid); |
| | | addHongBaoWithMQ(commonOrderList, jdOrder.getOrderId() + "", uid, Constant.SOURCE_TYPE_JD, |
| | | HongBaoV2.TYPE_SHARE_GOODS); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(jdOrder.getOrderId() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_JD); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | placeOrderCMQManager.addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + jdOrder.getOrderId()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 是否是分享赚订单 |
| | | * |
| | | * @param pddOrder |
| | | * @return |
| | | */ |
| | | private boolean isShareOrder(PDDOrder pddOrder) { |
| | | String positionId = pddOrder.getpId(); |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_PDD, positionId); |
| | | |
| | | if (pidType != null && pidType == SystemPIDInfo.PidType.share) |
| | | return true; |
| | | else |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 处理拼多多订单 |
| | | */ |
| | | @Override |
| | | public void processPDDOrder(PDDOrder pddOrder) { |
| | | if (pddOrder == null) |
| | | return; |
| | | String customParameters = pddOrder.getCustomParameters(); |
| | | Long uid = null; |
| | | if (!StringUtil.isNullOrEmpty(customParameters)) |
| | | uid = Long.parseLong(PinDuoDuoUtil.getUidFromCustomParams(customParameters)); |
| | | String positionId = pddOrder.getpId(); |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_PDD, positionId); |
| | | if (pidType != null) { |
| | | if (pidType == SystemPIDInfo.PidType.fanli)// 返利订单 |
| | | { |
| | | processFanLiPDDOrder(pddOrder, uid); |
| | | lostOrderService.processSuceess(pddOrder.getOrderSn(), Constant.SOURCE_TYPE_PDD); |
| | | } else if (pidType == SystemPIDInfo.PidType.share) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processSharePDDOrder(pddOrder, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiPDDOrder(pddOrder, null); |
| | | } |
| | | } else { |
| | | processFanLiPDDOrder(pddOrder, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理拼多多自购返利订单 |
| | | * |
| | | * @param pddOrder |
| | | * @param uid |
| | | */ |
| | | private void processFanLiPDDOrder(PDDOrder pddOrder, Long uid) { |
| | | int orderState = 0; |
| | | if (pddOrder.getOrderStatus() == -1 || pddOrder.getOrderStatus() == 8) |
| | | orderState = Order.STATE_SHIXIAO; |
| | | else |
| | | orderState = Order.STATE_YIZHIFU; |
| | | |
| | | BigDecimal totalMoney = MoneyBigDecimalUtil.div(new BigDecimal(pddOrder.getOrderAmount()), new BigDecimal(100)); |
| | | |
| | | // 加入订单 |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(pddOrder.getOrderSn(), Constant.SOURCE_TYPE_PDD); |
| | | if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("补单")) |
| | | uid = oldOrder.getUserInfo().getId(); |
| | | |
| | | if (uid == null) |
| | | return; |
| | | |
| | | if (oldOrder == null)// 新增 |
| | | { |
| | | Order order = new Order(); |
| | | order.setBeizhu("拼多多返利订单"); |
| | | order.setCreatetime(System.currentTimeMillis()); |
| | | order.setOrderId(pddOrder.getOrderSn()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_PDD); |
| | | order.setState(orderState); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | order.setVersion(2); |
| | | if (pddOrder.getFailReason() != null && pddOrder.getFailReason().contains("比价")) |
| | | order.setStateDesc("比价订单"); |
| | | order.setThirdCreateTime(new Date(pddOrder.getOrderCreateTime() * 1000)); |
| | | order.setMoney(totalMoney); |
| | | // 加入到订单表 |
| | | orderMapper.insertSelective(order); |
| | | } else { |
| | | Order updateOrder = new Order(); |
| | | updateOrder.setId(oldOrder.getId()); |
| | | updateOrder.setMoney(totalMoney); |
| | | if (pddOrder.getFailReason() != null && pddOrder.getFailReason().contains("比价")) |
| | | updateOrder.setStateDesc("比价订单"); |
| | | orderMapper.updateByPrimaryKeySelective(updateOrder); |
| | | } |
| | | |
| | | try { |
| | | List<PDDOrder> pddOrderList = new ArrayList<>(); |
| | | pddOrderList.add(pddOrder); |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addPDDOrder(pddOrderList, uid); |
| | | addHongBaoWithMQ(commonOrderList, pddOrder.getOrderSn(), uid, Constant.SOURCE_TYPE_PDD, |
| | | HongBaoV2.TYPE_ZIGOU); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(pddOrder.getOrderSn()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_PDD); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | placeOrderCMQManager.addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addPDDOrder或addHongBao出错", "订单号:" + pddOrder.getOrderSn()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理拼多多分享订单 |
| | | * |
| | | * @param pddOrder |
| | | * @param uid |
| | | */ |
| | | private void processSharePDDOrder(PDDOrder pddOrder, Long uid) { |
| | | try { |
| | | List<PDDOrder> pddOrderList = new ArrayList<>(); |
| | | pddOrderList.add(pddOrder); |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addPDDOrder(pddOrderList, uid); |
| | | addHongBaoWithMQ(commonOrderList, pddOrder.getOrderSn(), uid, Constant.SOURCE_TYPE_PDD, |
| | | HongBaoV2.TYPE_SHARE_GOODS); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(pddOrder.getOrderSn()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_PDD); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | placeOrderCMQManager.addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + pddOrder.getOrderId()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void processVipShopOrder(VipShopOrder order) { |
| | | |
| | | if (order == null || order.getDetailList() == null || order.getDetailList().size() == 0) |
| | | return; |
| | | |
| | | |
| | | // 根据ext1与subUnionId跟单 |
| | | String channelTag = order.getChannelTag(); |
| | | |
| | | String uidStr = VipShopUtil.getUidFromChanTag(channelTag); |
| | | |
| | | Long uid = null; |
| | | if (!StringUtil.isNullOrEmpty(uidStr) && NumberUtil.isNumeric(uidStr)) |
| | | uid = Long.parseLong(uidStr); |
| | | String type = VipShopUtil.getTypeFromChanTag(channelTag); |
| | | if ("buy".equalsIgnoreCase(type))// 返利订单 |
| | | { |
| | | processFanLiVipShopOrder(order, uid); |
| | | lostOrderService.processSuceess(order.getOrderSn() + "", Constant.SOURCE_TYPE_VIP); |
| | | } else if ("share".equalsIgnoreCase(type)) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processShareVipShopOrder(order, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiVipShopOrder(order, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理唯品会返利订单 |
| | | * |
| | | * @param vipShopOrder |
| | | * @param uid |
| | | */ |
| | | private void processFanLiVipShopOrder(VipShopOrder vipShopOrder, Long uid) { |
| | | int invalidCount = 0; |
| | | BigDecimal totalMoney = new BigDecimal(0); |
| | | // 订单状态判断 |
| | | for (VipShopOrderDetail item : vipShopOrder.getDetailList()) { |
| | | if (item.getCommissionTotalCost() != null) |
| | | totalMoney = totalMoney.add(item.getCommissionTotalCost()); |
| | | if (item.getStatus() == VipShopOrderDetail.STATUS_INVALID) { |
| | | invalidCount++; |
| | | } |
| | | } |
| | | |
| | | // 加入订单 |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(vipShopOrder.getOrderSn() + "", |
| | | Constant.SOURCE_TYPE_VIP); |
| | | if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("补单")) |
| | | uid = oldOrder.getUserInfo().getId(); |
| | | |
| | | if (uid == null) |
| | | return; |
| | | |
| | | if (oldOrder == null)// 新增 |
| | | { |
| | | Order order = new Order(); |
| | | order.setBeizhu("唯品会返利订单"); |
| | | order.setCreatetime(System.currentTimeMillis()); |
| | | order.setOrderId(vipShopOrder.getOrderSn() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_VIP); |
| | | order.setState( |
| | | invalidCount == vipShopOrder.getDetailList().size() ? Order.STATE_SHIXIAO : Order.STATE_YIZHIFU); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | order.setVersion(2); |
| | | order.setThirdCreateTime(new Date(vipShopOrder.getOrderTime())); |
| | | order.setMoney(totalMoney); |
| | | // 加入到订单表 |
| | | orderMapper.insertSelective(order); |
| | | } else { |
| | | Order updateOrder = new Order(); |
| | | updateOrder.setId(oldOrder.getId()); |
| | | updateOrder.setMoney(totalMoney); |
| | | orderMapper.updateByPrimaryKeySelective(updateOrder); |
| | | } |
| | | |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addVipShopOrder(vipShopOrder, uid); |
| | | addHongBaoWithMQ(commonOrderList, vipShopOrder.getOrderSn() + "", uid, Constant.SOURCE_TYPE_VIP, |
| | | HongBaoV2.TYPE_ZIGOU); |
| | | |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(vipShopOrder.getOrderSn() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_VIP); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | placeOrderCMQManager.addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addVipShopOrder或addHongBao出错", "订单号:" + vipShopOrder.getOrderSn()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理京东分享订单 |
| | | * |
| | | * @param jdOrder |
| | | * @param uid |
| | | */ |
| | | private void processShareVipShopOrder(VipShopOrder jdOrder, Long uid) { |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addVipShopOrder(jdOrder, uid); |
| | | addHongBaoWithMQ(commonOrderList, jdOrder.getOrderSn() + "", uid, Constant.SOURCE_TYPE_VIP, |
| | | HongBaoV2.TYPE_SHARE_GOODS); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(jdOrder.getOrderSn() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_VIP); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | placeOrderCMQManager.addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + jdOrder.getOrderSn()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理苏宁订单 |
| | | */ |
| | | @Override |
| | | public void processSuningOrder(SuningOrderInfo suningOrder) { |
| | | if (suningOrder == null) |
| | | return; |
| | | String uidStr = suningOrder.getChildAccountId(); |
| | | Long uid = null; |
| | | if (!StringUtil.isNullOrEmpty(uidStr)) |
| | | uid = Long.parseLong(uidStr); |
| | | String positionId = suningOrder.getPositionId(); |
| | | |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_SUNING, positionId); |
| | | |
| | | if (pidType != null) { |
| | | if (pidType == SystemPIDInfo.PidType.fanli)// 返利订单 |
| | | { |
| | | processFanLiSuningOrder(suningOrder, uid); |
| | | lostOrderService.processSuceess(suningOrder.getOrderCode(), Constant.SOURCE_TYPE_SUNING); |
| | | } else if (pidType == SystemPIDInfo.PidType.share) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processShareSuningOrder(suningOrder, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiSuningOrder(suningOrder, null); |
| | | } |
| | | } else { |
| | | processFanLiSuningOrder(suningOrder, null); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 处理苏宁自购返利订单 |
| | | * |
| | | * @param suningOrder |
| | | * @param uid |
| | | */ |
| | | private void processFanLiSuningOrder(SuningOrderInfo suningOrder, Long uid) { |
| | | int orderState = 0; |
| | | |
| | | // 等待付款;支付完成;退款;订单已取消;确认收货 |
| | | |
| | | if ("订单已取消".equalsIgnoreCase(suningOrder.getOrderLineStatusDesc()) |
| | | || "退款".equalsIgnoreCase(suningOrder.getOrderLineStatusDesc())) |
| | | orderState = Order.STATE_SHIXIAO; |
| | | else |
| | | orderState = Order.STATE_YIZHIFU; |
| | | |
| | | BigDecimal totalMoney = new BigDecimal(suningOrder.getPayAmount()); |
| | | |
| | | // 加入订单 |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(suningOrder.getOrderCode(), |
| | | Constant.SOURCE_TYPE_SUNING); |
| | | if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("补单")) |
| | | uid = oldOrder.getUserInfo().getId(); |
| | | |
| | | if (uid == null) |
| | | return; |
| | | |
| | | if (oldOrder == null)// 新增 |
| | | { |
| | | Order order = new Order(); |
| | | order.setBeizhu("苏宁返利订单"); |
| | | order.setCreatetime(System.currentTimeMillis()); |
| | | order.setOrderId(suningOrder.getOrderCode()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_SUNING); |
| | | order.setState(orderState); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | order.setVersion(2); |
| | | order.setThirdCreateTime( |
| | | new Date(TimeUtil.convertToTimeTemp(suningOrder.getOrderSubmitTime(), "yyyy-MM-dd HH:mm:ss"))); |
| | | order.setMoney(totalMoney); |
| | | // 加入到订单表 |
| | | orderMapper.insertSelective(order); |
| | | } else { |
| | | Order updateOrder = new Order(); |
| | | updateOrder.setId(oldOrder.getId()); |
| | | updateOrder.setMoney(totalMoney); |
| | | orderMapper.updateByPrimaryKeySelective(updateOrder); |
| | | } |
| | | |
| | | try { |
| | | List<SuningOrderInfo> pddOrderList = new ArrayList<>(); |
| | | pddOrderList.add(suningOrder); |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addSuningOrder(pddOrderList, uid); |
| | | addHongBaoWithMQ(commonOrderList, suningOrder.getOrderCode(), uid, Constant.SOURCE_TYPE_SUNING, |
| | | HongBaoV2.TYPE_ZIGOU); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(suningOrder.getOrderCode()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_SUNING); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | placeOrderCMQManager.addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addPDDOrder或addHongBao出错", "订单号:" + suningOrder.getOrderCode()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理苏宁分享订单 |
| | | * |
| | | * @param suningOrder |
| | | * @param uid |
| | | */ |
| | | private void processShareSuningOrder(SuningOrderInfo suningOrder, Long uid) { |
| | | try { |
| | | List<SuningOrderInfo> suningOrderList = new ArrayList<>(); |
| | | suningOrderList.add(suningOrder); |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addSuningOrder(suningOrderList, uid); |
| | | addHongBaoWithMQ(commonOrderList, suningOrder.getOrderCode(), uid, Constant.SOURCE_TYPE_SUNING, |
| | | HongBaoV2.TYPE_SHARE_GOODS); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(suningOrder.getOrderCode()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_SUNING); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | placeOrderCMQManager.addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + suningOrder.getOrderCode()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void processDYOrder(DYOrder order) { |
| | | if (order == null) |
| | | return; |
| | | |
| | | |
| | | // 根据ext1与subUnionId跟单 |
| | | String extra_info = order.getExternal_info(); |
| | | |
| | | Long uid = DYUtil.getUid(extra_info); |
| | | String type = DYUtil.getTypeFromExtraInfo(extra_info); |
| | | if ("buy".equalsIgnoreCase(type))// 返利订单 |
| | | { |
| | | processFanLiDYOrder(order, uid); |
| | | lostOrderService.processSuceess(order.getOrder_id() + "", Constant.SOURCE_TYPE_DY); |
| | | } else if ("share".equalsIgnoreCase(type)) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processShareDYOrder(order, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiDYOrder(order, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理抖音返利订单 |
| | | * |
| | | * @param dyOrder |
| | | * @param uid |
| | | */ |
| | | private void processFanLiDYOrder(DYOrder dyOrder, Long uid) { |
| | | |
| | | BigDecimal totalMoney = new BigDecimal(dyOrder.getTotal_pay_amount()).divide(new BigDecimal(100),2, RoundingMode.FLOOR); |
| | | |
| | | // 加入订单 |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(dyOrder.getOrder_id() + "", |
| | | Constant.SOURCE_TYPE_DY); |
| | | if (uid == null && oldOrder != null && oldOrder.getBeizhu() != null && oldOrder.getBeizhu().contains("补单")) |
| | | uid = oldOrder.getUserInfo().getId(); |
| | | |
| | | if (uid == null) |
| | | return; |
| | | |
| | | if (oldOrder == null)// 新增 |
| | | { |
| | | Order order = new Order(); |
| | | order.setBeizhu("抖音返利订单"); |
| | | order.setCreatetime(System.currentTimeMillis()); |
| | | order.setOrderId(dyOrder.getOrder_id() + ""); |
| | | order.setOrderType(Constant.SOURCE_TYPE_DY); |
| | | order.setState( |
| | | (dyOrder.getFlow_point().equalsIgnoreCase(DYOrder.FLOW_POINT_REFUND)) ? Order.STATE_SHIXIAO : Order.STATE_YIZHIFU); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | order.setVersion(2); |
| | | order.setThirdCreateTime(new Date(TimeUtil.convertToTimeTemp(dyOrder.getPay_success_time(),"yyyy-MM-dd HH:mm:ss"))); |
| | | order.setMoney(totalMoney); |
| | | // 加入到订单表 |
| | | orderMapper.insertSelective(order); |
| | | } else { |
| | | Order updateOrder = new Order(); |
| | | updateOrder.setId(oldOrder.getId()); |
| | | updateOrder.setMoney(totalMoney); |
| | | orderMapper.updateByPrimaryKeySelective(updateOrder); |
| | | } |
| | | |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addDYOrder(dyOrder, uid); |
| | | addHongBaoWithMQ(commonOrderList, dyOrder.getOrder_id() + "", uid, Constant.SOURCE_TYPE_DY, |
| | | HongBaoV2.TYPE_ZIGOU); |
| | | |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(dyOrder.getOrder_id()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_DY); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | placeOrderCMQManager.addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addDYOrder或addHongBao出错", "订单号:" + dyOrder.getOrder_id()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理抖音分享订单 |
| | | * |
| | | * @param dyOrder |
| | | * @param uid |
| | | */ |
| | | private void processShareDYOrder(DYOrder dyOrder, Long uid) { |
| | | try { |
| | | List<CommonOrderAddResultDTO> commonOrderList = commonOrderService.addDYOrder(dyOrder, uid); |
| | | addHongBaoWithMQ(commonOrderList, dyOrder.getOrder_id() + "", uid, Constant.SOURCE_TYPE_DY, |
| | | HongBaoV2.TYPE_SHARE_GOODS); |
| | | if (isCommonOrderAllAdd(commonOrderList)) { |
| | | Order order = new Order(); |
| | | order.setOrderId(dyOrder.getOrder_id()); |
| | | order.setOrderType(Constant.SOURCE_TYPE_DY); |
| | | order.setUserInfo(new UserInfo(uid)); |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | placeOrderCMQManager.addPlaceOrderMsg(order); |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } catch (CommonOrderException e) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addDYOrder或addHongBao出错", "订单号:" + dyOrder.getOrder_id()); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void repairCommonOrderByByTaoBaoOrder(String orderId) { |
| | | // 根据订单号查询淘宝订单 |
| | | List<TaoBaoOrder> orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(orderId); |
| | | if (orderList != null) |
| | | for (TaoBaoOrder order : orderList) { |
| | | // 根据交易ID查询常规订单 |
| | | CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, |
| | | order.getTradeId()); |
| | | // 修复orderby |
| | | if (commonOrder != null) { |
| | | CommonOrder update = new CommonOrder(commonOrder.getId()); |
| | | update.setOrderBy(order.getOrderBy()); |
| | | update.setUpdateTime(new Date()); |
| | | commonOrderService.updateByPrimaryKeySelective(update); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public boolean isShareOrder(CommonOrder commonOrder) { |
| | | //获取系统 |
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(commonOrder.getUserInfo().getId()); |
| | | SystemEnum system = user.getSystem(); |
| | | switch (commonOrder.getSourceType()) { |
| | | case Constant.SOURCE_TYPE_TAOBAO: |
| | | return isShareOrder(system, taoBaoOrderService.selectByTradeId(commonOrder.getTradeId())); |
| | | case Constant.SOURCE_TYPE_JD: |
| | | return isShareOrder(jdOrderService.selectDetailByOrderId(Long.parseLong(commonOrder.getOrderNo()))); |
| | | case Constant.SOURCE_TYPE_PDD: |
| | | return isShareOrder(pddOrderService.selectByOrderSn(commonOrder.getOrderNo()).get(0)); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 转为普通订单 |
| | | * |
| | | * @param dtoList |
| | | * @return |
| | | */ |
| | | private List<CommonOrder> convertCommonOrder(List<CommonOrderAddResultDTO> dtoList) { |
| | | List<CommonOrder> commonOrderList = new ArrayList<>(); |
| | | if (dtoList != null) |
| | | for (CommonOrderAddResultDTO dto : dtoList) |
| | | commonOrderList.add(dto.getCommonOrder()); |
| | | return commonOrderList; |
| | | } |
| | | |
| | | /** |
| | | * 是否全是增加 |
| | | * |
| | | * @param list |
| | | * @return |
| | | */ |
| | | private boolean isCommonOrderAllAdd(List<CommonOrderAddResultDTO> list) { |
| | | if (list == null || list.size() == 0) |
| | | return false; |
| | | int addCount = 0; |
| | | if (list != null) |
| | | for (CommonOrderAddResultDTO dto : list) { |
| | | if (dto.getType() == CommonOrderAddResultDTO.TYPE_ADD) |
| | | addCount++; |
| | | } |
| | | if (addCount == list.size()) |
| | | return true; |
| | | else |
| | | return false; |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void invalidHongBaoV2AndGiveGodenCorn(Long hongBaoId, Long uid, String orderId, int sourceType, |
| | | String beiZhu) throws Exception { |
| | | HongBaoOrder hongbaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBaoId); |
| | | if (hongbaoOrder != null) { |
| | | CommonOrder commonOrder = commonOrderService.selectByPrimaryKey(hongbaoOrder.getCommonOrder().getId()); |
| | | if (commonOrder != null) { |
| | | if (commonOrder.getState() == CommonOrder.STATE_FK) { |
| | | CommonOrder updateOrder = new CommonOrder(commonOrder.getId()); |
| | | updateOrder.setState(CommonOrder.STATE_SX); |
| | | updateOrder.setUpdateTime(new Date()); |
| | | commonOrderService.updateByPrimaryKeySelective(updateOrder); |
| | | } |
| | | } |
| | | } |
| | | |
| | | HongBaoV2 hongBao = hongBaoV2Service.selectByPrimaryKey(hongBaoId); |
| | | if (hongBao == null || hongBao.getState() == HongBaoV2.STATE_SHIXIAO) |
| | | return; |
| | | |
| | | HongBaoV2 v2 = new HongBaoV2(hongBaoId); |
| | | v2.setState(HongBaoV2.STATE_SHIXIAO); |
| | | v2.setBeizhu(beiZhu); |
| | | v2.setUpdateTime(new Date()); |
| | | hongBaoV2Service.updateByPrimaryKeySelective(v2); |
| | | List<HongBaoV2> children = hongBaoV2Service.listChildrenById(hongBaoId); |
| | | if (children != null) |
| | | for (HongBaoV2 child : children) { |
| | | HongBaoV2 update = new HongBaoV2(child.getId()); |
| | | update.setState(HongBaoV2.STATE_SHIXIAO); |
| | | update.setBeizhu(beiZhu); |
| | | update.setUpdateTime(new Date()); |
| | | hongBaoV2Service.updateByPrimaryKeySelective(update); |
| | | } |
| | | |
| | | if (hongBao.getType() == HongBaoV2.TYPE_ZIGOU || hongBao.getType() == HongBaoV2.TYPE_SHARE_GOODS) { |
| | | userOrderMsgNotificationService.orderInvalidToBusinessRunning(uid, orderId, sourceType, hongBao.getType()); |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void doTaoBaoSellerNotPaid(TaoBaoOrder order) { |
| | | |
| | | // 根据交易ID查询 |
| | | if (!StringUtil.isNullOrEmpty(order.getTradeId())) { |
| | | List<CommonOrder> commonOrderList = commonOrderService |
| | | .listBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, order.getTradeId()); |
| | | if (commonOrderList != null) |
| | | // 查询主订单 |
| | | for (CommonOrder commonOrder : commonOrderList) { |
| | | // 查询主红包 |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null) { |
| | | if (hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_BUKELINGQU || hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_SHIXIAO) { |
| | | // 订单失效,赠送金币 |
| | | try { |
| | | invalidHongBaoV2AndGiveGodenCorn(hongBaoOrder.getHongBaoV2().getId(), hongBaoOrder.getHongBaoV2().getUserInfo().getId(), commonOrder.getOrderNo(), commonOrder.getSourceType(), "订单成功,商家未打款"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void elmeFanli() { |
| | | |
| | | } |
| | | |
| | | // 饿了么订单 |
| | | @Resource |
| | | private ElmeHongBaoOrderMapService elmeHongBaoOrderMapService; |
| | | |
| | | @Resource |
| | | private ElmeOrderService elmeOrderService; |
| | | |
| | | @Resource |
| | | private ElmeOrderProcessService elmeOrderProcessService; |
| | | |
| | | /** |
| | | * 获取饿了么可以返利的红包 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<HongBaoV2> getCanBalanceElmeFanliHongBao() { |
| | | List<Integer> list = new ArrayList<>(); |
| | | list.add(HongBaoV2.TYPE_ELME); |
| | | return hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(list, null, null, new Date(), 0, 1000); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void elmeFanli(Long hongBaoId) { |
| | | // 查询详情 |
| | | HongBaoV2 hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBaoId); |
| | | if (hongBao.getType() == HongBaoV2.TYPE_ELME && hongBao.getState() == HongBaoV2.STATE_KELINGQU |
| | | && hongBao.getPreGetTime() != null && System.currentTimeMillis() > hongBao.getPreGetTime().getTime()) {// 可以到账了 |
| | | // 判断用户状态 |
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(hongBao.getUserInfo().getId()); |
| | | if (user == null || user.getState() != UserInfo.STATE_NORMAL) |
| | | return; |
| | | ElmeHongBaoOrderMap map = elmeHongBaoOrderMapService.selectByHongBaoId(hongBaoId); |
| | | if (map == null) |
| | | return; |
| | | ElmeOrder order = elmeOrderService.selectByPrimaryKey(map.getElmeOrder().getId()); |
| | | if (order == null) |
| | | return; |
| | | |
| | | // 到账,加数据 |
| | | HongBaoV2 update = new HongBaoV2(hongBao.getId()); |
| | | update.setUpdateTime(new Date()); |
| | | update.setGetTime(new Date()); |
| | | update.setState(HongBaoV2.STATE_YILINGQU); |
| | | hongBaoV2Mapper.updateByPrimaryKeySelective(update); |
| | | // 增加资金 |
| | | UserMoneyDetail detail = null; |
| | | try { |
| | | detail = UserMoneyDetailFactory.createElmeFanLi(hongBao.getUserInfo().getId(), order.getOrderId(), |
| | | hongBao.getId(), hongBao.getMoney()); |
| | | } catch (UserMoneyDetailException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | userMoneyService.addUserMoney(hongBao.getUserInfo().getId(), hongBao.getMoney(), detail); |
| | | BigDecimal balance = userInfoMapper.selectByPrimaryKey(hongBao.getUserInfo().getId()).getMyHongBao(); |
| | | } |
| | | // 返利到账 |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加红包与事务消息 |
| | | * |
| | | * @param commonOrderList |
| | | * @param orderId |
| | | * @param uid |
| | | * @param sourceType |
| | | * @param hongBaoType |
| | | */ |
| | | private void addHongBaoWithMQ(List<CommonOrderAddResultDTO> commonOrderList, String orderId, Long uid, |
| | | int sourceType, int hongBaoType) { |
| | | final List<CommonOrder> coList = convertCommonOrder(commonOrderList); |
| | | HongBaoAddResult result = null; |
| | | try { |
| | | long time = TimeUtil.convertToTimeTemp("2019-12-06", "yyyy-MM-dd"); |
| | | if (!Constant.IS_TEST) |
| | | time = TimeUtil.convertToTimeTemp("2019-12-20", "yyyy-MM-dd"); |
| | | |
| | | if (coList.get(0).getThirdCreateTime().getTime() < time) |
| | | result = hongBaoV2Service.addHongBao(coList, hongBaoType); |
| | | else |
| | | result = hongBaoV2AddManager.addHongBao(coList, hongBaoType); |
| | | } catch (HongBaoException e) { |
| | | if (e.getCode() != HongBaoException.CODE_ORDER_WEIQUAN) { |
| | | try { |
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + orderId); |
| | | } catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } catch (UserAccountException e) { |
| | | |
| | | } |
| | | if (result == null) { |
| | | return; |
| | | } |
| | | |
| | | |
| | | if (!Constant.IS_TEST) |
| | | if (result.getResultCode() == HongBaoAddResult.CODE_ADD) {// 只发送新增消息 |
| | | OrderMQMsg mqMsg = new OrderMQMsg(orderId, sourceType, uid, OrderMQMsg.HANDLE_TYPE_ADD, |
| | | isCommonOrderValid(coList), 0, new Date(), result.isMiandan(), coList.get(0).getThirdCreateTime()); |
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderStatistic, mqMsg); |
| | | rocketMQManager.sendNormalMsg(msg, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 订单是否有效 |
| | | * |
| | | * @param coList |
| | | * @return |
| | | */ |
| | | private boolean isCommonOrderValid(List<CommonOrder> coList) { |
| | | for (CommonOrder commonOrder : coList) { |
| | | if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK |
| | | || commonOrder.getState() == CommonOrder.STATE_WQ) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void invalidTaoBaoOrder(String tradeId) { |
| | | TaoBaoOrder taoBaoOrder = taoBaoOrderService.selectByTradeId(tradeId); |
| | | //订单付款和订单成功的状态才允许失效 |
| | | if (taoBaoOrder != null && ("订单付款".equalsIgnoreCase(taoBaoOrder.getOrderState()) || "订单成功".equalsIgnoreCase(taoBaoOrder.getOrderState()))) { |
| | | TaoBaoOrder update = new TaoBaoOrder(); |
| | | update.setId(taoBaoOrder.getId()); |
| | | update.setLatestUpdateTime(new Date()); |
| | | update.setOrderState("订单失效"); |
| | | taoBaoOrderService.updateSelectiveByPrimaryKey(update); |
| | | rabbitmqManager.addTaoBaoOrderMsg(taoBaoOrder.getOrderId()); |
| | | } |
| | | } |
| | | |
| | | } |