|
|
@@ -18,6 +18,7 @@ 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.param.CourseFinishRewardParam;
|
|
|
import com.fs.his.vo.CourseFinishRewardVO;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -134,109 +135,210 @@ public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper,
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public R sendAutoCourseCoupon(Long videoId, Long userId,Long companyId,Long qwUserId,Long qwExternalId) {
|
|
|
- CourseFinishRewardVO rewardVO = new CourseFinishRewardVO();
|
|
|
- rewardVO.setTag(0);
|
|
|
- Integer integral = null;
|
|
|
- BigDecimal amount = null;
|
|
|
- String couponName = null;
|
|
|
-
|
|
|
- boolean isSend = true;
|
|
|
- //课程小节信息
|
|
|
- FsUserCourseVideo courseVideo = userCourseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
|
|
|
- if (courseVideo == null) {
|
|
|
- return R.error("课程小节不存在");
|
|
|
- }
|
|
|
-
|
|
|
- FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideo(userId, videoId, qwUserId.toString(), qwExternalId);
|
|
|
- if (log == null){
|
|
|
- return R.error("请先观看课程");
|
|
|
- }
|
|
|
- FsCourseCouponUser selectByLogId = courseCouponUserMapper.selectByLogId(log.getLogId());
|
|
|
- if (selectByLogId != null) {
|
|
|
- return R.ok().put("data", rewardVO);
|
|
|
- }
|
|
|
- //优惠券
|
|
|
- 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());
|
|
|
- couponUser.setLogId(log.getLogId());
|
|
|
- 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);
|
|
|
- rewardVO.setTag(1);
|
|
|
- return R.ok().put("data",rewardVO);
|
|
|
+ CourseFinishRewardParam param = new CourseFinishRewardParam();
|
|
|
+ param.setVideoId(videoId);
|
|
|
+ param.setUserId(userId);
|
|
|
+ param.setCompanyId(companyId);
|
|
|
+ param.setQwUsrId(qwUserId);
|
|
|
+ param.setQwExternalId(qwExternalId);
|
|
|
+ return sendCoupon(param,1);
|
|
|
+// CourseFinishRewardVO rewardVO = new CourseFinishRewardVO();
|
|
|
+// rewardVO.setTag(0);
|
|
|
+// String couponName = null;
|
|
|
+//
|
|
|
+// boolean isSend = true;
|
|
|
+// //课程小节信息
|
|
|
+// FsUserCourseVideo courseVideo = userCourseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
|
|
|
+// if (courseVideo == null) {
|
|
|
+// return R.error("课程小节不存在");
|
|
|
+// }
|
|
|
+// if (courseVideo.getCourseCouponId() == null){
|
|
|
+// //没用优惠券直接返回
|
|
|
+// return R.ok().put("data", rewardVO);
|
|
|
+// }
|
|
|
+//
|
|
|
+// FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideo(userId, videoId, qwUserId.toString(), qwExternalId);
|
|
|
+// if (log == null){
|
|
|
+// return R.error("请先观看课程");
|
|
|
+// }
|
|
|
+// FsCourseCouponUser selectByLogId = courseCouponUserMapper.selectByLogId(log.getLogId());
|
|
|
+// if (selectByLogId != null) {
|
|
|
+// return R.ok().put("data", rewardVO);
|
|
|
+// }
|
|
|
+// //优惠券
|
|
|
+// 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());
|
|
|
+// couponUser.setLogId(log.getLogId());
|
|
|
+// 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);
|
|
|
+// }
|
|
|
+// rewardVO.setCouponName(couponName);
|
|
|
+// rewardVO.setTag(1);
|
|
|
+// return R.ok().put("data",rewardVO);
|
|
|
+// } else {
|
|
|
+// return R.ok().put("data",rewardVO);
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
//手动
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public R sendCourseCoupon(Long videoId, Long userId,Long companyId,Long periodId,Long companyUserId) {
|
|
|
+ CourseFinishRewardParam param = new CourseFinishRewardParam();
|
|
|
+ param.setVideoId(videoId);
|
|
|
+ param.setUserId(userId);
|
|
|
+ param.setCompanyId(companyId);
|
|
|
+ param.setPeriodId(periodId);
|
|
|
+ param.setCompanyUserId(companyUserId);
|
|
|
+ return sendCoupon(param,2);
|
|
|
+// CourseFinishRewardVO rewardVO = new CourseFinishRewardVO();
|
|
|
+// rewardVO.setTag(0);
|
|
|
+// String couponName;
|
|
|
+//
|
|
|
+// boolean isSend = true;
|
|
|
+// //课程小节信息
|
|
|
+// FsUserCourseVideo courseVideo = userCourseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
|
|
|
+// if (courseVideo == null) {
|
|
|
+// return R.error("课程小节不存在");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (courseVideo.getCourseCouponId() == null){
|
|
|
+// //没用优惠券直接返回
|
|
|
+// return R.ok().put("data", rewardVO);
|
|
|
+// }
|
|
|
+//
|
|
|
+// FsCourseWatchLog log = courseWatchLogMapper.getWatchLogByFsUserAndPeriodId(videoId, userId, companyUserId, periodId);
|
|
|
+// if (log == null) {
|
|
|
+// return R.error("请先观看课程");
|
|
|
+// }
|
|
|
+// FsCourseCouponUser selectByLogId = courseCouponUserMapper.selectByLogId(log.getLogId());
|
|
|
+// if (selectByLogId != null) {
|
|
|
+// return R.ok().put("data", rewardVO);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //优惠券
|
|
|
+// 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());
|
|
|
+// couponUser.setLogId(log.getLogId());
|
|
|
+// 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);
|
|
|
+// }
|
|
|
+// rewardVO.setCouponName(couponName);
|
|
|
+// rewardVO.setTag(1);
|
|
|
+// return R.ok().put("data",rewardVO);
|
|
|
+// } else {
|
|
|
+// return R.ok().put("data", rewardVO);
|
|
|
+// }
|
|
|
+//// // 获取配置信息
|
|
|
+//// 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();
|
|
|
+//// }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送看课优惠券
|
|
|
+ * @param param 优惠券参数
|
|
|
+ * @param type 1 自动 2 手动
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ private R sendCoupon(CourseFinishRewardParam param,Integer type){
|
|
|
CourseFinishRewardVO rewardVO = new CourseFinishRewardVO();
|
|
|
+ //默认不弹窗
|
|
|
rewardVO.setTag(0);
|
|
|
- Integer integral = null;
|
|
|
- BigDecimal amount = null;
|
|
|
- String couponName = null;
|
|
|
-
|
|
|
+ //默认发送优惠券
|
|
|
boolean isSend = true;
|
|
|
//课程小节信息
|
|
|
- FsUserCourseVideo courseVideo = userCourseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
|
|
|
+ FsUserCourseVideo courseVideo = userCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
|
if (courseVideo == null) {
|
|
|
return R.error("课程小节不存在");
|
|
|
}
|
|
|
|
|
|
- FsCourseWatchLog log = courseWatchLogMapper.getWatchLogByFsUserAndPeriodId(videoId, userId, companyUserId, periodId);
|
|
|
+ if (courseVideo.getCourseCouponId() == null){
|
|
|
+ //没用优惠券直接返回
|
|
|
+ return R.ok().put("data", rewardVO);
|
|
|
+ }
|
|
|
+ FsCourseWatchLog log = null;
|
|
|
+ if (type == 1) {
|
|
|
+ log = courseWatchLogMapper.getWatchCourseVideo(param.getUserId(), param.getVideoId(), param.getQwUsrId().toString(), param.getQwExternalId());
|
|
|
+ } else {
|
|
|
+ log = courseWatchLogMapper.getWatchLogByFsUserAndPeriodId(param.getVideoId(), param.getUserId(), param.getCompanyUserId(), param.getPeriodId());
|
|
|
+ }
|
|
|
if (log == null) {
|
|
|
return R.error("请先观看课程");
|
|
|
}
|
|
|
+
|
|
|
FsCourseCouponUser selectByLogId = courseCouponUserMapper.selectByLogId(log.getLogId());
|
|
|
if (selectByLogId != null) {
|
|
|
return R.ok().put("data", rewardVO);
|
|
|
@@ -252,7 +354,7 @@ public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper,
|
|
|
isSend = false;
|
|
|
}
|
|
|
//用户领取优惠券总数
|
|
|
- Integer count = courseCouponUserMapper.selectCountByUserIdAndCouponId(userId, courseVideo.getCourseCouponId());
|
|
|
+ Integer count = courseCouponUserMapper.selectCountByUserIdAndCouponId(param.getUserId(), courseVideo.getCourseCouponId());
|
|
|
if (count >= fsCourseCoupon.getLimitCount()) {
|
|
|
isSend = false;
|
|
|
}
|
|
|
@@ -264,42 +366,23 @@ public class FsCourseCouponServiceImpl extends ServiceImpl<FsCourseCouponMapper,
|
|
|
//发放优惠券
|
|
|
FsCourseCouponUser couponUser = new FsCourseCouponUser();
|
|
|
couponUser.setCouponId(courseVideo.getCourseCouponId());
|
|
|
- couponUser.setUserId(userId);
|
|
|
+ couponUser.setUserId(param.getUserId());
|
|
|
couponUser.setStartTime(new Date());
|
|
|
couponUser.setLimitTime(fsCourseCoupon.getLimitTime());
|
|
|
couponUser.setCreateTime(new Date());
|
|
|
couponUser.setLogId(log.getLogId());
|
|
|
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);
|
|
|
}
|
|
|
+ //返回的优惠券名称
|
|
|
+ rewardVO.setCouponName(fsCourseCoupon.getTitle());
|
|
|
+ rewardVO.setTag(1);
|
|
|
}
|
|
|
- // 获取配置信息
|
|
|
- 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);
|
|
|
- rewardVO.setTag(1);
|
|
|
return R.ok().put("data",rewardVO);
|
|
|
}
|
|
|
}
|