From 9a24f2802a3d6fe3e82c05e52f2880d65ad04dcf Mon Sep 17 00:00:00 2001 From: yujian <yujian> Date: 星期一, 29 四月 2019 08:59:47 +0800 Subject: [PATCH] Merge branch 'div_develop' into master_develop --- fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java | 522 +++++++++++++++++++++++++++------------------------------ 1 files changed, 251 insertions(+), 271 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 43f9f66..7cf4837 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,9 +1,8 @@ package com.yeshi.fanli.service.impl.hongbao; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -18,28 +17,24 @@ import org.springframework.transaction.annotation.Transactional; import com.yeshi.fanli.dao.mybatis.HongBaoV2Mapper; -import com.yeshi.fanli.dao.mybatis.PidOrderMapper; -import com.yeshi.fanli.dao.mybatis.hongbao.HongBaoMapper; 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.HongBao; 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; 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.taobao.PidOrder; import com.yeshi.fanli.entity.taobao.TaoBaoOrder; -import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder; import com.yeshi.fanli.exception.HongBaoException; import com.yeshi.fanli.exception.order.ShareGoodsActivityOrderException; import com.yeshi.fanli.exception.share.UserShareGoodsRecordException; @@ -61,7 +56,6 @@ import com.yeshi.fanli.util.MoneyBigDecimalUtil; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.TimeUtil; -import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil; @Service public class HongBaoV2ServiceImpl implements HongBaoV2Service { @@ -70,13 +64,7 @@ private HongBaoV2Mapper hongBaoV2Mapper; @Resource - private HongBaoMapper hongBaoMapper; - - @Resource private TaoBaoOrderMapper taoBaoOrderMapper; - - @Resource - private OrderItemMapper orderItemMapper; @Resource private CommonOrderMapper commonOrderMapper; @@ -101,9 +89,6 @@ @Resource private UserShareGoodsGroupService userShareGoodsGroupService; - - @Resource - private PidOrderMapper pidOrderMapper; @Resource private HongBaoManageService hongBaoManageService; @@ -162,230 +147,6 @@ return hongBaoV2Mapper.selectByPrimaryKey(id); } - private HongBaoV2 getHongBaoV2(HongBao hb) { - int type = hb.getType().intValue(); - HongBaoV2 v2 = new HongBaoV2(hb.getId()); - v2.setCreateTime(new Date(hb.getCreatetime())); - if (hb.getGetTime() == null || hb.getGetTime() == 0) - v2.setGetTime(null); - else - v2.setGetTime(new Date(hb.getGetTime())); - - v2.setMoney(hb.getMoney()); - if (hb.getParent() != null) - v2.setParent(new HongBaoV2(hb.getParent().getId())); - - if (hb.getType() == HongBao.TYPE_SHARE_GOODS) { - if (hb.getBalanceTime() != null) - v2.setPreGetTime(new Date(hb.getPreGettime())); - else - v2.setPreGetTime(null); - } else { - if (hb.getPreGettime() == null || hb.getPreGettime() == 0) - v2.setPreGetTime(null); - else - v2.setPreGetTime(new Date(hb.getPreGettime())); - } - - v2.setState(hb.getState()); - if (hb.getState() == 1 && hb.getBalanceTime() != null) { - v2.setState(HongBaoV2.STATE_KELINGQU); - } - v2.setType(type); - v2.setUpdateTime(new Date(hb.getCreatetime())); - v2.setUrank(hb.getUrank()); - v2.setUserInfo(hb.getUserInfo()); - v2.setVersion(hb.getVersion()); - return v2; - } - - @Transactional - @Override - public void convert(HongBao hb) { - if (hb == null || hb.getParent() != null) - return; - - int type = hb.getType().intValue(); - if (type == HongBao.TYPE_TAOBAO || type == HongBao.TYPE_SHARE_GOODS) {// 鑷喘涓庡垎浜禋闇�瑕佹煡璇㈠嚭鎵�鏈夌殑璁㈠崟 - // 灞炰簬杩斿埄璁㈠崟 - String orderId = ""; - if (hb.getOrder() != null) { - orderId = hb.getOrder().getOrderId(); - // 鏌ヨ鍚屼竴璁㈠崟鍙风殑闈炲瓙绾㈠寘 - } else - orderId = hb.getOrderId(); - - int count = commonOrderMapper.countByOrderNOAndOrderType(orderId, Constant.SOURCE_TYPE_TAOBAO); - - // 宸茬粡鎻掑叆璁㈠崟 - if (count > 0) - return; - - // - - if (hb.getVersion() == 1) {// 寰堣�佺増鏈殑澶勭悊鏂瑰紡,宸瞙ongbao涓轰富 - if (hongBaoV2Mapper.selectByPrimaryKey(hb.getId()) != null) - return; - HongBaoV2 hongBaoV2 = getHongBaoV2(hb); - hongBaoV2.setBeizhu("璁㈠崟鍙�:" + orderId); - hongBaoV2Mapper.insert(hongBaoV2); - - if (hb.getHasChild())// 瀛樺湪瀛愮孩鍖� - { - List<HongBao> children = hongBaoMapper.selectChildHongBaoByPid(hb.getId()); - if (children != null) - for (HongBao hongBao : children) { - HongBaoV2 child = getHongBaoV2(hongBao); - hongBaoV2Mapper.insert(child); - } - } - - } else {// 鏂扮増鏈鐞嗘柟寮� - - List<HongBao> list = hongBaoMapper.selectByOrderId(orderId); - - if (list.size() == 0) - list = hongBaoMapper.selectByOid(hb.getOrder().getId()); - if (list != null) - // 鍒犻櫎瀛愮孩鍖� - for (int i = 0; i < list.size(); i++) { - if (list.get(i).getParent() != null) { - list.remove(i); - i--; - } - - } - - if (list.size() <= 0) - return; - if (list.get(0).getType() == 20) - for (HongBao hb1 : list) { - PidOrder pidOrder = pidOrderMapper.getPidOrderByHongBaoId(hb1.getId()); - if (pidOrder != null) - hb1.setAuctionId(pidOrder.getAuctionId()); - - } - - List<TaoBaoOrder> orderList = taoBaoOrderMapper.selectTaoBaoOrderByOrderId(orderId); - - if (orderList == null || orderList.size() < list.size()) { - System.out.println("绾㈠寘鏁颁笌璁㈠崟鏁颁笉瀵瑰簲"); - return; - } - - // 鍔犲叆鎺掑簭鍊� - for (int i = 0; i < orderList.size(); i++) { - orderList.get(i).setOrderBy(i + 1); - } - - // 鎸夌収auctionId,payMoney鎺掑簭 - Comparator<HongBao> cm = new Comparator<HongBao>() { - @Override - public int compare(HongBao o1, HongBao o2) { - if (o1.getAuctionId().longValue() < o2.getAuctionId().longValue()) - return -3; - else if (o1.getAuctionId().longValue() > o2.getAuctionId().longValue()) { - return 3; - } else { - if (o1.getState() - o2.getState() > 0) - return 2; - else if (o1.getState() - o2.getState() < 0) - return -2; - else { - if (o1.getPayMoney().compareTo(o2.getPayMoney()) >= 0) - return 1; - else - return -1; - } - } - } - }; - - Collections.sort(list, cm); - - Comparator<TaoBaoOrder> cmOrder = new Comparator<TaoBaoOrder>() { - - @Override - public int compare(TaoBaoOrder o1, TaoBaoOrder o2) { - - if (o1.getAuctionId().longValue() < o2.getAuctionId().longValue()) - return -3; - else if (o1.getAuctionId().longValue() > o2.getAuctionId().longValue()) { - return 3; - } else { - if (o1.getPayment().compareTo(o2.getPayment()) < 0) - return 2; - else - return -2; - } - } - }; - - Collections.sort(orderList, cmOrder); - - for (TaoBaoOrder t : orderList) - System.out.println(t.getAuctionId()); - - for (int i = 0; i < list.size(); i++) { - CommonOrder commonOrder = TaoBaoOrderUtil.convert(orderList.get(i)); - CommonOrderGoods goods = new CommonOrderGoods(); - goods.setGoodsId(orderList.get(i).getAuctionId() + ""); - goods.setGoodsType(Constant.SOURCE_TYPE_TAOBAO); - // 鍟嗗搧鏄惁宸茬粡鎻掑叆 - List<CommonOrderGoods> commonGoodsList = commonOrderGoodsMapper - .listByGoodsIdAndGoodsType(goods.getGoodsId(), goods.getGoodsType()); - if (commonGoodsList.size() <= 0)// 涓嶅瓨鍦ㄥ氨鎻掑叆鍟嗗搧 - commonOrderGoodsMapper.insertSelective(goods); - else - goods.setId(commonGoodsList.get(commonGoodsList.size() - 1).getId()); - commonOrder.setCommonOrderGoods(goods); - - commonOrder.setUserInfo(list.get(i).getUserInfo()); - commonOrder.setCreateTime(new Date(list.get(i).getCreatetime())); - - // TODO 缁存潈鍒ゆ柇 - List<TaoBaoWeiQuanOrder> weiQuanList = taoBaoWeiQuanOrderMapper.selectListByOrderIdAndState(orderId, - "缁存潈鎴愬姛"); - if (weiQuanList != null && weiQuanList.size() > 0) - commonOrder.setState(CommonOrder.STATE_WQ); - - commonOrderMapper.insertSelective(commonOrder); - - // 鎻掑叆绾㈠寘 - HongBaoV2 hongBaoV2 = getHongBaoV2(list.get(i)); - hongBaoV2.setId(list.get(i).getId()); - hongBaoV2Mapper.insert(hongBaoV2); - - HongBaoOrder ho = new HongBaoOrder(); - ho.setCommonOrder(commonOrder); - ho.setCreateTime(new Date()); - ho.setHongBaoV2(hongBaoV2); - hongBaoOrderMapper.insertSelective(ho); - - if (list.get(i).getHasChild())// 瀛樺湪瀛愮孩鍖� - { - List<HongBao> children = hongBaoMapper.selectChildHongBaoByPid(list.get(i).getId()); - if (children != null) - for (HongBao hongBao : children) { - HongBaoV2 child = getHongBaoV2(hongBao); - hongBaoV2Mapper.insert(child); - } - } - } - } - - } else {// 鐩存帴鎻掑叆 - - if (type != HongBao.TYPE_ERJI && type != HongBao.TYPE_YIJI && type != HongBao.TYPE_SHARE_YIJI - && type != HongBao.TYPE_SHARE_ERJI) { - if (hongBaoV2Mapper.selectByPrimaryKey(hb.getId()) == null) - hongBaoV2Mapper.insert(getHongBaoV2(hb)); - } - - } - - } - @Transactional @Override public void addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException { @@ -414,7 +175,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(); @@ -445,6 +205,11 @@ MsgOrderDetail.STATE_FK, null, money); userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, commonOrder.getPayment(), money, goodsCount, state); + break; + + case HongBaoV2.TYPE_SHARE_YIJI: + userOrderMsgNotificationService.orderShareFirstLevelStatistic(uid, orderId, + commonOrder.getPayment(), money, goodsCount, state, notify.getBeizhu()); break; } } @@ -478,6 +243,9 @@ userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, commonOrder.getPayment(), money, state); break; + case HongBaoV2.TYPE_SHARE_YIJI: + userOrderMsgNotificationService.orderShareFirstLevelStateChanged(uid, orderId, + commonOrder.getPayment(), money, state); } } } @@ -514,18 +282,15 @@ BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime()); // 鍏嶅崟澶勭悊 boolean mianDan = false; - if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) { - List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO, - commonOrder.getOrderNo()); - if (orderList != null && orderList.size() == 1) {// 鍙湁1涓鍗曟墠鍙備笌鍏嶅崟 - BigDecimal payMent = commonOrder.getPayment(); - if (commonOrder.getState() == CommonOrder.STATE_JS) - payMent = commonOrder.getSettlement(); + List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO, + commonOrder.getOrderNo()); + if (orderList != null && orderList.size() == 1) {// 鍙湁1涓鍗曟墠鍙備笌鍏嶅崟 + BigDecimal payMent = commonOrder.getPayment(); + if (commonOrder.getState() == CommonOrder.STATE_JS) + payMent = commonOrder.getSettlement(); - if (payMent.compareTo(new BigDecimal(10)) < 0) { - mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getOrderNo()); - fanliRate = new BigDecimal(100); - } + if (payMent.compareTo(new BigDecimal(10)) < 0) { + mianDan = userSystemCouponRecordService.isSuccessMianDan(commonOrder.getOrderNo()); } } @@ -536,14 +301,27 @@ hongBao.setState(HongBaoV2.STATE_BUKELINGQU); hongBao.setMoney( MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100)))); + if (mianDan) + hongBao.setMoney(commonOrder.getPayment()); } else if (commonOrder.getState() == CommonOrder.STATE_JS) { 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 (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 (mianDan) { + try { + userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo()); + } catch (Exception e) { + e.printStackTrace(); + throw new HongBaoException(12, "鍏嶅崟鍒搁��娆惧嚭閿�"); + } + } } hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao); @@ -567,7 +345,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()); @@ -616,7 +394,110 @@ } } + 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()); List<ShareGoodsActivityOrder> list = shareGoodsActivityOrderService @@ -674,17 +555,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); @@ -692,13 +576,34 @@ 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()); + 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()); + tempHongBaoOrder.getCommonOrder().setPayment( + tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + tempHongBaoOrder.getHongBaoV2() + .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(childUpdate.getMoney())); + notificationMap.put(child.getType(), tempHongBaoOrder); + } + + } } else throw new HongBaoException(2, "type閿欒"); @@ -710,7 +615,7 @@ if (type == HongBaoV2.TYPE_ZIGOU) {// 鑾峰彇鑷喘鐨勮繑鍒╂瘮渚� BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime()); // 鏌ヨ鏄惁鏈夊厤鍗曡鍒� - boolean mianDan = false; + BigDecimal mianDanMoney = null; if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK) { List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(Constant.SOURCE_TYPE_TAOBAO, commonOrder.getOrderNo()); @@ -724,16 +629,22 @@ if (goods != null) { try { - mianDan = userSystemCouponService.updateCouponRecordUsed(commonOrder.getUserInfo().getId(), - commonOrder.getOrderNo(), payMent, Long.parseLong(goods.getGoodsId())); - if (mianDan) - fanliRate = new BigDecimal(100); + if (userSystemCouponService.updateCouponRecordUsed(commonOrder.getUserInfo().getId(), + commonOrder.getOrderNo(), payMent, Long.parseLong(goods.getGoodsId()))) + mianDanMoney = payMent; } catch (NumberFormatException e) { throw new HongBaoException(10, "鍏嶅崟鍟嗗搧澶勭悊鍑洪敊"); } catch (Exception e) { + e.printStackTrace(); throw new HongBaoException(11, "鍏嶅崟鍟嗗搧澶勭悊鍑洪敊"); } } + } + } else if (commonOrder.getState() == CommonOrder.STATE_SX) {// 璁剧疆鍏嶅崟鍒稿け鏁� + try { + userSystemCouponService.updateStateByDrawback(commonOrder.getOrderNo()); + } catch (Exception e) { + e.printStackTrace(); } } @@ -757,6 +668,10 @@ } else { throw new HongBaoException(3, "缁存潈璁㈠崟涓嶈兘鍒涘缓绾㈠寘"); } + + if (mianDanMoney != null) + hongBao.setMoney(mianDanMoney); + UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId()); hongBao.setUrank(user.getRank()); hongBaoV2Mapper.insertSelective(hongBao); @@ -785,7 +700,7 @@ } UserInfo boss = threeSaleSerivce.getBoss(user.getId()); - if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO && !mianDan) {// 1绾OSS瀛樺湪涓旂孩鍖呮湭澶辨晥,鍏嶅崟涓嶆敮鎸佸绾у垎閿� + if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO && mianDanMoney == null) {// 1绾OSS瀛樺湪涓旂孩鍖呮湭澶辨晥,鍏嶅崟涓嶆敮鎸佸绾у垎閿� // 鎻掑叆涓�绾у瓙绾㈠寘 BigDecimal firstRate = hongBaoManageService @@ -918,7 +833,6 @@ } } } - } HongBaoV2 hongBao = new HongBaoV2(); @@ -965,6 +879,56 @@ tempHongBaoOrder.getHongBaoV2() .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney())); 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); + } + } } // 淇敼缁熻鏁版嵁 @@ -1048,4 +1012,20 @@ 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); + } } -- Gitblit v1.8.0