From 2f01e509236aa3ff895a0f9bb87b301049b42294 Mon Sep 17 00:00:00 2001
From: gao <gaoleox@163>
Date: Tue, 26 May 2020 11:31:49 +0800
Subject: [PATCH] 快捷买卖接口

---
 src/main/java/com/xcong/excoin/modules/platform/dao/PlatformCnyUsdtExchangeDao.java                  |   12 +
 src/main/resources/mapper/home/MemberQuickBuySaleDao.xml                                             |    5 
 src/main/java/com/xcong/excoin/modules/platform/entity/PlatformCnyUsdtExchangeEntity.java            |   26 +++
 src/main/java/com/xcong/excoin/modules/platform/service/impl/PlatformCnyUsdtExchangeServiceImpl.java |   38 ++++
 src/main/resources/mapper/member/MemberWalletCoinDao.xml                                             |   11 +
 src/main/java/com/xcong/excoin/modules/platform/controller/PlatformCnyUsdtExchangeController.java    |   34 ++++
 src/main/resources/mapper/home/MemberPaymentMethodDao.xml                                            |    9 +
 src/main/java/com/xcong/excoin/modules/home/service/impl/MemberQuickBuySaleServiceImpl.java          |  114 ++++++++------
 src/main/java/com/xcong/excoin/modules/platform/service/PlatformCnyUsdtExchangeService.java          |   13 +
 src/main/java/com/xcong/excoin/modules/home/entity/MemberPaymentMethodEntity.java                    |   70 ++------
 src/main/java/com/xcong/excoin/modules/platform/vo/PlatformCnyUsdtExchangeVo.java                    |   13 +
 src/main/java/com/xcong/excoin/modules/home/service/MemberQuickBuySaleService.java                   |    7 
 src/main/java/com/xcong/excoin/modules/home/controller/MemberQuickBuySaleController.java             |   82 ++++++++--
 src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletCoinDao.java                           |    2 
 src/main/java/com/xcong/excoin/modules/home/dao/MemberQuickBuySaleDao.java                           |    3 
 src/main/java/com/xcong/excoin/modules/home/dao/MemberPaymentMethodDao.java                          |    3 
 16 files changed, 323 insertions(+), 119 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/home/controller/MemberQuickBuySaleController.java b/src/main/java/com/xcong/excoin/modules/home/controller/MemberQuickBuySaleController.java
index 32725f9..869335b 100644
--- a/src/main/java/com/xcong/excoin/modules/home/controller/MemberQuickBuySaleController.java
+++ b/src/main/java/com/xcong/excoin/modules/home/controller/MemberQuickBuySaleController.java
@@ -8,57 +8,103 @@
 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.LoginUserUtils;
 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.service.MemberQuickBuySaleService;
+import com.xcong.excoin.modules.member.entity.MemberEntity;
 
+import cn.hutool.crypto.SecureUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
 
 @RestController
+@Slf4j
 @RequestMapping(value = "/api/quick")
-@Api(value = "USDT快捷买卖类", tags = "USDT快捷买卖类")
+@Api(value = "MemberQuickBuySaleController", tags = "USDT快捷买卖类")
 public class MemberQuickBuySaleController {
 
 	@Autowired
 	MemberQuickBuySaleService memberQuickBuySaleService;
 
-	@ApiOperation(value = "USDT快速充值", notes = "USDT快速充值")
+	@ApiOperation(value = "recharge", notes = "USDT快速充值")
 	@RequestMapping(value = "/recharge", method = RequestMethod.POST)
 	public Result recharge(@RequestBody MemberQuickBuySaleDto memberQuickBuySaleDto) {
-		return memberQuickBuySaleService.recharge(memberQuickBuySaleDto);
+		log.info("入参----->{}", memberQuickBuySaleDto);
+		//获取用户ID
+		MemberEntity member = LoginUserUtils.getAppLoginUser();
+		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("请输入正确的交易密码");
+		}
+		return memberQuickBuySaleService.recharge(member, memberQuickBuySaleDto);
 	}
 	
 	
-	@ApiOperation(value = "USDT充值支付确认", notes = "USDT充值支付确认")
+	@ApiOperation(value = "commitPay", notes = "USDT充值支付确认")
 	@RequestMapping(value = "/commitPay", method = RequestMethod.POST)
 	public Result commitPay(@RequestBody MemberQuickBuySaleCommitDto memberQuickBuySaleCommitDto) {
 		return memberQuickBuySaleService.commitPay(memberQuickBuySaleCommitDto);
 	}
 	
-	@ApiOperation(value = "查询单个买卖记录", notes = "查询单个买卖记录")
+	@ApiOperation(value = "selectById", 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 = "充值撤销")
+	@ApiOperation(value = "cancel", notes = "充值撤销")
 	@GetMapping(value = "/cancel/{id}")
 	public Result cancel(@PathVariable(value = "id") Long id) {
 		return memberQuickBuySaleService.cancelRecharge(id);
 	}
 	
-	
-	
+	@ApiOperation(value = "sell", notes = "USDT快速充值")
+	@RequestMapping(value = "/sell", method = RequestMethod.POST)
+	public Result sell(MemberQuickBuySaleDto memberQuickBuySaleDto) {
+		// 获取当前登录用户
+		MemberEntity member = LoginUserUtils.getAppLoginUser();
+		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("请输入交易密码");
+		}
+		// 验证交易密码
+		if (!tradePassword.equals(SecureUtil.md5(tradePasswordWeb))) {
+			return Result.fail("请输入正确的交易密码");
+		}
+		return memberQuickBuySaleService.sell(member,memberQuickBuySaleDto);
+	}
 }
diff --git a/src/main/java/com/xcong/excoin/modules/home/dao/MemberPaymentMethodDao.java b/src/main/java/com/xcong/excoin/modules/home/dao/MemberPaymentMethodDao.java
index 3f8a82c..7a45a09 100644
--- a/src/main/java/com/xcong/excoin/modules/home/dao/MemberPaymentMethodDao.java
+++ b/src/main/java/com/xcong/excoin/modules/home/dao/MemberPaymentMethodDao.java
@@ -1,8 +1,11 @@
 package com.xcong.excoin.modules.home.dao;
 
+import java.util.List;
+
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.xcong.excoin.modules.home.entity.MemberPaymentMethodEntity;
 
 public interface MemberPaymentMethodDao extends BaseMapper<MemberPaymentMethodEntity> {
 
+	public List<MemberPaymentMethodEntity> selectByMemberId(Long memberId);
 }
diff --git a/src/main/java/com/xcong/excoin/modules/home/dao/MemberQuickBuySaleDao.java b/src/main/java/com/xcong/excoin/modules/home/dao/MemberQuickBuySaleDao.java
index b4515af..5f084f8 100644
--- a/src/main/java/com/xcong/excoin/modules/home/dao/MemberQuickBuySaleDao.java
+++ b/src/main/java/com/xcong/excoin/modules/home/dao/MemberQuickBuySaleDao.java
@@ -1,9 +1,12 @@
 package com.xcong.excoin.modules.home.dao;
 
+import org.apache.ibatis.annotations.Param;
+
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.xcong.excoin.modules.home.entity.MemberQuickBuySaleEntity;
 
 public interface MemberQuickBuySaleDao extends BaseMapper<MemberQuickBuySaleEntity> {
 	
+	MemberQuickBuySaleEntity selectByIdAndMemberId(@Param("memberId")Long memberId,@Param("id")Long id);
 
 }
diff --git a/src/main/java/com/xcong/excoin/modules/home/entity/MemberPaymentMethodEntity.java b/src/main/java/com/xcong/excoin/modules/home/entity/MemberPaymentMethodEntity.java
index d3de533..29e3e3e 100644
--- a/src/main/java/com/xcong/excoin/modules/home/entity/MemberPaymentMethodEntity.java
+++ b/src/main/java/com/xcong/excoin/modules/home/entity/MemberPaymentMethodEntity.java
@@ -1,7 +1,5 @@
 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;
 
@@ -10,33 +8,20 @@
 
 @EqualsAndHashCode(callSuper = true)
 @Data
-@TableName("member_quick_buy_sale")
+@TableName("member_payment_method")
 public class MemberPaymentMethodEntity  extends BaseEntity{
 	/**
-	 * 订单状态 1-新建
+	 * 付款方式:支付宝
 	 */
-	public static final Integer CHARGE_STATUS_CREATE = 1;
-	
+	public static String PAYMENT_TYPE_ALIPAY = "1";
 	/**
-	 * 订单状态 2-已付款
+	 * 付款方式:微信
 	 */
-	public static final Integer CHARGE_STATUS_PAID = 2;
-	
+	public static String PAYMENT_TYPE_WEPAY = "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;
-	
+	public static String PAYMENT_TYPE_BANK = "3";
 
 	private static final long serialVersionUID = 1L;
 	/**
@@ -44,43 +29,32 @@
      */
     private Long memberId;
     /**
-     * 金额(人民币)
+     * 姓名
      */
-    private BigDecimal amountCny;
+    private String name;
     /**
-     * 金额(USDT)
+     * 账号
      */
-    private BigDecimal amountUsdt;
+    private String account;
     /**
-     * 付款方式 1-支付宝2-微信3-银行卡
+     * 收款二维码
      */
-    private Integer paymentType;
+    private String paymentQrcode;
     /**
-     * 收款账号
+     * 银行
      */
-    private String paymentAccount;
+    private String bank;
     /**
-     * 收款人姓名
+     * 支行
      */
-    private String paymentName;
+    private String subBank;
     /**
-     * 支付码
+     * 类型 1-支付宝2-微信3-银行卡
      */
-    private String paymentCode;
+    private String paymentType;
     /**
-     * 单价
+     * 默认收款方式
      */
-    private BigDecimal unitPrice;
-    /**
-     * 订单状态 1-新建2-已付款3-已审核4-撤单5-系统取消
-     */
-    private int orderStatus;
-    /**
-     * 订单编号
-     */
-    private String orderNo;
-    /**
-     * 订单类型 B买入 S卖出
-     */
-    private String orderType;
+    private int isDefualt;
+    
 }
diff --git a/src/main/java/com/xcong/excoin/modules/home/service/MemberQuickBuySaleService.java b/src/main/java/com/xcong/excoin/modules/home/service/MemberQuickBuySaleService.java
index 6ab4ba5..d7bf632 100644
--- a/src/main/java/com/xcong/excoin/modules/home/service/MemberQuickBuySaleService.java
+++ b/src/main/java/com/xcong/excoin/modules/home/service/MemberQuickBuySaleService.java
@@ -5,16 +5,17 @@
 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;
 
 public interface MemberQuickBuySaleService extends IService<MemberQuickBuySaleEntity> {
 
-	public Result recharge(MemberQuickBuySaleDto memberQuickBuySaleDto);
+	public Result recharge(MemberEntity member,MemberQuickBuySaleDto memberQuickBuySaleDto);
 	
 	public Result commitPay(MemberQuickBuySaleCommitDto memberQuickBuySaleCommitDto);
 	
 	public Result selectById(Long id);
 	
-	public Result sell();
-	
 	public Result cancelRecharge(Long id);
+	
+	public Result sell(MemberEntity member,MemberQuickBuySaleDto memberQuickBuySaleDto);
 }
diff --git a/src/main/java/com/xcong/excoin/modules/home/service/impl/MemberQuickBuySaleServiceImpl.java b/src/main/java/com/xcong/excoin/modules/home/service/impl/MemberQuickBuySaleServiceImpl.java
index 567c560..3c4eaac 100644
--- a/src/main/java/com/xcong/excoin/modules/home/service/impl/MemberQuickBuySaleServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/home/service/impl/MemberQuickBuySaleServiceImpl.java
@@ -8,9 +8,10 @@
 
 import org.springframework.stereotype.Service;
 
-import com.alibaba.druid.util.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xcong.excoin.common.LoginUserUtils;
+import com.xcong.excoin.common.enumerates.CoinTypeEnum;
 import com.xcong.excoin.common.response.Result;
 import com.xcong.excoin.modules.home.dao.MemberPaymentMethodDao;
 import com.xcong.excoin.modules.home.dao.MemberQuickBuySaleDao;
@@ -26,11 +27,7 @@
 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
@@ -43,43 +40,17 @@
 	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("请输入正确的交易密码");
-		}
+	public Result recharge(MemberEntity member,MemberQuickBuySaleDto memberQuickBuySaleDto) {
 		// 生成订单号
 		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.setOrderStatus(MemberQuickBuySaleEntity.CHARGE_STATUS_CREATE);
+		memberQuickBuySaleEntity.setMemberId(member.getId());
+		memberQuickBuySaleEntity.setAmountUsdt(memberQuickBuySaleDto.getAmountUsdt());
+		memberQuickBuySaleEntity.setAmountCny(memberQuickBuySaleDto.getAmountCny());
 		memberQuickBuySaleEntity.setCreateTime(new Date());
 		memberQuickBuySaleEntity.setOrderNo(chargeNo);
 		memberQuickBuySaleEntity.setOrderType("B");
@@ -120,22 +91,73 @@
 		return Result.ok(memberQuickBuySaleVo);
 	}
 
-	
+	@Override
+	public Result sell(MemberEntity member,MemberQuickBuySaleDto memberQuickBuySaleDto) {
+		// 判断是否存在足够余额
+		MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(member.getId(),CoinTypeEnum.USDT.toString());
+		// 判断是否存在足够余额
+		if(walletCoin ==null) {
+			return Result.fail("您当前可用USDT额度不够");
+		}
+		BigDecimal extractUsdt = memberQuickBuySaleDto.getAmountUsdt();
+		if (extractUsdt == null) {
+			return Result.fail("请输入提币量");
+		}
+		// 判断是否足够
+		System.out.println("提币数:"+extractUsdt.doubleValue()+"   可用:"+walletCoin.getAvailableBalance());
+		if (extractUsdt.compareTo(walletCoin.getAvailableBalance())==1) {
+			return Result.fail("您当前可用USDT额度不够");
+		}
+
+
+		// 判断是否存在收款方式
+		List<MemberPaymentMethodEntity> payMentMethodList = memberPaymentMethodDao.selectByMemberId(member.getId());
+		if(CollectionUtils.isEmpty(payMentMethodList)){
+			return Result.fail("请配置收款方式");
+		}
+		// 冻结可用额度
+		int i = memberWalletCoinDao.updateFrozenBalance(member.getId(),
+				walletCoin.getId(), extractUsdt);
+		if (i <= 0) {
+			return Result.fail("可用USDT余额不足");
+		}
+		
+		// 生成订单号
+		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(member.getId());
+		memberQuickBuySaleEntity.setAmountUsdt(memberQuickBuySaleDto.getAmountUsdt());
+		memberQuickBuySaleEntity.setAmountCny(memberQuickBuySaleDto.getAmountCny());
+		memberQuickBuySaleEntity.setOrderNo(chargeNo);
+		memberQuickBuySaleEntity.setOrderType("S");
+		// 支付码 ID+四位随机数
+		int ran = (int) (Math.random() * 10000000);
+		memberQuickBuySaleEntity.setPaymentCode(ran + "");
+		
+		memberQuickBuySaleDao.insert(memberQuickBuySaleEntity);
+
+		// TODO dingtalk
+		
+		return Result.ok("下单成功");
+	}
 
 	@Override
 	public Result cancelRecharge(Long id) {
 		// 获取当前登录用户
-		Long memberId = LoginUserUtils.getAppLoginUser().getId();
-		MemberEntity member = memberDao.selectById(memberId);
-		if(memberId==null) {
+		MemberEntity member = LoginUserUtils.getAppLoginUser();
+		if(member==null) {
 			return Result.fail("登录用户已失效");
 		}
-		MemberQuickBuySaleEntity memberQuickBuySaleEntity = memberQuickBuySaleDao.selectById(id);
+		MemberQuickBuySaleEntity memberQuickBuySaleEntity = memberQuickBuySaleDao.selectByIdAndMemberId(id,member.getId());
 		memberQuickBuySaleEntity.setOrderStatus(MemberQuickBuySaleEntity.CHARGE_STATUS_CANCEL_USER);
 		memberQuickBuySaleDao.updateById(memberQuickBuySaleEntity);
 		
 		// 判断是否存在足够余额
-		MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(id,"USDT");
+		MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(member.getId(),CoinTypeEnum.USDT.toString());
 		boolean flag = true;
 		while(flag) {
 			walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(memberQuickBuySaleEntity.getAmountUsdt()));
@@ -144,14 +166,8 @@
 			if(i>0) {
 				flag = false;
 			}
-			walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(id,"USDT");
+			walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(member.getId(),CoinTypeEnum.USDT.toString());
 		}
 		return Result.ok("成功");
-	}
-
-	@Override
-	public Result sell() {
-		// TODO Auto-generated method stub
-		return null;
 	}
 }
diff --git a/src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletCoinDao.java b/src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletCoinDao.java
index f5f3927..eb14610 100644
--- a/src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletCoinDao.java
+++ b/src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletCoinDao.java
@@ -1,5 +1,6 @@
 package com.xcong.excoin.modules.member.dao;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 import org.apache.ibatis.annotations.Param;
@@ -16,4 +17,5 @@
 	
 	MemberWalletCoinEntity selectWalletCoinBymIdAndCode(@Param("memberId")Long memberId,@Param("walletCode")String walletCode);
 	
+	int updateFrozenBalance(@Param("memberId")Long memberId,@Param("id")Long id,@Param("memberId")BigDecimal amount);
 }
diff --git a/src/main/java/com/xcong/excoin/modules/platform/controller/PlatformCnyUsdtExchangeController.java b/src/main/java/com/xcong/excoin/modules/platform/controller/PlatformCnyUsdtExchangeController.java
new file mode 100644
index 0000000..c10bd37
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/platform/controller/PlatformCnyUsdtExchangeController.java
@@ -0,0 +1,34 @@
+package com.xcong.excoin.modules.platform.controller;
+
+import javax.annotation.Resource;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.xcong.excoin.common.response.Result;
+import com.xcong.excoin.modules.platform.service.PlatformCnyUsdtExchangeService;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.extern.slf4j.Slf4j;
+
+@RestController
+@Slf4j
+@RequestMapping(value = "/api/exchange")
+@Api(value = "PlatformCnyUsdtExchangeController", tags = "平台Cny|Usdt兑换类")
+public class PlatformCnyUsdtExchangeController {
+	
+	@Resource
+	PlatformCnyUsdtExchangeService platformCnyUsdtExchangeService;
+	
+	@ApiOperation(value = "findUsdtCnyExchange", notes = "Cny|Usdt兑换")
+	@GetMapping(value = "/findUsdtCnyExchange")
+	public Result findUsdtCnyExchange(@ApiParam(name = "type", value = "类型", type="string", required=true) @RequestParam("type") String type) {
+		log.info("type值----->{}", type);
+		return platformCnyUsdtExchangeService.findUsdtCnyExchange(type);
+	}
+	
+}
diff --git a/src/main/java/com/xcong/excoin/modules/platform/dao/PlatformCnyUsdtExchangeDao.java b/src/main/java/com/xcong/excoin/modules/platform/dao/PlatformCnyUsdtExchangeDao.java
new file mode 100644
index 0000000..91aeda2
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/platform/dao/PlatformCnyUsdtExchangeDao.java
@@ -0,0 +1,12 @@
+package com.xcong.excoin.modules.platform.dao;
+
+import java.util.List;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.xcong.excoin.modules.home.entity.MemberPaymentMethodEntity;
+import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
+
+public interface PlatformCnyUsdtExchangeDao extends BaseMapper<PlatformCnyUsdtExchangeEntity> {
+
+	
+}
diff --git a/src/main/java/com/xcong/excoin/modules/platform/entity/PlatformCnyUsdtExchangeEntity.java b/src/main/java/com/xcong/excoin/modules/platform/entity/PlatformCnyUsdtExchangeEntity.java
new file mode 100644
index 0000000..da9b97f
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/platform/entity/PlatformCnyUsdtExchangeEntity.java
@@ -0,0 +1,26 @@
+package com.xcong.excoin.modules.platform.entity;
+
+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{
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 兑换比例
+	 */
+	private BigDecimal value;
+	/**
+	 * 增减偏量
+	 */
+	private BigDecimal diff;
+}
diff --git a/src/main/java/com/xcong/excoin/modules/platform/service/PlatformCnyUsdtExchangeService.java b/src/main/java/com/xcong/excoin/modules/platform/service/PlatformCnyUsdtExchangeService.java
new file mode 100644
index 0000000..264f3c3
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/platform/service/PlatformCnyUsdtExchangeService.java
@@ -0,0 +1,13 @@
+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.PlatformCnyUsdtExchangeEntity;
+
+public interface PlatformCnyUsdtExchangeService extends IService<PlatformCnyUsdtExchangeEntity> {
+
+	public Result findUsdtCnyExchange(@RequestParam("type") String type);
+	
+}
diff --git a/src/main/java/com/xcong/excoin/modules/platform/service/impl/PlatformCnyUsdtExchangeServiceImpl.java b/src/main/java/com/xcong/excoin/modules/platform/service/impl/PlatformCnyUsdtExchangeServiceImpl.java
new file mode 100644
index 0000000..f1d757f
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/platform/service/impl/PlatformCnyUsdtExchangeServiceImpl.java
@@ -0,0 +1,38 @@
+package com.xcong.excoin.modules.platform.service.impl;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.springframework.stereotype.Service;
+
+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.entity.PlatformCnyUsdtExchangeEntity;
+import com.xcong.excoin.modules.platform.service.PlatformCnyUsdtExchangeService;
+
+@Service
+public class PlatformCnyUsdtExchangeServiceImpl extends ServiceImpl<PlatformCnyUsdtExchangeDao, PlatformCnyUsdtExchangeEntity> implements PlatformCnyUsdtExchangeService{
+	@Resource
+	PlatformCnyUsdtExchangeDao platformCnyUsdtExchangeDao;
+	
+	@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);
+	}
+	
+}
diff --git a/src/main/java/com/xcong/excoin/modules/platform/vo/PlatformCnyUsdtExchangeVo.java b/src/main/java/com/xcong/excoin/modules/platform/vo/PlatformCnyUsdtExchangeVo.java
new file mode 100644
index 0000000..8a06fc6
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/platform/vo/PlatformCnyUsdtExchangeVo.java
@@ -0,0 +1,13 @@
+package com.xcong.excoin.modules.platform.vo;
+
+import java.math.BigDecimal;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+@Data
+@ApiModel(value = "会员快捷买入卖出", description = "会员快捷买入卖出类")
+public class PlatformCnyUsdtExchangeVo {
+	
+	
+}
diff --git a/src/main/resources/mapper/home/MemberPaymentMethodDao.xml b/src/main/resources/mapper/home/MemberPaymentMethodDao.xml
new file mode 100644
index 0000000..b18ffb4
--- /dev/null
+++ b/src/main/resources/mapper/home/MemberPaymentMethodDao.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper
+	namespace="com.xcong.excoin.modules.home.dao.MemberPaymentMethodDao">
+	<!-- 字段sql -->
+	<select id="selectByMemberId" resultType="com.xcong.excoin.modules.home.entity.MemberPaymentMethodEntity">
+		SELECT a.* FROM member_payment_method a WHERE a.member_id = #{memberId}
+	</select>
+</mapper>
\ No newline at end of file
diff --git a/src/main/resources/mapper/home/MemberQuickBuySaleDao.xml b/src/main/resources/mapper/home/MemberQuickBuySaleDao.xml
index 44ea088..4af7288 100644
--- a/src/main/resources/mapper/home/MemberQuickBuySaleDao.xml
+++ b/src/main/resources/mapper/home/MemberQuickBuySaleDao.xml
@@ -2,5 +2,8 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper
 	namespace="com.xcong.excoin.modules.home.dao.MemberQuickBuySaleDao">
-	<!-- 字段sql -->
+	
+	<select id="selectByIdAndMemberId" resultType="com.xcong.excoin.modules.home.entity.MemberQuickBuySaleEntity">
+		SELECT a.* FROM member_quick_buy_sale a WHERE a.id = #{id} AND a.member_id = #{memberId}
+	</select>
 </mapper>
\ No newline at end of file
diff --git a/src/main/resources/mapper/member/MemberWalletCoinDao.xml b/src/main/resources/mapper/member/MemberWalletCoinDao.xml
index fed0917..9d67869 100644
--- a/src/main/resources/mapper/member/MemberWalletCoinDao.xml
+++ b/src/main/resources/mapper/member/MemberWalletCoinDao.xml
@@ -9,6 +9,17 @@
     <select id="selectWalletCoinBymIdAndCode" resultType="com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity">
         select * from member_wallet_coin where member_id = #{memberId} and wallet_code = #{walletCode}
     </select>
+    
+    <update id="updateFrozenBalance" parameterType="map">
+		UPDATE member_wallet_coin
+		SET available_balance = available_balance - #{amount},
+		 	frozen_balance = frozen_balance + #{amount}
+		WHERE
+			id = #{id}
+		AND member_id = #{memberId}
+	</update>
+    
+    
 
 
 

--
Gitblit v1.9.1