From 5981b2cae7c20ec9021c8ccbe1a926f35f640210 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 03 一月 2019 17:43:18 +0800 Subject: [PATCH] Merge branch 'dev-hongbao' --- fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java | 304 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 294 insertions(+), 10 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 09a4a20..634c724 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.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -19,17 +20,24 @@ 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.entity.bus.user.HongBao; import com.yeshi.fanli.entity.bus.user.HongBaoV2; +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.taobao.TaoBaoOrder; +import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder; import com.yeshi.fanli.exception.HongBaoException; import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service; +import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce; import com.yeshi.fanli.service.inter.order.CommonOrderService; +import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.MoneyBigDecimalUtil; +import com.yeshi.fanli.util.TimeUtil; import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil; @Service @@ -61,6 +69,12 @@ @Resource private CommonOrderService commonOrderService; + + @Resource + private UserInfoService userInfoService; + + @Resource + private TaoBaoWeiQuanOrderMapper taoBaoWeiQuanOrderMapper; @Override public int insert(HongBaoV2 record) { @@ -132,7 +146,6 @@ if (hb.getOrder() != null) { orderId = hb.getOrder().getOrderId(); // 鏌ヨ鍚屼竴璁㈠崟鍙风殑闈炲瓙绾㈠寘 - } else orderId = hb.getOrderId(); @@ -180,9 +193,15 @@ if (list.size() <= 0) return; 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鎺掑簭 @@ -228,6 +247,11 @@ 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); // 鎻掑叆绾㈠寘 @@ -268,24 +292,284 @@ @Resource private HongBaoManageService hongBaoManageService; + @Resource + private ThreeSaleSerivce threeSaleSerivce; + + @Transactional @Override public void addHongBao(CommonOrder commonOrder, int type) throws HongBaoException { if (commonOrder == null || commonOrder.getId() == null || commonOrder.getUserInfo() == null) throw new HongBaoException(1, "璁㈠崟淇℃伅涓嶅畬鏁�"); HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); if (hongBaoOrder == null) { - if (type == HongBaoV2.TYPE_ZIGOU) {// 鑾峰彇鑷喘鐨勮繑鍒╂瘮渚� - BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime()); - - } else if (type == HongBaoV2.TYPE_SHARE_GOODS) { - - } else - throw new HongBaoException(2, "type閿欒"); - + saveHongBao(commonOrder, type); } else { - + updateHongBao(hongBaoOrder, commonOrder, type); } } + @Transactional + private void updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type) throws HongBaoException { + System.out.println(commonOrder.getOrderNo()); + 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; + + if (type == HongBaoV2.TYPE_ZIGOU) {// 鑾峰彇鑷喘鐨勮繑鍒╂瘮渚� + BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime()); + HongBaoV2 hongBao = new HongBaoV2(hongBaoOrder.getHongBaoV2().getId()); + hongBao.setUpdateTime(new Date()); + // 鏇存敼鐘舵�佷笌璧勯噾 + if (commonOrder.getState() == CommonOrder.STATE_FK) { + hongBao.setState(HongBaoV2.STATE_BUKELINGQU); + hongBao.setMoney( + MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100)))); + } 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)); + } else if (commonOrder.getState() == CommonOrder.STATE_SX) { + hongBao.setState(HongBaoV2.STATE_SHIXIAO); + hongBao.setMoney(new BigDecimal(0)); + } + hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao); + + // 鑾峰彇瀛愮孩鍖� + List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId()); + if (children != null) + for (HongBaoV2 child : children) { + HongBaoV2 childUpdate = new HongBaoV2(child.getId()); + childUpdate.setState(hongBao.getState()); + childUpdate.setUpdateTime(new Date()); + BigDecimal rate = null; + if (child.getType() == HongBaoV2.TYPE_YIJI) {// 涓�绾у垎浜禋 + rate = hongBaoManageService.getFirstInviteRate(child.getUrank(), + commonOrder.getCreateTime().getTime()); + } else if (child.getType() == HongBaoV2.TYPE_ERJI) {// 浜岀骇鍒嗕韩璧� + rate = hongBaoManageService.getSecondInviteRate(child.getUrank(), + commonOrder.getCreateTime().getTime()); + } + + // 浠ュ疄闄呮敹鍏ヤ负鍑嗚绠楅浼版敹鐩� + if (hongBao.getState() == HongBaoV2.STATE_KELINGQU) { + childUpdate.setMoney( + MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), rate.divide(new BigDecimal(100)))); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(commonOrder.getSettleTime()); + calendar.add(Calendar.MONTH, 1); + childUpdate.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) { + childUpdate.setMoney( + MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), rate.divide(new BigDecimal(100)))); + } + hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate); + } + + } else if (type == HongBaoV2.TYPE_SHARE_GOODS) { + BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime()); + HongBaoV2 hongBao = new HongBaoV2(hongBaoOrder.getHongBaoV2().getId()); + hongBao.setUpdateTime(new Date()); + // 鏇存敼鐘舵�佷笌璧勯噾 + if (commonOrder.getState() == CommonOrder.STATE_FK) { + hongBao.setState(HongBaoV2.STATE_BUKELINGQU); + hongBao.setMoney( + MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100)))); + } else if (commonOrder.getState() == CommonOrder.STATE_JS) { + hongBao.setState(HongBaoV2.STATE_KELINGQU); + hongBao.setMoney( + MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), fanliRate.divide(new BigDecimal(100)))); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(commonOrder.getSettleTime()); + calendar.add(Calendar.MONTH, 1); + hongBao.setPreGetTime(new Date(TimeUtil.convertToTimeTemp( + calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd"))); + } else if (commonOrder.getState() == CommonOrder.STATE_SX) { + hongBao.setState(HongBaoV2.STATE_SHIXIAO); + hongBao.setMoney(new BigDecimal(0)); + } + hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao); + + // 鑾峰彇瀛愮孩鍖� + List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId()); + if (children != null) + for (HongBaoV2 child : children) { + HongBaoV2 childUpdate = new HongBaoV2(child.getId()); + // 缁熶竴璁剧疆鐘舵�� + childUpdate.setState(hongBao.getState()); + childUpdate.setUpdateTime(new Date()); + BigDecimal rate = null; + if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) {// 涓�绾у垎浜禋 + rate = hongBaoManageService.getFirstShareRate(child.getUrank(), + commonOrder.getCreateTime().getTime()); + } else if (child.getType() == HongBaoV2.TYPE_SHARE_ERJI) {// 浜岀骇鍒嗕韩璧� + rate = hongBaoManageService.getSecondShareRate(child.getUrank(), + commonOrder.getCreateTime().getTime()); + } + + // 浠ュ疄闄呮敹鍏ヤ负鍑嗚绠楅浼版敹鐩� + if (CommonOrder.STATE_JS == commonOrder.getState()) { + childUpdate.setMoney( + MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), rate.divide(new BigDecimal(100)))); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(commonOrder.getSettleTime()); + calendar.add(Calendar.MONTH, 1); + childUpdate.setPreGetTime(new Date(TimeUtil.convertToTimeTemp( + 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(commonOrder.getEstimate(), rate.divide(new BigDecimal(100)))); + } + hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate); + } + } else + throw new HongBaoException(2, "type閿欒"); + } + + @Transactional + private void saveHongBao(CommonOrder commonOrder, int type) throws HongBaoException { + if (type == HongBaoV2.TYPE_ZIGOU) {// 鑾峰彇鑷喘鐨勮繑鍒╂瘮渚� + BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime()); + HongBaoV2 hongBao = new HongBaoV2(); + hongBao.setUserInfo(commonOrder.getUserInfo()); + hongBao.setCreateTime(new Date()); + hongBao.setType(HongBaoV2.TYPE_ZIGOU); + hongBao.setVersion(2); + if (commonOrder.getState() == CommonOrder.STATE_FK) { + hongBao.setState(HongBaoV2.STATE_BUKELINGQU); + hongBao.setMoney( + MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), fanliRate.divide(new BigDecimal(100)))); + } 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)); + } else if (commonOrder.getState() == CommonOrder.STATE_SX) { + hongBao.setState(HongBaoV2.STATE_SHIXIAO); + hongBao.setMoney(new BigDecimal(0)); + } else { + throw new HongBaoException(3, "缁存潈璁㈠崟涓嶈兘鍒涘缓绾㈠寘"); + } + UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId()); + hongBao.setUrank(user.getRank()); + hongBaoV2Mapper.insertSelective(hongBao); + // 娣诲姞绾㈠寘涓庤鍗曠殑鏄犲皠 + HongBaoOrder hongBaoOrder = new HongBaoOrder(); + hongBaoOrder.setCommonOrder(commonOrder); + hongBaoOrder.setCreateTime(new Date()); + hongBaoOrder.setHongBaoV2(hongBao); + hongBaoOrderMapper.insertSelective(hongBaoOrder); + + UserInfo boss = threeSaleSerivce.getBoss(user.getId()); + if (boss != null && hongBao.getState() != HongBaoV2.STATE_SHIXIAO) {// 1绾OSS瀛樺湪涓旂孩鍖呮湭澶辨晥 + + // 鎻掑叆涓�绾у瓙绾㈠寘 + 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(commonOrder.geteIncome(), 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(commonOrder.getEstimate(), firstRate.divide(new BigDecimal(100)))); + } + hongBaoV2Mapper.insertSelective(firstHongbao); + + // 鎻掑叆浜岀骇瀛愮孩鍖� + 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) { + firstHongbao.setMoney(MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), + 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(commonOrder.getEstimate(), + secondRate.divide(new BigDecimal(100)))); + } + hongBaoV2Mapper.insertSelective(secondHongbao); + } + + } + + } else if (type == HongBaoV2.TYPE_SHARE_GOODS) { + // 鍒嗕韩璧氫笉鍔犲叆澶辨晥鐨勮鍗� + if (commonOrder.getState() == CommonOrder.STATE_SX || commonOrder.getState() == CommonOrder.STATE_WQ) + return; + // 鍒嗕韩璧� + BigDecimal shareRate = hongBaoManageService.getShareRate(commonOrder.getCreateTime().getTime()); + HongBaoV2 hongBao = new HongBaoV2(); + hongBao.setCreateTime(new Date()); + hongBao.setType(HongBaoV2.TYPE_SHARE_GOODS); + hongBao.setVersion(2); + if (commonOrder.getState() == CommonOrder.STATE_FK) { + hongBao.setState(HongBaoV2.STATE_BUKELINGQU); + hongBao.setMoney( + MoneyBigDecimalUtil.mul(commonOrder.getEstimate(), shareRate.divide(new BigDecimal(100)))); + } else if (commonOrder.getState() == CommonOrder.STATE_JS) { + hongBao.setState(HongBaoV2.STATE_KELINGQU); + hongBao.setMoney( + MoneyBigDecimalUtil.mul(commonOrder.geteIncome(), shareRate.divide(new BigDecimal(100)))); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(commonOrder.getSettleTime()); + calendar.add(Calendar.MONTH, 1); + hongBao.setPreGetTime(new Date(TimeUtil.convertToTimeTemp( + calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd"))); + } + UserInfo user = userInfoService.getUserById(commonOrder.getUserInfo().getId()); + hongBao.setUrank(user.getRank()); + hongBao.setUserInfo(user); + hongBaoV2Mapper.insertSelective(hongBao); + // 鎻掑叆绾㈠寘涓庤鍗曟槧灏� + HongBaoOrder hongBaoOrder = new HongBaoOrder(); + hongBaoOrder.setCommonOrder(commonOrder); + hongBaoOrder.setCreateTime(new Date()); + hongBaoOrder.setHongBaoV2(hongBao); + hongBaoOrderMapper.insertSelective(hongBaoOrder); + } else + throw new HongBaoException(2, "type閿欒"); + } } -- Gitblit v1.8.0