src/main/java/com/xcong/excoin/modules/home/controller/MemberQuickBuySaleController.java
@@ -1,5 +1,7 @@ package com.xcong.excoin.modules.home.controller; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -32,7 +34,7 @@ @ApiOperation(value = "recharge", notes = "USDT快速充值") @RequestMapping(value = "/recharge", method = RequestMethod.POST) public Result recharge(@RequestBody MemberQuickBuySaleDto memberQuickBuySaleDto) { public Result recharge(@RequestBody @Valid MemberQuickBuySaleDto memberQuickBuySaleDto) { log.info("入参----->{}", memberQuickBuySaleDto); //获取用户ID MemberEntity member = LoginUserUtils.getAppLoginUser(); src/main/java/com/xcong/excoin/modules/home/dto/MemberQuickBuySaleDto.java
@@ -1,7 +1,6 @@ package com.xcong.excoin.modules.home.dto; import java.math.BigDecimal; import java.util.Date; import javax.validation.constraints.NotNull; @@ -28,14 +27,7 @@ @ApiModelProperty(value = "单价",example = "7") private BigDecimal unitPrice; @NotNull(message = "订单类型不能为空") @ApiModelProperty(value = "订单类型 B买入 S卖出",example = "B") private String orderType; @NotNull(message = "交易密码不能为空") @ApiModelProperty(value = "交易密码",example = "123456") private String tradePassword; @ApiModelProperty(value = "充值时间") private Date ChargeTime; } src/main/java/com/xcong/excoin/modules/home/service/impl/MemberQuickBuySaleServiceImpl.java
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.xcong.excoin.common.LoginUserUtils; @@ -26,6 +27,8 @@ import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao; import com.xcong.excoin.modules.member.entity.MemberEntity; import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; import com.xcong.excoin.modules.platform.dao.PlatformPaymentMethodDao; import com.xcong.excoin.modules.platform.entity.PlatformPaymentMethodEntity; @Service public class MemberQuickBuySaleServiceImpl extends ServiceImpl<MemberQuickBuySaleDao, MemberQuickBuySaleEntity> implements MemberQuickBuySaleService{ @@ -38,6 +41,8 @@ MemberWalletCoinDao memberWalletCoinDao; @Resource MemberPaymentMethodDao memberPaymentMethodDao; @Resource PlatformPaymentMethodDao platformPaymentMethodDao; @Override public Result recharge(MemberEntity member,MemberQuickBuySaleDto memberQuickBuySaleDto) { @@ -47,7 +52,7 @@ String chargeNo = String.valueOf(timestamp).substring(2) + random; // 插入订单表 MemberQuickBuySaleEntity memberQuickBuySaleEntity = new MemberQuickBuySaleEntity(); memberQuickBuySaleEntity.setOrderStatus(MemberQuickBuySaleEntity.CHARGE_STATUS_CREATE); memberQuickBuySaleEntity.setOrderStatus(1); memberQuickBuySaleEntity.setMemberId(member.getId()); memberQuickBuySaleEntity.setAmountUsdt(memberQuickBuySaleDto.getAmountUsdt()); memberQuickBuySaleEntity.setAmountCny(memberQuickBuySaleDto.getAmountCny()); @@ -58,10 +63,27 @@ int ran = (int) (Math.random() * 10000000); memberQuickBuySaleEntity.setPaymentCode(ran + ""); // 收款信息 QueryWrapper<PlatformPaymentMethodEntity> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("status", "1"); List<PlatformPaymentMethodEntity> paymentMethodList = platformPaymentMethodDao.selectList(queryWrapper); // 随机一个 if (CollectionUtils.isEmpty(paymentMethodList)) { return Result.fail("收款方式为空"); } // int total = paymentMethodList.size(); // int index = (int) (Math.random() * total); // PlatformPaymentMethodEntity paymemtMethod = paymentMethodList.get(index); // memberQuickBuySaleEntity.setPaymentName(paymemtMethod.getName()); // memberQuickBuySaleEntity.setPaymentAccount(paymemtMethod.getAccount()); memberQuickBuySaleDao.insert(memberQuickBuySaleEntity); MemberQuickBuySaleVo memberQuickBuySaleVo = MemberQuickBuySaleEntityMapper.INSTANCE.entityToVo(memberQuickBuySaleEntity); // 返回前台付款方式 // memberQuickBuySaleVo.setPlatforPaymentMethodList(paymentMethodList); // memberQuickBuySaleEntity.setReceiveMethod(payMethodList.get(index)); // 返回前台付款方式 // memberChargeUsdt.setReceiveMethod(payMethodList.get(index)); return Result.ok("购买成功,请及时付款"); return Result.ok(memberQuickBuySaleVo); } @Override @@ -69,7 +91,7 @@ // 用户提交支付确认 将状态改为付款中 MemberQuickBuySaleEntity memberQuickBuySaleEntity = new MemberQuickBuySaleEntity(); memberQuickBuySaleEntity.setId(memberQuickBuySaleCommitDto.getId()); memberQuickBuySaleEntity.setOrderStatus(MemberQuickBuySaleEntity.CHARGE_STATUS_PAID); memberQuickBuySaleEntity.setOrderStatus(2); memberQuickBuySaleEntity.setPaymentAccount(memberQuickBuySaleCommitDto.getPaymentAccount()); memberQuickBuySaleEntity.setPaymentName(memberQuickBuySaleCommitDto.getPaymentName()); @@ -128,7 +150,7 @@ String chargeNo = String.valueOf(timestamp).substring(2) + random; // 插入订单表 MemberQuickBuySaleEntity memberQuickBuySaleEntity = new MemberQuickBuySaleEntity(); memberQuickBuySaleEntity.setOrderStatus(MemberQuickBuySaleEntity.CHARGE_STATUS_CREATE); memberQuickBuySaleEntity.setOrderStatus(1); memberQuickBuySaleEntity.setMemberId(member.getId()); memberQuickBuySaleEntity.setAmountUsdt(memberQuickBuySaleDto.getAmountUsdt()); memberQuickBuySaleEntity.setAmountCny(memberQuickBuySaleDto.getAmountCny()); @@ -153,7 +175,7 @@ return Result.fail("登录用户已失效"); } MemberQuickBuySaleEntity memberQuickBuySaleEntity = memberQuickBuySaleDao.selectByIdAndMemberId(id,member.getId()); memberQuickBuySaleEntity.setOrderStatus(MemberQuickBuySaleEntity.CHARGE_STATUS_CANCEL_USER); memberQuickBuySaleEntity.setOrderStatus(1); memberQuickBuySaleDao.updateById(memberQuickBuySaleEntity); // 判断是否存在足够余额 src/main/java/com/xcong/excoin/modules/home/vo/MemberQuickBuySaleVo.java
@@ -1,6 +1,9 @@ package com.xcong.excoin.modules.home.vo; import java.math.BigDecimal; import java.util.List; import com.xcong.excoin.modules.platform.entity.PlatformPaymentMethodEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -33,4 +36,6 @@ private String orderType; @ApiModelProperty(value = "剩余时间") private Long timeLeft; @ApiModelProperty(value = "平台收款方式") private List<PlatformPaymentMethodEntity> platforPaymentMethodList; } src/main/java/com/xcong/excoin/modules/platform/controller/PlatformController.java
@@ -9,6 +9,7 @@ import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.platform.service.PlatformCnyUsdtExchangeService; import com.xcong.excoin.modules.platform.service.PlatformPaymentMethodService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -23,6 +24,8 @@ @Resource PlatformCnyUsdtExchangeService platformCnyUsdtExchangeService; @Resource PlatformPaymentMethodService platformPaymentMethodService; @ApiOperation(value = "findUsdtCnyExchange", notes = "Cny|Usdt兑换") @GetMapping(value = "/findUsdtCnyExchange") @@ -31,4 +34,10 @@ return platformCnyUsdtExchangeService.findUsdtCnyExchange(type); } @ApiOperation(value = "findAllPaymentMethod", notes = "查询平台收款方式") @GetMapping(value = "/findAllPaymentMethod") public Result findAllPaymentMethod() { return platformPaymentMethodService.findAll(); } } src/main/java/com/xcong/excoin/modules/platform/entity/PlatformCnyUsdtExchangeEntity.java
@@ -3,17 +3,13 @@ import java.math.BigDecimal; import com.baomidou.mybatisplus.annotation.TableName; import com.xcong.excoin.common.system.base.BaseEntity; import lombok.Data; @Data @TableName("platform_cny_usdt_exchange") public class PlatformCnyUsdtExchangeEntity extends BaseEntity{ public class PlatformCnyUsdtExchangeEntity{ /** * */ private static final long serialVersionUID = 1L; private Long id; /** * 兑换比例 src/main/java/com/xcong/excoin/modules/platform/entity/PlatformPaymentMethodEntity.java
@@ -1,26 +1,44 @@ package com.xcong.excoin.modules.platform.entity; import java.math.BigDecimal; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.xcong.excoin.common.system.base.BaseEntity; import lombok.Data; @Data @TableName("platform_cny_usdt_exchange") public class PlatformPaymentMethodEntity extends BaseEntity{ @TableName("platform_payment_method") public class PlatformPaymentMethodEntity{ @TableId(value = "id",type = IdType.AUTO) private Long id; /** * * 姓名 */ private static final long serialVersionUID = 1L; private String name; /** * 兑换比例 * 账号 */ private BigDecimal value; private String account; /** * 增减偏量 * 收款二维码 */ private BigDecimal diff; private String paymentQrcode; /** * 类型【1、支付宝2、微信3、银行卡】 */ private int type; /** * 银行名 */ private String bank; /** * 状态 */ private int status; /** * 联系方式 */ private String phone; } src/main/java/com/xcong/excoin/modules/platform/service/PlatformPaymentMethodService.java
@@ -1,13 +1,11 @@ package com.xcong.excoin.modules.platform.service; import org.springframework.web.bind.annotation.RequestParam; import com.baomidou.mybatisplus.extension.service.IService; import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.platform.entity.PlatformPaymentMethodEntity; public interface PlatformPaymentMethodService extends IService<PlatformPaymentMethodEntity> { public Result findUsdtCnyExchange(@RequestParam("type") String type); public Result findAll(); } src/main/java/com/xcong/excoin/modules/platform/service/impl/PlatformPaymentMethodServiceImpl.java
@@ -1,40 +1,28 @@ package com.xcong.excoin.modules.platform.service.impl; import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao; import com.xcong.excoin.modules.platform.dao.PlatformPaymentMethodDao; import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity; import com.xcong.excoin.modules.platform.entity.PlatformPaymentMethodEntity; import com.xcong.excoin.modules.platform.service.PlatformPaymentMethodService; @Service public class PlatformPaymentMethodServiceImpl extends ServiceImpl<PlatformPaymentMethodDao, PlatformPaymentMethodEntity> implements PlatformPaymentMethodService{ @Resource PlatformCnyUsdtExchangeDao platformCnyUsdtExchangeDao; PlatformPaymentMethodDao platformPaymentMethodDao; @Override public Result findUsdtCnyExchange(String type) { // 查询当前兑换价格 Map<String, Object> map = new HashMap<String, Object>(); PlatformCnyUsdtExchangeEntity platformCnyUsdtExchangeEntity = platformCnyUsdtExchangeDao.selectById(1); BigDecimal cnyUsdt = platformCnyUsdtExchangeEntity.getValue(); if ("B".equals(type)) { // 买的时候提高价格 map.put("exchange", cnyUsdt.add(platformCnyUsdtExchangeEntity.getDiff())); }else { // 卖的时候降低 map.put("exchange", cnyUsdt.subtract(platformCnyUsdtExchangeEntity.getDiff())); } return Result.ok(map); public Result findAll() { QueryWrapper<PlatformPaymentMethodEntity> queryWrapper = new QueryWrapper<>(); List<PlatformPaymentMethodEntity> paymentMethodList = platformPaymentMethodDao.selectList(queryWrapper); return Result.ok(paymentMethodList); } }