From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 二月 2025 16:41:22 +0800
Subject: [PATCH] 淘宝转链接口更新

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinNewbiesServiceImpl.java |  808 ++++++++++++++++++++++++++++++---------------------------
 1 files changed, 427 insertions(+), 381 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinNewbiesServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinNewbiesServiceImpl.java
index 694c0fd..9d0a2db 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinNewbiesServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/tlj/UserTaoLiJinNewbiesServiceImpl.java
@@ -1,381 +1,427 @@
-package com.yeshi.fanli.service.impl.tlj;
-
-import java.math.BigDecimal;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.annotation.Resource;
-
-import org.springframework.core.task.TaskExecutor;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import org.yeshi.utils.DateUtil;
-
-import com.yeshi.fanli.dao.mybatis.tlj.UserTaoLiJinNewbiesMapper;
-import com.yeshi.fanli.dto.taobao.TaoLiJinDTO;
-import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail;
-import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail.TaoLiJinDetailTypeEnum;
-import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinNewbies;
-import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
-import com.yeshi.fanli.entity.push.DeviceActive;
-import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
-import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
-import com.yeshi.fanli.exception.taobao.TaoKeApiException;
-import com.yeshi.fanli.exception.tlj.TaoLiJinCreateException;
-import com.yeshi.fanli.exception.tlj.UserTaoLiJinNewbiesException;
-import com.yeshi.fanli.log.LogHelper;
-import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
-import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
-import com.yeshi.fanli.service.inter.push.DeviceActiveService;
-import com.yeshi.fanli.service.inter.redpack.UserTaoLiJinNewbiesService;
-import com.yeshi.fanli.service.inter.taobao.TLJFreeBuyGoodsService;
-import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService;
-import com.yeshi.fanli.service.inter.tlj.ConfigTaoLiJinService;
-import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinDetailService;
-import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
-import com.yeshi.fanli.util.Constant;
-import com.yeshi.fanli.util.MoneyBigDecimalUtil;
-import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.TaoBaoConstant;
-import com.yeshi.fanli.util.annotation.RequestSerializableByKeyService;
-import com.yeshi.fanli.util.taobao.TaoBaoUtil;
-import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
-import com.yeshi.fanli.vo.redpack.TaoLiJinWinDetailVO;
-
-@Service
-public class UserTaoLiJinNewbiesServiceImpl implements UserTaoLiJinNewbiesService {
-
-	@Resource
-	private UserTaoLiJinNewbiesMapper userTaoLiJinNewbiesMapper;
-	
-	@Resource
-	private ConfigTaoLiJinService configTaoLiJinService;
-	
-	@Resource	
-	private UserInfoExtraService userInfoExtraService;
-	
-	@Resource
-	private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
-	
-	@Resource
-	private DeviceActiveService deviceActiveService;
-	
-	@Resource
-	private JumpDetailV2Service jumpDetailV2Service;
-	
-	@Resource(name = "taskExecutor")
-	private TaskExecutor executor;
-	
-	@Resource
-	private TLJFreeBuyGoodsService tljFreeBuyGoodsService;
-	
-	@Resource
-	private UserTaoLiJinDetailService userTaoLiJinDetailService;
-	
-	@Resource
-	private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService;
-	
-	
-	@Override
-	public boolean verifyHasReward(Long uid, String device) {
-		try {
-			if (StringUtil.isNullOrEmpty(device) && (uid == null || uid <= 0)) 
-				return false;
-			
-			if (uid == null || uid <= 0) {
-				DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(device);
-				if (deviceActive == null) 
-					return true; // 鏂拌澶囧脊鍑�
-				
-				Date nowTime = new Date();
-				Date createTime = deviceActive.getCreateTime();
-				int days = DateUtil.daysBetween2(createTime, nowTime);
-				if (days >= Constant.TLJ_NEW_USER_DAYS) {
-					return false; // 宸茬粡瓒呭嚭璁剧疆澶╂暟
-				}
-				return true; // 鏈秴杩囨椂闂�
-			}
-			
-			UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
-			if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null) 
-				return false;
-			
-			Date nowTime = new Date();
-			Date firstLoginTime = userInfoExtra.getFirstLoginTime();
-			int days = DateUtil.daysBetween2(firstLoginTime, nowTime);
-			if (days >= Constant.TLJ_NEW_USER_DAYS)
-				return false; // 宸茬粡瓒呭嚭璁剧疆澶╂暟
-			
-			UserTaoLiJinNewbies redPackWin = userTaoLiJinNewbiesMapper.selectByPrimaryKey(uid);
-			if (redPackWin != null) {
-				if (redPackWin.getMoney().compareTo(Constant.TLJ_NEW_USER_MONEY) >= 0)
-					return false; // 宸查鍙栧畬
-				
-				Date updateTime = redPackWin.getUpdateTime();
-				int daysNum = DateUtil.daysBetween2(updateTime, nowTime);
-				if (daysNum == 0) 
-					return false; // 浠婃棩宸查鍙�
-				
-				Integer num = redPackWin.getNum();
-				if (num >= Constant.TLJ_NEW_USER_DAYS) 
-					return false; // 棰嗗彇娆℃暟瓒呴檺
-			}
-			return true;
-		} catch (Exception e) {
-			LogHelper.errorDetailInfo(e);
-		}
-		return false;
-	}
-	
-	
-	
-	@RequestSerializableByKeyService(key = "#uid")
-	@Transactional(rollbackFor = Exception.class)
-	@Override
-	public TaoLiJinWinDetailVO receiveReward(Long uid) throws Exception {
-		if (uid == null || uid <= 0) 
-			return null; // 鏈櫥褰曞脊鍑�
-		
-		UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
-		if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null) 
-			return null;
-		
-		Date nowTime = new Date();
-		Date firstLoginTime = userInfoExtra.getFirstLoginTime();
-		int days = DateUtil.daysBetween2(firstLoginTime, nowTime);
-		if (days >= Constant.TLJ_NEW_USER_DAYS)
-			return null; // 宸茬粡瓒呭嚭璁剧疆澶╂暟
-		
-		UserTaoLiJinNewbies redPackWin = userTaoLiJinNewbiesMapper.selectForUpdate(uid);
-		if (redPackWin != null) {
-			if (redPackWin.getMoney().compareTo(Constant.TLJ_NEW_USER_MONEY) >= 0)
-				return null; // 宸查鍙栧畬
-			
-			Date updateTime = redPackWin.getUpdateTime();
-			int daysNum = DateUtil.daysBetween2(updateTime, nowTime);
-			if (daysNum == 0) 
-				return null; // 浠婃棩宸查鍙�
-			
-			Integer num = redPackWin.getNum();
-			if (num >= Constant.TLJ_NEW_USER_DAYS) 
-				return null; // 棰嗗彇娆℃暟瓒呴檺
-		}
-				
-		BigDecimal money = null;
-		if (redPackWin == null) { // 绗竴娆�
-			if (days == Constant.TLJ_NEW_USER_DAYS - 1) {  // 鏈�鍚庝竴澶�
-				money = Constant.TLJ_NEW_USER_MONEY;
-			} else { // 璁$畻闅忔満濂栧姳
-				double randomNum = Constant.TLJ_NEW_USER_MIN +  Math.random() * (Constant.TLJ_NEW_USER_MAX - Constant.TLJ_NEW_USER_MIN);
-				randomNum = randomNum/100;
-				BigDecimal rate = new BigDecimal(randomNum).setScale(2, BigDecimal.ROUND_DOWN);
-				money = MoneyBigDecimalUtil.mul(Constant.TLJ_NEW_USER_MONEY,rate);
-			}
-		} else if (days == Constant.TLJ_NEW_USER_DAYS - 1) { // 鏈�鍚庝竴澶�
-			money = MoneyBigDecimalUtil.sub(Constant.TLJ_NEW_USER_MONEY, redPackWin.getMoney());
-		} else { // 璁$畻鍓╀綑闅忔満濂栧姳 10%-25% 
-			double randomNum = 10 +  Math.random() * (20 - 10);
-			BigDecimal rate = new BigDecimal(randomNum/100).setScale(2, BigDecimal.ROUND_DOWN);
-			money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.sub(Constant.TLJ_NEW_USER_MONEY,redPackWin.getMoney()),rate);
-		}
-		
-		if (money.compareTo(new BigDecimal(0)) <= 0)
-			return null;
-		
-		money = money.setScale(2);
-		
-		int num = 1;
-		BigDecimal balance = null;
-		if (redPackWin == null) {
-			balance = money;
-			// 娉ㄥ唽寮�濮� 鏈夋晥鏈�
-			Date endDate = DateUtil.plusDayDate(Constant.TLJ_NEW_USER_LIMIT, firstLoginTime);
-			redPackWin = new UserTaoLiJinNewbies();
-			redPackWin.setId(uid);
-			redPackWin.setNum(1);
-			redPackWin.setMoney(money);
-			redPackWin.setEndTime(endDate);
-			redPackWin.setCreateTime(nowTime);
-			redPackWin.setUpdateTime(nowTime);
-			userTaoLiJinNewbiesMapper.insertSelective(redPackWin);
-		} else {
-			userTaoLiJinNewbiesMapper.addMoney(uid, money);
-			
-			num = redPackWin.getNum() + 1;
-			balance = MoneyBigDecimalUtil.add(money, redPackWin.getMoney());
-		}
-		
-		// 鏄庣粏
-		UserTaoLiJinDetail detail = new UserTaoLiJinDetail();
-		detail.setUid(uid);
-		detail.setMoney(money);
-		detail.setTitle(TaoLiJinDetailTypeEnum.add.getDesc());
-		detail.setType(TaoLiJinDetailTypeEnum.add);
-		detail.setCreateTime(new Date());
-		userTaoLiJinDetailService.insertSelective(detail);
-		
-		
-		Map<String,String> map = new HashMap<String,String>();
-		map.put("url", configTaoLiJinService.getValueByKey("new_user_free_buy_list"));
-		
-		TaoLiJinWinDetailVO winDetailVO = new TaoLiJinWinDetailVO();
-		winDetailVO.setTitle("鏂颁汉绾㈠寘");
-		winDetailVO.setBless("鎭枩浣狅紒宸查" + num + "/" + Constant.TLJ_NEW_USER_DAYS + "娆�");
-		winDetailVO.setMoney(money.toString());
-		winDetailVO.setDesc("宸查鍙栵細" + balance + "鍏�");
-		winDetailVO.setTips(configTaoLiJinService.getValueByKey("new_user_win_tips"));
-		winDetailVO.setParams(map.toString());
-		winDetailVO.setJumpDetail(jumpDetailV2Service.getByTypeCache("web"));
-		winDetailVO.setLogo(Constant.systemCommonConfig.getDefaultPortrait());
-		winDetailVO.setLogoLight(Constant.systemCommonConfig.getDefaultPortrait());
-		return winDetailVO;
-	}
-	
-	
-	@RequestSerializableByKeyService(key = "#uid")
-	@Transactional(rollbackFor = Exception.class)
-	@Override
-	public String createTaoLiJinForBuy(TaoBaoGoodsBrief goods, Long uid) throws UserTaoLiJinNewbiesException {
-		if (uid == null || uid <= 0 || goods == null) 
-			throw new UserTaoLiJinNewbiesException(1,"鍙傛暟淇℃伅缂哄け");
-		
-		if (goods == null || goods.getCouponAmount() == null || 
-				goods.getCouponAmount().compareTo(new BigDecimal(0)) == 0) {
-			executor.execute(new Runnable() {
-				@Override
-				public void run() {
-					tljFreeBuyGoodsService.deleteByGoodsId(goods.getId());
-				}
-			});
-			throw new UserTaoLiJinNewbiesException(1, "璇ュ晢鍝侀潪鍏嶅崟鍟嗗搧");
-		}
-		
-		BigDecimal money = TaoBaoUtil.getAfterUseCouplePrice(goods);
-		if (money.compareTo(new BigDecimal(1.0)) < 0 && money.compareTo(new BigDecimal(2.0)) > 0) {
-			executor.execute(new Runnable() {
-				@Override
-				public void run() {
-					tljFreeBuyGoodsService.deleteByGoodsId(goods.getId());
-				}
-			});
-			throw new UserTaoLiJinNewbiesException(1, "璇ュ晢鍝侀潪鍏嶅崟鍟嗗搧");
-		}
-		
-		UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
-		if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null)
-			throw new UserTaoLiJinNewbiesException(1001, "浣犱笉鏄�滄柊鐢ㄦ埛鈥濇棤娉曚娇鐢ㄦ柊浜虹孩鍖�0鍏冭喘涔般��");
-			
-		try {
-			int days = DateUtil.daysBetween2(userInfoExtra.getFirstLoginTime(), new Date());
-			if (days > Constant.TLJ_NEW_USER_DEFINE)
-				throw new UserTaoLiJinNewbiesException(1001, "浣犱笉鏄�滄柊鐢ㄦ埛鈥濇棤娉曚娇鐢ㄦ柊浜虹孩鍖�0鍏冭喘涔般��");
-		} catch (ParseException e1) {
-			throw new UserTaoLiJinNewbiesException(1, "鏃ユ湡淇℃伅璁$畻澶辫触");
-		}
-			
-		UserTaoLiJinNewbies taoLiJinNewbies = userTaoLiJinNewbiesMapper.selectForUpdate(uid);
-		if (taoLiJinNewbies == null || taoLiJinNewbies.getMoney() == null ||
-				taoLiJinNewbies.getMoney().compareTo(money)	< 0) 
-			throw new UserTaoLiJinNewbiesException(1001, "鏂颁汉绾㈠寘涓嶈冻锛岃鎹釜鍟嗗搧鍐嶈瘯鎴栫户缁鍙栧埌瓒抽鏂颁汉绾㈠寘銆�");
-		
-		if (taoLiJinNewbies.getEndTime() == null 
-				|| taoLiJinNewbies.getEndTime().getTime() < java.lang.System.currentTimeMillis())
-			throw new UserTaoLiJinNewbiesException(1, "鏂颁汉绾㈠寘宸茶繃鏈�");
-		
-		// 绾㈠寘鍑忓皯
-		userTaoLiJinNewbiesMapper.subMoney(uid, money);
-		
-		// 鍔犲叆鏄庣粏
-		UserTaoLiJinDetail detail = new UserTaoLiJinDetail();
-		detail.setUid(uid);
-		detail.setMoney(new BigDecimal("-" + money));
-		detail.setTitle(TaoLiJinDetailTypeEnum.reduce.getDesc());
-		detail.setType(TaoLiJinDetailTypeEnum.reduce);
-		detail.setCreateTime(new Date());
-		userTaoLiJinDetailService.insertSelective(detail);
-		
-		// 鍒涘缓娣樼ぜ閲戦摼鎺�
-		if (TaoBaoUtil.isSpecialGoods(goods.getMaterialLibType())) {
-			return createTaoLiJin(goods.getAuctionId(), money, 1, TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT);
-		} else { // 闈炶繑鍒╁簱鍟嗗搧
-			String relationId = null;
-			try {
-				relationId = taoBaoBuyRelationMapService.getRelationId(uid);
-			} catch (Exception e) {
-				LogHelper.errorDetailInfo(e, "uid:" + uid, null);
-			}
-
-			if (StringUtil.isNullOrEmpty(relationId))
-				throw new UserTaoLiJinNewbiesException(1, "娓犻亾鏈妗�");
-			
-			return createTaoLiJin(goods.getAuctionId(), money, 1, TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)
-					+ "&relationId=" + relationId;
-		}
-	}
-	
-	
-	@Transactional
-	private String createTaoLiJin(Long auctionId, BigDecimal perface, int totalNum, String pid) throws UserTaoLiJinNewbiesException {
-		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
-		SimpleDateFormat formatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-		
-		String name = "鏂颁汉鍏嶅崟璐�";
-		Date date = new Date();
-		String date_str = format.format(date);
-		String sendEndTime_str = date_str + " 22:00:00";
-		String useEndTime_str = date_str + " 23:59:59";
-		
-		// 鍙戞斁鏃堕棿
-		Date sendStartTime = date;
-		Date sendEndTime = null;
-		
-		// 浣跨敤鏃堕棿
-		Date useStartTime = null;
-		Date useEndTime = null;
-		try {
-			sendEndTime = formatStr.parse(sendEndTime_str);
-			useEndTime = formatStr.parse(useEndTime_str);
-		} catch (ParseException e2) {
-			e2.printStackTrace();
-		}
-	
-		// 鍒涘缓娣樼ぜ閲戠孩鍖�
-		TaoLiJinDTO taoLiJinDTO = null;
-		TaoKeAppInfo taoKeAppInfo = new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, pid);
-		try {
-			taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, name, perface, totalNum, sendStartTime,
-					sendEndTime, useStartTime, useEndTime, taoKeAppInfo);
-		} catch (TaoLiJinCreateException e) {
-			LogHelper.errorDetailInfo(e);
-			executor.execute(new Runnable() {
-				@Override
-				public void run() {
-					if (e.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) {
-						// 璇ュ晢鍝佷笉鏀寔鍒涘缓娣樼ぜ閲戠孩鍖�
-						tljFreeBuyGoodsService.deleteByGoodsId(auctionId);
-					} else if (e.getCode() == TaoLiJinCreateException.CODE_TLJ_NO_MONEY) {
-						// 瀹樻柟鐜╂硶閽卞寘浣欓涓嶈冻 TODO
-					}
-				}
-			});
-		} catch (TaoKeApiException e) {
-			LogHelper.errorDetailInfo(e);
-		}
-
-		if (taoLiJinDTO == null || StringUtil.isNullOrEmpty(taoLiJinDTO.getSendUrl()))
-			throw new UserTaoLiJinNewbiesException(1, "娣樺疂API绾㈠寘鍒涘缓澶辫触");
-		
-		return taoLiJinDTO.getSendUrl();
-	}
-
-	
-	
-	@Override
-	public UserTaoLiJinNewbies selectByPrimaryKey(Long uid) {
-		return userTaoLiJinNewbiesMapper.selectByPrimaryKey(uid);
-	}
-
-}
+package com.yeshi.fanli.service.impl.tlj;
+
+import java.math.BigDecimal;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import com.yeshi.fanli.entity.SystemEnum;
+import com.yeshi.fanli.entity.SystemPIDInfo;
+import com.yeshi.fanli.service.inter.config.SystemConfigService;
+import com.yeshi.fanli.service.manger.PIDManager;
+import org.springframework.core.task.TaskExecutor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.yeshi.utils.DateUtil;
+
+import com.yeshi.fanli.dao.mybatis.tlj.UserTaoLiJinNewbiesMapper;
+import com.yeshi.fanli.dto.taobao.TaoLiJinDTO;
+import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail;
+import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail.TaoLiJinDetailTypeEnum;
+import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinNewbies;
+import com.yeshi.fanli.entity.bus.user.UserInfo;
+import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
+import com.yeshi.fanli.entity.push.DeviceActive;
+import com.yeshi.fanli.entity.taobao.TLJFreeBuyGoods;
+import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.common.entity.taobao.TaoKeAppInfo;
+import com.yeshi.fanli.exception.taobao.TaoKeApiException;
+import com.yeshi.fanli.exception.tlj.TaoLiJinCreateException;
+import com.yeshi.fanli.exception.tlj.UserTaoLiJinNewbiesException;
+import com.yeshi.fanli.log.LogHelper;
+import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
+import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
+import com.yeshi.fanli.service.inter.push.DeviceActiveService;
+import com.yeshi.fanli.service.inter.redpack.UserTaoLiJinNewbiesService;
+import com.yeshi.fanli.service.inter.taobao.TLJFreeBuyGoodsService;
+import com.yeshi.fanli.service.inter.taobao.TaoBaoBuyRelationMapService;
+import com.yeshi.fanli.service.inter.tlj.ConfigTaoLiJinService;
+import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinDetailService;
+import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
+import com.yeshi.fanli.service.inter.user.UserInfoService;
+import com.yeshi.fanli.util.Constant;
+import org.yeshi.utils.MoneyBigDecimalUtil;
+import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.TaoBaoConstant;
+import org.yeshi.utils.TimeUtil;
+import com.yeshi.fanli.util.annotation.RequestSerializableByKeyService;
+import com.yeshi.fanli.util.taobao.TaoBaoUtil;
+import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
+import com.yeshi.fanli.vo.redpack.TaoLiJinWinDetailVO;
+
+import net.sf.json.JSONObject;
+
+@Service
+public class UserTaoLiJinNewbiesServiceImpl implements UserTaoLiJinNewbiesService {
+
+    @Resource
+    private UserTaoLiJinNewbiesMapper userTaoLiJinNewbiesMapper;
+
+    @Resource
+    private ConfigTaoLiJinService configTaoLiJinService;
+
+    @Resource
+    private UserInfoService userInfoService;
+
+    @Resource
+    private UserInfoExtraService userInfoExtraService;
+
+    @Resource
+    private DeviceActiveService deviceActiveService;
+
+    @Resource
+    private JumpDetailV2Service jumpDetailV2Service;
+
+    @Resource(name = "taskExecutor")
+    private TaskExecutor executor;
+
+    @Resource
+    private TLJFreeBuyGoodsService tljFreeBuyGoodsService;
+
+    @Resource
+    private UserTaoLiJinDetailService userTaoLiJinDetailService;
+
+    @Resource
+    private TaoBaoBuyRelationMapService taoBaoBuyRelationMapService;
+
+    @Resource
+    private PIDManager pidManager;
+
+
+
+    @Override
+    public boolean verifyHasReward(Long uid, String device) {
+        try {
+            if (StringUtil.isNullOrEmpty(device) && (uid == null || uid <= 0))
+                return false;
+
+            if (uid == null || uid <= 0) {
+                DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(device);
+                if (deviceActive == null)
+                    return true; // 鏂拌澶囧脊鍑�
+
+                Date nowTime = new Date();
+                Date createTime = deviceActive.getCreateTime();
+                int days = DateUtil.daysBetween2(createTime, nowTime);
+                if (days >= Constant.TLJ_NEW_USER_DAYS) {
+                    return false; // 宸茬粡瓒呭嚭璁剧疆澶╂暟
+                }
+                return true; // 鏈秴杩囨椂闂�
+            }
+
+            UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
+            if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null)
+                return false;
+
+            Date nowTime = new Date();
+            Date firstLoginTime = userInfoExtra.getFirstLoginTime();
+            int days = DateUtil.daysBetween2(firstLoginTime, nowTime);
+            if (days >= Constant.TLJ_NEW_USER_DAYS)
+                return false; // 宸茬粡瓒呭嚭璁剧疆澶╂暟
+
+            UserTaoLiJinNewbies redPackWin = userTaoLiJinNewbiesMapper.selectByPrimaryKey(uid);
+            if (redPackWin != null) {
+                if (redPackWin.getMoney().compareTo(Constant.TLJ_NEW_USER_MONEY) >= 0)
+                    return false; // 宸查鍙栧畬
+
+                Date updateTime = redPackWin.getUpdateTime();
+                int daysNum = DateUtil.daysBetween2(updateTime, nowTime);
+                if (daysNum == 0)
+                    return false; // 浠婃棩宸查鍙�
+
+                Integer num = redPackWin.getNum();
+                if (num >= Constant.TLJ_NEW_USER_DAYS)
+                    return false; // 棰嗗彇娆℃暟瓒呴檺
+            }
+            return true;
+        } catch (Exception e) {
+            LogHelper.errorDetailInfo(e);
+        }
+        return false;
+    }
+
+
+    @RequestSerializableByKeyService(key = "#uid")
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public TaoLiJinWinDetailVO receiveReward(Long uid) throws Exception {
+        if (uid == null || uid <= 0)
+            return null; // 鏈櫥褰曞脊鍑�
+
+        UserInfo userInfo = userInfoService.selectByPKey(uid);
+        if (userInfo == null)
+            return null;
+
+        UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
+        if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null)
+            return null;
+
+        Date nowTime = new Date();
+        Date firstLoginTime = userInfoExtra.getFirstLoginTime();
+        int days = DateUtil.daysBetween2(firstLoginTime, nowTime);
+        if (days >= Constant.TLJ_NEW_USER_DAYS)
+            return null; // 宸茬粡瓒呭嚭璁剧疆澶╂暟
+
+        UserTaoLiJinNewbies redPackWin = userTaoLiJinNewbiesMapper.selectForUpdate(uid);
+        if (redPackWin != null) {
+            if (redPackWin.getMoney().compareTo(Constant.TLJ_NEW_USER_MONEY) >= 0)
+                return null; // 宸查鍙栧畬
+
+            Date updateTime = redPackWin.getUpdateTime();
+            int daysNum = DateUtil.daysBetween2(updateTime, nowTime);
+            if (daysNum == 0)
+                return null; // 浠婃棩宸查鍙�
+
+            Integer num = redPackWin.getNum();
+            if (num >= Constant.TLJ_NEW_USER_DAYS)
+                return null; // 棰嗗彇娆℃暟瓒呴檺
+        }
+
+        BigDecimal money = null;
+        if (redPackWin == null) { // 绗竴娆�
+            if (days == Constant.TLJ_NEW_USER_DAYS - 1) {  // 鏈�鍚庝竴澶�
+                money = Constant.TLJ_NEW_USER_MONEY;
+            } else { // 璁$畻闅忔満濂栧姳
+                double randomNum = Constant.TLJ_NEW_USER_MIN + Math.random() * (Constant.TLJ_NEW_USER_MAX - Constant.TLJ_NEW_USER_MIN);
+                randomNum = randomNum / 100;
+                BigDecimal rate = new BigDecimal(randomNum).setScale(2, BigDecimal.ROUND_DOWN);
+                money = MoneyBigDecimalUtil.mul(Constant.TLJ_NEW_USER_MONEY, rate);
+            }
+        } else if (days == Constant.TLJ_NEW_USER_DAYS - 1) { // 鏈�鍚庝竴澶�
+            money = MoneyBigDecimalUtil.sub(Constant.TLJ_NEW_USER_MONEY, redPackWin.getMoney());
+        } else { // 璁$畻鍓╀綑闅忔満濂栧姳 10%-25%
+            double randomNum = 10 + Math.random() * (20 - 10);
+            BigDecimal rate = new BigDecimal(randomNum / 100).setScale(2, BigDecimal.ROUND_DOWN);
+            money = MoneyBigDecimalUtil.mul(MoneyBigDecimalUtil.sub(Constant.TLJ_NEW_USER_MONEY, redPackWin.getMoney()), rate);
+        }
+
+        if (money.compareTo(new BigDecimal(0)) <= 0)
+            return null;
+
+        money = money.setScale(2);
+
+        int num = 1;
+        BigDecimal balance = null;
+        if (redPackWin == null) {
+            balance = money;
+            // 娉ㄥ唽寮�濮� 鏈夋晥鏈�
+            Date endDate = DateUtil.plusDayDate(Constant.TLJ_NEW_USER_LIMIT, firstLoginTime);
+            redPackWin = new UserTaoLiJinNewbies();
+            redPackWin.setId(uid);
+            redPackWin.setNum(1);
+            redPackWin.setMoney(money);
+            redPackWin.setEndTime(endDate);
+            redPackWin.setCreateTime(nowTime);
+            redPackWin.setUpdateTime(nowTime);
+            userTaoLiJinNewbiesMapper.insertSelective(redPackWin);
+        } else {
+            userTaoLiJinNewbiesMapper.addMoney(uid, money);
+
+            num = redPackWin.getNum() + 1;
+            balance = MoneyBigDecimalUtil.add(money, redPackWin.getMoney());
+        }
+
+        // 鏄庣粏
+        UserTaoLiJinDetail detail = new UserTaoLiJinDetail();
+        detail.setUid(uid);
+        detail.setMoney(money);
+        detail.setTitle(TaoLiJinDetailTypeEnum.add.getDesc());
+        detail.setType(TaoLiJinDetailTypeEnum.add);
+        detail.setCreateTime(new Date());
+        detail.setRemark("鏂颁汉绾㈠寘");
+        userTaoLiJinDetailService.insertSelective(detail);
+
+        JSONObject json = new JSONObject();
+        json.put("url", configTaoLiJinService.getValueByKey("new_user_free_buy_list"));
+
+        TaoLiJinWinDetailVO winDetailVO = new TaoLiJinWinDetailVO();
+        winDetailVO.setTitle("鏂颁汉绾㈠寘");
+        winDetailVO.setBless("鎭枩浣狅紒宸查" + num + "/" + Constant.TLJ_NEW_USER_DAYS + "娆�");
+        winDetailVO.setMoney(money.toString());
+        winDetailVO.setDesc("宸查鍙栵細" + balance + "鍏�");
+        winDetailVO.setTips(configTaoLiJinService.getValueByKey("new_user_win_tips"));
+        winDetailVO.setParams(json.toString());
+        winDetailVO.setJumpDetail(jumpDetailV2Service.getByTypeCache("web",userInfo.getSystem()));
+        winDetailVO.setLogo(userInfoService.getDefaultPortrait(userInfo.getSystem()));
+        winDetailVO.setLogoLight(userInfo.getPortrait());
+        return winDetailVO;
+    }
+
+
+    @RequestSerializableByKeyService(key = "#uid")
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public String createTaoLiJinForBuy(TaoBaoGoodsBrief goods, Long uid) throws UserTaoLiJinNewbiesException {
+        if (uid == null || uid <= 0 || goods == null)
+            throw new UserTaoLiJinNewbiesException(1, "鍙傛暟淇℃伅缂哄け");
+
+        // 楠岃瘉鍟嗗搧鏄惁鍦ㄥ厤鍗曞晢鍝佸簱
+        TLJFreeBuyGoods tljFreeBuyGoods = tljFreeBuyGoodsService.selectByAuctionIdAndDay(goods.getAuctionId(),
+                TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd"));
+        if (tljFreeBuyGoods == null)
+            throw new UserTaoLiJinNewbiesException(1, "璇ュ晢鍝侀潪鍏嶅崟鍟嗗搧");
+
+        // 楠岃瘉鏄惁鏈夊埜
+        if (goods == null || goods.getCouponAmount() == null ||
+                goods.getCouponAmount().compareTo(new BigDecimal(0)) <= 0) {
+            executor.execute(new Runnable() {
+                @Override
+                public void run() {
+                    tljFreeBuyGoodsService.deleteByGoodsId(goods.getAuctionId());
+                }
+            });
+            throw new UserTaoLiJinNewbiesException(1, "璇ュ晢鍝侀潪鍏嶅崟鍟嗗搧");
+        }
+
+        // 楠岃瘉鍒稿悗浠� 鏄惁鍦� 1-2鍏�
+        BigDecimal money = TaoBaoUtil.getCouponPrice(goods);
+        if (money.compareTo(new BigDecimal(1.0)) < 0 || money.compareTo(new BigDecimal(2.0)) > 0) {
+            executor.execute(new Runnable() {
+                @Override
+                public void run() {
+                    tljFreeBuyGoodsService.deleteByGoodsId(goods.getAuctionId());
+                }
+            });
+            throw new UserTaoLiJinNewbiesException(1, "璇ュ晢鍝侀潪鍏嶅崟鍟嗗搧");
+        }
+
+        // 楠岃瘉鐢ㄦ埛淇℃伅
+        UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
+        if (userInfoExtra == null || userInfoExtra.getFirstLoginTime() == null)
+            throw new UserTaoLiJinNewbiesException(1001, "浣犱笉鏄�滄柊鐢ㄦ埛鈥濇棤娉曚娇鐢ㄦ柊浜虹孩鍖�0鍏冭喘涔般��");
+
+        // 楠岃瘉鏄惁婵�娲�
+        if (StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode()))
+            throw new UserTaoLiJinNewbiesException(1002, "閭�璇风爜鏈縺娲伙紝鏃犳硶浣跨敤鏂颁汉绾㈠寘0鍏冭喘涔般��");
+
+        // 楠岃瘉鏄惁宸茶秴鍑烘柊鐢ㄦ埛瀹氫箟
+        try {
+            int days = DateUtil.daysBetween2(userInfoExtra.getFirstLoginTime(), new Date());
+            if (days > Constant.TLJ_NEW_USER_DEFINE)
+                throw new UserTaoLiJinNewbiesException(1001, "浣犱笉鏄�滄柊鐢ㄦ埛鈥濇棤娉曚娇鐢ㄦ柊浜虹孩鍖�0鍏冭喘涔般��");
+        } catch (ParseException e1) {
+            throw new UserTaoLiJinNewbiesException(1, "鏃ユ湡淇℃伅璁$畻澶辫触");
+        }
+
+        // 楠岃瘉浣欓
+        UserTaoLiJinNewbies taoLiJinNewbies = userTaoLiJinNewbiesMapper.selectForUpdate(uid);
+        if (taoLiJinNewbies == null || taoLiJinNewbies.getMoney() == null ||
+                taoLiJinNewbies.getMoney().compareTo(money) < 0)
+            throw new UserTaoLiJinNewbiesException(1001, "鏂颁汉绾㈠寘涓嶈冻锛岃鎹釜鍟嗗搧鍐嶈瘯鎴栫户缁鍙栧埌瓒抽鏂颁汉绾㈠寘銆�");
+
+        // 楠岃瘉鏄惁宸茶繃鏈�
+        if (taoLiJinNewbies.getEndTime() == null
+                || taoLiJinNewbies.getEndTime().getTime() < java.lang.System.currentTimeMillis())
+            throw new UserTaoLiJinNewbiesException(1, "鏂颁汉绾㈠寘宸茶繃鏈�");
+
+        // 绾㈠寘鍑忓皯
+        userTaoLiJinNewbiesMapper.subMoney(uid, money);
+
+        // 鍔犲叆鏄庣粏
+        UserTaoLiJinDetail detail = new UserTaoLiJinDetail();
+        detail.setUid(uid);
+        detail.setMoney(new BigDecimal("-" + money));
+        detail.setTitle(TaoLiJinDetailTypeEnum.reduce.getDesc());
+        detail.setType(TaoLiJinDetailTypeEnum.reduce);
+        detail.setCreateTime(new Date());
+        detail.setRemark("鏂颁汉鍏嶅崟浣跨敤绾㈠寘");
+        userTaoLiJinDetailService.insertSelective(detail);
+
+
+        String specialId = pidManager.getPid(SystemEnum.blks, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanli);
+        String specialRelationIdId = pidManager.getPid(SystemEnum.blks, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel);
+
+
+        // 鍒涘缓娣樼ぜ閲戦摼鎺�
+        if (TaoBaoUtil.isSpecialGoods(goods.getMaterialLibType())) {
+            return createTaoLiJin(goods.getAuctionId(), money, 1, specialId);
+        } else { // 闈炶繑鍒╁簱鍟嗗搧
+            String relationId = null;
+            try {
+                relationId = taoBaoBuyRelationMapService.getRelationId(uid);
+            } catch (Exception e) {
+                LogHelper.errorDetailInfo(e, "uid:" + uid, null);
+            }
+
+            if (StringUtil.isNullOrEmpty(relationId))
+                throw new UserTaoLiJinNewbiesException(1, "娓犻亾鏈妗�");
+
+            return createTaoLiJin(goods.getAuctionId(), money, 1, specialRelationIdId)
+                    + "&relationId=" + relationId;
+        }
+    }
+
+
+    private String createTaoLiJin(String auctionId, BigDecimal perface, int totalNum, String pid) throws UserTaoLiJinNewbiesException {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        SimpleDateFormat formatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+        String name = "鏂颁汉鍏嶅崟璐�";
+        Date date = new Date();
+        String date_str = format.format(date);
+        String sendEndTime_str = date_str + " 22:00:00";
+        String useEndTime_str = date_str + " 23:59:59";
+
+        // 鍙戞斁鏃堕棿
+        Date sendStartTime = date;
+        Date sendEndTime = null;
+
+        // 浣跨敤鏃堕棿
+        Date useStartTime = null;
+        Date useEndTime = null;
+        try {
+            sendEndTime = formatStr.parse(sendEndTime_str);
+            useEndTime = formatStr.parse(useEndTime_str);
+        } catch (ParseException e2) {
+            e2.printStackTrace();
+        }
+
+        // 鍒涘缓娣樼ぜ閲戠孩鍖�
+        TaoLiJinDTO taoLiJinDTO = null;
+        TaoKeAppInfo taoKeAppInfo = new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, pid);
+        try {
+            taoLiJinDTO = TaoKeApiUtil.createTaoLiJin(auctionId, name, perface, totalNum, sendStartTime,
+                    sendEndTime, useStartTime, useEndTime, taoKeAppInfo);
+        } catch (TaoLiJinCreateException e) {
+            LogHelper.errorDetailInfo(e);
+            executor.execute(new Runnable() {
+                @Override
+                public void run() {
+                    if (e.getCode() == TaoLiJinCreateException.CODE_TLJ_FORBIDDEN) {
+                        // 璇ュ晢鍝佷笉鏀寔鍒涘缓娣樼ぜ閲戠孩鍖�
+                        tljFreeBuyGoodsService.deleteByGoodsId(auctionId);
+                    } else if (e.getCode() == TaoLiJinCreateException.CODE_TLJ_NO_MONEY) {
+                        // 瀹樻柟鐜╂硶閽卞寘浣欓涓嶈冻 TODO
+                    }
+                }
+            });
+        } catch (TaoKeApiException e) {
+            LogHelper.errorDetailInfo(e);
+        }
+
+        if (taoLiJinDTO == null || StringUtil.isNullOrEmpty(taoLiJinDTO.getSendUrl()))
+            throw new UserTaoLiJinNewbiesException(1, "娣樺疂API绾㈠寘鍒涘缓澶辫触");
+
+        return taoLiJinDTO.getSendUrl();
+    }
+
+
+    @Override
+    public UserTaoLiJinNewbies selectByPrimaryKey(Long uid) {
+        return userTaoLiJinNewbiesMapper.selectByPrimaryKey(uid);
+    }
+
+
+    @Override
+    public long count(String key) {
+        return userTaoLiJinNewbiesMapper.count(key);
+    }
+
+    @Override
+    public List<UserTaoLiJinNewbies> query(int page, int count, String key, Integer order) {
+        return userTaoLiJinNewbiesMapper.query((page - 1) * count, count, key, order);
+    }
+}

--
Gitblit v1.8.0