package com.joker.web.controller.orange;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.joker.common.constant.CacheConstants;
import com.joker.common.core.domain.entity.SysUser;
import com.joker.common.utils.redis.RedisUtils;
import com.joker.orange.domain.*;
import com.joker.orange.mapper.*;
import com.joker.system.mapper.SysUserMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
/**
* 扣单逻辑
*/
@RequiredArgsConstructor
@Service
@Transactional
public class AppDeductionOrderService {
private final UserInfoMapper userInfoMapper;
private final SysUserMapper sysUserMapper;
private final UserOrderRecordMapper userOrderRecordMapper;
private final MemberOrderMapper orderMapper;
private final UserDeductionMapper deductionMapper;
private final AgentUserStatisticsMapper agentUserStatisticsMapper;
/**
* 扣单逻辑
*
* @param userId 用户ID
* @param orderNo 订单编号
*/
public void DeductionRegister(String userId, String orderNo) {
MemberOrder order = orderMapper.selectOne(
new LambdaUpdateWrapper<MemberOrder>().eq(
MemberOrder::getOrderNo, orderNo
));
UserInfo userInfo = userInfoMapper.selectById(userId);
// 上级类型(0-用户、1-平台、2-代理)
if ("2".equals(userInfo.getSuperiorType())) {
// 查询出上级
SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(userInfo.getSpreadId()));
if (ObjectUtil.isNotNull(sysUser)) {
// 查询代理的订单数量
Integer orderCount = getOrderCount(sysUser.getUserId()) + 1;
// 判断上级的代理等级 代理等级==1、2、3
if ("1".equals(sysUser.getAgentLevel())) {
// 查询平台的扣单比例,判断平台是否扣单
UserDeduction deduction = deductionMapper.selectOne(new LambdaUpdateWrapper<UserDeduction>()
.eq(UserDeduction::getDeductionType, "0"));
// 订单数量满足平台扣单,此单扣除,更新代理订单数量表为空
if (ObjectUtil.equals(orderCount, deduction.getOrderCount())) {
RedisUtils.setCacheObject(CacheConstants.USER_ORDER_KEY + sysUser.getUserId(), "0");
userOrderRecordMapper.update(null, new LambdaUpdateWrapper<UserOrderRecord>()
.set(UserOrderRecord::getOrderCount, "0")
.eq(UserOrderRecord::getUserId, sysUser.getUserId()));
// todo 记录扣单
} else {
// 不满足扣单,按照分成比例进行分配
BigDecimal commissionRatio = sysUser.getCommissionRatio();
BigDecimal divideMoney = commissionRatio.multiply(order.getOrderAmount()).setScale(2, RoundingMode.HALF_UP);
sysUser.setBalance(sysUser.getBalance().add(divideMoney));
sysUserMapper.updateById(sysUser);
// 更新订单数量
RedisUtils.setCacheObject(CacheConstants.USER_ORDER_KEY + sysUser.getUserId(), orderCount);
userOrderRecordMapper.update(null, new LambdaUpdateWrapper<UserOrderRecord>()
.set(UserOrderRecord::getOrderCount, orderCount)
.eq(UserOrderRecord::getUserId, sysUser.getUserId()));
// 记录代理统计
AgentUserStatistics(divideMoney, sysUser, userInfo.getAppType(), order.getOrderType());
}
} else if ("2".equals(sysUser.getAgentLevel())) {
// 代理等级是2级,查询2级代理的上级
SysUser firstUser = sysUserMapper.selectVoOne(new LambdaUpdateWrapper<SysUser>()
.eq(SysUser::getSuperiorAgent, sysUser.getUserId()));
// 2级代理的上级是平台
if ("0".equals(firstUser.getAgentLevel())) {
// 查询平台的扣单比例,判断平台是否扣单
UserDeduction deduction = deductionMapper.selectOne(new LambdaUpdateWrapper<UserDeduction>()
.eq(UserDeduction::getDeductionType, "0"));
// 订单数量满足平台扣单,此单扣除,更新代理订单数量表为空
if (ObjectUtil.equals(orderCount, deduction.getOrderCount())) {
RedisUtils.setCacheObject(CacheConstants.USER_ORDER_KEY + sysUser.getUserId(), "0");
userOrderRecordMapper.update(null, new LambdaUpdateWrapper<UserOrderRecord>()
.set(UserOrderRecord::getOrderCount, "0")
.eq(UserOrderRecord::getUserId, sysUser.getUserId()));
// todo 记录扣单
} else {
// 不满足扣单,按照分成比例进行分配
BigDecimal commissionRatio = sysUser.getCommissionRatio();
BigDecimal divideMoney = commissionRatio.multiply(order.getOrderAmount()).setScale(2, RoundingMode.HALF_UP);
sysUser.setBalance(sysUser.getBalance().add(divideMoney));
sysUserMapper.updateById(sysUser);
// 更新订单数量
RedisUtils.setCacheObject(CacheConstants.USER_ORDER_KEY + sysUser.getUserId(), orderCount);
userOrderRecordMapper.update(null, new LambdaUpdateWrapper<UserOrderRecord>()
.set(UserOrderRecord::getOrderCount, orderCount)
.eq(UserOrderRecord::getUserId, sysUser.getUserId()));
// 记录代理统计
AgentUserStatistics(divideMoney, sysUser, userInfo.getAppType(), order.getOrderType());
}
// 2级代理的上级是1级代理
} else if ("1".equals(firstUser.getAgentLevel())) {
// 查询平台的扣单比例,判断平台是否扣单
UserDeduction deduction = deductionMapper.selectOne(new LambdaUpdateWrapper<UserDeduction>()
.eq(UserDeduction::getDeductionType, "0"));
// 订单数量满足平台扣单,此单扣除,更新代理订单数量表为空
if (ObjectUtil.equals(orderCount, deduction.getOrderCount())) {
RedisUtils.setCacheObject(CacheConstants.USER_ORDER_KEY + sysUser.getUserId(), orderCount);
userOrderRecordMapper.update(null, new LambdaUpdateWrapper<UserOrderRecord>()
.set(UserOrderRecord::getOrderCount, "0")
.eq(UserOrderRecord::getUserId, sysUser.getUserId()));
// todo 记录扣单
} else {
// 平台不扣单,查询一级代理是否扣单
UserDeduction firstDeduction = deductionMapper.selectOne(new LambdaUpdateWrapper<UserDeduction>()
.eq(UserDeduction::getDeductionType, "1")
.eq(UserDeduction::getUserId, firstUser.getUserId()));
// 一级代理
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
该项目是一款名为橘子影视的平台,采用Java语言进行核心开发,并融入Shell脚本技术,整体源码包含701个文件。其中,Java源文件593个,XML配置文件67个,VM文件18个,Markdown文件6个,YAML文件4个,属性文件4个,文本文件2个,EditorConfig文件1个,Git忽略文件1个,以及LICENSE文件1个。该平台旨在提供便捷的影视观看体验。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java及Shell脚本技术的橘子影视平台设计源码 (701个子文件)
ry.bat 2KB
.editorconfig 340B
.gitignore 649B
AppDeductionOrderService.java 31KB
AppPixivController.java 23KB
OrderInfoServiceImpl.java 18KB
GenTableServiceImpl.java 18KB
AppPersonalCenterController.java 18KB
SysUserServiceImpl.java 16KB
VelocityUtils.java 15KB
SysMenuServiceImpl.java 14KB
SysRoleServiceImpl.java 14KB
RedisUtils.java 12KB
ExcelUtil.java 12KB
OpenApiHandler.java 10KB
SysDictTypeServiceImpl.java 10KB
SysDeptServiceImpl.java 10KB
OssClient.java 10KB
VideoInfoServiceImpl.java 10KB
SysUserController.java 10KB
StringUtils.java 9KB
SysLoginService.java 9KB
StreamUtils.java 9KB
GenUtils.java 8KB
PlusDataPermissionHandler.java 8KB
AppGridVideoController.java 8KB
AppIndexController.java 8KB
SysConfigServiceImpl.java 8KB
LogAspect.java 8KB
SysRoleController.java 8KB
EncryptUtils.java 7KB
SysOssServiceImpl.java 7KB
AppLoginController.java 7KB
CaricatureInfoServiceImpl.java 7KB
GenController.java 7KB
AcceptPushedDataService.java 7KB
UserInfoServiceImpl.java 7KB
SysOssConfigServiceImpl.java 7KB
NovelInfoServiceImpl.java 7KB
GlobalExceptionHandler.java 6KB
LoginService.java 6KB
AgentUserServiceImpl.java 6KB
AgentUserStatisticsServiceImpl.java 6KB
CaricatureChapterServiceImpl.java 6KB
SysLogininforServiceImpl.java 6KB
GenTableColumn.java 6KB
BeanCopyUtils.java 6KB
RepeatSubmitAspect.java 6KB
PlusSpringCacheManager.java 6KB
BaseMapperPlus.java 6KB
ServletUtils.java 6KB
QueueUtils.java 6KB
AppPersonalCenterService.java 6KB
NovelChapterServiceImpl.java 6KB
CacheController.java 6KB
RateLimiterAspect.java 5KB
RedisConfig.java 5KB
CaricatureChapterController.java 5KB
SysPostServiceImpl.java 5KB
SysOperLogServiceImpl.java 5KB
NovelChapterController.java 5KB
WithdrawRecordServiceImpl.java 5KB
SysLoginController.java 5KB
PlusSaTokenDao.java 5KB
SwaggerConfig.java 5KB
DateUtils.java 5KB
AgentUserStatisticsBo.java 5KB
SysUser.java 5KB
AppShortVideoController.java 5KB
BuyOrderServiceImpl.java 5KB
SysDictDataServiceImpl.java 5KB
SysProfileController.java 5KB
AgentUserController.java 5KB
MybatisEncryptInterceptor.java 4KB
ISysUserService.java 4KB
SysUserImportListener.java 4KB
VideoInfoController.java 4KB
GenTable.java 4KB
SysMenuController.java 4KB
UserActionListener.java 4KB
UserInfoVo.java 4KB
AgentUserVo.java 4KB
UserDeductionController.java 4KB
PlusDataPermissionInterceptor.java 4KB
SysConfigController.java 4KB
AppOrderController.java 4KB
UserInfoBo.java 4KB
UserInfoController.java 4KB
MybatisDecryptInterceptor.java 4KB
SysDeptController.java 4KB
CaricatureInfoController.java 4KB
CaricatureCategoryServiceImpl.java 4KB
LongVideoCategoryServiceImpl.java 4KB
NovelInfoController.java 4KB
LongVideoCategoryController.java 4KB
ShortVideoAdvertisingServiceImpl.java 4KB
LoginHelper.java 4KB
OrderServiceImpl.java 4KB
CaricatureCategoryController.java 4KB
SysDictTypeController.java 4KB
共 701 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
lsx202406
- 粉丝: 2239
- 资源: 5546
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功