From 3f7c35dcb3bd703fcb952bb1a7d3ba5088d87b54 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 30 十月 2019 15:13:00 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/redpack/RedPackGiveRecordServiceImpl.java |   63 ++++++++++++++++++++++++++++++-
 1 files changed, 61 insertions(+), 2 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 1fe1d30..ba6dcc6 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
@@ -12,14 +12,17 @@
 import com.yeshi.fanli.dao.mybatis.redpack.RedPackGiveRecordMapper;
 import com.yeshi.fanli.entity.bus.user.TokenRecord;
 import com.yeshi.fanli.entity.bus.user.TokenRecord.TokenTypeEnum;
+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.redpack.RedPackBalanceService;
 import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
+import com.yeshi.fanli.service.inter.redpack.RedPackDetailService;
 import com.yeshi.fanli.service.inter.redpack.RedPackGiveRecordService;
 import com.yeshi.fanli.service.inter.user.TokenRecordService;
 import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.TokenUtil;
 import com.yeshi.fanli.util.factory.RedPackDetailFactory;
 
@@ -38,6 +41,22 @@
 	
 	@Resource
 	private TokenRecordService tokenRecordService;
+	
+	@Resource
+	private RedPackDetailService redPackDetailService;
+	
+	
+	@Override
+	public RedPackGiveRecord selectByPrimaryKey(Long id) {
+		return redPackGiveRecordMapper.selectByPrimaryKey(id);
+	}
+	
+	@Override
+	public void updateByPrimaryKeySelective(RedPackGiveRecord record) {
+		redPackGiveRecordMapper.updateByPrimaryKeySelective(record);
+	}
+	
+	
 	
 	@Override
 	@Transactional(rollbackFor = Exception.class)
@@ -85,14 +104,54 @@
 			tips = tips.replace("{APP鍚嶇О}", projectChineseName);
 		}
 		tips = tips.replace("{鍙d护}", token).replace("{涓嬭浇閾炬帴}", redPackConfigService.getValueByKey("app_down_link")).replace("{闈㈤}",
-				amount.setScale(0).toString());
+				amount.toString());
 		
 		// 鍑忓皯绾㈠寘
 		try {
-			redPackBalanceService.subRedPack(uid, amount, RedPackDetailFactory.createGiveOthers(giveRecord, null, RedPackDetailTypeEnum.giveOthers));
+			redPackBalanceService.subRedPack(uid, amount, RedPackDetailFactory.createGiveOthers(giveRecord));
 		} catch (Exception e) {
 			throw new RedPackGiveRecordException(1, "绾㈠寘鍒涘缓澶辫触");
 		}
 		return tips;
 	}
+	
+	
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public RedPackGiveRecord receiveFriendsGive(Long uid, Long id) throws RedPackGiveRecordException{
+		RedPackGiveRecord giveRecord = redPackGiveRecordMapper.selectByPrimaryKey(id);
+		if (giveRecord == null || giveRecord.getState() != RedPackGiveRecord.STATE_INIT)
+			throw new RedPackGiveRecordException(1, "璧犻�佽褰曞け鏁堟垨宸茶棰嗗彇");
+	
+		Date now = new Date();
+		Date endTime = giveRecord.getEndTime();
+		if (endTime != null && endTime.getTime() < now.getTime())
+			throw new RedPackGiveRecordException(1, "绾㈠寘宸插け鏁堜簡");
+		
+		giveRecord.setGiveUid(uid);
+		giveRecord.setReceiveTime(now);
+		giveRecord.setState(RedPackGiveRecord.STATE_RECEIVE);
+		// 棰嗗彇浜哄鍔犵孩鍖�
+		try {
+			redPackBalanceService.addRedPack(uid, giveRecord.getAmount(), RedPackDetailFactory.createGiveOthersReceive(giveRecord));
+		} catch (Exception e) {
+			throw new RedPackGiveRecordException(1, "绾㈠寘棰嗗彇澶辫触");
+		}		
+		
+		// 鏇存柊璧犻�佽褰�
+		redPackGiveRecordMapper.updateByPrimaryKey(giveRecord);
+		
+		try {
+			String identifyCode = StringUtil.Md5(RedPackDetailTypeEnum.giveOthers.name() + ":" + giveRecord.getId());
+			RedPackDetail redPackDetail = redPackDetailService.getByIdentifyCode(identifyCode);
+			
+			RedPackDetail updateDetail = RedPackDetailFactory.createGiveOthersSucceed(redPackDetail.getId(), giveRecord);
+			redPackDetailService.updateByPrimaryKeySelective(updateDetail);
+		} catch (Exception e) {
+			throw new RedPackGiveRecordException(1,"鏇存柊鎻愮幇鏄庣粏鍑洪敊");
+		}
+		return giveRecord;
+	}
+
+	
 }

--
Gitblit v1.8.0