| | |
| | | package com.yeshi.fanli.service.impl.user.integral;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | |
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.yeshi.utils.DateUtil;
|
| | |
|
| | | import com.aliyun.openservices.ons.api.Message;
|
| | | import com.aliyun.openservices.ons.api.Producer;
|
| | | import com.google.gson.Gson;
|
| | | import com.yeshi.fanli.dao.mybatis.integral.IntegralTaskRecordMapper;
|
| | | import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
|
| | | import com.yeshi.fanli.dto.mq.user.body.IntegralTaskMQMsg;
|
| | | import com.yeshi.fanli.dto.msg.MsgOtherRewardIntegralDTO;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.entity.integral.IntegralDetail;
|
| | |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | |
|
| | | @Service
|
| | | public class IntegralTaskRecordServiceImpl implements IntegralTaskRecordService {
|
| | |
| | | @Lazy
|
| | | @Resource
|
| | | private IntegralTaskClassService integralTaskClassService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private UserOtherMsgNotificationService userOtherMsgNotificationService;
|
| | | |
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | | |
| | | |
| | |
|
| | | @Resource(name = "producer")
|
| | | private Producer producer;
|
| | |
|
| | | @Override
|
| | | public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) {
|
| | |
| | | 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);
|
| | |
| | | return listRecord;
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public List<IntegralTaskRecord> getSign7DaysRecord(long uid, Long cid) {
|
| | | List<IntegralTaskRecord> listRecord = new ArrayList<IntegralTaskRecord>();
|
| | |
| | | }
|
| | | date = createTime;
|
| | | listRecord.add(record);
|
| | | |
| | | if(listRecord.size() >= 7)
|
| | |
|
| | | if (listRecord.size() >= 7)
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | }
|
| | | return listRecord;
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public List<IntegralTaskRecord> listNotReceived(int count, long uid) {
|
| | | return integralTaskRecordMapper.listNotReceived(count, uid);
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public Integer receiveGoldCoinALL(Long uid) throws IntegralTaskRecordException {
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getByUidForUpdate(uid);
|
| | | if (userInfoExtra == null)
|
| | |
| | | if (addDetail(uid, record))
|
| | | totalGoldCoin += record.getGoldCoin();
|
| | | }
|
| | | |
| | | Integer goldCoin = userInfoExtra.getGoldCoin();
|
| | | if (goldCoin == null)
|
| | | goldCoin = 0;
|
| | |
|
| | | goldCoin = goldCoin + totalGoldCoin;
|
| | | |
| | | // 更新金币
|
| | | userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), goldCoin);
|
| | | |
| | | return goldCoin;
|
| | | userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
|
| | |
|
| | | return (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin()) + totalGoldCoin;
|
| | | }
|
| | |
|
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class)
|
| | | @Override
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | public Integer receiveGoldCoin(Long uid, Set<Long> idList) throws IntegralTaskRecordException {
|
| | | if (idList == null || idList.size() == 0) {
|
| | | throw new IntegralTaskRecordException(1, "id为空");
|
| | |
| | | if (userInfoExtra == null) {
|
| | | throw new IntegralTaskRecordException(1, "用户信息不全");
|
| | | }
|
| | | |
| | |
|
| | | Integer totalGoldCoin = 0;
|
| | | for (Long id : idList) {
|
| | | IntegralTaskRecord record = integralTaskRecordMapper.selectByPrimaryKey(id);
|
| | | if (record == null)
|
| | | continue;
|
| | | |
| | |
|
| | | // 已领取
|
| | | Integer state = record.getState();
|
| | | if (state != null && state == 1) |
| | | if (state != null && state == 1)
|
| | | continue;
|
| | | |
| | |
|
| | | if (addDetail(uid, record))
|
| | | totalGoldCoin += record.getGoldCoin();
|
| | | }
|
| | | |
| | | Integer goldCoin = userInfoExtra.getGoldCoin();
|
| | | if (goldCoin == null)
|
| | | goldCoin = 0;
|
| | |
|
| | | goldCoin = goldCoin + totalGoldCoin;
|
| | | |
| | | // 更新金币
|
| | | userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), goldCoin);
|
| | | userInfoExtraService.updateGoldCoin(userInfoExtra.getId(), totalGoldCoin);
|
| | |
|
| | | return goldCoin;
|
| | | return totalGoldCoin + (userInfoExtra.getGoldCoin() == null ? 0 : userInfoExtra.getGoldCoin());
|
| | | }
|
| | |
|
| | | @Transactional
|
| | |
| | | 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 + "次";
|
| | |
| | | return integralTaskRecordMapper.countGetCountByTaskIdAndDay(taskId, uid, minTime, maxTime);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public IntegralTaskRecord addRecord(IntegralTaskRecord record) throws IntegralTaskRecordException {
|
| | | if (record == null)
|
| | |
| | | if (record.getUpdateTime() == null)
|
| | | record.setUpdateTime(new Date());
|
| | | integralTaskRecordMapper.insertSelective(record);
|
| | | long count = integralTaskRecordMapper.getTotalGoldCoinByUid(record.getUid());
|
| | | if (count >= 200) {// 大于200发送消息
|
| | | IntegralTaskMQMsg msg = new IntegralTaskMQMsg(record.getUid(), count, new Date());
|
| | | Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.integralTaskFinish,
|
| | | msg);
|
| | | producer.send(message);
|
| | | }
|
| | |
|
| | | return record;
|
| | | }
|
| | |
|
| | |
| | | public List<IntegralTaskRecord> listByUidAndTaskId(Long uid, Long taskId, int page, int count) {
|
| | | return integralTaskRecordMapper.listByUidAndTaskId(uid, taskId, (page - 1) * count, count);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | public long getTotalGoldCoinByUid(Long uid) {
|
| | | return integralTaskRecordMapper.getTotalGoldCoinByUid(uid);
|
| | | }
|
| | |
|
| | | @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");
|
| | | if (StringUtil.isNullOrEmpty(reward)) |
| | | if (StringUtil.isNullOrEmpty(reward))
|
| | | return;
|
| | | firstOrderReward(uid, originUid, Integer.parseInt(reward), "一", beizu);
|
| | | }
|
| | | |
| | |
|
| | | @Async()
|
| | | @Override
|
| | | public void firstRebateOrderRewardBossSuper(Long uid, Long originUid, String beizu) {
|
| | | if (uid == null || originUid == null)
|
| | | return;
|
| | | |
| | |
|
| | | String reward = configService.get("first_order_reward_boss_super");
|
| | | if (StringUtil.isNullOrEmpty(reward)) |
| | | if (StringUtil.isNullOrEmpty(reward))
|
| | | return;
|
| | | firstOrderReward(uid, originUid, Integer.parseInt(reward), "二", beizu);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Async()
|
| | | @Override
|
| | | public void firstShareOrderReward(Long uid, String beizu) {
|
| | | if(uid == null)
|
| | | if (uid == null)
|
| | | return;
|
| | | |
| | |
|
| | | String reward = configService.get("first_share_order_reward");
|
| | | if (StringUtil.isNullOrEmpty(reward)) |
| | | if (StringUtil.isNullOrEmpty(reward))
|
| | | return;
|
| | | firstOrderReward(uid, null, Integer.parseInt(reward), null, beizu);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Async()
|
| | | @Override
|
| | | public void firstSharerOrderRewardBoss(Long uid, Long originUid, String beizu) {
|
| | | if (uid == null || originUid == null)
|
| | | return;
|
| | | |
| | |
|
| | | String reward = configService.get("first_share_order_reward_boss");
|
| | | if (StringUtil.isNullOrEmpty(reward)) |
| | | if (StringUtil.isNullOrEmpty(reward))
|
| | | return;
|
| | | firstOrderReward(uid, originUid, Integer.parseInt(reward), "一", beizu);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 队员首单奖励金币
|
| | | * |
| | | * @param uid
|
| | | * @param addGoldCoin
|
| | | * @param level 所属哪级队员
|
| | | * @param level
|
| | | * 所属哪级队员
|
| | | * @param beizu
|
| | | */
|
| | | private void firstOrderReward(Long uid, Long originUid, Integer addGoldCoin, String level, String beizu) {
|
| | | String uniqueKey = "firstOrder-"+ uid.toString();
|
| | | if (originUid != null) |
| | | String uniqueKey = "firstOrder-" + uid.toString();
|
| | | if (originUid != null)
|
| | | uniqueKey = uniqueKey + "-" + originUid;
|
| | | |
| | |
|
| | | // 判断是否已领取
|
| | | IntegralDetail detailRecord = integralDetailService.getDetailByUniqueKey(uniqueKey);
|
| | | if (detailRecord != null)
|
| | | return;
|
| | | |
| | |
|
| | | UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
|
| | | if (userInfoExtra == null) |
| | | 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());
|
| | |
| | | detail.setUniqueKey(uniqueKey);
|
| | | detail.setCreateTime(new Date());
|
| | | integralDetailService.insertSelective(detail);
|
| | | |
| | |
|
| | | // 消息
|
| | | MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO();
|
| | | msgOther.setTitle("金币奖励");
|
| | |
| | | }
|
| | | 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);
|
| | | }
|
| | | }
|