| | |
| | | package com.yeshi.fanli.service.impl.order;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.order.UserOrderWeiQuanRecordMapper;
|
| | | import com.yeshi.fanli.dto.HongBaoDTO;
|
| | | 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.HongBaoV2Service;
|
| | | import com.yeshi.fanli.service.inter.order.UserOrderWeiQuanRecordService;
|
| | | import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | |
|
| | | @Service
|
| | | public class UserOrderWeiQuanRecordServiceImpl implements UserOrderWeiQuanRecordService {
|
| | | |
| | | @Resource
|
| | | private UserOrderWeiQuanRecordMapper userOrderWeiQuanRecordMapper;
|
| | | |
| | | @Resource
|
| | | private TaoBaoWeiQuanOrderService taoBaoWeiQuanOrderService;
|
| | | |
| | | @Resource
|
| | | private TaoBaoWeiQuanDrawBackService taoBaoWeiQuanDrawBackService;
|
| | | |
| | | @Resource
|
| | | private HongBaoV2Service hongBaoV2Service;
|
| | | |
| | | @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_DOWN);
|
| | | |
| | | // 大于返利金额 则等于返利金额
|
| | | 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);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | }
|
| | | 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); |
| | | } |
| | | } |