From 0d881874136ef0fecf31af98419af6bebdef1ac6 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 20 May 2021 16:40:13 +0800
Subject: [PATCH] modify

---
 src/main/java/com/xcong/excoin/modules/otc/dao/OtcOrderDao.java                  |    2 
 src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java |  101 ++++++++++++++++++++++++++++++++-
 src/main/java/com/xcong/excoin/modules/otc/vo/BuyOrderDetailVo.java              |    8 ++
 src/main/resources/mapper/otc/OtcEntrustOrderDao.xml                             |    2 
 src/main/java/com/xcong/excoin/modules/otc/vo/SaleOrderDetailVo.java             |   12 ++--
 src/main/java/com/xcong/excoin/modules/otc/controller/OtcOrderController.java    |   23 +++++--
 src/main/java/com/xcong/excoin/modules/otc/dto/HasPayDto.java                    |   16 +++++
 src/main/java/com/xcong/excoin/modules/otc/service/OtcOrderService.java          |    8 ++
 src/main/resources/mapper/otc/OtcOrderDao.xml                                    |    3 +
 src/main/java/com/xcong/excoin/modules/otc/service/OtcEntrustOrderService.java   |    1 
 10 files changed, 157 insertions(+), 19 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/otc/controller/OtcOrderController.java b/src/main/java/com/xcong/excoin/modules/otc/controller/OtcOrderController.java
index e2018f5..ef94ab0 100644
--- a/src/main/java/com/xcong/excoin/modules/otc/controller/OtcOrderController.java
+++ b/src/main/java/com/xcong/excoin/modules/otc/controller/OtcOrderController.java
@@ -3,12 +3,17 @@
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.xcong.excoin.common.response.Result;
+import com.xcong.excoin.modules.otc.dto.HasPayDto;
 import com.xcong.excoin.modules.otc.dto.OrderAddDto;
 import com.xcong.excoin.modules.otc.dto.OrderListDto;
 import com.xcong.excoin.modules.otc.service.OtcOrderService;
+import com.xcong.excoin.modules.otc.vo.BuyOrderDetailVo;
 import com.xcong.excoin.modules.otc.vo.OrderListVo;
+import com.xcong.excoin.modules.otc.vo.SaleOrderDetailVo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.ibatis.annotations.Param;
@@ -47,21 +52,27 @@
     }
 
     @ApiOperation(value = "买单 - 订单详情")
+    @ApiResponses({
+            @ApiResponse(code = 200, message = "success", response = BuyOrderDetailVo.class)
+    })
     @GetMapping(value = "/buyOrderDetail/{id}")
     public Result buyOrderDetail(@PathVariable("id") Long id) {
-        return null;
+        return otcOrderService.findBuyOrderDetail(id);
     }
 
     @ApiOperation(value = "卖单 - 订单详情")
-    @GetMapping(value = "/saleOrderDetail")
+    @ApiResponses({
+            @ApiResponse(code = 200, message = "success", response = SaleOrderDetailVo.class)
+    })
+    @GetMapping(value = "/saleOrderDetail/{id}")
     public Result saleOrderDetail(@PathVariable("id") Long id) {
-        return null;
+        return otcOrderService.findSaleOrderDetail(id);
     }
 
     @ApiOperation(value = "已付款,请放币")
-    @PostMapping(value = "/hasPay/{id}")
-    public Result hasPay(@PathVariable("id") Long id) {
-        otcOrderService.hasPay(id);
+    @PostMapping(value = "/hasPay")
+    public Result hasPay(@RequestBody HasPayDto hasPayDto) {
+        otcOrderService.hasPay(hasPayDto);
         return Result.ok("操作成功");
     }
 
diff --git a/src/main/java/com/xcong/excoin/modules/otc/dao/OtcOrderDao.java b/src/main/java/com/xcong/excoin/modules/otc/dao/OtcOrderDao.java
index 6d44837..99bc7b7 100644
--- a/src/main/java/com/xcong/excoin/modules/otc/dao/OtcOrderDao.java
+++ b/src/main/java/com/xcong/excoin/modules/otc/dao/OtcOrderDao.java
@@ -15,7 +15,7 @@
 
     IPage<OrderListVo> selectOrdderListInPage(@Param("record") OtcOrder order, Page<OrderListVo> page);
 
-    int updateOrderStatusByOrderNo(@Param("status") Integer status, @Param("orderNo") String orderNo);
+    int updateOrderStatusByOrderNo(@Param("status") Integer status, @Param("payName") String payName, @Param("orderNo") String orderNo);
 
     OtcOrder selectOrderByOrderNoAndType(String orderNo, String orderType);
 }
diff --git a/src/main/java/com/xcong/excoin/modules/otc/dto/HasPayDto.java b/src/main/java/com/xcong/excoin/modules/otc/dto/HasPayDto.java
new file mode 100644
index 0000000..81651d7
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/otc/dto/HasPayDto.java
@@ -0,0 +1,16 @@
+package com.xcong.excoin.modules.otc.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "HasPayDto", description = "已付款接口接收参数类")
+public class HasPayDto {
+
+    @ApiModelProperty(value = "订单ID", example = "1")
+    private Long id;
+
+    @ApiModelProperty(value = "姓名", example = "张三")
+    private String name;
+}
diff --git a/src/main/java/com/xcong/excoin/modules/otc/service/OtcEntrustOrderService.java b/src/main/java/com/xcong/excoin/modules/otc/service/OtcEntrustOrderService.java
index 3253a14..e007954 100644
--- a/src/main/java/com/xcong/excoin/modules/otc/service/OtcEntrustOrderService.java
+++ b/src/main/java/com/xcong/excoin/modules/otc/service/OtcEntrustOrderService.java
@@ -24,4 +24,5 @@
     void cancelEntrustOrder(Long id);
 
     Result findEntrustOrderDetail(Long id);
+
 }
diff --git a/src/main/java/com/xcong/excoin/modules/otc/service/OtcOrderService.java b/src/main/java/com/xcong/excoin/modules/otc/service/OtcOrderService.java
index c0bb223..34b64bd 100644
--- a/src/main/java/com/xcong/excoin/modules/otc/service/OtcOrderService.java
+++ b/src/main/java/com/xcong/excoin/modules/otc/service/OtcOrderService.java
@@ -2,6 +2,8 @@
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.xcong.excoin.common.response.Result;
+import com.xcong.excoin.modules.otc.dto.HasPayDto;
 import com.xcong.excoin.modules.otc.dto.OrderAddDto;
 import com.xcong.excoin.modules.otc.dto.OrderListDto;
 import com.xcong.excoin.modules.otc.entity.OtcOrder;
@@ -15,7 +17,11 @@
 
     IPage<OrderListVo> findOrderListInPage(OrderListDto orderListDto);
 
-    void hasPay(Long id);
+    void hasPay(HasPayDto hasPayDto);
 
     void finishOrder(Long id);
+
+    Result findBuyOrderDetail(Long id);
+
+    Result findSaleOrderDetail(Long id);
 }
diff --git a/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java b/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java
index 9c3a8c1..f0838ba 100644
--- a/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/otc/service/impl/OtcOrderServiceImpl.java
@@ -8,19 +8,27 @@
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xcong.excoin.common.LoginUserUtils;
 import com.xcong.excoin.common.exception.GlobalException;
+import com.xcong.excoin.common.response.Result;
 import com.xcong.excoin.common.system.service.CommonService;
 import com.xcong.excoin.modules.member.dao.MemberDao;
+import com.xcong.excoin.modules.member.dao.MemberPaymentMethodDao;
 import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
 import com.xcong.excoin.modules.member.entity.MemberEntity;
+import com.xcong.excoin.modules.member.entity.MemberPaymentMethodEntity;
 import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
 import com.xcong.excoin.modules.otc.dao.OtcEntrustOrderDao;
+import com.xcong.excoin.modules.otc.dao.OtcMarketBussinessDao;
+import com.xcong.excoin.modules.otc.dto.HasPayDto;
 import com.xcong.excoin.modules.otc.dto.OrderAddDto;
 import com.xcong.excoin.modules.otc.dto.OrderListDto;
 import com.xcong.excoin.modules.otc.entity.OtcEntrustOrder;
+import com.xcong.excoin.modules.otc.entity.OtcMarketBussiness;
 import com.xcong.excoin.modules.otc.entity.OtcOrder;
 import com.xcong.excoin.modules.otc.dao.OtcOrderDao;
 import com.xcong.excoin.modules.otc.service.OtcOrderService;
+import com.xcong.excoin.modules.otc.vo.BuyOrderDetailVo;
 import com.xcong.excoin.modules.otc.vo.OrderListVo;
+import com.xcong.excoin.modules.otc.vo.SaleOrderDetailVo;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.context.annotation.Bean;
@@ -36,10 +44,13 @@
 @RequiredArgsConstructor
 public class OtcOrderServiceImpl extends ServiceImpl<OtcOrderDao, OtcOrder> implements OtcOrderService {
 
+    private final OtcMarketBussinessDao otcMarketBussinessDao;
     private final OtcEntrustOrderDao otcEntrustOrderDao;
     private final CommonService commonService;
     private final MemberWalletCoinDao memberWalletCoinDao;
     private final MemberDao memberDao;
+    private final MemberPaymentMethodDao memberPaymentMethodDao;
+
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -153,8 +164,9 @@
     }
 
     @Override
-    public void hasPay(Long id) {
-        OtcOrder otcOrder = this.baseMapper.selectById(id);
+    public void hasPay(HasPayDto hasPayDto) {
+        MemberEntity member = LoginUserUtils.getAppLoginUser();
+        OtcOrder otcOrder = this.baseMapper.selectById(hasPayDto.getId());
 
         if (otcOrder == null) {
             throw new GlobalException("订单不存在");
@@ -168,7 +180,12 @@
             throw new GlobalException("不是购买单");
         }
 
-        this.baseMapper.updateOrderStatusByOrderNo(OtcOrder.STATUS_PAY, otcOrder.getOrderNo());
+        if (StrUtil.isBlank(hasPayDto.getName())) {
+            MemberPaymentMethodEntity defualtMethod = memberPaymentMethodDao.selectDefualtMethod(member.getId(), 3, "1");
+            hasPayDto.setName(defualtMethod.getName());
+        }
+
+        this.baseMapper.updateOrderStatusByOrderNo(OtcOrder.STATUS_PAY, hasPayDto.getName(), otcOrder.getOrderNo());
     }
 
     @Override
@@ -200,6 +217,82 @@
         // 出售者钱包冻结减少币
         memberWalletCoinDao.reduceFrozenBalance(saleWallet.getId(), buyOrder.getCoinAmount());
 
-        this.baseMapper.updateOrderStatusByOrderNo(OtcOrder.STATUS_PAY, otcOrder.getOrderNo());
+        this.baseMapper.updateOrderStatusByOrderNo(OtcOrder.STATUS_PAY, null, otcOrder.getOrderNo());
+    }
+
+    @Override
+    public Result findBuyOrderDetail(Long id) {
+        MemberEntity member = LoginUserUtils.getAppLoginUser();
+        member = memberDao.selectById(member.getId());
+        OtcOrder otcOrder = this.baseMapper.selectById(id);
+        if (otcOrder == null) {
+            return Result.fail("订单不存在");
+        }
+
+        OtcOrder buyOrder = this.baseMapper.selectOrderByOrderNoAndType(otcOrder.getOrderNo(), OtcEntrustOrder.ORDER_TYPE_B);
+        if (buyOrder == null) {
+            return Result.fail("参数错误");
+        }
+
+        BuyOrderDetailVo buyDetail = new BuyOrderDetailVo();
+        buyDetail.setOrderNo(buyOrder.getOrderNo());
+        buyDetail.setUsdtAmount(buyOrder.getCoinAmount());
+        buyDetail.setStatus(buyOrder.getStatus());
+        buyDetail.setTotalAmount(buyOrder.getTotalAmount());
+        buyDetail.setUnitPrice(buyOrder.getUnitPrice());
+        buyDetail.setCreateTime(new Date());
+        buyDetail.setIsMb(member.getIsTrader());
+
+        OtcOrder saleOrder = this.baseMapper.selectOrderByOrderNoAndType(otcOrder.getOrderNo(), OtcEntrustOrder.ORDER_TYPE_S);
+        MemberEntity saleMember = memberDao.selectById(saleOrder.getMemberId());
+
+        buyDetail.setSaleName(saleMember.getName());
+        MemberPaymentMethodEntity defaultMethod = memberPaymentMethodDao.selectDefualtMethod(saleOrder.getMemberId(), 3, "1");
+        buyDetail.setBankName(defaultMethod.getName());
+        buyDetail.setBankNo(defaultMethod.getAccount());
+        buyDetail.setPayName(defaultMethod.getName());
+        buyDetail.setPayTime(buyDetail.getPayTime());
+
+        if (!buyOrder.getMemberId().equals(buyOrder.getEntrustMemberId())) {
+            OtcMarketBussiness otcMb = otcMarketBussinessDao.selectMarketBussinessByMemberId(buyOrder.getEntrustMemberId());
+            buyDetail.setMbId(otcMb.getId());
+            buyDetail.setFinishRatio(otcMb.getFinishRatio());
+            buyDetail.setOrderCnt(otcMb.getBuyCnt());
+        }
+
+        return Result.ok(buyDetail);
+    }
+
+    @Override
+    public Result findSaleOrderDetail(Long id) {
+        MemberEntity member = LoginUserUtils.getAppLoginUser();
+        OtcOrder otcOrder = this.baseMapper.selectById(id);
+        if (otcOrder == null) {
+            return Result.fail("订单不存在");
+        }
+
+        OtcOrder saleOrder = this.baseMapper.selectOrderByOrderNoAndType(otcOrder.getOrderNo(), OtcEntrustOrder.ORDER_TYPE_S);
+        if (saleOrder == null) {
+            return Result.fail("参数错误");
+        }
+
+        SaleOrderDetailVo saleDetail = new SaleOrderDetailVo();
+        saleDetail.setOrderNo(saleOrder.getOrderNo());
+        saleDetail.setUsdtAmount(saleOrder.getCoinAmount());
+        saleDetail.setStatus(saleOrder.getStatus());
+        saleDetail.setTotalAmount(saleOrder.getTotalAmount());
+        saleDetail.setUnitPrice(saleOrder.getUnitPrice());
+        saleDetail.setCreateTime(new Date());
+        saleDetail.setIsMb(member.getIsTrader());
+        saleDetail.setPayName(saleOrder.getPayName());
+
+        if (!saleOrder.getMemberId().equals(saleOrder.getEntrustMemberId())) {
+            OtcMarketBussiness otcMb = otcMarketBussinessDao.selectMarketBussinessByMemberId(saleOrder.getEntrustMemberId());
+            saleDetail.setMbId(otcMb.getId());
+            saleDetail.setFinishRatio(otcMb.getFinishRatio());
+            saleDetail.setOrderCnt(otcMb.getBuyCnt());
+        }
+
+        return Result.ok(saleDetail);
     }
 }
diff --git a/src/main/java/com/xcong/excoin/modules/otc/vo/OrderDetailVo.java b/src/main/java/com/xcong/excoin/modules/otc/vo/BuyOrderDetailVo.java
similarity index 86%
rename from src/main/java/com/xcong/excoin/modules/otc/vo/OrderDetailVo.java
rename to src/main/java/com/xcong/excoin/modules/otc/vo/BuyOrderDetailVo.java
index 443034d..43e877d 100644
--- a/src/main/java/com/xcong/excoin/modules/otc/vo/OrderDetailVo.java
+++ b/src/main/java/com/xcong/excoin/modules/otc/vo/BuyOrderDetailVo.java
@@ -11,7 +11,7 @@
 
 @Data
 @ApiModel(value = "OtcOrderDetailVo", description = "otc订单详情")
-public class OrderDetailVo {
+public class BuyOrderDetailVo {
 
     @ApiModelProperty(value = "交易总额")
     private BigDecimal totalAmount;
@@ -53,4 +53,10 @@
 
     @ApiModelProperty(value = "完成率")
     private BigDecimal finishRatio;
+
+    @ApiModelProperty(value = "是否市商 1是 2否")
+    private Integer isMb;
+
+    @ApiModelProperty(value = "订单状态 1-已提交 2-已付款 3-完成")
+    private Integer status;
 }
diff --git a/src/main/java/com/xcong/excoin/modules/otc/vo/OrderDetailVo.java b/src/main/java/com/xcong/excoin/modules/otc/vo/SaleOrderDetailVo.java
similarity index 85%
copy from src/main/java/com/xcong/excoin/modules/otc/vo/OrderDetailVo.java
copy to src/main/java/com/xcong/excoin/modules/otc/vo/SaleOrderDetailVo.java
index 443034d..8175747 100644
--- a/src/main/java/com/xcong/excoin/modules/otc/vo/OrderDetailVo.java
+++ b/src/main/java/com/xcong/excoin/modules/otc/vo/SaleOrderDetailVo.java
@@ -11,7 +11,7 @@
 
 @Data
 @ApiModel(value = "OtcOrderDetailVo", description = "otc订单详情")
-public class OrderDetailVo {
+public class SaleOrderDetailVo {
 
     @ApiModelProperty(value = "交易总额")
     private BigDecimal totalAmount;
@@ -29,11 +29,8 @@
     @ApiModelProperty("下单时间")
     private Date createTime;
 
-    @ApiModelProperty(value = "银行名称")
-    private String bankName;
-
-    @ApiModelProperty(value = "银行卡号")
-    private String bankNo;
+    @ApiModelProperty(value = "订单状态 1-已提交 2-已付款 3-完成")
+    private Integer status;
 
     @ApiModelProperty(value = "姓名")
     private String payName;
@@ -53,4 +50,7 @@
 
     @ApiModelProperty(value = "完成率")
     private BigDecimal finishRatio;
+
+    @ApiModelProperty(value = "是否市商 1是 2否")
+    private Integer isMb;
 }
diff --git a/src/main/resources/mapper/otc/OtcEntrustOrderDao.xml b/src/main/resources/mapper/otc/OtcEntrustOrderDao.xml
index fcfc65c..822c2a1 100644
--- a/src/main/resources/mapper/otc/OtcEntrustOrderDao.xml
+++ b/src/main/resources/mapper/otc/OtcEntrustOrderDao.xml
@@ -24,6 +24,7 @@
                 </if>
             </if>
         </where>
+        order by create_time desc
     </select>
 
     <select id="selectEntrustOrderByOrderType" resultType="com.xcong.excoin.modules.otc.entity.OtcEntrustOrder">
@@ -60,6 +61,7 @@
                 and status == #{record.status}
             </if>
         </where>
+        order by create_time desc
     </select>
 
     <update id="updateRemainAmount">
diff --git a/src/main/resources/mapper/otc/OtcOrderDao.xml b/src/main/resources/mapper/otc/OtcOrderDao.xml
index de07544..d5bb0d4 100644
--- a/src/main/resources/mapper/otc/OtcOrderDao.xml
+++ b/src/main/resources/mapper/otc/OtcOrderDao.xml
@@ -41,6 +41,9 @@
     <update id="updateOrderStatusByOrderNo">
         update otc_order
         set status=#{status}
+        <if test="payName != null and payName != ''">
+            , pay_name = #{payName}
+        </if>
         where order_no=#{orderNo}
     </update>
 

--
Gitblit v1.9.1