| | |
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
|
| | | import com.yeshi.fanli.dto.HongBao;
|
| | | import com.yeshi.fanli.dto.HongBaoDTO;
|
| | | import com.yeshi.fanli.dto.order.HongBaoAddResult;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale;
|
| | | import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
|
| | | 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.CommonOrderGoods;
|
| | | import com.yeshi.fanli.entity.order.HongBaoOrder;
|
| | | import com.yeshi.fanli.entity.order.ShareGoodsActivityOrder;
|
| | | import com.yeshi.fanli.entity.system.ConfigKeyEnum;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
|
| | | import com.yeshi.fanli.exception.order.HongBaoException;
|
| | | import com.yeshi.fanli.exception.order.ShareGoodsActivityOrderException;
|
| | |
| | | return hongBaoV2Mapper.selectByPrimaryKey(id);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public int addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException, UserAccountException {
|
| | | public HongBaoAddResult addHongBao(List<CommonOrder> commonOrderList, int type)
|
| | | throws HongBaoException, UserAccountException {
|
| | | Set<Integer> stateSet = new HashSet<>();// 订单状态Set
|
| | | if (commonOrderList != null && commonOrderList.size() > 0) {
|
| | | int orderType = commonOrderList.get(0).getSourceType();
|
| | |
|
| | | boolean miandan = false;
|
| | | Map<Integer, HongBaoOrder> notificationMap = new HashMap<>();
|
| | | int goodsCount = 0;
|
| | | boolean hasAdd = false;
|
| | |
| | | throw new HongBaoException(1, "订单信息不完整");
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder == null) {
|
| | | saveHongBao(commonOrder, type, notificationMap);
|
| | | miandan = saveHongBao(commonOrder, type, notificationMap);
|
| | | hasAdd = true;
|
| | | } else {
|
| | | boolean update = updateHongBao(hongBaoOrder, commonOrder, type, notificationMap);
|
| | |
| | | switch (t) {
|
| | | case HongBaoV2.TYPE_ZIGOU:
|
| | | userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, goodsCount, state);
|
| | | commonOrder.getPayment(), money, goodsCount, commonOrder.getState(),
|
| | | commonOrder.getThirdCreateTime());
|
| | |
|
| | | break;
|
| | | case HongBaoV2.TYPE_SHARE_GOODS:
|
| | |
|
| | | userOrderMsgNotificationService.orderShareStatistic(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, goodsCount, state);
|
| | | commonOrder.getPayment(), money, goodsCount, commonOrder.getState(),
|
| | | commonOrder.getThirdCreateTime());
|
| | |
|
| | | break;
|
| | | case HongBaoV2.TYPE_YIJI:
|
| | |
|
| | | userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, goodsCount, state);
|
| | | commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
|
| | | commonOrder.getThirdCreateTime());
|
| | | break;
|
| | | case HongBaoV2.TYPE_ERJI:
|
| | |
|
| | | userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, goodsCount, state);
|
| | | commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
|
| | | commonOrder.getThirdCreateTime());
|
| | | break;
|
| | |
|
| | | case HongBaoV2.TYPE_SHARE_YIJI:
|
| | | userOrderMsgNotificationService.orderShareFirstLevelStatistic(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, goodsCount, state, notify.getBeizhu());
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
|
| | | commonOrder.getThirdCreateTime());
|
| | |
|
| | | // 添加新版本通知
|
| | |
|
| | | if (!hasAdd) {
|
| | | Iterator<Integer> its = notificationMap.keySet().iterator();
|
| | | while (its.hasNext()) {
|
| | | Integer t = its.next();
|
| | | HongBaoV2 notify = notificationMap.get(t).getHongBaoV2();
|
| | | CommonOrder commonOrder = notificationMap.get(t).getCommonOrder();
|
| | | String orderId = commonOrderList.get(0).getOrderNo();
|
| | | Long uid = notify.getUserInfo().getId();
|
| | | BigDecimal money = notify.getMoney();
|
| | | switch (t) {
|
| | | case HongBaoV2.TYPE_ZIGOU:
|
| | | userOrderMsgNotificationService.orderFanLiStateChanged(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, state);
|
| | | case HongBaoV2.TYPE_SHARE_ERJI:
|
| | | userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, new BigDecimal(0), goodsCount, commonOrder.getState(),
|
| | | commonOrder.getThirdCreateTime());
|
| | | break;
|
| | | case HongBaoV2.TYPE_SHARE_GOODS:
|
| | | userOrderMsgNotificationService.orderShareStateChanged(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, state);
|
| | | break;
|
| | | case HongBaoV2.TYPE_YIJI:
|
| | | userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, state);
|
| | | break;
|
| | | case HongBaoV2.TYPE_ERJI:
|
| | | userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, state);
|
| | | break;
|
| | | case HongBaoV2.TYPE_SHARE_YIJI:
|
| | | userOrderMsgNotificationService.orderShareFirstLevelStateChanged(uid, orderId, orderType,
|
| | | commonOrder.getPayment(), money, state);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | int resultCode = 0;
|
| | | if (hasAdd && hasUpdate)
|
| | | return 12;
|
| | | return new HongBaoAddResult(HongBaoAddResult.CODE_ADD_AND_UPDATE, miandan);
|
| | | else if (hasAdd)
|
| | | return 1;
|
| | | return new HongBaoAddResult(HongBaoAddResult.CODE_ADD, miandan);
|
| | | else if (hasUpdate)
|
| | | return 2;
|
| | | return resultCode;
|
| | | return new HongBaoAddResult(HongBaoAddResult.CODE_UPDATE, miandan);
|
| | | return new HongBaoAddResult(resultCode, miandan);
|
| | | }
|
| | | return 0;
|
| | | return new HongBaoAddResult(0, false);
|
| | | }
|
| | |
|
| | | private int getOrderState(Set<Integer> states) {
|
| | |
| | | return CommonOrder.STATE_SX;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | private boolean updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type,
|
| | | Map<Integer, HongBaoOrder> notificationMap) throws HongBaoException, UserAccountException {
|
| | | System.out.println(commonOrder.getOrderNo());
|
| | |
| | | return false;
|
| | |
|
| | | if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
|
| | | BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime());
|
| | | BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,
|
| | | commonOrder.getCreateTime().getTime());
|
| | | // 免单处理
|
| | | boolean mianDan = false;
|
| | | List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO,
|
| | |
| | | && commonOrder.getSourcePosition().equalsIgnoreCase(TaoBaoConstant.TAOBAO_TLJ_RELATION_PID_DEFAULT))
|
| | | fanliRate = hongBaoManageService.getTLJShareRate(commonOrder.getCreateTime().getTime());
|
| | | else
|
| | | fanliRate = hongBaoManageService.getShareRate(commonOrder.getCreateTime().getTime());
|
| | | fanliRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,
|
| | | commonOrder.getCreateTime().getTime());
|
| | |
|
| | | List<ShareGoodsActivityOrder> list = shareGoodsActivityOrderService
|
| | | .listByOrderIdAndUid(commonOrder.getUserInfo().getId(), commonOrder.getOrderNo());
|
| | |
| | | return true;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | private boolean saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap)
|
| | | throws HongBaoException, UserAccountException {
|
| | | if (type == HongBaoV2.TYPE_ZIGOU) {// 获取自购的返利比例
|
| | | BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime());
|
| | | BigDecimal fanliRate = hongBaoManageService.getFanLiRate(UserLevelEnum.daRen,
|
| | | commonOrder.getCreateTime().getTime());
|
| | | // 查询是否有免单计划
|
| | | BigDecimal mianDanMoney = null;
|
| | | if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) {
|
| | |
| | | BigDecimal firstRate = hongBaoManageService
|
| | | .getFirstInviteRate(boss.getRank() == null ? 0 : boss.getRank());
|
| | | if (firstRate.compareTo(new BigDecimal(0)) <= 0)
|
| | | return;
|
| | | return mianDanMoney != null;
|
| | | HongBaoV2 firstHongbao = new HongBaoV2();
|
| | | firstHongbao.setUserInfo(boss);
|
| | | firstHongbao.setUrank(boss.getRank());
|
| | |
| | | }
|
| | | // 返利为0的不通知
|
| | | if (firstHongbao.getMoney() == null || firstHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
|
| | | return;
|
| | | return mianDanMoney != null;
|
| | |
|
| | | hongBaoV2Mapper.insertSelective(firstHongbao);
|
| | | // 用户通知
|
| | |
| | | BigDecimal secondRate = hongBaoManageService
|
| | | .getSecondInviteRate(boss.getRank() == null ? 0 : boss.getRank());
|
| | | if (secondRate.compareTo(new BigDecimal(0)) <= 0)
|
| | | return;
|
| | | return mianDanMoney != null;
|
| | | HongBaoV2 secondHongbao = new HongBaoV2();
|
| | | secondHongbao.setUserInfo(boss);
|
| | | secondHongbao.setUrank(boss.getRank());
|
| | |
| | |
|
| | | // 返利为0的不统计
|
| | | if (secondHongbao.getMoney() == null || secondHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0)
|
| | | return;
|
| | | return mianDanMoney != null;
|
| | |
|
| | | hongBaoV2Mapper.insertSelective(secondHongbao);
|
| | |
|
| | |
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | return mianDanMoney != null;
|
| | | } else if (type == HongBaoV2.TYPE_SHARE_GOODS) {
|
| | | // 分享赚不加入失效的订单
|
| | | if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ)
|
| | | return;
|
| | | return false;
|
| | | // 分享赚
|
| | | BigDecimal shareRate = null;
|
| | | if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_TAOBAO
|
| | | && commonOrder.getSourcePosition().equalsIgnoreCase(TaoBaoConstant.TAOBAO_TLJ_RELATION_PID_DEFAULT))// 来自于淘礼金的分享
|
| | | shareRate = hongBaoManageService.getTLJShareRate(commonOrder.getCreateTime().getTime());
|
| | | else
|
| | | shareRate = hongBaoManageService.getShareRate(commonOrder.getCreateTime().getTime());
|
| | | shareRate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,
|
| | | commonOrder.getCreateTime().getTime());
|
| | |
|
| | | // 判断订单分享活动是否开启
|
| | | if ("1".equalsIgnoreCase(configService.get("share_goods_activity_open"))) {
|
| | | if ("1".equalsIgnoreCase(configService.get(ConfigKeyEnum.shareGoodsActivityOpen.getKey()))) {
|
| | | // 没有订单,并且是渠道ID来的,并且
|
| | | UserExtraTaoBaoInfo taoBaoExtraInfo = userExtraTaoBaoInfoService
|
| | | .getByUid(commonOrder.getUserInfo().getId());
|
| | |
| | | }
|
| | | } else
|
| | | throw new HongBaoException(2, "type错误");
|
| | |
|
| | | return false;
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | return hongBaoV2Mapper.listByIds(idList);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<HongBaoDTO> listByOrderTradeId(String tradeId) {
|
| | | return hongBaoV2Mapper.listByOrderTradeId(tradeId);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public Integer getDirectBossUrankByPid(Long pid) {
|
| | | return hongBaoV2Mapper.getDirectBossUrankByPid(pid);
|
| | | }
|
| | |
|
| | | |
| | | }
|