|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|