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/HongBaoServiceImpl.java |  247 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 238 insertions(+), 9 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoServiceImpl.java
index a95acfd..f50b971 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoServiceImpl.java
@@ -2,15 +2,18 @@
 
 import java.io.Serializable;
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 
-import org.apache.ibatis.annotations.Param;
+import net.sf.json.JSONObject;
+
 import org.hibernate.HibernateException;
 import org.hibernate.Query;
 import org.hibernate.SQLQuery;
@@ -22,6 +25,7 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
+import org.yeshi.utils.DateUtil;
 
 import com.yeshi.fanli.dao.hongbao.HongBaoDao;
 import com.yeshi.fanli.dao.mybatis.AccountDetailsMapper;
@@ -33,6 +37,7 @@
 import com.yeshi.fanli.dao.mybatis.ThreeSaleMapper;
 import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
 import com.yeshi.fanli.dao.mybatis.hongbao.HongBaoMapper;
+import com.yeshi.fanli.dao.mybatis.money.UserMoneyDetailMapper;
 import com.yeshi.fanli.dao.mybatis.order.OrderItemMapper;
 import com.yeshi.fanli.dao.mybatis.order.OrderMapper;
 import com.yeshi.fanli.entity.admin.OrderAdmin;
@@ -47,8 +52,10 @@
 import com.yeshi.fanli.entity.bus.user.ThreeSaleGift;
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.entity.common.Config;
+import com.yeshi.fanli.entity.money.UserMoneyDetail;
 import com.yeshi.fanli.entity.taobao.OrderVital;
 import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
+import com.yeshi.fanli.exception.money.UserMoneyDetailException;
 import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.service.inter.config.ConfigService;
 import com.yeshi.fanli.service.inter.config.SystemConfigService;
@@ -59,7 +66,6 @@
 import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
 import com.yeshi.fanli.service.inter.order.OrderItemServcie;
 import com.yeshi.fanli.service.inter.order.OrderService;
-import com.yeshi.fanli.service.inter.push.PushService;
 import com.yeshi.fanli.service.inter.user.AccountDetailsService;
 import com.yeshi.fanli.service.inter.user.AccountMessageService;
 import com.yeshi.fanli.service.inter.user.MoneyRecordService;
@@ -75,11 +81,10 @@
 import com.yeshi.fanli.util.factory.AccountDetailsFactory;
 import com.yeshi.fanli.util.factory.AccountMessageFactory;
 import com.yeshi.fanli.util.factory.HongBaoFactory;
+import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
 import com.yeshi.fanli.util.push.XiaoMiPushUtil;
 import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
 import com.yeshi.fanli.util.taobao.TaoBaoUtil;
-
-import net.sf.json.JSONObject;
 
 @Service
 public class HongBaoServiceImpl implements HongBaoService {
@@ -164,6 +169,9 @@
 
 	@Resource
 	private UserNotificationService userNotificationService;
+	
+	@Resource
+	private UserMoneyDetailMapper userMoneyDetailMapper;
 
 	private static final String NEW_USER_HONGBAO = "new_user_hongbao";
 
@@ -441,6 +449,18 @@
 
 		AccountDetails ac = AccountDetailsFactory.create("+" + money, AccountDetailsFactory.XINREN, null, null, form);
 		accountDetailsMapper.insertSelective(ac);
+		// 鏂扮増璧勯噾鏄庣粏
+		try {
+			UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createNewerHongBao(hongBao);
+			userMoneyDetail.setId(ac.getId());
+			userMoneyDetailMapper.insert(userMoneyDetail);
+		} catch (UserMoneyDetailException e) {
+			try {
+				LogHelper.errorDetailInfo(e);
+			} catch (Exception e1) {
+				e1.printStackTrace();
+			}
+		}
 
 		userInfoMapper.addHongBaoByUid(form.getId(), new BigDecimal(money));
 		userNotificationService.newerHongBao(form.getId(), new BigDecimal(money));
@@ -870,8 +890,8 @@
 
 	@Transactional
 	public void updateHongBao(HongBao hongBao, TaoBaoOrder taoBaoOrder) {
-		BigDecimal rate = new BigDecimal(hongBaoManageMapper.selectByKey("hongbao_goods_proportion").getValue())
-				.divide(new BigDecimal(100));
+		BigDecimal proportion = hongBaoManageService.getFanLiRate();
+		BigDecimal rate = proportion.divide(new BigDecimal(100));
 		// 鏇存柊绾㈠寘椤�
 		HongBao updateHongBao = new HongBao();
 		updateHongBao.setId(hongBao.getId());
@@ -981,8 +1001,8 @@
 	public void addHongBao(Order order, TaoBaoOrder taoBaoOrder, Long orderItemId) {
 		OrderItem orderItem = orderItemMapper.selectByPrimaryKey(orderItemId);
 		// 璁㈠崟杩斿埄姣斾緥
-		BigDecimal baseRate = new BigDecimal(hongBaoManageMapper.selectByKey("hongbao_goods_proportion").getValue())
-				.divide(new BigDecimal(100));
+		BigDecimal proportion = hongBaoManageService.getFanLiRate();
+		BigDecimal baseRate = proportion.divide(new BigDecimal(100));
 
 		// 鍒涘缓绾㈠寘
 		JSONObject data = new JSONObject();
@@ -1010,6 +1030,10 @@
 		if (boss != null) {
 			hongBao.setHasChild(true);
 		}
+
+		// 濡傛灉澶辨晥灏卞垽瀹氬凡缁忓け鏁�
+		if (taoBaoOrder.getOrderState().equalsIgnoreCase("璁㈠崟澶辨晥"))
+			hongBao.setState(HongBao.STATE_SHIXIAO);
 
 		hongBaoMapper.insertSelective(hongBao);
 		// 閫氱煡鐢ㄦ埛璁㈠崟琚粺璁�
@@ -1205,8 +1229,213 @@
 
 	@Override
 	public int getTotalTiChengCount(Long uid) {
-
 		return hongBaoMapper.getTotalTiChengCount(uid);
 	}
 
+	
+	@Override
+	public List<Object> count24HOderByChannel(String channel, Integer type, String years,
+			String startTime, String endTime) throws Exception{
+		List<Map<String, Object>> list = hongBaoMapper.count24HOderByChannel(channel, type, years, 
+				startTime, endTime);
+		
+		if (list == null || list.size() == 0) {
+			return null;
+		} 
+		
+		switch (type){
+			case 1: // 鎸夊ぉ澶勭悊
+				return dayFactory(startTime, endTime, list);
+			case 2: // 鎸夋湀澶勭悊
+				return monthFactory(list);
+			case 3: 
+				return yearFactory(list);
+			default: 
+				return null;
+		}
+		
+	}
+	
+	@Override
+	public List<Object> countHistoryOderByChannel(String channel, Integer type, String years,
+			String startTime, String endTime) throws Exception{
+		
+		List<Map<String, Object>> list = hongBaoMapper.countHistoryOderByChannel(channel, type, years, 
+				startTime, endTime);
+		
+		if (list == null || list.size() == 0) {
+			return null;
+		} 
+		
+		switch (type){
+			case 1: // 鎸夊ぉ澶勭悊
+				return dayFactory(startTime, endTime, list);
+			case 2: // 鎸夋湀澶勭悊
+				return monthFactory(list);
+			case 3: 
+				return yearFactory(list);
+			default: 
+				return null;
+		}
+		
+	}
+	
+	
+	public List<Object> dayFactory(String startTime, String endTime, List<Map<String, Object>> list) throws Exception {
+	    
+		List<Object> listObject = new ArrayList<Object>();
+	
+		if (startTime.equals(endTime)) {
+			
+			Map<String, Object> map = list.get(0);
+			Object payMoney = map.get("payMoney");
+			Object countOrder = map.get("countOrder");
+			Object commision = map.get("commision");
+			
+			if (payMoney == null) {
+				map.put("payMoney", 0);
+			}
+			if (countOrder == null) {
+				map.put("countOrder", 0);
+			}
+			if (commision == null) {
+				map.put("commision", 0);
+			}
+			listObject.add(map);
+			return listObject;
+		}
+		
+		
+		String plusDay = "";
+		for (int i = 0; i < 1000 ; i++) {
+			if (i == 0) {
+				plusDay = startTime;
+			} else {
+				plusDay = DateUtil.plusDay(i, startTime);
+			}
+			
+			Map<String, Object> mapObject = new HashMap<String, Object>();
+			Object payMoney = null;
+			Object countOrder = null;
+			Object commision = null; 
+			
+			for (int j = 0; j < list.size(); j++) {
+				Map<String, Object> map = list.get(j);
+				Object createDate = map.get("createDate");
+				String month = createDate.toString();
+				if (plusDay.equalsIgnoreCase(month)) {
+					payMoney = map.get("payMoney");
+					countOrder = map.get("countOrder");
+					commision = map.get("commision");
+					break;
+				}
+			}
+			
+			if (payMoney == null) {
+				payMoney = 0;
+			}
+			mapObject.put("payMoney", payMoney);
+			
+			if (countOrder == null) {
+				countOrder = 0;
+			}
+			mapObject.put("countOrder", countOrder);
+			
+			if (commision == null) {
+				 commision = 0;
+			}
+			mapObject.put("commision", commision);
+			
+			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+	        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd");
+			Date parseDate = sdf.parse(plusDay.toString());
+			
+			mapObject.put("createDate", sdf2.format(parseDate));
+			
+			listObject.add(mapObject);
+			
+			if (plusDay.equals(endTime)) {
+				break; // 鏃堕棿缁撴潫
+			}
+		}
+		
+		return listObject;
+	}
+	
+	
+	public List<Object> monthFactory(List<Map<String, Object>> list) {
+		
+		List<Object> listObject = new ArrayList<Object>();
+		// 12 涓湀澶勭悊
+		for (int i = 1; i <= 12; i++) {
+			Map<String, Object> mapObject = new HashMap<String, Object>();
+			Object payMoney = null;
+			Object countOrder = null;
+			Object commision = null; 
+			
+			for (int j = 0; j < list.size(); j++) {
+				Map<String, Object> map = list.get(j);
+				Object createDate = map.get("createDate");
+				String month = createDate.toString();
+				if ((i+"").equalsIgnoreCase(month) || i == Integer.parseInt(month)) {
+					payMoney = map.get("payMoney");
+					countOrder = map.get("countOrder");
+					commision = map.get("commision");
+					break;
+				}
+			}
+			
+			if (payMoney == null) {
+				payMoney = 0;
+			}
+			mapObject.put("payMoney", payMoney);
+			
+			if (countOrder == null) {
+				countOrder = 0;
+			}
+			mapObject.put("countOrder", countOrder);
+			
+			if (commision == null) {
+				 commision = 0;
+			}
+			mapObject.put("commision", commision);
+			
+			mapObject.put("createDate", i + "鏈�");
+			
+			listObject.add(mapObject);
+		}
+		return listObject;
+	}
+	
+	public List<Object> yearFactory(List<Map<String, Object>> list) {
+		
+		List<Object> listObject = new ArrayList<Object>();
+		
+		for (int i = 0; i < list.size(); i++) {
+			Map<String, Object> map = list.get(i);
+			Object payMoney =  map.get("payMoney");
+			Object countOrder =  map.get("countOrder");
+			Object commision = map.get("commision"); 
+			
+			if (payMoney == null) {
+				payMoney = 0;
+			}
+			map.put("payMoney", payMoney);
+			
+			if (countOrder == null) {
+				countOrder = 0;
+			}
+			map.put("countOrder", countOrder);
+			
+			if (commision == null) {
+				 commision = 0;
+			}
+			map.put("commision", commision + "骞�");
+			
+			
+			listObject.add(map);
+		}
+		
+		return listObject;
+	}
 }

--
Gitblit v1.8.0