From a56bd9db6b5c989fb2eaecd3a854ac6782b55f95 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 26 十月 2019 14:44:19 +0800
Subject: [PATCH] 淘宝维权退款服务修改

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java |  120 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 97 insertions(+), 23 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java
index 4b479cc..4c29b74 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java
@@ -954,12 +954,77 @@
 	}
 	
 	
+	
 	@Override
-	public List<String> getAutoExtractOpenIds() throws Exception {
+	public List<UserInfo> preAutoUser() throws Exception {
 		int page = 0;
 		int pageSize = 100;
 		int maxSize = 300;
 		Date nowDate = new Date();
+		// 涓�銆佽嚜鍔ㄦ彁鐜伴拡瀵圭殑鐢ㄦ埛缇わ細 鍓嶆彁鏉′欢:鐢ㄦ埛鍦ㄨ窛浠�60澶╁埌90澶╁唴鏈椿璺冭繃鐨勭敤鎴�
+		String beganDate = DateUtil.reduceDayTostring(90, nowDate);
+		String endDate = DateUtil.reduceDayTostring(60, nowDate);
+		// 鏉′欢3锛氳窛绂讳笂涓�娆℃垚鍔熼鍙栧井淇$孩鍖呭凡缁忚秴杩囦簡30澶╂椂闂达紝鍙湪绗�31澶╁啀娆′笅鍙戯紱
+		String receivedDate = DateUtil.reduceDayTostring(30, nowDate);
+		// 鏉′欢4锛氳窛绂讳笂涓�娆℃湭鎴愬姛棰嗗彇寰俊绾㈠寘宸茬粡瓒呰繃浜�15澶╂椂闂达紝鍙湪绗�16澶╁啀娆′笅鍙戯紱
+		String refundDate = DateUtil.reduceDayTostring(15, nowDate);
+		
+		// 浣欓鏈�浣庨檺鍒�
+		BigDecimal minSurplus = BigDecimal.valueOf(Constant.AUTO_EXTRACT_MIN_SURPLUS);
+		
+		List<UserInfo> list = new ArrayList<UserInfo>();
+		
+		while (true) {
+			// 鏌ヨ婊¤冻鏉′欢 1銆�2 鐨剈id
+			List<UserInfo> listUser = userInfoService.getAutoExtractUser(page * pageSize, pageSize, minSurplus, beganDate, endDate);
+			if (listUser == null || listUser.isEmpty())
+				break;
+			
+			List<Long> listId = new ArrayList<Long>();
+			for (UserInfo userInfo: listUser) {
+				listId.add(userInfo.getId());
+			}
+			
+			// 鏌ヨ璁板綍鏄惁婊¤冻
+			List<Long> listValid = extractWeiXinRecordService.getValidUsers(listId, receivedDate, refundDate);
+			if (listValid == null || listValid.isEmpty()) {
+				page ++;
+				continue;
+			}
+			
+			for (Long uid: listValid) {
+				if (list.size() >= maxSize)
+					break;
+				for (UserInfo userInfo: listUser) {
+					if (list.size() >= maxSize)
+						break;
+					
+					if (userInfo.getId().longValue() == uid.longValue()) {
+						list.add(userInfo);
+						break;
+					}
+				}
+			}
+			
+			if (list.size() >= maxSize)
+				break;
+			
+			page ++;
+		}
+		return list;
+	}
+	
+	
+	
+	@Override
+	public List<String> getAutoExtractOpenIds() throws Exception {
+		int page = 0;
+		int pageSize = 100;
+		int maxSize = 301; // appId + 瀹為檯openid300涓�
+		Date nowDate = new Date();
+		// 涓�銆佽嚜鍔ㄦ彁鐜伴拡瀵圭殑鐢ㄦ埛缇わ細 鍓嶆彁鏉′欢:鐢ㄦ埛鍦ㄨ窛浠�60澶╁埌90澶╁唴鏈椿璺冭繃鐨勭敤鎴�
+		String beganDate = DateUtil.reduceDayTostring(90, nowDate);
+		String endDate = DateUtil.reduceDayTostring(60, nowDate);
 		// 鏉′欢3锛氳窛绂讳笂涓�娆℃垚鍔熼鍙栧井淇$孩鍖呭凡缁忚秴杩囦簡30澶╂椂闂达紝鍙湪绗�31澶╁啀娆′笅鍙戯紱
 		String receivedDate = DateUtil.reduceDayTostring(30, nowDate);
 		// 鏉′欢4锛氳窛绂讳笂涓�娆℃湭鎴愬姛棰嗗彇寰俊绾㈠寘宸茬粡瓒呰繃浜�15澶╂椂闂达紝鍙湪绗�16澶╁啀娆′笅鍙戯紱
@@ -976,9 +1041,14 @@
 		
 		while (true) {
 			// 鏌ヨ婊¤冻鏉′欢 1銆�2 鐨剈id
-			List<Long> listId = userInfoService.getAutoExtractUserIds(page * pageSize, pageSize, minSurplus);
-			if (listId == null || listId.isEmpty())
+			List<UserInfo> listUser = userInfoService.getAutoExtractUser(page * pageSize, pageSize, minSurplus, beganDate, endDate);
+			if (listUser == null || listUser.isEmpty())
 				break;
+			
+			List<Long> listId = new ArrayList<Long>();
+			for (UserInfo userInfo: listUser) {
+				listId.add(userInfo.getId());
+			}
 			
 			// 鏌ヨ璁板綍鏄惁婊¤冻
 			List<Long> listValid = extractWeiXinRecordService.getValidUsers(listId, receivedDate, refundDate);
@@ -1009,7 +1079,8 @@
 	@Transactional(rollbackFor = Exception.class)
 	private UserInfo subHongBaoByUid(Long uid, BigDecimal money, BigDecimal minSurplus) {
 		UserInfo userInfo = userInfoMapper.selectByPrimaryKeyForUpdate(uid);
-		if (userInfo != null && userInfo.getMyHongBao().compareTo(minSurplus) >= 0) {
+		if (userInfo != null && !StringUtil.isNullOrEmpty(userInfo.getWxOpenId())
+				&& !StringUtil.isNullOrEmpty(userInfo.getWxUnionId()) && userInfo.getMyHongBao().compareTo(minSurplus) >= 0) {
 			// 寰俊鎻愮幇璁板綍
 			ExtractWeiXinRecord extractRecord = new ExtractWeiXinRecord();
 			extractRecord.setUid(uid);
@@ -1071,8 +1142,8 @@
 			
 		// 鐘舵�佽繃婊�
 		String statusOld = record.getStatus();
-		if (StringUtil.isNullOrEmpty(statusOld) ||ExtractWeiXinRecord.REFUND.equals(statusOld) 
-				|| ExtractWeiXinRecord.RFUND_ING.equals(statusOld)) 
+		if (StringUtil.isNullOrEmpty(statusOld) || ExtractWeiXinRecord.REFUND.equals(statusOld) 
+				|| ExtractWeiXinRecord.RECEIVED.equals(statusOld)) 
 			return;
 		
 		ExtractWeiXinRecord updeteRecord = new ExtractWeiXinRecord();
@@ -1126,25 +1197,28 @@
 			}  
 		}
 		updeteRecord.setStatus(status);
-		
-		// 鏇存柊绾㈠寘璁板綍
 		extractWeiXinRecordService.updateByPrimaryKeySelective(updeteRecord);
 		
-		if (!ExtractWeiXinRecord.REFUND.equals(status))
-			return;
-		
-		// 璧勯噾鏄庣粏
-		UserMoneyDetail detail = new UserMoneyDetail();
-		detail.setCreateTime(new Date());
-		detail.setIdentifyCode(StringUtil.Md5(UserMoneyDetailTypeEnum.extractAutoWXRefund.name() + ":" + record.getId()));
-		detail.setMoney(record.getMoney());
-		detail.setTitle(UserMoneyDetailTypeEnum.extractAutoWXRefund.getDesc());
-		detail.setType(UserMoneyDetailTypeEnum.extractAutoWXRefund);
-		detail.setUpdateTime(new Date());
-		detail.setUserInfo(new UserInfo(record.getUid()));
-		
-		// 璧勯噾璁$畻
-		userMoneyService.addUserMoney(record.getUid(), record.getMoney(), detail);
+		if (ExtractWeiXinRecord.RECEIVED.equals(status)) {
+			// 鍙戦�佹秷鎭�氱煡
+			userMoneyMsgNotificationService.extractAuto(record, "宸查鍙�-宸叉彁鐜�", null, null);
+		} else if (ExtractWeiXinRecord.REFUND.equals(status)) {
+			// 璧勯噾鏄庣粏
+			UserMoneyDetail detail = new UserMoneyDetail();
+			detail.setCreateTime(new Date());
+			detail.setIdentifyCode(StringUtil.Md5(UserMoneyDetailTypeEnum.extractAutoWXRefund.name() + ":" + record.getId()));
+			detail.setMoney(record.getMoney());
+			detail.setTitle(UserMoneyDetailTypeEnum.extractAutoWXRefund.getDesc());
+			detail.setType(UserMoneyDetailTypeEnum.extractAutoWXRefund);
+			detail.setUpdateTime(new Date());
+			detail.setUserInfo(new UserInfo(record.getUid()));
+			
+			// 璧勯噾璁$畻
+			userMoneyService.addUserMoney(record.getUid(), record.getMoney(), detail);
+			
+			// 鍙戦�佹秷鎭�氱煡
+			userMoneyMsgNotificationService.extractAuto(record, "宸查��鍥�-浣欓涓�", null, null);
+		}
 	}
 	
 }

--
Gitblit v1.8.0