| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.system.domain.Agreement; |
| | | import com.ruoyi.system.domain.User; |
| | | import com.ruoyi.system.mapper.AgreementMapper; |
| | | import com.ruoyi.system.mapper.AppUserMapper; |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.system.domain.*; |
| | | import com.ruoyi.system.mapper.*; |
| | | import com.ruoyi.system.pojo.dto.AddAgreementDTO; |
| | | import com.ruoyi.system.pojo.dto.AppUserPageDTO; |
| | | import com.ruoyi.system.pojo.dto.UpdateBalanceDTO; |
| | | import com.ruoyi.system.pojo.model.BuyerInfoAndOrder; |
| | | import com.ruoyi.system.pojo.vo.AppUserPageVO; |
| | | import com.ruoyi.system.pojo.vo.AppUserVO; |
| | | import com.ruoyi.system.pojo.vo.InviteUser; |
| | | import com.ruoyi.system.pojo.vo.SysDeptPageVO; |
| | | import com.ruoyi.system.service.AgreementService; |
| | | import com.ruoyi.system.service.AppUserService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.ruoyi.common.utils.SecurityUtils.getLoginUser; |
| | | |
| | | @Service |
| | | public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, User> implements AppUserService { |
| | | |
| | | @Resource |
| | | private OrderMapper orderMapper; |
| | | |
| | | @Resource |
| | | private CompanyMapper companyMapper; |
| | | |
| | | @Resource |
| | | private AccountDetailMapper accountDetailMapper; |
| | | |
| | | @Override |
| | | public IPage<AppUserPageVO> getAppUserPage(AppUserPageDTO dto) { |
| | | IPage<SysDeptPageVO> iPage = new Page<>(dto.getPageNum(), dto.getPageSize()); |
| | | return this.baseMapper.getAppUserPage(iPage,dto); |
| | | } |
| | | |
| | | @Override |
| | | public AppUserVO detail(String id) { |
| | | //1.基础信息 |
| | | AppUserVO vo=this.baseMapper.getDetailInfoById(id); |
| | | //2.计算待入账金额 |
| | | BigDecimal recorded=new BigDecimal("0.00"); |
| | | //2.1查询待处理中的订单 |
| | | List<BuyerInfoAndOrder> orders=companyMapper.getProcessingOrdersByUserId(id); |
| | | |
| | | //2.2计算订单金额 扣减超时订单金额 |
| | | for(BuyerInfoAndOrder order :orders) { |
| | | BigDecimal total = new BigDecimal("0.00"); |
| | | total = total.add(order.getPrice()).subtract(order.getCommissionPrice()).subtract(order.getCommissionPlatform()); |
| | | System.out.println(total); |
| | | //扣减超时订单 |
| | | //到期时间 支付时间 + 预计时间 + 新增时间 |
| | | LocalDateTime end = order.getPayTime().plusDays(order.getEstimatedDays()).plusDays(order.getAddDay()); |
| | | LocalDateTime now = LocalDateTime.now();//计算扣费时间 |
| | | if (!now.isAfter(end)) { |
| | | recorded = recorded.add(total); |
| | | break; |
| | | } |
| | | // 计算两个时间点的差值(精确到秒) |
| | | long seconds = ChronoUnit.SECONDS.between(end, now); |
| | | // 向上取整:超过时间不满24小时按一天计算 |
| | | long days= (seconds + 86399) / 86400;//24小时 |
| | | //计算天数差 |
| | | BigDecimal dailyAmount = new BigDecimal("100.00"); |
| | | total = total.subtract((dailyAmount.multiply(BigDecimal.valueOf(days)))); |
| | | recorded = recorded.add(total); |
| | | } |
| | | |
| | | //2.3查询待处理中的分佣订单 |
| | | BigDecimal commissionPrice = orderMapper.getProcessingCommissionPriceByShareUserId(id); |
| | | //2.4累计 |
| | | recorded = recorded.add(commissionPrice); |
| | | vo.setRecorded(recorded); |
| | | //3.下级用户 |
| | | List<InviteUser> list = this.baseMapper.getInviteUserListByInviteId(id); |
| | | vo.setInviteUserList(list); |
| | | return vo; |
| | | } |
| | | |
| | | @Override |
| | | public void frozen(String id) { |
| | | //查看用户是否存在 |
| | | User user = this.baseMapper.selectById(id); |
| | | if (null == user|| user.getIsDelete() != 0|| user.getStatus() == 3) { |
| | | throw new ServiceException("用户不存在"); |
| | | } |
| | | user.setStatus(user.getStatus()==1?2:1); |
| | | user.setUpdateTime(LocalDateTime.now()); |
| | | LoginUser loginUser = getLoginUser(); |
| | | user.setUpdateBy(loginUser.getUserId()); |
| | | this.baseMapper.updateById(user); |
| | | |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void balance(UpdateBalanceDTO dto) { |
| | | User user = this.baseMapper.selectById(dto.getId()); |
| | | if (null == user|| user.getIsDelete() != 0|| user.getStatus() == 3) { |
| | | throw new ServiceException("用户不存在"); |
| | | } |
| | | //添加明细表 |
| | | AccountDetail accountDetail = new AccountDetail(); |
| | | accountDetail.setUserId(dto.getId()); |
| | | accountDetail.setType(dto.getType()); |
| | | accountDetail.setMoney(dto.getMoney()); |
| | | accountDetail.setRemark(dto.getRemark()); |
| | | accountDetailMapper.insert(accountDetail); |
| | | //修改用户余额 |
| | | if (dto.getType()==1){ |
| | | //加余额 |
| | | user.setBalance(user.getBalance().add(accountDetail.getMoney())); |
| | | }else { |
| | | //减余额 |
| | | user.setBalance(user.getBalance().subtract(accountDetail.getMoney())); |
| | | } |
| | | user.setUpdateTime(LocalDateTime.now()); |
| | | user.setUpdateBy(getLoginUser().getUserId()); |
| | | this.baseMapper.updateById(user); |
| | | //todo 是否需要加消息 |
| | | |
| | | } |
| | | } |