src/main/java/com/xcong/excoin/modules/home/controller/MemberQuickBuySaleController.java
@@ -1,25 +1,19 @@ package com.xcong.excoin.modules.home.controller; import java.util.Date; import org.apache.commons.codec.digest.Md5Crypt; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.alibaba.druid.util.StringUtils; import com.xcong.excoin.common.annotations.UserAuth; import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.home.dao.MemberQuickBuySaleDao; import com.xcong.excoin.modules.home.dto.MemberQuickBuySaleCommitDto; import com.xcong.excoin.modules.home.dto.MemberQuickBuySaleDto; import com.xcong.excoin.modules.home.entity.MemberQuickBuySaleEntity; import com.xcong.excoin.modules.member.entity.MemberEntity; import com.xcong.excoin.modules.home.service.MemberQuickBuySaleService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @RestController @@ -28,69 +22,41 @@ public class MemberQuickBuySaleController { @Autowired MemberQuickBuySaleDao memberQuickBuySaleDao; MemberQuickBuySaleService memberQuickBuySaleService; @ApiOperation(value = "USDT快速充值", notes = "USDT快速充值") @RequestMapping(value = "/recharge", method = RequestMethod.POST) public Result recharge(@RequestBody MemberQuickBuySaleDto memberQuickBuySaleDto, @UserAuth MemberEntity memberEntity) { // 验证是否实名认证 if (MemberEntity.CERTIFY_STATUS_Y.equals(memberEntity.getCertifyStatus())) { return Result.fail("请先实名认证"); } String tradePasswordWeb = memberQuickBuySaleDto.getTradePassword(); // 验证支付密码 String tradePassword = memberEntity.getTradePassword(); if (StringUtils.isEmpty(tradePassword)) { return Result.fail("请先配置交易密码"); } if (StringUtils.isEmpty(tradePasswordWeb)) { return Result.fail("请输入交易密码"); } // System.out.println("交易密码:"+MD5.GetMD5Code(tradePasswordWeb)+" tradePassword = // "+tradePassword); // 验证交易密码 if (!Md5Crypt.apr1Crypt(tradePasswordWeb).equals(tradePassword)) { return Result.fail("请输入正确的交易密码"); } // 生成订单号 Long timestamp = System.currentTimeMillis(); int random = (int) (Math.random() * 10); String chargeNo = String.valueOf(timestamp).substring(2) + random; // 插入订单表 MemberQuickBuySaleEntity memberQuickBuySaleEntity = new MemberQuickBuySaleEntity(); memberQuickBuySaleEntity.setOrderStatus(memberQuickBuySaleEntity.CHARGE_STATUS_CREATE); memberQuickBuySaleEntity.setMemberId(memberEntity.getId()); memberQuickBuySaleEntity.setCreateTime(new Date()); memberQuickBuySaleEntity.setOrderNo(chargeNo); memberQuickBuySaleEntity.setOrderType("B"); // 支付码 ID+四位随机数 int ran = (int) (Math.random() * 10000000); memberQuickBuySaleEntity.setPaymentCode(ran + ""); memberQuickBuySaleEntity.setPaymentAccount(memberQuickBuySaleDto.getPaymentAccount()); memberQuickBuySaleEntity.setPaymentName(memberQuickBuySaleDto.getPaymentName()); System.out.println("实体对象:"+memberQuickBuySaleEntity); memberQuickBuySaleDao.insert(memberQuickBuySaleEntity); // 返回前台付款方式 // memberChargeUsdt.setReceiveMethod(payMethodList.get(index)); return Result.ok("购买成功,请及时付款"); public Result recharge(@RequestBody MemberQuickBuySaleDto memberQuickBuySaleDto) { return memberQuickBuySaleService.recharge(memberQuickBuySaleDto); } @ApiOperation(value = "USDT充值支付确认", notes = "USDT充值支付确认") @ApiImplicitParam(name = "token", value = "token", required = false, dataType = "String", paramType = "body") @RequestMapping(value = "/commitPay", method = RequestMethod.GET) public Result commitPay(@PathVariable(value = "id") Long id) { // 用户提交支付确认 将状态改为付款中 MemberQuickBuySaleEntity MemberQuickBuySaleEntity = new MemberQuickBuySaleEntity(); MemberQuickBuySaleEntity.setId(id); MemberQuickBuySaleEntity.setOrderStatus(MemberQuickBuySaleEntity.CHARGE_STATUS_PAID); memberQuickBuySaleDao.updateById(MemberQuickBuySaleEntity); // TODO dingtalk return Result.ok("确认成功"); @RequestMapping(value = "/commitPay", method = RequestMethod.POST) public Result commitPay(@RequestBody MemberQuickBuySaleCommitDto memberQuickBuySaleCommitDto) { return memberQuickBuySaleService.commitPay(memberQuickBuySaleCommitDto); } @ApiOperation(value = "查询单个买卖记录", notes = "查询单个买卖记录") @GetMapping(value = "/selectById/{id}") public Result selectById(@PathVariable(value = "id") Long id) { return memberQuickBuySaleService.selectById(id); } /** * 充值撤销 * * @param memberChargeUsdt * @param page * @param rows * @return */ @ApiOperation(value = "充值撤销", notes = "充值撤销") @GetMapping(value = "/cancel/{id}") public Result cancel(@PathVariable(value = "id") Long id) { return memberQuickBuySaleService.cancelRecharge(id); } src/main/java/com/xcong/excoin/modules/home/dao/MemberPaymentMethodDao.java
New file @@ -0,0 +1,8 @@ package com.xcong.excoin.modules.home.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.xcong.excoin.modules.home.entity.MemberPaymentMethodEntity; public interface MemberPaymentMethodDao extends BaseMapper<MemberPaymentMethodEntity> { } src/main/java/com/xcong/excoin/modules/home/dto/MemberQuickBuySaleCommitDto.java
New file @@ -0,0 +1,22 @@ package com.xcong.excoin.modules.home.dto; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data @ApiModel(value = "确认快捷买入接收参数", description = "确认快捷买入接收参数") public class MemberQuickBuySaleCommitDto { @ApiModelProperty(value = "主键",example = "1") private Long id; @ApiModelProperty(value = "付款方式 1-支付宝2-微信3-银行卡",example = "1") private int paymentType; @ApiModelProperty(value = "收款账号",example = "13000000000") private String paymentAccount; @ApiModelProperty(value = "收款人姓名",example = "张三") private String paymentName; } src/main/java/com/xcong/excoin/modules/home/dto/MemberQuickBuySaleDto.java
@@ -25,15 +25,6 @@ @ApiModelProperty(value = "金额(USDT)",example = "100") private BigDecimal amountUsdt; @ApiModelProperty(value = "付款方式 1-支付宝2-微信3-银行卡",example = "1") private int paymentType; @ApiModelProperty(value = "收款账号",example = "13000000000") private String paymentAccount; @ApiModelProperty(value = "收款人姓名",example = "张三") private String paymentName; @ApiModelProperty(value = "单价",example = "7") private BigDecimal unitPrice; @@ -42,6 +33,7 @@ private String orderType; @NotNull(message = "交易密码不能为空") @ApiModelProperty(value = "交易密码",example = "123456") private String tradePassword; @ApiModelProperty(value = "充值时间") src/main/java/com/xcong/excoin/modules/home/entity/MemberPaymentMethodEntity.java
New file @@ -0,0 +1,86 @@ package com.xcong.excoin.modules.home.entity; import java.math.BigDecimal; import com.baomidou.mybatisplus.annotation.TableName; import com.xcong.excoin.common.system.base.BaseEntity; import lombok.Data; import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) @Data @TableName("member_quick_buy_sale") public class MemberPaymentMethodEntity extends BaseEntity{ /** * 订单状态 1-新建 */ public static final Integer CHARGE_STATUS_CREATE = 1; /** * 订单状态 2-已付款 */ public static final Integer CHARGE_STATUS_PAID = 2; /** * 订单状态 3-已审核 */ public static final Integer CHARGE_STATUS_CHECKED = 3; /** * 订单状态 4-撤单 */ public static final Integer CHARGE_STATUS_CANCEL_USER = 4; /** * 订单状态 5-系统取消 */ public static final Integer CHARGE_STATUS_CANCEL_SYSTEM = 5; private static final long serialVersionUID = 1L; /** * 用户Id */ private Long memberId; /** * 金额(人民币) */ private BigDecimal amountCny; /** * 金额(USDT) */ private BigDecimal amountUsdt; /** * 付款方式 1-支付宝2-微信3-银行卡 */ private Integer paymentType; /** * 收款账号 */ private String paymentAccount; /** * 收款人姓名 */ private String paymentName; /** * 支付码 */ private String paymentCode; /** * 单价 */ private BigDecimal unitPrice; /** * 订单状态 1-新建2-已付款3-已审核4-撤单5-系统取消 */ private int orderStatus; /** * 订单编号 */ private String orderNo; /** * 订单类型 B买入 S卖出 */ private String orderType; } src/main/java/com/xcong/excoin/modules/home/entity/MemberQuickBuySaleEntity.java
@@ -15,27 +15,27 @@ /** * 订单状态 1-新建 */ public final int CHARGE_STATUS_CREATE = 1; public static final Integer CHARGE_STATUS_CREATE = 1; /** * 订单状态 2-已付款 */ public final int CHARGE_STATUS_PAID = 2; public static final Integer CHARGE_STATUS_PAID = 2; /** * 订单状态 3-已审核 */ public final int CHARGE_STATUS_CHECKED = 3; public static final Integer CHARGE_STATUS_CHECKED = 3; /** * 订单状态 4-撤单 */ public final int CHARGE_STATUS_CANCEL_USER = 4; public static final Integer CHARGE_STATUS_CANCEL_USER = 4; /** * 订单状态 5-系统取消 */ public final int CHARGE_STATUS_CANCEL_SYSTEM = 5; public static final Integer CHARGE_STATUS_CANCEL_SYSTEM = 5; private static final long serialVersionUID = 1L; @@ -54,7 +54,7 @@ /** * 付款方式 1-支付宝2-微信3-银行卡 */ private int paymentType; private Integer paymentType; /** * 收款账号 */ src/main/java/com/xcong/excoin/modules/home/mapper/MemberQuickBuySaleEntityMapper.java
@@ -4,6 +4,8 @@ import org.mapstruct.factory.Mappers; import com.xcong.excoin.modules.home.dto.MemberQuickBuySaleDto; import com.xcong.excoin.modules.home.entity.MemberQuickBuySaleEntity; import com.xcong.excoin.modules.home.vo.MemberQuickBuySaleVo; @Mapper @@ -13,5 +15,7 @@ public abstract MemberQuickBuySaleEntityMapper dtoToEntity(MemberQuickBuySaleDto dto); public abstract MemberQuickBuySaleVo entityToVo(MemberQuickBuySaleEntity memberQuickBuySaleEntity); } src/main/java/com/xcong/excoin/modules/home/service/MemberQuickBuySaleService.java
@@ -1,9 +1,20 @@ package com.xcong.excoin.modules.home.service; import com.baomidou.mybatisplus.extension.service.IService; import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.home.dto.MemberQuickBuySaleCommitDto; import com.xcong.excoin.modules.home.dto.MemberQuickBuySaleDto; import com.xcong.excoin.modules.home.entity.MemberQuickBuySaleEntity; public interface MemberQuickBuySaleService extends IService<MemberQuickBuySaleEntity> { public Result recharge(MemberQuickBuySaleDto memberQuickBuySaleDto); public Result commitPay(MemberQuickBuySaleCommitDto memberQuickBuySaleCommitDto); public Result selectById(Long id); public Result sell(); public Result cancelRecharge(Long id); } src/main/java/com/xcong/excoin/modules/home/service/impl/MemberQuickBuySaleServiceImpl.java
New file @@ -0,0 +1,157 @@ package com.xcong.excoin.modules.home.service.impl; import java.math.BigDecimal; import java.util.Date; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.alibaba.druid.util.StringUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.xcong.excoin.common.LoginUserUtils; import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.home.dao.MemberPaymentMethodDao; import com.xcong.excoin.modules.home.dao.MemberQuickBuySaleDao; import com.xcong.excoin.modules.home.dto.MemberQuickBuySaleCommitDto; import com.xcong.excoin.modules.home.dto.MemberQuickBuySaleDto; import com.xcong.excoin.modules.home.entity.MemberPaymentMethodEntity; import com.xcong.excoin.modules.home.entity.MemberQuickBuySaleEntity; import com.xcong.excoin.modules.home.mapper.MemberQuickBuySaleEntityMapper; import com.xcong.excoin.modules.home.service.MemberQuickBuySaleService; import com.xcong.excoin.modules.home.vo.MemberQuickBuySaleVo; import com.xcong.excoin.modules.member.dao.MemberDao; 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 cn.hutool.crypto.SecureUtil; import lombok.extern.slf4j.Slf4j; @Service @Slf4j public class MemberQuickBuySaleServiceImpl extends ServiceImpl<MemberQuickBuySaleDao, MemberQuickBuySaleEntity> implements MemberQuickBuySaleService{ @Resource MemberDao memberDao; @Resource MemberQuickBuySaleDao memberQuickBuySaleDao; @Resource MemberWalletCoinDao memberWalletCoinDao; @Resource MemberPaymentMethodDao memberPaymentMethodDao; @Override public Result recharge(MemberQuickBuySaleDto memberQuickBuySaleDto) { log.info("入参----->{}", memberQuickBuySaleDto); //获取用户ID Long memberId = LoginUserUtils.getAppLoginUser().getId(); MemberEntity member = memberDao.selectById(memberId); log.info("查询到的会员----->{}", member); // 验证是否实名认证 if (MemberEntity.CERTIFY_STATUS_Y.equals(member.getCertifyStatus())) { return Result.fail("请先实名认证"); } String tradePasswordWeb = memberQuickBuySaleDto.getTradePassword(); // 验证支付密码 String tradePassword = member.getTradePassword(); log.info("入参交易密码{},用户设置的交易密码{}", tradePasswordWeb,tradePassword); if (StringUtils.isEmpty(tradePassword)) { return Result.fail("请先配置交易密码"); } if (StringUtils.isEmpty(tradePasswordWeb)) { return Result.fail("请输入交易密码"); } // System.out.println("交易密码:"+MD5.GetMD5Code(tradePasswordWeb)+" tradePassword = // "+tradePassword); // 验证交易密码 if (!tradePassword.equals(SecureUtil.md5(tradePasswordWeb))) { return Result.fail("请输入正确的交易密码"); } // 生成订单号 Long timestamp = System.currentTimeMillis(); int random = (int) (Math.random() * 10); String chargeNo = String.valueOf(timestamp).substring(2) + random; // 插入订单表 MemberQuickBuySaleEntity memberQuickBuySaleEntity = new MemberQuickBuySaleEntity(); memberQuickBuySaleEntity.setOrderStatus(memberQuickBuySaleEntity.CHARGE_STATUS_CREATE); memberQuickBuySaleEntity.setMemberId(memberId); memberQuickBuySaleEntity.setCreateTime(new Date()); memberQuickBuySaleEntity.setOrderNo(chargeNo); memberQuickBuySaleEntity.setOrderType("B"); // 支付码 ID+四位随机数 int ran = (int) (Math.random() * 10000000); memberQuickBuySaleEntity.setPaymentCode(ran + ""); memberQuickBuySaleDao.insert(memberQuickBuySaleEntity); // 返回前台付款方式 // memberChargeUsdt.setReceiveMethod(payMethodList.get(index)); return Result.ok("购买成功,请及时付款"); } @Override public Result commitPay(MemberQuickBuySaleCommitDto memberQuickBuySaleCommitDto) { // 用户提交支付确认 将状态改为付款中 MemberQuickBuySaleEntity memberQuickBuySaleEntity = new MemberQuickBuySaleEntity(); memberQuickBuySaleEntity.setId(memberQuickBuySaleCommitDto.getId()); memberQuickBuySaleEntity.setOrderStatus(MemberQuickBuySaleEntity.CHARGE_STATUS_PAID); memberQuickBuySaleEntity.setPaymentAccount(memberQuickBuySaleCommitDto.getPaymentAccount()); memberQuickBuySaleEntity.setPaymentName(memberQuickBuySaleCommitDto.getPaymentName()); memberQuickBuySaleDao.updateById(memberQuickBuySaleEntity); // TODO dingtalk return Result.ok("确认成功"); } @Override public Result selectById(Long id) { MemberQuickBuySaleEntity memberQuickBuySaleEntity = memberQuickBuySaleDao.selectById(id); MemberQuickBuySaleVo memberQuickBuySaleVo = MemberQuickBuySaleEntityMapper.INSTANCE.entityToVo(memberQuickBuySaleEntity); long startTime = memberQuickBuySaleEntity.getCreateTime().getTime(); long nowTime = new Date().getTime(); long third = 30*60*1000; memberQuickBuySaleVo.setTimeLeft((third-nowTime+startTime)/1000); return Result.ok(memberQuickBuySaleVo); } @Override public Result cancelRecharge(Long id) { // 获取当前登录用户 Long memberId = LoginUserUtils.getAppLoginUser().getId(); MemberEntity member = memberDao.selectById(memberId); if(memberId==null) { return Result.fail("登录用户已失效"); } MemberQuickBuySaleEntity memberQuickBuySaleEntity = memberQuickBuySaleDao.selectById(id); memberQuickBuySaleEntity.setOrderStatus(MemberQuickBuySaleEntity.CHARGE_STATUS_CANCEL_USER); memberQuickBuySaleDao.updateById(memberQuickBuySaleEntity); // 判断是否存在足够余额 MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(id,"USDT"); boolean flag = true; while(flag) { walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(memberQuickBuySaleEntity.getAmountUsdt())); walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(memberQuickBuySaleEntity.getAmountUsdt())); int i = memberWalletCoinDao.updateById(walletCoin); if(i>0) { flag = false; } walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(id,"USDT"); } return Result.ok("成功"); } @Override public Result sell() { // TODO Auto-generated method stub return null; } } src/main/java/com/xcong/excoin/modules/home/vo/MemberQuickBuySaleVo.java
@@ -31,4 +31,6 @@ private String orderNo; @ApiModelProperty(value = "订单类型 B买入 S卖出") private String orderType; @ApiModelProperty(value = "剩余时间") private Long timeLeft; } src/main/resources/mapper/home/MemberQuickBuySaleDao.xml
@@ -3,46 +3,4 @@ <mapper namespace="com.xcong.excoin.modules.home.dao.MemberQuickBuySaleDao"> <!-- 字段sql --> <sql id="columns"> id, member_id, amount_cny, amount_usdt, payment_type, payment_account, payment_name, payment_code, unit_price, order_status, order_no, order_type </sql> <!-- 属性sql --> <sql id="propertys"> #{item.id}, #{item.memberId}, #{item.amountCny}, #{item.amountUsdt}, #{item.paymentType}, #{item.paymentAccount}, #{item.paymentName}, #{item.paymentCode}, #{item.unitPrice}, #{item.orderStatus}, #{item.orderNo}, #{item.orderType} </sql> <!-- 插入方法 --> <insert id="insert" parameterType="com.xcong.excoin.modules.home.entity.MemberQuickBuySaleEntity" useGeneratedKeys="true" keyProperty="id"> INSERT INTO member_quick_buy_sale ( <include refid="columns"></include> ) VALUES ( <include refid="propertys"></include> ) </insert> </mapper>