From 2c2e4b771af2840c6d8ad720543823a974d2989b Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 02 一月 2019 09:58:45 +0800
Subject: [PATCH] 暂存修改

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java |  231 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 224 insertions(+), 7 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..9c32806 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;
@@ -21,6 +22,7 @@
 import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoOrderMapper;
 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;
@@ -28,8 +30,12 @@
 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 +67,9 @@
 
 	@Resource
 	private CommonOrderService commonOrderService;
+
+	@Resource
+	private UserInfoService userInfoService;
 
 	@Override
 	public int insert(HongBaoV2 record) {
@@ -268,19 +277,16 @@
 	@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閿欒");
 
 		} else {
 
@@ -288,4 +294,215 @@
 
 	}
 
+	@Transactional
+	private void updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type) throws HongBaoException {
+		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_BUFENSHIXIAO);
+				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);
+			}
+			hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao);
+			// 鑾峰彇瀛愮孩鍖�
+			List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBaoOrder.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) {
+			// TODO 鍒嗕韩璧氱殑浜岀骇鏇存柊
+			// 鍒嗕韩璧�
+			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_BUFENSHIXIAO);
+				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());
+			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閿欒");
+	}
+
+	@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.setCreateTime(new Date());
+			hongBao.setType(HongBaoV2.TYPE_ZIGOU);
+			hongBao.setVersion(2);
+			if (commonOrder.getState() == CommonOrder.STATE_FK) {
+				hongBao.setState(HongBaoV2.STATE_BUFENSHIXIAO);
+				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());
+				HongBaoV2 firstHongbao = new HongBaoV2();
+				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());
+					HongBaoV2 secondHongbao = new HongBaoV2();
+					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_BUFENSHIXIAO);
+				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());
+			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