From 9eeda0d3049b71877c373c04d65533939b5582ef Mon Sep 17 00:00:00 2001 From: yujian <yujian@123.com> Date: 星期一, 02 九月 2019 09:55:55 +0800 Subject: [PATCH] getBoss方法只查询有效上级信息 --- fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java | 376 +++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 321 insertions(+), 55 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java index 28b1cc5..5aba925 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java @@ -1,6 +1,7 @@ package com.yeshi.fanli.service.impl.hongbao; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; @@ -19,14 +20,13 @@ import com.yeshi.fanli.dao.mybatis.order.CommonOrderGoodsMapper; import com.yeshi.fanli.dao.mybatis.order.CommonOrderMapper; import com.yeshi.fanli.dao.mybatis.order.HongBaoOrderMapper; -import com.yeshi.fanli.dao.mybatis.order.OrderItemMapper; import com.yeshi.fanli.dao.mybatis.order.OrderMapper; import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoOrderMapper; import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper; import com.yeshi.fanli.dto.HongBao; import com.yeshi.fanli.dto.HongBaoDTO; -import com.yeshi.fanli.entity.bus.msg.MsgOrderDetail; 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.order.CommonOrder; @@ -47,13 +47,13 @@ import com.yeshi.fanli.service.inter.order.ShareGoodsActivityOrderService; import com.yeshi.fanli.service.inter.user.UserExtraTaoBaoInfoService; import com.yeshi.fanli.service.inter.user.UserInfoService; -import com.yeshi.fanli.service.inter.user.UserNotificationService; import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService; import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService; import com.yeshi.fanli.service.inter.user.UserSystemCouponService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.MoneyBigDecimalUtil; import com.yeshi.fanli.util.StringUtil; +import com.yeshi.fanli.util.TaoBaoConstant; import com.yeshi.fanli.util.TimeUtil; @Service @@ -64,9 +64,6 @@ @Resource private TaoBaoOrderMapper taoBaoOrderMapper; - - @Resource - private OrderItemMapper orderItemMapper; @Resource private CommonOrderMapper commonOrderMapper; @@ -92,15 +89,11 @@ @Resource private UserShareGoodsGroupService userShareGoodsGroupService; - @Resource private HongBaoManageService hongBaoManageService; @Resource private ThreeSaleSerivce threeSaleSerivce; - - @Resource - private UserNotificationService userNotificationService; @Resource private UserOrderMsgNotificationService userOrderMsgNotificationService; @@ -150,12 +143,13 @@ return hongBaoV2Mapper.selectByPrimaryKey(id); } - @Transactional @Override public void addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException { Set<Integer> stateSet = new HashSet<>();// 璁㈠崟鐘舵�丼et if (commonOrderList != null && commonOrderList.size() > 0) { + int orderType = commonOrderList.get(0).getSourceType(); + Map<Integer, HongBaoOrder> notificationMap = new HashMap<>(); int goodsCount = 0; boolean hasAdd = false; @@ -179,7 +173,6 @@ 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(); @@ -188,28 +181,28 @@ BigDecimal money = notify.getMoney(); switch (t) { case HongBaoV2.TYPE_ZIGOU: - userNotificationService.orderFanliStatisticed(uid, orderId, goodsCount, MsgOrderDetail.STATE_FK, - null, money); - userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, commonOrder.getPayment(), - money, goodsCount, state); + userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, orderType, + commonOrder.getPayment(), money, goodsCount, state); break; case HongBaoV2.TYPE_SHARE_GOODS: - userNotificationService.orderShareStatisticed(uid, orderId, goodsCount, MsgOrderDetail.STATE_FK, - null, money); - userOrderMsgNotificationService.orderShareStatistic(uid, orderId, commonOrder.getPayment(), - money, goodsCount, state); + + userOrderMsgNotificationService.orderShareStatistic(uid, orderId, orderType, + commonOrder.getPayment(), money, goodsCount, state); break; case HongBaoV2.TYPE_YIJI: - userNotificationService.orderInviteStatisticed(uid, orderId, goodsCount, - MsgOrderDetail.STATE_FK, null, money); - userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, commonOrder.getPayment(), - money, goodsCount, state); + + userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType, + commonOrder.getPayment(), money, goodsCount, state); break; case HongBaoV2.TYPE_ERJI: - userNotificationService.orderInviteStatisticed(uid, orderId, goodsCount, - MsgOrderDetail.STATE_FK, null, money); - userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, commonOrder.getPayment(), - money, goodsCount, state); + + userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, orderType, + commonOrder.getPayment(), money, goodsCount, state); + break; + + case HongBaoV2.TYPE_SHARE_YIJI: + userOrderMsgNotificationService.orderShareFirstLevelStatistic(uid, orderId, orderType, + commonOrder.getPayment(), money, goodsCount, state, notify.getBeizhu()); break; } } @@ -228,21 +221,24 @@ BigDecimal money = notify.getMoney(); switch (t) { case HongBaoV2.TYPE_ZIGOU: - userOrderMsgNotificationService.orderFanLiStateChanged(uid, orderId, commonOrder.getPayment(), - money, state); + userOrderMsgNotificationService.orderFanLiStateChanged(uid, orderId, orderType, + commonOrder.getPayment(), money, state); break; case HongBaoV2.TYPE_SHARE_GOODS: - userOrderMsgNotificationService.orderShareStateChanged(uid, orderId, commonOrder.getPayment(), - money, state); + userOrderMsgNotificationService.orderShareStateChanged(uid, orderId, orderType, + commonOrder.getPayment(), money, state); break; case HongBaoV2.TYPE_YIJI: - userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, commonOrder.getPayment(), - money, state); + userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, orderType, + commonOrder.getPayment(), money, state); break; case HongBaoV2.TYPE_ERJI: - userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, commonOrder.getPayment(), - money, state); + userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, orderType, + commonOrder.getPayment(), money, state); break; + case HongBaoV2.TYPE_SHARE_YIJI: + userOrderMsgNotificationService.orderShareFirstLevelStateChanged(uid, orderId, orderType, + commonOrder.getPayment(), money, state); } } } @@ -271,7 +267,7 @@ HongBaoV2 oldHongBao = hongBaoV2Mapper.selectByPrimaryKey(hongBaoOrder.getHongBaoV2().getId()); if (oldHongBao == null) throw new HongBaoException(10, "绾㈠寘瀵硅薄涓嶅瓨鍦�"); - // 宸茬粡澶辨晥鎴栬�呭凡缁忛鍙栫殑绾㈠寘涓嶅仛澶勭悊 + // 宸茬粡澶辨晥锛屽凡缁忛鍙栵紝鏂拌�佺姸鎬佷竴鑷寸殑绾㈠寘涓嶅仛澶勭悊 if (oldHongBao.getState() == HongBaoV2.STATE_SHIXIAO || oldHongBao.getState() == HongBaoV2.STATE_YILINGQU) return; @@ -287,7 +283,8 @@ payMent = commonOrder.getSettlement(); if (payMent.compareTo(new BigDecimal(10)) < 0) { - mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getOrderNo()); + mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getSourceType(), + commonOrder.getOrderNo()); } } @@ -304,13 +301,24 @@ hongBao.setState(HongBaoV2.STATE_KELINGQU); hongBao.setMoney( MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100)))); - hongBao.setPreGetTime(new Date(commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L)); + if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_PDD)// 鎷煎澶�15澶╄繃1涓皬鏃跺埌璐� + hongBao.setPreGetTime(new Date( + commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L + 1000 * 60 * 60 * 1L)); + else + hongBao.setPreGetTime(new Date(commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L)); if (mianDan) hongBao.setMoney(commonOrder.getSettlement().compareTo(commonOrder.getPayment()) <= 0 ? commonOrder.getSettlement() : commonOrder.getPayment());// 杩斿埄缁撶畻涓庝粯娆捐緝灏忕殑閲戦 } else if (commonOrder.getState() == CommonOrder.STATE_SX) { hongBao.setState(HongBaoV2.STATE_SHIXIAO); hongBao.setMoney(new BigDecimal(0)); + } + + // 鏂拌�佺孩鍖呯姸鎬佷竴鑷翠笉澶勭悊 + if (oldHongBao.getState().intValue() == hongBao.getState()) + return; + + if (hongBao.getState() == HongBaoV2.STATE_SHIXIAO) { if (mianDan) { try { userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo()); @@ -320,6 +328,7 @@ } } } + hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao); // 鍔犲叆閫氱煡 @@ -342,7 +351,7 @@ // 鑾峰彇瀛愮孩鍖� List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId()); - if (children != null) + if (children != null && children.size() > 0) for (HongBaoV2 child : children) { HongBaoV2 childUpdate = new HongBaoV2(child.getId()); childUpdate.setState(hongBao.getState()); @@ -391,9 +400,118 @@ } } + else {// 淇涔嬪墠浜岀骇,涓夌骇璁㈠崟鏈粺璁″埌鐨勬儏鍐� + if (!mianDan) { + ThreeSale threeSale = threeSaleSerivce.selectByWorkerId(commonOrder.getUserInfo().getId()); + if (threeSale != null && threeSale.getSucceedTime() != null + && threeSale.getSucceedTime() <= commonOrder.getThirdCreateTime().getTime()) { + UserInfo boss = threeSaleSerivce.getBoss(commonOrder.getUserInfo().getId()); + // 鎻掑叆涓�绾у瓙绾㈠寘 + BigDecimal firstRate = hongBaoManageService + .getFirstInviteRate(boss.getRank() == null ? 0 : boss.getRank()); + if (firstRate.compareTo(new BigDecimal(0)) <= 0) + return; + HongBaoV2 firstHongbao = new HongBaoV2(); + firstHongbao.setUserInfo(boss); + firstHongbao.setUrank(boss.getRank()); + firstHongbao.setParent(hongBao); + firstHongbao.setCreateTime(new Date()); + firstHongbao.setType(HongBaoV2.TYPE_YIJI); + firstHongbao.setVersion(2); + firstHongbao.setState(hongBao.getState()); + if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) { + firstHongbao.setMoney( + MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100)))); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(commonOrder.getSettleTime()); + calendar.add(Calendar.MONTH, 1); + firstHongbao.setPreGetTime(new Date(TimeUtil.convertToTimeTemp( + calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", + "yyyy-M-dd"))); + } else if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU) { + firstHongbao.setMoney( + MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100)))); + } + hongBaoV2Mapper.insertSelective(firstHongbao); + // 鐢ㄦ埛閫氱煡 + if (notificationMap.get(HongBaoV2.TYPE_YIJI) == null) { + HongBaoV2 tempHongBao = new HongBaoV2(firstHongbao.getId()); + tempHongBao.setUserInfo(firstHongbao.getUserInfo()); + tempHongBao.setMoney(firstHongbao.getMoney()); + CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); + tempCommonOrder.setPayment(commonOrder.getPayment()); + notificationMap.put(HongBaoV2.TYPE_YIJI, new HongBaoOrder(tempCommonOrder, tempHongBao)); + } else { + // 澧炲姞浠樻閲戦涓庤祫閲� + HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_YIJI); + tempHongBaoOrder.getCommonOrder().setPayment( + tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + tempHongBaoOrder.getHongBaoV2() + .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(firstHongbao.getMoney())); + notificationMap.put(HongBaoV2.TYPE_YIJI, tempHongBaoOrder); + } + + // 鎻掑叆浜岀骇瀛愮孩鍖� + boss = threeSaleSerivce.getBoss(boss.getId()); + if (boss != null) {// 浜岀骇BOSS瀛樺湪 + BigDecimal secondRate = hongBaoManageService + .getSecondInviteRate(boss.getRank() == null ? 0 : boss.getRank()); + if (secondRate.compareTo(new BigDecimal(0)) <= 0) + return; + HongBaoV2 secondHongbao = new HongBaoV2(); + secondHongbao.setUserInfo(boss); + secondHongbao.setUrank(boss.getRank()); + secondHongbao.setParent(hongBao); + secondHongbao.setCreateTime(new Date()); + secondHongbao.setType(HongBaoV2.TYPE_ERJI); + secondHongbao.setVersion(2); + secondHongbao.setState(hongBao.getState()); + if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) { + secondHongbao.setMoney(MoneyBigDecimalUtil.mul(hongBao.getMoney(), + secondRate.divide(new BigDecimal(100)))); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(commonOrder.getSettleTime()); + calendar.add(Calendar.MONTH, 1); + secondHongbao.setPreGetTime(new Date(TimeUtil.convertToTimeTemp( + calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", + "yyyy-M-dd"))); + } else if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU) { + secondHongbao.setMoney(MoneyBigDecimalUtil.mul(hongBao.getMoney(), + secondRate.divide(new BigDecimal(100)))); + } + hongBaoV2Mapper.insertSelective(secondHongbao); + + // 鐢ㄦ埛閫氱煡 + if (notificationMap.get(HongBaoV2.TYPE_ERJI) == null) { + HongBaoV2 tempHongBao = new HongBaoV2(secondHongbao.getId()); + tempHongBao.setUserInfo(secondHongbao.getUserInfo()); + tempHongBao.setMoney(secondHongbao.getMoney()); + CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); + tempCommonOrder.setPayment(commonOrder.getPayment()); + notificationMap.put(HongBaoV2.TYPE_ERJI, + new HongBaoOrder(tempCommonOrder, tempHongBao)); + } else { + // 澧炲姞浠樻閲戦涓庤祫閲� + HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_ERJI); + tempHongBaoOrder.getCommonOrder().setPayment( + tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + tempHongBaoOrder.getHongBaoV2().setMoney( + tempHongBaoOrder.getHongBaoV2().getMoney().add(secondHongbao.getMoney())); + notificationMap.put(HongBaoV2.TYPE_ERJI, tempHongBaoOrder); + } + } + } + } + } } else if (type == HongBaoV2.TYPE_SHARE_GOODS) { - BigDecimal fanliRate = hongBaoManageService.getShareRate(commonOrder.getCreateTime().getTime()); + BigDecimal fanliRate = null; + if (commonOrder.getSourceType() == 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()); + List<ShareGoodsActivityOrder> list = shareGoodsActivityOrderService .listByOrderIdAndUid(commonOrder.getUserInfo().getId(), commonOrder.getOrderNo()); if (list != null && list.size() > 0) { @@ -449,17 +567,20 @@ childUpdate.setUpdateTime(new Date()); BigDecimal rate = null; if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) {// 涓�绾у垎浜禋 - rate = hongBaoManageService.getFirstShareRate(child.getUrank(), - commonOrder.getCreateTime().getTime()); + rate = hongBaoManageService.getFirstShareRate(1, commonOrder.getCreateTime().getTime()); } else if (child.getType() == HongBaoV2.TYPE_SHARE_ERJI) {// 浜岀骇鍒嗕韩璧� - rate = hongBaoManageService.getSecondShareRate(child.getUrank(), - commonOrder.getCreateTime().getTime()); + rate = hongBaoManageService.getSecondShareRate(1, commonOrder.getCreateTime().getTime()); } // 浠ュ疄闄呮敹鍏ヤ负鍑嗚绠楅浼版敹鐩� if (CommonOrder.STATE_JS == commonOrder.getState()) { childUpdate.setMoney( MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100)))); + if (commonOrder.getThirdCreateTime().getTime() > TimeUtil.convertToTimeTemp("2019-04-16", + "yyyy-MM-dd")) + childUpdate.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), + rate.divide(new BigDecimal(100)))); + Calendar calendar = Calendar.getInstance(); calendar.setTime(commonOrder.getSettleTime()); calendar.add(Calendar.MONTH, 1); @@ -467,13 +588,36 @@ calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd"))); } else if (CommonOrder.STATE_FK == commonOrder.getState()) { - if (commonOrder.getOrderNo().equalsIgnoreCase("314134177659155087")) - System.out.println(""); - - childUpdate.setMoney( - MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100)))); + if (commonOrder.getThirdCreateTime().getTime() > TimeUtil.convertToTimeTemp("2019-04-16", + "yyyy-MM-dd")) + childUpdate.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), + rate.divide(new BigDecimal(100)))); + else + childUpdate.setMoney( + MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100)))); } hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate); + // 娣诲姞閫氱煡 + if (notificationMap.get(child.getType()) == null) { + HongBaoV2 tempHongBao = new HongBaoV2(child.getId()); + tempHongBao.setUserInfo(child.getUserInfo()); + tempHongBao + .setMoney(childUpdate.getMoney() == null ? new BigDecimal(0) : childUpdate.getMoney()); + CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); + tempCommonOrder.setPayment(commonOrder.getPayment()); + notificationMap.put(child.getType(), new HongBaoOrder(tempCommonOrder, tempHongBao)); + } else { + // 澧炲姞浠樻閲戦涓庤祫閲� + HongBaoOrder tempHongBaoOrder = notificationMap.get(child.getType()); + if (commonOrder.getPayment() != null) + tempHongBaoOrder.getCommonOrder().setPayment( + tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + if (childUpdate.getMoney() != null) + tempHongBaoOrder.getHongBaoV2() + .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(childUpdate.getMoney())); + notificationMap.put(child.getType(), tempHongBaoOrder); + } + } } else throw new HongBaoException(2, "type閿欒"); @@ -487,7 +631,7 @@ // 鏌ヨ鏄惁鏈夊厤鍗曡鍒� BigDecimal mianDanMoney = null; if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) { - List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO, + List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(commonOrder.getSourceType(), commonOrder.getOrderNo()); if (orderList != null && orderList.size() == 1) {// 鍙湁1涓鍗曟墠鍙備笌鍏嶅崟 BigDecimal payMent = commonOrder.getPayment(); @@ -511,6 +655,7 @@ } } } else if (commonOrder.getState() == CommonOrder.STATE_SX) {// 璁剧疆鍏嶅崟鍒稿け鏁� + commonOrder.setPayment(new BigDecimal(0));// 璁㈠崟澶辨晥鍚庣殑浠樻閲戦璁剧疆涓�0 try { userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo()); } catch (Exception e) { @@ -531,7 +676,11 @@ hongBao.setState(HongBaoV2.STATE_KELINGQU); hongBao.setMoney( MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100)))); - hongBao.setPreGetTime(new Date(commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L)); + if (commonOrder.getSourceType() == Constant.SOURCE_TYPE_PDD)// 鎷煎澶�15澶╁崐鍒拌处 + hongBao.setPreGetTime(new Date( + commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L + 1000 * 60 * 60 * 12L)); + else + hongBao.setPreGetTime(new Date(commonOrder.getSettleTime().getTime() + 1000 * 60 * 60 * 24 * 15L)); } else if (commonOrder.getState() == CommonOrder.STATE_SX) { hongBao.setState(HongBaoV2.STATE_SHIXIAO); hongBao.setMoney(new BigDecimal(0)); @@ -599,6 +748,10 @@ firstHongbao.setMoney( MoneyBigDecimalUtil.mul(hongBao.getMoney(), firstRate.divide(new BigDecimal(100)))); } + // 杩斿埄涓�0鐨勪笉閫氱煡 + if (firstHongbao.getMoney() == null || firstHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0) + return; + hongBaoV2Mapper.insertSelective(firstHongbao); // 鐢ㄦ埛閫氱煡 if (notificationMap.get(HongBaoV2.TYPE_YIJI) == null) { @@ -646,6 +799,11 @@ secondHongbao.setMoney( MoneyBigDecimalUtil.mul(hongBao.getMoney(), secondRate.divide(new BigDecimal(100)))); } + + // 杩斿埄涓�0鐨勪笉缁熻 + if (secondHongbao.getMoney() == null || secondHongbao.getMoney().compareTo(new BigDecimal(0)) <= 0) + return; + hongBaoV2Mapper.insertSelective(secondHongbao); // 鐢ㄦ埛閫氱煡 @@ -674,7 +832,12 @@ if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ) return; // 鍒嗕韩璧� - BigDecimal shareRate = hongBaoManageService.getShareRate(commonOrder.getCreateTime().getTime()); + 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()); // 鍒ゆ柇璁㈠崟鍒嗕韩娲诲姩鏄惁寮�鍚� if ("1".equalsIgnoreCase(configService.get("share_goods_activity_open"))) { @@ -703,7 +866,6 @@ } } } - } HongBaoV2 hongBao = new HongBaoV2(); @@ -752,6 +914,56 @@ notificationMap.put(type, tempHongBaoOrder); } + // 4鏈�17鏃ュ悗鎵嶆湁涓�绾у垎浜禋 + if (commonOrder.getThirdCreateTime().getTime() > TimeUtil.convertToTimeTemp("2019-04-17", "yyyy-MM-dd")) { + UserInfo boss = threeSaleSerivce.getBoss(hongBao.getUserInfo().getId()); + if (boss != null) { + BigDecimal firstLevelRate = hongBaoManageService.getFirstShareRate(1, + commonOrder.getThirdCreateTime().getTime()); + HongBaoV2 child = new HongBaoV2(); + child.setParent(hongBao); + child.setType(HongBaoV2.TYPE_SHARE_YIJI); + if (commonOrder.getState() == CommonOrder.STATE_FK) { + child.setState(HongBaoV2.STATE_BUKELINGQU); + child.setMoney(MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), + firstLevelRate.divide(new BigDecimal(100)))); + } else if (commonOrder.getState() == CommonOrder.STATE_JS) { + child.setState(HongBaoV2.STATE_KELINGQU); + child.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), + firstLevelRate.divide(new BigDecimal(100)))); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(commonOrder.getSettleTime()); + calendar.add(Calendar.MONTH, 1); + child.setPreGetTime(new Date(TimeUtil.convertToTimeTemp( + calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", + "yyyy-M-dd"))); + } + child.setUserInfo(boss); + child.setUrank(boss.getRank()); + child.setVersion(2); + child.setCreateTime(new Date()); + hongBaoV2Mapper.insertSelective(child); + // 娣诲姞閫氱煡 + if (notificationMap.get(HongBaoV2.TYPE_SHARE_YIJI) == null) { + HongBaoV2 tempHongBao = new HongBaoV2(child.getId()); + tempHongBao.setUserInfo(child.getUserInfo()); + tempHongBao.setMoney(child.getMoney()); + tempHongBao.setBeizhu(hongBao.getUserInfo().getNickName()); + CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); + tempCommonOrder.setPayment(commonOrder.getPayment()); + notificationMap.put(HongBaoV2.TYPE_SHARE_YIJI, new HongBaoOrder(tempCommonOrder, tempHongBao)); + } else { + // 澧炲姞浠樻閲戦涓庤祫閲� + HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_SHARE_YIJI); + tempHongBaoOrder.getCommonOrder().setPayment( + tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + tempHongBaoOrder.getHongBaoV2() + .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(child.getMoney())); + notificationMap.put(HongBaoV2.TYPE_SHARE_YIJI, tempHongBaoOrder); + } + } + } + // 淇敼缁熻鏁版嵁 Long goodsId = commonOrder.getCommonOrderGoods().getId(); // 鏌ヨ鍟嗗搧 @@ -764,7 +976,7 @@ hb.setMoney(hongBao.getMoney()); try { - userShareGoodsGroupService.updateOrderRecord(hb); + userShareGoodsGroupService.updateOrderRecord(hb, commonOrder.getSourceType()); } catch (UserShareGoodsRecordException e) { try { LogHelper.errorDetailInfo(e); @@ -833,4 +1045,58 @@ else return money; } + + @Override + public BigDecimal computeMoneyByUidAndState(Long uid, int state) { + List<Integer> stateList = new ArrayList<>(); + stateList.add(state); + BigDecimal money = hongBaoV2Mapper.computeMoneyByUidAndState(uid, stateList); + if (money == null) + return new BigDecimal(0); + else + return money; + } + + @Override + public List<HongBaoV2> listChildrenById(Long id) { + return hongBaoV2Mapper.listChildrenById(id); + } + + @Override + public List<Long> getUidByNear30DayShareSucceed() { + return hongBaoV2Mapper.getUidByNear30DayShareSucceed(); + } + + @Override + public void invalidInviteHongBaoByParentUid(Long parentUid, String beiZhu) { + List<Integer> typeList = new ArrayList<>(); + typeList.add(HongBaoV2.TYPE_YIJI); + typeList.add(HongBaoV2.TYPE_ERJI); + typeList.add(HongBaoV2.TYPE_SHARE_YIJI); + typeList.add(HongBaoV2.TYPE_SHARE_ERJI); + List<Integer> stateList = new ArrayList<>(); + stateList.add(HongBaoV2.STATE_KELINGQU); + stateList.add(HongBaoV2.STATE_BUKELINGQU); + long count = hongBaoV2Mapper.countByParentUidAndTypeAndState(parentUid, typeList, stateList); + int page = (int) (count % 100 == 0 ? count / 100 : count / 100 + 1); + for (int i = 1; i <= page; i++) { + List<HongBaoV2> list = hongBaoV2Mapper.listByParentUidAndTypeAndState(parentUid, typeList, stateList, 0, + 100); + if (list != null) + for (HongBaoV2 v2 : list) { + HongBaoV2 update = new HongBaoV2(v2.getId()); + update.setUpdateTime(new Date()); + update.setState(HongBaoV2.STATE_SHIXIAO); + update.setBeizhu(beiZhu); + hongBaoV2Mapper.updateByPrimaryKeySelective(update); + } + } + } + + @Override + public List<HongBaoV2> listBySourceTypeAndTradeIdListAndUid(int sourceType, long uid, List<String> tradeIdList) { + if (tradeIdList == null || tradeIdList.size() == 0) + return null; + return hongBaoV2Mapper.listBySourceTypeAndTradeIdListAndUid(sourceType, uid, tradeIdList); + } } -- Gitblit v1.8.0