yujian
2019-09-03 972d3bc71115ec977dccf835fbcd148da3bcc86c
fanli/src/main/java/com/yeshi/fanli/service/impl/integral/IntegralTaskRecordServiceImpl.java
@@ -14,6 +14,7 @@
import org.yeshi.utils.DateUtil;
import com.yeshi.fanli.dao.mybatis.integral.IntegralTaskRecordMapper;
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.entity.integral.IntegralTask;
@@ -24,11 +25,14 @@
import com.yeshi.fanli.exception.integral.IntegralTaskRecordException;
import com.yeshi.fanli.exception.user.UserInfoExtraException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.integral.IntegralDetailService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskClassService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskRecordService;
import com.yeshi.fanli.service.inter.integral.IntegralTaskService;
import com.yeshi.fanli.service.inter.msg.UserOtherMsgNotificationService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
@Service
@@ -48,6 +52,14 @@
   @Resource
   private IntegralTaskClassService integralTaskClassService;
   @Resource
   private UserOtherMsgNotificationService userOtherMsgNotificationService;
   @Resource
   private ConfigService configService;
   @Override
   public Integer getTotalGoldCoin(long uid, Long cid, Integer dateType) {
@@ -191,13 +203,18 @@
      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)
            continue;
         if (addDetail(uid, record))
            totalGoldCoin += record.getGoldCoin();
      }
@@ -279,19 +296,18 @@
         }
         detail.setTitle(taskClass.getName() + "-第" + num + "天");
      } else {
         int num = 0;
         FrequencyEnum frequency = integralTask.getFrequency();
         if (frequency == FrequencyEnum.everyday) {
            num = integralTaskRecordMapper.countByTaskIdTodayNum(uid, taskId,
            int num = integralTaskRecordMapper.countByTaskIdTodayNum(uid, taskId,
                  TimeUtil.getWholeTime(record.getCreateTime().getTime()));
            if (num <= 0)
               num = 1;
            String title = taskClass.getName() + "-" + integralTask.getName() + "-第" + num + "次";
            detail.setTitle(title);
         } else if (frequency == FrequencyEnum.onlyOne) {
            num = 1;
            String title = taskClass.getName() + "-" + integralTask.getName();
            detail.setTitle(title);
         }
         if (num <= 0)
            num = 1;
         String title = taskClass.getName() + "-" + integralTask.getName() + "-第" + num + "次";
         detail.setTitle(title);
      }
      detail.setUid(uid);
@@ -304,11 +320,16 @@
   @Override
   public int countGetCountByTaskIdAndDay(Long taskId, Long uid, Date day) {
      if (day == null)
         return 0;
      Date minTime = new Date(
            TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(day.getTime(), "yyyy-MM-dd"), "yyyy-MM-dd"));
      Date maxTime = new Date(minTime.getTime() + 1000 * 60 * 60 * 24L);
      Date minTime = null;
      Date maxTime = null;
      if (day == null) {
         minTime = new Date(TimeUtil.convertToTimeTemp("1970-01-01", "yyyy-MM-dd"));
         maxTime = new Date(TimeUtil.convertToTimeTemp("2100-01-01", "yyyy-MM-dd"));
      } else {
         minTime = new Date(
               TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(day.getTime(), "yyyy-MM-dd"), "yyyy-MM-dd"));
         maxTime = new Date(minTime.getTime() + 1000 * 60 * 60 * 24L);
      }
      return integralTaskRecordMapper.countGetCountByTaskIdAndDay(taskId, uid, minTime, maxTime);
   }
@@ -341,4 +362,61 @@
   public long countByCidAndUidAndCreateTime(Long cid, Long uid, Date minTime, Date maxTime) {
      return integralTaskRecordMapper.countByCidAndUidAndCreateTime(cid, uid, minTime, maxTime);
   }
   @Override
   public List<IntegralTaskRecord> listByUidAndTaskId(Long uid, Long taskId, int page, int count) {
      return integralTaskRecordMapper.listByUidAndTaskId(uid, taskId, (page - 1) * count, count);
   }
   /**
    * 被邀请人下了首单(第一笔返利订单) 直接给邀请人一笔金币
    * @param uid
    */
   @Override
   public void firstOrderRewardInviter(Long uid, String beizu) {
      UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid);
      if (userInfoExtra == null)
         return;
      String reward = configService.get("first_order_reward_boss");
      if (StringUtil.isNullOrEmpty(reward))
         return;
      Integer goldCoin = userInfoExtra.getGoldCoin();
      if (goldCoin == null)
         goldCoin = 0;
      int addGoldCoin = Integer.parseInt(reward);
      goldCoin = goldCoin + addGoldCoin;
      try {
         // 增加金币
         UserInfoExtra extra = new UserInfoExtra();
         extra.setId(userInfoExtra.getId());
         extra.setGoldCoin(goldCoin);
         userInfoExtraService.saveUserInfoExtra(extra);
      } catch (UserInfoExtraException e) {
         e.printStackTrace();
         return;
      }
      // 金币详情
      IntegralDetail detail = new IntegralDetail();
      detail.setTitle("队员首笔奖励");
      detail.setUid(uid);
      detail.setMoney(addGoldCoin);
      detail.setRemark(beizu);
      detail.setCreateTime(new Date());
      integralDetailService.insertSelective(detail);
      // 消息
      MsgOtherRewardIntegralDTO msgOther = new MsgOtherRewardIntegralDTO();
      msgOther.setTitle("金币奖励");
      msgOther.setSource("一级队员首笔下单,系统奖励邀请人金币");
      msgOther.setNum(addGoldCoin + "金币");
      msgOther.setTotal(goldCoin + "金币");
      msgOther.setExplain("仅一级队员首笔下单奖励");
      userOtherMsgNotificationService.firstOrderRewardMsg(uid, "订单已到账后系统会自动奖励", msgOther);
   }
}