From 69bee82b81626b82b7f39f0e459e4f56b1699b51 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 13 三月 2019 12:02:16 +0800
Subject: [PATCH] 正式数据库修改

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoServiceImpl.java |  180 +++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 100 insertions(+), 80 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoServiceImpl.java
index a6a4b69..bb37e7b 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoServiceImpl.java
@@ -22,6 +22,9 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
+import org.yeshi.utils.HttpUtil;
+import org.yeshi.utils.NumberUtil;
+import org.yeshi.utils.tencentcloud.COSManager;
 
 import com.google.gson.Gson;
 import com.yeshi.fanli.dao.mybatis.BindingAccountMapper;
@@ -37,9 +40,10 @@
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.entity.bus.user.WeiXinUser;
 import com.yeshi.fanli.entity.system.System;
+import com.yeshi.fanli.exception.ThreeSaleException;
 import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.service.inter.config.ConfigService;
-import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
+import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
 import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
 import com.yeshi.fanli.service.inter.user.UserInfoService;
 import com.yeshi.fanli.util.Constant;
@@ -49,9 +53,6 @@
 import com.yeshi.fanli.util.Utils;
 import com.yeshi.fanli.util.account.UserUtil;
 import com.yeshi.fanli.util.wx.WXLoginUtil;
-import org.yeshi.utils.HttpUtil;
-import org.yeshi.utils.NumberUtil;
-import org.yeshi.utils.tencentcloud.COSManager;
 
 @Service
 public class UserInfoServiceImpl implements UserInfoService {
@@ -63,9 +64,6 @@
 	private UserInfoService userInfoService;
 
 	@Resource
-	private HongBaoService hongBaoService;
-
-	@Resource
 	private ConfigService configService;
 
 	@Resource
@@ -73,23 +71,24 @@
 
 	@Resource
 	private UserInfoMapper userInfoMapper;
-	
+
 	@Resource
 	private BindingAccountMapper bindingAccountMapper;
-	
+
 	@Resource
 	private PayInfoMapper payInfoMapper;
-	
+
 	@Resource
 	private UserShareGoodsHistoryMapper userShareGoodsHistoryMapper;
-	
+
 	@Resource
 	private ScanHistoryMapper scanHistoryMapper;
-	
+
 	@Resource
 	private ShareMapper shareMapper;
-	
-	
+
+	@Resource
+	private HongBaoV2CountService hongBaoV2CountService;
 
 	public UserInfo getUserByLoginTypeAndOpenId(int loginType, String openid, String appid) {
 		List<UserInfo> list = null;
@@ -100,6 +99,16 @@
 			list = userInfoDao.list("from UserInfo u where u.wxUnionId=? and u.appId = ? ",
 					new Serializable[] { openid, appid });
 		}
+
+		if (list != null)
+			for (int i = 0; i < list.size(); i++) {
+				if (list.get(i).getState() == UserInfo.STATE_DELETE
+						|| list.get(i).getState() == UserInfo.STATE_DELETE_OUT_OF_DATE) {
+					list.remove(i);
+					i--;
+				}
+			}
+
 		if (list != null && list.size() > 0) {
 			return list.get(0);
 		}
@@ -146,8 +155,6 @@
 				return form;
 			}
 
-			if (form.getSystem().getId() != 7)
-				hongBaoService.setNewUserHongBao(form, 1);
 			LogHelper.userInfo("娣诲姞鐢ㄦ埛:" + form);
 			if (form.getLoginType() == Constant.WEIXIN) {
 				// final UserInfo temp = form;
@@ -420,13 +427,15 @@
 		}
 		String wxUnionId = weiXinUser.getUnionid();
 		UserInfo find = getUserByLoginTypeAndOpenId(Constant.WEIXIN, wxUnionId, Constant.APPID);
+
 		if (find == null) {
 			find = new UserInfo();
 			find.setAppId(Constant.APPID);
 			find.setWxUnionId(weiXinUser.getUnionid());
-			String wxHeadImg = COSManager.getInstance().uploadFile(
-					HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl()),
-					Constant.WXHEADURL + UUID.randomUUID().toString()).getUrl();
+			String wxHeadImg = COSManager.getInstance()
+					.uploadFile(HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl()),
+							Constant.WXHEADURL + UUID.randomUUID().toString())
+					.getUrl();
 			find.setPortrait(wxHeadImg);
 			find.setWxPic(wxHeadImg);
 			find.setNickName(weiXinUser.getNickname());
@@ -437,17 +446,15 @@
 			System system = new System(Constant.FANLI);
 			system.setPlatform(1);
 			find.setSystem(system);
-			UserInfo addUser = null;
-			synchronized (UserInfo.class) {
-				addUser = addUser(find, Constant.APPID);
-				if (addUser != null && addUser.getId() > 1) {
-					threeSaleSerivce.bind(find, inviter);
-					return true;
-				}
-			}
 		}
 
-		return false;
+		try {
+			threeSaleSerivce.bind(find, inviter);
+			return true;
+		} catch (ThreeSaleException e) {
+			e.printStackTrace();
+			return false;
+		}
 	}
 
 	@Transactional
@@ -551,7 +558,8 @@
 				public List<InviteUser> doInHibernate(Session session) throws HibernateException {
 					List list = session
 							.createSQLQuery(
-									"SELECT u.id,u.`nick_name`,u.`portrait`,uu.state FROM (SELECT t.* FROM `yeshi_ec_threesale` t  WHERE t.`boss_id`=? ORDER BY t.createTime DESC) uu LEFT JOIN yeshi_ec_user u ON u.`id`=uu.worker_id")
+									"SELECT u.id,u.`nick_name`,u.`portrait`,uu.state FROM (SELECT t.* FROM `yeshi_ec_threesale` t  "
+											+ "WHERE t.`boss_id`=? AND (t.expire = 0  OR  t.expire IS NULL) ORDER BY t.createTime DESC) uu LEFT JOIN yeshi_ec_user u ON u.`id`=uu.worker_id")
 							.setParameter(0, id).setFirstResult((page - 1) * pageSize).setMaxResults(pageSize).list();
 					return covertToInviteUserList(list);
 				}
@@ -562,7 +570,8 @@
 				public List<InviteUser> doInHibernate(Session session) throws HibernateException {
 					List list = session
 							.createSQLQuery(
-									"SELECT u.id,u.`nick_name`,u.`portrait`,uu.state FROM (SELECT tt.* FROM `yeshi_ec_threesale` t  LEFT JOIN yeshi_ec_threesale tt ON tt.`boss_id`=t.`worker_id`  WHERE t.`boss_id`=? AND tt.`id` IS NOT NULL ORDER BY tt.createTime DESC) uu LEFT JOIN yeshi_ec_user u ON u.`id`=uu.worker_id")
+									"SELECT u.id,u.`nick_name`,u.`portrait`,uu.state FROM (SELECT tt.* FROM `yeshi_ec_threesale` t  LEFT JOIN yeshi_ec_threesale tt ON tt.`boss_id`=t.`worker_id` "
+											+ " WHERE t.`boss_id`=? AND tt.`id` IS NOT NULL AND (tt.expire = 0  OR  tt.expire IS NULL) ORDER BY tt.createTime DESC) uu LEFT JOIN yeshi_ec_user u ON u.`id`=uu.worker_id")
 							.setParameter(0, id).setFirstResult((page - 1) * pageSize).setMaxResults(pageSize).list();
 					return covertToInviteUserList(list);
 				}
@@ -596,12 +605,12 @@
 	@Override
 	public long getFriendsListCount(long id, int type) {
 		if (type == 1)
-			return userInfoDao
-					.getCountSQL("SELECT COUNT(t.`id`) FROM `yeshi_ec_threesale` t  WHERE t.`boss_id`=  " + id);
+			return userInfoDao.getCountSQL("SELECT COUNT(t.`id`) FROM `yeshi_ec_threesale` t  WHERE t.`boss_id`=  " + id
+					+ " AND (t.expire = 0  OR  t.expire IS NULL)");
 		else
 			return userInfoDao.getCountSQL(
 					"SELECT COUNT(tt.id) FROM `yeshi_ec_threesale` t  LEFT JOIN yeshi_ec_threesale tt ON tt.`boss_id`=t.`worker_id`  WHERE t.`boss_id`="
-							+ id + " AND tt.`id` IS NOT NULL");
+							+ id + " AND tt.`id` IS NOT NULL AND (tt.expire = 0  OR  tt.expire IS NULL)");
 	}
 
 	@Override
@@ -616,19 +625,18 @@
 
 	@Override
 	public UserInfo getUserByIdWithMybatis(long uid) {
-		UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
+		UserInfo user = userInfoMapper.selectByPKey(uid);
 		return UserUtil.filterForClientUser(user);
 	}
 
-
 	@Override
-	public List<UserInfoAdmin> query(long start, int count, String key, Integer userType, 
-			Integer days, String startTime, String endTime, Integer orderField,Integer orderMode) {
+	public List<UserInfoAdmin> query(long start, int count, String key, Integer userType, Integer days,
+			String startTime, String endTime, Integer orderField, Integer orderMode) {
 
 		List<UserInfoAdmin> adminList = new ArrayList<UserInfoAdmin>();
 
-		List<UserInfo> userList = userInfoMapper.query(start, count, key, userType, days,
-				startTime, endTime, orderField,orderMode);
+		List<UserInfo> userList = userInfoMapper.query(start, count, key, userType, days, startTime, endTime,
+				orderField, orderMode);
 		if (userList == null || userList.size() == 0) {
 			return null;
 		}
@@ -636,37 +644,34 @@
 		for (UserInfo userInfo : userList) {
 
 			UserInfoAdmin userInfoAdmin = new UserInfoAdmin();
-			
+
 			Long lastLoginTime = userInfo.getLastLoginTime();
 			if (lastLoginTime == null) {
 				userInfo.setLastLoginTime(0L);
-			} 
-			
-			
+			}
+
 			userInfoAdmin.setUserInfo(userInfo);
-			
+
 			String wxName = userInfo.getWxName();
 			if (StringUtil.isNullOrEmpty(wxName)) {
 				userInfoAdmin.setWxNameState(1);
 			} else {
 				userInfoAdmin.setWxNameState(2);
 			}
-			
+
 			String phone = userInfo.getPhone();
 			if (StringUtil.isNullOrEmpty(phone)) {
 				userInfoAdmin.setPhoneState(1);
 			} else {
 				userInfoAdmin.setPhoneState(2);
 			}
-			
+
 			String tbName = userInfo.getTbName();
 			if (StringUtil.isNullOrEmpty(tbName)) {
 				userInfoAdmin.setTbNameState(1);
 			} else {
 				userInfoAdmin.setTbNameState(2);
 			}
-			
-			
 
 			Long uid = userInfo.getId();
 
@@ -680,7 +685,7 @@
 					userInfoAdmin.setAccountAlipay(bindingAccount.getAccount());
 					userInfoAdmin.setAccountName(bindingAccount.getName());
 					userInfoAdmin.setAccountBindId(bindingAccount.getId());
-					
+
 				} else if (type != null && type == 2) {
 					// 寰俊
 					userInfoAdmin.setAccountWX(bindingAccount.getAccount());
@@ -688,58 +693,62 @@
 					userInfoAdmin.setAccountBindIdWX(bindingAccount.getId());
 				}
 			}
-			
-			
+
 			// 鏈�鍚庝竴娆′笅鍗曟椂闂�
-			Long lastOrderTime = hongBaoService.getLastOrderTime(uid);
+			Date lastOrderTime = hongBaoV2CountService.getLastHongBaoTime(uid);
 			if (lastOrderTime == null) {
 				userInfoAdmin.setLastOrderTime(0);
 			} else {
-				userInfoAdmin.setLastOrderTime(lastOrderTime);
+				userInfoAdmin.setLastOrderTime(lastOrderTime.getTime());
 			}
-			
-			
+
 			// 鍘嗗彶鎬昏鍗�
-			long totalOrder = hongBaoService.countByUidSelf(uid, null, null);
+			long totalOrder = hongBaoV2CountService.countValidNumberByUid(uid, null);
+
 			// 浠婃棩鎬昏鍗�
-			long todayOrder = hongBaoService.countByUidSelf(uid, 1, null);
+			long todayOrder = hongBaoV2CountService.countValidNumberByUid(uid, 1);
 			// 鏈湀鎬昏鍗�
-			long monthOrder = hongBaoService.countByUidSelf(uid, null, 1);
+			long monthOrder = hongBaoV2CountService.countValidNumberByUid(uid, 2);
 
 			userInfoAdmin.setTotalOrder(totalOrder);
 			userInfoAdmin.setTodayOrder(todayOrder);
 			userInfoAdmin.setMonthOrder(monthOrder);
 
+			// 鏈鍙栫孩鍖� 寰呭叆璐﹂噾棰�
+			BigDecimal unaccountedMoney = hongBaoV2CountService.countWillGetMoneyByUid(uid);
+			if (unaccountedMoney == null) {
+				unaccountedMoney = new BigDecimal(0);
+			}
+			userInfoAdmin.setUnaccountedMoney(unaccountedMoney.toString());
+
+			// 鍘嗗彶鎬绘敹鐩�
+			BigDecimal totalMoneyHistory = hongBaoV2CountService.countMoneyByUidAndState(uid, 3);
+			if (totalMoneyHistory == null) {
+				totalMoneyHistory = new BigDecimal(0);
+			}
+			userInfoAdmin.setTotalMoneyHistory(totalMoneyHistory.toString());
+
 			// 鏀粯瀹濊处鍙� 绱杞处鎬婚噾棰�
 			double totalMoney = payInfoMapper.sumMoneyByUid(uid);
 			userInfoAdmin.setTotalMoney(totalMoney);
-			
-			// 绱鎻愮幇    (鏆傛湭璁″叆寰俊)
+
+			// 绱鎻愮幇 (鏆傛湭璁″叆寰俊)
 			userInfoAdmin.setTotalExtract(totalMoney);
 
-			// 鏈鍙栫孩鍖� 寰呭叆璐﹂噾棰�
-			double unaccountedMoney = hongBaoService.countForecastMoneysByUid(uid);
-			userInfoAdmin.setUnaccountedMoney(unaccountedMoney);
-
-			// 鍘嗗彶鎬绘敹鐩�
-			double totalMoneyHistory = hongBaoService.countReceiveMoneysByUid(uid);
-			userInfoAdmin.setTotalMoneyHistory(totalMoneyHistory);
-			
-			
 			// 缁熻鍒嗕韩涓暟
 			long countUserShares = userShareGoodsHistoryMapper.countUserShares(uid);
 			userInfoAdmin.setCountUserShares(countUserShares);
-			
+
 			// 缁熻娴忚瓒宠抗
 			long countScanHistory = scanHistoryMapper.countUserScanHistory(uid);
 			userInfoAdmin.setCountScanHistory(countScanHistory);
-			
+
 			// 涓�搴﹂槦鍛樻暟閲�
-			int firstTeamCount = shareMapper.myFirstTeamCount(uid +"");
+			int firstTeamCount = shareMapper.myFirstTeamCount(uid + "");
 			userInfoAdmin.setCountLevelOne(firstTeamCount);
-			
+
 			// 浜屽害闃熷憳鏁伴噺
-			int secondTeamCount = shareMapper.mySecondTeamCount(uid +"");
+			int secondTeamCount = shareMapper.mySecondTeamCount(uid + "");
 			userInfoAdmin.setCountLevelTwo(secondTeamCount);
 			adminList.add(userInfoAdmin);
 		}
@@ -752,7 +761,7 @@
 	public long queryCount(String key, Integer userType, Integer days, String startTime, String endTime) {
 		return userInfoMapper.queryCount(key, userType, days, startTime, endTime);
 	}
-	
+
 	@Override
 	public double querySumMoney(String key, Integer userType, Integer days, String startTime, String endTime) {
 		return userInfoMapper.querySumMoney(key, userType, days, startTime, endTime);
@@ -762,12 +771,12 @@
 	public UserInfo selectByPKey(Long id) {
 		return userInfoMapper.selectByPKey(id);
 	}
-	
+
 	@Override
 	public int updateByPrimaryKeySelective(UserInfo record) {
 		return userInfoMapper.updateByPrimaryKeySelective(record);
 	}
-	
+
 	@Override
 	@Transactional
 	public void deleteBindInfo(UserInfo user, int type) {
@@ -796,11 +805,22 @@
 
 		userInfoMapper.updateByPrimaryKeySelective(user);
 	}
-	
-	
+
 	@Override
-	public List<Long> longTimeNoLogin(int daysNum, List<Long> list ) {
+	public List<Long> longTimeNoLogin(int daysNum, List<Long> list) {
 		return userInfoMapper.longTimeNoLogin(daysNum, list);
 	}
 
+	/**
+	 * 鏍规嵁鐢佃瘽鍙风爜銆侀個璇风爜鑾峰彇閭�璇风敤鎴�
+	 * 
+	 * @param phone
+	 * @param inviteCode
+	 * @return
+	 */
+	@Override
+	public UserInfo getInfoByPhoneOrInviteCode(String phone, String inviteCode) {
+		return userInfoMapper.getInfoByPhoneOrInviteCode(phone, inviteCode);
+	}
+
 }

--
Gitblit v1.8.0