From 3ce9e928e082ff8abf697dba560cbfbb412e89f8 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期一, 11 十一月 2019 15:45:02 +0800
Subject: [PATCH] 商城后台编辑

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackGiveRecordServiceImpl.java |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackGiveRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackGiveRecordServiceImpl.java
index ba6dcc6..1a8d80e 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackGiveRecordServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackGiveRecordServiceImpl.java
@@ -1,7 +1,9 @@
 package com.yeshi.fanli.service.impl.redpack;
 
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.List;
 
 import javax.annotation.Resource;
 
@@ -9,13 +11,18 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.yeshi.utils.DateUtil;
 
+import com.google.gson.Gson;
 import com.yeshi.fanli.dao.mybatis.redpack.RedPackGiveRecordMapper;
+import com.yeshi.fanli.dto.msg.MsgRedPackGiveContentDTO;
+import com.yeshi.fanli.entity.bus.msg.MsgMoneyDetail.MsgTypeMoneyTypeEnum;
 import com.yeshi.fanli.entity.bus.user.TokenRecord;
 import com.yeshi.fanli.entity.bus.user.TokenRecord.TokenTypeEnum;
+import com.yeshi.fanli.entity.redpack.RedPackBalance;
 import com.yeshi.fanli.entity.redpack.RedPackDetail;
 import com.yeshi.fanli.entity.redpack.RedPackDetail.RedPackDetailTypeEnum;
 import com.yeshi.fanli.entity.redpack.RedPackGiveRecord;
 import com.yeshi.fanli.exception.redpack.RedPackGiveRecordException;
+import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
 import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService;
 import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
 import com.yeshi.fanli.service.inter.redpack.RedPackDetailService;
@@ -45,6 +52,9 @@
 	@Resource
 	private RedPackDetailService redPackDetailService;
 	
+	@Resource
+	private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
+	
 	
 	@Override
 	public RedPackGiveRecord selectByPrimaryKey(Long id) {
@@ -56,6 +66,38 @@
 		redPackGiveRecordMapper.updateByPrimaryKeySelective(record);
 	}
 	
+	
+	@Override
+	public List<RedPackGiveRecord> overdueList(int count) {
+		return redPackGiveRecordMapper.overdueList(count);
+	}
+	
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public void overdue(List<RedPackGiveRecord> list) throws Exception {
+		if (list == null || list.size() == 0)
+			return;
+		
+		SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm");
+		RedPackGiveRecord updateRecord = null;
+		for (RedPackGiveRecord giveRecord: list) {
+			updateRecord = new RedPackGiveRecord();
+			updateRecord.setId(giveRecord.getId());
+			updateRecord.setState(1);
+			redPackGiveRecordMapper.updateByPrimaryKeySelective(updateRecord);
+			
+			// 閫�鍥炵孩鍖�
+			redPackBalanceService.addRedPack(giveRecord.getGiveUid(), giveRecord.getAmount(), RedPackDetailFactory.createGiveOthersFail(giveRecord));
+			
+			// 閫�鍥炴秷鎭�
+			MsgRedPackGiveContentDTO givedto = new MsgRedPackGiveContentDTO();
+			givedto.setTitle("浣犺禒閫佺殑绾㈠寘鏈鎴愬姛棰嗗彇");
+			givedto.setMoney("楼" + giveRecord.getAmount().setScale(2));
+			givedto.setTime(sd.format(new Date()));
+			givedto.setGiveTime(sd.format(giveRecord.getGiveTime()));
+			userMoneyMsgNotificationService.redPackMsg(giveRecord.getGiveUid(), MsgTypeMoneyTypeEnum.redPackGiveBack, new Gson().toJson(givedto), "璇峰埌鎴戠殑-绾㈠寘鏌ョ湅");
+		}
+	}
 	
 	
 	@Override
@@ -69,9 +111,16 @@
 		if (amount.compareTo(new BigDecimal(giveMin)) < 0 || amount.compareTo(new BigDecimal(giveMax)) > 0)
 			throw new RedPackGiveRecordException(1, "璧犻�侀噾棰濊嚦灏�" + giveMin + "鍏冭嚦澶�" + giveMax + "鍏�");
 		
-		BigDecimal balance = redPackBalanceService.getBalance(uid);
-		if (balance == null || amount.compareTo(balance) > 0)
+		RedPackBalance balance = redPackBalanceService.selectByPrimaryKey(uid);
+		if (balance == null)
 			throw new RedPackGiveRecordException(1, "浣欓涓嶈冻");
+		
+		if (balance.getState() != null && balance.getState() == RedPackBalance.STATE_LOCKED) 
+			throw new RedPackGiveRecordException(1, "绾㈠寘宸插皝绂侊紝鎰熻阿浣跨敤");
+		
+		if (balance.getMoney() == null || amount.compareTo(balance.getMoney()) > 0)
+			throw new RedPackGiveRecordException(1, "浣欓涓嶈冻");
+		
 
 		Date nowDate = new Date();
 		// 璧犻�佽褰�
@@ -104,7 +153,7 @@
 			tips = tips.replace("{APP鍚嶇О}", projectChineseName);
 		}
 		tips = tips.replace("{鍙d护}", token).replace("{涓嬭浇閾炬帴}", redPackConfigService.getValueByKey("app_down_link")).replace("{闈㈤}",
-				amount.toString());
+				amount.setScale(2).toString());
 		
 		// 鍑忓皯绾㈠寘
 		try {
@@ -128,7 +177,7 @@
 		if (endTime != null && endTime.getTime() < now.getTime())
 			throw new RedPackGiveRecordException(1, "绾㈠寘宸插け鏁堜簡");
 		
-		giveRecord.setGiveUid(uid);
+		giveRecord.setReceiveUid(uid);
 		giveRecord.setReceiveTime(now);
 		giveRecord.setState(RedPackGiveRecord.STATE_RECEIVE);
 		// 棰嗗彇浜哄鍔犵孩鍖�

--
Gitblit v1.8.0