|
|
@@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import io.renren.common.utils.PageUtils;
|
|
|
import io.renren.common.utils.R;
|
|
|
+import io.renren.modules.qmgj.dao.MemberInfoDao;
|
|
|
+import io.renren.modules.qmgj.entity.MemberInfoEntity;
|
|
|
import io.renren.modules.qmjz.entity.ScoreStu;
|
|
|
import io.renren.modules.qmjz.entity.TaskManage;
|
|
|
import io.renren.modules.qmjz.entity.bo.ScoreStuBo;
|
|
|
@@ -21,8 +23,11 @@ import io.renren.modules.qmjz.model.PageQuery;
|
|
|
import io.renren.modules.qmjz.service.ScoreStuService;
|
|
|
import io.renren.modules.qmjz.utils.DateForStr;
|
|
|
import io.renren.modules.qmjz.utils.StringUtils;
|
|
|
+import io.renren.modules.qyh.entity.PointsGiftConfigEntity;
|
|
|
+import io.renren.modules.qyh.service.PointsGiftConfigService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
@@ -38,7 +43,11 @@ public class ScoreStuServiceImpl extends ServiceImpl<ScoreStuMapper, ScoreStu> i
|
|
|
@Autowired
|
|
|
private TaskManageMapper taskManageMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PointsGiftConfigService pointsGiftConfigService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MemberInfoDao memberInfoDao;
|
|
|
/**
|
|
|
* 每日登陆
|
|
|
*
|
|
|
@@ -93,6 +102,76 @@ public class ScoreStuServiceImpl extends ServiceImpl<ScoreStuMapper, ScoreStu> i
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public R giftPoints(Long stuId, Long receiveUserId, Integer giftScore) {
|
|
|
+ if (ObjectUtil.isNull(stuId)) {
|
|
|
+ return R.error("赠送人不存在");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNull(receiveUserId)) {
|
|
|
+ return R.error("接收人不存在");
|
|
|
+ }
|
|
|
+ MemberInfoEntity memberInfoEntity = memberInfoDao.memberById(receiveUserId);
|
|
|
+ if (ObjectUtil.isNull(memberInfoEntity)) {
|
|
|
+ return R.error("接收人不存在");
|
|
|
+ }
|
|
|
+ if (stuId.equals(receiveUserId)) {
|
|
|
+ return R.error("不能给自己赠送积分");
|
|
|
+ }
|
|
|
+ PointsGiftConfigEntity info = pointsGiftConfigService.info();
|
|
|
+ if (ObjectUtil.isEmpty(giftScore) || giftScore < info.getMinGiftPoints() || giftScore > info.getMaxGiftPoints()) {
|
|
|
+ return R.error("赠送积分数量必须在" + info.getMinGiftPoints() + "-" + info.getMaxGiftPoints() + "之间");
|
|
|
+ }
|
|
|
+ // 查询今日赠送次数
|
|
|
+ Integer todayGiftCount = queryTodayGiftCount(stuId);
|
|
|
+ if (todayGiftCount >= info.getDailyGiftLimit()) {
|
|
|
+ return R.error("今日赠送次数已达上限(" + info.getDailyGiftLimit() + "次)");
|
|
|
+ }
|
|
|
+ // 检查赠送人积分是否足够
|
|
|
+ Integer totalScore = getTotalScore(stuId);
|
|
|
+ if (totalScore < giftScore) {
|
|
|
+ return R.error("积分不足");
|
|
|
+ }
|
|
|
+ String day = DateForStr.getInfoDateStr(new Date());
|
|
|
+ // 扣除赠送人积分
|
|
|
+ ScoreStu deductScore = new ScoreStu();
|
|
|
+ deductScore.setDay(day);
|
|
|
+ deductScore.setStuId(stuId);
|
|
|
+ deductScore.setScoreType(ScoreType.TASK_SCORE.getCode());
|
|
|
+ deductScore.setTaskId(TaskType.GIFT_POINTS.getCode());
|
|
|
+ deductScore.setBusinessId(receiveUserId);
|
|
|
+ deductScore.setScoreEvent(TaskType.GIFT_POINTS.getInfo());
|
|
|
+ deductScore.setScoreValue(-giftScore);
|
|
|
+ deductScore.setCreateTime(new Date());
|
|
|
+ deductScore.setSurplusScore(totalScore - giftScore);
|
|
|
+ scoreStuMapper.insert(deductScore);
|
|
|
+
|
|
|
+ // 增加接收人积分
|
|
|
+ Integer receiverTotalScore = getTotalScore(receiveUserId);
|
|
|
+ ScoreStu addScore = new ScoreStu();
|
|
|
+ addScore.setDay(day);
|
|
|
+ addScore.setStuId(receiveUserId);
|
|
|
+ addScore.setScoreType(ScoreType.TASK_SCORE.getCode());
|
|
|
+ addScore.setTaskId(TaskType.RECEIVE_GIFT_POINTS.getCode());
|
|
|
+ addScore.setBusinessId(stuId);
|
|
|
+ addScore.setScoreEvent(TaskType.RECEIVE_GIFT_POINTS.getInfo());
|
|
|
+ addScore.setScoreValue(giftScore);
|
|
|
+ addScore.setCreateTime(new Date());
|
|
|
+ addScore.setSurplusScore(receiverTotalScore + giftScore);
|
|
|
+ scoreStuMapper.insert(addScore);
|
|
|
+
|
|
|
+ return R.ok("成功赠送" + giftScore + "积分给" + memberInfoEntity.getVipname());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer queryTodayGiftCount(Long stuId) {
|
|
|
+ String day = DateForStr.getInfoDateStr();
|
|
|
+ return scoreStuMapper.selectCount(new LambdaQueryWrapper<ScoreStu>()
|
|
|
+ .eq(ScoreStu::getDay, day)
|
|
|
+ .eq(ScoreStu::getStuId, stuId)
|
|
|
+ .eq(ScoreStu::getTaskId, TaskType.GIFT_POINTS.getCode()));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* api获取总积分
|
|
|
*
|