yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
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,8 +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.count.HongBaoV2CountService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.UserInfoService;
@@ -49,9 +54,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 {
@@ -73,22 +75,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) {
@@ -420,13 +424,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 +443,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 +555,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 +567,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 +602,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
@@ -620,15 +626,14 @@
      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 +641,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 +682,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 +690,66 @@
               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 +762,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 +772,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 +806,21 @@
      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);
   }
}