From 190d6bc6aa7e4ca33c281bd9785339f3bddaf11e Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 08 五月 2021 12:43:37 +0800
Subject: [PATCH] bug修复
---
fanli/src/main/java/com/yeshi/fanli/service/impl/order/UserOrderWeiQuanRecordServiceImpl.java | 336 +++++++++++++++++++++++++++++++------------------------
1 files changed, 189 insertions(+), 147 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/UserOrderWeiQuanRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/UserOrderWeiQuanRecordServiceImpl.java
index 9f76f36..8f86056 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/UserOrderWeiQuanRecordServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/UserOrderWeiQuanRecordServiceImpl.java
@@ -1,147 +1,189 @@
-package com.yeshi.fanli.service.impl.order;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.Date;
-import java.util.List;
-
-import javax.annotation.Resource;
-
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import com.yeshi.fanli.dao.mybatis.order.UserOrderWeiQuanRecordMapper;
-import com.yeshi.fanli.dto.HongBaoDTO;
-import com.yeshi.fanli.entity.bus.user.HongBaoV2;
-import com.yeshi.fanli.entity.order.CommonOrder;
-import com.yeshi.fanli.entity.order.HongBaoOrder;
-import com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord;
-import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanDrawBack;
-import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
-import com.yeshi.fanli.service.inter.money.tb.TaoBaoWeiQuanDrawBackService;
-import com.yeshi.fanli.service.inter.order.CommonOrderService;
-import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
-import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
-import com.yeshi.fanli.service.inter.order.UserOrderWeiQuanRecordService;
-import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService;
-import com.yeshi.fanli.util.Constant;
-
-@Service
-public class UserOrderWeiQuanRecordServiceImpl implements UserOrderWeiQuanRecordService {
-
- @Resource
- private UserOrderWeiQuanRecordMapper userOrderWeiQuanRecordMapper;
-
- @Resource
- private TaoBaoWeiQuanOrderService taoBaoWeiQuanOrderService;
-
- @Resource
- private TaoBaoWeiQuanDrawBackService taoBaoWeiQuanDrawBackService;
-
- @Resource
- private HongBaoV2Service hongBaoV2Service;
-
- @Resource
- private CommonOrderService commonOrderService;
-
- @Resource
- private HongBaoOrderService hongBaoOrderService;
-
- @Override
- public void syncPrevious() {
- BigDecimal zero = new BigDecimal(0);
- for (int page = 1; page < Integer.MAX_VALUE; page++) {
- List<TaoBaoWeiQuanOrder> list = taoBaoWeiQuanOrderService.listByBeginWeiQuan(page, 100);
- if (list == null || list.isEmpty())
- break;
-
- for (TaoBaoWeiQuanOrder weiQuanOrder : list) {
- String orderItemId = weiQuanOrder.getOrderItemId();
-
- List<HongBaoDTO> listV2 = hongBaoV2Service.listByOrderTradeId(orderItemId);
- for (HongBaoDTO hongBaoV2 : listV2) {
- Long uid = hongBaoV2.getUserInfo().getId();
- TaoBaoWeiQuanDrawBack drawBack = taoBaoWeiQuanDrawBackService.selectByOrderItemIdAndUid(orderItemId,
- uid);
-
- int state = 0;
- BigDecimal money = null;
- if (drawBack != null) {
- state = 1; // 宸叉墸娆�
- BigDecimal drawBackMoney = drawBack.getDrawBackMoney();
- if (drawBackMoney.compareTo(zero) > 0) {
- money = drawBackMoney;
- }
- }
-
- if (money == null) {
- // (缁存潈閲戦/缁撶畻閲戦) * 杩斿埄閲戦
- BigDecimal wqmoney = weiQuanOrder.getMoney();
- money = wqmoney.multiply(hongBaoV2.getMoney()).divide(hongBaoV2.getSettlement(), 2,
- BigDecimal.ROUND_UP);
-
- // 澶т簬杩斿埄閲戦 鍒欑瓑浜庤繑鍒╅噾棰�
- if (money.compareTo(hongBaoV2.getMoney()) > 0)
- money = hongBaoV2.getMoney();
- }
-
- UserOrderWeiQuanRecord weiQuanRecord = new UserOrderWeiQuanRecord();
- weiQuanRecord.setUid(uid);
- weiQuanRecord.setSourceType(1); // 娣樺疂
- weiQuanRecord.setTradeId(orderItemId);
- weiQuanRecord.setCreateTime(weiQuanOrder.getCreateTime());
- weiQuanRecord.setMoney(money);
- weiQuanRecord.setState(state);
- userOrderWeiQuanRecordMapper.insertSelective(weiQuanRecord);
- }
- }
- }
- }
-
- @Transactional(rollbackFor = Exception.class)
- @Override
- public void addTaoBaoWeiQuan(TaoBaoWeiQuanOrder order) {
- if (!order.getState().contains("缁存潈鎴愬姛"))
- return;
- // 鏌ヨ鏄惁瀛樺湪绾㈠寘
- CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
- order.getOrderItemId());
- if (commonOrder == null)
- return;
- HongBaoOrder hongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(commonOrder.getId());
- if (hongBaoOrder == null || hongBaoOrder.getHongBaoV2() == null)
- return;
-
- BigDecimal settleMoney = hongBaoOrder.getCommonOrder().getSettlement();
- HongBaoV2 mainHongBao = hongBaoOrder.getHongBaoV2();
- UserOrderWeiQuanRecord ur = userOrderWeiQuanRecordMapper.selectByOrderInfoAndUid(
- mainHongBao.getUserInfo().getId(), order.getOrderItemId(), Constant.SOURCE_TYPE_TAOBAO);
- if (ur == null) {
- UserOrderWeiQuanRecord record = new UserOrderWeiQuanRecord();
- record.setCreateTime(new Date());
- record.setMoney(hongBaoOrder.getHongBaoV2().getMoney().multiply(order.getMoney()).divide(settleMoney, 2,
- RoundingMode.UP));
- record.setSourceType(Constant.SOURCE_TYPE_TAOBAO);
- record.setState(0);
- record.setTradeId(order.getOrderItemId());
- record.setUid(hongBaoOrder.getHongBaoV2().getUserInfo().getId());
- userOrderWeiQuanRecordMapper.insertSelective(record);
- }
- List<HongBaoV2> children = hongBaoV2Service.listChildrenById(mainHongBao.getId());
- for (HongBaoV2 v2 : children) {
- UserOrderWeiQuanRecord record = userOrderWeiQuanRecordMapper.selectByOrderInfoAndUid(
- v2.getUserInfo().getId(), order.getOrderItemId(), Constant.SOURCE_TYPE_TAOBAO);
- if (record == null) {
- record = new UserOrderWeiQuanRecord();
- record.setCreateTime(new Date());
- record.setMoney(v2.getMoney().multiply(order.getMoney()).divide(settleMoney, 2, RoundingMode.UP));
- record.setSourceType(Constant.SOURCE_TYPE_TAOBAO);
- record.setState(0);
- record.setTradeId(order.getOrderItemId());
- record.setUid(v2.getUserInfo().getId());
- userOrderWeiQuanRecordMapper.insertSelective(record);
- }
- }
- }
-
-}
+package com.yeshi.fanli.service.impl.order;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Date;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.yeshi.fanli.dao.mybatis.order.UserOrderWeiQuanRecordMapper;
+import com.yeshi.fanli.dto.HongBaoDTO;
+import com.yeshi.fanli.entity.bus.user.HongBaoV2;
+import com.yeshi.fanli.entity.order.CommonOrder;
+import com.yeshi.fanli.entity.order.HongBaoOrder;
+import com.yeshi.fanli.entity.order.UserOrderWeiQuanRecord;
+import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanDrawBack;
+import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
+import com.yeshi.fanli.service.inter.money.tb.TaoBaoWeiQuanDrawBackService;
+import com.yeshi.fanli.service.inter.order.CommonOrderService;
+import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
+import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
+import com.yeshi.fanli.service.inter.order.UserOrderWeiQuanRecordService;
+import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService;
+import com.yeshi.fanli.util.Constant;
+
+@Service
+public class UserOrderWeiQuanRecordServiceImpl implements UserOrderWeiQuanRecordService {
+
+ @Resource
+ private UserOrderWeiQuanRecordMapper userOrderWeiQuanRecordMapper;
+
+ @Resource
+ private TaoBaoWeiQuanOrderService taoBaoWeiQuanOrderService;
+
+ @Resource
+ private TaoBaoWeiQuanDrawBackService taoBaoWeiQuanDrawBackService;
+
+ @Resource
+ private HongBaoV2Service hongBaoV2Service;
+
+ @Resource
+ private CommonOrderService commonOrderService;
+
+ @Resource
+ private HongBaoOrderService hongBaoOrderService;
+
+ @Override
+ public void syncPrevious() {
+ BigDecimal zero = new BigDecimal(0);
+ for (int page = 1; page < Integer.MAX_VALUE; page++) {
+ List<TaoBaoWeiQuanOrder> list = taoBaoWeiQuanOrderService.listByBeginWeiQuan(page, 100);
+ if (list == null || list.isEmpty())
+ break;
+
+ for (TaoBaoWeiQuanOrder weiQuanOrder : list) {
+ String orderItemId = weiQuanOrder.getOrderItemId();
+
+ List<HongBaoDTO> listV2 = hongBaoV2Service.listByOrderTradeId(orderItemId);
+ for (HongBaoDTO hongBaoV2 : listV2) {
+ Long uid = hongBaoV2.getUserInfo().getId();
+ TaoBaoWeiQuanDrawBack drawBack = taoBaoWeiQuanDrawBackService.selectByOrderItemIdAndUid(orderItemId,
+ uid);
+
+ int state = 0;
+ BigDecimal money = null;
+ if (drawBack != null) {
+ state = 1; // 宸叉墸娆�
+ BigDecimal drawBackMoney = drawBack.getDrawBackMoney();
+ if (drawBackMoney.compareTo(zero) > 0) {
+ money = drawBackMoney;
+ }
+ }
+
+ if (money == null) {
+ // (缁存潈閲戦/缁撶畻閲戦) * 杩斿埄閲戦
+ BigDecimal wqmoney = weiQuanOrder.getMoney();
+ money = wqmoney.multiply(hongBaoV2.getMoney()).divide(hongBaoV2.getSettlement(), 2,
+ BigDecimal.ROUND_UP);
+
+ // 澶т簬杩斿埄閲戦 鍒欑瓑浜庤繑鍒╅噾棰�
+ if (money.compareTo(hongBaoV2.getMoney()) > 0)
+ money = hongBaoV2.getMoney();
+ }
+
+ UserOrderWeiQuanRecord weiQuanRecord = new UserOrderWeiQuanRecord();
+ weiQuanRecord.setUid(uid);
+ weiQuanRecord.setSourceType(1); // 娣樺疂
+ weiQuanRecord.setTradeId(orderItemId);
+ weiQuanRecord.setCreateTime(weiQuanOrder.getCreateTime());
+ weiQuanRecord.setMoney(money);
+ weiQuanRecord.setState(state);
+ userOrderWeiQuanRecordMapper.insertSelective(weiQuanRecord);
+ }
+ }
+ }
+ }
+
+ @Transactional(rollbackFor = Exception.class)
+ @Override
+ public void addTaoBaoWeiQuan(TaoBaoWeiQuanOrder order) {
+ if (!order.getState().contains("缁存潈鎴愬姛"))
+ return;
+ // 鏌ヨ鏄惁瀛樺湪绾㈠寘
+ CommonOrder commonOrder = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
+ order.getOrderItemId());
+ if (commonOrder == null)
+ return;
+ HongBaoOrder hongBaoOrder = hongBaoOrderService.selectDetailByCommonOrderId(commonOrder.getId());
+ if (hongBaoOrder == null || hongBaoOrder.getHongBaoV2() == null)
+ return;
+
+ BigDecimal settleMoney = hongBaoOrder.getCommonOrder().getSettlement();
+ HongBaoV2 mainHongBao = hongBaoOrder.getHongBaoV2();
+ UserOrderWeiQuanRecord ur = userOrderWeiQuanRecordMapper.selectByOrderInfoAndUid(
+ mainHongBao.getUserInfo().getId(), order.getOrderItemId(), Constant.SOURCE_TYPE_TAOBAO);
+ if (ur == null) {
+ UserOrderWeiQuanRecord record = new UserOrderWeiQuanRecord();
+ record.setCreateTime(new Date());
+ record.setMoney(hongBaoOrder.getHongBaoV2().getMoney().multiply(order.getMoney()).divide(settleMoney, 2,
+ RoundingMode.UP));
+ record.setSourceType(Constant.SOURCE_TYPE_TAOBAO);
+ record.setState(UserOrderWeiQuanRecord.STATE_NOT_RETURN);
+ record.setTradeId(order.getOrderItemId());
+ record.setUid(hongBaoOrder.getHongBaoV2().getUserInfo().getId());
+
+ if (record.getMoney().compareTo(hongBaoOrder.getHongBaoV2().getMoney()) > 0)
+ record.setMoney(hongBaoOrder.getHongBaoV2().getMoney());
+
+ userOrderWeiQuanRecordMapper.insertSelective(record);
+ }
+ List<HongBaoV2> children = hongBaoV2Service.listChildrenById(mainHongBao.getId());
+ for (HongBaoV2 v2 : children) {
+ UserOrderWeiQuanRecord record = userOrderWeiQuanRecordMapper.selectByOrderInfoAndUid(
+ v2.getUserInfo().getId(), order.getOrderItemId(), Constant.SOURCE_TYPE_TAOBAO);
+ if (record == null) {
+ record = new UserOrderWeiQuanRecord();
+ record.setCreateTime(new Date());
+ record.setMoney(v2.getMoney().multiply(order.getMoney()).divide(settleMoney, 2, RoundingMode.UP));
+ record.setSourceType(Constant.SOURCE_TYPE_TAOBAO);
+ record.setState(UserOrderWeiQuanRecord.STATE_NOT_RETURN);
+ record.setTradeId(order.getOrderItemId());
+ record.setUid(v2.getUserInfo().getId());
+
+ if (record.getMoney().compareTo(v2.getMoney()) > 0)
+ record.setMoney(v2.getMoney());
+
+ userOrderWeiQuanRecordMapper.insertSelective(record);
+ }
+ }
+ }
+
+ @Override
+ public UserOrderWeiQuanRecord selectByOrderInfoAndUid(Long uid, String tradeId, int sourceType) {
+ UserOrderWeiQuanRecord record = userOrderWeiQuanRecordMapper.selectByOrderInfoAndUid(uid, tradeId, sourceType);
+
+ return record;
+ }
+
+
+ @Override
+ public Integer countWeiQaunOrderNumberByDate(String preDay) {
+ return userOrderWeiQuanRecordMapper.countWeiQaunOrderNumberByDate(preDay);
+ }
+
+
+ @Override
+ public BigDecimal countWeiQaunOrderMoneyByDate(String preDay) {
+ return userOrderWeiQuanRecordMapper.countWeiQaunOrderMoneyByDate(preDay);
+ }
+
+ @Transactional
+ @Override
+ public void weiQuanMoneyReturn(Long uid, String tradeId, int sourceType) {
+ UserOrderWeiQuanRecord record = selectByOrderInfoAndUid(uid, tradeId, sourceType);
+ if (record == null) {
+ return;
+ }
+ if (record.getState() == UserOrderWeiQuanRecord.STATE_RETURNED)
+ return;
+ UserOrderWeiQuanRecord update = new UserOrderWeiQuanRecord();
+ update.setId(record.getId());
+ update.setState(UserOrderWeiQuanRecord.STATE_RETURNED);
+ update.setUpdateTime(new Date());
+ userOrderWeiQuanRecordMapper.updateByPrimaryKeySelective(update);
+ }
+}
--
Gitblit v1.8.0