| | |
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.HashSet;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.concurrent.ConcurrentHashMap;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.order.InviteOrderSubsidyMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
|
| | | import com.yeshi.fanli.entity.order.CommonOrder;
|
| | | import com.yeshi.fanli.entity.order.HongBaoOrder;
|
| | | import com.yeshi.fanli.entity.order.InviteOrderSubsidy;
|
| | | import com.yeshi.fanli.entity.order.OrderTeamReward;
|
| | | import com.yeshi.fanli.exception.order.CommonOrderException;
|
| | | import com.yeshi.fanli.exception.order.InviteOrderSubsidyException;
|
| | | import com.yeshi.fanli.exception.order.OrderTeamRewardException;
|
| | | 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.InviteOrderSubsidyServiceV2;
|
| | | import com.yeshi.fanli.service.inter.order.OrderHongBaoMapService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderTeamRewardService;
|
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
|
| | | import com.yeshi.fanli.service.manger.user.UserLevelManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | |
|
| | | @Service
|
| | | public class InviteOrderSubsidyServiceImplV2 implements InviteOrderSubsidyServiceV2 {
|
| | |
| | | @Resource
|
| | | private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
|
| | |
|
| | | @Resource
|
| | | private OrderTeamRewardService orderTeamRewardService;
|
| | |
|
| | | @Resource
|
| | | private ThreeSaleSerivce threeSaleSerivce;
|
| | |
|
| | | @Override
|
| | | public InviteOrderSubsidy getByOrderNoAndType(Long uid, String orderNo, Integer type) {
|
| | | return inviteOrderSubsidyMapper.getByOrderNoAndType(uid, orderNo, type);
|
| | |
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | private void addOrderSubsidy(InviteOrderSubsidy orderSubsidy) throws InviteOrderSubsidyException {
|
| | | private void addOrderSubsidy(InviteOrderSubsidy orderSubsidy)
|
| | | throws InviteOrderSubsidyException, OrderTeamRewardException, CommonOrderException {
|
| | | if (orderSubsidy.getMoney() == null || StringUtil.isNullOrEmpty(orderSubsidy.getOrderNo())
|
| | | || orderSubsidy.getSourceType() == null || orderSubsidy.getUid() == null)
|
| | | throw new InviteOrderSubsidyException(1, "数据不完整");
|
| | |
| | | update.setState(orderSubsidy.getState());
|
| | | update.setUpdateTime(new Date());
|
| | | inviteOrderSubsidyMapper.updateByPrimaryKeySelective(update);
|
| | | // 添加奖励
|
| | | addTeamReward(old.getId());
|
| | | } else {// 添加
|
| | | if (orderSubsidy.getCreateTime() == null)
|
| | | orderSubsidy.setCreateTime(new Date());
|
| | | inviteOrderSubsidyMapper.insertSelective(orderSubsidy);
|
| | | // 添加奖励
|
| | | addTeamReward(orderSubsidy.getId());
|
| | | }
|
| | | }
|
| | |
|
| | | // 添加团队奖励
|
| | | private void addTeamReward(Long subsidyId) throws OrderTeamRewardException, CommonOrderException {
|
| | | // 查询团队奖励的人
|
| | | // 计算相应的比例
|
| | | InviteOrderSubsidy subsidy = inviteOrderSubsidyMapper.selectByPrimaryKeyForUpdate(subsidyId);
|
| | | if (subsidy == null)
|
| | | throw new OrderTeamRewardException(20, "补贴不存在");
|
| | |
|
| | | // 获取上4级用户
|
| | | List<CommonOrder> commonOrderList = commonOrderService.listBySourceTypeAndOrderId(subsidy.getSourceType(),
|
| | | subsidy.getOrderNo());
|
| | | if (commonOrderList == null || commonOrderList.size() == 0) {
|
| | | throw new CommonOrderException(1, "订单不存在");
|
| | | }
|
| | |
|
| | | Date orderTime = commonOrderList.get(0).getThirdCreateTime();
|
| | |
|
| | | Long sourceUid = commonOrderList.get(0).getUserInfo().getId();
|
| | |
|
| | | List<ThreeSale> bossList = threeSaleSerivce.getMyBossDeepList(sourceUid, 4);
|
| | | // 无需要团队奖励的上级
|
| | | if (bossList.size() < 3)
|
| | | return;
|
| | |
|
| | | Set<Long> rewardUid = new HashSet<>();
|
| | | for (int i = 2; i < bossList.size(); i++) {
|
| | | rewardUid.add(bossList.get(i).getBoss().getId());
|
| | | }
|
| | |
|
| | | // 删除补贴用户的下级用户
|
| | | for (int i = 0; i < bossList.size(); i++) {
|
| | | if (bossList.get(i).getBoss().getId().longValue() == subsidy.getUid()) {
|
| | | break;
|
| | | } else {
|
| | | bossList.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | |
|
| | | for (int i = 1; i < bossList.size(); i++) {
|
| | | if (rewardUid.contains(bossList.get(i).getBoss().getId())) {
|
| | | UserInfo boss = bossList.get(i).getBoss();
|
| | | if (i == 1) {
|
| | | if (bossList.get(i).getSucceedTime() < subsidy.getCreateTime().getTime()) {
|
| | | UserLevelEnum userLevel = userLevelManager.getUserLevel(boss.getId(), orderTime);
|
| | | BigDecimal rewardMoney = orderHongBaoMoneyComputeService
|
| | | .computeFirstTeamReward(subsidy.getMoney(), subsidy.getCreateTime(), userLevel);
|
| | |
|
| | | if (rewardMoney != null) {
|
| | | // 添加奖励
|
| | | orderTeamRewardService.addOrUpdate(subsidy, rewardMoney, boss.getId(),
|
| | | OrderTeamReward.LEVEL_ONE);
|
| | | }
|
| | | }
|
| | | } else if (i == 2) {
|
| | | if (bossList.get(i).getSucceedTime() < subsidy.getCreateTime().getTime()) {
|
| | | UserLevelEnum userLevel = userLevelManager.getUserLevel(boss.getId(), orderTime);
|
| | | BigDecimal rewardMoney = orderHongBaoMoneyComputeService
|
| | | .computeSecondTeamReward(subsidy.getMoney(), subsidy.getCreateTime(), userLevel);
|
| | |
|
| | | if (rewardMoney != null) {
|
| | | // 添加奖励
|
| | | orderTeamRewardService.addOrUpdate(subsidy, rewardMoney, boss.getId(),
|
| | | OrderTeamReward.LEVEL_TWO);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | if (list != null && list.size() > 0) {
|
| | | // 必须是自购订单才返利
|
| | | HongBaoV2 parent = hongBaoV2Service.selectByPrimaryKey(list.get(0).getHongBaoV2().getId());
|
| | | if (parent != null && parent.getUrank() != UserLevelEnum.superVIP.getOrderRank()) {// 不是超级会员的自购/分享才补贴
|
| | | if (parent != null && parent.getUrank() != UserLevelEnum.superVIP.getOrderRank()
|
| | | && (parent.getType() == HongBaoV2.TYPE_SHARE_GOODS || parent.getType() == HongBaoV2.TYPE_ZIGOU)) {// 不是超级会员的自购/分享才补贴
|
| | | boolean isShare = (parent.getType() == HongBaoV2.TYPE_SHARE_GOODS);
|
| | |
|
| | | List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(sourceType, orderId);
|
| | | if (orderList == null || orderList.size() == 0)
|
| | |
| | | // 计算奖励金
|
| | | for (Iterator<Long> its = uidHongBaoMap.keySet().iterator(); its.hasNext();) {
|
| | | Long uid = its.next();
|
| | | UserLevelEnum userLevel = userLevelManager.getUserLevel(uid);
|
| | | UserLevelEnum userLevel = userLevelManager.getUserLevel(uid, placeOrderTime);
|
| | |
|
| | | int type = uidHongBaoMap.get(uid);
|
| | | if (type == HongBaoV2.TYPE_YIJI || type == HongBaoV2.TYPE_ERJI) {
|
| | |
| | | orderSubsidy.setOrderNo(orderId);
|
| | | orderSubsidy.setSourceType(sourceType);
|
| | | orderSubsidy.setState(state);
|
| | | if (type == HongBaoV2.TYPE_YIJI)
|
| | | orderSubsidy.setLevel(InviteOrderSubsidy.LEVEL_ONE);
|
| | | else
|
| | | orderSubsidy.setLevel(InviteOrderSubsidy.LEVEL_TWO);
|
| | | // 会员才能补贴
|
| | | if (userLevel != UserLevelEnum.daRen)
|
| | | if (userLevel != UserLevelEnum.daRen) {
|
| | | try {
|
| | | addOrderSubsidy(orderSubsidy);
|
| | | } catch (OrderTeamRewardException e) {
|
| | | throw new InviteOrderSubsidyException(e.getCode(), e.getMsg());
|
| | | } catch (CommonOrderException e) {
|
| | | throw new InviteOrderSubsidyException(e.getCode(), e.getMsg());
|
| | | }
|
| | | // 分享赚不能使用返利奖励券,不用等待5天
|
| | | if (isShare) {
|
| | | validByOrderIdAndSourceType(orderId, sourceType);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | return inviteOrderSubsidyMapper.countByOrderNoAndType(orderId, sourceType);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void invalidByOrderIdAndSourceType(String orderId, int sourceType) {
|
| | | List<InviteOrderSubsidy> list = inviteOrderSubsidyMapper.listByOrderNoAndType(orderId, sourceType);
|
| | |
| | | update.setState(InviteOrderSubsidy.STATE_INVALID);
|
| | | update.setUpdateTime(new Date());
|
| | | inviteOrderSubsidyMapper.updateByPrimaryKeySelective(update);
|
| | | orderTeamRewardService.invalidByOrderIdAndSourceType(subsidy.getId());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void validByOrderIdAndSourceType(String orderId, int sourceType) {
|
| | | public void validByOrderIdAndSourceType(String orderId, int sourceType) throws InviteOrderSubsidyException {
|
| | | // 查询预计到账时间
|
| | | List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(sourceType, orderId);
|
| | | if (orderList == null || orderList.size() == 0)
|
| | | throw new InviteOrderSubsidyException(31, "订单不存在");
|
| | |
|
| | | if (orderList.get(0).getSettleTime() == null)
|
| | | throw new InviteOrderSubsidyException(32, "订单尚未确认收货");
|
| | |
|
| | | // 确认收货时间的下月25号到账
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTime(orderList.get(0).getSettleTime());
|
| | | calendar.add(Calendar.MONTH, 1);
|
| | | Date preGetTime = new Date(TimeUtil.convertToTimeTemp(
|
| | | calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd"));
|
| | |
|
| | | List<InviteOrderSubsidy> list = inviteOrderSubsidyMapper.listByOrderNoAndType(orderId, sourceType);
|
| | | if (list != null && list.size() > 0)
|
| | | for (InviteOrderSubsidy subsidy : list) {
|
| | |
| | | InviteOrderSubsidy update = new InviteOrderSubsidy(subsidy.getId());
|
| | | update.setState(InviteOrderSubsidy.STATE_VALID);
|
| | | update.setUpdateTime(new Date());
|
| | | update.setPreGetTime(preGetTime);
|
| | | inviteOrderSubsidyMapper.updateByPrimaryKeySelective(update);
|
| | | orderTeamRewardService.validByOrderIdAndSourceType(subsidy.getId(), preGetTime);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|