From 0ec22dcf4fd9c4496e6f681e7fab89f56c6e4e8a Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期四, 02 四月 2020 14:45:20 +0800 Subject: [PATCH] vip 消息 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java | 119 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 97 insertions(+), 22 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java index 2722005..500a5d6 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/integral/IntegralTaskRecordServiceImpl.java @@ -1,5 +1,6 @@ package com.yeshi.fanli.service.impl.user.integral; +import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -15,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional; import org.yeshi.utils.DateUtil; +import com.aliyun.openservices.ons.api.Producer; import com.yeshi.fanli.dao.mybatis.integral.IntegralTaskRecordMapper; import com.yeshi.fanli.dto.msg.MsgOtherRewardIntegralDTO; import com.yeshi.fanli.entity.bus.user.UserInfoExtra; @@ -24,6 +26,7 @@ import com.yeshi.fanli.entity.integral.IntegralTaskClass; import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum; import com.yeshi.fanli.entity.integral.IntegralTaskRecord; +import com.yeshi.fanli.entity.system.ConfigKeyEnum; import com.yeshi.fanli.exception.integral.IntegralTaskRecordException; import com.yeshi.fanli.exception.user.UserInfoExtraException; import com.yeshi.fanli.log.LogHelper; @@ -34,6 +37,7 @@ import com.yeshi.fanli.service.inter.user.integral.IntegralTaskClassService; import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService; import com.yeshi.fanli.service.inter.user.integral.IntegralTaskService; +import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.TimeUtil; @@ -62,6 +66,9 @@ @Resource private ConfigService configService; + @Resource(name = "producer") + private Producer producer; + @Override public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) { return integralTaskRecordMapper.getTotalGoldCoin(uid, cid, dateType); @@ -73,13 +80,18 @@ } @Override + public void invalidGoldCoin() { + integralTaskRecordMapper.invalidGoldCoin(); + } + + @Override public void finishedTask(long uid, long cid, long taskId, int goldCoin) { IntegralTaskRecord taskRecord = new IntegralTaskRecord(); taskRecord.setUid(uid); taskRecord.setCid(cid); taskRecord.setTaskId(taskId); taskRecord.setGoldCoin(goldCoin); - taskRecord.setState(0); + taskRecord.setState(IntegralTaskRecord.STATE_WAITING_RECIEVE); taskRecord.setCreateTime(new Date()); taskRecord.setUpdateTime(new Date()); integralTaskRecordMapper.insertSelective(taskRecord); @@ -206,7 +218,7 @@ // 鏇存柊閲戝竵 userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin); - return (userInfoExtra.getGoldCoin()==null?0:userInfoExtra.getGoldCoin()) + totalGoldCoin; + return (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin()) + totalGoldCoin; } @Override @@ -229,7 +241,7 @@ // 宸查鍙� Integer state = record.getState(); - if (state != null && state == 1) + if (state != null && state != 0) continue; if (addDetail(uid, record)) @@ -239,10 +251,10 @@ // 鏇存柊閲戝竵 userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin); - return totalGoldCoin+(userInfoExtra.getGoldCoin()==null?0:userInfoExtra.getGoldCoin()); + return totalGoldCoin + (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin()); } - @Transactional + @Transactional(rollbackFor = Exception.class) public boolean addDetail(Long uid, IntegralTaskRecord record) throws IntegralTaskRecordException { Long uid2 = record.getUid(); if (uid2 == null || uid.longValue() != uid2.longValue()) @@ -306,7 +318,7 @@ FrequencyEnum frequency = integralTask.getFrequency(); if (frequency == FrequencyEnum.everyday) { int num = integralTaskRecordMapper.countByTaskIdTodayNum(uid, taskId, - TimeUtil.getWholeTime(record.getCreateTime().getTime())); + TimeUtil.getWholeTime(record.getCreateTime().getTime()), record.getId()); if (num <= 0) num = 1; String title = taskClass.getName() + "-" + integralTask.getName() + "-绗�" + num + "娆�"; @@ -340,6 +352,7 @@ return integralTaskRecordMapper.countGetCountByTaskIdAndDay(taskId, uid, minTime, maxTime); } + @Transactional(rollbackFor = Exception.class) @Override public IntegralTaskRecord addRecord(IntegralTaskRecord record) throws IntegralTaskRecordException { if (record == null) @@ -348,12 +361,15 @@ if (record.getCid() == null || record.getTaskId() == null || record.getGoldCoin() == null || record.getState() == null || record.getUid() == null) throw new IntegralTaskRecordException(2, "鏁版嵁涓嶅畬鎴�"); - + Date date = new Date(); if (record.getCreateTime() == null) - record.setCreateTime(new Date()); + record.setCreateTime(date); if (record.getUpdateTime() == null) - record.setUpdateTime(new Date()); + record.setUpdateTime(date); + + // 璁剧疆鏈夋晥鏈� + record.setEndTime(DateUtil.plusDayDate(Constant.GOLD_COIN_VALID_DAYS, date)); integralTaskRecordMapper.insertSelective(record); return record; } @@ -375,13 +391,14 @@ return integralTaskRecordMapper.listByUidAndTaskId(uid, taskId, (page - 1) * count, count); } + @Async() @Override public void firstRebateOrderRewardBoss(Long uid, Long originUid, String beizu) { if (uid == null || originUid == null) return; - String reward = configService.get("first_order_reward_boss"); + String reward = configService.get(ConfigKeyEnum.firstOrderRewardBoss.getKey()); if (StringUtil.isNullOrEmpty(reward)) return; firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu); @@ -393,7 +410,7 @@ if (uid == null || originUid == null) return; - String reward = configService.get("first_order_reward_boss_super"); + String reward = configService.get(ConfigKeyEnum.firstOrderRewardBossSuper.getKey()); if (StringUtil.isNullOrEmpty(reward)) return; firstOrderReward(uid, originUid, Integer.parseInt(reward), "浜�", beizu); @@ -405,7 +422,7 @@ if (uid == null) return; - String reward = configService.get("first_share_order_reward"); + String reward = configService.get(ConfigKeyEnum.firstShareOrderReward.getKey()); if (StringUtil.isNullOrEmpty(reward)) return; firstOrderReward(uid, null, Integer.parseInt(reward), null, beizu); @@ -417,7 +434,7 @@ if (uid == null || originUid == null) return; - String reward = configService.get("first_share_order_reward_boss"); + String reward = configService.get(ConfigKeyEnum.firstShareOrderRewardBoss.getKey()); if (StringUtil.isNullOrEmpty(reward)) return; firstOrderReward(uid, originUid, Integer.parseInt(reward), "涓�", beizu); @@ -446,16 +463,18 @@ if (userInfoExtra == null) return; - Integer goldCoin = userInfoExtra.getGoldCoin(); - if (goldCoin == null) - goldCoin = 0; - goldCoin = goldCoin + addGoldCoin; - + int totalGoldCoin = 0; try { UserInfoExtra extra = new UserInfoExtra(); extra.setId(userInfoExtra.getId()); - extra.setGoldCoin(goldCoin); + Integer goldCoin = userInfoExtra.getGoldCoin(); + if (goldCoin == null) { + extra.setGoldCoin(addGoldCoin); + } else { + extra.setGoldCoin(goldCoin + addGoldCoin); + } userInfoExtraService.saveUserInfoExtra(extra); + totalGoldCoin = extra.getGoldCoin(); } catch (UserInfoExtraException e) { LogHelper.errorDetailInfo(e); return; @@ -475,14 +494,70 @@ MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO(); msgOther.setTitle("閲戝竵濂栧姳"); msgOther.setNum(addGoldCoin + "閲戝竵"); - msgOther.setTotal(goldCoin + "閲戝竵"); + msgOther.setTotal(totalGoldCoin + "閲戝竵"); if (StringUtil.isNullOrEmpty(level)) { msgOther.setSource("棣栫瑪鍒嗕韩璁㈠崟锛岀郴缁熷鍔遍噾甯� "); msgOther.setExplain("棣栫瑪鍒嗕韩璁㈠崟寰楀埌鐨勫閲戜笉瓒�0.01鍏冩椂濂栧姳 "); } else { - msgOther.setSource(level + "绾ч槦鍛橀娆′笅鍗曪紝绯荤粺濂栧姳閲戝竵 "); - msgOther.setExplain("浠呮柊閭�璇烽槦鍛橀涓嬪崟浣犲緱鍒扮殑濂栭噾涓嶈冻0.01鍏冩椂濂栧姳 "); + if (level.equalsIgnoreCase("涓�") || level.equalsIgnoreCase("1")) + msgOther.setSource("鐩存帴绮変笣棣栨涓嬪崟锛岀郴缁熷鍔遍噾甯� "); + else + msgOther.setSource("闂存帴绮変笣棣栨涓嬪崟锛岀郴缁熷鍔遍噾甯� "); + msgOther.setExplain("浠呮柊閭�璇风矇涓濋涓嬪崟浣犲緱鍒扮殑濂栭噾涓嶈冻0.01鍏冩椂濂栧姳 "); } userOtherMsgNotificationService.firstOrderRewardMsg(uid, null, msgOther); } + + /** + * 鎺ㄥ箍绾㈠寘鎶樼畻閲戝竵 + * + * @param uid + * @param addGoldCoin + * @param tlj + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void taoLiJinExchange(Long uid, Integer addGoldCoin, BigDecimal tlj) { + String uniqueKey = "taoLiJinExchange-" + uid.toString(); + IntegralDetail detailRecord = integralDetailService.getDetailByUniqueKey(uniqueKey); + if (detailRecord != null) + return; + + UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid); + if (userInfoExtra == null) + return; + + Integer goldCoin = userInfoExtra.getGoldCoin(); + if (goldCoin == null) + goldCoin = 0; + goldCoin = goldCoin + addGoldCoin; + + try { + UserInfoExtra extra = new UserInfoExtra(); + extra.setId(userInfoExtra.getId()); + extra.setGoldCoin(goldCoin); + userInfoExtraService.saveUserInfoExtra(extra); + } catch (UserInfoExtraException e) { + LogHelper.errorDetailInfo(e); + return; + } + + // 閲戝竵璇︽儏 + IntegralDetail detail = new IntegralDetail(); + detail.setTitle("鎺ㄥ箍绾㈠寘涓嬬嚎-绯荤粺鎶樼畻鎴愰噾甯�"); + detail.setUid(uid); + detail.setMoney(addGoldCoin); + detail.setUniqueKey(uniqueKey); + detail.setCreateTime(new Date()); + integralDetailService.insertSelective(detail); + + // 娑堟伅 + MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO(); + msgOther.setTitle("鎺ㄥ箍绾㈠寘"); + msgOther.setTotal("鎺ㄥ箍绾㈠寘楼" + tlj.setScale(2)); + msgOther.setNum(addGoldCoin + "鏋�"); + msgOther.setSource("宸茶繘鍏ュ埌鍙敤閲戝竵涓�"); + msgOther.setExplain("鍘熸帹骞跨孩鍖呭姛鑳戒笅绾匡紝鍓╀綑鎺ㄥ箍绾㈠寘鎸夌収10:1鎶樼畻涓洪噾甯� "); + userOtherMsgNotificationService.taoLiJinExchangeMsg(uid, "鏈姌绠楁湁涓斾粎鏈変竴娆�", msgOther); + } } -- Gitblit v1.8.0