Browse Source

分帐接口

花田厝 3 months ago
parent
commit
0a8f960920

+ 85 - 0
jsjp-admin/src/main/java/com/miaxis/pc/PcOrderInfoController.java

@@ -21,6 +21,7 @@ import io.swagger.annotations.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -182,4 +183,88 @@ public class PcOrderInfoController extends BaseController{
     }
 
 
+    /**
+     * 发起分账
+     */
+    @PutMapping(value = "/shareProfit/{outTradeNo}")
+    @ApiOperation("发起分账")
+    public Response<OrderInfo> shareProfit(
+            @ApiParam(name = "outTradeNo", value = "商户订单信息", required = true)
+            @PathVariable("outTradeNo") String outTradeNo) throws Exception {
+        OrderInfo orderInfo = orderInfoService.getByOutTradeNo(outTradeNo);
+
+        if (orderInfo.getTradeType() != 1) {
+            Response response = new Response(400, "非支付成功的订单,无法分账。");
+            return response;
+        }
+        if (orderInfo.getIsFz() != 1 || orderInfo.getIsFz() != 3) {
+            Response response = new Response(400, "非待分账订单,无法分账。");
+            return response;
+        }
+
+        // 获取当前时间
+        Date currentDate = new Date();
+        // 添加5分钟
+        long fiveMinutesInMillis = 2 * 60 * 1000; // 1分钟的毫秒数
+        Date nowDate = new Date(currentDate.getTime() - fiveMinutesInMillis);
+
+        if (nowDate.compareTo(orderInfo.getSuccessTime()) < 0) {
+            Response response = new Response(400, "支付成功的订单,未满2分钟无法分账,请稍后操作。");
+            return response;
+        }
+
+        boolean addFlag = orderInfoService.wxAddFenZhang(orderInfo);
+        boolean flag = orderInfoService.wxProfitsharing(orderInfo);
+        if (flag && addFlag) {
+            Response response = new Response(200, "分账成功");
+            return response;
+        } else {
+            Response response = new Response(400, "分账失败,请联系管理员");
+            return response;
+        }
+
+    }
+
+
+    /**
+     * 批量分账
+     */
+    @PutMapping(value = "/shareProfitBatch/{ids}")
+    @ApiOperation("批量分账")
+    public Response<String> doExtractError(
+            @ApiParam(name = "ids", value = "订单ID", required = true)
+            @PathVariable("ids") Long[] ids
+    ) throws Exception {
+
+        List<OrderInfo> orderInfoList = orderInfoService.getOrderInfoByIds(ids);
+        int s = 0;
+        int f = 0;
+        int z = 0;
+
+        for (int i = 0; i < orderInfoList.size(); i++) {
+            OrderInfo orderInfo = orderInfoList.get(i);
+
+            // 获取当前时间
+            Date currentDate = new Date();
+            // 添加2分钟
+            long fiveMinutesInMillis = 2 * 60 * 1000; // 1分钟的毫秒数
+            Date nowDate = new Date(currentDate.getTime() - fiveMinutesInMillis); //当前时间减掉2分钟
+            if (nowDate.compareTo(orderInfo.getSuccessTime()) < 0) {   //当前时间如果还小于 支付成功时间就不能分账
+                z++;
+                continue;
+            }
+
+            boolean addFlag = orderInfoService.wxAddFenZhang(orderInfo);
+            boolean flag = orderInfoService.wxProfitsharing(orderInfo);
+            if (flag && addFlag) {
+                s++;
+            } else {
+                f++;
+            }
+        }
+        Response response = new Response(200, "分账成功"+s+"条,分账失败"+f+"条,分账时间不足"+z+"条,总计"+orderInfoList.size()+"条。");
+        return response;
+    }
+
+
 }

+ 1 - 1
jsjp-service/src/main/java/com/miaxis/order/domain/OrderInfo.java

@@ -146,7 +146,7 @@ public class OrderInfo extends BaseBusinessEntity{
     /** 是否状态 0不分账 1未分账 2分账成功 3分账失败 */
     @Excel(name = "是否状态 0不分账 1未分账 2分账成功 3分账失败")
     @TableField("is_fz")
-    @ApiModelProperty(value = "是否状态 0不分账 1未分账 2分账成功 3分账失败")
+    @ApiModelProperty(value = "是否状态 0不分账 1未分账 2分账成功 3分账失败 4分账回退")
     private Integer isFz;
 
 

+ 2 - 0
jsjp-service/src/main/java/com/miaxis/order/mapper/OrderInfoMapper.java

@@ -43,4 +43,6 @@ public interface OrderInfoMapper extends BaseMapper<OrderInfo> {
     List<OrderInfo> selectOrderInfoByWaitProfit();
 
     Integer getFzMoney(QuerySchoolOrderListDTO orderInfo);
+
+    List<OrderInfo> getOrderInfoByIds(Long[] ids);
 }

+ 2 - 0
jsjp-service/src/main/java/com/miaxis/order/service/IOrderInfoService.java

@@ -63,4 +63,6 @@ public interface IOrderInfoService extends IService<OrderInfo> {
 
     @Transactional
     boolean wxProfitsharingRetrun(OrderInfo orderInfo, OrderSplit orderSplit) throws Exception;
+
+    List<OrderInfo> getOrderInfoByIds(Long[] ids);
 }

+ 9 - 0
jsjp-service/src/main/java/com/miaxis/order/service/impl/OrderInfoServiceImpl.java

@@ -2346,6 +2346,9 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
             return false;
         } else {
             //更新成交订单表
+            orderInfo.setIsFz(4); //分账退回
+            this.updateById(orderInfo);
+
             String returnNo = resMap.get("return_no");
             orderSplit.setStatus(2); //分账回退成功
             orderSplit.setOutReturnNo(outReturnNo);
@@ -2358,4 +2361,10 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
 
 
 
+    @Override
+    public List<OrderInfo> getOrderInfoByIds(Long[] ids) {
+        return orderInfoMapper.getOrderInfoByIds(ids);
+    }
+
+
 }

+ 11 - 0
jsjp-service/src/main/resources/mapper/order/OrderInfoMapper.xml

@@ -358,4 +358,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ORDER BY success_time;
     </select>
 
+
+    <select id="getOrderInfoByIds" parameterType="Long" resultType="com.miaxis.order.domain.OrderInfo">
+        select * from order_info
+        <where>
+            id in
+            <foreach collection="array" item="id" index="index" open="(" close=")"  separator=","  >
+                #{id}
+            </foreach>
+        </where>
+    </select>
+
 </mapper>