|
@@ -0,0 +1,152 @@
|
|
|
+package com.txz.cif.web.mng;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.txz.cif.core.Result;
|
|
|
+import com.txz.cif.model.PaymentMethod;
|
|
|
+import com.txz.cif.model.PaymentPriceConfig;
|
|
|
+import com.txz.cif.service.PaymentMethodService;
|
|
|
+import com.txz.cif.service.PaymentPriceConfigService;
|
|
|
+import com.txz.cif.web.ro.PaymentPriceConfigRO;
|
|
|
+import com.txz.cif.web.vo.PaymentPriceVO;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * [后台]充值金额配置
|
|
|
+ *
|
|
|
+ * @author: MTD®️
|
|
|
+ * @date: 2025/8/28
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequiredArgsConstructor
|
|
|
+@RequestMapping("paymentPriceConfig")
|
|
|
+public class PaymentPriceConfigController {
|
|
|
+
|
|
|
+ private final PaymentPriceConfigService paymentPriceConfigService;
|
|
|
+
|
|
|
+ private final PaymentMethodService paymentMethodService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列表
|
|
|
+ */
|
|
|
+ @GetMapping("list/{paymentId:^\\d+$}")
|
|
|
+ public Result<PaymentPriceVO> list(@PathVariable("paymentId") Long paymentId) {
|
|
|
+ PaymentMethod paymentMethod = paymentMethodService.findById(paymentId);
|
|
|
+ return Result.success(PaymentPriceVO.builder()
|
|
|
+ .list(paymentPriceConfigService.list(
|
|
|
+ Wrappers.<PaymentPriceConfig>lambdaQuery()
|
|
|
+ .eq(PaymentPriceConfig::getPaymentId, paymentId)
|
|
|
+ .eq(PaymentPriceConfig::getIsValid, 1)
|
|
|
+ .orderByAsc(PaymentPriceConfig::getPriceVal)
|
|
|
+ ))
|
|
|
+ .miniPrice(paymentMethod.getMiniPrice())
|
|
|
+ .maxPrice(paymentMethod.getMaxPrice())
|
|
|
+ .build()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ */
|
|
|
+ @PostMapping("add/{paymentId:^\\d+$}")
|
|
|
+ public Result add(@PathVariable("paymentId") Long paymentId, @RequestBody @Validated({PaymentPriceConfigRO.Add.class}) PaymentPriceConfigRO ro) {
|
|
|
+ if (paymentPriceConfigService.count(
|
|
|
+ Wrappers.<PaymentPriceConfig>lambdaQuery()
|
|
|
+ .eq(PaymentPriceConfig::getPaymentId, paymentId)
|
|
|
+ .eq(PaymentPriceConfig::getIsValid, 1)) >= 9L
|
|
|
+ ) {
|
|
|
+ return Result.fail("最多添加9个");
|
|
|
+ }
|
|
|
+ PaymentPriceConfig exist = paymentPriceConfigService.getOne(Wrappers.<PaymentPriceConfig>lambdaQuery()
|
|
|
+ .eq(PaymentPriceConfig::getPriceVal, ro.getPriceVal())
|
|
|
+ .eq(PaymentPriceConfig::getPaymentId, paymentId)
|
|
|
+ .eq(PaymentPriceConfig::getIsValid, 1)
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isNotEmpty(exist)) {
|
|
|
+ return Result.fail("该金额已存在");
|
|
|
+ }
|
|
|
+ PaymentPriceConfig addInfo = new PaymentPriceConfig();
|
|
|
+ addInfo.setPaymentId(paymentId);
|
|
|
+ addInfo.setPriceVal(ro.getPriceVal());
|
|
|
+ addInfo.setIsValid(1);
|
|
|
+ paymentPriceConfigService.save(addInfo);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ */
|
|
|
+ @PatchMapping("edit/{id:^\\d+$}")
|
|
|
+ public Result edit(@PathVariable("id") Long id, @RequestBody @Validated({PaymentPriceConfigRO.Edit.class}) PaymentPriceConfigRO ro) {
|
|
|
+ PaymentPriceConfig exist = paymentPriceConfigService.getOne(Wrappers.<PaymentPriceConfig>lambdaQuery()
|
|
|
+ .eq(PaymentPriceConfig::getPriceVal, ro.getPriceVal())
|
|
|
+ .ne(PaymentPriceConfig::getId, id)
|
|
|
+ .eq(PaymentPriceConfig::getIsValid, 1)
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isNotEmpty(exist)) {
|
|
|
+ return Result.fail("该金额已存在");
|
|
|
+ }
|
|
|
+ paymentPriceConfigService.update(Wrappers.<PaymentPriceConfig>lambdaUpdate()
|
|
|
+ .eq(PaymentPriceConfig::getId, id)
|
|
|
+ .set(PaymentPriceConfig::getPriceVal, ro.getPriceVal())
|
|
|
+
|
|
|
+ );
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ */
|
|
|
+ @DeleteMapping("del/{id:^\\d+$}")
|
|
|
+ public Result del(@PathVariable("id") Long id) {
|
|
|
+ paymentPriceConfigService.update(Wrappers.<PaymentPriceConfig>lambdaUpdate()
|
|
|
+ .eq(PaymentPriceConfig::getId, id)
|
|
|
+ .set(PaymentPriceConfig::getIsValid, 0)
|
|
|
+
|
|
|
+ );
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改区间
|
|
|
+ */
|
|
|
+ @PatchMapping("editInterval/{paymentId:^\\d+$}")
|
|
|
+ public Result editInterval(@PathVariable("paymentId") Long paymentId, @RequestBody @Validated({PaymentPriceConfigRO.EditInterval.class}) PaymentPriceConfigRO ro) {
|
|
|
+ // PaymentPriceConfig mini = paymentPriceConfigService.getOne(Wrappers.<PaymentPriceConfig>lambdaQuery()
|
|
|
+ // .eq(PaymentPriceConfig::getPaymentId, paymentId)
|
|
|
+ // .lt(PaymentPriceConfig::getPriceVal, ro.getMiniPrice())
|
|
|
+ // .eq(PaymentPriceConfig::getIsValid, 1)
|
|
|
+ // .last("limit 1")
|
|
|
+ // );
|
|
|
+ // if (ObjectUtil.isNotEmpty(mini)) {
|
|
|
+ // return Result.fail("最小金额不能小于已配置金额");
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // PaymentPriceConfig max = paymentPriceConfigService.getOne(Wrappers.<PaymentPriceConfig>lambdaQuery()
|
|
|
+ // .eq(PaymentPriceConfig::getPaymentId, paymentId)
|
|
|
+ // .gt(PaymentPriceConfig::getPriceVal, ro.getMaxPrice())
|
|
|
+ // .eq(PaymentPriceConfig::getIsValid, 1)
|
|
|
+ // .last("limit 1")
|
|
|
+ // );
|
|
|
+ // if (ObjectUtil.isNotEmpty(max)) {
|
|
|
+ // return Result.fail("最大金额不能大于已配置金额");
|
|
|
+ // }
|
|
|
+
|
|
|
+ if (ro.getMiniPrice() > ro.getMaxPrice()) {
|
|
|
+ return Result.fail("最小金额不能大于最大金额");
|
|
|
+ }
|
|
|
+
|
|
|
+ PaymentMethod updateMethod = new PaymentMethod();
|
|
|
+ updateMethod.setId(paymentId);
|
|
|
+ updateMethod.setMiniPrice(ro.getMiniPrice());
|
|
|
+ updateMethod.setMaxPrice(ro.getMaxPrice());
|
|
|
+
|
|
|
+ paymentMethodService.update(updateMethod);
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|