| | |
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper;
|
| | | import com.yeshi.fanli.dao.mybatis.money.ExtractCheckCompensateMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.order.CommonOrderTradeIdMapMapper;
|
| | |
| | | import com.yeshi.fanli.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.ExtractCheckCompensate;
|
| | | 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.HongBaoOrder;
|
| | | import com.yeshi.fanli.entity.order.OrderRepairHistory;
|
| | | import com.yeshi.fanli.entity.order.ShareGoodsActivityOrder;
|
| | | import com.yeshi.fanli.entity.push.PushInfo;
|
| | | import com.yeshi.fanli.entity.push.PushInfo.PushTypeEnum;
|
| | | 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.PushException;
|
| | | import com.yeshi.fanli.exception.money.UserMoneyDetailException;
|
| | | import com.yeshi.fanli.exception.push.PushInfoException;
|
| | | 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.msg.UserMoneyMsgNotificationService;
|
| | | 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.push.PushInfoService;
|
| | | 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.util.taobao.TaoBaoOrderUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Service
|
| | | public class OrderRepairServiceImpl implements OrderRepairService {
|
| | |
| | |
|
| | | @Resource
|
| | | private UserMoneyService userMoneyService;
|
| | |
|
| | | @Resource
|
| | | private PushInfoService pushInfoService;
|
| | |
|
| | | @Resource
|
| | | private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
|
| | |
|
| | | @Resource
|
| | | private ExtractCheckCompensateMapper extractCheckCompensateMapper;
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | |
| | |
|
| | | @Transactional(propagation = Propagation.REQUIRED)
|
| | | private void deleteByCommonOrderId(Long commonOrderId) {
|
| | | commonOrderMapper.deleteByPrimaryKey(commonOrderId);
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrderId);
|
| | | if (hongBaoOrder == null || hongBaoOrder.getHongBaoV2() == null)
|
| | | return;
|
| | |
| | | }
|
| | | hongBaoV2Mapper.deleteByPrimaryKey(hongBaoOrder.getHongBaoV2().getId());
|
| | | hongBaoOrderMapper.deleteByPrimaryKey(hongBaoOrder.getId());
|
| | | commonOrderMapper.deleteByPrimaryKey(commonOrderId);
|
| | |
|
| | | }
|
| | |
|
| | | @Transactional
|
| | |
| | | return orderInfoMap.get(orderId);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void repireFirstAndSecondLevel(String orderId) throws Exception {
|
| | | repireFirstShare(orderId);
|
| | | if (1 > 0)
|
| | | return;
|
| | | OrderInfo info = getOrderInfo(orderId);
|
| | | Map<Long, BigDecimal> oldMoneyMap = new HashMap<>();
|
| | | if (info.getFirstUid() != null)
|
| | |
| | |
|
| | | for (CommonOrder commonOrder : list) {
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder == null)
|
| | | continue;
|
| | | HongBaoV2 hongBao = hongBaoOrder.getHongBaoV2();
|
| | | Long firstUid = info.getFirstUid();
|
| | | Long secondUid = info.getSecondUid();
|
| | |
| | |
|
| | | }
|
| | |
|
| | | private void repireFirstShare(String orderId) throws Exception {
|
| | | OrderInfo info = getOrderInfo(orderId);
|
| | | Long firstUid = info.getFirstUid();
|
| | | 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) {
|
| | | if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ)
|
| | | continue;
|
| | | // 分享赚
|
| | |
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder == null)
|
| | | continue;
|
| | |
|
| | | HongBaoV2 hongBao = hongBaoOrder.getHongBaoV2();
|
| | | // 4月17日后才有一级分享赚
|
| | | if (commonOrder.getThirdCreateTime().getTime() > TimeUtil.convertToTimeTemp("2019-04-17",
|
| | | "yyyy-MM-dd")) {
|
| | | UserInfo boss = null;
|
| | | if (firstUid != null)
|
| | | boss = userInfoService.selectByPKey(firstUid);
|
| | | if (boss != null) {
|
| | | BigDecimal firstLevelRate = hongBaoManageService.getFirstShareRate(1,
|
| | | commonOrder.getThirdCreateTime().getTime());
|
| | | HongBaoV2 child = new HongBaoV2();
|
| | | child.setBeizhu("2019年7月批量修改");
|
| | | child.setParent(hongBao);
|
| | | child.setType(HongBaoV2.TYPE_SHARE_YIJI);
|
| | | if (commonOrder.getState() == CommonOrder.STATE_FK) {
|
| | | child.setState(HongBaoV2.STATE_BUKELINGQU);
|
| | | child.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(),
|
| | | firstLevelRate.divide(new BigDecimal(100))));
|
| | | } else if (commonOrder.getState() == CommonOrder.STATE_JS) {
|
| | | child.setState(HongBaoV2.STATE_KELINGQU);
|
| | | child.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(),
|
| | | firstLevelRate.divide(new BigDecimal(100))));
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTime(commonOrder.getSettleTime());
|
| | | calendar.add(Calendar.MONTH, 1);
|
| | | child.setPreGetTime(new Date(TimeUtil.convertToTimeTemp(
|
| | | calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25",
|
| | | "yyyy-M-dd")));
|
| | |
|
| | | if (child.getPreGetTime().getTime() < System.currentTimeMillis()) {
|
| | | child.setGetTime(child.getPreGetTime());
|
| | | child.setState(HongBaoV2.STATE_YILINGQU);
|
| | | }
|
| | |
|
| | | }
|
| | | child.setUserInfo(boss);
|
| | | child.setUrank(boss.getRank());
|
| | | child.setVersion(2);
|
| | | child.setCreateTime(new Date());
|
| | | hongBaoV2Mapper.insertSelective(child);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | // 统计修改后的资金
|
| | | 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;
|
| | |
| | | @Override
|
| | | public void doMoney(Long uid) {
|
| | | List<OrderRepairHistory> historyList = listByUid(uid);
|
| | | for (int i = 0; i < historyList.size(); i++) {
|
| | | if (historyList.get(i).getCreateTime().getTime() < TimeUtil.convertToTimeTemp("2019-07-15 17:00:38",
|
| | | "yyyy-MM-dd HH:mm:ss")) {
|
| | | historyList.remove(i);
|
| | | i--;
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | BigDecimal money = new BigDecimal(0);
|
| | | String orders = "";
|
| | | for (OrderRepairHistory history : historyList) {
|
| | | money.add(history.getAfterGetMoney().subtract(history.getBeforeGetMoney()));
|
| | | money = money.add(history.getAfterGetMoney().subtract(history.getBeforeGetMoney()));
|
| | | orders += history.getOrderId() + ",";
|
| | | }
|
| | | if (money.compareTo(new BigDecimal(0)) > 0)// 资金需要增加
|
| | | {
|
| | | try {
|
| | | UserMoneyDetail detail = UserMoneyDetailFactory.createSystemEqualize(null, money, new UserInfo(uid));
|
| | | UserMoneyDetail detail = UserMoneyDetailFactory.createSystemEqualize("订单统计异常修复", money,
|
| | | new UserInfo(uid));
|
| | | // 系统补齐
|
| | | // 加资金
|
| | | userMoneyService.addUserMoney(uid, money, detail);
|
| | | pushMsg(uid, "关于近期订单与资金异常的排查与修复结果通知",
|
| | | "尊敬的用户,经仔细核对您账户中的订单,发现您账户中有未统计或错误统计的订单,我们已经为您补齐资金,对应资金已经存入您的账户余额中,敬请查收注查收。感谢信任,返利券App终将成为您最信任的购物省钱助手。");
|
| | | userMoneyMsgNotificationService.systemEqualize(uid, "订单统计异常修复", money, userInfoService.getBalance(uid));
|
| | | } catch (UserMoneyDetailException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | } else {// 资金需要减少
|
| | | } else {// 资金需要减少,不要扣钱
|
| | | pushMsg(uid, "关于近期订单与资金异常的排查与修复结果通知",
|
| | | "尊敬的用户,经仔细核对您账户中的订单,发现您账户中有错误统计的订单,我们已经为您恢复正常,所涉及订单多统计出来的资金,不会被扣除,即您账户中的资金将保持不变,已提现的资金,也不会收回,敬请知晓。感谢信任,返利券App终将成为您最信任的购物省钱助手。");
|
| | | // userMoneyMsgNotificationService.systemEqualize(uid, "订单统计异常修复",
|
| | | // money, userInfoService.getBalance(uid));
|
| | | // 加入提现审核异常保护中
|
| | | ExtractCheckCompensate check = new ExtractCheckCompensate();
|
| | | check.setBeiZhu("7月订单异常系统处理:" + orders);
|
| | | check.setCreateTime(new Date());
|
| | | check.setMoney(money);
|
| | | check.setUserInfo(new UserInfo(uid));
|
| | | check.setUpdateTime(new Date());
|
| | | extractCheckCompensateMapper.insertSelective(check);
|
| | | }
|
| | | }
|
| | |
|
| | | private void pushMsg(Long uid, String title, String content) {
|
| | |
|
| | | PushInfo pushInfo = new PushInfo();
|
| | | pushInfo.setTitle(title);
|
| | | pushInfo.setContent(content);
|
| | | pushInfo.setUids(uid + "");
|
| | | JSONObject jsonData = new JSONObject();
|
| | | jsonData.put("url", "");
|
| | | jsonData.put("ios", "全推");
|
| | | jsonData.put("android", "全推");
|
| | | pushInfo.setJsonData(jsonData.toString());
|
| | | pushInfo.setType(PushTypeEnum.ZNX);
|
| | | pushInfo.setArrayAndroid("[全推]");
|
| | | pushInfo.setArrayIOS("[全推]");
|
| | |
|
| | | pushInfo.setCreateTime(new Date());
|
| | |
|
| | | try {
|
| | | pushInfoService.save(pushInfo);
|
| | | } catch (PushInfoException e) {
|
| | | e.printStackTrace();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | try {
|
| | | pushInfoService.handPush(pushInfo.getId());
|
| | | } catch (PushInfoException e) {
|
| | | e.printStackTrace();
|
| | | } catch (PushException e) {
|
| | | e.printStackTrace();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|