facade-goods/facade-goods.iml
@@ -18,7 +18,7 @@ <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="library" name="javas" level="project" /> <orderEntry type="module" module-name="facede-common" /> <orderEntry type="module" module-name="utils" /> <orderEntry type="library" name="Maven: com.yeshi:utils:0.0.1-SNAPSHOT" level="project" /> <orderEntry type="library" name="Maven: com.opencsv:opencsv:4.3.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.3" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.2" level="project" /> facede-common/facede-common.iml
@@ -17,7 +17,7 @@ <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="library" name="javas" level="project" /> <orderEntry type="module" module-name="utils" /> <orderEntry type="library" name="Maven: com.yeshi:utils:0.0.1-SNAPSHOT" level="project" /> <orderEntry type="library" name="Maven: com.opencsv:opencsv:4.3.2" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.3" level="project" /> <orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.2" level="project" /> fanli/src/main/java/com/yeshi/fanli/controller/client/v2/TuanYouController.java
New file @@ -0,0 +1,38 @@ package com.yeshi.fanli.controller.client.v2; import com.yeshi.fanli.entity.accept.AcceptData; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.util.TuanYouUtil; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.yeshi.utils.JsonUtil; import javax.annotation.Resource; import java.io.PrintWriter; @Controller @RequestMapping("api/v2/tuanyou") public class TuanYouController { @Resource private UserInfoService userInfoService; /** * @param acceptData * @param uid */ @RequestMapping(value = "getAuthCode") public void getAuthCode(AcceptData acceptData, Long uid, PrintWriter out) { UserInfo userInfo = userInfoService.selectByPKey(uid); if (userInfo != null) { String code = TuanYouUtil.getAuthCode(userInfo.getPhone()); out.print(JsonUtil.loadTrueResult(code)); return; } out.print(JsonUtil.loadFalseResult("获取授权码失败")); } } fanli/src/main/java/com/yeshi/fanli/dao/user/UserGoodsChannelConfigDao.java
New file @@ -0,0 +1,28 @@ package com.yeshi.fanli.dao.user; import com.yeshi.common.MongodbBaseDao; import com.yeshi.fanli.entity.goods.UserGoodsChannelConfig; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; import org.springframework.stereotype.Repository; import java.util.Date; @Repository public class UserGoodsChannelConfigDao extends MongodbBaseDao<UserGoodsChannelConfig> { public void updateSelective(UserGoodsChannelConfig config) { Query query = new Query(); query.addCriteria(Criteria.where("uid").is(config.getUid())); Update update = new Update(); if (config.getPddFanliCustomerParams() != null) { update.set("pddFanliCustomerParams", config.getPddFanliCustomerParams()); } config.setUpdateTime(new Date()); update(query, update); } } fanli/src/main/java/com/yeshi/fanli/entity/goods/UserGoodsChannelConfig.java
New file @@ -0,0 +1,56 @@ package com.yeshi.fanli.entity.goods; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; import java.util.Date; /** * 商品渠道配置 */ @Document(collection = "userGoodsChannelConfig") public class UserGoodsChannelConfig { @Id private Long uid; //拼多多自购的CustomerParams private String pddFanliCustomerParams; private Date createTime; private Date updateTime; public Long getUid() { return uid; } public void setUid(Long uid) { this.uid = uid; } public String getPddFanliCustomerParams() { return pddFanliCustomerParams; } public void setPddFanliCustomerParams(String pddFanliCustomerParams) { this.pddFanliCustomerParams = pddFanliCustomerParams; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } public Date getUpdateTime() { return updateTime; } public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } } fanli/src/main/java/com/yeshi/fanli/job/JobDefend.java
New file @@ -0,0 +1,29 @@ package com.yeshi.fanli.job; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import com.yeshi.fanli.service.manger.JobManager; import org.springframework.stereotype.Component; import javax.annotation.Resource; @Component public class JobDefend { @Resource private JobManager jobManager; /** * 维护job * * @param param * @return * @throws Exception */ @XxlJob("jobDefend-defend") public ReturnT<String> defend(String param) throws Exception { jobManager.repaire(); return ReturnT.SUCCESS; } } fanli/src/main/java/com/yeshi/fanli/service/impl/money/extract/ExtractServiceImpl.java
@@ -438,14 +438,12 @@ * * @param extract * @param msg * @param session */ @Transactional private void extractFail(Extract extract, String msg) { private void extractFail(Extract extract, String subCode, String msg) { UserInfo user = extract.getUserInfo(); // MoneyRecord moneyRecord = new MoneyRecord(user, null, extract // .getMoney(), "提现", "提现失败", new Date().getTime(), 3); if ("付款方余额不足".equals(msg)) { if ("PAYER_BALANCE_NOT_ENOUGH".equals(subCode)) { Extract updateExtract = new Extract(); updateExtract.setId(extract.getId()); updateExtract.setState(Constant.EXTRACT_DEFUALT); @@ -671,10 +669,10 @@ if ("10000".equals(code)) { extractSuccess(extract, response.getOrderId()); } else { extractFail(extract, response.getSubMsg()); extractFail(extract, response.getSubCode(), response.getSubMsg()); } } else { extractFail(extract, response.getSubMsg()); extractFail(extract, response.getSubCode(), response.getSubMsg()); } PayInfo payInfo = new PayInfo(); payInfo.setBizno(response.getOutBizNo()); fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderProcessServiceImpl.java
@@ -14,6 +14,7 @@ import javax.annotation.Resource; import com.yeshi.fanli.service.manger.order.TeamRewardManager; import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -1069,10 +1070,10 @@ public void processPDDOrder(PDDOrder pddOrder) { if (pddOrder == null) return; String uidStr = pddOrder.getCustomParameters(); String customParameters = pddOrder.getCustomParameters(); Long uid = null; if (!StringUtil.isNullOrEmpty(uidStr)) uid = Long.parseLong(uidStr); if (!StringUtil.isNullOrEmpty(customParameters)) uid = Long.parseLong(PinDuoDuoUtil.getUidFromCustomParams(customParameters)); String positionId = pddOrder.getpId(); if (PinDuoDuoApiUtil.PID_FANLI.equalsIgnoreCase(positionId))// 返利订单 { fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
@@ -15,7 +15,9 @@ import javax.annotation.Resource; import com.yeshi.fanli.dao.user.UserGoodsChannelConfigDao; import com.yeshi.fanli.entity.SystemEnum; import com.yeshi.fanli.entity.goods.UserGoodsChannelConfig; import com.yeshi.fanli.util.*; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; @@ -68,819 +70,832 @@ @Service public class UserInfoExtraServiceImpl implements UserInfoExtraService { @Resource private UserInfoExtraMapper userInfoExtraMapper; @Resource private UserInfoExtraMapper userInfoExtraMapper; @Resource private UserRankRecordMapper userRankRecordMapper; @Resource private UserRankRecordMapper userRankRecordMapper; @Resource private UserRankService userRankService; @Resource private UserRankService userRankService; @Resource private CommonOrderCountService commonOrderCountService; @Resource private CommonOrderCountService commonOrderCountService; @Resource private ConfigService configService; @Resource private ConfigService configService; @Resource private ThreeSaleSerivce threeSaleSerivce; @Resource private ThreeSaleSerivce threeSaleSerivce; @Resource private UserInfoService userInfoService; @Resource private UserInfoService userInfoService; @Resource private UserAccountService userAccountService; @Resource private UserAccountService userAccountService; @Resource private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService; @Resource private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService; @Resource private UserInviteRecordService userInviteRecordService; @Resource private UserInviteRecordService userInviteRecordService; @Resource @Lazy private UserActivedRecordService userActivedRecordService; @Resource private UserAccountMsgNotificationService userAccountMsgNotificationService; @Resource @Lazy private UserActivedRecordService userActivedRecordService; @Resource private RocketMQManager rocketMQManager; @Resource private UserAccountMsgNotificationService userAccountMsgNotificationService; @Override public UserInfoExtraVO getRankInfo(Long uid) throws UserInfoExtraException, Exception { @Resource private RocketMQManager rocketMQManager; UserInfoExtraVO extraVO = userInfoExtraMapper.getInfoExtraVOByUid(uid); if (extraVO == null) { throw new UserInfoExtraException(1, "用户附加信息不存在"); } @Override public UserInfoExtraVO getRankInfo(Long uid) throws UserInfoExtraException, Exception { SystemEnum system= userInfoService.getUserSystem(uid); UserInfoExtraVO extraVO = userInfoExtraMapper.getInfoExtraVOByUid(uid); if (extraVO == null) { throw new UserInfoExtraException(1, "用户附加信息不存在"); } // 等级对照表 String contrast = configService.getValue(ConfigKeyEnum.userRankContrast.getKey(),system); extraVO.setRankContrast(contrast); // 特别提醒 String rankTip = configService.getValue(ConfigKeyEnum.userRankTip.getKey(),system); extraVO.setRankTip(rankTip); SystemEnum system = userInfoService.getUserSystem(uid); Integer rankOrderNum = extraVO.getRankOrderNum(); // 等级对照表 String contrast = configService.getValue(ConfigKeyEnum.userRankContrast.getKey(), system); extraVO.setRankContrast(contrast); // 特别提醒 String rankTip = configService.getValue(ConfigKeyEnum.userRankTip.getKey(), system); extraVO.setRankTip(rankTip); UserRank userRank = extraVO.getUserRank(); // 青铜等级不返回恭喜语句 注:青铜等级id 必须为1 if (userRank != null && userRank.getId() != null && userRank.getId() > 1) { Integer rankOrderNum = extraVO.getRankOrderNum(); String rankMsg = null; Integer rankSource = extraVO.getRankSource(); switch (rankSource) { case Constant.TYPE_REBATE: rankMsg = "返利订单"; break; case Constant.TYPE_SHAER: rankMsg = "分享订单"; break; case Constant.TYPE_INVITE: rankMsg = "邀请订单"; break; default: break; } UserRank userRank = extraVO.getUserRank(); // 青铜等级不返回恭喜语句 注:青铜等级id 必须为1 if (userRank != null && userRank.getId() != null && userRank.getId() > 1) { List<Object> listMsg = new ArrayList<Object>(); String rankMsg = null; Integer rankSource = extraVO.getRankSource(); switch (rankSource) { case Constant.TYPE_REBATE: rankMsg = "返利订单"; break; case Constant.TYPE_SHAER: rankMsg = "分享订单"; break; case Constant.TYPE_INVITE: rankMsg = "邀请订单"; break; default: break; } if (rankMsg != null) { String color_red = "#E5005C"; String color_black = "#333333"; List<Object> listMsg = new ArrayList<Object>(); Map<String, String> map1 = new HashMap<String, String>(); map1.put("content", "上月"); map1.put("color", color_black); listMsg.add(map1); if (rankMsg != null) { String color_red = "#E5005C"; String color_black = "#333333"; Map<String, String> map2 = new HashMap<String, String>(); map2.put("content", rankMsg); map2.put("color", color_red); listMsg.add(map2); Map<String, String> map1 = new HashMap<String, String>(); map1.put("content", "上月"); map1.put("color", color_black); listMsg.add(map1); Map<String, String> map3 = new HashMap<String, String>(); map3.put("content", "达到了"); map3.put("color", color_black); listMsg.add(map3); Map<String, String> map2 = new HashMap<String, String>(); map2.put("content", rankMsg); map2.put("color", color_red); listMsg.add(map2); Map<String, String> map4 = new HashMap<String, String>(); map4.put("content", rankOrderNum + ""); map4.put("color", color_red); listMsg.add(map4); Map<String, String> map3 = new HashMap<String, String>(); map3.put("content", "达到了"); map3.put("color", color_black); listMsg.add(map3); Map<String, String> map5 = new HashMap<String, String>(); map5.put("content", "单"); map5.put("color", color_black); listMsg.add(map5); extraVO.setGalaMsg(listMsg); } } Map<String, String> map4 = new HashMap<String, String>(); map4.put("content", rankOrderNum + ""); map4.put("color", color_red); listMsg.add(map4); return extraVO; } Map<String, String> map5 = new HashMap<String, String>(); map5.put("content", "单"); map5.put("color", color_black); listMsg.add(map5); extraVO.setGalaMsg(listMsg); } } @Override public void updateUserRankByUid(Long uid) throws UserInfoExtraException { if (uid == null || uid == 0) { return; } return extraVO; } boolean isupdateRank = true; UserInfoExtra extra = new UserInfoExtra(); @Override public void updateUserRankByUid(Long uid) throws UserInfoExtraException { if (uid == null || uid == 0) { return; } UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid); if (userInfoExtra != null && userInfoExtra.getId() != null) { // 判断当月是否已更新 Date rankUpdateTime = userInfoExtra.getRankUpdateTime(); if (rankUpdateTime != null) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); if (sdf.format(rankUpdateTime).equals(sdf.format(new Date()))) { isupdateRank = false; } } extra.setId(userInfoExtra.getId()); } else { extra.setUserInfo(new UserInfo(uid)); } boolean isupdateRank = true; UserInfoExtra extra = new UserInfoExtra(); // 更新等级 if (isupdateRank) { List<UserRank> listRank = userRankService.getAllRank(); if (listRank == null || listRank.size() == 0) { throw new UserInfoExtraException(1, "系统等级不存在"); } UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid); if (userInfoExtra != null && userInfoExtra.getId() != null) { // 判断当月是否已更新 Date rankUpdateTime = userInfoExtra.getRankUpdateTime(); if (rankUpdateTime != null) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); if (sdf.format(rankUpdateTime).equals(sdf.format(new Date()))) { isupdateRank = false; } } extra.setId(userInfoExtra.getId()); } else { extra.setUserInfo(new UserInfo(uid)); } int selfOrderNum = 0; int sharedOrderNum = 0; int inviteOrderNum = 0; Map<String, Object> map = commonOrderCountService.lastMonthSettleOrderNumber(uid); if (map != null) { // 返利订单 if (map.get("totalSelf") != null) { selfOrderNum = Integer.parseInt(map.get("totalSelf").toString()); } // 更新等级 if (isupdateRank) { List<UserRank> listRank = userRankService.getAllRank(); if (listRank == null || listRank.size() == 0) { throw new UserInfoExtraException(1, "系统等级不存在"); } // 分享订单 if (map.get("totalShared") != null) { sharedOrderNum = Integer.parseInt(map.get("totalShared").toString()); } int selfOrderNum = 0; int sharedOrderNum = 0; int inviteOrderNum = 0; Map<String, Object> map = commonOrderCountService.lastMonthSettleOrderNumber(uid); if (map != null) { // 返利订单 if (map.get("totalSelf") != null) { selfOrderNum = Integer.parseInt(map.get("totalSelf").toString()); } // 邀请订单 if (map.get("totalInvite") != null) { inviteOrderNum = Integer.parseInt(map.get("totalInvite").toString()); } } // 分享订单 if (map.get("totalShared") != null) { sharedOrderNum = Integer.parseInt(map.get("totalShared").toString()); } UserRank rank = null; for (UserRank userRank : listRank) { // 邀请满足 Integer inviteNum = userRank.getInviteNum(); if (inviteOrderNum >= inviteNum) { rank = userRank; extra.setRankOrderNum(inviteOrderNum); extra.setRankSource(Constant.TYPE_INVITE); } // 邀请订单 if (map.get("totalInvite") != null) { inviteOrderNum = Integer.parseInt(map.get("totalInvite").toString()); } } // 分享满足 int shareNum = userRank.getShareNum(); if (sharedOrderNum >= shareNum) { rank = userRank; extra.setRankOrderNum(sharedOrderNum); extra.setRankSource(Constant.TYPE_SHAER); } UserRank rank = null; for (UserRank userRank : listRank) { // 邀请满足 Integer inviteNum = userRank.getInviteNum(); if (inviteOrderNum >= inviteNum) { rank = userRank; extra.setRankOrderNum(inviteOrderNum); extra.setRankSource(Constant.TYPE_INVITE); } // 返利满足 int directNum = userRank.getRebateNum(); if (selfOrderNum >= directNum) { rank = userRank; extra.setRankOrderNum(selfOrderNum); extra.setRankSource(Constant.TYPE_REBATE); } // 分享满足 int shareNum = userRank.getShareNum(); if (sharedOrderNum >= shareNum) { rank = userRank; extra.setRankOrderNum(sharedOrderNum); extra.setRankSource(Constant.TYPE_SHAER); } if (rank != null) { extra.setUserRank(rank); } else { rank = userRank; // 默认最低等级:青铜 extra.setUserRank(rank); extra.setRankOrderNum(selfOrderNum); extra.setRankSource(Constant.TYPE_REBATE); break; } } // 返利满足 int directNum = userRank.getRebateNum(); if (selfOrderNum >= directNum) { rank = userRank; extra.setRankOrderNum(selfOrderNum); extra.setRankSource(Constant.TYPE_REBATE); } // 等级更新时间 当月1号 Calendar calendar1 = Calendar.getInstance(); calendar1.set(Calendar.DAY_OF_MONTH, 1); extra.setRankUpdateTime(calendar1.getTime()); if (rank != null) { extra.setUserRank(rank); } else { rank = userRank; // 默认最低等级:青铜 extra.setUserRank(rank); extra.setRankOrderNum(selfOrderNum); extra.setRankSource(Constant.TYPE_REBATE); break; } } // 保存等级信息 saveUserInfoExtra(extra); // 等级更新时间 当月1号 Calendar calendar1 = Calendar.getInstance(); calendar1.set(Calendar.DAY_OF_MONTH, 1); extra.setRankUpdateTime(calendar1.getTime()); // 保存等级变化记录 UserRankRecord userRankRecord = new UserRankRecord(); userRankRecord.setUid(uid); userRankRecord.setRankId(rank.getId()); userRankRecord.setCreateTime(new Date()); userRankRecordMapper.insertSelective(userRankRecord); } } // 保存等级信息 saveUserInfoExtra(extra); @Override public void createUserInfoExtra(Long uid) throws UserInfoExtraException { UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid); if (userInfoExtra != null) { return; } // 保存等级变化记录 UserRankRecord userRankRecord = new UserRankRecord(); userRankRecord.setUid(uid); userRankRecord.setRankId(rank.getId()); userRankRecord.setCreateTime(new Date()); userRankRecordMapper.insertSelective(userRankRecord); } } userInfoExtra = new UserInfoExtra(); userInfoExtra.setUserInfo(new UserInfo(uid)); userInfoExtra.setFirstLoginTime(new Date()); userInfoExtra.setCreateTime(new Date()); userInfoExtra.setUpdateTime(new Date()); userInfoExtra.setActiveTime(new Date()); userInfoExtraMapper.insertSelective(userInfoExtra); } @Override public void createUserInfoExtra(Long uid) throws UserInfoExtraException { UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid); if (userInfoExtra != null) { return; } @Override public UserInfoExtra saveUserInfoExtra(UserInfoExtra userInfoExtra) throws UserInfoExtraException { userInfoExtra = new UserInfoExtra(); userInfoExtra.setUserInfo(new UserInfo(uid)); userInfoExtra.setFirstLoginTime(new Date()); userInfoExtra.setCreateTime(new Date()); userInfoExtra.setUpdateTime(new Date()); userInfoExtra.setActiveTime(new Date()); userInfoExtraMapper.insertSelective(userInfoExtra); } if (userInfoExtra == null) { throw new UserInfoExtraException(1, "附加信息不能为空"); } @Override public UserInfoExtra saveUserInfoExtra(UserInfoExtra userInfoExtra) throws UserInfoExtraException { Long extraId = userInfoExtra.getId(); if (extraId != null) { userInfoExtra.setUpdateTime(new Date()); userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra); } else { UserInfo userInfo = userInfoExtra.getUserInfo(); if (userInfo == null || userInfo.getId() == null) { throw new UserInfoExtraException(1, "用户不存在"); } if (userInfoExtra == null) { throw new UserInfoExtraException(1, "附加信息不能为空"); } Long uid = userInfo.getId(); UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null && extra.getId() != null) { userInfoExtra.setId(extra.getId()); userInfoExtra.setUpdateTime(new Date()); userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra); } else { userInfoExtra.setCreateTime(new Date()); userInfoExtra.setUpdateTime(new Date()); userInfoExtraMapper.insertSelective(userInfoExtra); } Long extraId = userInfoExtra.getId(); if (extraId != null) { userInfoExtra.setUpdateTime(new Date()); userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra); } else { UserInfo userInfo = userInfoExtra.getUserInfo(); if (userInfo == null || userInfo.getId() == null) { throw new UserInfoExtraException(1, "用户不存在"); } } return userInfoExtra; } Long uid = userInfo.getId(); UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null && extra.getId() != null) { userInfoExtra.setId(extra.getId()); userInfoExtra.setUpdateTime(new Date()); userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra); } else { userInfoExtra.setCreateTime(new Date()); userInfoExtra.setUpdateTime(new Date()); userInfoExtraMapper.insertSelective(userInfoExtra); } @Override @Transactional(rollbackFor = Exception.class) public String activateInviteCode(Long uid, String inviteCode) throws UserInfoExtraException { if (uid == null || inviteCode == null) throw new UserInfoExtraException(1, "激活信息不能为空"); } return userInfoExtra; } // 被邀请人信息 UserInfo invitee = userInfoService.selectByPKey(uid); if (invitee == null) throw new UserInfoExtraException(1, "用户不存在"); @Override @Transactional(rollbackFor = Exception.class) public String activateInviteCode(Long uid, String inviteCode) throws UserInfoExtraException { if (uid == null || inviteCode == null) throw new UserInfoExtraException(1, "激活信息不能为空"); // 额外信息 UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) throw new UserInfoExtraException(1, "已经激活, 无需再次激活"); // 被邀请人信息 UserInfo invitee = userInfoService.selectByPKey(uid); if (invitee == null) throw new UserInfoExtraException(1, "用户不存在"); inviteCode = inviteCode.toUpperCase(); // 邀请码对应用户信息 UserInfo boss = userInfoService.getUserInfoByInviteCode(inviteCode); if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) throw new UserInfoExtraException(1, "上级邀请码不存在"); // 额外信息 UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) throw new UserInfoExtraException(1, "已经激活, 无需再次激活"); // 生成邀请关系 return inviteCodeActive(uid, boss.getId()); } inviteCode = inviteCode.toUpperCase(); @Override @Transactional(rollbackFor = Exception.class) public void activationInviteWX(WXAccountInfoDTO wxAccount, Long uid, String code) throws UserInfoExtraException { if (uid == null || code == null) throw new UserInfoExtraException(1, "激活信息不完整"); // 邀请码对应用户信息 UserInfo boss = userInfoService.getUserInfoByInviteCode(inviteCode); if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) throw new UserInfoExtraException(1, "上级邀请码不存在"); UserInfo invitee = userInfoService.selectByPKey(uid); if (invitee == null) throw new UserInfoExtraException(1, "用户不存在"); // 生成邀请关系 return inviteCodeActive(uid, boss.getId()); } // 额外信息 UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) throw new UserInfoExtraException(1, "已经激活, 无需再次激活"); @Override @Transactional(rollbackFor = Exception.class) public void activationInviteWX(WXAccountInfoDTO wxAccount, Long uid, String code) throws UserInfoExtraException { if (uid == null || code == null) throw new UserInfoExtraException(1, "激活信息不完整"); // 获取微信信息 WeiXinUser weiXinUser = WXAppLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret()); if (weiXinUser == null) { throw new UserInfoExtraException(1, "微信授权失败"); } String wxUnionId = weiXinUser.getUnionid(); if (wxUnionId == null || wxUnionId.trim().length() == 0) { throw new UserInfoExtraException(1, "微信授权失败"); } UserInfo invitee = userInfoService.selectByPKey(uid); if (invitee == null) throw new UserInfoExtraException(1, "用户不存在"); // 验证数据 String wxUnionIdExist = invitee.getWxUnionId(); if (StringUtil.isNullOrEmpty(wxUnionIdExist)) { UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(),invitee.getSystem()); if (newUser != null) { throw new UserInfoExtraException(1, "此微信已被其他帐号绑定"); } // 额外信息 UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) throw new UserInfoExtraException(1, "已经激活, 无需再次激活"); // 自动绑定微信 UserInfo updateUserInfo = new UserInfo(uid); updateUserInfo.setWxOpenId(weiXinUser.getOpenid()); updateUserInfo.setWxUnionId(weiXinUser.getUnionid()); updateUserInfo.setWxName(weiXinUser.getNickname()); updateUserInfo.setWxPic(weiXinUser.getHeadimgurl()); // 获取微信信息 WeiXinUser weiXinUser = WXAppLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret()); if (weiXinUser == null) { throw new UserInfoExtraException(1, "微信授权失败"); } String wxUnionId = weiXinUser.getUnionid(); if (wxUnionId == null || wxUnionId.trim().length() == 0) { throw new UserInfoExtraException(1, "微信授权失败"); } // 将默认昵称替换成微信昵称 String defaultNickName = Constant.systemCommonConfig.getDefaultNickName(); if (!StringUtil.isNullOrEmpty(defaultNickName) && !StringUtil.isNullOrEmpty(weiXinUser.getNickname())) { defaultNickName = defaultNickName + uid; if ((defaultNickName.equals(invitee.getNickName()) || "返利券".equals(invitee.getNickName()) || invitee.getNickName().startsWith(Constant.systemCommonConfig.getDefaultNickName()))) { updateUserInfo.setNickName(weiXinUser.getNickname()); } } // 验证数据 String wxUnionIdExist = invitee.getWxUnionId(); if (StringUtil.isNullOrEmpty(wxUnionIdExist)) { UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), invitee.getSystem()); if (newUser != null) { throw new UserInfoExtraException(1, "此微信已被其他帐号绑定"); } // 将默认头像替换成微信头像 String defaultPortrait = Constant.systemCommonConfig.getDefaultPortrait(); if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl()) && !StringUtil.isNullOrEmpty(defaultPortrait) && defaultPortrait.equals(invitee.getPortrait())) { String headimgurl = weiXinUser.getHeadimgurl(); InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl); if (asInputStream == null) { LogHelper.test("微信头像下载失败: " + weiXinUser.getUnionid() + " " + headimgurl); } else { FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) { headimgurl = result.getUrl(); } else { LogHelper.test("微信头像上传失败: " + weiXinUser.getUnionid() + " " + headimgurl); } } updateUserInfo.setPortrait(headimgurl); } // 自动绑定微信 UserInfo updateUserInfo = new UserInfo(uid); updateUserInfo.setWxOpenId(weiXinUser.getOpenid()); updateUserInfo.setWxUnionId(weiXinUser.getUnionid()); updateUserInfo.setWxName(weiXinUser.getNickname()); updateUserInfo.setWxPic(weiXinUser.getHeadimgurl()); // 将默认昵称替换成微信昵称 String defaultNickName = Constant.systemCommonConfig.getDefaultNickName(); if (!StringUtil.isNullOrEmpty(defaultNickName) && !StringUtil.isNullOrEmpty(weiXinUser.getNickname())) { defaultNickName = defaultNickName + uid; if ((defaultNickName.equals(invitee.getNickName()) || "返利券".equals(invitee.getNickName()) || invitee.getNickName().startsWith(Constant.systemCommonConfig.getDefaultNickName()))) { updateUserInfo.setNickName(weiXinUser.getNickname()); } } // 将默认头像替换成微信头像 String defaultPortrait = Constant.systemCommonConfig.getDefaultPortrait(); if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl()) && !StringUtil.isNullOrEmpty(defaultPortrait) && defaultPortrait.equals(invitee.getPortrait())) { String headimgurl = weiXinUser.getHeadimgurl(); InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl); if (asInputStream == null) { LogHelper.test("微信头像下载失败: " + weiXinUser.getUnionid() + " " + headimgurl); } else { FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) { headimgurl = result.getUrl(); } else { LogHelper.test("微信头像上传失败: " + weiXinUser.getUnionid() + " " + headimgurl); } } updateUserInfo.setPortrait(headimgurl); } userInfoService.updateByPrimaryKeySelective(updateUserInfo); } else if (!wxUnionId.equals(wxUnionIdExist)) { throw new UserInfoExtraException(1, "绑定微信与激活微信不一致"); } // 是否存在邀请人 Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); if (inviterId == null) throw new UserInfoExtraException(1, "没有对应的邀请关系"); UserInfo boss = userInfoService.selectByPKey(inviterId); if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) { throw new UserInfoExtraException(1, "没有对应的邀请关系"); } // 邀请码激活 inviteCodeActive(uid, boss.getId()); } @Override @Transactional(rollbackFor = Exception.class) public void activeInviteWX(Long uid, WeiXinUser weiXinUser) throws UserInfoExtraException { if (uid == null || weiXinUser == null) { throw new UserInfoExtraException(1, "激活信息不完整"); } // 用户信息 UserInfo invitee = userInfoService.selectByPKey(uid); if (invitee == null) { throw new UserInfoExtraException(1, "用户不存在"); } String wxUnionId = weiXinUser.getUnionid(); if (wxUnionId == null || wxUnionId.trim().length() == 0) { throw new UserInfoExtraException(1, "微信授权失败"); } // 验证数据 String wxUnionIdExist = invitee.getWxUnionId(); if (StringUtil.isNullOrEmpty(wxUnionIdExist)) { UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), invitee.getSystem()); if (newUser != null) { throw new UserInfoExtraException(1, "此微信已被其他帐号绑定"); } // 自动绑定微信 UserInfo updateUserInfo = new UserInfo(uid); updateUserInfo.setWxOpenId(weiXinUser.getOpenid()); updateUserInfo.setWxUnionId(weiXinUser.getUnionid()); updateUserInfo.setWxName(weiXinUser.getNickname()); updateUserInfo.setWxPic(weiXinUser.getHeadimgurl()); // 将默认昵称替换成微信昵称 String defaultNickName = Constant.systemCommonConfig.getDefaultNickName(); if (!StringUtil.isNullOrEmpty(defaultNickName) && !StringUtil.isNullOrEmpty(weiXinUser.getNickname())) { defaultNickName = defaultNickName + uid; if ((defaultNickName.equals(invitee.getNickName()) || "返利券".equals(invitee.getNickName()) || invitee.getNickName().startsWith(Constant.systemCommonConfig.getDefaultNickName()))) { updateUserInfo.setNickName(weiXinUser.getNickname()); } } // 将默认头像替换成微信头像 String defaultPortrait = Constant.systemCommonConfig.getDefaultPortrait(); if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl()) && !StringUtil.isNullOrEmpty(defaultPortrait) && defaultPortrait.equals(invitee.getPortrait())) { String headimgurl = weiXinUser.getHeadimgurl(); InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl); if (asInputStream == null) { LogHelper.test("微信头像下载失败: " + weiXinUser.getUnionid() + " " + headimgurl); } else { FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) { headimgurl = result.getUrl(); } else { LogHelper.test("微信头像上传失败: " + weiXinUser.getUnionid() + " " + headimgurl); } } updateUserInfo.setPortrait(headimgurl); } userInfoService.updateByPrimaryKeySelective(updateUserInfo); } else if (!wxUnionId.equals(wxUnionIdExist)) { throw new UserInfoExtraException(1, "绑定微信与激活微信不一致"); } // 邀请人ID -1.5.3新版 Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); if (inviterId == null) { throw new UserInfoExtraException(1, "没有对应的邀请关系"); } UserInfo boss = userInfoService.selectByPKey(inviterId); if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) { throw new UserInfoExtraException(1, "没有对应的邀请关系"); } userInfoService.updateByPrimaryKeySelective(updateUserInfo); // 邀请码激活 inviteCodeActive(uid, boss.getId()); } } else if (!wxUnionId.equals(wxUnionIdExist)) { throw new UserInfoExtraException(1, "绑定微信与激活微信不一致"); } // 是否存在邀请人 Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); if (inviterId == null) throw new UserInfoExtraException(1, "没有对应的邀请关系"); UserInfo boss = userInfoService.selectByPKey(inviterId); if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) { throw new UserInfoExtraException(1, "没有对应的邀请关系"); } /** * 邀请关系生成激活码 * * @param uid * @param bossId * @return * @throws UserInfoExtraException */ private String inviteCodeActive(Long uid, Long bossId) throws UserInfoExtraException { UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) { throw new UserInfoExtraException(1, "已经激活, 无需再次激活"); } // 邀请码激活 inviteCodeActive(uid, boss.getId()); } // 绑定关系 try { threeSaleSerivce.bindInviteRelationship(uid, bossId); } catch (ThreeSaleException e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } throw new UserInfoExtraException(1, "关系绑定时失败"); } @Override @Transactional(rollbackFor = Exception.class) public void activeInviteWX(Long uid, WeiXinUser weiXinUser) throws UserInfoExtraException { if (uid == null || weiXinUser == null) { throw new UserInfoExtraException(1, "激活信息不完整"); } // 生成邀请码 String inviteCode = createInviteCode(uid); if (StringUtil.isNullOrEmpty(inviteCode)) throw new UserInfoExtraException(1, "激活码生成失败"); // 用户信息 UserInfo invitee = userInfoService.selectByPKey(uid); if (invitee == null) { throw new UserInfoExtraException(1, "用户不存在"); } UserInfoExtra userInfoExtra = new UserInfoExtra(); userInfoExtra.setUserInfo(new UserInfo(uid)); userInfoExtra.setInviteCode(inviteCode); userInfoExtra.setUpdateTime(new Date()); if (extra != null) { userInfoExtra.setId(extra.getId()); userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra); } else { userInfoExtra.setCreateTime(new Date()); userInfoExtraMapper.insertSelective(userInfoExtra); } String wxUnionId = weiXinUser.getUnionid(); if (wxUnionId == null || wxUnionId.trim().length() == 0) { throw new UserInfoExtraException(1, "微信授权失败"); } userActivedRecordService.add(new UserActivedRecord(uid)); // 验证数据 String wxUnionIdExist = invitee.getWxUnionId(); if (StringUtil.isNullOrEmpty(wxUnionIdExist)) { UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(),invitee.getSystem()); if (newUser != null) { throw new UserInfoExtraException(1, "此微信已被其他帐号绑定"); } if (!Constant.IS_TEST) { // 发送激活成功消息 Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteCodeActive, new InviteCodeActiveMQMsg(uid, new Date())); rocketMQManager.sendNormalMsg(message, null); } // 自动绑定微信 UserInfo updateUserInfo = new UserInfo(uid); updateUserInfo.setWxOpenId(weiXinUser.getOpenid()); updateUserInfo.setWxUnionId(weiXinUser.getUnionid()); updateUserInfo.setWxName(weiXinUser.getNickname()); updateUserInfo.setWxPic(weiXinUser.getHeadimgurl()); return inviteCode; } // 将默认昵称替换成微信昵称 String defaultNickName = Constant.systemCommonConfig.getDefaultNickName(); if (!StringUtil.isNullOrEmpty(defaultNickName) && !StringUtil.isNullOrEmpty(weiXinUser.getNickname())) { defaultNickName = defaultNickName + uid; if ((defaultNickName.equals(invitee.getNickName()) || "返利券".equals(invitee.getNickName()) || invitee.getNickName().startsWith(Constant.systemCommonConfig.getDefaultNickName()))) { updateUserInfo.setNickName(weiXinUser.getNickname()); } } // 将默认头像替换成微信头像 String defaultPortrait = Constant.systemCommonConfig.getDefaultPortrait(); if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl()) && !StringUtil.isNullOrEmpty(defaultPortrait) && defaultPortrait.equals(invitee.getPortrait())) { String headimgurl = weiXinUser.getHeadimgurl(); InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl); if (asInputStream == null) { LogHelper.test("微信头像下载失败: " + weiXinUser.getUnionid() + " " + headimgurl); } else { FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + "")); if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) { headimgurl = result.getUrl(); } else { LogHelper.test("微信头像上传失败: " + weiXinUser.getUnionid() + " " + headimgurl); } } updateUserInfo.setPortrait(headimgurl); } @Override public void updateActiveTime(Long uid, Date date) { UserInfoExtra userInfoExtra = new UserInfoExtra(); userInfoExtra.setUserInfo(new UserInfo(uid)); userInfoExtra.setActiveTime(date); userInfoExtraMapper.updateInfoExtraByUid(userInfoExtra); } userInfoService.updateByPrimaryKeySelective(updateUserInfo); @Override public UserInfoExtra getUserInfoExtra(Long uid) { return userInfoExtraMapper.getInfoExtraByUid(uid); } } else if (!wxUnionId.equals(wxUnionIdExist)) { throw new UserInfoExtraException(1, "绑定微信与激活微信不一致"); } @Override public UserInfoExtra getUserALLInfo(Long uid) { return userInfoExtraMapper.gerUserRank(uid); } // 邀请人ID -1.5.3新版 Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); if (inviterId == null) { throw new UserInfoExtraException(1, "没有对应的邀请关系"); } UserInfo boss = userInfoService.selectByPKey(inviterId); if (boss == null || boss.getState() != UserInfo.STATE_NORMAL) { throw new UserInfoExtraException(1, "没有对应的邀请关系"); } // 邀请码激活 inviteCodeActive(uid, boss.getId()); } /** * 邀请关系生成激活码 * @param uid * @param bossId * @return * @throws UserInfoExtraException */ private String inviteCodeActive(Long uid, Long bossId) throws UserInfoExtraException{ UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode())) { throw new UserInfoExtraException(1, "已经激活, 无需再次激活"); } // 绑定关系 try { threeSaleSerivce.bindInviteRelationship(uid, bossId); } catch (ThreeSaleException e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } throw new UserInfoExtraException(1, "关系绑定时失败"); } @Override @Transactional public UserInfoExtra getByUidForUpdate(Long uid) { return userInfoExtraMapper.getByUidForUpdate(uid); } // 生成邀请码 String inviteCode = createInviteCode(uid); if (StringUtil.isNullOrEmpty(inviteCode)) throw new UserInfoExtraException(1, "激活码生成失败"); @Override @Transactional public void updateGoldCoin(Long id, Integer goldCoin) { userInfoExtraMapper.updateGoldCoin(id, goldCoin); } UserInfoExtra userInfoExtra = new UserInfoExtra(); userInfoExtra.setUserInfo(new UserInfo(uid)); userInfoExtra.setInviteCode(inviteCode); userInfoExtra.setUpdateTime(new Date()); if (extra != null) { userInfoExtra.setId(extra.getId()); userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra); } else { userInfoExtra.setCreateTime(new Date()); userInfoExtraMapper.insertSelective(userInfoExtra); } userActivedRecordService.add(new UserActivedRecord(uid)); @Override public void addGoldCoinByUid(Long uid, Integer goldCoin) { userInfoExtraMapper.addGoldCoinByUid(uid, goldCoin); } if (!Constant.IS_TEST) { // 发送激活成功消息 Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.inviteCodeActive, new InviteCodeActiveMQMsg(uid, new Date())); rocketMQManager.sendNormalMsg(message, null); } return inviteCode; } @Override public void updateByPrimaryKeySelective(UserInfoExtra record) { userInfoExtraMapper.updateByPrimaryKeySelective(record); } @Override public void updateActiveTime(Long uid, Date date) { UserInfoExtra userInfoExtra = new UserInfoExtra(); userInfoExtra.setUserInfo(new UserInfo(uid)); userInfoExtra.setActiveTime(date); userInfoExtraMapper.updateInfoExtraByUid(userInfoExtra); } @Override public UserInfoExtraVO getInfoExtraVOByUid(Long uid) { return userInfoExtraMapper.getInfoExtraVOByUid(uid); } @Override public UserInfoExtra getUserInfoExtra(Long uid) { return userInfoExtraMapper.getInfoExtraByUid(uid); } @Override public String getInviteCodeByUid(Long uid) { UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid); if (userInfoExtra != null) { // vip邀请码优先 if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCodeVip())) return userInfoExtra.getInviteCodeVip(); @Override public UserInfoExtra getUserALLInfo(Long uid) { return userInfoExtraMapper.gerUserRank(uid); } if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) return userInfoExtra.getInviteCode(); @Override @Transactional public UserInfoExtra getByUidForUpdate(Long uid) { return userInfoExtraMapper.getByUidForUpdate(uid); } // 是否满足生产邀请码 int relationshipNum = threeSaleSerivce.getSuccessRelationshipNum(uid); if (relationshipNum > 0) { try { String inviteCode = createInviteCode(uid); if (!StringUtil.isNullOrEmpty(inviteCode)) { UserInfoExtra extra = new UserInfoExtra(); extra.setId(userInfoExtra.getId()); extra.setInviteCode(inviteCode); userInfoExtraMapper.updateByPrimaryKeySelective(extra); return inviteCode; } } catch (Exception e) { LogHelper.errorDetailInfo(e); } } } return ""; } @Override @Transactional public void updateGoldCoin(Long id, Integer goldCoin) { userInfoExtraMapper.updateGoldCoin(id, goldCoin); } /** * 生产邀请码 * * @param uid * @return */ private String createInviteCode(Long uid) { String inviteCode = null; for (int i = 1; i <= 5; i++) { inviteCode = UserUtil.getInviteCode(i, uid); long countCode = userInfoExtraMapper.countByInviteCode(inviteCode); if (countCode <= 0) break; } return inviteCode; } @Override public void addGoldCoinByUid(Long uid, Integer goldCoin) { userInfoExtraMapper.addGoldCoinByUid(uid, goldCoin); } @Override public long countByRankId(Long rankId) { return userInfoExtraMapper.countByRankId(rankId); } @Override public void updateByPrimaryKeySelective(UserInfoExtra record) { userInfoExtraMapper.updateByPrimaryKeySelective(record); } @Override public boolean isNewUser(Long uid) { boolean isNew = false; if (uid == null) { return isNew; } @Override public UserInfoExtraVO getInfoExtraVOByUid(Long uid) { return userInfoExtraMapper.getInfoExtraVOByUid(uid); } UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null && extra.getFirstLoginTime() != null) { try { int day = DateUtil.daysBetween(extra.getFirstLoginTime(), new Date()); if (day <= 15) { isNew = true; } } catch (ParseException e) { e.printStackTrace(); } } return isNew; } @Override public String getInviteCodeByUid(Long uid) { UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid); if (userInfoExtra != null) { // vip邀请码优先 if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCodeVip())) return userInfoExtra.getInviteCodeVip(); @Override public UserRank gerUserRank(Long uid) { if (uid == null) { return null; } if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode())) return userInfoExtra.getInviteCode(); UserInfoExtra userInfoExtra = userInfoExtraMapper.gerUserRank(uid); if (userInfoExtra == null) { return null; } return userInfoExtra.getUserRank(); } // 是否满足生产邀请码 int relationshipNum = threeSaleSerivce.getSuccessRelationshipNum(uid); if (relationshipNum > 0) { try { String inviteCode = createInviteCode(uid); if (!StringUtil.isNullOrEmpty(inviteCode)) { UserInfoExtra extra = new UserInfoExtra(); extra.setId(userInfoExtra.getId()); extra.setInviteCode(inviteCode); userInfoExtraMapper.updateByPrimaryKeySelective(extra); return inviteCode; } } catch (Exception e) { LogHelper.errorDetailInfo(e); } } } return ""; } @Override public UserInfo getUserByInviteCode(String inviteCode) throws UserInfoExtraException { if (StringUtil.isNullOrEmpty(inviteCode)) throw new UserInfoExtraException(1, "邀请码不能为空"); /** * 生产邀请码 * * @param uid * @return */ private String createInviteCode(Long uid) { String inviteCode = null; for (int i = 1; i <= 5; i++) { inviteCode = UserUtil.getInviteCode(i, uid); long countCode = userInfoExtraMapper.countByInviteCode(inviteCode); if (countCode <= 0) break; } return inviteCode; } UserInfo inviter = userInfoService.getUserInfoByInviteCode(inviteCode); if (inviter == null) throw new UserInfoExtraException(1, "上级邀请码不存在"); @Override public long countByRankId(Long rankId) { return userInfoExtraMapper.countByRankId(rankId); } if (inviter.getState() != UserInfo.STATE_NORMAL) { throw new UserInfoExtraException(1, "上级邀请码不存在"); } @Override public boolean isNewUser(Long uid) { boolean isNew = false; if (uid == null) { return isNew; } return inviter; } UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null && extra.getFirstLoginTime() != null) { try { int day = DateUtil.daysBetween(extra.getFirstLoginTime(), new Date()); if (day <= 15) { isNew = true; } } catch (ParseException e) { e.printStackTrace(); } } return isNew; } @Override public UserInfo getInviterInfo(Long uid, String wxUnionId) throws UserInfoExtraException { if (wxUnionId == null) { throw new UserInfoExtraException(1, "unionId信息不完整"); } @Override public UserRank gerUserRank(Long uid) { if (uid == null) { return null; } // 用户信息 UserInfo invitee = userInfoService.selectByPKey(uid); if (invitee == null) { throw new UserInfoExtraException(1, "用户不存在"); } UserInfoExtra userInfoExtra = userInfoExtraMapper.gerUserRank(uid); if (userInfoExtra == null) { return null; } return userInfoExtra.getUserRank(); } // 用户额外信息 UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null) { String inviteCodeHas = extra.getInviteCode(); if (inviteCodeHas != null && inviteCodeHas.trim().length() > 0) { throw new UserInfoExtraException(1, "已经激活, 无需再次激活"); } } @Override public UserInfo getUserByInviteCode(String inviteCode) throws UserInfoExtraException { if (StringUtil.isNullOrEmpty(inviteCode)) throw new UserInfoExtraException(1, "邀请码不能为空"); // 验证数据 String wxUnionIdExist = invitee.getWxUnionId(); if (StringUtil.isNullOrEmpty(wxUnionIdExist)) { UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(wxUnionId, invitee.getSystem()); if (newUser != null) { throw new UserInfoExtraException(1, "此微信已被其他帐号绑定"); } } else if (!wxUnionId.equals(wxUnionIdExist)) { throw new UserInfoExtraException(1, "绑定微信与激活微信不一致"); } UserInfo inviter = userInfoService.getUserInfoByInviteCode(inviteCode); if (inviter == null) throw new UserInfoExtraException(1, "上级邀请码不存在"); if (inviter.getState() != UserInfo.STATE_NORMAL) { throw new UserInfoExtraException(1, "上级邀请码不存在"); } // 邀请人ID Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); if (inviterId == null) { throw new UserInfoExtraException(1, "没有对应的邀请关系"); } return inviter; } UserInfo inviter = userInfoService.selectByPKey(inviterId); if (inviter == null) { throw new UserInfoExtraException(1, "对应的邀请关系不存在"); } @Override public UserInfo getInviterInfo(Long uid, String wxUnionId) throws UserInfoExtraException { if (wxUnionId == null) { throw new UserInfoExtraException(1, "unionId信息不完整"); } if (inviter.getState() != UserInfo.STATE_NORMAL) { throw new UserInfoExtraException(1, "对应的邀请关系不存在"); } // 用户信息 UserInfo invitee = userInfoService.selectByPKey(uid); if (invitee == null) { throw new UserInfoExtraException(1, "用户不存在"); } return inviter; } // 用户额外信息 UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra != null) { String inviteCodeHas = extra.getInviteCode(); if (inviteCodeHas != null && inviteCodeHas.trim().length() > 0) { throw new UserInfoExtraException(1, "已经激活, 无需再次激活"); } } // 验证数据 String wxUnionIdExist = invitee.getWxUnionId(); if (StringUtil.isNullOrEmpty(wxUnionIdExist)) { UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(wxUnionId,invitee.getSystem()); if (newUser != null) { throw new UserInfoExtraException(1, "此微信已被其他帐号绑定"); } } else if (!wxUnionId.equals(wxUnionIdExist)) { throw new UserInfoExtraException(1, "绑定微信与激活微信不一致"); } @Transactional(rollbackFor = Exception.class) @Override public void updateInviteCodeVip(String inviteCodeVip, Long uid) throws UserInfoExtraException { if (inviteCodeVip == null || inviteCodeVip.length() < 4 || inviteCodeVip.length() > 12) throw new UserInfoExtraException(1, "邀请码必须为4到12位"); // 邀请人ID Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId); if (inviterId == null) { throw new UserInfoExtraException(1, "没有对应的邀请关系"); } UserInfoExtra extra = getUserInfoExtra(uid); if (extra == null) throw new UserInfoExtraException(2, "用户信息不存在"); UserInfo inviter = userInfoService.selectByPKey(inviterId); if (inviter == null) { throw new UserInfoExtraException(1, "对应的邀请关系不存在"); } if (inviter.getState() != UserInfo.STATE_NORMAL) { throw new UserInfoExtraException(1, "对应的邀请关系不存在"); } return inviter; } if (StringUtil.isNullOrEmpty(extra.getInviteCode())) throw new UserInfoExtraException(3, "邀请码尚未激活"); if (!StringUtil.isNullOrEmpty(extra.getInviteCodeVip())) throw new UserInfoExtraException(4, "只能修改一次"); @Transactional(rollbackFor = Exception.class) @Override public void updateInviteCodeVip(String inviteCodeVip, Long uid) throws UserInfoExtraException { if (inviteCodeVip == null || inviteCodeVip.length() < 4 || inviteCodeVip.length() > 12) throw new UserInfoExtraException(1, "邀请码必须为4到12位"); // 转换成大写 inviteCodeVip = inviteCodeVip.toUpperCase(); UserInfoExtra extra = getUserInfoExtra(uid); if (extra == null) throw new UserInfoExtraException(2, "用户信息不存在"); // 验证特殊码 if (InviteCodeFilterUtil.isSpecialCode(inviteCodeVip)) throw new UserInfoExtraException(5, "邀请码已存在"); if (StringUtil.isNullOrEmpty(extra.getInviteCode())) throw new UserInfoExtraException(3, "邀请码尚未激活"); if (inviteCodeVip.equalsIgnoreCase(extra.getInviteCode())) throw new UserInfoExtraException(5, "不能为原邀请码"); if (!StringUtil.isNullOrEmpty(extra.getInviteCodeVip())) throw new UserInfoExtraException(4, "只能修改一次"); long count = userInfoExtraMapper.countByInviteCode(inviteCodeVip); if (count > 0) throw new UserInfoExtraException(6, "邀请码已存在"); // 转换成大写 inviteCodeVip = inviteCodeVip.toUpperCase(); UserInfoExtra update = new UserInfoExtra(); update.setId(extra.getId()); update.setInviteCodeVip(inviteCodeVip); update.setUpdateTime(new Date()); userInfoExtraMapper.updateByPrimaryKeySelective(update); // 验证特殊码 if (InviteCodeFilterUtil.isSpecialCode(inviteCodeVip)) throw new UserInfoExtraException(5, "邀请码已存在"); if (!Constant.IS_TEST) { // 发送邀请码更改成功的消息 Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userInfoUpdate, new UserInfoUpdateMQMsg(uid, UserInfoUpdateTypeEnum.inviteCode, inviteCodeVip, new Date())); rocketMQManager.sendNormalMsg(message, null); } if (inviteCodeVip.equalsIgnoreCase(extra.getInviteCode())) throw new UserInfoExtraException(5, "不能为原邀请码"); // 消息 userAccountMsgNotificationService.createChangeInviteCode(uid, extra.getInviteCode(), inviteCodeVip); } long count = userInfoExtraMapper.countByInviteCode(inviteCodeVip); if (count > 0) throw new UserInfoExtraException(6, "邀请码已存在"); @Override public void uploadERCode(MultipartFile file, Long uid) { UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra == null) return; UserInfoExtra update = new UserInfoExtra(); update.setId(extra.getId()); update.setInviteCodeVip(inviteCodeVip); update.setUpdateTime(new Date()); userInfoExtraMapper.updateByPrimaryKeySelective(update); // 压缩 String targetPath = FileUtil.getCacheDir() + "/erCode_" + uid + "_" + System.currentTimeMillis() + ".jpg"; try { Thumbnails.of(file.getInputStream()).size(200, 200).toFile(targetPath); } catch (IOException e) { LogHelper.errorDetailInfo(e); return; } if (!Constant.IS_TEST) { // 发送邀请码更改成功的消息 Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userInfoUpdate, new UserInfoUpdateMQMsg(uid, UserInfoUpdateTypeEnum.inviteCode, inviteCodeVip, new Date())); rocketMQManager.sendNormalMsg(message, null); } // 消息 userAccountMsgNotificationService.createChangeInviteCode(uid, extra.getInviteCode(), inviteCodeVip); } // 执行上传 String filePath = FilePathEnum.userERcode.getPath() + UUID.randomUUID().toString().replace("-", "") + ".jpg"; String fileLink = COSManager.getInstance().uploadFile(new File(targetPath), filePath).getUrl(); @Override public void uploadERCode(MultipartFile file, Long uid) { UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid); if (extra == null) return; // 删除本地图片 if (new File(targetPath).exists()) { new File(targetPath).delete(); } // 压缩 String targetPath = FileUtil.getCacheDir() + "/erCode_" + uid + "_" + System.currentTimeMillis() + ".jpg"; try { Thumbnails.of(file.getInputStream()).size(200, 200).toFile(targetPath); } catch (IOException e) { LogHelper.errorDetailInfo(e); return; } // 原二维码 String erCode = extra.getErCode(); // 执行上传 String filePath = FilePathEnum.userERcode.getPath() + UUID.randomUUID().toString().replace("-", "") + ".jpg"; String fileLink = COSManager.getInstance().uploadFile(new File(targetPath), filePath).getUrl(); UserInfoExtra update = new UserInfoExtra(); update.setId(extra.getId()); update.setErCode(fileLink); userInfoExtraMapper.updateByPrimaryKeySelective(update); // 删除本地图片 if (new File(targetPath).exists()) { new File(targetPath).delete(); } // 原二维码 if (!StringUtil.isNullOrEmpty(erCode)) { COSManager.getInstance().deleteFile(erCode); } } // 原二维码 String erCode = extra.getErCode(); @Resource private UserGoodsChannelConfigDao userGoodsChannelConfigDao; UserInfoExtra update = new UserInfoExtra(); update.setId(extra.getId()); update.setErCode(fileLink); userInfoExtraMapper.updateByPrimaryKeySelective(update); @Override public String getPddFanliCustomerParams(Long uid) { UserGoodsChannelConfig config = userGoodsChannelConfigDao.get(uid); if (config == null || StringUtil.isNullOrEmpty(config.getPddFanliCustomerParams())) { return uid + ""; } return config.getPddFanliCustomerParams(); } // 原二维码 if (!StringUtil.isNullOrEmpty(erCode)) { COSManager.getInstance().deleteFile(erCode); } } } fanli/src/main/java/com/yeshi/fanli/service/inter/user/UserInfoExtraService.java
@@ -202,5 +202,9 @@ * @param uid */ public void uploadERCode(MultipartFile file, Long uid); public String getPddFanliCustomerParams(Long uid); } fanli/src/main/java/com/yeshi/fanli/service/manger/JobManager.java
New file @@ -0,0 +1,1325 @@ package com.yeshi.fanli.service.manger; import com.google.gson.Gson; import com.yeshi.fanli.dto.ad.DouYinDeviceActiveQueueDTO; import com.yeshi.fanli.dto.money.UserMoneyChangeDTO; import com.yeshi.fanli.dto.mq.UidDateDTO; import com.yeshi.fanli.dto.push.PushContentDetailDTO; import com.yeshi.fanli.entity.ad.DouYinClickEvent; import com.yeshi.fanli.entity.bus.user.*; import com.yeshi.fanli.entity.jd.JDOrder; import com.yeshi.fanli.entity.order.CommonOrder; import com.yeshi.fanli.entity.order.HongBaoOrder; import com.yeshi.fanli.entity.pdd.PDDOrder; import com.yeshi.fanli.entity.push.DeviceActive; import com.yeshi.fanli.entity.push.PushQueueRecord; import com.yeshi.fanli.entity.suning.SuningOrderInfo; import com.yeshi.fanli.entity.taobao.TaoBaoOrder; import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder; import com.yeshi.fanli.entity.vipshop.VipShopOrder; import com.yeshi.fanli.exception.order.TaoBaoWeiQuanException; import com.yeshi.fanli.exception.order.dividents.TeamDividentsRecordException; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.impl.JobThreadExecutorServiceImpl; import com.yeshi.fanli.service.inter.ad.DouYinClickEventService; import com.yeshi.fanli.service.inter.lable.BoutiqueAutoRuleService; import com.yeshi.fanli.service.inter.money.UserMoneyDebtService; import com.yeshi.fanli.service.inter.money.extract.ExtractService; import com.yeshi.fanli.service.inter.order.CommonOrderService; import com.yeshi.fanli.service.inter.order.HongBaoOrderService; import com.yeshi.fanli.service.inter.order.HongBaoV2Service; import com.yeshi.fanli.service.inter.order.OrderProcessService; import com.yeshi.fanli.service.inter.order.jd.JDOrderService; import com.yeshi.fanli.service.inter.order.pdd.PDDOrderService; import com.yeshi.fanli.service.inter.order.suning.SuningOrderService; import com.yeshi.fanli.service.inter.order.tb.TaoBaoOrderService; import com.yeshi.fanli.service.inter.order.vipshop.VipShopOrderService; import com.yeshi.fanli.service.inter.push.DeviceActiveService; import com.yeshi.fanli.service.inter.push.HWPushService; import com.yeshi.fanli.service.inter.push.IOSPushService; import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService; import com.yeshi.fanli.service.inter.user.integral.IntegralGetService; import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService; import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce; import com.yeshi.fanli.service.manger.money.TeamEincomeManager; import com.yeshi.fanli.service.manger.order.TeamDividentsManager; import com.yeshi.fanli.util.CMQManager; import com.yeshi.fanli.util.RedisKeyEnum; import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.ad.DouYinAdUtil; import com.yeshi.fanli.util.mq.cmq.DouYinDeviceActiveCMQManager; import com.yeshi.fanli.util.mq.cmq.HongBaoRecieveCMQManager; import com.yeshi.fanli.util.mq.cmq.PushCMQManager; import com.yeshi.fanli.util.mq.cmq.UserMoneyChangeCMQManager; import com.yeshi.fanli.util.mq.cmq.order.*; import com.yeshi.fanli.util.taobao.TaoKeApiUtil; import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; import org.springframework.core.task.TaskExecutor; import org.springframework.stereotype.Component; import org.yeshi.utils.NumberUtil; import org.yeshi.utils.TimeUtil; import javax.annotation.Resource; import java.lang.reflect.Method; import java.math.BigDecimal; import java.util.*; @Component public class JobManager { @Resource private BoutiqueAutoRuleService boutiqueAutoRuleService; @Resource private ExtractService extractService; @Resource private IOSPushService iosPushService; @Resource(name = "taskExecutor") private TaskExecutor executor; @Resource private OrderProcessService orderProcessService; @Resource private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService; @Resource private ThreeSaleSerivce threeSaleSerivce; @Resource private TaoBaoOrderService taoBaoOrderService; @Resource private RedisManager redisManager; @Resource private UserMoneyDebtService userMoneyDebtService; @Resource private JDOrderService jdOrderService; @Resource private PDDOrderService pddOrderService; @Resource private HongBaoV2Service hongBaoV2Service; @Resource private IntegralGetService integralGetService; @Resource private CommonOrderService commonOrderService; @Resource private HongBaoOrderService hongBaoOrderService; @Resource private IntegralTaskRecordService integralTaskRecordService; @Resource private DeviceActiveService deviceActiveService; @Resource private TeamDividentsManager teamDividentsManager; @Resource private TeamEincomeManager teamEincomeManager; @Resource private VipShopOrderService vipShopOrderService; @Resource private SuningOrderService suningOrderService; @Resource private HWPushService hwPushService; private Map<String, Long> latestRunTimeMap = new HashMap<>(); class MyRunnable implements Runnable { private String method; public MyRunnable(String methodName) { this.method = methodName; } @Override public void run() { latestRunTimeMap.put(method, System.currentTimeMillis()); } } /** * 开始任务 */ public void start() { doExtractResult();// 处理提现结果 doTaoBaoOrders();// 处理淘宝订单 doTaoBaoNewOrders();// 处理淘宝订单(刚刚产生的) doOrderFanLiNew();// 新版返利 doOrderShareFanLi(); doWeiQuanOrder();// 处理维权订单 doPushIOS();// 处理发送IOS消息 doUserMoneyDebtJob();// 债务偿还 initScheduler();// 启动商品更新定时任务 doUpdateGoodsJob(); // 更新商品队列 doJDOrderJob();// 京东订单处理 doPDDOrderJob();// 拼多多订单处理 doVipShopOrderJob();// 唯品会订单处理 doSuningOrderJob();// 苏宁订单处理 doImportantTaoBaoGoodsUpdateJob();// 淘宝重要商品的信息更新 doHongBaoRecieveIntegralGetJob();// 返利到账,金币增加 // doPlaceOrderIntegralJob();// 下单赠送金币任务 // doDouYinDeviceActiveJob();// 抖音设备激活广告监测 doOrderTeamIncomePreFanLi();// 处理订单提成返利 doDividentsPreJob(); doOrderTeamRewardFanLi(); doDividentsJob(); //华为推送 doHWPushJob(); } /** * 修复未运行的 */ public void repaire() { for (Iterator<String> its = latestRunTimeMap.keySet().iterator(); its.hasNext(); ) { String methodName = its.next(); //15分钟以上的需要修复 if (System.currentTimeMillis() - latestRunTimeMap.get(methodName).longValue() > 1000 * 60 * 15L) { try { Method method = this.getClass().getMethod(methodName); method.invoke(this); } catch (Exception e) { } } } } /** * 获取方法名称 * * @param thread * @return */ private String getMethodName(Thread thread) { return thread.getStackTrace()[2].getMethodName(); } /** * 处理提现结果的队列 */ public void doExtractResult() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, AlipayTransferResultInfo> map = CMQManager.getInstance().consumeExtractResultMsg(1); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { extractService.processExtractResult(map.get(key)); CMQManager.getInstance().deleteExtractResultMsg(key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { } } }); } /** * 处理淘宝订单 */ public void doTaoBaoOrders() { String methodName = getMethodName(Thread.currentThread()); // 同时开启3个线程处理 for (int i = 0; i < 3; i++) { new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { // 取16个订单 List<String> orderIds = CMQManager.getInstance().consumeTaoBaoOrderMsg(16); if (orderIds != null) { for (String orderId : orderIds) { if (NumberUtil.isNumeric(orderId.trim())) { Map<String, List<TaoBaoOrder>> map = new HashMap<>(); List<TaoBaoOrder> orderList = taoBaoOrderService .getTaoBaoOrderByOrderId(orderId); map.put(orderId, orderList); LogHelper.orderInfo("开始处理订单:" + orderId); orderProcessService.processOrder(map); LogHelper.orderInfo("结束处理订单:" + orderId); } } } } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { } } } }); } } /** * 刚刚产生的订单 */ public void doTaoBaoNewOrders() { String methodName = getMethodName(Thread.currentThread()); // 同时开启3个线程处理 for (int i = 0; i < 1; i++) { new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { // 取16个订单 List<String> orderIds = CMQManager.getInstance().consumeTaoBaoNewOrderMsg(16); Map<String, List<TaoBaoOrder>> map = new HashMap<>(); if (orderIds != null) { for (String orderId : orderIds) { List<TaoBaoOrder> orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(orderId); map.put(orderId, orderList); LogHelper.orderInfo("新订单-开始处理订单:" + orderId); long startTime = System.currentTimeMillis(); orderProcessService.processOrder(map); LogHelper.orderInfo("新订单-结束处理订单:" + orderId + "- 处理时间:" + (System.currentTimeMillis() - startTime)); } } } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { } } } }); } } /** * 处理新版淘宝订单返利 */ public void doOrderFanLiNew() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, HongBaoV2> map = CMQManager.getInstance().consumeFanLiMsgNew(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String handler = its.next(); try { HongBaoV2 hongbao = map.get(handler); if (hongbao != null) { String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.hongBaoFanLi, hongbao.getId() + ""); if (StringUtil.isNullOrEmpty(redisManager.getCommonString(key))) { // 处理之后要隔2小时再次进行处理 redisManager.cacheCommonString(key, "1", 60 * 60 * 2); orderProcessService.fanli(map.get(handler)); } } CMQManager.getInstance().deleteFanLiMsgNew(handler); } catch (TaoBaoWeiQuanException e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } catch (Exception e) { try { LogHelper.errorDetailInfo(e, "HongBaoV2-ID:" + map.get(handler).getId(), ""); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { } } }); } /** * 处理团队订单返利 */ public void doOrderTeamIncomePreFanLi() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, UidDateDTO> map = TeamOrderCMQManager.getInstance() .consumeFanLiTeamIncomePreMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String handler = its.next(); try { UidDateDTO dto = map.get(handler); orderProcessService.fanliPreInvaite(dto.getUid(), dto.getDate()); TeamOrderCMQManager.getInstance().deleteTeamIncomePreMsg(handler); } catch (Exception e) { try { LogHelper.errorDetailInfo(e, new Gson().toJson(map.get(handler)).toString(), ""); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { } } }); } /** * 处理团队奖金返利 */ public void doOrderTeamRewardFanLi() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, UidDateDTO> map = TeamOrderCMQManager.getInstance().consumeFanLiTeamIncomeMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String handler = its.next(); try { UidDateDTO dto = map.get(handler); teamEincomeManager.addTeamRewardTOUserAccount(dto.getDate(), dto.getUid()); TeamOrderCMQManager.getInstance().deleteTeamIncomeMsg(handler); } catch (Exception e) { try { LogHelper.errorDetailInfo(e, map.get(handler).toString(), ""); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { } } }); } /** * 处理分享订单返利 */ public void doOrderShareFanLi() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, UidDateDTO> map = CMQManager.getInstance().consumeFanLiShareMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String handler = its.next(); try { UidDateDTO dto = map.get(handler); orderProcessService.fanliShare(dto.getUid(), dto.getDate()); CMQManager.getInstance().deleteFanLiShareMsg(handler); } catch (Exception e) { try { LogHelper.errorDetailInfo(e, map.get(handler).toString(), ""); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { } } }); } /** * 处理淘宝订单维权 */ public void doWeiQuanOrder() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, TaoBaoWeiQuanOrder> map = CMQManager.getInstance().consumeWeiQuanOrderMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String handler = its.next(); try { orderProcessService.weiQuanOrder(map.get(handler)); CMQManager.getInstance().deleteWeiQuanOrderMsg(handler); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { } } }); } /** * IOS 推送消息 */ public void doPushIOS() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, PushQueueRecord> map = CMQManager.getInstance().consumeIOSPushMsg(10); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { iosPushService.readyPushIOS(map.get(key)); CMQManager.getInstance().deleteIOSPushMsg(key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { LogHelper.errorDetailInfo(e); } } }); } /** * 创建Scheduler()执行自动爬取 */ private void initScheduler() { boutiqueAutoRuleService.startScheduler(); } /** * 更新精选库商品 */ public void doUpdateGoodsJob() { String methodName = getMethodName(Thread.currentThread()); for (int i = 0; i < 1; i++) new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, Long> map = CMQManager.getInstance().consumeNeedUpdateTaoBaoGoodsIdMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); taoBaoGoodsUpdateService.updateByTaoKeGoodsDetail(Long.parseLong(key)); CMQManager.getInstance().deleteNeedUpdateTaoBaoGoodsIdMsg(key); } } } catch (Exception e) { e.printStackTrace(); LogHelper.error("更新商品出错:" + e.getMessage()); } } }); } /** * 用户借贷处理 */ public void doUserMoneyDebtJob() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, UserMoneyChangeDTO> map = UserMoneyChangeCMQManager.getInstance() .consumeQueueMsg(UserMoneyChangeCMQManager.QUEUE_DEBT, 16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { UserMoneyChangeDTO dto = map.get(key); if (dto != null && dto.getChangeMoney().compareTo(new BigDecimal(0)) > 0) { userMoneyDebtService.repayDebt(dto.getUid()); } UserMoneyChangeCMQManager.getInstance() .deleteQueueMsg(UserMoneyChangeCMQManager.QUEUE_DEBT, key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { LogHelper.error("还款出错:" + e.getMessage()); } } }); } public void doJDOrderJob() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, String> map = JDOrderCMQManager.getInstance().consumeJDOrder(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { String orderId = map.get(key); if (!StringUtil.isNullOrEmpty(orderId)) { JDOrder order = jdOrderService.selectDetailByOrderId(Long.parseLong(orderId)); orderProcessService.processJDOrder(order); } JDOrderCMQManager.getInstance().deleteJDOrder(key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { LogHelper.error("拼多多订单出错:" + e.getMessage()); } } }); } public void doPDDOrderJob() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, String> map = PDDOrderCMQManager.getInstance().consumePDDOrder(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { String orderId = map.get(key); if (!StringUtil.isNullOrEmpty(orderId)) { List<PDDOrder> orderList = pddOrderService.selectByOrderSn(orderId); if (orderList != null) for (PDDOrder order : orderList) orderProcessService.processPDDOrder(order); } PDDOrderCMQManager.getInstance().deletePDDOrder(key); } catch (Exception e) { LogHelper.errorDetailInfo(e); } } } } catch (Exception e) { LogHelper.error("拼多多订单:" + e.getMessage()); } } }); } public void doVipShopOrderJob() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, String> map = VipShopOrderCMQManager.getInstance().consumeVipShopOrder(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { String orderId = map.get(key); LogHelper.test("唯品会订单消费:" + orderId); if (!StringUtil.isNullOrEmpty(orderId)) { List<VipShopOrder> orderList = vipShopOrderService.listDetailByOrderSn(orderId); if (orderList != null) for (VipShopOrder order : orderList) orderProcessService.processVipShopOrder(order); } VipShopOrderCMQManager.getInstance().deleteVipShopOrder(key); } catch (Exception e) { LogHelper.errorDetailInfo(e); } } } } catch (Exception e) { LogHelper.errorDetailInfo(e); } } }); } public void doSuningOrderJob() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); try { Map<String, String> map = SuningOrderCMQManager.getInstance().consumeSuningOrder(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { String orderId = map.get(key); if (!StringUtil.isNullOrEmpty(orderId)) { List<SuningOrderInfo> orderList = suningOrderService.listByOrderCode(orderId); if (orderList != null) for (SuningOrderInfo order : orderList) orderProcessService.processSuningOrder(order); } SuningOrderCMQManager.getInstance().deleteSuningOrder(key); } catch (Exception e) { LogHelper.errorDetailInfo(e); } } } } catch (Exception e) { LogHelper.errorDetailInfo(e); } } }); } /** * 重要的淘宝商品信息更新 */ public void doImportantTaoBaoGoodsUpdateJob() { String methodName = getMethodName(Thread.currentThread()); // 开启2个线程做更新 for (int i = 0; i < 2; i++) new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); Map<String, Long> map = CMQManager.getInstance().consumeTBImpGoodsUpdateMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { long startTime = System.currentTimeMillis(); TaoBaoGoodsBrief goods = TaoKeApiUtil.searchGoodsDetail(map.get(key)); // 更新一条数据需要的时间 taoBaoGoodsUpdateService.updateTaoBaoGoods(goods); long time = System.currentTimeMillis() - startTime; LogHelper.test("淘宝重要商品库更新时间:" + time); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } finally { CMQManager.getInstance().deleteTBImpGoodsUpdateMsg(key); } } } } }); } /** * 红包到账后的金币获取 */ public void doHongBaoRecieveIntegralGetJob() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); Map<String, Long> map = HongBaoRecieveCMQManager.getInstance() .consumeQueueMsg(HongBaoRecieveCMQManager.QUEUE_INTEGRAL, 16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); Long hongBaoId = map.get(key); try { HongBaoV2 hongBaoV2 = hongBaoV2Service.selectByPrimaryKey(hongBaoId); if (hongBaoV2 != null && hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU && hongBaoV2.getMoney().compareTo(new BigDecimal(0)) > 0) { // 到账送金币 fanliGetIntegral(hongBaoV2); HongBaoRecieveCMQManager.getInstance() .deleteQueueMsg(HongBaoRecieveCMQManager.QUEUE_INTEGRAL, key); // 返利不足0.01元送金币 if (hongBaoV2.getType() == HongBaoV2.TYPE_ZIGOU) {// 自购 // 判断是否为该用户的首笔红包 List<Integer> typeList = new ArrayList<>(); typeList.add(HongBaoV2.TYPE_ZIGOU); HongBaoV2 firstHongBao = hongBaoV2Service.getFirstValidHongBaoByTypeAndUid( typeList, hongBaoV2.getUserInfo().getId()); if (firstHongBao != null && firstHongBao.getId().longValue() == hongBaoV2.getId()) {// 自购首单到账 // 查询下级红包 BigDecimal firstLevelMoney = new BigDecimal(0); BigDecimal secondLevelMoney = new BigDecimal(0); // 获取改单下面的红包 List<HongBaoV2> hongBaoList = new ArrayList<>(); HongBaoOrder hongBaoOrder = hongBaoOrderService .selectDetailByHongBaoId(hongBaoV2.getId()); if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {// 计算改订单号下面的所有返利金额 CommonOrder commonOrder = hongBaoOrder.getCommonOrder(); List<CommonOrder> list = commonOrderService.listBySourceTypeAndOrderId( commonOrder.getSourceType(), commonOrder.getOrderNo()); for (CommonOrder co : list) { HongBaoOrder hbo = hongBaoOrderService .selectDetailByCommonOrderId(co.getId()); if (hbo != null && hbo.getHongBaoV2() != null) hongBaoList.add(hbo.getHongBaoV2()); } } for (HongBaoV2 hb : hongBaoList) { List<HongBaoV2> children = hongBaoV2Service .listChildrenById(hb.getId()); if (children != null) for (HongBaoV2 child : children) if (child.getType() == HongBaoV2.TYPE_YIJI) { firstLevelMoney = firstLevelMoney.add(child.getMoney()); } else if (child.getType() == HongBaoV2.TYPE_ERJI) { secondLevelMoney = secondLevelMoney.add(child.getMoney()); } } // 查询下级的生效时间 ThreeSale threeSale = threeSaleSerivce.selectLatestByWorkerIdAndState( hongBaoV2.getUserInfo().getId(), ThreeSale.STATE_SUCCESS); if (threeSale != null && threeSale.getSucceedTime() != null && threeSale .getSucceedTime() < hongBaoV2.getCreateTime().getTime()) {// 邀请成功的时间是否在下单的时间之前 // 成功时间要大于20190910日才开始送金币 if (threeSale.getSucceedTime() > TimeUtil.convertToTimeTemp("20190901", "yyyyMMdd")) { if (firstLevelMoney.compareTo(new BigDecimal("0.01")) < 0) {// 一级返利小于0.01 integralTaskRecordService.firstRebateOrderRewardBoss( threeSale.getBoss().getId(), hongBaoV2.getUserInfo().getId(), null); LogHelper.test("自购-一级用户-" + threeSale.getBoss().getId() + "-hongBaoId:" + hongBaoV2.getId()); } } } // 查询下下级生效时间 if (threeSale != null) { threeSale = threeSaleSerivce.selectLatestByWorkerIdAndState( threeSale.getBoss().getId(), ThreeSale.STATE_SUCCESS); if (threeSale != null && threeSale.getSucceedTime() != null && threeSale .getSucceedTime() < hongBaoV2.getCreateTime().getTime()) {// 邀请成功的时间是否在下单的时间之前 // 成功时间要大于20190910日才开始送金币 if (threeSale.getSucceedTime() > TimeUtil .convertToTimeTemp("20190901", "yyyyMMdd")) { if (secondLevelMoney.compareTo(new BigDecimal("0.01")) < 0) {// 二级返利小于0.01 integralTaskRecordService.firstRebateOrderRewardBossSuper( threeSale.getBoss().getId(), hongBaoV2.getUserInfo().getId(), null); LogHelper.test("自购-二级用户-" + threeSale.getBoss().getId() + "-hongBaoId:" + hongBaoV2.getId()); } } } } } } else if (hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_GOODS) {// 分享赚 // 判断是否为该用户的首笔红包 List<Integer> typeList = new ArrayList<>(); typeList.add(HongBaoV2.TYPE_SHARE_GOODS); HongBaoV2 firstHongBao = hongBaoV2Service.getFirstValidHongBaoByTypeAndUid( typeList, hongBaoV2.getUserInfo().getId()); if (firstHongBao != null && firstHongBao.getId().longValue() == hongBaoV2.getId()) // 分享首笔到账 { // 查询下级红包 BigDecimal firstLevelMoney = new BigDecimal(0); // 获取改单下面的红包 List<HongBaoV2> hongBaoList = new ArrayList<>(); HongBaoOrder hongBaoOrder = hongBaoOrderService .selectDetailByHongBaoId(hongBaoV2.getId()); if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {// 计算改订单号下面的所有返利金额 CommonOrder commonOrder = hongBaoOrder.getCommonOrder(); List<CommonOrder> list = commonOrderService.listBySourceTypeAndOrderId( commonOrder.getSourceType(), commonOrder.getOrderNo()); for (CommonOrder co : list) { HongBaoOrder hbo = hongBaoOrderService .selectDetailByCommonOrderId(co.getId()); if (hbo != null && hbo.getHongBaoV2() != null) hongBaoList.add(hbo.getHongBaoV2()); } } for (HongBaoV2 hb : hongBaoList) { List<HongBaoV2> children = hongBaoV2Service .listChildrenById(hb.getId()); if (children != null) for (HongBaoV2 child : children) if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) { firstLevelMoney = firstLevelMoney.add(child.getMoney()); } } ThreeSale threeSale = threeSaleSerivce.selectLatestByWorkerIdAndState( hongBaoV2.getUserInfo().getId(), ThreeSale.STATE_SUCCESS); if (threeSale != null && threeSale.getSucceedTime() != null && threeSale .getSucceedTime() < hongBaoV2.getCreateTime().getTime()) {// 邀请成功的时间是否在下单的时间之前 // 成功时间要大于20190910日才开始送金币 if (threeSale.getSucceedTime() > TimeUtil.convertToTimeTemp("20190901", "yyyyMMdd")) { if (firstLevelMoney.compareTo(new BigDecimal("0.01")) < 0) {// 一级返利小于0.01 integralTaskRecordService.firstSharerOrderRewardBoss( threeSale.getBoss().getId(), hongBaoV2.getUserInfo().getId(), null); LogHelper.test("分享-一级用户-" + threeSale.getBoss().getId() + "-hongBaoId:" + hongBaoV2.getId()); } } } } } } } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } finally { } } } } }); } private void fanliGetIntegral(HongBaoV2 hongBaoV2) { if (hongBaoV2 != null && hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU && hongBaoV2.getMoney().compareTo(new BigDecimal(0)) > 0) { // 查询对应的订单号 Long mainHongBaoId = hongBaoV2.getId(); if (hongBaoV2.getParent() != null && hongBaoV2.getParent().getId() != null) mainHongBaoId = hongBaoV2.getParent().getId(); HongBaoOrder hongbaoOrder = hongBaoOrderService.selectDetailByHongBaoId(mainHongBaoId); if (hongbaoOrder == null || hongbaoOrder.getCommonOrder() == null) return; CommonOrder commonOrder = hongbaoOrder.getCommonOrder(); if (hongBaoV2.getType() == HongBaoV2.TYPE_ZIGOU) {// 自购订单 integralGetService.addRebateOrder(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(), commonOrder.getSourceType()); } else if (hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_GOODS) {// 分享订单 integralGetService.addShareOrder(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(), commonOrder.getSourceType()); } else if (hongBaoV2.getType() == HongBaoV2.TYPE_YIJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_YIJI) {// 一级邀请 integralGetService.addInviteOrderLevelOne(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(), commonOrder.getSourceType()); } else if (hongBaoV2.getType() == HongBaoV2.TYPE_ERJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_ERJI) {// 二级邀请 integralGetService.addInviteOrderLevelTwo(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(), commonOrder.getSourceType()); } } } private boolean isFirstValidOrder(String orderId, int sourceType, Long uid) { CommonOrder commonOrder = commonOrderService.selectLatestValidByUid(uid); if (commonOrder != null && commonOrder.getOrderNo().equalsIgnoreCase(orderId) && sourceType == commonOrder.getSourceType()) return true; else return false; } // 下单获取金币任务 public void doPlaceOrderIntegralJob() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); Map<String, Order> map = PlaceOrderCMQManager.getInstance() .consumeQueueMsg(PlaceOrderCMQManager.QUEUE_INTEGRAL, 16); if (map != null) { for (Iterator<String> its = map.keySet().iterator(); its.hasNext(); ) { try { String key = its.next(); Order order = map.get(key); // 是否是首单 if (isFirstValidOrder(order.getOrderId(), order.getOrderType(), order.getUserInfo().getId())) { // 统计订单下的用户所获得的返利金额 List<CommonOrder> list = commonOrderService .listBySourceTypeAndOrderId(order.getOrderType(), order.getOrderId()); Map<Long, BigDecimal> hongBaoMoney = new HashMap<>(); if (list != null) for (CommonOrder commonOrder : list) { HongBaoOrder hongBaoOrder = hongBaoOrderService .selectDetailByCommonOrderId(commonOrder.getId()); if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null) { Long mainUid = hongBaoOrder.getHongBaoV2().getUserInfo().getId(); if (hongBaoMoney.get(mainUid) == null) hongBaoMoney.put(mainUid, new BigDecimal(0)); hongBaoMoney.put(mainUid, hongBaoMoney.get(mainUid) .add(hongBaoOrder.getHongBaoV2().getMoney())); // 查询上级 List<HongBaoV2> children = hongBaoV2Service .listChildrenById(hongBaoOrder.getHongBaoV2().getId()); if (children != null) { for (HongBaoV2 hongBao : children) { Long uid = hongBao.getUserInfo().getId(); if (hongBaoMoney.get(uid) == null) hongBaoMoney.put(uid, new BigDecimal(0)); hongBaoMoney.put(uid, hongBaoMoney.get(uid).add(hongBao.getMoney())); } } } } if (isFirstValidOrder(order.getOrderId(), order.getOrderType(), order.getUserInfo().getId())) {// 有效的首单 if (hongBaoMoney.get(order.getUserInfo().getId()) == null || hongBaoMoney .get(order.getUserInfo().getId()).compareTo(new BigDecimal("0")) <= 0) { // 分享奖金是0 integralTaskRecordService.firstShareOrderReward(order.getUserInfo().getId(), null); } // 获取上两级数据 UserInfo boss = threeSaleSerivce.getBoss(order.getUserInfo().getId()); if (boss != null) {// 判断上级的红包 if (hongBaoMoney.get(boss.getId()) == null || hongBaoMoney.get(boss.getId()) .compareTo(new BigDecimal("0")) <= 0) { // 补偿金币 integralTaskRecordService.firstSharerOrderRewardBoss(boss.getId(), order.getUserInfo().getId(), null); } } } else {// 自购订单 UserInfo boss = threeSaleSerivce.getBoss(order.getUserInfo().getId()); if (boss != null) {// 判断上级的红包 if (hongBaoMoney.get(boss.getId()) == null || hongBaoMoney.get(boss.getId()) .compareTo(new BigDecimal("0")) <= 0) { // 补偿金币1级 integralTaskRecordService.firstRebateOrderRewardBoss(boss.getId(), order.getUserInfo().getId(), null); } boss = threeSaleSerivce.getBoss(boss.getId()); if (boss != null) {// 判断上级的红包 if (hongBaoMoney.get(boss.getId()) == null || hongBaoMoney .get(boss.getId()).compareTo(new BigDecimal("0")) <= 0) { // 补偿金币2级 integralTaskRecordService.firstRebateOrderRewardBossSuper( boss.getId(), order.getUserInfo().getId(), null); } } } } } PlaceOrderCMQManager.getInstance().deleteQueueMsg(PlaceOrderCMQManager.QUEUE_INTEGRAL, key); } catch (Exception e) { LogHelper.errorDetailInfo(e); } } } } }); } // 抖音广告监控 public void doPlaceOrderAdJob() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); Map<String, Order> map = PlaceOrderCMQManager.getInstance() .consumeQueueMsg(PlaceOrderCMQManager.QUEUE_AD, 16); if (map != null) { // 是否是首单 for (Iterator<String> its = map.keySet().iterator(); its.hasNext(); ) { String key = its.next(); Order order = map.get(key); if (isFirstValidOrder(order.getOrderId(), order.getOrderType(), order.getUserInfo().getId())) {// 有效的首单 // TODO 抖音的数据回调 } } } } }); } @Resource private DouYinClickEventService douYinClickEventService; // 抖音 public void doDouYinDeviceActiveJob() { String methodName = getMethodName(Thread.currentThread()); LogHelper.test("开始执行:doDouYinDeviceActiveJob"); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); Map<String, DouYinDeviceActiveQueueDTO> map = DouYinDeviceActiveCMQManager.getInstance() .consume(16); if (map != null) { // 是否是首单 for (Iterator<String> its = map.keySet().iterator(); its.hasNext(); ) { String key = its.next(); DouYinDeviceActiveQueueDTO active = map.get(key); if (active.getType() == DouYinDeviceActiveQueueDTO.TYPE_AD) {// 抖音 DouYinClickEvent event = douYinClickEventService.selectByCallback(active.getCallback()); if (event != null) { if (event.getOs() == 0 && !StringUtil.isNullOrEmpty(event.getUuid())) { DeviceActive deviceActive = deviceActiveService .getFirstActiveInfoByImei(event.getUuid()); if (deviceActive != null) { if (event != null) { if (event.getOs() == 0) DouYinAdUtil.activeAndroid(event.getCallback(), event.getImei(), deviceActive.getCreateTime().getTime()); else if (event.getOs() == 1) DouYinAdUtil.activeIOS(event.getCallback(), event.getIdfa(), deviceActive.getCreateTime().getTime()); } } } else {// TODO 处理IOS } } } else if (active.getType() == DouYinDeviceActiveQueueDTO.TYPE_DEVICE) {// 设备 if (active.getPlatform() == 1) { DeviceActive deviceActive = deviceActiveService .getFirstActiveInfo(active.getDevice()); if (deviceActive != null && !StringUtil.isNullOrEmpty(deviceActive.getImei())) { DouYinClickEvent event = douYinClickEventService .selectByUuid(deviceActive.getImei()); if (event != null) {// 回调 if (deviceActive != null) DouYinAdUtil.activeAndroid(event.getCallback(), event.getImei(), deviceActive.getCreateTime().getTime()); } } } else { // TODO 兼容IOS } } DouYinDeviceActiveCMQManager.getInstance().delete(key); } } } }); } // 分红 public void doDividentsPreJob() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); Map<String, UidDateDTO> map = TeamOrderCMQManager.getInstance().consumeTeamDividentsPreMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); UidDateDTO dto = map.get(key); try { teamDividentsManager.addToTeamEincome(dto.getUid(), dto.getDate()); TeamOrderCMQManager.getInstance().deleteTeamDividentsPreMsg(key); } catch (TeamDividentsRecordException e1) { if (e1.getCode() == TeamDividentsRecordException.CODE_EXIST) { TeamOrderCMQManager.getInstance().deleteTeamDividentsPreMsg(key); } else { try { LogHelper.errorDetailInfo(e1); } catch (Exception e2) { e2.printStackTrace(); } } } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } finally { } } } } }); } // 分红 public void doDividentsJob() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); Map<String, UidDateDTO> map = TeamOrderCMQManager.getInstance().consumeTeamDividentsMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); UidDateDTO dto = map.get(key); try { teamEincomeManager.addTeamDividentsTOUserAccount(dto.getDate(), dto.getUid()); TeamOrderCMQManager.getInstance().deleteTeamDividentsMsg(key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } finally { } } } } }); } // 华为推送 public void doHWPushJob() { String methodName = getMethodName(Thread.currentThread()); new JobThreadExecutorServiceImpl().run(new MyRunnable(methodName) { @Override public void run() { super.run(); Map<String, PushContentDetailDTO> map = PushCMQManager.getInstance().consumeHWPush(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); PushContentDetailDTO dto = map.get(key); LogHelper.pushHW("接受到消息:" + new Gson().toJson(dto)); try { hwPushService.push(dto); PushCMQManager.getInstance().deleteHWPush(key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } finally { } } } } }); } } fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java
@@ -13,6 +13,7 @@ import com.yeshi.fanli.dto.push.PushContentDetailDTO; import com.yeshi.fanli.service.impl.JobThreadExecutorServiceImpl; import com.yeshi.fanli.service.inter.push.HWPushService; import com.yeshi.fanli.service.manger.JobManager; import com.yeshi.fanli.util.mq.cmq.PushCMQManager; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; @@ -90,75 +91,8 @@ */ @Component public class SpringContext implements ApplicationListener<ContextRefreshedEvent> { @Resource private BoutiqueAutoRuleService boutiqueAutoRuleService; @Resource private ExtractService extractService; @Resource private IOSPushService iosPushService; @Resource(name = "taskExecutor") private TaskExecutor executor; @Resource private OrderProcessService orderProcessService; @Resource private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService; @Resource private ThreeSaleSerivce threeSaleSerivce; @Resource private TaoBaoOrderService taoBaoOrderService; @Resource private RedisManager redisManager; @Resource private UserMoneyDebtService userMoneyDebtService; @Resource private JDOrderService jdOrderService; @Resource private PDDOrderService pddOrderService; @Resource private HongBaoV2Service hongBaoV2Service; @Resource private IntegralGetService integralGetService; @Resource private CommonOrderService commonOrderService; @Resource private HongBaoOrderService hongBaoOrderService; @Resource private IntegralTaskRecordService integralTaskRecordService; @Resource private DeviceActiveService deviceActiveService; @Resource private TeamDividentsManager teamDividentsManager; @Resource private TeamEincomeManager teamEincomeManager; @Resource private VipShopOrderService vipShopOrderService; @Resource private SuningOrderService suningOrderService; @Resource private HWPushService hwPushService; private JobManager jobManager; private static boolean isInited = false; @@ -180,34 +114,8 @@ private void init(ContextRefreshedEvent arg0) { initCOS(); if (Constant.IS_TASK) { doExtractResult();// 处理提现结果 doTaoBaoOrders();// 处理淘宝订单 doTaoBaoNewOrders();// 处理淘宝订单(刚刚产生的) doOrderFanLiNew();// 新版返利 doOrderShareFanLi(); doWeiQuanOrder();// 处理维权订单 doPushIOS();// 处理发送IOS消息 doUserMoneyDebtJob();// 债务偿还 initScheduler();// 启动商品更新定时任务 doUpdateGoodsJob(); // 更新商品队列 doJDOrderJob();// 京东订单处理 doPDDOrderJob();// 拼多多订单处理 doVipShopOrderJob();// 唯品会订单处理 doSuningOrderJob();// 苏宁订单处理 doImportantTaoBaoGoodsUpdateJob();// 淘宝重要商品的信息更新 doHongBaoRecieveIntegralGetJob();// 返利到账,金币增加 // doPlaceOrderIntegralJob();// 下单赠送金币任务 // doDouYinDeviceActiveJob();// 抖音设备激活广告监测 doOrderTeamIncomePreFanLi();// 处理订单提成返利 doDividentsPreJob(); doOrderTeamRewardFanLi(); doDividentsJob(); //华为推送 doHWPushJob(); jobManager.start(); } } /** @@ -225,1067 +133,6 @@ params.setSecretKey(ps.getProperty("secretKey")); // 初始化 COSManager.getInstance().init(params); } /** * 处理提现结果的队列 */ public void doExtractResult() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, AlipayTransferResultInfo> map = CMQManager.getInstance().consumeExtractResultMsg(1); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { extractService.processExtractResult(map.get(key)); CMQManager.getInstance().deleteExtractResultMsg(key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { } } }); } /** * 处理淘宝订单 */ public void doTaoBaoOrders() { // 同时开启3个线程处理 for (int i = 0; i < 3; i++) { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { // 取16个订单 List<String> orderIds = CMQManager.getInstance().consumeTaoBaoOrderMsg(16); if (orderIds != null) { for (String orderId : orderIds) { if (NumberUtil.isNumeric(orderId.trim())) { Map<String, List<TaoBaoOrder>> map = new HashMap<>(); List<TaoBaoOrder> orderList = taoBaoOrderService .getTaoBaoOrderByOrderId(orderId); map.put(orderId, orderList); LogHelper.orderInfo("开始处理订单:" + orderId); orderProcessService.processOrder(map); LogHelper.orderInfo("结束处理订单:" + orderId); } } } } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { } } } }); } } /** * 刚刚产生的订单 */ public void doTaoBaoNewOrders() { // 同时开启3个线程处理 for (int i = 0; i < 1; i++) { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { // 取16个订单 List<String> orderIds = CMQManager.getInstance().consumeTaoBaoNewOrderMsg(16); Map<String, List<TaoBaoOrder>> map = new HashMap<>(); if (orderIds != null) { for (String orderId : orderIds) { List<TaoBaoOrder> orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(orderId); map.put(orderId, orderList); LogHelper.orderInfo("新订单-开始处理订单:" + orderId); long startTime = System.currentTimeMillis(); orderProcessService.processOrder(map); LogHelper.orderInfo("新订单-结束处理订单:" + orderId + "- 处理时间:" + (System.currentTimeMillis() - startTime)); } } } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { } } } }); } } /** * 处理新版淘宝订单返利 */ public void doOrderFanLiNew() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, HongBaoV2> map = CMQManager.getInstance().consumeFanLiMsgNew(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String handler = its.next(); try { HongBaoV2 hongbao = map.get(handler); if (hongbao != null) { String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.hongBaoFanLi, hongbao.getId() + ""); if (StringUtil.isNullOrEmpty(redisManager.getCommonString(key))) { // 处理之后要隔2小时再次进行处理 redisManager.cacheCommonString(key, "1", 60 * 60 * 2); orderProcessService.fanli(map.get(handler)); } } CMQManager.getInstance().deleteFanLiMsgNew(handler); } catch (TaoBaoWeiQuanException e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } catch (Exception e) { try { LogHelper.errorDetailInfo(e, "HongBaoV2-ID:" + map.get(handler).getId(), ""); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { } } }); } /** * 处理团队订单返利 */ public void doOrderTeamIncomePreFanLi() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, UidDateDTO> map = TeamOrderCMQManager.getInstance() .consumeFanLiTeamIncomePreMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String handler = its.next(); try { UidDateDTO dto = map.get(handler); orderProcessService.fanliPreInvaite(dto.getUid(), dto.getDate()); TeamOrderCMQManager.getInstance().deleteTeamIncomePreMsg(handler); } catch (Exception e) { try { LogHelper.errorDetailInfo(e, new Gson().toJson(map.get(handler)).toString(), ""); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { } } }); } /** * 处理团队奖金返利 */ public void doOrderTeamRewardFanLi() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, UidDateDTO> map = TeamOrderCMQManager.getInstance().consumeFanLiTeamIncomeMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String handler = its.next(); try { UidDateDTO dto = map.get(handler); teamEincomeManager.addTeamRewardTOUserAccount(dto.getDate(), dto.getUid()); TeamOrderCMQManager.getInstance().deleteTeamIncomeMsg(handler); } catch (Exception e) { try { LogHelper.errorDetailInfo(e, map.get(handler).toString(), ""); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { } } }); } /** * 处理分享订单返利 */ public void doOrderShareFanLi() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, UidDateDTO> map = CMQManager.getInstance().consumeFanLiShareMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String handler = its.next(); try { UidDateDTO dto = map.get(handler); orderProcessService.fanliShare(dto.getUid(), dto.getDate()); CMQManager.getInstance().deleteFanLiShareMsg(handler); } catch (Exception e) { try { LogHelper.errorDetailInfo(e, map.get(handler).toString(), ""); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { } } }); } /** * 处理淘宝订单维权 */ public void doWeiQuanOrder() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, TaoBaoWeiQuanOrder> map = CMQManager.getInstance().consumeWeiQuanOrderMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String handler = its.next(); try { orderProcessService.weiQuanOrder(map.get(handler)); CMQManager.getInstance().deleteWeiQuanOrderMsg(handler); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { } } }); } /** * IOS 推送消息 */ public void doPushIOS() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, PushQueueRecord> map = CMQManager.getInstance().consumeIOSPushMsg(10); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { iosPushService.readyPushIOS(map.get(key)); CMQManager.getInstance().deleteIOSPushMsg(key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { LogHelper.errorDetailInfo(e); } } }); } /** * 创建Scheduler()执行自动爬取 */ private void initScheduler() { boutiqueAutoRuleService.startScheduler(); } /** * 更新精选库商品 */ public void doUpdateGoodsJob() { for (int i = 0; i < 1; i++) new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, Long> map = CMQManager.getInstance().consumeNeedUpdateTaoBaoGoodsIdMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); taoBaoGoodsUpdateService.updateByTaoKeGoodsDetail(Long.parseLong(key)); CMQManager.getInstance().deleteNeedUpdateTaoBaoGoodsIdMsg(key); } } } catch (Exception e) { e.printStackTrace(); LogHelper.error("更新商品出错:" + e.getMessage()); } } }); } /** * 用户借贷处理 */ public void doUserMoneyDebtJob() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, UserMoneyChangeDTO> map = UserMoneyChangeCMQManager.getInstance() .consumeQueueMsg(UserMoneyChangeCMQManager.QUEUE_DEBT, 16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { UserMoneyChangeDTO dto = map.get(key); if (dto != null && dto.getChangeMoney().compareTo(new BigDecimal(0)) > 0) { userMoneyDebtService.repayDebt(dto.getUid()); } UserMoneyChangeCMQManager.getInstance() .deleteQueueMsg(UserMoneyChangeCMQManager.QUEUE_DEBT, key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { LogHelper.error("还款出错:" + e.getMessage()); } } }); } public void doJDOrderJob() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, String> map = JDOrderCMQManager.getInstance().consumeJDOrder(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { String orderId = map.get(key); if (!StringUtil.isNullOrEmpty(orderId)) { JDOrder order = jdOrderService.selectDetailByOrderId(Long.parseLong(orderId)); orderProcessService.processJDOrder(order); } JDOrderCMQManager.getInstance().deleteJDOrder(key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } } } } catch (Exception e) { LogHelper.error("拼多多订单出错:" + e.getMessage()); } } }); } public void doPDDOrderJob() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, String> map = PDDOrderCMQManager.getInstance().consumePDDOrder(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { String orderId = map.get(key); if (!StringUtil.isNullOrEmpty(orderId)) { List<PDDOrder> orderList = pddOrderService.selectByOrderSn(orderId); if (orderList != null) for (PDDOrder order : orderList) orderProcessService.processPDDOrder(order); } PDDOrderCMQManager.getInstance().deletePDDOrder(key); } catch (Exception e) { LogHelper.errorDetailInfo(e); } } } } catch (Exception e) { LogHelper.error("拼多多订单:" + e.getMessage()); } } }); } public void doVipShopOrderJob() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, String> map = VipShopOrderCMQManager.getInstance().consumeVipShopOrder(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { String orderId = map.get(key); LogHelper.test("唯品会订单消费:" + orderId); if (!StringUtil.isNullOrEmpty(orderId)) { List<VipShopOrder> orderList = vipShopOrderService.listDetailByOrderSn(orderId); if (orderList != null) for (VipShopOrder order : orderList) orderProcessService.processVipShopOrder(order); } VipShopOrderCMQManager.getInstance().deleteVipShopOrder(key); } catch (Exception e) { LogHelper.errorDetailInfo(e); } } } } catch (Exception e) { LogHelper.errorDetailInfo(e); } } }); } public void doSuningOrderJob() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { try { Map<String, String> map = SuningOrderCMQManager.getInstance().consumeSuningOrder(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { String orderId = map.get(key); if (!StringUtil.isNullOrEmpty(orderId)) { List<SuningOrderInfo> orderList = suningOrderService.listByOrderCode(orderId); if (orderList != null) for (SuningOrderInfo order : orderList) orderProcessService.processSuningOrder(order); } SuningOrderCMQManager.getInstance().deleteSuningOrder(key); } catch (Exception e) { LogHelper.errorDetailInfo(e); } } } } catch (Exception e) { LogHelper.errorDetailInfo(e); } } }); } /** * 重要的淘宝商品信息更新 */ public void doImportantTaoBaoGoodsUpdateJob() { // 开启2个线程做更新 for (int i = 0; i < 2; i++) new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { Map<String, Long> map = CMQManager.getInstance().consumeTBImpGoodsUpdateMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); try { long startTime = System.currentTimeMillis(); TaoBaoGoodsBrief goods = TaoKeApiUtil.searchGoodsDetail(map.get(key)); // 更新一条数据需要的时间 taoBaoGoodsUpdateService.updateTaoBaoGoods(goods); long time = System.currentTimeMillis() - startTime; LogHelper.test("淘宝重要商品库更新时间:" + time); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } finally { CMQManager.getInstance().deleteTBImpGoodsUpdateMsg(key); } } } } }); } /** * 红包到账后的金币获取 */ public void doHongBaoRecieveIntegralGetJob() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { Map<String, Long> map = HongBaoRecieveCMQManager.getInstance() .consumeQueueMsg(HongBaoRecieveCMQManager.QUEUE_INTEGRAL, 16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); Long hongBaoId = map.get(key); try { HongBaoV2 hongBaoV2 = hongBaoV2Service.selectByPrimaryKey(hongBaoId); if (hongBaoV2 != null && hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU && hongBaoV2.getMoney().compareTo(new BigDecimal(0)) > 0) { // 到账送金币 fanliGetIntegral(hongBaoV2); HongBaoRecieveCMQManager.getInstance() .deleteQueueMsg(HongBaoRecieveCMQManager.QUEUE_INTEGRAL, key); // 返利不足0.01元送金币 if (hongBaoV2.getType() == HongBaoV2.TYPE_ZIGOU) {// 自购 // 判断是否为该用户的首笔红包 List<Integer> typeList = new ArrayList<>(); typeList.add(HongBaoV2.TYPE_ZIGOU); HongBaoV2 firstHongBao = hongBaoV2Service.getFirstValidHongBaoByTypeAndUid( typeList, hongBaoV2.getUserInfo().getId()); if (firstHongBao != null && firstHongBao.getId().longValue() == hongBaoV2.getId()) {// 自购首单到账 // 查询下级红包 BigDecimal firstLevelMoney = new BigDecimal(0); BigDecimal secondLevelMoney = new BigDecimal(0); // 获取改单下面的红包 List<HongBaoV2> hongBaoList = new ArrayList<>(); HongBaoOrder hongBaoOrder = hongBaoOrderService .selectDetailByHongBaoId(hongBaoV2.getId()); if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {// 计算改订单号下面的所有返利金额 CommonOrder commonOrder = hongBaoOrder.getCommonOrder(); List<CommonOrder> list = commonOrderService.listBySourceTypeAndOrderId( commonOrder.getSourceType(), commonOrder.getOrderNo()); for (CommonOrder co : list) { HongBaoOrder hbo = hongBaoOrderService .selectDetailByCommonOrderId(co.getId()); if (hbo != null && hbo.getHongBaoV2() != null) hongBaoList.add(hbo.getHongBaoV2()); } } for (HongBaoV2 hb : hongBaoList) { List<HongBaoV2> children = hongBaoV2Service .listChildrenById(hb.getId()); if (children != null) for (HongBaoV2 child : children) if (child.getType() == HongBaoV2.TYPE_YIJI) { firstLevelMoney = firstLevelMoney.add(child.getMoney()); } else if (child.getType() == HongBaoV2.TYPE_ERJI) { secondLevelMoney = secondLevelMoney.add(child.getMoney()); } } // 查询下级的生效时间 ThreeSale threeSale = threeSaleSerivce.selectLatestByWorkerIdAndState( hongBaoV2.getUserInfo().getId(), ThreeSale.STATE_SUCCESS); if (threeSale != null && threeSale.getSucceedTime() != null && threeSale .getSucceedTime() < hongBaoV2.getCreateTime().getTime()) {// 邀请成功的时间是否在下单的时间之前 // 成功时间要大于20190910日才开始送金币 if (threeSale.getSucceedTime() > TimeUtil.convertToTimeTemp("20190901", "yyyyMMdd")) { if (firstLevelMoney.compareTo(new BigDecimal("0.01")) < 0) {// 一级返利小于0.01 integralTaskRecordService.firstRebateOrderRewardBoss( threeSale.getBoss().getId(), hongBaoV2.getUserInfo().getId(), null); LogHelper.test("自购-一级用户-" + threeSale.getBoss().getId() + "-hongBaoId:" + hongBaoV2.getId()); } } } // 查询下下级生效时间 if (threeSale != null) { threeSale = threeSaleSerivce.selectLatestByWorkerIdAndState( threeSale.getBoss().getId(), ThreeSale.STATE_SUCCESS); if (threeSale != null && threeSale.getSucceedTime() != null && threeSale .getSucceedTime() < hongBaoV2.getCreateTime().getTime()) {// 邀请成功的时间是否在下单的时间之前 // 成功时间要大于20190910日才开始送金币 if (threeSale.getSucceedTime() > TimeUtil .convertToTimeTemp("20190901", "yyyyMMdd")) { if (secondLevelMoney.compareTo(new BigDecimal("0.01")) < 0) {// 二级返利小于0.01 integralTaskRecordService.firstRebateOrderRewardBossSuper( threeSale.getBoss().getId(), hongBaoV2.getUserInfo().getId(), null); LogHelper.test("自购-二级用户-" + threeSale.getBoss().getId() + "-hongBaoId:" + hongBaoV2.getId()); } } } } } } else if (hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_GOODS) {// 分享赚 // 判断是否为该用户的首笔红包 List<Integer> typeList = new ArrayList<>(); typeList.add(HongBaoV2.TYPE_SHARE_GOODS); HongBaoV2 firstHongBao = hongBaoV2Service.getFirstValidHongBaoByTypeAndUid( typeList, hongBaoV2.getUserInfo().getId()); if (firstHongBao != null && firstHongBao.getId().longValue() == hongBaoV2.getId()) // 分享首笔到账 { // 查询下级红包 BigDecimal firstLevelMoney = new BigDecimal(0); // 获取改单下面的红包 List<HongBaoV2> hongBaoList = new ArrayList<>(); HongBaoOrder hongBaoOrder = hongBaoOrderService .selectDetailByHongBaoId(hongBaoV2.getId()); if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {// 计算改订单号下面的所有返利金额 CommonOrder commonOrder = hongBaoOrder.getCommonOrder(); List<CommonOrder> list = commonOrderService.listBySourceTypeAndOrderId( commonOrder.getSourceType(), commonOrder.getOrderNo()); for (CommonOrder co : list) { HongBaoOrder hbo = hongBaoOrderService .selectDetailByCommonOrderId(co.getId()); if (hbo != null && hbo.getHongBaoV2() != null) hongBaoList.add(hbo.getHongBaoV2()); } } for (HongBaoV2 hb : hongBaoList) { List<HongBaoV2> children = hongBaoV2Service .listChildrenById(hb.getId()); if (children != null) for (HongBaoV2 child : children) if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) { firstLevelMoney = firstLevelMoney.add(child.getMoney()); } } ThreeSale threeSale = threeSaleSerivce.selectLatestByWorkerIdAndState( hongBaoV2.getUserInfo().getId(), ThreeSale.STATE_SUCCESS); if (threeSale != null && threeSale.getSucceedTime() != null && threeSale .getSucceedTime() < hongBaoV2.getCreateTime().getTime()) {// 邀请成功的时间是否在下单的时间之前 // 成功时间要大于20190910日才开始送金币 if (threeSale.getSucceedTime() > TimeUtil.convertToTimeTemp("20190901", "yyyyMMdd")) { if (firstLevelMoney.compareTo(new BigDecimal("0.01")) < 0) {// 一级返利小于0.01 integralTaskRecordService.firstSharerOrderRewardBoss( threeSale.getBoss().getId(), hongBaoV2.getUserInfo().getId(), null); LogHelper.test("分享-一级用户-" + threeSale.getBoss().getId() + "-hongBaoId:" + hongBaoV2.getId()); } } } } } } } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } finally { } } } } }); } private void fanliGetIntegral(HongBaoV2 hongBaoV2) { if (hongBaoV2 != null && hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU && hongBaoV2.getMoney().compareTo(new BigDecimal(0)) > 0) { // 查询对应的订单号 Long mainHongBaoId = hongBaoV2.getId(); if (hongBaoV2.getParent() != null && hongBaoV2.getParent().getId() != null) mainHongBaoId = hongBaoV2.getParent().getId(); HongBaoOrder hongbaoOrder = hongBaoOrderService.selectDetailByHongBaoId(mainHongBaoId); if (hongbaoOrder == null || hongbaoOrder.getCommonOrder() == null) return; CommonOrder commonOrder = hongbaoOrder.getCommonOrder(); if (hongBaoV2.getType() == HongBaoV2.TYPE_ZIGOU) {// 自购订单 integralGetService.addRebateOrder(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(), commonOrder.getSourceType()); } else if (hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_GOODS) {// 分享订单 integralGetService.addShareOrder(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(), commonOrder.getSourceType()); } else if (hongBaoV2.getType() == HongBaoV2.TYPE_YIJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_YIJI) {// 一级邀请 integralGetService.addInviteOrderLevelOne(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(), commonOrder.getSourceType()); } else if (hongBaoV2.getType() == HongBaoV2.TYPE_ERJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_ERJI) {// 二级邀请 integralGetService.addInviteOrderLevelTwo(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(), commonOrder.getSourceType()); } } } private boolean isFirstValidOrder(String orderId, int sourceType, Long uid) { CommonOrder commonOrder = commonOrderService.selectLatestValidByUid(uid); if (commonOrder != null && commonOrder.getOrderNo().equalsIgnoreCase(orderId) && sourceType == commonOrder.getSourceType()) return true; else return false; } // 下单获取金币任务 public void doPlaceOrderIntegralJob() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { Map<String, Order> map = PlaceOrderCMQManager.getInstance() .consumeQueueMsg(PlaceOrderCMQManager.QUEUE_INTEGRAL, 16); if (map != null) { for (Iterator<String> its = map.keySet().iterator(); its.hasNext(); ) { try { String key = its.next(); Order order = map.get(key); // 是否是首单 if (isFirstValidOrder(order.getOrderId(), order.getOrderType(), order.getUserInfo().getId())) { // 统计订单下的用户所获得的返利金额 List<CommonOrder> list = commonOrderService .listBySourceTypeAndOrderId(order.getOrderType(), order.getOrderId()); Map<Long, BigDecimal> hongBaoMoney = new HashMap<>(); if (list != null) for (CommonOrder commonOrder : list) { HongBaoOrder hongBaoOrder = hongBaoOrderService .selectDetailByCommonOrderId(commonOrder.getId()); if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null) { Long mainUid = hongBaoOrder.getHongBaoV2().getUserInfo().getId(); if (hongBaoMoney.get(mainUid) == null) hongBaoMoney.put(mainUid, new BigDecimal(0)); hongBaoMoney.put(mainUid, hongBaoMoney.get(mainUid) .add(hongBaoOrder.getHongBaoV2().getMoney())); // 查询上级 List<HongBaoV2> children = hongBaoV2Service .listChildrenById(hongBaoOrder.getHongBaoV2().getId()); if (children != null) { for (HongBaoV2 hongBao : children) { Long uid = hongBao.getUserInfo().getId(); if (hongBaoMoney.get(uid) == null) hongBaoMoney.put(uid, new BigDecimal(0)); hongBaoMoney.put(uid, hongBaoMoney.get(uid).add(hongBao.getMoney())); } } } } if (isFirstValidOrder(order.getOrderId(), order.getOrderType(), order.getUserInfo().getId())) {// 有效的首单 if (hongBaoMoney.get(order.getUserInfo().getId()) == null || hongBaoMoney .get(order.getUserInfo().getId()).compareTo(new BigDecimal("0")) <= 0) { // 分享奖金是0 integralTaskRecordService.firstShareOrderReward(order.getUserInfo().getId(), null); } // 获取上两级数据 UserInfo boss = threeSaleSerivce.getBoss(order.getUserInfo().getId()); if (boss != null) {// 判断上级的红包 if (hongBaoMoney.get(boss.getId()) == null || hongBaoMoney.get(boss.getId()) .compareTo(new BigDecimal("0")) <= 0) { // 补偿金币 integralTaskRecordService.firstSharerOrderRewardBoss(boss.getId(), order.getUserInfo().getId(), null); } } } else {// 自购订单 UserInfo boss = threeSaleSerivce.getBoss(order.getUserInfo().getId()); if (boss != null) {// 判断上级的红包 if (hongBaoMoney.get(boss.getId()) == null || hongBaoMoney.get(boss.getId()) .compareTo(new BigDecimal("0")) <= 0) { // 补偿金币1级 integralTaskRecordService.firstRebateOrderRewardBoss(boss.getId(), order.getUserInfo().getId(), null); } boss = threeSaleSerivce.getBoss(boss.getId()); if (boss != null) {// 判断上级的红包 if (hongBaoMoney.get(boss.getId()) == null || hongBaoMoney .get(boss.getId()).compareTo(new BigDecimal("0")) <= 0) { // 补偿金币2级 integralTaskRecordService.firstRebateOrderRewardBossSuper( boss.getId(), order.getUserInfo().getId(), null); } } } } } PlaceOrderCMQManager.getInstance().deleteQueueMsg(PlaceOrderCMQManager.QUEUE_INTEGRAL, key); } catch (Exception e) { LogHelper.errorDetailInfo(e); } } } } }); } // 抖音广告监控 public void doPlaceOrderAdJob() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { Map<String, Order> map = PlaceOrderCMQManager.getInstance() .consumeQueueMsg(PlaceOrderCMQManager.QUEUE_AD, 16); if (map != null) { // 是否是首单 for (Iterator<String> its = map.keySet().iterator(); its.hasNext(); ) { String key = its.next(); Order order = map.get(key); if (isFirstValidOrder(order.getOrderId(), order.getOrderType(), order.getUserInfo().getId())) {// 有效的首单 // TODO 抖音的数据回调 } } } } }); } @Resource private DouYinClickEventService douYinClickEventService; // 抖音 public void doDouYinDeviceActiveJob() { LogHelper.test("开始执行:doDouYinDeviceActiveJob"); new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { Map<String, DouYinDeviceActiveQueueDTO> map = DouYinDeviceActiveCMQManager.getInstance() .consume(16); if (map != null) { // 是否是首单 for (Iterator<String> its = map.keySet().iterator(); its.hasNext(); ) { String key = its.next(); DouYinDeviceActiveQueueDTO active = map.get(key); if (active.getType() == DouYinDeviceActiveQueueDTO.TYPE_AD) {// 抖音 DouYinClickEvent event = douYinClickEventService.selectByCallback(active.getCallback()); if (event != null) { if (event.getOs() == 0 && !StringUtil.isNullOrEmpty(event.getUuid())) { DeviceActive deviceActive = deviceActiveService .getFirstActiveInfoByImei(event.getUuid()); if (deviceActive != null) { if (event != null) { if (event.getOs() == 0) DouYinAdUtil.activeAndroid(event.getCallback(), event.getImei(), deviceActive.getCreateTime().getTime()); else if (event.getOs() == 1) DouYinAdUtil.activeIOS(event.getCallback(), event.getIdfa(), deviceActive.getCreateTime().getTime()); } } } else {// TODO 处理IOS } } } else if (active.getType() == DouYinDeviceActiveQueueDTO.TYPE_DEVICE) {// 设备 if (active.getPlatform() == 1) { DeviceActive deviceActive = deviceActiveService .getFirstActiveInfo(active.getDevice()); if (deviceActive != null && !StringUtil.isNullOrEmpty(deviceActive.getImei())) { DouYinClickEvent event = douYinClickEventService .selectByUuid(deviceActive.getImei()); if (event != null) {// 回调 if (deviceActive != null) DouYinAdUtil.activeAndroid(event.getCallback(), event.getImei(), deviceActive.getCreateTime().getTime()); } } } else { // TODO 兼容IOS } } DouYinDeviceActiveCMQManager.getInstance().delete(key); } } } }); } // 分红 public void doDividentsPreJob() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { Map<String, UidDateDTO> map = TeamOrderCMQManager.getInstance().consumeTeamDividentsPreMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); UidDateDTO dto = map.get(key); try { teamDividentsManager.addToTeamEincome(dto.getUid(), dto.getDate()); TeamOrderCMQManager.getInstance().deleteTeamDividentsPreMsg(key); } catch (TeamDividentsRecordException e1) { if (e1.getCode() == TeamDividentsRecordException.CODE_EXIST) { TeamOrderCMQManager.getInstance().deleteTeamDividentsPreMsg(key); } else { try { LogHelper.errorDetailInfo(e1); } catch (Exception e2) { e2.printStackTrace(); } } } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } finally { } } } } }); } // 分红 public void doDividentsJob() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { Map<String, UidDateDTO> map = TeamOrderCMQManager.getInstance().consumeTeamDividentsMsg(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); UidDateDTO dto = map.get(key); try { teamEincomeManager.addTeamDividentsTOUserAccount(dto.getDate(), dto.getUid()); TeamOrderCMQManager.getInstance().deleteTeamDividentsMsg(key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } finally { } } } } }); } // 华为推送 public void doHWPushJob() { new JobThreadExecutorServiceImpl().run(new Runnable() { @Override public void run() { Map<String, PushContentDetailDTO> map = PushCMQManager.getInstance().consumeHWPush(16); if (map != null) { Iterator<String> its = map.keySet().iterator(); while (its.hasNext()) { String key = its.next(); PushContentDetailDTO dto = map.get(key); LogHelper.pushHW("接受到消息:" + new Gson().toJson(dto)); try { hwPushService.push(dto); PushCMQManager.getInstance().deleteHWPush(key); } catch (Exception e) { try { LogHelper.errorDetailInfo(e); } catch (Exception e1) { e1.printStackTrace(); } } finally { } } } } }); } } fanli/src/main/java/com/yeshi/fanli/util/TuanYouUtil.java
New file @@ -0,0 +1,79 @@ package com.yeshi.fanli.util; import net.sf.json.JSONObject; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod; import org.yeshi.utils.HttpUtil; import java.io.IOException; import java.util.*; public class TuanYouUtil { private final static String APP_KEY = "appm_h598645363"; private final static String APP_SECRET = "dec748b401b5df426fc0fa795e2704db"; private static String getSign(Map<String, String> params) { List<String> list = new ArrayList<>(); for (Iterator<String> its = params.keySet().iterator(); its.hasNext(); ) { String key = its.next(); list.add(key + params.get(key)); } Collections.sort(list); return StringUtil.Md5(APP_SECRET + StringUtil.concat(list, "") + APP_SECRET); } private static Map<String, String> getBaseRequestParams() { Map<String, String> map = new HashMap<>(); map.put("app_key", APP_KEY); map.put("timestamp", System.currentTimeMillis() + ""); return map; } private static String request(String url, Map<String, String> map) { Iterator<String> its = map.keySet().iterator(); NameValuePair[] params = new NameValuePair[map.keySet().size()]; for (int p = 0; its.hasNext(); ++p) { String key = (String) its.next(); NameValuePair np = new NameValuePair(key, (String) map.get(key)); params[p] = np; } HttpClient client = new HttpClient(); PostMethod method = new PostMethod(url); method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded"); method.setRequestBody(params); try { client.executeMethod(method); return method.getResponseBodyAsString(); } catch (HttpException var8) { var8.printStackTrace(); } catch (IOException var9) { var9.printStackTrace(); } return ""; } public static String getAuthCode(String phone) { Map<String, String> map = getBaseRequestParams(); map.put("platformId", "98645363"); map.put("phone", phone); String sign = getSign(map); map.put("sign", sign); String result = request("https://mcs.czb365.com/services/v3/begin/getSecretCode", map); JSONObject data = JSONObject.fromObject(result); if (data.optInt("code") == 200) { return data.optString("result"); } return ""; } } fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java
@@ -562,4 +562,25 @@ } else return true; } public static String getAuthLink(String pid, String customParameters) { Map<String, String> map = new HashMap<>(); map.put("type", "pdd.ddk.rp.prom.url.generate"); map.put("channel_type", 10 + ""); map.put("custom_parameters", customParameters); map.put("p_id_list", "[\"" + pid + "\"]"); String result = baseRequest(map); JSONObject resultJson = JSONObject.fromObject(result); JSONArray array = resultJson.optJSONObject("rp_promotion_url_generate_response").optJSONArray("url_list"); if (array != null && array.size() > 0) { JSONObject item = array.optJSONObject(0); String url = item.optString("url"); if (StringUtil.isNullOrEmpty(url)) { url = item.optString("mobile_url"); } return url; } return null; } } fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoUtil.java
@@ -37,6 +37,7 @@ import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.yeshi.utils.TimeUtil; public class PinDuoDuoUtil { @@ -641,4 +642,12 @@ return urlList; } public static String getCustomParams(String uid) { return uid + "_" + TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMddHH"); } public static String getUidFromCustomParams(String params) { return params.split("_")[0]; } } fanli/src/test/java/org/fanli/TaoKeTest.java
@@ -227,7 +227,7 @@ + "https://u.jd.com/d9fcGr\n" + "⚡京东秒杀\n" + "https://u.jd.com/WSIi1z\n" + "【记得与更多好友分享[愉快]】"; ConvertLinkManager convertLinkManager = BeanUtil.getBean(ConvertLinkManager.class); try { System.out.println(convertLinkManager.convertLinkFromText(text, 437032L, true,false)); System.out.println(convertLinkManager.convertLinkFromText(text, 437032L, true, false)); } catch (Exception e) { e.printStackTrace(); } @@ -280,7 +280,7 @@ @Test public void test13() { TaoKeApiUtil.specialConvertCoupon(579875678934L, new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET, TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT),null,null); TaoBaoConstant.TAOBAO_AUTH_APPSECRET, TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT), null, null); try { TaoKeApiUtil.getSimpleGoodsInfo(556371219169L); } catch (TaobaoGoodsDownException e) { @@ -328,7 +328,7 @@ sf.setEndTkRate(9000); sf.setPage(25); sf.setPageSize(50); TaoBaoSearchResult result = TaoKeApiUtil.searchWuLiao(sf,null,null); TaoBaoSearchResult result = TaoKeApiUtil.searchWuLiao(sf, null, null); System.out.println(result); } @@ -348,13 +348,23 @@ @Test public void test18(){ public void test18() { TaoKeAppInfo app = new TaoKeAppInfo(); app.setAppKey("27867727"); app.setAppSecret("781fce83545edbed13af32dc3fa9fc3a"); app.setPid("mm_124933865_865950258_109407350204"); OrderQuery q=new OrderQuery(); q.startTime="2020-01-01"; q.pageNo=1; q.pageSize=20; TaoKeOrderApiUtil.queryTaoBaoOrder(q,TaoBaoConstant.TAOBAO_AUTH_APPKEY,TaoBaoConstant.TAOBAO_AUTH_APPSECRET); SearchFilter filter = new SearchFilter(); filter.setKey("活着"); filter.setPage(1); filter.setPageSize(20); Long id = 535786796994L; try { TaoKeApiUtil.searchGoodsDetailForConvert(id, app, "", ""); } catch (TaobaoGoodsDownException e) { e.printStackTrace(); } } } utils/pom.xml
@@ -58,6 +58,13 @@ <version>1.0.7</version> </dependency> <!--商户平台API --> <dependency> <groupId>com.github.wechatpay-apiv3</groupId> <artifactId>wechatpay-apache-httpclient</artifactId> <version>0.2.1</version> </dependency> </dependencies> </project> utils/src/main/java/org/yeshi/utils/entity/wx/WXAPPInfo.java
@@ -1,53 +1,97 @@ package org.yeshi.utils.entity.wx; public class WXAPPInfo { private String appId; private String appSecret; private String mchId; private String appId; private String appSecret; private String mchId; private String mchKey; public WXAPPInfo(String appId, String appSecret, String mchId, String mchKey) { this.appId = appId; this.appSecret = appSecret; this.mchId = mchId; this.mchKey = mchKey; } public WXAPPInfo() { /** * V3接口新增字段 */ //证书序列号 private String mchSerialNo; //证书私钥 private String privateKey; private String apiV3Key; } private String mchKey; public WXAPPInfo(String appId, String appSecret, String mchId, String mchKey) { this.appId = appId; this.appSecret = appSecret; this.mchId = mchId; this.mchKey = mchKey; } public String getAppId() { return appId; } public WXAPPInfo(String appId, String mchId, String mchSerialNo, String privateKey, String apiV3Key) { this.appId = appId; this.mchId = mchId; this.mchSerialNo = mchSerialNo; this.privateKey = privateKey; this.apiV3Key = apiV3Key; } public void setAppId(String appId) { this.appId = appId; } public String getAppSecret() { return appSecret; } public WXAPPInfo() { public void setAppSecret(String appSecret) { this.appSecret = appSecret; } } public String getMchId() { return mchId; } public void setMchId(String mchId) { this.mchId = mchId; } public String getMchSerialNo() { return mchSerialNo; } public String getMchKey() { return mchKey; } public void setMchSerialNo(String mchSerialNo) { this.mchSerialNo = mchSerialNo; } public void setMchKey(String mchKey) { this.mchKey = mchKey; } public String getPrivateKey() { return privateKey; } public void setPrivateKey(String privateKey) { this.privateKey = privateKey; } public String getApiV3Key() { return apiV3Key; } public void setApiV3Key(String apiV3Key) { this.apiV3Key = apiV3Key; } public String getAppId() { return appId; } public void setAppId(String appId) { this.appId = appId; } public String getAppSecret() { return appSecret; } public void setAppSecret(String appSecret) { this.appSecret = appSecret; } public String getMchId() { return mchId; } public void setMchId(String mchId) { this.mchId = mchId; } public String getMchKey() { return mchKey; } public void setMchKey(String mchKey) { this.mchKey = mchKey; } } utils/src/main/java/org/yeshi/utils/entity/wx/WXPlaceOrderParams.java
@@ -4,83 +4,95 @@ /** * 微信支付统一下单参数 * * @author Administrator * * @author Administrator */ public class WXPlaceOrderParams { private String orderNo; private BigDecimal fee; private String openId; private String body; private String ip; private String tradeType; private String notifyUrl; private String orderNo; private BigDecimal fee; private String openId; private String body; private String ip; private String tradeType; private String notifyUrl; private WXAPPInfo info; //附加数据-V3接口中使用,支付结果通知中会原样返回 private String attach; public String getOrderNo() { return orderNo; } public void setOrderNo(String orderNo) { this.orderNo = orderNo; } private WXAPPInfo app; public BigDecimal getFee() { return fee; } public String getOrderNo() { return orderNo; } public void setFee(BigDecimal fee) { this.fee = fee; } public void setOrderNo(String orderNo) { this.orderNo = orderNo; } public String getOpenId() { return openId; } public BigDecimal getFee() { return fee; } public void setOpenId(String openId) { this.openId = openId; } public void setFee(BigDecimal fee) { this.fee = fee; } public String getBody() { return body; } public String getOpenId() { return openId; } public void setBody(String body) { this.body = body; } public void setOpenId(String openId) { this.openId = openId; } public String getIp() { return ip; } public String getBody() { return body; } public void setIp(String ip) { this.ip = ip; } public void setBody(String body) { this.body = body; } public String getTradeType() { return tradeType; } public String getIp() { return ip; } public void setTradeType(String tradeType) { this.tradeType = tradeType; } public void setIp(String ip) { this.ip = ip; } public WXAPPInfo getInfo() { return info; } public String getTradeType() { return tradeType; } public void setInfo(WXAPPInfo info) { this.info = info; } public void setTradeType(String tradeType) { this.tradeType = tradeType; } public String getNotifyUrl() { return notifyUrl; } public WXAPPInfo getApp() { return app; } public void setNotifyUrl(String notifyUrl) { this.notifyUrl = notifyUrl; } public void setApp(WXAPPInfo app) { this.app = app; } public String getAttach() { return attach; } public void setAttach(String attach) { this.attach = attach; } public String getNotifyUrl() { return notifyUrl; } public void setNotifyUrl(String notifyUrl) { this.notifyUrl = notifyUrl; } } utils/src/main/java/org/yeshi/utils/sms/TencentSMSUtil.java
New file @@ -0,0 +1,41 @@ package org.yeshi.utils.sms; import com.github.qcloudsms.SmsSingleSender; import com.github.qcloudsms.SmsSingleSenderResult; import com.github.qcloudsms.httpclient.HTTPException; import org.json.JSONException; import java.io.IOException; public class TencentSMSUtil { /** * 发送单一短信 * * @param phone * @param msg */ public static SmsSingleSenderResult sendSingleMsg(int appId, String appKey, String phone, String msg) { SmsSingleSender ssender = new SmsSingleSender(appId, appKey); SmsSingleSenderResult result = null; try { result = ssender.send(0, "86", phone, msg, "", ""); } catch (JSONException e) { e.printStackTrace(); } catch (HTTPException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; // if (result == null) // throw new SMSException(2, "短信发送失败"); // if (result.result == 1025) { // throw new SMSException(result.result, "今日验证码发送超限,请明日再试"); // } else if (result.result != 0) {// 发送失败 // throw new SMSException(result.result, "短信发送失败"); // } } } utils/src/main/java/org/yeshi/utils/wx/WXPayUtil.java
@@ -172,16 +172,16 @@ if (params == null) throw new WXPlaceOrderParamsException(1, "请传入下单参数"); if (params.getInfo() == null) if (params.getApp() == null) throw new WXPlaceOrderParamsException(2, "请传入下单应用信息"); if (StringUtil.isNullOrEmpty(params.getInfo().getAppId())) if (StringUtil.isNullOrEmpty(params.getApp().getAppId())) throw new WXPlaceOrderParamsException(201, "请传入下单应用信息-appId"); if (StringUtil.isNullOrEmpty(params.getInfo().getAppSecret())) if (StringUtil.isNullOrEmpty(params.getApp().getAppSecret())) throw new WXPlaceOrderParamsException(202, "请传入下单应用信息-appSecret"); if (StringUtil.isNullOrEmpty(params.getInfo().getMchId())) if (StringUtil.isNullOrEmpty(params.getApp().getMchId())) throw new WXPlaceOrderParamsException(203, "请传入下单应用信息-mchId"); if (StringUtil.isNullOrEmpty(params.getInfo().getMchKey())) if (StringUtil.isNullOrEmpty(params.getApp().getMchKey())) throw new WXPlaceOrderParamsException(204, "请传入下单应用信息-mchKey"); if (StringUtil.isNullOrEmpty(params.getBody())) throw new WXPlaceOrderParamsException(3, "请传入body"); @@ -205,8 +205,8 @@ // throw new WXPlaceOrderParamsException(9, "请传入openId"); Map<String, String> map = new HashMap<String, String>(); map.put("appid", params.getInfo().getAppId()); map.put("mch_id", params.getInfo().getMchId()); map.put("appid", params.getApp().getAppId()); map.put("mch_id", params.getApp().getMchId()); map.put("nonce_str", StringUtil.getRandomCode(32)); map.put("body", params.getBody()); map.put("out_trade_no", params.getOrderNo()); @@ -216,7 +216,7 @@ map.put("trade_type", params.getTradeType()); if (!StringUtil.isNullOrEmpty(params.getOpenId())) map.put("openid", params.getOpenId()); map.put("sign", WXUtil.getSignMD5(map, params.getInfo().getMchKey())); map.put("sign", WXUtil.getSignMD5(map, params.getApp().getMchKey())); String entity = WXUtil.loadWXMessage(map); utils/src/main/java/org/yeshi/utils/wx/WXPayV3Util.java
New file @@ -0,0 +1,199 @@ package org.yeshi.utils.wx; import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder; import com.wechat.pay.contrib.apache.httpclient.auth.AutoUpdateCertificatesVerifier; import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner; import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials; import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator; import com.wechat.pay.contrib.apache.httpclient.util.PemUtil; import net.sf.json.JSONObject; import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; import org.yeshi.utils.StringUtil; import org.yeshi.utils.entity.wx.WXAPPInfo; import org.yeshi.utils.entity.wx.WXPlaceOrderParams; import org.yeshi.utils.exception.WXOrderException; import org.yeshi.utils.exception.WXPlaceOrderParamsException; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.math.BigDecimal; import java.net.URLEncoder; import java.nio.file.Files; import java.nio.file.Paths; import java.security.PrivateKey; /** * 微信支付帮助类(基于微信支付V3接口) * * @author Administrator */ public class WXPayV3Util { private static CloseableHttpClient getHttpClient(WXAPPInfo app) throws Exception { // 加载商户私钥(privateKey:私钥字符串) PrivateKey merchantPrivateKey = PemUtil .loadPrivateKey(new ByteArrayInputStream(app.getPrivateKey().getBytes("utf-8"))); // 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3秘钥) AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier( new WechatPay2Credentials(app.getMchId(), new PrivateKeySigner(app.getMchSerialNo(), merchantPrivateKey)), app.getApiV3Key().getBytes("utf-8")); // 初始化httpClient return WechatPayHttpClientBuilder.create() .withMerchant(app.getMchId(), app.getMchSerialNo(), merchantPrivateKey) .withValidator(new WechatPay2Validator(verifier)).build(); } /** * 网络请求 * * @param url * @param requestData * @param app * @return * @throws Exception */ private static JSONObject request(String url, String requestData, WXAPPInfo app) throws Exception { HttpPost httpPost = new HttpPost(url); if (!StringUtil.isNullOrEmpty(requestData)) { StringEntity entity = new StringEntity(requestData, ContentType.APPLICATION_JSON.withCharset(Charsets.UTF_8)); entity.setContentType("application/json;charset=utf-8"); httpPost.setEntity(entity); } httpPost.setHeader("Accept", "application/json;charset=utf-8"); //完成签名并执行请求 CloseableHttpClient httpClient = getHttpClient(app); CloseableHttpResponse response = httpClient.execute(httpPost); try { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == 200) { System.out.println("success,return body = " + EntityUtils.toString(response.getEntity())); String result = EntityUtils.toString(response.getEntity()); JSONObject resultJson = JSONObject.fromObject(result); return resultJson; } else if (statusCode == 204) { System.out.println("success"); } else { System.out.println("failed,resp code = " + statusCode + ",return body = " + EntityUtils.toString(response.getEntity())); throw new Exception("request failed"); } } finally { response.close(); } return null; } /** * H5支付统一下单接口 * * @param params * @return 支付链接 * @throws WXPlaceOrderParamsException * @throws Exception */ public static String createH5Order(WXPlaceOrderParams params, String redirectUrl) throws WXPlaceOrderParamsException, Exception { if (params == null) throw new WXPlaceOrderParamsException(1, "请传入下单参数"); if (params.getApp() == null) throw new WXPlaceOrderParamsException(2, "请传入下单应用信息"); if (StringUtil.isNullOrEmpty(params.getApp().getAppId())) throw new WXPlaceOrderParamsException(201, "请传入下单应用信息-appId"); if (StringUtil.isNullOrEmpty(params.getApp().getMchId())) throw new WXPlaceOrderParamsException(203, "请传入下单应用信息-mchId"); if (StringUtil.isNullOrEmpty(params.getApp().getApiV3Key())) throw new WXPlaceOrderParamsException(204, "请传入下单应用信息apiV3Key"); if (StringUtil.isNullOrEmpty(params.getBody())) throw new WXPlaceOrderParamsException(3, "请传入body"); if (StringUtil.isNullOrEmpty(params.getOrderNo())) throw new WXPlaceOrderParamsException(4, "请传入orderNo"); if (params.getFee() == null) throw new WXPlaceOrderParamsException(5, "请传入fee"); if (StringUtil.isNullOrEmpty(params.getIp())) throw new WXPlaceOrderParamsException(6, "请传入ip"); if (StringUtil.isNullOrEmpty(params.getNotifyUrl())) throw new WXPlaceOrderParamsException(7, "请传入notifyUrl"); // 请求body参数 String reqdata = "{" + "\"amount\": {" + "\"total\": " + params.getFee().multiply(new BigDecimal(100)).intValue() + "," + "\"currency\": \"CNY\"" + "}," + "\"scene_info\": {" + "\"payer_client_ip\":\"" + params.getIp() + "\"," + "\"h5_info\": {" + "\"type\": \"Wap\"" + "}}," + "\"mchid\": \"" + params.getApp().getMchId() + "\"," + "\"description\": \"" + params.getBody() + "\"," + "\"notify_url\": \"" + params.getNotifyUrl() + "\","; //附加数据,在支付结果通知中会原样返回 if (params.getAttach() != null) reqdata += ("\"attach\": \"" + params.getAttach() + "\","); reqdata += ("\"out_trade_no\": \"" + params.getOrderNo() + "\"," + "\"appid\": \"" + params.getApp().getAppId() + "\"" + "}"); JSONObject result = request("https://api.mch.weixin.qq.com/v3/pay/transactions/h5", reqdata, params.getApp()); if (result == null) return null; return result.optString("h5_url") + "&redirect_url=" + URLEncoder.encode(redirectUrl, "UTF-8"); } /** * 查询订单号是否支付成功 * * @param orderNo * @param app * @return * @throws WXOrderException */ public static boolean isPaySuccess(String orderNo, WXAPPInfo app) throws Exception { String url = String.format("https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/%s?mchid=%s", URLEncoder.encode(orderNo), app.getMchId()); JSONObject result = request(url, null, app); if (result == null) return false; return "SUCCESS".equalsIgnoreCase(result.optString("trade_state")); } public static void main(String[] args) { String privateKey = ""; try { String content = IOUtils.toString(new FileInputStream("D:\\项目\\返利券\\商户平台\\1520950211_20210125_cert\\apiclient_key.pem")); privateKey = content.replace("-----BEGIN PRIVATE KEY-----", "") .replace("-----END PRIVATE KEY-----", "") .replaceAll("\\s+", ""); } catch (Exception e) { } WXPlaceOrderParams params = new WXPlaceOrderParams(); params.setBody("影视大全VIP-包月"); params.setFee(new BigDecimal("0.1")); params.setNotifyUrl("http://api.ysdq.yeshitv.com:8089/BuWan/wx/pay/vip"); params.setOrderNo("buwan-vip-8"); params.setIp("113.249.192.231"); params.setApp(new WXAPPInfo("wxa99686bb65a9f466", "1520950211", "454328C324C6CC21355D064B44D6524CD7506DD0", privateKey, "XYJkJ2018FAfaodCCx899mLl138rfGVd")); try { String payUrl = WXPayV3Util.createH5Order(params, "http://vip.ysdq.yeshitv.com/wx_result.html"); System.out.println(payUrl); } catch (Exception e) { e.printStackTrace(); } } } utils/utils.iml
@@ -40,6 +40,11 @@ <orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.26" level="project" /> <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.7.0" level="project" /> <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.12.0" level="project" /> <orderEntry type="library" name="Maven: com.github.wechatpay-apiv3:wechatpay-apache-httpclient:0.2.1" level="project" /> <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.12" level="project" /> <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.10" level="project" /> <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.10" level="project" /> <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.10" level="project" /> <orderEntry type="library" name="Maven: net.sf.ehcache:ehcache-core:2.6.11" level="project" /> <orderEntry type="library" name="Maven: net.sf.ehcache:ehcache-web:2.0.4" level="project" /> <orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.0.RELEASE" level="project" /> @@ -103,9 +108,6 @@ <orderEntry type="library" name="Maven: com.github.jai-imageio:jai-imageio-core:1.3.0" level="project" /> <orderEntry type="library" name="Maven: com.qcloud:cos_api:5.2.4" level="project" /> <orderEntry type="library" name="Maven: joda-time:joda-time:2.9.6" level="project" /> <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.5" level="project" /> <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" /> <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.5" level="project" /> <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" /> <orderEntry type="library" name="Maven: commons-fileupload:commons-fileupload:1.3.1" level="project" /> <orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" /> @@ -115,7 +117,6 @@ <orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.47" level="project" /> <orderEntry type="library" name="Maven: com.github.qcloudsms:qcloudsms:1.0.2" level="project" /> <orderEntry type="library" name="Maven: org.json:json:20170516" level="project" /> <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.3" level="project" /> <orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:2.13.0-rc0" level="project" /> <orderEntry type="library" name="Maven: org.springframework.data:spring-data-mongodb:1.10.10.RELEASE" level="project" /> <orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:1.13.10.RELEASE" level="project" />