|
@@ -0,0 +1,70 @@
|
|
|
|
|
+package com.td.boss.game.comcnttosnb.service;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
+import com.td.boss.common.pojo.Result;
|
|
|
|
|
+import com.td.boss.common.service.CommonServiceImpl;
|
|
|
|
|
+import com.td.boss.game.comcnttosnb.pojo.ComCntToSnb;
|
|
|
|
|
+import com.td.boss.game.comcnttosnb.repository.ComCntToSnbRespository;
|
|
|
|
|
+import com.td.boss.game.comcnttosnb.vo.ComCntToSnbVo;
|
|
|
|
|
+import com.td.boss.game.comusers.service.ComUsersService;
|
|
|
|
|
+import com.td.boss.util.CopyUtil;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+public class ComCntToSnbServiceImpl extends CommonServiceImpl<ComCntToSnbVo, ComCntToSnb, Integer> implements ComCntToSnbService {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ComCntToSnbRespository comCntToSnbRespository;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ComUsersService comUsersService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 通过userid查看snb领取情况
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param userId 用户id
|
|
|
|
|
+ * @return {@link ComCntToSnbVo}
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ComCntToSnbVo findByUserId(String userId) {
|
|
|
|
|
+ ComCntToSnb comCntToSnb = comCntToSnbRespository.findByUserId(userId).orElse(null);
|
|
|
|
|
+ return comCntToSnb == null ? null : CopyUtil.copy(comCntToSnb, ComCntToSnbVo.class);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 通过userid领取snb
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param userId 用户id
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Result<String> receiveByUserId(String userId) {
|
|
|
|
|
+ ComCntToSnb comCntToSnb = comCntToSnbRespository.findByUserId(userId).orElse(null);
|
|
|
|
|
+ if (comCntToSnb == null || comCntToSnb.getStatus().equals(0)) {
|
|
|
|
|
+ return Result.of(null, false, "非法领取");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (comCntToSnb.getReceivedDay() >= comCntToSnb.getTotalDay()) {
|
|
|
|
|
+ return Result.of(null, false, "已全部领取完毕");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 计算可领天数. 服务器时间 - 开始时间
|
|
|
|
|
+ Integer day = Convert.toInt(DateUtil.betweenDay(comCntToSnb.getBeginTime(), new Date(), true));
|
|
|
|
|
+ if (day - comCntToSnb.getReceivedDay() <= 0) {
|
|
|
|
|
+ return Result.of(null, false, "领取失败,今日已领取");
|
|
|
|
|
+ }
|
|
|
|
|
+ DateUtil.offsetDay(comCntToSnb.getBeginTime(), comCntToSnb.getReceivedDay());
|
|
|
|
|
+ // 本次领取量
|
|
|
|
|
+ comCntToSnb.setReceivedQuantity(
|
|
|
|
|
+ NumberUtil.add(
|
|
|
|
|
+ comCntToSnb.getReceivedQuantity(),
|
|
|
|
|
+ NumberUtil.mul(comCntToSnb.getUnitQuantity(), day)
|
|
|
|
|
+ ));
|
|
|
|
|
+ // 本次领取天数
|
|
|
|
|
+ comCntToSnb.setReceivedDay(comCntToSnb.getReceivedDay() + day);
|
|
|
|
|
+ comCntToSnbRespository.save(comCntToSnb);
|
|
|
|
|
+ //TODO 更新comUsers
|
|
|
|
|
+ //TODO 插入comSnbTran
|
|
|
|
|
+ return Result.of(null, false, "领取成功");
|
|
|
|
|
+ }
|
|
|
|
|
+}
|