| | |
| | | package com.yeshi.fanli.service.impl.order;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.FileNotFoundException;
|
| | | import java.math.BigDecimal;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | |
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Scanner;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Propagation;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper;
|
| | |
| | | import com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.CommonOrderTradeIdMapMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.HongBaoOrderMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.OrderRepairHistoryMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.money.UserMoneyDetail;
|
| | | import com.yeshi.fanli.entity.order.CommonOrder;
|
| | | import com.yeshi.fanli.entity.order.CommonOrderGoods;
|
| | | import com.yeshi.fanli.entity.order.CommonOrderTradeIdMap;
|
| | |
| | | import com.yeshi.fanli.entity.order.ShareGoodsActivityOrder;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
|
| | | import com.yeshi.fanli.exception.HongBaoException;
|
| | | import com.yeshi.fanli.exception.money.UserMoneyDetailException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service;
|
| | | import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderRepairHistoryService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderRepairService;
|
| | | import com.yeshi.fanli.service.inter.order.ShareGoodsActivityOrderService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoOrderService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoWeiQuanOrderService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.UserMoneyService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.factory.CommonOrderGoodsFactory;
|
| | | import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
|
| | | @Service
|
| | | public class OrderRepairServiceImpl implements OrderRepairService {
|
| | |
|
| | | @Resource
|
| | | private OrderRepairHistoryMapper orderRepairHistoryMapper;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoOrderService taoBaoOrderService;
|
| | |
| | | @Resource
|
| | | private OrderRepairHistoryService orderRepairHistoryService;
|
| | |
|
| | | @Resource
|
| | | private DataSourceTransactionManager dataSourceTransactionManager;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoWeiQuanOrderService taoBaoWeiQuanOrderService;
|
| | |
|
| | | @Resource
|
| | | private UserMoneyService userMoneyService;
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void repairOrder(String orderId) {
|
| | | public void repairOrder(String orderId) throws Exception {
|
| | | // 比较CommonOrder与TaoBaoOrder的预估收益
|
| | | List<TaoBaoOrder> orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(orderId);
|
| | | // 统计
|
| | | BigDecimal sumMoney = new BigDecimal("0");
|
| | | for (TaoBaoOrder order : orderList) {
|
| | | // if (order.getOrderState().equalsIgnoreCase("订单付款") ||
|
| | | // order.getOrderState().equalsIgnoreCase("订单成功"))
|
| | | // return;
|
| | | if (order.getSubsidy() == null)
|
| | | order.setSubsidy(new BigDecimal(0));
|
| | | if (order.geteIncome() == null)
|
| | | order.seteIncome(new BigDecimal(0));
|
| | |
|
| | | BigDecimal money = order.geteIncome().add(order.getSubsidy());
|
| | | sumMoney = sumMoney.add(money);
|
| | | if (order.getOrderState().equalsIgnoreCase("订单付款") || order.getOrderState().equalsIgnoreCase("订单成功"))
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | List<CommonOrder> commonOrderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
|
| | | orderId);
|
| | |
| | | commonSumMoney = commonSumMoney.add(commonOrder.geteIncome());
|
| | | }
|
| | |
|
| | | try {
|
| | | processLessFanOrder(orderId);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | // 不处理维权过的订单
|
| | | List<TaoBaoWeiQuanOrder> weiQuanOrderList = taoBaoWeiQuanOrderService.getWeiQuanSuccessOrders(orderId);
|
| | | if (weiQuanOrderList != null && weiQuanOrderList.size() > 0)
|
| | | return;
|
| | |
|
| | | processLessFanOrder(orderId);
|
| | |
|
| | | // if (sumMoney.compareTo(commonSumMoney) > 0) {
|
| | | // // 少返了
|
| | |
| | |
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
| | | private void processLessFanOrder(String orderId) throws Exception {
|
| | | List<CommonOrder> commonOrderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
|
| | |
|
| | | List<CommonOrder> commonOrderList = commonOrderMapper.listBySourceTypeAndOrderNo(Constant.SOURCE_TYPE_TAOBAO,
|
| | | orderId);
|
| | | // 确定是自购还是分享赚
|
| | | if (commonOrderList.size() <= 0)
|
| | | return;
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(commonOrderList.get(0).getId());
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrderList.get(0).getId());
|
| | | // 统计原来的上下级关系及返利的资金
|
| | | Map<Long, BigDecimal> oldMoney = new HashMap<>();
|
| | | Long firstUid = null;
|
| | |
| | | Long mainUid = null;
|
| | | // 统计返利的资金
|
| | | for (CommonOrder co : commonOrderList) {
|
| | | HongBaoOrder tempHongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(co.getId());
|
| | | HongBaoOrder tempHongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(co.getId());
|
| | | if (tempHongBaoOrder == null || tempHongBaoOrder.getHongBaoV2() == null)
|
| | | continue;
|
| | | hongBaoOrder = tempHongBaoOrder;
|
| | |
| | | if (hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_YILINGQU)
|
| | | oldMoney.put(mainUid, oldMoney.get(mainUid).add(hongBaoOrder.getHongBaoV2().getMoney()));
|
| | | // 查询是否有下级
|
| | | List<HongBaoV2> childrenList = hongBaoV2Service.listChildrenById(hongBaoOrder.getHongBaoV2().getId());
|
| | | List<HongBaoV2> childrenList = hongBaoV2Mapper.listChildrenById(hongBaoOrder.getHongBaoV2().getId());
|
| | | for (HongBaoV2 child : childrenList) {
|
| | | if (child.getType() == HongBaoV2.TYPE_YIJI || child.getType() == HongBaoV2.TYPE_SHARE_YIJI) {
|
| | | firstUid = child.getUserInfo().getId();
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // FileWriter fw = null;
|
| | | // try {
|
| | | // // 如果文件存在,则追加内容;如果文件不存在,则创建文件
|
| | | // File f = new File("D:\\three_sale.txt");
|
| | | // fw = new FileWriter(f, true);
|
| | | // } catch (IOException e) {
|
| | | // e.printStackTrace();
|
| | | // }
|
| | | // PrintWriter pw = new PrintWriter(fw);
|
| | | // pw.println(orderId+"#"+firstUid+"-"+oldMoney.get(firstUid)+"#"+secondUid+"-"+(secondUid!=null?
|
| | | // oldMoney.get(secondUid):""));
|
| | | // pw.flush();
|
| | | // try {
|
| | | // fw.flush();
|
| | | // pw.close();
|
| | | // fw.close();
|
| | | // } catch (IOException e) {
|
| | | // e.printStackTrace();
|
| | | // }
|
| | | //
|
| | | // if (1 > 0)
|
| | | // return;
|
| | |
|
| | | List<TaoBaoOrder> taoBaoOrderList = taoBaoOrderService.getTaoBaoOrderByOrderId(orderId);
|
| | |
|
| | |
| | | if (newCommonOrderList != null)
|
| | | for (CommonOrder co : newCommonOrderList) {
|
| | | HongBaoOrder newHongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(co.getId());
|
| | | if (newHongBaoOrder == null)
|
| | | continue;
|
| | | HongBaoV2 hongBao = newHongBaoOrder.getHongBaoV2();
|
| | | if (hongBao.getState() == HongBaoV2.STATE_YILINGQU) {
|
| | | Long uid = hongBao.getUserInfo().getId();
|
| | | if (newMap.get(uid) == null)
|
| | | newMap.put(uid, new BigDecimal(0));
|
| | | newMap.put(uid, newMap.get(uid).add(hongBao.getMoney()));
|
| | | } else {
|
| | | Long uid = hongBao.getUserInfo().getId();
|
| | | if (newMap.get(uid) == null)
|
| | | newMap.put(uid, new BigDecimal(0));
|
| | | }
|
| | | List<HongBaoV2> children = hongBaoV2Service.listChildrenById(hongBao.getId());
|
| | | if (children != null)
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | public void addOrder(CommonOrder commonOrder, int type, Long firstUid, Long secondUid) throws Exception {
|
| | | // 增加commonOrder
|
| | | commonOrder.setCreateTime(commonOrder.getThirdCreateTime());
|
| | |
| | | if (mianDanMoney != null)
|
| | | hongBao.setMoney(mianDanMoney);
|
| | |
|
| | | UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId());
|
| | | UserInfo user = userInfoService.getUserByIdWithMybatis(commonOrder.getUserInfo().getId());
|
| | | hongBao.setUrank(user.getRank());
|
| | | hongBaoV2Mapper.insertSelective(hongBao);
|
| | | // 添加红包与订单的映射
|
| | |
| | | firstHongbao.setVersion(2);
|
| | | firstHongbao.setState(hongBao.getState());
|
| | |
|
| | | if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
|
| | | if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {// ||
|
| | | // hongBao.getState()
|
| | | // ==
|
| | | // HongBaoV2.STATE_YILINGQU
|
| | | firstHongbao.setMoney(
|
| | | MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
|
| | | Calendar calendar = Calendar.getInstance();
|
| | |
| | | secondHongbao.setType(HongBaoV2.TYPE_ERJI);
|
| | | secondHongbao.setVersion(2);
|
| | | secondHongbao.setState(hongBao.getState());
|
| | | if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
|
| | | if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) {// ||
|
| | | // hongBao.getState()
|
| | | // ==
|
| | | // HongBaoV2.STATE_YILINGQU
|
| | | secondHongbao.setMoney(
|
| | | MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100))));
|
| | | Calendar calendar = Calendar.getInstance();
|
| | |
| | | hongBao.setState(HongBaoV2.STATE_YILINGQU);
|
| | | }
|
| | | }
|
| | | UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId());
|
| | | UserInfo user = userInfoService.getUserByIdWithMybatis(commonOrder.getUserInfo().getId());
|
| | | hongBao.setUrank(user.getRank());
|
| | | hongBao.setUserInfo(user);
|
| | | hongBaoV2Mapper.insertSelective(hongBao);
|
| | |
| | |
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Transactional(propagation = Propagation.REQUIRED)
|
| | | private void deleteByCommonOrderId(Long commonOrderId) {
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(commonOrderId);
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrderId);
|
| | | if (hongBaoOrder == null || hongBaoOrder.getHongBaoV2() == null)
|
| | | return;
|
| | | List<HongBaoV2> children = hongBaoV2Service.listChildrenById(hongBaoOrder.getHongBaoV2().getId());
|
| | | List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBaoOrder.getHongBaoV2().getId());
|
| | | if (children != null)
|
| | | for (HongBaoV2 hongBao : children) {
|
| | | hongBaoV2Service.deleteByPrimaryKey(hongBao.getId());
|
| | | hongBaoV2Mapper.deleteByPrimaryKey(hongBao.getId());
|
| | | }
|
| | | hongBaoV2Service.deleteByPrimaryKey(hongBaoOrder.getHongBaoV2().getId());
|
| | | hongBaoOrderService.deleteByPrimaryKey(hongBaoOrder.getId());
|
| | | commonOrderService.deleteByPrimaryKey(commonOrderId);
|
| | | hongBaoV2Mapper.deleteByPrimaryKey(hongBaoOrder.getHongBaoV2().getId());
|
| | | hongBaoOrderMapper.deleteByPrimaryKey(hongBaoOrder.getId());
|
| | | commonOrderMapper.deleteByPrimaryKey(commonOrderId);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void testTransaction() {
|
| | | hongBaoV2Mapper.selectByPrimaryKey(1L);
|
| | | }
|
| | |
|
| | | private static Map<String, OrderInfo> orderInfoMap;
|
| | |
|
| | | private OrderInfo getOrderInfo(String orderId) {
|
| | | if (orderInfoMap == null) {
|
| | | orderInfoMap = new HashMap<>();
|
| | | Scanner scanner = null;
|
| | | try {
|
| | | scanner = new Scanner(new File("C:\\Users\\Administrator\\Desktop\\订单集中排查\\three_sale.txt"));
|
| | | while (scanner.hasNext()) {
|
| | | OrderInfo orderInfo = new OrderInfo();
|
| | | String info = scanner.next();
|
| | | if (StringUtil.isNullOrEmpty(info))
|
| | | continue;
|
| | |
|
| | | String[] sts = info.split("#");
|
| | | String orderid = sts[0];
|
| | | orderInfo.setOrderId(orderid);
|
| | | String firstUid = sts[1].split("-")[0];
|
| | | String firstUidMoney = sts[1].split("-")[1];
|
| | | orderInfo.setFirstUid(Long.parseLong(firstUid));
|
| | | orderInfo.setFirstUidMoney(new BigDecimal(firstUidMoney));
|
| | |
|
| | | String secondUid = sts[2].split("-")[0];
|
| | | String secondUidMoney = null;
|
| | | if (sts[2].split("-").length > 1)
|
| | | secondUidMoney = sts[2].split("-")[1];
|
| | | if (!StringUtil.isNullOrEmpty(secondUid))
|
| | | orderInfo.setSecondUid(Long.parseLong(secondUid));
|
| | | if (!StringUtil.isNullOrEmpty(secondUidMoney))
|
| | | orderInfo.setSecondUidMoney(new BigDecimal(secondUidMoney));
|
| | | orderInfoMap.put(orderInfo.getOrderId(), orderInfo);
|
| | | }
|
| | | } catch (FileNotFoundException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | scanner.close();
|
| | | }
|
| | |
|
| | | return orderInfoMap.get(orderId);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void repireFirstAndSecondLevel(String orderId) throws Exception {
|
| | | OrderInfo info = getOrderInfo(orderId);
|
| | | Map<Long, BigDecimal> oldMoneyMap = new HashMap<>();
|
| | | if (info.getFirstUid() != null)
|
| | | oldMoneyMap.put(info.getFirstUid(), info.getFirstUidMoney());
|
| | | if (info.getSecondUid() != null)
|
| | | oldMoneyMap.put(info.getSecondUid(), info.getSecondUidMoney());
|
| | |
|
| | | if (info != null) {
|
| | | List<CommonOrder> list = commonOrderMapper.listBySourceTypeAndOrderNo(Constant.SOURCE_TYPE_TAOBAO,
|
| | | info.getOrderId());
|
| | | // 查询是否有子红包
|
| | | for (CommonOrder commonOrder : list) {
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder == null)
|
| | | continue;
|
| | | List<HongBaoV2> hongBaoList = hongBaoV2Mapper.listChildrenById(hongBaoOrder.getHongBaoV2().getId());
|
| | | if (hongBaoList != null && hongBaoList.size() > 0)// 有子红包就不处理了
|
| | | return;
|
| | | }
|
| | |
|
| | | for (CommonOrder commonOrder : list) {
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | HongBaoV2 hongBao = hongBaoOrder.getHongBaoV2();
|
| | | Long firstUid = info.getFirstUid();
|
| | | Long secondUid = info.getSecondUid();
|
| | | // 加入子红包
|
| | | UserInfo boss = null;
|
| | | if (firstUid != null)
|
| | | boss = userInfoService.selectByPKey(firstUid);
|
| | |
|
| | | if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO) {// 1级BOSS存在且红包未失效,免单不支持多级分销
|
| | | // 插入一级子红包
|
| | | BigDecimal firstRate = hongBaoManageService
|
| | | .getFirstInviteRate(boss.getRank() == null ? 0 : boss.getRank());
|
| | | if (firstRate.compareTo(new BigDecimal(0)) <= 0)
|
| | | return;
|
| | | HongBaoV2 firstHongbao = new HongBaoV2();
|
| | | firstHongbao.setBeizhu("2019年7月批量修改");
|
| | | firstHongbao.setUserInfo(boss);
|
| | | firstHongbao.setUrank(boss.getRank());
|
| | | firstHongbao.setParent(hongBao);
|
| | | firstHongbao.setCreateTime(new Date());
|
| | | firstHongbao.setType(HongBaoV2.TYPE_YIJI);
|
| | | firstHongbao.setVersion(2);
|
| | | firstHongbao.setState(hongBao.getState());
|
| | |
|
| | | if (hongBao.getState() == HongBaoV2.STATE_KELINGQU
|
| | | || hongBao.getState() == HongBaoV2.STATE_YILINGQU) {
|
| | | firstHongbao.setMoney(
|
| | | MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTime(commonOrder.getSettleTime());
|
| | | calendar.add(Calendar.MONTH, 1);
|
| | | firstHongbao.setPreGetTime(new Date(TimeUtil.convertToTimeTemp(
|
| | | calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25",
|
| | | "yyyy-M-dd")));
|
| | | if (firstHongbao.getPreGetTime().getTime() < System.currentTimeMillis()) {
|
| | | firstHongbao.setGetTime(firstHongbao.getPreGetTime());
|
| | | firstHongbao.setState(HongBaoV2.STATE_YILINGQU);
|
| | | }
|
| | | } else if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU) {
|
| | | firstHongbao.setMoney(
|
| | | MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100))));
|
| | | }
|
| | | // 返利为0的不通知
|
| | | if (firstHongbao.getMoney() == null || firstHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
|
| | | continue;
|
| | |
|
| | | hongBaoV2Mapper.insertSelective(firstHongbao);
|
| | |
|
| | | // 插入二级子红包
|
| | | if (secondUid == null)
|
| | | boss = null;
|
| | | else
|
| | | boss = userInfoService.selectByPKey(secondUid);
|
| | |
|
| | | if (boss != null) {// 二级BOSS存在
|
| | | BigDecimal secondRate = hongBaoManageService
|
| | | .getSecondInviteRate(boss.getRank() == null ? 0 : boss.getRank());
|
| | | if (secondRate.compareTo(new BigDecimal(0)) <= 0)
|
| | | return;
|
| | | HongBaoV2 secondHongbao = new HongBaoV2();
|
| | | secondHongbao.setBeizhu("2019年7月批量修改");
|
| | | secondHongbao.setUserInfo(boss);
|
| | | secondHongbao.setUrank(boss.getRank());
|
| | | secondHongbao.setParent(hongBao);
|
| | | secondHongbao.setCreateTime(new Date());
|
| | | secondHongbao.setType(HongBaoV2.TYPE_ERJI);
|
| | | secondHongbao.setVersion(2);
|
| | | secondHongbao.setState(hongBao.getState());
|
| | | if (hongBao.getState() == HongBaoV2.STATE_KELINGQU
|
| | | || hongBao.getState() == HongBaoV2.STATE_YILINGQU) {
|
| | | secondHongbao.setMoney(MoneyBigDecimalUtil.mul(hongBao.getMoney(),
|
| | | secondRate.divide(new BigDecimal(100))));
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTime(commonOrder.getSettleTime());
|
| | | calendar.add(Calendar.MONTH, 1);
|
| | | secondHongbao.setPreGetTime(new Date(TimeUtil.convertToTimeTemp(
|
| | | calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25",
|
| | | "yyyy-M-dd")));
|
| | | if (secondHongbao.getPreGetTime().getTime() < System.currentTimeMillis()) {
|
| | | secondHongbao.setGetTime(secondHongbao.getPreGetTime());
|
| | | secondHongbao.setState(HongBaoV2.STATE_YILINGQU);
|
| | | }
|
| | |
|
| | | } else if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU) {
|
| | | secondHongbao.setMoney(MoneyBigDecimalUtil.mul(hongBao.getMoney(),
|
| | | secondRate.divide(new BigDecimal(100))));
|
| | | }
|
| | |
|
| | | // 返利为0的不统计
|
| | | if (secondHongbao.getMoney() == null
|
| | | || secondHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
|
| | | continue;
|
| | | hongBaoV2Mapper.insertSelective(secondHongbao);
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // 统计修改后的资金
|
| | | List<CommonOrder> newCommonOrderList = commonOrderMapper.listBySourceTypeAndOrderNo(Constant.SOURCE_TYPE_TAOBAO,
|
| | | orderId);
|
| | | Map<Long, BigDecimal> newMap = new HashMap<>();
|
| | | if (newCommonOrderList != null)
|
| | | for (CommonOrder co : newCommonOrderList) {
|
| | | HongBaoOrder newHongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(co.getId());
|
| | | if (newHongBaoOrder == null)
|
| | | continue;
|
| | | HongBaoV2 hongBao = newHongBaoOrder.getHongBaoV2();
|
| | | List<HongBaoV2> children = hongBaoV2Service.listChildrenById(hongBao.getId());
|
| | | if (children != null)
|
| | | for (HongBaoV2 child : children) {
|
| | | if (newMap.get(child.getUserInfo().getId()) == null)
|
| | | newMap.put(child.getUserInfo().getId(), new BigDecimal(0));
|
| | | if (child.getState() == HongBaoV2.STATE_YILINGQU)
|
| | | newMap.put(child.getUserInfo().getId(),
|
| | | newMap.get(child.getUserInfo().getId()).add(child.getMoney()));
|
| | | }
|
| | | }
|
| | |
|
| | | for (Iterator<Long> its = newMap.keySet().iterator(); its.hasNext();) {
|
| | | Long uid = its.next();
|
| | | BigDecimal beforeGetMoney = oldMoneyMap.get(uid);
|
| | | BigDecimal afterGetMoney = newMap.get(uid);
|
| | | OrderRepairHistory history = new OrderRepairHistory();
|
| | | history.setAfterGetMoney(afterGetMoney);
|
| | | history.setBeforeGetMoney(beforeGetMoney);
|
| | | history.setOrderId(orderId);
|
| | | history.setUid(uid);
|
| | | orderRepairHistoryService.addOrderRepairHistory(history);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | class OrderInfo {
|
| | | private String orderId;
|
| | | private Long firstUid;
|
| | | private BigDecimal firstUidMoney;
|
| | | private Long secondUid;
|
| | | private BigDecimal secondUidMoney;
|
| | |
|
| | | public String getOrderId() {
|
| | | return orderId;
|
| | | }
|
| | |
|
| | | public void setOrderId(String orderId) {
|
| | | this.orderId = orderId;
|
| | | }
|
| | |
|
| | | public Long getFirstUid() {
|
| | | return firstUid;
|
| | | }
|
| | |
|
| | | public void setFirstUid(Long firstUid) {
|
| | | this.firstUid = firstUid;
|
| | | }
|
| | |
|
| | | public BigDecimal getFirstUidMoney() {
|
| | | return firstUidMoney;
|
| | | }
|
| | |
|
| | | public void setFirstUidMoney(BigDecimal firstUidMoney) {
|
| | | this.firstUidMoney = firstUidMoney;
|
| | | }
|
| | |
|
| | | public Long getSecondUid() {
|
| | | return secondUid;
|
| | | }
|
| | |
|
| | | public void setSecondUid(Long secondUid) {
|
| | | this.secondUid = secondUid;
|
| | | }
|
| | |
|
| | | public BigDecimal getSecondUidMoney() {
|
| | | return secondUidMoney;
|
| | | }
|
| | |
|
| | | public void setSecondUidMoney(BigDecimal secondUidMoney) {
|
| | | this.secondUidMoney = secondUidMoney;
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<OrderRepairHistory> listByUid(Long uid) {
|
| | |
|
| | | return orderRepairHistoryMapper.listByUid(uid);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void doMoney(Long uid) {
|
| | | List<OrderRepairHistory> historyList = listByUid(uid);
|
| | | BigDecimal money = new BigDecimal(0);
|
| | | for (OrderRepairHistory history : historyList) {
|
| | | money.add(history.getAfterGetMoney().subtract(history.getBeforeGetMoney()));
|
| | | }
|
| | | if (money.compareTo(new BigDecimal(0)) > 0)// 资金需要增加
|
| | | {
|
| | | try {
|
| | | UserMoneyDetail detail = UserMoneyDetailFactory.createSystemEqualize(null, money, new UserInfo(uid));
|
| | | // 系统补齐
|
| | | userMoneyService.addUserMoney(uid, money, detail);
|
| | | } catch (UserMoneyDetailException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | } else {// 资金需要减少
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|