|
@@ -1,45 +1,41 @@
|
|
package com.wteam.framework.modules.pay.serviceimpl.handler;
|
|
package com.wteam.framework.modules.pay.serviceimpl.handler;
|
|
|
|
|
|
|
|
|
|
-import cn.hutool.http.HttpRequest;
|
|
|
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpResponse;
|
|
import cn.hutool.http.HttpResponse;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
import com.egzosn.pay.common.api.PayMessageHandler;
|
|
import com.egzosn.pay.common.api.PayMessageHandler;
|
|
import com.egzosn.pay.common.api.PayService;
|
|
import com.egzosn.pay.common.api.PayService;
|
|
import com.egzosn.pay.common.bean.PayMessage;
|
|
import com.egzosn.pay.common.bean.PayMessage;
|
|
import com.egzosn.pay.common.bean.PayOutMessage;
|
|
import com.egzosn.pay.common.bean.PayOutMessage;
|
|
import com.egzosn.pay.common.exception.PayErrorException;
|
|
import com.egzosn.pay.common.exception.PayErrorException;
|
|
-
|
|
|
|
import com.wteam.framework.common.enums.CardTypeEnum;
|
|
import com.wteam.framework.common.enums.CardTypeEnum;
|
|
import com.wteam.framework.common.enums.OrderStatus;
|
|
import com.wteam.framework.common.enums.OrderStatus;
|
|
import com.wteam.framework.common.enums.OrderStatusEnum;
|
|
import com.wteam.framework.common.enums.OrderStatusEnum;
|
|
-
|
|
|
|
import com.wteam.framework.common.exception.ServiceException;
|
|
import com.wteam.framework.common.exception.ServiceException;
|
|
-
|
|
|
|
import com.wteam.framework.modules.book.entity.Card;
|
|
import com.wteam.framework.modules.book.entity.Card;
|
|
import com.wteam.framework.modules.book.entity.OrderInfo;
|
|
import com.wteam.framework.modules.book.entity.OrderInfo;
|
|
|
|
+import com.wteam.framework.modules.book.entity.Store;
|
|
import com.wteam.framework.modules.book.mapper.CardMapper;
|
|
import com.wteam.framework.modules.book.mapper.CardMapper;
|
|
import com.wteam.framework.modules.book.mapper.OrderInfoMapper;
|
|
import com.wteam.framework.modules.book.mapper.OrderInfoMapper;
|
|
|
|
+import com.wteam.framework.modules.book.mapper.StoreMapper;
|
|
import com.wteam.framework.modules.book.service.CardService;
|
|
import com.wteam.framework.modules.book.service.CardService;
|
|
-
|
|
|
|
import com.wteam.framework.modules.book.service.OrderInfoService;
|
|
import com.wteam.framework.modules.book.service.OrderInfoService;
|
|
import com.wteam.framework.modules.card.entity.CbCardAdmin;
|
|
import com.wteam.framework.modules.card.entity.CbCardAdmin;
|
|
import com.wteam.framework.modules.card.mapper.CardAdminMapper;
|
|
import com.wteam.framework.modules.card.mapper.CardAdminMapper;
|
|
import com.wteam.framework.modules.hardware.ApiCallerUtil;
|
|
import com.wteam.framework.modules.hardware.ApiCallerUtil;
|
|
|
|
+import com.wteam.framework.modules.hardware.QrCodeRegistrationUtil;
|
|
import com.wteam.framework.modules.user.entity.User;
|
|
import com.wteam.framework.modules.user.entity.User;
|
|
|
|
+import com.wteam.framework.modules.user.mapper.UserMapper;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
-
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-
|
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-
|
|
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
-
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -59,6 +55,10 @@ public class MyPayMessageHandler implements PayMessageHandler {
|
|
private CardMapper cardMapper;
|
|
private CardMapper cardMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private CardAdminMapper cardAdminMapper;
|
|
private CardAdminMapper cardAdminMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserMapper userMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private StoreMapper storeMapper;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 重写这个接口处理支付业务请求
|
|
* 重写这个接口处理支付业务请求
|
|
@@ -77,95 +77,114 @@ public class MyPayMessageHandler implements PayMessageHandler {
|
|
throw new IllegalArgumentException("Invalid payMessage");
|
|
throw new IllegalArgumentException("Invalid payMessage");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //TODO :这里需要的是map集合里面的另外两个参数
|
|
|
|
+
|
|
// 处理支付逻辑
|
|
// 处理支付逻辑
|
|
String outTradeNo = payMessage.getOutTradeNo(); // 获取交易订单号
|
|
String outTradeNo = payMessage.getOutTradeNo(); // 获取交易订单号
|
|
- Number totalFee = payMessage.getTotalFee(); // 获取总费用(可能是一个数字)
|
|
|
|
- String subject = payMessage.getSubject(); // 获取交易主题
|
|
|
|
- String payType = payMessage.getPayType(); // 获取支付类型
|
|
|
|
- String transactionType = payMessage.getTransactionType(); // 获取交易类型
|
|
|
|
log.info("此时的支付订单号为{}", outTradeNo);
|
|
log.info("此时的支付订单号为{}", outTradeNo);
|
|
- log.info("此时的支付总费用为{}", totalFee);
|
|
|
|
- log.info("此时的支付交易主题为{}", subject);
|
|
|
|
- log.info("此时的支付支付类型为{}", payType);
|
|
|
|
- log.info("获取交易类型为{}", transactionType);
|
|
|
|
|
|
+
|
|
|
|
+ Map<String, Object> message = payMessage.getPayMessage();
|
|
|
|
+ // 获取transaction_id
|
|
|
|
+ String transactionId = (String) message.get("transaction_id");
|
|
|
|
+ log.info("此时的transactionId为:{}", transactionId);
|
|
|
|
|
|
// 根据订单ID查询订单信息
|
|
// 根据订单ID查询订单信息
|
|
OrderInfo orderInfo = orderInfoMapper.selectById(outTradeNo);
|
|
OrderInfo orderInfo = orderInfoMapper.selectById(outTradeNo);
|
|
|
|
+ orderInfo.setTransactionId(transactionId);
|
|
log.info("此时的order信息为{}", orderInfo);
|
|
log.info("此时的order信息为{}", orderInfo);
|
|
|
|
|
|
- //如果是超时的情况,单独考虑
|
|
|
|
- Double overPrice = orderInfo.getOverPrice();
|
|
|
|
- if (overPrice != null && overPrice > 0) {
|
|
|
|
- // overPrice 大于 0 表示超时,需要处理超时情况
|
|
|
|
- // 在这里可以执行超时处理的逻辑
|
|
|
|
- //生成一个只能通过一次的二维码
|
|
|
|
- // 获取当前日期
|
|
|
|
- LocalDate currentDate = LocalDate.now();
|
|
|
|
- // 格式化日期为字符串
|
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
|
- String formattedDate = currentDate.format(formatter);
|
|
|
|
- String data = "pxo_" + formattedDate + "_" + orderInfo.getUserId() + "_" + orderInfo.getId() + "_00";
|
|
|
|
- log.info("此时生成的二维码为:{} ", data);
|
|
|
|
- //更新数据库里面此时二维码信息
|
|
|
|
- orderInfo.setQrCode(data);
|
|
|
|
- orderInfoMapper.updateById(orderInfo);
|
|
|
|
- // 注册二维码
|
|
|
|
- // 接口地址和参数
|
|
|
|
- String apiUrl = "https://xiaofeng.pankzone.com/api/openapi/reg_access_qcode.x";
|
|
|
|
- String mac = "863569068849199";
|
|
|
|
- String tk = ApiCallerUtil.callApi();
|
|
|
|
- log.info("此时获取到的token为:{} ", tk);
|
|
|
|
-
|
|
|
|
- //调用hutool接口注册二维码信息
|
|
|
|
- HttpResponse response = HttpRequest.post(apiUrl).form("mac", mac).form("tk", tk).form("qcodetxt", data).form("enablecount", 1).execute();
|
|
|
|
- //获取响应结果
|
|
|
|
- String body = response.body();
|
|
|
|
- // 处理返回结果
|
|
|
|
- JSONObject json = new JSONObject(body);
|
|
|
|
- int code = json.getInt("code");
|
|
|
|
- String qcodetxt = json.getStr("qcodetxt");
|
|
|
|
- log.info("此时返回的qcodetxt为:{}", qcodetxt);
|
|
|
|
- String desc = json.getStr("desc");
|
|
|
|
- log.info("此时返回的desc为:{}", desc);
|
|
|
|
- //对响应结果处理
|
|
|
|
- if (code != 0) {
|
|
|
|
- throw new ServiceException("硬件回调url设置接口异常!");
|
|
|
|
- }
|
|
|
|
- log.info("此时接口响应数据为:{} (不要记录敏感信息在日志中)", body);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (orderInfo != null) {
|
|
|
|
-
|
|
|
|
- //这里根据订单的类型生成不同的二维码注销
|
|
|
|
- String orderType = orderInfo.getOrderType();
|
|
|
|
- /**
|
|
|
|
- * 租场订单-->生成的二维码有时间限制,前5后15,进出次数不限制
|
|
|
|
- * 门票订单-->生成的二维码没有时间限制,任何时候来都可以,但是进出限制2次,一出一进就结束
|
|
|
|
- * 计时订单-->生成的二维码没有时间限制,也是先支付一个小时的钱,支付成功后修改订单状态!
|
|
|
|
- * 月卡订单-->生成的二维码截至时间为月卡结束时间,进出没有限制
|
|
|
|
- * 储值卡订单-->直接完成支付业务逻辑即可
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- switch (orderType) {
|
|
|
|
- case "RENTAL":
|
|
|
|
- // 处理租场订单类型的支付逻辑
|
|
|
|
- return RentalOrder(orderInfo);
|
|
|
|
- case "TICKET":
|
|
|
|
- // 处理门票订单类型的支付逻辑
|
|
|
|
- return TicketOrder(orderInfo);
|
|
|
|
- case "TIMER":
|
|
|
|
- // 处理计时订单类型的支付逻辑
|
|
|
|
- return TimerOrder(orderInfo);
|
|
|
|
- case "MONTHLY":
|
|
|
|
- // 处理月卡订单类型的支付逻辑
|
|
|
|
- return MonthlyOrder(orderInfo);
|
|
|
|
- case "STORED_VALUE":
|
|
|
|
- // 处理卡片订单类型的支付逻辑
|
|
|
|
- return CardOrder(orderInfo);
|
|
|
|
- default:
|
|
|
|
- // 处理未知订单类型的情况
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+// //如果是超时的情况,单独考虑
|
|
|
|
+// Double overPrice = orderInfo.getOverPrice();
|
|
|
|
+// if (overPrice != null && overPrice > 0) {
|
|
|
|
+// // overPrice 大于 0 表示超时,需要处理超时情况
|
|
|
|
+// // 在这里可以执行超时处理的逻辑
|
|
|
|
+// //生成一个只能通过一次的二维码
|
|
|
|
+// // 获取当前日期
|
|
|
|
+// LocalDate currentDate = LocalDate.now();
|
|
|
|
+// //TODO :这里的
|
|
|
|
+//
|
|
|
|
+// String numbers = RandomUtil.randomNumbers(5);
|
|
|
|
+// // 格式化日期为字符串
|
|
|
|
+// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
|
+// String formattedDate = currentDate.format(formatter);
|
|
|
|
+// String data = "pxo_" + formattedDate + "_" + numbers + "_" + orderInfo.getId() + "_00";
|
|
|
|
+// log.info("此时生成的二维码为:{} ", data);
|
|
|
|
+//
|
|
|
|
+// //更新数据库里面此时二维码信息
|
|
|
|
+// orderInfo.setQrCode(data);
|
|
|
|
+// orderInfo.setOrderState(String.valueOf(OrderStatusEnum.IN_USE));
|
|
|
|
+// orderInfoMapper.updateById(orderInfo);
|
|
|
|
+//
|
|
|
|
+// // 注册二维码
|
|
|
|
+// // 接口地址和参数
|
|
|
|
+// String apiUrl = "https://xiaofeng.pankzone.com/api/openapi/reg_access_qcode.x";
|
|
|
|
+// String mac1 = "863569068849199";
|
|
|
|
+// String mac2 = "863569068848969";
|
|
|
|
+// String tk = ApiCallerUtil.callApi(mac1);
|
|
|
|
+// log.info("此时获取到的token为:{} ", tk);
|
|
|
|
+//
|
|
|
|
+// // 拼接两个 MAC 地址,以逗号分隔
|
|
|
|
+// String macParam = mac1 + "_" + mac2;
|
|
|
|
+// log.info("此时拼接的macParam为:{}", macParam);
|
|
|
|
+//
|
|
|
|
+// //调用hutool接口注册二维码信息
|
|
|
|
+// HttpResponse response = HttpRequest.post(apiUrl).form("mac", macParam).form("tk", tk)
|
|
|
|
+// .form("qcodetxt", data)
|
|
|
|
+// .form("enablecount", 1).execute();
|
|
|
|
+//
|
|
|
|
+// //获取响应结果
|
|
|
|
+// String body = response.body();
|
|
|
|
+//
|
|
|
|
+// // 处理返回结果
|
|
|
|
+// JSONObject json = new JSONObject(body);
|
|
|
|
+// int code = json.getInt("code");
|
|
|
|
+// log.info("此时的超时的code为:{}", code);
|
|
|
|
+// String qcodetxt = json.getStr("qcodetxt");
|
|
|
|
+// log.info("此时返回的qcodetxt为:{}", qcodetxt);
|
|
|
|
+// String desc = json.getStr("desc");
|
|
|
|
+// log.info("此时返回的desc为:{}", desc);
|
|
|
|
+//
|
|
|
|
+// //对响应结果处理
|
|
|
|
+// if (code != 0) {
|
|
|
|
+// throw new ServiceException("硬件回调url设置接口异常!");
|
|
|
|
+// }
|
|
|
|
+// log.info("此时接口响应数据为:{} (不要记录敏感信息在日志中)", body);
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ //这里根据订单的类型生成不同的二维码注销
|
|
|
|
+ String orderType = orderInfo.getOrderType();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 租场订单-->生成的二维码有时间限制,前30后30,进出次数不限制
|
|
|
|
+ * 门票订单-->生成的二维码没有时间限制,任何时候来都可以,但是进出限制2次,一出一进就结束
|
|
|
|
+ * 计时订单-->生成的二维码没有时间限制,也是先支付一个小时的钱,支付成功后修改订单状态!
|
|
|
|
+ * 月卡订单-->生成的二维码截至时间为月卡结束时间,进出没有限制
|
|
|
|
+ * 储值卡订单-->直接完成支付业务逻辑即可
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ switch (orderType) {
|
|
|
|
+ case "RENTAL":
|
|
|
|
+ // 处理租场订单类型的支付逻辑
|
|
|
|
+ return RentalOrder(orderInfo);
|
|
|
|
+ case "TICKET":
|
|
|
|
+ // 处理门票订单类型的支付逻辑
|
|
|
|
+ return TicketOrder(orderInfo);
|
|
|
|
+ case "TIMER":
|
|
|
|
+ // 处理计时订单类型的支付逻辑
|
|
|
|
+ return TimerOrder(orderInfo);
|
|
|
|
+ case "MONTHLY":
|
|
|
|
+ // 处理月卡订单类型的支付逻辑
|
|
|
|
+ return MonthlyOrder(orderInfo);
|
|
|
|
+ case "STORED_VALUE":
|
|
|
|
+ // 合并储值卡订单和散客储值卡订单的支付逻辑
|
|
|
|
+ // 处理储值卡订单类型的支付逻辑
|
|
|
|
+ return CardOrder(orderInfo);
|
|
|
|
+ case "PERSON_CARD":
|
|
|
|
+ // 处理散客储值卡订单类型的支付逻辑
|
|
|
|
+ return PersonCardOrder(orderInfo);
|
|
|
|
+ default:
|
|
|
|
+ // 处理未知订单类型的情况
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.info("此时的异常为:{}", e.getMessage());
|
|
log.info("此时的异常为:{}", e.getMessage());
|
|
@@ -173,75 +192,197 @@ public class MyPayMessageHandler implements PayMessageHandler {
|
|
return PayOutMessage.TEXT().content("fail").build();
|
|
return PayOutMessage.TEXT().content("fail").build();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //TODO:散客储值卡购买完成并没有获取到
|
|
|
|
+ private PayOutMessage PersonCardOrder(OrderInfo orderInfo) {
|
|
|
|
+
|
|
|
|
+ // 修改订单支付方式和支付状态
|
|
|
|
+ orderInfo.setPaymentMethods("WECHAT");
|
|
|
|
+ orderInfo.setOrderState(String.valueOf(OrderStatus.PAYMENT_SUCCESSFUL));
|
|
|
|
+ orderInfoMapper.updateById(orderInfo);
|
|
|
|
+
|
|
|
|
+ // 格式化日期为字符串
|
|
|
|
+ // 获取当前日期
|
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
|
+ String formattedDate = currentDate.format(formatter);
|
|
|
|
+
|
|
|
|
+ // 微信购买卡之后支付回调信息
|
|
|
|
+ Integer cardId = orderInfo.getCardId();
|
|
|
|
+ log.info("此时卡id为{}", cardId);
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 可能是储值卡充值也可能是购买储值卡
|
|
|
|
+ */
|
|
|
|
+ // 储值卡充值
|
|
|
|
+ Card card = cardMapper.selectById(cardId);
|
|
|
|
+ log.info("此时卡信息为{}", card);
|
|
|
|
+
|
|
|
|
+ String userId = null;
|
|
|
|
+
|
|
|
|
+ if (card != null) {
|
|
|
|
+ userId = card.getUserId();
|
|
|
|
+ log.info("此时的useId为:{}", userId);
|
|
|
|
+ // 这种情况就证明此时该用户进行的是储值卡充值的操作
|
|
|
|
+ Double orderPrice = orderInfo.getOrderPrice();
|
|
|
|
+ Double currentBalance = card.getCurrentBalance();
|
|
|
|
+ double v = orderPrice + currentBalance;
|
|
|
|
+ log.info("此时的储值卡充值之后的余额为:{}", v);
|
|
|
|
+ card.setCurrentBalance(v);
|
|
|
|
+ cardMapper.updateById(card);
|
|
|
|
+ // 给用户加上累计消费
|
|
|
|
+ // addUserTotalConsumption(orderInfo);
|
|
|
|
+ return PayOutMessage.TEXT().content("success").build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 购买储值卡
|
|
|
|
+ CbCardAdmin cbCardAdmin = cardAdminMapper.selectById(cardId);
|
|
|
|
+
|
|
|
|
+ if (cbCardAdmin != null) {
|
|
|
|
+ Card cardUser = new Card();
|
|
|
|
+
|
|
|
|
+ // 获取余额
|
|
|
|
+ Integer faceValue = cbCardAdmin.getFaceValue();
|
|
|
|
+ cardUser.setCreateTime(new Date());
|
|
|
|
+ cardUser.setCardName(cbCardAdmin.getCardName());
|
|
|
|
+ cardUser.setCardType(cbCardAdmin.getCardType());
|
|
|
|
+ Integer days = cbCardAdmin.getDays();
|
|
|
|
+ cardUser.setDays(days);
|
|
|
|
+ cardUser.setStartDate(formattedDate);
|
|
|
|
+
|
|
|
|
+ // 将天数添加到日期
|
|
|
|
+ LocalDate newDate = currentDate.plusDays(days);
|
|
|
|
+
|
|
|
|
+ // 将新日期格式化为字符串
|
|
|
|
+ String newFormattedDate = newDate.format(formatter);
|
|
|
|
+ cardUser.setEndDate(newFormattedDate);
|
|
|
|
+ cardUser.setFaceValue(faceValue);
|
|
|
|
+ cardUser.setBonusAmount(cbCardAdmin.getBonusAmount());
|
|
|
|
+ cardUser.setCurrentBalance(Double.valueOf(faceValue + cbCardAdmin.getBonusAmount()));
|
|
|
|
+ cardUser.setUserId(orderInfo.getUserId());
|
|
|
|
+ cardUser.setStoreId(9376L);
|
|
|
|
+ cardUser.setDiscountValue(cbCardAdmin.getDiscountValue());
|
|
|
|
+ cardUser.setOrderId(orderInfo.getId());
|
|
|
|
+ log.info("此时的cardUser信息为:{}", cardUser);
|
|
|
|
+ // 给用户加上累计消费
|
|
|
|
+ // addUserTotalConsumption(orderInfo);
|
|
|
|
+ boolean save = cardService.save(cardUser);
|
|
|
|
+
|
|
|
|
+ Integer cardUserId = cardUser.getId();
|
|
|
|
+ orderInfo.setCardId(cardUserId);
|
|
|
|
+ log.info("此时的卡id为:{}", cardUserId);
|
|
|
|
+ orderInfoMapper.updateById(orderInfo);
|
|
|
|
+
|
|
|
|
+ if (save) {
|
|
|
|
+ return PayOutMessage.TEXT().content("success").build();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return PayOutMessage.TEXT().content("fail").build();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * 购买卡之后的支付回调
|
|
|
|
|
|
+ * 购买储值卡之后的支付回调
|
|
*
|
|
*
|
|
* @param orderInfo
|
|
* @param orderInfo
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
|
|
+
|
|
|
|
+//TODO :储值卡不能重复购买 购买前需要先行校验
|
|
private PayOutMessage CardOrder(OrderInfo orderInfo) {
|
|
private PayOutMessage CardOrder(OrderInfo orderInfo) {
|
|
- //修改订单状态
|
|
|
|
|
|
+ //修改订单支付方式和支付状态
|
|
orderInfo.setPaymentMethods("WECHAT");
|
|
orderInfo.setPaymentMethods("WECHAT");
|
|
orderInfo.setOrderState(String.valueOf(OrderStatus.PAYMENT_SUCCESSFUL));
|
|
orderInfo.setOrderState(String.valueOf(OrderStatus.PAYMENT_SUCCESSFUL));
|
|
orderInfoMapper.updateById(orderInfo);
|
|
orderInfoMapper.updateById(orderInfo);
|
|
|
|
+
|
|
// 格式化日期为字符串
|
|
// 格式化日期为字符串
|
|
// 获取当前日期
|
|
// 获取当前日期
|
|
LocalDate currentDate = LocalDate.now();
|
|
LocalDate currentDate = LocalDate.now();
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
String formattedDate = currentDate.format(formatter);
|
|
String formattedDate = currentDate.format(formatter);
|
|
|
|
+
|
|
//微信购买卡之后支付回调信息
|
|
//微信购买卡之后支付回调信息
|
|
Integer cardId = orderInfo.getCardId();
|
|
Integer cardId = orderInfo.getCardId();
|
|
log.info("此时卡id为{}", cardId);
|
|
log.info("此时卡id为{}", cardId);
|
|
- //获取卡信息
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 可能是储值卡充值 也可能是购买储值卡
|
|
|
|
+ */
|
|
|
|
+ //储值卡充值
|
|
Card card = cardMapper.selectById(cardId);
|
|
Card card = cardMapper.selectById(cardId);
|
|
log.info("此时卡信息为{}", card);
|
|
log.info("此时卡信息为{}", card);
|
|
- String userId = card.getUserId();
|
|
|
|
- log.info("此时userId信息为{}", userId);
|
|
|
|
- if (userId != null && !userId.isEmpty()) {
|
|
|
|
- try {
|
|
|
|
- // 这种情况就证明此时该用户进行的是储值卡充值的操作
|
|
|
|
- Double orderPrice = orderInfo.getOrderPrice();
|
|
|
|
- card.setCurrentBalance(orderPrice);
|
|
|
|
- cardMapper.updateById(card);
|
|
|
|
- return PayOutMessage.TEXT().content("success").build();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- // 处理异常,可以记录日志或返回适当的错误信息
|
|
|
|
- e.printStackTrace(); // 这里仅作示例,实际中请根据需求处理异常
|
|
|
|
- return PayOutMessage.TEXT().content("充值失败,请联系客服").build();
|
|
|
|
- }
|
|
|
|
|
|
+ String userId = null;
|
|
|
|
+ if (card != null) {
|
|
|
|
+ userId = card.getUserId();
|
|
|
|
+ log.info("此时的useId为:{}", userId);
|
|
|
|
+ // 这种情况就证明此时该用户进行的是储值卡充值的操作
|
|
|
|
+ Double orderPrice = orderInfo.getOrderPrice();
|
|
|
|
+ Double currentBalance = card.getCurrentBalance();
|
|
|
|
+ double v = orderPrice + currentBalance;
|
|
|
|
+ log.info("此时的储值卡充值之后的余额为:{}", v);
|
|
|
|
+ card.setCurrentBalance(v);
|
|
|
|
+ cardMapper.updateById(card);
|
|
|
|
+ //给用户加上累计消费
|
|
|
|
+// addUserTotalConsumption(orderInfo);
|
|
|
|
+ return PayOutMessage.TEXT().content("success").build();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 购买储值卡
|
|
CbCardAdmin cbCardAdmin = cardAdminMapper.selectById(cardId);
|
|
CbCardAdmin cbCardAdmin = cardAdminMapper.selectById(cardId);
|
|
Card cardUser = new Card();
|
|
Card cardUser = new Card();
|
|
|
|
+
|
|
//获取余额
|
|
//获取余额
|
|
Integer faceValue = cbCardAdmin.getFaceValue();
|
|
Integer faceValue = cbCardAdmin.getFaceValue();
|
|
- cardUser.setCardName(cbCardAdmin.getCardName());
|
|
|
|
- cardUser.setUserId(orderInfo.getUserId());
|
|
|
|
- cardUser.setFaceValue(faceValue);
|
|
|
|
cardUser.setCreateTime(new Date());
|
|
cardUser.setCreateTime(new Date());
|
|
- log.info("当前的余额为:{}", faceValue);
|
|
|
|
|
|
+ cardUser.setCardName(cbCardAdmin.getCardName());
|
|
cardUser.setCardType(cbCardAdmin.getCardType());
|
|
cardUser.setCardType(cbCardAdmin.getCardType());
|
|
- cardUser.setDays(cbCardAdmin.getDays());
|
|
|
|
- cardUser.setStartDate(formattedDate);
|
|
|
|
- cardUser.setCurrentBalance(Double.valueOf(faceValue));
|
|
|
|
cardUser.setUserId(orderInfo.getUserId());
|
|
cardUser.setUserId(orderInfo.getUserId());
|
|
- log.info("此时获取出来的userId为:{}", orderInfo.getUserId());
|
|
|
|
- cardUser.setDiscountValue(cbCardAdmin.getDiscountValue());
|
|
|
|
- Integer days = card.getDays();
|
|
|
|
|
|
+ Integer days = cbCardAdmin.getDays();
|
|
|
|
+ cardUser.setDays(days);
|
|
|
|
+ cardUser.setStartDate(formattedDate);
|
|
|
|
+
|
|
// 将天数添加到日期
|
|
// 将天数添加到日期
|
|
LocalDate newDate = currentDate.plusDays(days);
|
|
LocalDate newDate = currentDate.plusDays(days);
|
|
|
|
+
|
|
// 将新日期格式化为字符串
|
|
// 将新日期格式化为字符串
|
|
String newFormattedDate = newDate.format(formatter);
|
|
String newFormattedDate = newDate.format(formatter);
|
|
cardUser.setEndDate(newFormattedDate);
|
|
cardUser.setEndDate(newFormattedDate);
|
|
- log.info("此时的enddate为:{}", newFormattedDate);
|
|
|
|
|
|
+ cardUser.setFaceValue(faceValue);
|
|
|
|
+ cardUser.setBonusAmount(cbCardAdmin.getBonusAmount());
|
|
|
|
+ cardUser.setCurrentBalance(Double.valueOf(faceValue + cbCardAdmin.getBonusAmount()));
|
|
|
|
+ cardUser.setUserId(orderInfo.getUserId());
|
|
|
|
+ cardUser.setStoreId(9376L);
|
|
|
|
+ cardUser.setDiscountValue(cbCardAdmin.getDiscountValue());
|
|
|
|
+ cardUser.setOrderId(orderInfo.getId());
|
|
log.info("此时的cardUser信息为:{}", cardUser);
|
|
log.info("此时的cardUser信息为:{}", cardUser);
|
|
|
|
+ //给用户加上累计消费
|
|
|
|
+// addUserTotalConsumption(orderInfo);
|
|
boolean save = cardService.save(cardUser);
|
|
boolean save = cardService.save(cardUser);
|
|
|
|
+
|
|
|
|
+ Integer cardUserId = cardUser.getId();
|
|
|
|
+ orderInfo.setCardId(cardUserId);
|
|
|
|
+ log.info("此时的卡id为:{}", cardUserId);
|
|
|
|
+ orderInfoMapper.updateById(orderInfo);
|
|
|
|
+
|
|
if (save) {
|
|
if (save) {
|
|
- return PayOutMessage.TEXT().content("success").build();
|
|
|
|
|
|
+ return PayOutMessage.TEXT()
|
|
|
|
+
|
|
|
|
+ .content("success")
|
|
|
|
+
|
|
|
|
+ .build();
|
|
}
|
|
}
|
|
- return PayOutMessage.TEXT().content("fail").build();
|
|
|
|
|
|
+ return PayOutMessage.TEXT().
|
|
|
|
+
|
|
|
|
+ content("fail").
|
|
|
|
+
|
|
|
|
+ build();
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- private PayOutMessage MonthlyOrder(OrderInfo orderInfo) {
|
|
|
|
|
|
+ //TODO:月卡无法进入
|
|
|
|
+
|
|
|
|
+ private PayOutMessage MonthlyOrder(OrderInfo orderInfo) throws ParseException {
|
|
// 修改订单状态为已支付
|
|
// 修改订单状态为已支付
|
|
orderInfo.setOrderState(String.valueOf(OrderStatus.PAYMENT_SUCCESSFUL));
|
|
orderInfo.setOrderState(String.valueOf(OrderStatus.PAYMENT_SUCCESSFUL));
|
|
log.info("此时的OrderState信息为{}", orderInfo.getOrderState());
|
|
log.info("此时的OrderState信息为{}", orderInfo.getOrderState());
|
|
@@ -252,19 +393,19 @@ public class MyPayMessageHandler implements PayMessageHandler {
|
|
|
|
|
|
orderInfoMapper.updateById(orderInfo);
|
|
orderInfoMapper.updateById(orderInfo);
|
|
|
|
|
|
- //格式转化一下
|
|
|
|
|
|
+// //给用户加上累计消费
|
|
|
|
+// addUserTotalConsumption(orderInfo);
|
|
|
|
+
|
|
|
|
+ // 获得
|
|
String id = orderInfo.getId();
|
|
String id = orderInfo.getId();
|
|
- log.info("转化之后的id为:{}", id);
|
|
|
|
- long l = Long.parseLong(id);
|
|
|
|
- log.info("转化之后的id为:{}", l);
|
|
|
|
|
|
+ log.info("此时的orderId为:{}", id);
|
|
|
|
|
|
//获取卡信息
|
|
//获取卡信息
|
|
Integer cardId = orderInfo.getCardId();
|
|
Integer cardId = orderInfo.getCardId();
|
|
log.info("此时的卡id为:{}", cardId);
|
|
log.info("此时的卡id为:{}", cardId);
|
|
CbCardAdmin card = cardAdminMapper.selectById(cardId);
|
|
CbCardAdmin card = cardAdminMapper.selectById(cardId);
|
|
- log.info("此时的卡信息为:{}", card);
|
|
|
|
- String endDate = card.getEndDate();
|
|
|
|
- log.info("此时的结束时间为{}", endDate);
|
|
|
|
|
|
+ log.info("此时的基础卡信息为:{}", card);
|
|
|
|
+
|
|
|
|
|
|
// 格式化日期为字符串
|
|
// 格式化日期为字符串
|
|
// 获取当前日期
|
|
// 获取当前日期
|
|
@@ -274,117 +415,152 @@ public class MyPayMessageHandler implements PayMessageHandler {
|
|
|
|
|
|
//创建卡信息
|
|
//创建卡信息
|
|
Card cardUser = new Card();
|
|
Card cardUser = new Card();
|
|
- Integer faceValue = card.getFaceValue();
|
|
|
|
- cardUser.setCardName(card.getCardName());
|
|
|
|
- cardUser.setUserId(orderInfo.getUserId());
|
|
|
|
- cardUser.setFaceValue(faceValue);
|
|
|
|
cardUser.setCreateTime(new Date());
|
|
cardUser.setCreateTime(new Date());
|
|
- log.info("当前的余额为:{}", faceValue);
|
|
|
|
|
|
+ cardUser.setCardName(card.getCardName());
|
|
cardUser.setCardType(card.getCardType());
|
|
cardUser.setCardType(card.getCardType());
|
|
- cardUser.setDays(card.getDays());
|
|
|
|
- cardUser.setStartDate(formattedDate);
|
|
|
|
- cardUser.setCurrentBalance(Double.valueOf(faceValue));
|
|
|
|
- cardUser.setUserId(orderInfo.getUserId());
|
|
|
|
- cardUser.setDiscountValue(card.getDiscountValue());
|
|
|
|
Integer days = card.getDays();
|
|
Integer days = card.getDays();
|
|
|
|
+ cardUser.setDays(days);
|
|
|
|
+ cardUser.setStartDate(formattedDate);
|
|
|
|
+
|
|
// 将天数添加到日期
|
|
// 将天数添加到日期
|
|
LocalDate newDate = currentDate.plusDays(days);
|
|
LocalDate newDate = currentDate.plusDays(days);
|
|
|
|
+
|
|
// 将新日期格式化为字符串
|
|
// 将新日期格式化为字符串
|
|
String newFormattedDate = newDate.format(formatter);
|
|
String newFormattedDate = newDate.format(formatter);
|
|
cardUser.setEndDate(newFormattedDate);
|
|
cardUser.setEndDate(newFormattedDate);
|
|
- log.info("此时的enddate为:{}", newFormattedDate);
|
|
|
|
|
|
+ cardUser.setUserId(orderInfo.getUserId());
|
|
|
|
+ cardUser.setStoreId(9376L);
|
|
|
|
+ cardUser.setOrderId(id);
|
|
log.info("此时的cardUser信息为:{}", cardUser);
|
|
log.info("此时的cardUser信息为:{}", cardUser);
|
|
cardService.save(cardUser);
|
|
cardService.save(cardUser);
|
|
|
|
|
|
|
|
+ //将购买的卡存入对应的订单信息
|
|
|
|
+ Integer cardUserId = cardUser.getId();
|
|
|
|
+ orderInfo.setCardId(cardUserId);
|
|
|
|
+ log.info("此时的卡id为:{}", cardUserId);
|
|
|
|
+ orderInfoMapper.updateById(orderInfo);
|
|
|
|
|
|
- //此时的结束时间为卡二维码截至时间
|
|
|
|
- try {
|
|
|
|
- // 获取当前日期
|
|
|
|
- LocalDate currentDate1 = LocalDate.now();
|
|
|
|
- log.info("此时的时间为{}", currentDate);
|
|
|
|
-
|
|
|
|
- // 创建 SimpleDateFormat 对象,指定日期格式
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
- // 将日期字符串解析为 Date 对象
|
|
|
|
- Date date = sdf.parse(endDate);
|
|
|
|
- log.info("此时的date为:{}", date);
|
|
|
|
|
|
+// // 获取当前日期
|
|
|
|
+// LocalDate currentDate1 = LocalDate.now();
|
|
|
|
+// log.info("此时的时间为{}", currentDate1);
|
|
|
|
|
|
- // 将 Date 对象转化为秒级时间戳
|
|
|
|
- // 除以1000以获取秒级时间戳
|
|
|
|
- long timestamp = date.getTime() / 1000;
|
|
|
|
|
|
+ String numbers = RandomUtil.randomNumbers(5);
|
|
|
|
|
|
- // 格式化日期为字符串
|
|
|
|
- DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
|
- String formattedDate1 = currentDate1.format(formatter1);
|
|
|
|
- log.info("此时格式化的日期为:{}", formattedDate);
|
|
|
|
|
|
|
|
- String data = "pxo_" + formattedDate1 + "_" + orderInfo.getUserId() + "_" + l + "_00";
|
|
|
|
- log.info("此时生成的二维码为:{} ", data);
|
|
|
|
- orderInfo.setQrCode(data);
|
|
|
|
- orderInfoService.updateById(orderInfo);
|
|
|
|
|
|
+// // 格式化日期为字符串
|
|
|
|
+// DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
|
+// String formattedDate1 = currentDate1.format(formatter1);
|
|
|
|
+// log.info("此时格式化的日期为:{}", formattedDate);
|
|
|
|
|
|
- // 注册二维码
|
|
|
|
- // 接口地址和参数
|
|
|
|
- String apiUrl = "https://xiaofeng.pankzone.com/api/openapi/reg_access_qcode.x";
|
|
|
|
- String mac = "863569068849199";
|
|
|
|
- String tk = ApiCallerUtil.callApi();
|
|
|
|
- log.info("此时获取到的token为:{} ", tk);
|
|
|
|
|
|
+ String data = "pxo_" + formattedDate + "_" + numbers + "_" + id + "_00";
|
|
|
|
+ log.info("此时生成的二维码为:{} ", data);
|
|
|
|
+ orderInfo.setQrCode(data);
|
|
|
|
+ orderInfoMapper.updateById(orderInfo);
|
|
|
|
|
|
- //使用hutool调用接口
|
|
|
|
- HttpResponse response = HttpRequest.post(apiUrl).form("mac", mac).form("tk", tk).form("qcodetxt", data).form("enabletime", timestamp).form("enablecount", 5000).execute();
|
|
|
|
- //获取响应结果
|
|
|
|
- String body = response.body();
|
|
|
|
- // 处理返回结果
|
|
|
|
- JSONObject json = new JSONObject(body);
|
|
|
|
- int code = json.getInt("code");
|
|
|
|
- String qcodetxt = json.getStr("qcodetxt");
|
|
|
|
- log.info("此时返回的qcodetxt为:{}", qcodetxt);
|
|
|
|
- String desc = json.getStr("desc");
|
|
|
|
- log.info("此时返回的desc为:{}", desc);
|
|
|
|
- //对响应结果处理
|
|
|
|
- if (code != 0) {
|
|
|
|
- throw new ServiceException("硬件回调url设置接口异常!");
|
|
|
|
- }
|
|
|
|
- log.info("此时接口响应数据为:{} (不要记录敏感信息在日志中)", body);
|
|
|
|
- } catch (ParseException e) {
|
|
|
|
- log.info("此时的异常为:{}", e.getMessage());
|
|
|
|
|
|
+// 此时的结束时间为卡二维码截至时间
|
|
|
|
+ // 创建 SimpleDateFormat 对象,指定日期格式
|
|
|
|
+// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+//
|
|
|
|
+// // 将日期字符串解析为 Date 对象
|
|
|
|
+// Date date = sdf.parse(newFormattedDate);
|
|
|
|
+// log.info("此时的date为:{}", date);
|
|
|
|
+//
|
|
|
|
+// // 将 Date 对象转化为秒级时间戳
|
|
|
|
+// // 除以1000以获取秒级时间戳
|
|
|
|
+// long EdTimestamp = date.getTime() / 1000;
|
|
|
|
+//
|
|
|
|
+// // 将时间戳转换为Date对象
|
|
|
|
+// Date endTime = new Date(EdTimestamp * 1000);
|
|
|
|
+// log.info("此时的有效截至时间为:{}", endTime);
|
|
|
|
+//
|
|
|
|
+// // 获取当前时间的时间戳(秒级) 这是的时间戳为月卡的开始有效时间戳
|
|
|
|
+// long StTimestamp = System.currentTimeMillis() / 1000;
|
|
|
|
+// Date StTime = new Date(StTimestamp * 1000);
|
|
|
|
+// log.info("此时的有效开始时间为:{}", StTime);
|
|
|
|
+
|
|
|
|
+// // 注册二维码
|
|
|
|
+// // 接口地址和参数
|
|
|
|
+// String apiUrl = "https://xiaofeng.pankzone.com/api/openapi/reg_access_qcode.x";
|
|
|
|
+// String mac1 = "863569068849199";
|
|
|
|
+// String mac2 = "863569068848969";
|
|
|
|
+// String tk = ApiCallerUtil.callApi(mac2);
|
|
|
|
+// log.info("此时获取到的token为:{} ", tk);
|
|
|
|
+//
|
|
|
|
+// String macParam = mac1 + "_" + mac2;
|
|
|
|
+// log.info("此时拼接的macParam为:{}", macParam);
|
|
|
|
+//
|
|
|
|
+// //使用hutool调用接口
|
|
|
|
+// HttpResponse response = HttpRequest.post(apiUrl)
|
|
|
|
+// .form("mac", macParam)
|
|
|
|
+// .form("tk", tk)
|
|
|
|
+// .form("qcodetxt", data)
|
|
|
|
+//// .form("starttime", StTimestamp)
|
|
|
|
+//// .form("enabletime", EdTimestamp)
|
|
|
|
+// .form("enablecount", 100)
|
|
|
|
+// .execute();
|
|
|
|
+//
|
|
|
|
+// //获取响应结果
|
|
|
|
+// String body = response.body();
|
|
|
|
+// // 处理返回结果
|
|
|
|
+// JSONObject json = new JSONObject(body);
|
|
|
|
+// int code = json.getInt("code");
|
|
|
|
+// log.info("此时返回的code为:{}", code);
|
|
|
|
+// String qcodetxt = json.getStr("qcodetxt");
|
|
|
|
+// log.info("此时返回的qcodetxt为:{}", qcodetxt);
|
|
|
|
+// String desc = json.getStr("desc");
|
|
|
|
+// log.info("此时返回的desc为:{}", desc);
|
|
|
|
+//
|
|
|
|
+// //对响应结果处理
|
|
|
|
+// if (code != 0) {
|
|
|
|
+// throw new ServiceException("硬件回调url设置接口异常!");
|
|
|
|
+// }
|
|
|
|
+// log.info("此时接口响应数据为:{} (不要记录敏感信息在日志中)", body);
|
|
|
|
+// // 返回适当的PayOutMessage
|
|
|
|
+// return PayOutMessage.TEXT().content("success").build();
|
|
|
|
+ Boolean b = QrCodeRegistrationUtil.registerMonthQrCode(data);
|
|
|
|
+ if (b) {
|
|
|
|
+ return PayOutMessage.TEXT().content("success").build();
|
|
}
|
|
}
|
|
- // 返回适当的PayOutMessage
|
|
|
|
- return PayOutMessage.TEXT().
|
|
|
|
|
|
+ return PayOutMessage.TEXT().content("fail").build();
|
|
|
|
+ }
|
|
|
|
|
|
- content("success").
|
|
|
|
|
|
|
|
- build();
|
|
|
|
|
|
+ private PayOutMessage TimerOrder(OrderInfo orderInfo) {
|
|
|
|
+ // 要分为超时的支付情况和正常的支付情况
|
|
|
|
+ // 获取此时的超时金额
|
|
|
|
+ Double overPrice = orderInfo.getOverPrice();
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if (overPrice != null) {
|
|
|
|
|
|
|
|
+ orderInfo.setOrderState(String.valueOf(OrderStatusEnum.IN_USE));
|
|
|
|
+ return PayOutMessage.TEXT().content("success").build();
|
|
|
|
|
|
- private PayOutMessage TimerOrder(OrderInfo orderInfo) {
|
|
|
|
- // 修改订单状态为已支付
|
|
|
|
- orderInfo.setOrderState(String.valueOf(OrderStatus.PAYMENT_SUCCESSFUL));
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 正常的支付情况
|
|
|
|
+ orderInfo.setOrderState(String.valueOf(OrderStatusEnum.IN_USE));
|
|
log.info("此时的OrderState信息为{}", orderInfo.getOrderState());
|
|
log.info("此时的OrderState信息为{}", orderInfo.getOrderState());
|
|
|
|
|
|
// 修改订单支付方式
|
|
// 修改订单支付方式
|
|
orderInfo.setPaymentMethods("WECHAT");
|
|
orderInfo.setPaymentMethods("WECHAT");
|
|
log.info("此时的PaymentMethods信息为{}", orderInfo.getPaymentMethods());
|
|
log.info("此时的PaymentMethods信息为{}", orderInfo.getPaymentMethods());
|
|
|
|
|
|
- orderInfoMapper.updateById(orderInfo);
|
|
|
|
|
|
+ int i = orderInfoMapper.updateById(orderInfo);
|
|
|
|
|
|
- //设置进出时间
|
|
|
|
- orderInfo.setStartTime(new Date());
|
|
|
|
|
|
+// //设置进出时间
|
|
|
|
+// orderInfo.setStartTime(new Date());
|
|
|
|
|
|
- //格式转化一下
|
|
|
|
- String id = orderInfo.getId();
|
|
|
|
- log.info("转化之后的id为:", id);
|
|
|
|
- long l = Long.parseLong(id);
|
|
|
|
- log.info("转化之后的id为:", l);
|
|
|
|
|
|
+// //格式转化一下
|
|
|
|
+// String id = orderInfo.getId();
|
|
|
|
+// log.info("此时获得的订单id为:{}:", id);
|
|
|
|
|
|
- int i = orderInfoMapper.updateById(orderInfo);
|
|
|
|
|
|
+// int i = orderInfoMapper.updateById(orderInfo);
|
|
|
|
|
|
if (i > 0) {
|
|
if (i > 0) {
|
|
return PayOutMessage.TEXT().content("success").build();
|
|
return PayOutMessage.TEXT().content("success").build();
|
|
}
|
|
}
|
|
|
|
+
|
|
// 返回适当的PayOutMessage
|
|
// 返回适当的PayOutMessage
|
|
return PayOutMessage.TEXT().content("fail").build();
|
|
return PayOutMessage.TEXT().content("fail").build();
|
|
}
|
|
}
|
|
@@ -401,65 +577,106 @@ public class MyPayMessageHandler implements PayMessageHandler {
|
|
|
|
|
|
orderInfoMapper.updateById(orderInfo);
|
|
orderInfoMapper.updateById(orderInfo);
|
|
|
|
|
|
|
|
+
|
|
|
|
+ //给用户加上累计消费
|
|
|
|
+// addUserTotalConsumption(orderInfo);
|
|
|
|
+
|
|
|
|
+ //得到此时的cardId
|
|
|
|
+ Integer cardId = orderInfo.getCardId();
|
|
|
|
+ CbCardAdmin cbCardAdmin = cardAdminMapper.selectById(cardId);
|
|
|
|
+ Integer days = cbCardAdmin.getDays();
|
|
|
|
+
|
|
// 获取当前日期
|
|
// 获取当前日期
|
|
LocalDate currentDate = LocalDate.now();
|
|
LocalDate currentDate = LocalDate.now();
|
|
|
|
|
|
//格式转化一下
|
|
//格式转化一下
|
|
String id = orderInfo.getId();
|
|
String id = orderInfo.getId();
|
|
- log.info("转化之后的id为:", id);
|
|
|
|
- long l = Long.parseLong(id);
|
|
|
|
- log.info("转化之后的id为:", l);
|
|
|
|
|
|
+ log.info("此时得到的订单id为:{}:", id);
|
|
|
|
|
|
//创建卡信息
|
|
//创建卡信息
|
|
Card cardUser = new Card();
|
|
Card cardUser = new Card();
|
|
- cardUser.setCardType(String.valueOf(CardTypeEnum.TICKET));
|
|
|
|
- cardUser.setDiscountValue(null);
|
|
|
|
- cardUser.setUserId(orderInfo.getUserId());
|
|
|
|
cardUser.setCreateTime(new Date());
|
|
cardUser.setCreateTime(new Date());
|
|
cardUser.setCardName("篮球次卡");
|
|
cardUser.setCardName("篮球次卡");
|
|
|
|
+ cardUser.setCardType(String.valueOf(CardTypeEnum.TICKET));
|
|
|
|
+ cardUser.setDays(days);
|
|
|
|
+ cardUser.setUserId(orderInfo.getUserId());
|
|
|
|
+ cardUser.setStoreId(9376L);
|
|
|
|
+ cardUser.setDiscountValue(null);
|
|
|
|
+ cardUser.setTimes(cbCardAdmin.getTimes());
|
|
|
|
+ cardUser.setOrderId(id);
|
|
|
|
+ log.info("此时的card信息为:{}", cardUser);
|
|
|
|
+
|
|
|
|
+ //存入数据库
|
|
cardService.save(cardUser);
|
|
cardService.save(cardUser);
|
|
|
|
|
|
|
|
+ //修改订单表里面的对应的卡id
|
|
|
|
+ Integer cardUserId = cardUser.getId();
|
|
|
|
+ orderInfo.setCardId(cardUserId);
|
|
|
|
+ orderInfoMapper.updateById(orderInfo);
|
|
|
|
+ log.info("此时的卡id为:{}", cardUserId);
|
|
|
|
+
|
|
|
|
+ //生成5位随机数字
|
|
|
|
+ String numbers = RandomUtil.randomNumbers(5);
|
|
|
|
|
|
// 格式化日期为字符串
|
|
// 格式化日期为字符串
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
String formattedDate = currentDate.format(formatter);
|
|
String formattedDate = currentDate.format(formatter);
|
|
- String data = "pxo_" + formattedDate + "_" + orderInfo.getUserId() + "_" + l + "_00";
|
|
|
|
|
|
+ String data = "pxo_" + formattedDate + "_" + numbers + "_" + id + "_00";
|
|
log.info("此时生成的二维码为:{} ", data);
|
|
log.info("此时生成的二维码为:{} ", data);
|
|
|
|
|
|
- // 保存入数据库
|
|
|
|
|
|
+ // 二维码保存入数据库
|
|
orderInfo.setQrCode(data);
|
|
orderInfo.setQrCode(data);
|
|
log.info("此时的orderInfo为:{}", orderInfo);
|
|
log.info("此时的orderInfo为:{}", orderInfo);
|
|
- boolean b = orderInfoService.updateById(orderInfo);
|
|
|
|
|
|
+ orderInfoService.updateById(orderInfo);
|
|
|
|
+ Boolean b = QrCodeRegistrationUtil.registerTicketQrCode(data);
|
|
|
|
|
|
if (b) {
|
|
if (b) {
|
|
- // 接口地址和参数
|
|
|
|
- String apiUrl = "https://xiaofeng.pankzone.com/api/openapi/reg_access_qcode.x";
|
|
|
|
- String mac = "863569068849199";
|
|
|
|
- String tk = ApiCallerUtil.callApi();
|
|
|
|
- log.info("此时获取到的token为:{} ", tk);
|
|
|
|
- //使用hutool调用接口
|
|
|
|
- HttpResponse response = HttpRequest.post(apiUrl).form("mac", mac).form("tk", tk).form("qcodetxt", data).form("enablecount", 2).execute();
|
|
|
|
- //获取响应结果
|
|
|
|
- String body = response.body();
|
|
|
|
- // 处理返回结果
|
|
|
|
- JSONObject json = new JSONObject(body);
|
|
|
|
- int code = json.getInt("code");
|
|
|
|
- String qcodetxt = json.getStr("qcodetxt");
|
|
|
|
- log.info("此时返回的qcodetxt为:{}", qcodetxt);
|
|
|
|
- String desc = json.getStr("desc");
|
|
|
|
- log.info("此时返回的desc为:{}", desc);
|
|
|
|
- //对响应结果处理
|
|
|
|
- if (code != 0) {
|
|
|
|
- throw new ServiceException("硬件回调url设置接口异常!");
|
|
|
|
- }
|
|
|
|
- log.info("此时接口响应数据为:{} ", body);
|
|
|
|
|
|
+ // 返回适当的PayOutMessage
|
|
|
|
+ return PayOutMessage.TEXT().content("success").build();
|
|
}
|
|
}
|
|
// 返回适当的PayOutMessage
|
|
// 返回适当的PayOutMessage
|
|
- return PayOutMessage.TEXT().content("success").build();
|
|
|
|
|
|
+ return PayOutMessage.TEXT().content("fail").build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void addUserTotalConsumption(OrderInfo orderInfo) {
|
|
|
|
+ String userId = orderInfo.getUserId();
|
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
|
+
|
|
|
|
+ if (user != null) {
|
|
|
|
+ double newCredit = user.getCredit() + orderInfo.getOrderPrice() + orderInfo.getOverPrice();
|
|
|
|
+ log.info("此时的消费为:{}", newCredit);
|
|
|
|
+ user.setCredit(newCredit);
|
|
|
|
+ userMapper.updateById(user);
|
|
|
|
+ } else {
|
|
|
|
+ log.error("用户不存在,无法更新消费信息。");
|
|
|
|
+ // 可以抛出异常或记录其他错误信息,具体根据需求而定。
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
private PayOutMessage RentalOrder(OrderInfo orderInfo) {
|
|
private PayOutMessage RentalOrder(OrderInfo orderInfo) {
|
|
|
|
+ //这里也要区分是否是超时支付超时的情况
|
|
|
|
+ //如果是补款超时金额的情况 只需要将其订单状态改为已完成订单即可
|
|
|
|
+ if (orderInfo.getOverPrice() != null) {
|
|
|
|
+ orderInfo.setOrderState(String.valueOf(OrderStatusEnum.USED));
|
|
|
|
+ // 获取当前日期
|
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
|
+ //生成随机5位数字
|
|
|
|
+ String numbers1 = RandomUtil.randomNumbers(5);
|
|
|
|
+ String numbers2 = RandomUtil.randomNumbers(5);
|
|
|
|
+ // 格式化日期为字符串
|
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
|
+ String formattedDate = currentDate.format(formatter);
|
|
|
|
+ String data = "pxo_" + formattedDate + "_" + numbers1 + "_" + numbers2 + "_e0";
|
|
|
|
+ String qrCode = QrCodeRegistrationUtil.registerOneQrCode(data);
|
|
|
|
+ log.info("生成的一次核销的二维码为:{}", qrCode);
|
|
|
|
+ orderInfo.setQrCode(qrCode);
|
|
|
|
+ orderInfoMapper.updateById(orderInfo);
|
|
|
|
+
|
|
|
|
+ // 返回适当的PayOutMessage
|
|
|
|
+ return PayOutMessage.TEXT().content("success").build();
|
|
|
|
+ }
|
|
|
|
+
|
|
// 修改订单状态为已支付
|
|
// 修改订单状态为已支付
|
|
orderInfo.setOrderState(String.valueOf(OrderStatusEnum.WAITING_TO_USE));
|
|
orderInfo.setOrderState(String.valueOf(OrderStatusEnum.WAITING_TO_USE));
|
|
log.info("此时的OrderState信息为{}", orderInfo.getOrderState());
|
|
log.info("此时的OrderState信息为{}", orderInfo.getOrderState());
|
|
@@ -468,21 +685,31 @@ public class MyPayMessageHandler implements PayMessageHandler {
|
|
orderInfo.setPaymentMethods("WECHAT");
|
|
orderInfo.setPaymentMethods("WECHAT");
|
|
log.info("此时的PaymentMethods信息为{}", orderInfo.getPaymentMethods());
|
|
log.info("此时的PaymentMethods信息为{}", orderInfo.getPaymentMethods());
|
|
|
|
|
|
|
|
+ Long storeId = orderInfo.getStoreId();
|
|
|
|
+ Store store = storeMapper.selectById(storeId);
|
|
|
|
+ Integer realTime = Integer.valueOf(store.getRealTime());
|
|
|
|
+ realTime = realTime * 2;
|
|
|
|
+ log.info("此时的核销次数为:{}", realTime);
|
|
|
|
+
|
|
orderInfoMapper.updateById(orderInfo);
|
|
orderInfoMapper.updateById(orderInfo);
|
|
|
|
|
|
|
|
+// //给用户加上累计消费
|
|
|
|
+// addUserTotalConsumption(orderInfo);
|
|
|
|
+
|
|
// 获取当前日期
|
|
// 获取当前日期
|
|
LocalDate currentDate = LocalDate.now();
|
|
LocalDate currentDate = LocalDate.now();
|
|
|
|
|
|
//格式转化一下
|
|
//格式转化一下
|
|
String id = orderInfo.getId();
|
|
String id = orderInfo.getId();
|
|
- log.info("转化之后的id为:{}", id);
|
|
|
|
- long l = Long.parseLong(id);
|
|
|
|
- log.info("转化之后的id为:{}", l);
|
|
|
|
|
|
+ log.info("此时获取到的订单id为:{}", id);
|
|
|
|
+
|
|
|
|
+ //生成随机5位数字
|
|
|
|
+ String numbers = RandomUtil.randomNumbers(5);
|
|
|
|
|
|
// 格式化日期为字符串
|
|
// 格式化日期为字符串
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
String formattedDate = currentDate.format(formatter);
|
|
String formattedDate = currentDate.format(formatter);
|
|
- String data = "pxo_" + formattedDate + "_" + orderInfo.getUserId() + "_" + l + "_00";
|
|
|
|
|
|
+ String data = "pxo_" + formattedDate + "_" + numbers + "_" + id + "_00";
|
|
log.info("此时生成的二维码为:{} ", data);
|
|
log.info("此时生成的二维码为:{} ", data);
|
|
|
|
|
|
// 保存入数据库
|
|
// 保存入数据库
|
|
@@ -492,37 +719,58 @@ public class MyPayMessageHandler implements PayMessageHandler {
|
|
if (save > 0) {
|
|
if (save > 0) {
|
|
// 接口地址和参数
|
|
// 接口地址和参数
|
|
String apiUrl = "https://xiaofeng.pankzone.com/api/openapi/reg_access_qcode.x";
|
|
String apiUrl = "https://xiaofeng.pankzone.com/api/openapi/reg_access_qcode.x";
|
|
- String mac = "863569068849199";
|
|
|
|
- String tk = ApiCallerUtil.callApi();
|
|
|
|
|
|
+ String mac1 = "863569068849199";
|
|
|
|
+ String mac2 = "863569068848969";
|
|
|
|
+ String tk = ApiCallerUtil.callApi(mac1);
|
|
log.info("此时获取到的token为:{} ", tk);
|
|
log.info("此时获取到的token为:{} ", tk);
|
|
|
|
+
|
|
//获取订单开始和结束时间
|
|
//获取订单开始和结束时间
|
|
Date orderSt = orderInfo.getOrderSt();
|
|
Date orderSt = orderInfo.getOrderSt();
|
|
Date orderEd = orderInfo.getOrderEd();
|
|
Date orderEd = orderInfo.getOrderEd();
|
|
|
|
+
|
|
// 转化为时间戳
|
|
// 转化为时间戳
|
|
- // 前5后15
|
|
|
|
- // 获取当前时间的时间戳(毫秒级)
|
|
|
|
- long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
|
|
+ // 前30后30
|
|
|
|
+ // 获取当前时间的时间戳(秒级)
|
|
|
|
+// long currentTimeMillis = System.currentTimeMillis() / 1000;
|
|
|
|
+
|
|
|
|
+ // 将订单开始时间前推30分钟并转换为时间戳
|
|
|
|
+ long orderStTimestamp = (orderSt.getTime() / 1000) - (30 * 60);
|
|
|
|
+ log.info("此时的订单开始时间戳为:{}", orderStTimestamp);
|
|
|
|
+ Date stTime = new Date(orderStTimestamp * 1000);
|
|
|
|
+ log.info("订单{}" + "的订单开始时间(二维码有效开始时间)为:{}", id, stTime);
|
|
|
|
+
|
|
|
|
|
|
- // 将订单开始时间前推5分钟并转换为时间戳
|
|
|
|
- long orderStTimestamp = orderSt.getTime() - (5 * 60 * 1000);
|
|
|
|
|
|
+ // 将订单结束时间后推30分钟并转换为时间戳
|
|
|
|
+ long orderEdTimestamp = (orderEd.getTime() / 1000) + (30 * 60);
|
|
|
|
+ log.info("此时的订单结束时间戳为:{}", orderEdTimestamp);
|
|
|
|
+ Date endTime = new Date(orderEdTimestamp * 1000);
|
|
|
|
+ log.info("订单{}" + "的订单结束时间(二维码失效时间)为:{}", id, endTime);
|
|
|
|
|
|
- // 将订单结束时间后推10分钟并转换为时间戳
|
|
|
|
- long orderEdTimestamp = orderEd.getTime() + (10 * 60 * 1000);
|
|
|
|
|
|
+// // 如果需要确保不早于当前时间,可以添加以下逻辑
|
|
|
|
+// orderStTimestamp = Math.max(orderStTimestamp, currentTimeMillis);
|
|
|
|
+// orderEdTimestamp = Math.max(orderEdTimestamp, currentTimeMillis);
|
|
|
|
+
|
|
|
|
+ // 拼接两个 MAC 地址,以逗号分隔
|
|
|
|
+ String macParam = mac1 + "_" + mac2;
|
|
|
|
+ log.info("此时拼接的macParam为:{}", macParam);
|
|
|
|
|
|
- // 如果需要确保不早于当前时间,可以添加以下逻辑
|
|
|
|
- orderStTimestamp = Math.max(orderStTimestamp, currentTimeMillis);
|
|
|
|
- orderEdTimestamp = Math.max(orderEdTimestamp, currentTimeMillis);
|
|
|
|
//使用hutool调用接口
|
|
//使用hutool调用接口
|
|
- HttpResponse response = HttpRequest.post(apiUrl).form("mac", mac).form("tk", tk).form("qcodetxt", data).form("starttime", orderStTimestamp).form("enabletime", orderEdTimestamp).form("enablecount", 100).execute();
|
|
|
|
|
|
+ HttpResponse response = HttpRequest.post(apiUrl).form("mac", macParam).form("tk", tk).form("qcodetxt", data).form("starttime", orderStTimestamp).form("enabletime", orderEdTimestamp).form("enablecount", realTime).execute();
|
|
|
|
+
|
|
//获取响应结果
|
|
//获取响应结果
|
|
String body = response.body();
|
|
String body = response.body();
|
|
|
|
+
|
|
// 处理返回结果
|
|
// 处理返回结果
|
|
JSONObject json = new JSONObject(body);
|
|
JSONObject json = new JSONObject(body);
|
|
int code = json.getInt("code");
|
|
int code = json.getInt("code");
|
|
|
|
+ log.info("此时返回的code为:{}", code);
|
|
|
|
+
|
|
String qcodetxt = json.getStr("qcodetxt");
|
|
String qcodetxt = json.getStr("qcodetxt");
|
|
log.info("此时返回的qcodetxt为:{}", qcodetxt);
|
|
log.info("此时返回的qcodetxt为:{}", qcodetxt);
|
|
|
|
+
|
|
String desc = json.getStr("desc");
|
|
String desc = json.getStr("desc");
|
|
log.info("此时返回的desc为:{}", desc);
|
|
log.info("此时返回的desc为:{}", desc);
|
|
|
|
+
|
|
//对响应结果处理
|
|
//对响应结果处理
|
|
if (code != 0) {
|
|
if (code != 0) {
|
|
throw new ServiceException("硬件回调url设置接口异常!");
|
|
throw new ServiceException("硬件回调url设置接口异常!");
|