| | |
| | | import com.yeshi.fanli.entity.order.InviteOrderSubsidy;
|
| | | 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.InviteOrderSubsidyService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderHongBaoMapService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
|
| | | 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.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | |
|
| | | @Service
|
| | | public class InviteOrderSubsidyServiceImplV2 implements InviteOrderSubsidyServiceV2 {
|
| | |
|
| | | public class InviteOrderSubsidyServiceImplV2 implements InviteOrderSubsidyService {
|
| | | @Resource
|
| | | private InviteOrderSubsidyMapper inviteOrderSubsidyMapper;
|
| | |
|
| | |
| | | return inviteOrderSubsidyMapper.getByOrderNoAndTypeForUpdate(uid, orderNo, type);
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public List<InviteOrderSubsidy> listByOrderNoAndType(String orderNo, Integer type) {
|
| | | return inviteOrderSubsidyMapper.listByOrderNoAndType(orderNo, type);
|
| | | }
|
| | |
|
| | | private void addOrderSubsidy(InviteOrderSubsidy orderSubsidy)
|
| | | throws InviteOrderSubsidyException, OrderTeamRewardException, CommonOrderException {
|
| | | throws InviteOrderSubsidyException, 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);
|
| | | //TODO 删除添加奖励
|
| | | } else {// 添加
|
| | | if (orderSubsidy.getCreateTime() == null)
|
| | | orderSubsidy.setCreateTime(new Date());
|
| | | inviteOrderSubsidyMapper.insertSelective(orderSubsidy);
|
| | | //TODO 删除添加奖励
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | if (list != null && list.size() > 0) {
|
| | | // 必须是自购订单才返利
|
| | | HongBaoV2 parent = hongBaoV2Service.selectByPrimaryKey(list.get(0).getHongBaoV2().getId());
|
| | | 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);
|
| | | if (parent != null
|
| | | && (parent.getType() == HongBaoV2.TYPE_SHARE_GOODS || parent.getType() == HongBaoV2.TYPE_ZIGOU)) {//
|
| | |
|
| | | List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(sourceType, orderId);
|
| | | if (orderList == null || orderList.size() == 0)
|
| | | throw new InviteOrderSubsidyException(10, "订单为空");
|
| | | CommonOrder firstOrder = orderList.get(0);
|
| | | Date placeOrderTime = firstOrder.getThirdCreateTime();
|
| | |
|
| | | if (placeOrderTime.getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME)
|
| | | return;
|
| | |
|
| | | int urank = firstOrder.getUrank();
|
| | | UserLevelEnum buyerUserLevel = null;
|
| | | for (UserLevelEnum level : UserLevelEnum.values())
|
| | |
| | | }
|
| | |
|
| | | List<HongBaoV2> hbList = hongBaoV2Service.listByIds(idList);
|
| | | int state = InviteOrderSubsidy.STATE_UNKNOWN;
|
| | | // 确定是否使用了奖励券
|
| | | if (orderHongBaoMapService.selectByOrderIdAndSourceType(orderId, sourceType) != null) {
|
| | | state = InviteOrderSubsidy.STATE_INVALID;
|
| | | } else {
|
| | | // 确定是否返利到账5天后
|
| | | if (recieveMoneyMoreThan(hbList, 5)) {
|
| | | state = InviteOrderSubsidy.STATE_VALID;
|
| | | } else {
|
| | | state = InviteOrderSubsidy.STATE_UNKNOWN;
|
| | | }
|
| | | }
|
| | | Integer state = InviteOrderSubsidy.STATE_UNKNOWN;
|
| | |
|
| | | // 产生改订单的返利总金额
|
| | | BigDecimal totalBuyFanLiMoney = new BigDecimal(0);
|
| | |
| | | UserLevelEnum userLevel = userLevelManager.getUserLevel(uid, placeOrderTime);
|
| | |
|
| | | int type = uidHongBaoMap.get(uid);
|
| | | if (type == HongBaoV2.TYPE_YIJI || type == HongBaoV2.TYPE_ERJI) {
|
| | | if (type == HongBaoV2.TYPE_YIJI || type == HongBaoV2.TYPE_ERJI
|
| | | || type == HongBaoV2.TYPE_SHARE_YIJI || type == HongBaoV2.TYPE_SHARE_ERJI) {
|
| | | BigDecimal money = null;
|
| | | if (type == HongBaoV2.TYPE_YIJI)
|
| | | if (type == HongBaoV2.TYPE_YIJI || type == HongBaoV2.TYPE_SHARE_YIJI)
|
| | | money = orderHongBaoMoneyComputeService.computeFirstTeamSubsidy(totalBuyFanLiMoney,
|
| | | placeOrderTime, buyerUserLevel, userLevel);
|
| | | else
|
| | | money = orderHongBaoMoneyComputeService.computeSecondTeamSubsidy(totalBuyFanLiMoney,
|
| | | placeOrderTime, buyerUserLevel, userLevel);
|
| | |
|
| | | if (money == null)
|
| | | continue;
|
| | |
|
| | | InviteOrderSubsidy orderSubsidy = new InviteOrderSubsidy();
|
| | | orderSubsidy.setMoney(money);
|
| | |
| | | orderSubsidy.setOrderNo(orderId);
|
| | | orderSubsidy.setSourceType(sourceType);
|
| | | orderSubsidy.setState(state);
|
| | | if (type == HongBaoV2.TYPE_YIJI)
|
| | | if (type == HongBaoV2.TYPE_YIJI || type == HongBaoV2.TYPE_SHARE_YIJI)
|
| | | orderSubsidy.setLevel(InviteOrderSubsidy.LEVEL_ONE);
|
| | | else
|
| | | orderSubsidy.setLevel(InviteOrderSubsidy.LEVEL_TWO);
|
| | | // 会员才能补贴
|
| | | 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);
|
| | | }
|
| | |
|
| | | try {
|
| | | addOrderSubsidy(orderSubsidy);
|
| | | } catch (CommonOrderException e) {
|
| | | throw new InviteOrderSubsidyException(e.getCode(), e.getMsg());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | boolean isSettle = false;
|
| | | if (orderList != null)
|
| | | for (CommonOrder commonOrder : orderList) {
|
| | | if (commonOrder.getState() == CommonOrder.STATE_JS
|
| | | || commonOrder.getState() == CommonOrder.STATE_WQ) {
|
| | | isSettle = true;
|
| | | break;
|
| | | }
|
| | | }
|
| | | if (isSettle) {
|
| | | validByOrderIdAndSourceType(orderId, sourceType);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | private boolean recieveMoneyMoreThan(List<HongBaoV2> hbList, int day) {
|
| | | // 是否全部是到账状态或失效状态
|
| | | int invalidCount = 0;// 失效个数
|
| | | int recieveCount = 0;// 到账的个数
|
| | | long maxGetTime = 0;
|
| | | for (HongBaoV2 v2 : hbList) {
|
| | | if (v2.getState() == HongBaoV2.STATE_SHIXIAO)
|
| | | invalidCount++;
|
| | | else if (v2.getState() == HongBaoV2.STATE_YILINGQU) {
|
| | | recieveCount++;
|
| | | if (v2.getGetTime() != null && v2.getGetTime().getTime() > maxGetTime)
|
| | | maxGetTime = v2.getGetTime().getTime();
|
| | |
|
| | | }
|
| | | }
|
| | | if (invalidCount + recieveCount == hbList.size() && recieveCount > 0 && maxGetTime > 0) {// 全部已到账
|
| | | // 查询到账时间距离当前时间是否超过指定天
|
| | | if (System.currentTimeMillis() - maxGetTime > 1000 * 60 * 60 * 24L * day)
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | inviteOrderSubsidyMapper.updateByPrimaryKeySelective(orderSubsidy);
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public BigDecimal sumRecievedMoneyByUid(long uid, Integer level) {
|
| | | BigDecimal money = inviteOrderSubsidyMapper.sumRecievedMoneyByUid(uid, level);
|
| | |
| | | }
|
| | | return money;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public BigDecimal sumValidMoneyByUidAndDate(long uid, Integer day, Integer level) {
|
| | | BigDecimal money = inviteOrderSubsidyMapper.sumValidMoneyByUidAndDate(uid, day, level);
|
| | |
| | | }
|
| | | return money;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public BigDecimal sumMoneyByUidAndDateAndState(long uid, Integer day, Integer level, Integer state) {
|
| | | BigDecimal money = inviteOrderSubsidyMapper.sumMoneyByUidAndDateAndState(uid, day, level, state);
|
| | |
| | | }
|
| | | return money;
|
| | | }
|
| | | |
| | | |
| | |
|
| | | }
|