|
|
@@ -1,27 +1,35 @@
|
|
|
package org.dromara.backstage.cardCenter.controller;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
-import jakarta.servlet.http.HttpServletResponse;
|
|
|
-import jakarta.validation.constraints.*;
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
+import jakarta.validation.constraints.NotEmpty;
|
|
|
+import jakarta.validation.constraints.NotNull;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.dromara.backstage.business.payments.strategy.impl.PaymentsStrategyContent;
|
|
|
+import org.dromara.backstage.cardCenter.domain.bo.PtCardBo;
|
|
|
+import org.dromara.backstage.cardCenter.domain.vo.PtCardVo;
|
|
|
+import org.dromara.backstage.cardCenter.service.IPtCardService;
|
|
|
import org.dromara.backstage.payment.domain.bo.PtBagBo;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
-import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
|
|
-import org.dromara.common.log.annotation.Log;
|
|
|
-import org.dromara.common.web.core.BaseController;
|
|
|
-import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import org.dromara.backstage.payment.domain.vo.PtBagVo;
|
|
|
+import org.dromara.backstage.payment.domain.vo.PtBagVoToPtBagMapperImpl;
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
+import org.dromara.common.core.enums.CreditTypeEnum;
|
|
|
+import org.dromara.common.core.enums.SystemUseTypeEnum;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.validate.AddGroup;
|
|
|
import org.dromara.common.core.validate.EditGroup;
|
|
|
-import org.dromara.common.log.enums.BusinessType;
|
|
|
import org.dromara.common.excel.utils.ExcelUtil;
|
|
|
-import org.dromara.backstage.cardCenter.domain.vo.PtCardVo;
|
|
|
-import org.dromara.backstage.cardCenter.domain.bo.PtCardBo;
|
|
|
-import org.dromara.backstage.cardCenter.service.IPtCardService;
|
|
|
+import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
|
|
+import org.dromara.common.log.annotation.Log;
|
|
|
+import org.dromara.common.log.enums.BusinessType;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.web.core.BaseController;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 账户卡片
|
|
|
@@ -37,6 +45,8 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
public class PtCardController extends BaseController {
|
|
|
|
|
|
private final IPtCardService ptCardService;
|
|
|
+ private final PaymentsStrategyContent paymentsStrategyContent;
|
|
|
+ private final PtBagVoToPtBagMapperImpl ptBagVoToPtBagMapperImpl;
|
|
|
|
|
|
/**
|
|
|
* 查询账户卡片列表
|
|
|
@@ -66,7 +76,7 @@ public class PtCardController extends BaseController {
|
|
|
@SaCheckPermission("cardOperation:ptCard:query")
|
|
|
@GetMapping("/{cardId}")
|
|
|
public R<PtCardVo> getInfo(@NotNull(message = "主键不能为空")
|
|
|
- @PathVariable Long cardId) {
|
|
|
+ @PathVariable Long cardId) {
|
|
|
return R.ok(ptCardService.queryById(cardId));
|
|
|
}
|
|
|
|
|
|
@@ -112,7 +122,7 @@ public class PtCardController extends BaseController {
|
|
|
@Log(title = "账户卡片", businessType = BusinessType.UPDATE)
|
|
|
@RepeatSubmit()
|
|
|
@PutMapping("/lockCard/{cardId}")
|
|
|
- public R<Void> lockPtCard( @PathVariable Long cardId) {
|
|
|
+ public R<Void> lockPtCard(@PathVariable Long cardId) {
|
|
|
return toAjax(ptCardService.lockCard(cardId));
|
|
|
}
|
|
|
|
|
|
@@ -123,18 +133,46 @@ public class PtCardController extends BaseController {
|
|
|
@Log(title = "账户卡片", businessType = BusinessType.UPDATE)
|
|
|
@RepeatSubmit()
|
|
|
@PutMapping("/unlockCard/{cardId}")
|
|
|
- public R<Void> unlockPtCard( @PathVariable Long cardId) {
|
|
|
+ public R<Void> unlockPtCard(@PathVariable Long cardId) {
|
|
|
return toAjax(ptCardService.unlockCard(cardId));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 修改账户卡片
|
|
|
+ * 充值
|
|
|
*/
|
|
|
@SaCheckPermission("cardOperation:ptCard:edit")
|
|
|
- @Log(title = "账户卡片", businessType = BusinessType.UPDATE)
|
|
|
+ @Log(title = "账户充值", businessType = BusinessType.UPDATE)
|
|
|
@RepeatSubmit()
|
|
|
@PostMapping("/recharge")
|
|
|
- public R<Void> recharge(@Validated(EditGroup.class) @RequestBody PtBagBo bo) {
|
|
|
- return toAjax(ptCardService.rechargeByBo(bo));
|
|
|
+ public R<PtBagVo> recharge(@Validated(EditGroup.class) @RequestBody PtBagBo bo) {
|
|
|
+ PtBagVo vo;
|
|
|
+ bo.setUseType(SystemUseTypeEnum.CONSUME);
|
|
|
+ BigDecimal commission = ptCardService.computeCommission(bo);
|
|
|
+ if (commission.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ PtBagBo commissionBo = MapstructUtils.convert(bo, PtBagBo.class);
|
|
|
+ if (commissionBo != null) {
|
|
|
+ commissionBo.setReceiptMoney(commission);
|
|
|
+ commissionBo.setCreditType(CreditTypeEnum.COMMISSION_CHARGE);
|
|
|
+ paymentsStrategyContent.createOrder(commissionBo);
|
|
|
+ }
|
|
|
+ bo.setReceiptMoney(bo.getReceiptMoney().subtract(commission));
|
|
|
+ }
|
|
|
+ vo = paymentsStrategyContent.createOrder(bo);
|
|
|
+ return R.ok(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 充值
|
|
|
+ */
|
|
|
+ @SaCheckPermission("cardOperation:ptCard:edit")
|
|
|
+ @Log(title = "账户退款", businessType = BusinessType.UPDATE)
|
|
|
+ @RepeatSubmit()
|
|
|
+ @PostMapping("/refund")
|
|
|
+ public R<PtBagVo> refund(@Validated(EditGroup.class) @RequestBody PtBagBo bo) {
|
|
|
+ //退款是记支出,所以金额设置为负数
|
|
|
+ bo.setUseType(SystemUseTypeEnum.CONSUME);
|
|
|
+ bo.setReceiptMoney(bo.getReceiptMoney().negate());
|
|
|
+ PtBagVo vo = paymentsStrategyContent.createOrder(bo);
|
|
|
+ return R.ok(vo);
|
|
|
}
|
|
|
}
|