|
|
@@ -0,0 +1,383 @@
|
|
|
+package com.fs.his.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.course.domain.FsCourseWatchLog;
|
|
|
+import com.fs.course.domain.FsUserCourseVideo;
|
|
|
+import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
|
+import com.fs.course.mapper.FsUserCourseVideoMapper;
|
|
|
+import com.fs.course.mapper.FsUserCourseVideoRedPackageMapper;
|
|
|
+import com.fs.his.domain.FsCourseCoupon;
|
|
|
+import com.fs.his.domain.FsCourseCouponUser;
|
|
|
+import com.fs.his.mapper.FsCourseCouponMapper;
|
|
|
+import com.fs.his.mapper.FsCourseCouponUserMapper;
|
|
|
+import com.fs.his.param.CourseFinishRewardParam;
|
|
|
+import com.fs.his.service.IFsCourseCouponService;
|
|
|
+import com.fs.his.vo.CourseFinishRewardVO;
|
|
|
+import com.fs.system.service.ISysConfigService;
|
|
|
+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.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 课程优惠券Service业务层处理
|
|
|
+ *
|
|
|
+ * @author fs
|
|
|
+ * @date 2026-05-13
|
|
|
+ */
|
|
|
+@Service
|
|
|
+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;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsCourseWatchLogMapper courseWatchLogMapper;
|
|
|
+ /**
|
|
|
+ * 查询课程优惠券
|
|
|
+ *
|
|
|
+ * @param id 课程优惠券主键
|
|
|
+ * @return 课程优惠券
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public FsCourseCoupon selectFsCourseCouponById(Long id)
|
|
|
+ {
|
|
|
+ return baseMapper.selectFsCourseCouponById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询课程优惠券列表
|
|
|
+ *
|
|
|
+ * @param fsCourseCoupon 课程优惠券
|
|
|
+ * @return 课程优惠券
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<FsCourseCoupon> selectFsCourseCouponList(FsCourseCoupon fsCourseCoupon)
|
|
|
+ {
|
|
|
+ return baseMapper.selectFsCourseCouponList(fsCourseCoupon);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增课程优惠券
|
|
|
+ *
|
|
|
+ * @param fsCourseCoupon 课程优惠券
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int insertFsCourseCoupon(FsCourseCoupon fsCourseCoupon)
|
|
|
+ {
|
|
|
+ fsCourseCoupon.setCreateTime(DateUtils.getNowDate());
|
|
|
+ fsCourseCoupon.setRemainNumber(fsCourseCoupon.getNumber());
|
|
|
+ return baseMapper.insertFsCourseCoupon(fsCourseCoupon);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改课程优惠券
|
|
|
+ *
|
|
|
+ * @param fsCourseCoupon 课程优惠券
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int updateFsCourseCoupon(FsCourseCoupon fsCourseCoupon)
|
|
|
+ {
|
|
|
+ fsCourseCoupon.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ return baseMapper.updateFsCourseCoupon(fsCourseCoupon);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除课程优惠券
|
|
|
+ *
|
|
|
+ * @param ids 需要删除的课程优惠券主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteFsCourseCouponByIds(Long[] ids)
|
|
|
+ {
|
|
|
+ return baseMapper.deleteFsCourseCouponByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除课程优惠券信息
|
|
|
+ *
|
|
|
+ * @param id 课程优惠券主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteFsCourseCouponById(Long id)
|
|
|
+ {
|
|
|
+ return baseMapper.deleteFsCourseCouponById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<FsCourseCoupon> selectFsCourseCouponOptions() {
|
|
|
+ return baseMapper.selectFsCourseCouponOptions();
|
|
|
+ }
|
|
|
+
|
|
|
+ //自动
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R sendAutoCourseCoupon(Long videoId, Long userId,Long companyId,Long qwUserId,Long qwExternalId) {
|
|
|
+ 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);
|
|
|
+ //默认发送优惠券
|
|
|
+ boolean isSend = true;
|
|
|
+ //课程小节信息
|
|
|
+ FsUserCourseVideo courseVideo = userCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
|
+ if (courseVideo == null) {
|
|
|
+ return R.error("课程小节不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ //优惠券
|
|
|
+ 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(param.getUserId(), courseVideo.getCourseCouponId());
|
|
|
+ if (count >= fsCourseCoupon.getLimitCount()) {
|
|
|
+ isSend = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isSend = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isSend) {
|
|
|
+ //发放优惠券
|
|
|
+ FsCourseCouponUser couponUser = new FsCourseCouponUser();
|
|
|
+ couponUser.setCouponId(courseVideo.getCourseCouponId());
|
|
|
+ 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);
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ return R.ok().put("data",rewardVO);
|
|
|
+ }
|
|
|
+}
|