|
@@ -1,14 +1,29 @@
|
|
|
package com.fs.his.service.impl;
|
|
package com.fs.his.service.impl;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.fs.course.config.CourseConfig;
|
|
|
|
|
+import com.fs.course.domain.FsUserCourseVideo;
|
|
|
|
|
+import com.fs.course.domain.FsUserCourseVideoRedPackage;
|
|
|
|
|
+import com.fs.course.mapper.FsUserCourseVideoMapper;
|
|
|
|
|
+import com.fs.course.mapper.FsUserCourseVideoRedPackageMapper;
|
|
|
|
|
+import com.fs.his.domain.FsCourseCouponUser;
|
|
|
|
|
+import com.fs.his.mapper.FsCourseCouponUserMapper;
|
|
|
|
|
+import com.fs.his.vo.CourseFinishRewardVO;
|
|
|
|
|
+import com.fs.system.service.ISysConfigService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fs.his.mapper.FsCourseCouponMapper;
|
|
import com.fs.his.mapper.FsCourseCouponMapper;
|
|
|
import com.fs.his.domain.FsCourseCoupon;
|
|
import com.fs.his.domain.FsCourseCoupon;
|
|
|
import com.fs.his.service.IFsCourseCouponService;
|
|
import com.fs.his.service.IFsCourseCouponService;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 课程优惠券Service业务层处理
|
|
* 课程优惠券Service业务层处理
|
|
@@ -19,6 +34,17 @@ import com.fs.his.service.IFsCourseCouponService;
|
|
|
@Service
|
|
@Service
|
|
|
public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper, FsCourseCoupon> implements IFsCourseCouponService {
|
|
public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper, FsCourseCoupon> implements IFsCourseCouponService {
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsCourseCouponUserMapper courseCouponUserMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsUserCourseVideoMapper userCourseVideoMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ISysConfigService configService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FsUserCourseVideoRedPackageMapper fsUserCourseVideoRedPackageMapper;
|
|
|
/**
|
|
/**
|
|
|
* 查询课程优惠券
|
|
* 查询课程优惠券
|
|
|
*
|
|
*
|
|
@@ -98,4 +124,156 @@ public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper,
|
|
|
public List<FsCourseCoupon> selectFsCourseCouponOptions() {
|
|
public List<FsCourseCoupon> selectFsCourseCouponOptions() {
|
|
|
return baseMapper.selectFsCourseCouponOptions();
|
|
return baseMapper.selectFsCourseCouponOptions();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ //自动
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public R sendAutoCourseCoupon(Long videoId, Long userId,Long companyId) {
|
|
|
|
|
+ CourseFinishRewardVO rewardVO = new CourseFinishRewardVO();
|
|
|
|
|
+
|
|
|
|
|
+ Integer integral = null;
|
|
|
|
|
+ BigDecimal amount = null;
|
|
|
|
|
+ String couponName = null;
|
|
|
|
|
+
|
|
|
|
|
+ boolean isSend = true;
|
|
|
|
|
+ //课程小节信息
|
|
|
|
|
+ FsUserCourseVideo courseVideo = userCourseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
|
|
|
|
|
+ if (courseVideo == null) {
|
|
|
|
|
+ return R.error("课程小节不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //优惠券
|
|
|
|
|
+ FsCourseCoupon fsCourseCoupon = baseMapper.selectFsCourseCouponById(courseVideo.getCourseCouponId());
|
|
|
|
|
+ if (fsCourseCoupon != null) {
|
|
|
|
|
+ if (fsCourseCoupon.getStatus() != 1) {
|
|
|
|
|
+ isSend = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fsCourseCoupon.getRemainNumber() <= 0) {
|
|
|
|
|
+ isSend = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ //用户领取优惠券总数
|
|
|
|
|
+ Integer count = courseCouponUserMapper.selectCountByUserIdAndCouponId(userId, courseVideo.getCourseCouponId());
|
|
|
|
|
+ if (count >= fsCourseCoupon.getLimitCount()) {
|
|
|
|
|
+ isSend = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ isSend = false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (isSend) {
|
|
|
|
|
+ //发放优惠券
|
|
|
|
|
+ FsCourseCouponUser couponUser = new FsCourseCouponUser();
|
|
|
|
|
+ couponUser.setCouponId(courseVideo.getCourseCouponId());
|
|
|
|
|
+ couponUser.setUserId(userId);
|
|
|
|
|
+ couponUser.setStartTime(new Date());
|
|
|
|
|
+ couponUser.setLimitTime(fsCourseCoupon.getLimitTime());
|
|
|
|
|
+ couponUser.setCreateTime(new Date());
|
|
|
|
|
+ int i = courseCouponUserMapper.insertFsCourseCouponUser(couponUser);
|
|
|
|
|
+
|
|
|
|
|
+ //返回的优惠券名称
|
|
|
|
|
+ couponName = fsCourseCoupon.getTitle();
|
|
|
|
|
+ if (i > 0) {
|
|
|
|
|
+ FsCourseCoupon coupon = new FsCourseCoupon();
|
|
|
|
|
+ coupon.setId(courseVideo.getCourseCouponId());
|
|
|
|
|
+ coupon.setRemainNumber(fsCourseCoupon.getRemainNumber() - 1);
|
|
|
|
|
+ baseMapper.updateFsCourseCoupon(coupon);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 获取配置信息
|
|
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
|
|
+ CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
|
|
+ Integer rewardType = config.getRewardType();
|
|
|
|
|
+
|
|
|
|
|
+ if (rewardType == 1) {
|
|
|
|
|
+ FsUserCourseVideoRedPackage redPackage = fsUserCourseVideoRedPackageMapper.selectRedPacketByVideoIdAndType(videoId, companyId, 1);
|
|
|
|
|
+ if (redPackage != null && redPackage.getRedPacketMoney() != null) {
|
|
|
|
|
+ amount = redPackage.getRedPacketMoney();
|
|
|
|
|
+ } else if (courseVideo.getRedPacketMoney() != null) {
|
|
|
|
|
+ amount = courseVideo.getRedPacketMoney();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (rewardType == 2) {
|
|
|
|
|
+ integral = config.getAnswerIntegral();
|
|
|
|
|
+ }
|
|
|
|
|
+ rewardVO.setCouponName(couponName);
|
|
|
|
|
+ rewardVO.setIntegral(integral);
|
|
|
|
|
+ rewardVO.setRedPacketMoney(amount);
|
|
|
|
|
+ return R.ok().put("data",rewardVO);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //手动
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public R sendCourseCoupon(Long videoId, Long userId,Long companyId,Long periodId) {
|
|
|
|
|
+ CourseFinishRewardVO rewardVO = new CourseFinishRewardVO();
|
|
|
|
|
+
|
|
|
|
|
+ Integer integral = null;
|
|
|
|
|
+ BigDecimal amount = null;
|
|
|
|
|
+ String couponName = null;
|
|
|
|
|
+
|
|
|
|
|
+ boolean isSend = true;
|
|
|
|
|
+ //课程小节信息
|
|
|
|
|
+ FsUserCourseVideo courseVideo = userCourseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
|
|
|
|
|
+ if (courseVideo == null) {
|
|
|
|
|
+ return R.error("课程小节不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //优惠券
|
|
|
|
|
+ FsCourseCoupon fsCourseCoupon = baseMapper.selectFsCourseCouponById(courseVideo.getCourseCouponId());
|
|
|
|
|
+ if (fsCourseCoupon != null) {
|
|
|
|
|
+ if (fsCourseCoupon.getStatus() != 1) {
|
|
|
|
|
+ isSend = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (fsCourseCoupon.getRemainNumber() <= 0) {
|
|
|
|
|
+ isSend = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ //用户领取优惠券总数
|
|
|
|
|
+ Integer count = courseCouponUserMapper.selectCountByUserIdAndCouponId(userId, courseVideo.getCourseCouponId());
|
|
|
|
|
+ if (count >= fsCourseCoupon.getLimitCount()) {
|
|
|
|
|
+ isSend = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ isSend = false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (isSend) {
|
|
|
|
|
+ //发放优惠券
|
|
|
|
|
+ FsCourseCouponUser couponUser = new FsCourseCouponUser();
|
|
|
|
|
+ couponUser.setCouponId(courseVideo.getCourseCouponId());
|
|
|
|
|
+ couponUser.setUserId(userId);
|
|
|
|
|
+ couponUser.setStartTime(new Date());
|
|
|
|
|
+ couponUser.setLimitTime(fsCourseCoupon.getLimitTime());
|
|
|
|
|
+ couponUser.setCreateTime(new Date());
|
|
|
|
|
+ int i = courseCouponUserMapper.insertFsCourseCouponUser(couponUser);
|
|
|
|
|
+
|
|
|
|
|
+ //返回的优惠券名称
|
|
|
|
|
+ couponName = fsCourseCoupon.getTitle();
|
|
|
|
|
+ if (i > 0) {
|
|
|
|
|
+ FsCourseCoupon coupon = new FsCourseCoupon();
|
|
|
|
|
+ coupon.setId(courseVideo.getCourseCouponId());
|
|
|
|
|
+ coupon.setRemainNumber(fsCourseCoupon.getRemainNumber() - 1);
|
|
|
|
|
+ baseMapper.updateFsCourseCoupon(coupon);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 获取配置信息
|
|
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
|
|
+ CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
|
|
+ Integer rewardType = config.getRewardType();
|
|
|
|
|
+
|
|
|
|
|
+ if (rewardType == 1) {
|
|
|
|
|
+ FsUserCourseVideoRedPackage redPackage = fsUserCourseVideoRedPackageMapper.selectRedPacketByCompanyId(videoId,companyId,periodId);
|
|
|
|
|
+ if (redPackage != null && redPackage.getRedPacketMoney() != null) {
|
|
|
|
|
+ amount = redPackage.getRedPacketMoney();
|
|
|
|
|
+ } else if (courseVideo.getRedPacketMoney() != null) {
|
|
|
|
|
+ amount = courseVideo.getRedPacketMoney();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (rewardType == 2) {
|
|
|
|
|
+ integral = config.getAnswerIntegral();
|
|
|
|
|
+ }
|
|
|
|
|
+ rewardVO.setCouponName(couponName);
|
|
|
|
|
+ rewardVO.setIntegral(integral);
|
|
|
|
|
+ rewardVO.setRedPacketMoney(amount);
|
|
|
|
|
+ return R.ok().put("data",rewardVO);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|