|
|
@@ -2,10 +2,13 @@ package com.cyksj.web.controller.manage;
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Assert;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.annotation.Log;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.dto.Result;
|
|
|
+import com.cyksj.enums.BusinessType;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
|
@@ -14,9 +17,11 @@ import com.cyksj.mapper.UserMapper;
|
|
|
import com.cyksj.mapper.corp.CorpUserFollowRelationMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.manage.views.UserView;
|
|
|
+import com.cyksj.model.request.UserBalanceReq;
|
|
|
import com.cyksj.model.request.UserFuncPropertyReq;
|
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.service.relation.GroupRelationClearService;
|
|
|
+import com.cyksj.service.user.UserBenefitsService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
@@ -26,6 +31,8 @@ import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@@ -62,6 +69,8 @@ public class CmsUserController{
|
|
|
|
|
|
private final OrderDonMapper orderDonMapper;
|
|
|
|
|
|
+ private final UserBenefitsService UserBenefitsService;
|
|
|
+
|
|
|
@GetMapping("/get")
|
|
|
public Result<SearchResult<UserView>> get(String otherPhone, Long sharedId, String userid, Long businessId, String sort, String order) {
|
|
|
MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
@@ -276,4 +285,32 @@ public class CmsUserController{
|
|
|
List<QuestionResponseRecordView> views = beanSearcher.searchAll(QuestionResponseRecordView.class, builder.build());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(views);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 余额扣除
|
|
|
+ */
|
|
|
+ @PutMapping("/sub/balance")
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
+ @Log(module = "用户管理/扣除用户余额", businessType = BusinessType.PUT, isSaveRequestData = true)
|
|
|
+ public Result<String> subBalance(@RequestBody @Validated UserBalanceReq balanceReq) {
|
|
|
+ BigDecimal deductBalance = balanceReq.getDeductBalance();
|
|
|
+ if (deductBalance.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("请扣除正确的余额数值");
|
|
|
+ }
|
|
|
+ Long userId = balanceReq.getUserId();
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ Assert.notNull(user, "用户不存在");
|
|
|
+ if (user.getBalance().compareTo(deductBalance) < 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("用户余额不足");
|
|
|
+ }
|
|
|
+ int update = userMapper.update(null, Wrappers.lambdaUpdate(User.class)
|
|
|
+ .set(User::getBalance, user.getBalance().subtract(deductBalance))
|
|
|
+ .eq(User::getId, userId)
|
|
|
+ .eq(User::getBalance, user.getBalance()));
|
|
|
+ if (update == 0) {
|
|
|
+ throw BusinessRuntimeException.getInstance("扣除用户余额失败,请重试...");
|
|
|
+ }
|
|
|
+ UserBenefitsService.recordBalanceBySource(userId, deductBalance.negate(), UserBalanceSourceRecord.Source.manual);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
}
|