| | |
| | | package com.yeshi.fanli.service.manger.order;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import com.yeshi.fanli.entity.SystemEnum;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | |
| | |
|
| | | /**
|
| | | * 团队分红来源管理
|
| | | * @author Administrator
|
| | | *
|
| | | * @author Administrator
|
| | | */
|
| | | @Component
|
| | | public class TeamDividentsSourceManager {
|
| | |
|
| | | @Resource
|
| | | private TeamDividentsSourceOrderService teamDividentsSourceOrderService;
|
| | | @Resource
|
| | | private TeamDividentsSourceOrderService teamDividentsSourceOrderService;
|
| | |
|
| | | @Resource
|
| | | private TeamDividentsSourceOrderUserMapService teamDividentsSourceOrderUserMapService;
|
| | | @Resource
|
| | | private TeamDividentsSourceOrderUserMapService teamDividentsSourceOrderUserMapService;
|
| | |
|
| | | @Resource
|
| | | private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
|
| | | @Resource
|
| | | private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
|
| | |
|
| | | @Resource
|
| | | private CommonOrderService commonOrderService;
|
| | | @Resource
|
| | | private CommonOrderService commonOrderService;
|
| | |
|
| | | /**
|
| | | * @throws ParamsException |
| | | * 添加分红源
|
| | | * @Title: addSource
|
| | | * @Description: |
| | | * @param commonOrderList
|
| | | * @param bossList |
| | | * void 返回类型
|
| | | * @throws
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void addSource(List<CommonOrder> commonOrderList, List<UserTeamLevel> bossList)
|
| | | throws TeamDividentsSourceOrderException, ParamsException {
|
| | | if (commonOrderList.get(0).getThirdCreateTime().getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME)
|
| | | return;
|
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | |
|
| | | UserLevelEnum level = UserLevelUtil.getByOrderRank(commonOrderList.get(0).getUrank());
|
| | | if (level == null)
|
| | | level = UserLevelEnum.daRen;
|
| | | TeamDividentsSourceOrder order = TeamDividentsSourceOrderFactory.create(commonOrderList);
|
| | | if (order == null)
|
| | | return;
|
| | | try {
|
| | | order = teamDividentsSourceOrderService.addTeamDividentsSourceOrder(order);
|
| | | } catch (ParamsException e) {
|
| | | throw new TeamDividentsSourceOrderException(101, "参数不完整");
|
| | | }
|
| | | /**
|
| | | * @param commonOrderList
|
| | | * @param bossList void 返回类型
|
| | | * @throws ParamsException 添加分红源
|
| | | * @throws
|
| | | * @Title: addSource
|
| | | * @Description:
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void addSource(List<CommonOrder> commonOrderList, List<UserTeamLevel> bossList)
|
| | | throws TeamDividentsSourceOrderException, ParamsException {
|
| | | if (commonOrderList.get(0).getThirdCreateTime().getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME)
|
| | | return;
|
| | |
|
| | | if (order == null || order.getId() == null) {
|
| | | throw new TeamDividentsSourceOrderException(2, "添加源订单失败");
|
| | | }
|
| | | Date placeOrderTime = commonOrderList.get(0).getThirdCreateTime();
|
| | |
|
| | | // 获取源订单分配的分红用户ID数量
|
| | | long count = teamDividentsSourceOrderUserMapService.countBySourceOrderId(order.getId());
|
| | | if (count > 0)// 已存在
|
| | | return;
|
| | | UserLevelEnum level = UserLevelUtil.getByOrderRank(commonOrderList.get(0).getUrank());
|
| | | if (level == null)
|
| | | level = UserLevelEnum.daRen;
|
| | | TeamDividentsSourceOrder order = TeamDividentsSourceOrderFactory.create(commonOrderList);
|
| | | if (order == null)
|
| | | return;
|
| | | try {
|
| | | order = teamDividentsSourceOrderService.addTeamDividentsSourceOrder(order);
|
| | | } catch (ParamsException e) {
|
| | | throw new TeamDividentsSourceOrderException(101, "参数不完整");
|
| | | }
|
| | |
|
| | | // 计算团队分红比例
|
| | | List<UserTeamRate> rateList = orderHongBaoMoneyComputeService.getTeamDividentsRates(level, bossList);
|
| | | if (rateList != null)
|
| | | for (UserTeamRate rate : rateList) {
|
| | | BigDecimal money = MoneyBigDecimalUtil.div(rate.getRate().multiply(order.getMoney()),
|
| | | new BigDecimal(100), 4);
|
| | | if (order == null || order.getId() == null) {
|
| | | throw new TeamDividentsSourceOrderException(2, "添加源订单失败");
|
| | | }
|
| | |
|
| | | TeamDividentsSourceOrderUserMap map = TeamDividentsSourceOrderUserMapFactory.create(order,
|
| | | rate.getUid(), rate.getRate(), money, TeamDividentsSourceOrderUserMap.TYPE_TEAM_DIVIDENTS);
|
| | | try {
|
| | | teamDividentsSourceOrderUserMapService.addDividentsSourceOrderUserMap(map);
|
| | | } catch (ParamsException e) {
|
| | | throw new TeamDividentsSourceOrderException(201, "参数不完整");
|
| | | }
|
| | | }
|
| | | // 计算二级外分红比例
|
| | | rateList = orderHongBaoMoneyComputeService.getTeamRewardMoreThan2LevelRates(level, bossList);
|
| | | if (rateList != null)
|
| | | for (UserTeamRate rate : rateList) {
|
| | | BigDecimal money = MoneyBigDecimalUtil.div(rate.getRate().multiply(order.getMoney()),
|
| | | new BigDecimal(100), 4);
|
| | | // 获取源订单分配的分红用户ID数量
|
| | | long count = teamDividentsSourceOrderUserMapService.countBySourceOrderId(order.getId());
|
| | | if (count > 0)// 已存在
|
| | | return;
|
| | |
|
| | | TeamDividentsSourceOrderUserMap map = TeamDividentsSourceOrderUserMapFactory.create(order,
|
| | | rate.getUid(), rate.getRate(), money, TeamDividentsSourceOrderUserMap.TYPE_MORE_THAN_2);
|
| | | try {
|
| | | teamDividentsSourceOrderUserMapService.addDividentsSourceOrderUserMap(map);
|
| | | } catch (ParamsException e) {
|
| | | throw new TeamDividentsSourceOrderException(301, "参数不完整");
|
| | | }
|
| | | }
|
| | | }
|
| | | SystemEnum system = userInfoService.getUserSystem(order.getUid());
|
| | |
|
| | | /**
|
| | | * 订单失效
|
| | | * @Title: invalidBySourceOrderId
|
| | | * @Description: |
| | | * @param sourceOrderId |
| | | * void 返回类型
|
| | | * @throws
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void invalidByOrder(String orderNo, int sourceType, String beiZhu) {
|
| | | teamDividentsSourceOrderService.invalidOrder(orderNo, sourceType, beiZhu);
|
| | | TeamDividentsSourceOrder order = teamDividentsSourceOrderService.selectByOrderNoSourceType(orderNo, sourceType);
|
| | | if (order != null) {
|
| | | teamDividentsSourceOrderUserMapService.invalidBySourceOrderId(order.getId());
|
| | | }
|
| | | }
|
| | | // 计算团队分红比例
|
| | | List<UserTeamRate> rateList = orderHongBaoMoneyComputeService.getTeamDividentsRates(level, bossList,
|
| | | placeOrderTime, system);
|
| | | if (rateList != null)
|
| | | for (UserTeamRate rate : rateList) {
|
| | | BigDecimal money = MoneyBigDecimalUtil.div(rate.getRate().multiply(order.getMoney()),
|
| | | new BigDecimal(100), 4);
|
| | |
|
| | | /**
|
| | | * 订单结算
|
| | | * @Title: orderSettle
|
| | | * @Description: |
| | | * @param sourceOrderId
|
| | | * @param income |
| | | * void 返回类型
|
| | | * @throws
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void orderSettle(String orderNo, int sourceType) {
|
| | | TeamDividentsSourceOrder order = teamDividentsSourceOrderService.selectByOrderNoSourceType(orderNo, sourceType);
|
| | | if (order != null) {
|
| | | List<CommonOrder> commonOrderList = commonOrderService.listBySourceTypeAndOrderId(sourceType, orderNo);
|
| | | if (commonOrderList == null)
|
| | | return;
|
| | | TeamDividentsSourceOrderUserMap map = TeamDividentsSourceOrderUserMapFactory.create(order,
|
| | | rate.getUid(), rate.getRate(), money, TeamDividentsSourceOrderUserMap.TYPE_TEAM_DIVIDENTS);
|
| | | try {
|
| | | teamDividentsSourceOrderUserMapService.addDividentsSourceOrderUserMap(map);
|
| | | } catch (ParamsException e) {
|
| | | throw new TeamDividentsSourceOrderException(201, "参数不完整");
|
| | | }
|
| | | }
|
| | | // 计算二级外分红比例
|
| | | rateList = orderHongBaoMoneyComputeService.getTeamRewardMoreThan2LevelRates(level, bossList, placeOrderTime, system);
|
| | | if (rateList != null)
|
| | | for (UserTeamRate rate : rateList) {
|
| | | BigDecimal money = MoneyBigDecimalUtil.div(rate.getRate().multiply(order.getMoney()),
|
| | | new BigDecimal(100), 4);
|
| | |
|
| | | TeamDividentsSourceOrder newOrder = TeamDividentsSourceOrderFactory.create(commonOrderList);
|
| | | TeamDividentsSourceOrderUserMap map = TeamDividentsSourceOrderUserMapFactory.create(order,
|
| | | rate.getUid(), rate.getRate(), money, TeamDividentsSourceOrderUserMap.TYPE_MORE_THAN_2);
|
| | | try {
|
| | | teamDividentsSourceOrderUserMapService.addDividentsSourceOrderUserMap(map);
|
| | | } catch (ParamsException e) {
|
| | | throw new TeamDividentsSourceOrderException(301, "参数不完整");
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (newOrder == null || newOrder.getPreSendTime() == null)
|
| | | return;
|
| | | /**
|
| | | * 订单失效
|
| | | *
|
| | | * @throws
|
| | | * @Title: invalidBySourceOrderId
|
| | | * @Description: void 返回类型
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void invalidByOrder(String orderNo, int sourceType, String beiZhu) {
|
| | | teamDividentsSourceOrderService.invalidOrder(orderNo, sourceType, beiZhu);
|
| | | TeamDividentsSourceOrder order = teamDividentsSourceOrderService.selectByOrderNoSourceType(orderNo, sourceType);
|
| | | if (order != null) {
|
| | | teamDividentsSourceOrderUserMapService.invalidBySourceOrderId(order.getId());
|
| | | }
|
| | | }
|
| | |
|
| | | BigDecimal money = CommonOrderUtil.computeIncome(commonOrderList);
|
| | | teamDividentsSourceOrderService.orderSettle(orderNo, sourceType, newOrder.getPreSendTime(), money);
|
| | | teamDividentsSourceOrderUserMapService.orderSettle(order.getId(), newOrder.getPreSendTime(), money);
|
| | | }
|
| | | }
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void invalidBySourceUid(Long sourceUid, String beiZhu) {
|
| | | // teamDividentsSourceOrderService.invalidOrderByUid(sourceUid, beiZhu);
|
| | | teamDividentsSourceOrderUserMapService.invalidOrderBySourceUid(sourceUid, beiZhu);
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void updateOrderMoney(String orderNo, int sourceType) {
|
| | | TeamDividentsSourceOrder order = teamDividentsSourceOrderService.selectByOrderNoSourceType(orderNo, sourceType);
|
| | | if (order != null) {
|
| | | List<CommonOrder> commonOrderList = commonOrderService.listBySourceTypeAndOrderId(sourceType, orderNo);
|
| | | if (commonOrderList == null)
|
| | | return;
|
| | | /**
|
| | | * 订单结算
|
| | | *
|
| | | * @throws
|
| | | * @Title: orderSettle
|
| | | * @Description: void 返回类型
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void orderSettle(String orderNo, int sourceType) {
|
| | | TeamDividentsSourceOrder order = teamDividentsSourceOrderService.selectByOrderNoSourceType(orderNo, sourceType);
|
| | | if (order != null) {
|
| | | List<CommonOrder> commonOrderList = commonOrderService.listBySourceTypeAndOrderId(sourceType, orderNo);
|
| | | if (commonOrderList == null)
|
| | | return;
|
| | |
|
| | | Integer state = CommonOrderUtil.getState(commonOrderList);
|
| | | BigDecimal money = null;
|
| | | switch (state) {
|
| | | case CommonOrder.STATE_FK:
|
| | | money = CommonOrderUtil.computeEstimate(commonOrderList);
|
| | | teamDividentsSourceOrderService.updateMoney(orderNo, sourceType, money);
|
| | | teamDividentsSourceOrderUserMapService.updateMoney(order.getId(), money);
|
| | | break;
|
| | | case CommonOrder.STATE_WQ:
|
| | | case CommonOrder.STATE_JS:
|
| | | TeamDividentsSourceOrder newOrder = TeamDividentsSourceOrderFactory.create(commonOrderList);
|
| | | TeamDividentsSourceOrder newOrder = TeamDividentsSourceOrderFactory.create(commonOrderList);
|
| | |
|
| | | if (newOrder == null || newOrder.getPreSendTime() == null)
|
| | | return;
|
| | | if (newOrder == null || newOrder.getPreSendTime() == null)
|
| | | return;
|
| | |
|
| | | money = CommonOrderUtil.computeIncome(commonOrderList);
|
| | | teamDividentsSourceOrderService.orderSettle(orderNo, sourceType, newOrder.getPreSendTime(), money);
|
| | | teamDividentsSourceOrderUserMapService.orderSettle(order.getId(), newOrder.getPreSendTime(), money);
|
| | | break;
|
| | | case CommonOrder.STATE_SX:
|
| | | invalidByOrder(orderNo, sourceType, "订单失效");
|
| | | break;
|
| | | }
|
| | | BigDecimal money = CommonOrderUtil.computeIncome(commonOrderList);
|
| | | teamDividentsSourceOrderService.orderSettle(orderNo, sourceType, newOrder.getPreSendTime(), money);
|
| | | teamDividentsSourceOrderUserMapService.orderSettle(order.getId(), newOrder.getPreSendTime(), money);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public void updateOrderMoney(String orderNo, int sourceType) {
|
| | | TeamDividentsSourceOrder order = teamDividentsSourceOrderService.selectByOrderNoSourceType(orderNo, sourceType);
|
| | | if (order != null) {
|
| | | List<CommonOrder> commonOrderList = commonOrderService.listBySourceTypeAndOrderId(sourceType, orderNo);
|
| | | if (commonOrderList == null)
|
| | | return;
|
| | |
|
| | | Integer state = CommonOrderUtil.getState(commonOrderList);
|
| | | BigDecimal money = null;
|
| | | switch (state) {
|
| | | case CommonOrder.STATE_FK:
|
| | | money = CommonOrderUtil.computeEstimate(commonOrderList);
|
| | | teamDividentsSourceOrderService.updateMoney(orderNo, sourceType, money);
|
| | | teamDividentsSourceOrderUserMapService.updateMoney(order.getId(), money);
|
| | | break;
|
| | | case CommonOrder.STATE_WQ:
|
| | | case CommonOrder.STATE_JS:
|
| | | TeamDividentsSourceOrder newOrder = TeamDividentsSourceOrderFactory.create(commonOrderList);
|
| | |
|
| | | if (newOrder == null || newOrder.getPreSendTime() == null)
|
| | | return;
|
| | |
|
| | | money = CommonOrderUtil.computeIncome(commonOrderList);
|
| | | teamDividentsSourceOrderService.orderSettle(orderNo, sourceType, newOrder.getPreSendTime(), money);
|
| | | teamDividentsSourceOrderUserMapService.orderSettle(order.getId(), newOrder.getPreSendTime(), money);
|
| | | break;
|
| | | case CommonOrder.STATE_SX:
|
| | | invalidByOrder(orderNo, sourceType, "订单失效");
|
| | | break;
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | | }
|