| | |
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.HashSet;
|
| | |
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Propagation;
|
| | | 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.HongBaoV2Mapper;
|
| | | 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.money.UserMoneyDetailMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.HongBaoOrderMapper;
|
| | | 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.dto.HongBao;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.bus.user.Order;
|
| | | import com.yeshi.fanli.entity.bus.user.OrderItem;
|
| | | import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.taobao.PidOrder;
|
| | | 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.taobao.PidUser;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanDrawBack;
|
| | | 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.exception.money.UserMoneyDetailException;
|
| | | import com.yeshi.fanli.exception.order.CommonOrderException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.AccountDetailsHongBaoMapService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
|
| | | import com.yeshi.fanli.service.inter.msg.UserMoneyMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService;
|
| | | 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.TaoBaoBuyRelationMapService;
|
| | | 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.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.UserMoneyService;
|
| | | import com.yeshi.fanli.service.inter.user.UserNotificationService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
|
| | | import com.yeshi.fanli.util.CMQManager;
|
| | | import com.yeshi.fanli.util.HongBaoUtil;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TaoBaoConstant;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.factory.AccountDetailsFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
|
| | | import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeOrderApiUtil;
|
| | |
|
| | | @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;
|
| | |
| | | private TaoBaoOrderService taoBaoOrderService;
|
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
|
| | | @Resource
|
| | | private LostOrderService lostOrderService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoWeiQuanOrderMapper taoBaoWeiQuanOrderMapper;
|
| | |
|
| | | @Resource
|
| | | private AccountDetailsHongBaoMapService accountDetailsHongBaoMapService;
|
| | |
|
| | | @Resource
|
| | | private UserMoneyDetailMapper userMoneyDetailMapper;
|
| | |
|
| | | @Resource
|
| | | private HongBaoV2Mapper hongBaoV2Mapper;
|
| | |
|
| | | @Resource
|
| | | private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
|
| | |
|
| | | @Resource
|
| | | private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
|
| | |
|
| | | @Resource
|
| | | private UserSystemCouponService userSystemCouponService;
|
| | |
|
| | | @Resource
|
| | | private UserMoneyService userMoneyService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService;
|
| | |
|
| | | @Resource
|
| | | private CommonOrderService commonOrderService;
|
| | |
|
| | | @Resource
|
| | | private HongBaoV2Service hongBaoV2Service;
|
| | |
|
| | | @Override
|
| | | public void processOrder(Map<String, List<TaoBaoOrder>> orders) {
|
| | | 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<PidOrder>> shareOrderMap = new HashMap<>();
|
| | | Map<String, List<TaoBaoOrder>> 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));
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(list.get(0).getSpecialId())
|
| | | || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)) {// 设置渠道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;
|
| | | }
|
| | | }
|
| | | shareOrderMap.put(orderId, pidOrderList);
|
| | | } else {// 普通返利订单
|
| | | fanliOrderMap.put(orderId, list);
|
| | | }
|
| | | }
|
| | |
| | | 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();
|
| | | String tempOrderId = "";
|
| | | while (its.hasNext()) {
|
| | | try {
|
| | | String orderId = its.next();
|
| | | tempOrderId = orderId;
|
| | | // 处理红包与子红包
|
| | | // if (isRedisLockOrder(orderId))
|
| | | // continue;
|
| | | // redisLockOrder(orderId);
|
| | | processShopingFanliOrder(orderId, orders.get(orderId));
|
| | | processShopingFanliOrderNew(orderId, orders.get(orderId));
|
| | | // redisUnlockOrder(orderId);
|
| | | // 出错了就不处理该订单了,需要定期检查
|
| | |
|
| | | // 更改丢失订单的状态
|
| | | lostOrderService.processSuceess(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<PidOrder>> orders) {
|
| | | pidOrderService.addPidOrderFromTaoBao(orders);
|
| | | }
|
| | | 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();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取最大的创建时间与最小的创建时间
|
| | | * |
| | | * @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);
|
| | | List<HongBaoV2> hongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByType(HongBao.TYPE_TAOBAO, 1000);
|
| | | //
|
| | | // /**
|
| | | // * 需要实时更新待返利的订单
|
| | |
| | | /**
|
| | | * 开始返利
|
| | | */
|
| | | for (HongBao hb : hongBaoList) {
|
| | | for (HongBaoV2 hb : hongBaoList) {
|
| | | //
|
| | | if (hb.getState() == HongBao.STATE_SHIXIAO || hb.getState() == HongBao.STATE_YILINGQU)
|
| | | if (hb.getState() == HongBaoV2.STATE_SHIXIAO || hb.getState() == HongBaoV2.STATE_YILINGQU)
|
| | | continue;
|
| | |
|
| | | if (hb.getPreGettime() == null || hb.getPreGettime() == 0
|
| | | || hb.getPreGettime() > System.currentTimeMillis())
|
| | | if (hb.getPreGetTime() == null || hb.getPreGetTime().getTime() == 0
|
| | | || hb.getPreGetTime().getTime() > System.currentTimeMillis())
|
| | | continue;
|
| | | try {
|
| | | CMQManager.getInstance().addFanLiMsg(hb);
|
| | | CMQManager.getInstance().addFanLiMsgNew(hb);
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 判断订单是否失效 全部订单失效才判断为失效
|
| | | * |
| | | * @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();
|
| | | }
|
| | | @Resource
|
| | | private HongBaoOrderMapper hongBaoOrderMapper;
|
| | |
|
| | | @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 = new BigDecimal(hongBaoManageMapper.selectByKey("hongbao_goods_proportion").getValue());
|
| | |
|
| | | // 查找是否存在红包
|
| | | 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 {
|
| | | public void fanli(HongBaoV2 hb1) throws TaoBaoWeiQuanException {
|
| | | // 查询最新的红包数据
|
| | | hb = hongBaoMapper.selectByPrimaryKeyForUpdate(hb.getId());
|
| | | // 维权中的不返利
|
| | | List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper
|
| | | .selectListByOrderIdAndState(hb.getOrderId(), "维权创建");
|
| | | if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
|
| | | hb1 = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hb1.getId());
|
| | | // 查询红包相关联的订单
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hb1.getId());
|
| | | if (hongBaoOrder == null) {
|
| | | LogHelper.error("返利失败:" + hb1.getId());
|
| | | return;
|
| | | }
|
| | |
|
| | | taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper.selectListByOrderIdAndState(hb.getOrderId(), "等待处理");
|
| | | if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
|
| | | 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;
|
| | |
|
| | | 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);
|
| | | taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper
|
| | | .selectListByOrderIdAndState(hongBaoOrder.getCommonOrder().getOrderNo(), "等待处理");
|
| | | if (taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
|
| | | return;
|
| | | }
|
| | |
|
| | | // 查询同一订单号的红包
|
| | | List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(
|
| | | hongBaoOrder.getCommonOrder().getSourceType(), hongBaoOrder.getCommonOrder().getOrderNo());
|
| | | List<HongBaoV2> hongBaoList = new ArrayList<>();
|
| | | Map<Long, BigDecimal> userMoney = new HashMap<>();
|
| | | Map<Long, List<HongBaoV2>> userHongBao = new HashMap<>();
|
| | | Map<Long, Integer> userGoodsCount = new HashMap<>();
|
| | | // Map<Long, BigDecimal> userPayMent = new HashMap<>();
|
| | | for (CommonOrder co : orderList) {
|
| | | hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(co.getId());
|
| | | hongBaoList.add(hongBaoOrder.getHongBaoV2());
|
| | | Long uid = co.getUserInfo().getId();
|
| | | if (userGoodsCount.get(uid) == null)
|
| | | userGoodsCount.put(uid, co.getCount());
|
| | | else
|
| | | userGoodsCount.put(uid, Integer.valueOf(co.getCount() + userGoodsCount.get(uid)));
|
| | | // if (userPayMent.get(uid) == null)
|
| | | // userPayMent.put(uid, new BigDecimal(0));
|
| | | // if (co.getState() == CommonOrder.STATE_JS)
|
| | | // userPayMent.put(uid,
|
| | | // userPayMent.get(uid).add(co.getSettlement()));
|
| | | // else
|
| | | // userPayMent.put(uid, userPayMent.get(uid).add(co.getPayment()));
|
| | | }
|
| | |
|
| | | for (HongBaoV2 hb : hongBaoList) {
|
| | | long currentTimeMillis = System.currentTimeMillis();
|
| | | if (hb.getState() != HongBao.STATE_SHIXIAO) {
|
| | | // 设置为已返利
|
| | | // 处理主红包
|
| | | if (hb.getState() != HongBaoV2.STATE_SHIXIAO && hb.getState() != HongBaoV2.STATE_YILINGQU
|
| | | && hb.getType() == HongBaoV2.TYPE_ZIGOU) {
|
| | | // 如果红包没被领取
|
| | | Long uid = hb.getUserInfo().getId();
|
| | | HongBaoV2 updateHongBao = new HongBaoV2();
|
| | | updateHongBao.setId(hb.getId());
|
| | | updateHongBao.setState(HongBaoV2.STATE_YILINGQU);
|
| | | updateHongBao.setGetTime(new Date(currentTimeMillis));
|
| | | hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
|
| | | if (userMoney.get(uid) == null)
|
| | | userMoney.put(uid, hb.getMoney());
|
| | | else
|
| | | userMoney.put(uid, userMoney.get(uid).add(hb.getMoney()));
|
| | |
|
| | | // 添加红包到用户
|
| | | if (userHongBao.get(uid) == null)
|
| | | userHongBao.put(uid, new ArrayList<>());
|
| | | userHongBao.get(uid).add(hb);
|
| | | }
|
| | | // 如果红包没被领取
|
| | | 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);
|
| | |
|
| | | // 维权扣款(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) {
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | | Iterator<Long> its = userMoney.keySet().iterator();
|
| | |
|
| | | while (its.hasNext()) {
|
| | | // 将自己添加到用户
|
| | | Long uid = its.next();
|
| | | BigDecimal money = userMoney.get(uid);
|
| | | UserMoneyDetail userMoneyDetail = null;
|
| | | // 插入新版资金明细
|
| | | try {
|
| | | // 此处不用订单号做唯一性索引
|
| | | userMoneyDetail = UserMoneyDetailFactory.createFanLi(uid, hongBaoOrder.getCommonOrder().getOrderNo(),
|
| | | hongBaoOrder.getCommonOrder().getSourceType(), null, money);
|
| | | } catch (UserMoneyDetailException e1) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e1, "订单号:" + hongBaoOrder.getCommonOrder().getOrderNo(), "");
|
| | | } catch (Exception e2) {
|
| | | e2.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | userMoneyService.addUserMoney(uid, money, userMoneyDetail);
|
| | | // 添加资金明细与红包的映射关系
|
| | | for (HongBaoV2 v2 : userHongBao.get(uid)) {
|
| | | accountDetailsHongBaoMapService.saveAccountDetailsHongBaoMap(v2.getId(), userMoneyDetail.getId());
|
| | | }
|
| | |
|
| | | // 站内信+推送
|
| | | UserInfo user = userInfoMapper.selectByPKey(uid);
|
| | | try {
|
| | | userNotificationService.orderFanliRecieved(uid, hongBaoOrder.getCommonOrder().getOrderNo(),
|
| | | userGoodsCount.get(uid), user.getMyHongBao(), money);
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | // 新版通知
|
| | | userMoneyMsgNotificationService.fanliOrderReceived(uid, hongBaoOrder.getCommonOrder().getOrderNo(),
|
| | | userGoodsCount.get(uid), money, user.getMyHongBao());
|
| | | }
|
| | | // 通知免单到账
|
| | | try {
|
| | | userSystemCouponService.updateStateByArrivalAccount(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | // 维权扣款(2018-08-05后开始实行)
|
| | | if (hongBaoOrder.getCommonOrder().getSettleTime() != null && hongBaoOrder.getCommonOrder().getSettleTime()
|
| | | .getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
|
| | | try {
|
| | | if (hongBaoOrder.getCommonOrder().getSourceType() == Constant.SOURCE_TYPE_TAOBAO)
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanFanli(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | | } catch (TaoBaoWeiQuanException e) {
|
| | | if (e.getCode() == TaoBaoWeiQuanException.CODE_NEDD_UPDATE_ORDER) {
|
| | | List<TaoBaoOrder> olist = taoBaoOrderService
|
| | | .getTaoBaoOrderByOrderId(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | |
|
| | | if (olist != null && olist.size() > 0) {
|
| | | long time = TimeUtil.convertToTimeTemp(olist.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss");
|
| | | olist = TaoKeOrderApiUtil.getTaoBaoAllOrder(TimeUtil.getGernalTime(time, "yyyy-MM-dd HH:mm:ss"),
|
| | | TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
|
| | | List<TaoBaoOrder> thirdOList = TaoKeOrderApiUtil.getTaoBaoThirdAllOrder(
|
| | | TimeUtil.getGernalTime(time, "yyyy-MM-dd HH:mm:ss"), 30, 1,
|
| | | TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET);
|
| | | if (thirdOList != null && thirdOList.size() > 0)
|
| | | olist.addAll(thirdOList);
|
| | |
|
| | | if (olist != null && olist.size() > 0) {
|
| | | for (int i = 0; i < olist.size(); i++) {
|
| | | if (!olist.get(i).getOrderId()
|
| | | .equalsIgnoreCase(hongBaoOrder.getCommonOrder().getOrderNo())) {// 删除无关订单
|
| | | olist.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | |
|
| | | taoBaoOrderService.addTaoBaoOrderList(olist);
|
| | | }
|
| | | }
|
| | | } else
|
| | | throw new TaoBaoWeiQuanException(e.getCode(), e.getMsg());
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void weiQuanOrder(List<TaoBaoWeiQuanOrder> orderList) {
|
| | | if (orderList != null)
|
| | | for (TaoBaoWeiQuanOrder order : orderList) {
|
| | | if (order.getState().equalsIgnoreCase("维权成功")) {
|
| | | if (order.getState().contains("维权成功")) {
|
| | | CMQManager.getInstance().addWeiQuanOrderMsg(order);
|
| | | }
|
| | | }
|
| | |
| | | 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;
|
| | | // if (order.getJieSuanTime().getTime() >=
|
| | | // TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
|
| | | // return;
|
| | | // }
|
| | |
|
| | | // TODO 处理维权成功但是已到账的订单
|
| | |
|
| | | if (order.getJieSuanTime().getTime() > TimeUtil.convertToTimeTemp("2019-01-01", "yyyy-MM-dd")) {// 结算时间在2月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) {// 还未扣款
|
| | | try {
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanFanli(order.getOrderId());
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanShare(order.getOrderId());
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanInvite(order.getOrderId());
|
| | | } catch (TaoBaoWeiQuanException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, null, "订单号:" + order.getOrderId());
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | 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();
|
| | | List<Long> inviteAndShareUids = hongBaoV2Mapper.listUidCanBanlanceShareAndInvite(1000);
|
| | | Set<Long> uidSets = new HashSet<>();
|
| | | if (shareUids != null)
|
| | | for (Long uid : shareUids)
|
| | | uidSets.add(uid);
|
| | | if (inviteUids != null)
|
| | | for (Long uid : inviteUids)
|
| | | if (inviteAndShareUids != null)
|
| | | for (Long uid : inviteAndShareUids)
|
| | | uidSets.add(uid);
|
| | | // 根据用户ID
|
| | | Iterator<Long> its = uidSets.iterator();
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | private HongBao filterWeiQuanINGHongBao(HongBao hongBao) {
|
| | | private HongBaoV2 filterWeiQuanINGHongBao(HongBaoV2 hongBao) {
|
| | |
|
| | | long hbId = hongBao.getId();
|
| | | if (hongBao.getParent() != null) {
|
| | | hbId = hongBao.getParent().getId();
|
| | | }
|
| | |
|
| | | HongBaoOrder hongbaoOrder = hongBaoOrderMapper.selectByHongBaoId(hbId);
|
| | |
|
| | | if (hongbaoOrder == null)
|
| | | return null;
|
| | |
|
| | | List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList = taoBaoWeiQuanOrderMapper
|
| | | .selectListByOrderIdAndState(hongBao.getOrderId(), "维权创建");
|
| | | .selectListByOrderIdAndState(hongbaoOrder.getCommonOrder().getOrderNo(), "维权创建");
|
| | |
|
| | | List<TaoBaoWeiQuanOrder> taoBaoWeiQuanList1 = taoBaoWeiQuanOrderMapper
|
| | | .selectListByOrderIdAndState(hongBao.getOrderId(), "等待处理");
|
| | | .selectListByOrderIdAndState(hongbaoOrder.getCommonOrder().getOrderNo(), "等待处理");
|
| | | if ((taoBaoWeiQuanList != null && taoBaoWeiQuanList.size() > 0)
|
| | | || (taoBaoWeiQuanList1 != null && taoBaoWeiQuanList1.size() > 0)) {
|
| | | return null;
|
| | |
| | | * 处理邀请赚订单
|
| | | */
|
| | | // 查询UID的邀请赚订单
|
| | | List<HongBao> hongBaoList = hongBaoMapper.selectCanBalanceHongBaoByChildHongBaoAndUid(uid);
|
| | | List<Integer> types = new ArrayList<>();
|
| | | types.add(HongBaoV2.TYPE_YIJI);
|
| | | types.add(HongBaoV2.TYPE_ERJI);
|
| | | List<HongBaoV2> hongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, 1000);
|
| | |
|
| | | BigDecimal money = new BigDecimal(0);
|
| | | List<Long> hbIdList = new ArrayList<>();
|
| | |
|
| | | BigDecimal invitemoney = new BigDecimal(0);
|
| | | Set<String> inviteOrders = new HashSet<>();
|
| | | int inviteGoodsCount = 0;
|
| | |
|
| | | // 需要判断退款的订单号
|
| | | Set<String> drawBackOrders = new HashSet<String>();
|
| | | for (HongBao hongBao : hongBaoList) {
|
| | | for (HongBaoV2 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();
|
| | |
|
| | | hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBao.getId());
|
| | | if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU || hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
|
| | | invitemoney = invitemoney.add(hongBao.getMoney());
|
| | | HongBaoV2 updateHongBao = new HongBaoV2();
|
| | | updateHongBao.setId(hongBao.getId());
|
| | | updateHongBao.setGetTime(System.currentTimeMillis());
|
| | | updateHongBao.setState(HongBao.STATE_YILINGQU);
|
| | | hongBaoMapper.updateByPrimaryKeySelective(updateHongBao);
|
| | | updateHongBao.setGetTime(new Date());
|
| | | updateHongBao.setState(HongBaoV2.STATE_YILINGQU);
|
| | | updateHongBao.setUpdateTime(new Date());
|
| | | hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
|
| | | // 添加到红包返利记录集合
|
| | | hbIdList.add(hongBao.getId());
|
| | |
|
| | | // 2018-08-05 过后的订单才处理维权
|
| | | Date balanceTime = null;
|
| | | if (hongBao.getParent() != null)
|
| | | balanceTime = hongBao.getParent().getBalanceTime();
|
| | | else
|
| | | balanceTime = hongBao.getBalanceTime();
|
| | |
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getParent().getId());
|
| | | inviteGoodsCount += hongBaoOrder.getCommonOrder().getCount();
|
| | | inviteOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | |
|
| | | Date balanceTime = hongBaoOrder.getCommonOrder().getSettleTime();
|
| | | 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());
|
| | | if (!StringUtil.isNullOrEmpty(hongBaoOrder.getCommonOrder().getOrderNo()))
|
| | | drawBackOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 处理顶级分享赚
|
| | | * 处理一级二级分享赚(属于邀请赚类型)
|
| | | */
|
| | |
|
| | | // 查询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);
|
| | | // 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<>();
|
| | | List<HongBaoV2> totalHongBaoList = new ArrayList<>();
|
| | | // 查询UID的二级或者三级分享赚订单
|
| | | // TODO 暂时查询10000条数据,后面再做分页
|
| | | List<HongBao> hbList = hongBaoMapper.selectCanBalanceHongBaoByTypeAndUid(HongBao.TYPE_SHARE_YIJI, uid, 10000);
|
| | | types.clear();
|
| | | types.add(HongBaoV2.TYPE_SHARE_YIJI);
|
| | | types.add(HongBaoV2.TYPE_SHARE_ERJI);
|
| | | List<HongBaoV2> hbList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, 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) {
|
| | | for (HongBaoV2 hb : totalHongBaoList) {
|
| | | if (hb.getState() == HongBaoV2.STATE_BUKELINGQU || hb.getState() == HongBaoV2.STATE_KELINGQU) {
|
| | | hb = filterWeiQuanINGHongBao(hb);
|
| | | if (hb == null)
|
| | | continue;
|
| | | money = money.add(hb.getMoney());
|
| | | HongBao updateHongBao = new HongBao();
|
| | | invitemoney = invitemoney.add(hb.getMoney());
|
| | | HongBaoV2 updateHongBao = new HongBaoV2();
|
| | | updateHongBao.setId(hb.getId());
|
| | | updateHongBao.setGetTime(System.currentTimeMillis());
|
| | | updateHongBao.setState(HongBao.STATE_YILINGQU);
|
| | | hongBaoMapper.updateByPrimaryKeySelective(updateHongBao);
|
| | | if (!StringUtil.isNullOrEmpty(hb.getOrderId()))
|
| | | drawBackOrders.add(hb.getOrderId());
|
| | | updateHongBao.setGetTime(new Date());
|
| | | updateHongBao.setState(HongBaoV2.STATE_YILINGQU);
|
| | | updateHongBao.setUpdateTime(new Date());
|
| | | hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
|
| | | // 添加到红包返利记录集合
|
| | | hbIdList.add(hb.getId());
|
| | |
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hb.getParent().getId());
|
| | | inviteGoodsCount += hongBaoOrder.getCommonOrder().getCount();
|
| | | inviteOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | | if (!StringUtil.isNullOrEmpty(hongBaoOrder.getCommonOrder().getOrderNo()))
|
| | | drawBackOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 增加用户资金记录
|
| | | */
|
| | | // 邀请赚到账
|
| | | if (invitemoney.compareTo(new BigDecimal(0)) > 0) {
|
| | |
|
| | | 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);
|
| | | // 添加新版详情记录
|
| | | try {
|
| | | // 查询邀请赚的有效订单,失效订单,维权订单
|
| | | Calendar ca = Calendar.getInstance();
|
| | | Date maxDate = new Date(TimeUtil
|
| | | .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
|
| | | ca.add(Calendar.MONTH, -1);
|
| | |
|
| | | Date minDate = new Date(TimeUtil
|
| | | .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
|
| | | long validCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS,
|
| | | minDate, maxDate);
|
| | | long weiQuanCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ,
|
| | | minDate, maxDate);
|
| | | long invalidCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_SX,
|
| | | minDate, maxDate);
|
| | |
|
| | | UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createInvite(uid, (int) validCount,
|
| | | (int) weiQuanCount, (int) invalidCount, invitemoney, new Date());
|
| | |
|
| | | // 增加资金
|
| | | userMoneyService.addUserMoney(uid, invitemoney, userMoneyDetail);
|
| | | // 添加到红包返利记录集合
|
| | | accountDetailsHongBaoMapService.saveAccountDetailsHongBaoMap(hbIdList, userMoneyDetail.getId());
|
| | | } catch (UserMoneyDetailException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | // 发送推送
|
| | | try {
|
| | | // 提成到账消息通知
|
| | | userNotificationService.tiChengRecieved(uid, money);
|
| | | userNotificationService.tiChengInviteRecieved(uid, inviteOrders.size(), inviteGoodsCount, null,
|
| | | invitemoney);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | // 新版通知
|
| | | userMoneyMsgNotificationService.inviteOrderReceived(uid, inviteOrders.size(), inviteGoodsCount, invitemoney,
|
| | | userInfoMapper.selectByPKey(uid).getMyHongBao());
|
| | |
|
| | | for (String orderId : drawBackOrders)
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanInvite(orderId);
|
| | | }
|
| | |
|
| | | hbIdList.clear();
|
| | | drawBackOrders.clear();
|
| | |
|
| | | /**
|
| | | * 处理分享赚
|
| | | */
|
| | |
|
| | | int shareGoodsCount = 0;
|
| | | Set<String> shareOrders = new HashSet<>();
|
| | | BigDecimal sharemoney = new BigDecimal(0);
|
| | | // 查询UID的分享赚订单
|
| | | types.clear();
|
| | | types.add(HongBaoV2.TYPE_SHARE_GOODS);
|
| | | List<HongBaoV2> hongBaoShareList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, 10000);
|
| | | for (HongBaoV2 hongBao : hongBaoShareList) {
|
| | | hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBao.getId());
|
| | | hongBao = filterWeiQuanINGHongBao(hongBao);
|
| | | if (hongBao == null)
|
| | | continue;
|
| | | if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU || hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
|
| | | sharemoney = sharemoney.add(hongBao.getMoney());
|
| | | HongBaoV2 updateHongBao = new HongBaoV2();
|
| | | updateHongBao.setId(hongBao.getId());
|
| | | updateHongBao.setGetTime(new Date());
|
| | | updateHongBao.setState(HongBao.STATE_YILINGQU);
|
| | | updateHongBao.setUpdateTime(new Date());
|
| | | hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
|
| | | // 添加到红包返利记录集合
|
| | | hbIdList.add(hongBao.getId());
|
| | | // 2018-08-05 过后的订单才处理维权
|
| | | Date balanceTime = null;
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getId());
|
| | | if (hongBaoOrder != null) {
|
| | | balanceTime = hongBaoOrder.getCommonOrder().getSettleTime();
|
| | | shareGoodsCount += hongBaoOrder.getCommonOrder().getCount();
|
| | | }
|
| | | shareOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | | if (balanceTime != null
|
| | | && balanceTime.getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
|
| | | drawBackOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 分享赚到账
|
| | | */
|
| | |
|
| | | if (sharemoney.compareTo(new BigDecimal(0)) > 0) {
|
| | | // 添加新版详情记录
|
| | | try {
|
| | | // 计算本月的有效订单,失效订单,维权订单
|
| | | Calendar ca = Calendar.getInstance();
|
| | |
|
| | | Date maxDate = new Date(TimeUtil
|
| | | .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
|
| | | ca.add(Calendar.MONTH, -1);
|
| | |
|
| | | Date minDate = new Date(TimeUtil
|
| | | .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
|
| | | long validCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS, minDate, maxDate);
|
| | | long weiQuanCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ, minDate, maxDate);
|
| | | long invalidCount =hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_SX, minDate, maxDate);
|
| | |
|
| | | UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, (int) validCount,
|
| | | (int) weiQuanCount, (int) invalidCount, sharemoney, new Date());
|
| | | // 添加资金
|
| | | userMoneyService.addUserMoney(uid, sharemoney, userMoneyDetail);
|
| | |
|
| | | // 添加到红包返利记录集合
|
| | | accountDetailsHongBaoMapService.saveAccountDetailsHongBaoMap(hbIdList, userMoneyDetail.getId());
|
| | | } catch (UserMoneyDetailException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | // 发送推送
|
| | | try {
|
| | | // 提成到账消息通知
|
| | | userNotificationService.tiChengShareRecieved(uid, shareOrders.size(), shareGoodsCount, null,
|
| | | sharemoney);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | // 新版通知
|
| | | userMoneyMsgNotificationService.shareOrderReceived(uid, shareOrders.size(), shareGoodsCount, sharemoney,
|
| | | userInfoMapper.selectByPrimaryKey(uid).getMyHongBao());
|
| | |
|
| | | for (String orderId : drawBackOrders)
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanShare(orderId);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @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());
|
| | |
|
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(orderId, Constant.SOURCE_TYPE_TAOBAO);
|
| | | // 原来不存在订单
|
| | | Long uid = null;
|
| | | if (oldOrder == null) {
|
| | | PidUser pidUser = null;// pidUserMapper.selectByPid(pid);
|
| | | if (pidUser != null) {
|
| | | uid = pidUser.getUid();
|
| | |
|
| | | // 插入到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 {
|
| | | Long targetUid = null;
|
| | | if (pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)
|
| | | && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {
|
| | | targetUid = taoBaoBuyRelationMapService.selectUidByRelationId(orderList.get(0).getRelationId());
|
| | |
|
| | | } else if (!StringUtil.isNullOrEmpty(orderList.get(0).getSpecialId())) {
|
| | | UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService
|
| | | .getBySpecialId(orderList.get(0).getSpecialId());
|
| | | 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<CommonOrder> commonOrderList = null;
|
| | | try {
|
| | | commonOrderList = commonOrderService.addTaoBaoOrder(orderList, uid);
|
| | | hongBaoV2Service.addHongBao(commonOrderList, HongBaoV2.TYPE_ZIGOU);
|
| | |
|
| | | } catch (CommonOrderException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "addTaoBaoOrder或addHongBao出错", "订单号:" + orderId);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void processShareGoodsOrderNew(String orderId, List<TaoBaoOrder> orderList) {
|
| | | 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());
|
| | | // 原来不存在订单
|
| | | Long uid = null;
|
| | | PidUser pidUser = null; // pidUserMapper.selectByPid(pid);-PID机制移除
|
| | | if (pidUser != null)
|
| | | uid = pidUser.getUid();
|
| | | else {
|
| | | UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService.getByRelationId(orderList.get(0).getRelationId());
|
| | | 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<CommonOrder> commonOrders = commonOrderService.addTaoBaoOrder(orderList, uid);
|
| | | hongBaoV2Service.addHongBao(commonOrders, HongBaoV2.TYPE_SHARE_GOODS);
|
| | | } catch (CommonOrderException e) {
|
| | | e.printStackTrace();
|
| | | } catch (HongBaoException e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|