|
@@ -1,7 +1,9 @@
|
|
|
package com.ruoyi.web.work.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.common.constant.CacheConstants;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.core.redis.RedisCache;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.PageUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
@@ -19,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -45,6 +48,9 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> i
|
|
|
@Autowired
|
|
|
private IResumeDeliverService resumeDeliverService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
@Override
|
|
|
public List<Position> selectList(Position position) {
|
|
|
return positionMapper.selectList(position);
|
|
@@ -93,10 +99,13 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> i
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public AjaxResult manageAdd(PositionDto dto) {
|
|
|
+ Platform platform = redisCache.getCacheObject(CacheConstants.APP_PLATFORM);
|
|
|
if (AppUtil.getUser().getIsAuthentication() != 1) {
|
|
|
return AjaxResult.error(7878, "发布全职或兼职需要实名认证");
|
|
|
}
|
|
|
User user = userService.getById(AppUtil.getUser().getId());
|
|
|
+ Position position = new Position();
|
|
|
+ BeanUtils.copyProperties(dto, position);
|
|
|
//全职
|
|
|
if (dto.getType() == 0) {
|
|
|
if (user.getType() != 1) {
|
|
@@ -108,18 +117,36 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> i
|
|
|
}
|
|
|
//兼职
|
|
|
if (dto.getType() == 1) {
|
|
|
- if (new BigDecimal(dto.getSalary()).compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ Object salaryObj = new BigDecimal(dto.getSalary());
|
|
|
+ if (!(salaryObj instanceof BigDecimal)) {
|
|
|
+ return AjaxResult.error("兼职金额不是一个有效类型");
|
|
|
+ }
|
|
|
+ BigDecimal salary = (BigDecimal) salaryObj;
|
|
|
+ if (salary.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
return AjaxResult.error("兼职金额必须大于0");
|
|
|
}
|
|
|
- if (new BigDecimal(dto.getSalary()).compareTo(user.getMoney()) > 0) {
|
|
|
+ if (salary.stripTrailingZeros().scale() > 2) {
|
|
|
+ return AjaxResult.error("兼职金额最多只能有两位小数");
|
|
|
+ }
|
|
|
+ //计算服务费
|
|
|
+ BigDecimal serviceMoney = platform.getPartTimeService().divide(new BigDecimal("100")).multiply(salary).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ //计算总费用
|
|
|
+ BigDecimal totalMoney = serviceMoney.add(salary).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ if (totalMoney.compareTo(user.getMoney()) > 0) {
|
|
|
return AjaxResult.error(8080, "余额不足请先充值");
|
|
|
}
|
|
|
+ if (!serviceMoney.equals(dto.getServiceMoney()) || !totalMoney.equals(dto.getRealMoney())) {
|
|
|
+ return AjaxResult.error("扣除金额异常");
|
|
|
+ }
|
|
|
+ position.setRate(platform.getPartTimeService());
|
|
|
+ position.setServiceMoney(serviceMoney);
|
|
|
}
|
|
|
- Position position = new Position();
|
|
|
- BeanUtils.copyProperties(dto, position);
|
|
|
- Column region = columnService.selectRegion(new Column().setTitle(position.getRegionName()).setLevel(3));
|
|
|
- if (region != null) {
|
|
|
- position.setAncestors(region.getAncestors() + "," + region.getId());
|
|
|
+ //根据地区名称找到对应的Ancestors
|
|
|
+ if (StringUtils.isNotEmpty(position.getRegionName())) {
|
|
|
+ Column region = columnService.selectRegion(new Column().setTitle(position.getRegionName()).setLevel(3));
|
|
|
+ if (region != null) {
|
|
|
+ position.setAncestors(region.getAncestors() + "," + region.getId());
|
|
|
+ }
|
|
|
}
|
|
|
//全职薪资
|
|
|
if (!position.getSalary().equals("面议") && position.getType() == 0) {
|
|
@@ -137,14 +164,16 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> i
|
|
|
//发布兼职更新账户和保存支出记录
|
|
|
if (dto.getType() == 1) {
|
|
|
//更新用户账户余额
|
|
|
- user.setMoney(user.getMoney().subtract(new BigDecimal(dto.getSalary())));
|
|
|
+ user.setMoney(user.getMoney().subtract(dto.getRealMoney()));
|
|
|
if (!userService.updateById(user)) {
|
|
|
throw new ServiceException("更新账户余额失败,请联系平台");
|
|
|
}
|
|
|
//添加支出记录
|
|
|
Pay pay = new Pay();
|
|
|
pay.setUserId(user.getId());
|
|
|
- pay.setMoney(new BigDecimal(dto.getSalary()));
|
|
|
+ pay.setMoney(dto.getRealMoney());
|
|
|
+ pay.setServiceMoney(dto.getServiceMoney());
|
|
|
+ pay.setRate(platform.getCashOutService());
|
|
|
pay.setState(1);
|
|
|
pay.setType(1);
|
|
|
pay.setTitle(position.getTitle());
|