Browse Source

扣款和退款操作

qzy 3 weeks ago
parent
commit
53bd5e0458

+ 1 - 1
sp-service/level-one-server/src/main/java/com/pj/tb_order/TbOrder.java

@@ -516,7 +516,7 @@ public class TbOrder extends Model<TbOrder> implements Serializable {
 
 
 	/**
-	 * (一级市场)订单扣款回执状态[0=初始值 1=扣款成功 2=扣款失败]
+	 * (一级市场)订单扣款回执状态[0=初始值 1=扣款成功 2=扣款失败,3=扣款中]
 	 */
 	private Integer Sxb010Status;
 	/**

+ 39 - 19
sp-service/level-one-server/src/main/java/com/pj/tb_order/TbOrderService.java

@@ -448,7 +448,7 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
         StaticLog.info("getPaymentData:{}", JSONUtil.toJsonStr(htTradeSettlement));
         PaymentDto paymentDto = new PaymentDto();
         BeanUtils.copyProperties(htTradeSettlement, paymentDto);
-
+        paymentDto.setId(tbOrder.getId());
         paymentDto.setTradeNo(tbOrder.getTradeNo());
         paymentDto.setCodeTs(tbOrder.getCodeTs());
         paymentDto.setBuyQty(tbOrder.getBuyQty());
@@ -720,11 +720,16 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
      */
     public boolean orderRefund(Long id) {
         TbOrder order = getById(id);
-        if (order.getPeopleConfirmStatus() != 1
-                || order.getSxb010Status() != 1
-                || order.getRefundStatus() != 0
-        )
-            throw new AjaxError("当前订单状态已改变,不可做退款操作,请刷新后操作!");
+        int refundStatus=order.getRefundStatus();
+        if(refundStatus==1||refundStatus==3){
+            StaticLog.error("\n---------退货退款失败:{}已退货退款", id);
+            throw new AjaxError("订单已退款或者退款中");
+        }
+        int sx010Status=order.getSxb010Status();
+        if (sx010Status!=1){
+            StaticLog.error("\n---------退货退款失败:{}银行��边民的款未成功", id);
+            throw new AjaxError("银行扣边民的款未成功");
+        }
 
         PaymentDto paymentDto = this.getPaymentData(order);
         paymentServerInterface.sendSXB013(paymentDto);
@@ -746,23 +751,30 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
         TbOrder tbOrder = getById(id);
         if (tbOrder == null) {
             StaticLog.error("\n---------补扣款失败:{}不存在", id);
-            return false;
+            throw new AjaxError("订单不存在");
         }
-        if (tbOrder.getSxb010Status() == 1) {
-            StaticLog.error("\n---------补扣款失败:{}不存在", id);
-            return false;
+        if (tbOrder.getSxb010Status() == 1 && tbOrder.getRefundStatus() == 0) {
+            StaticLog.error("\n---------补扣款失败:{}已扣款", id);
+            throw new AjaxError("订单已扣款");
+        }
+        if (tbOrder.getSxb010Status() == 3) {
+            StaticLog.error("\n---------补扣款失败:{}退款中", id);
+            throw new AjaxError("订单退款中");
         }
         if (StrUtil.isEmpty(tbOrder.getGoodsNames())) {
             StaticLog.error("\n---------无商品信息:{}", id);
-            return false;
+            throw new AjaxError("订单无商品信息");
         }
-
+        Integer deductionCount = tbOrder.getDeductionCount() + 1;
+        String tradeNo=tbOrder.getTradeNo();
+        tradeNo=StrUtil.subBefore(tradeNo,"_",false);
+        tbOrder.setTradeNo(tradeNo + "_" + deductionCount);
         PaymentDto paymentDto = this.getPaymentData(tbOrder);
         StaticLog.info("\n---订单补扣款---sendSXB010——PaymentDto——:{}", JSONUtil.toJsonStr(paymentDto));
         paymentServerInterface.sendSXB010(paymentDto);
-
-        tbOrder.setDeductionCount(tbOrder.getDeductionCount() + 1);
-        tbOrder.setDeductionTime(new Date());
+        tbOrder.setDeductionCount(deductionCount);
+        tbOrder.setDeductionTime(new Date())
+                .setSxb010Status(3);
 
         return super.updateById(tbOrder);
     }
@@ -774,15 +786,20 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
         LambdaQueryWrapper<TbOrder> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(TbOrder::getVeNo, veNo);
         wrapper.eq(TbOrder::getSaleMainId, id);
-        wrapper.ne(TbOrder::getSxb010Status, 1).orderByDesc(TbOrder::getCreateTime);
+        wrapper.and(i -> i.ne(TbOrder::getSxb010Status, 1).ne(TbOrder::getSxb010Status, 3))
+                .orderByDesc(TbOrder::getCreateTime);
         List<TbOrder> tbOrders = tbOrderMapper.selectList(wrapper);
         if (!tbOrders.isEmpty()) {
             for (TbOrder tbOrder : tbOrders) {
+                Integer deductionCount = tbOrder.getDeductionCount() + 1;
+                String tradeNo=tbOrder.getTradeNo();
+                tradeNo=StrUtil.subBefore(tradeNo,"_",false);
+                tbOrder.setTradeNo(tradeNo + "_" + deductionCount);
                 PaymentDto paymentDto = this.getPaymentData(tbOrder);
                 StaticLog.info("\n---订单补扣款——按车---sendSXB010——PaymentDto——:{}", JSONUtil.toJsonStr(paymentDto));
-                paymentServerInterface.sendSXB010(paymentDto);
+                //paymentServerInterface.sendSXB010(paymentDto);
 
-                tbOrder.setDeductionCount(tbOrder.getDeductionCount() + 1);
+                tbOrder.setDeductionCount(deductionCount);
                 tbOrder.setDeductionTime(new Date());
             }
         }
@@ -866,7 +883,10 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
         if (2 == SXB013Status) {//退款失败
             tbOrder.setRefundStatus(2).setRefundReason(note).setRefundTime(new Date());
         } else if (1 == SXB013Status) {//退款成功
-            tbOrder.setRefundStatus(1).setRefundReason(note).setRefundTime(new Date());
+            tbOrder.setRefundStatus(1)
+                    .setRefundReason(note)
+                    .setSxb010Status(0)
+                    .setRefundTime(new Date());
         }
         return updateById(tbOrder);
     }

+ 4 - 0
sp-service/payment-server/src/main/java/com/pj/bank_info/BankInfo.java

@@ -123,4 +123,8 @@ public class BankInfo extends Model<BankInfo> implements Serializable {
 	private String title;
 	private String swiftCode;
 	private String abroad;
+	/**
+	 * 一级市场订单编号
+	 */
+	private String levelOneOrderId;
 }

+ 89 - 68
sp-service/payment-server/src/main/java/com/pj/bank_info/BankInfoController.java

@@ -3,6 +3,7 @@ package com.pj.bank_info;
 import java.util.ArrayList;
 import java.util.List;
 
+import cn.hutool.core.util.StrUtil;
 import com.pj.api.dto.BankInfoDto;
 import com.pj.utils.so.SoMap;
 import org.springframework.beans.BeanUtils;
@@ -15,81 +16,101 @@ import com.pj.project4sp.SP;
 import cn.dev33.satoken.annotation.SaCheckPermission;
 
 
-
 /**
  * Controller: bank_info -- 银行回执信息表
+ *
  * @author lbl
  */
 @RestController
 @RequestMapping("/BankInfo/")
 public class BankInfoController {
 
-	/** 底层 Service 对象 */
-	@Autowired
-	BankInfoService bankInfoService;
-
-	/** 增 */
-	@RequestMapping("add")
-	@SaCheckPermission(BankInfo.PERMISSION_CODE_ADD)
-	public AjaxJson add(BankInfo b){
-		bankInfoService.add(b);
-		b = bankInfoService.getById(SP.publicMapper.getPrimarykey());
-		return AjaxJson.getSuccessData(b);
-	}
-
-	/** 删 */
-	@RequestMapping("delete")
-	@SaCheckPermission(BankInfo.PERMISSION_CODE_DEL)
-	public AjaxJson delete(Long id){
-		 bankInfoService.delete(id);
-		return AjaxJson.getSuccess();
-	}
-
-	/** 删 - 根据id列表 */
-	@RequestMapping("deleteByIds")
-	@SaCheckPermission(BankInfo.PERMISSION_CODE_DEL)
-	public AjaxJson deleteByIds(){
-		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class);
-		int line = SP.publicMapper.deleteByIds(BankInfo.TABLE_NAME, ids);
-		return AjaxJson.getByLine(line);
-	}
-
-	/** 改 */
-	@RequestMapping("update")
-	@SaCheckPermission(BankInfo.PERMISSION_CODE_EDIT)
-	public AjaxJson update(BankInfo b){
-		bankInfoService.update(b);
-		return AjaxJson.getSuccess();
-	}
-
-	/** 查 - 根据id */
-	@RequestMapping("getById")
-		@SaCheckPermission(BankInfo.PERMISSION_CODE)
-	public AjaxJson getById(Integer id){
-		BankInfo b = bankInfoService.getById(id);
-		return AjaxJson.getSuccessData(b);
-	}
-
-	/** 查集合 - 根据条件(参数为空时代表忽略指定条件) */
-	@RequestMapping("getList")
-	public AjaxJson getList() {
-		SoMap so = SoMap.getRequestSoMap();
-		List<BankInfo> list = bankInfoService.getList(so.startPage());
-		return AjaxJson.getPageData(so.getDataCount(), list);
-	}
-
-	@PostMapping("rpc/getListBySource")
-	public List<BankInfoDto> getListBySource(@RequestParam("source") String source) {
-		SoMap so = new SoMap();
-		so.put("source", source);
-		List<BankInfo> list = bankInfoService.getList(so);
-		List<BankInfoDto> dtoList = new ArrayList<>();
-		list.forEach(item -> {
-			BankInfoDto dto = new BankInfoDto();
-			BeanUtils.copyProperties(item, dto);
-			dtoList.add(dto);
-		});
-		return dtoList;
-	}
+    /**
+     * 底层 Service 对象
+     */
+    @Autowired
+    BankInfoService bankInfoService;
+
+    /**
+     * 增
+     */
+    @RequestMapping("add")
+    @SaCheckPermission(BankInfo.PERMISSION_CODE_ADD)
+    public AjaxJson add(BankInfo b) {
+        bankInfoService.add(b);
+        b = bankInfoService.getById(SP.publicMapper.getPrimarykey());
+        return AjaxJson.getSuccessData(b);
+    }
+
+    /**
+     * 删
+     */
+    @RequestMapping("delete")
+    @SaCheckPermission(BankInfo.PERMISSION_CODE_DEL)
+    public AjaxJson delete(Long id) {
+        bankInfoService.delete(id);
+        return AjaxJson.getSuccess();
+    }
+
+    /**
+     * 删 - 根据id列表
+     */
+    @RequestMapping("deleteByIds")
+    @SaCheckPermission(BankInfo.PERMISSION_CODE_DEL)
+    public AjaxJson deleteByIds() {
+        List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class);
+        int line = SP.publicMapper.deleteByIds(BankInfo.TABLE_NAME, ids);
+        return AjaxJson.getByLine(line);
+    }
+
+    /**
+     * 改
+     */
+    @RequestMapping("update")
+    @SaCheckPermission(BankInfo.PERMISSION_CODE_EDIT)
+    public AjaxJson update(BankInfo b) {
+        bankInfoService.update(b);
+        return AjaxJson.getSuccess();
+    }
+
+    /**
+     * 查 - 根据id
+     */
+    @RequestMapping("getById")
+    @SaCheckPermission(BankInfo.PERMISSION_CODE)
+    public AjaxJson getById(Integer id) {
+        BankInfo b = bankInfoService.getById(id);
+        return AjaxJson.getSuccessData(b);
+    }
+
+    /**
+     * 查集合 - 根据条件(参数为空时代表忽略指定条件)
+     */
+    @RequestMapping("getList")
+    public AjaxJson getList() {
+        SoMap so = SoMap.getRequestSoMap();
+        String source = so.getString("source");
+        if (StrUtil.isNotEmpty(source)) {
+            source = StrUtil.subBefore(source, "_", false);
+            so.put("source", source);
+        }
+        List<BankInfo> list = bankInfoService.getList(so.startPage());
+        return AjaxJson.getPageData(so.getDataCount(), list);
+    }
+
+    @PostMapping("rpc/getListBySource")
+    public List<BankInfoDto> getListBySource(@RequestParam("source") String source) {
+        SoMap so = new SoMap();
+        so.put("source", source);
+        List<BankInfo> list = bankInfoService.getList(so);
+        List<BankInfoDto> dtoList = new ArrayList<>();
+        list.forEach(item -> {
+            BankInfoDto dto = new BankInfoDto();
+            BeanUtils.copyProperties(item, dto);
+            dtoList.add(dto);
+        });
+        return dtoList;
+    }
+
 
 }

+ 2 - 1
sp-service/payment-server/src/main/java/com/pj/bank_info/BankInfoMapper.xml

@@ -29,7 +29,8 @@
 			<if test=' this.has("bankCode") '> and bankCode = #{bankCode} </if>
 			<if test=' this.has("operation") '> and operation = #{operation} </if>
 			<if test=' this.has("code") '> and code = #{code} </if>
-			<if test=' this.has("source") '> and source = #{source} </if>
+			<if test=' this.has("source") '> and source like concat(#{source},'%') </if>
+			<if test=' this.has("levelOneOrderId") '> and level_one_order_id = #{levelOneOrderId} </if>
 			<if test=' this.has("result") '> and result = #{result} </if>
 			<if test=' this.has("note") '> and note = #{note} </if>
 			<if test=' this.has("createTime") '> and create_time = #{createTime} </if>