|
@@ -3,7 +3,9 @@ package com.zanxiang.game.module.manage.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.zanxiang.erp.security.util.SecurityUtil;
|
|
|
+import com.zanxiang.game.back.base.pojo.enums.OrderStatusEnum;
|
|
|
import com.zanxiang.game.module.manage.constant.RedisKeyConstant;
|
|
|
+import com.zanxiang.game.module.manage.enums.ExpireTimeEnum;
|
|
|
import com.zanxiang.game.module.manage.enums.KfRoomMsgOwnerEnum;
|
|
|
import com.zanxiang.game.module.manage.enums.KfRoomMsgTypeEnum;
|
|
|
import com.zanxiang.game.module.manage.enums.KfWebSocketMsgEnum;
|
|
@@ -13,6 +15,7 @@ import com.zanxiang.game.module.manage.pojo.dto.PayApplicationDTO;
|
|
|
import com.zanxiang.game.module.manage.service.*;
|
|
|
import com.zanxiang.game.module.manage.service.api.KfWxApiService;
|
|
|
import com.zanxiang.game.module.manage.utils.FileUtil;
|
|
|
+import com.zanxiang.game.module.manage.utils.RedisUtil;
|
|
|
import com.zanxiang.game.module.mybatis.entity.*;
|
|
|
import com.zanxiang.module.oss.service.IOssService;
|
|
|
import com.zanxiang.module.util.JsonUtil;
|
|
@@ -84,6 +87,9 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
|
@Autowired
|
|
|
private IKfRoomMsgService kfRoomMsgService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil<String> redisUtil;
|
|
|
+
|
|
|
@Override
|
|
|
public void appletMsg(String postData) {
|
|
|
log.error("接收到SDK转发的小程序消息, postData : {}", postData);
|
|
@@ -94,10 +100,9 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
|
if (gameApplet == null) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- if (Objects.equals(kfAppletMsgDTO.getMsgType(), KfAppletMsgDTO.MSG_TYPE_EVENT)
|
|
|
- && Objects.equals(kfAppletMsgDTO.getEvent(), KfAppletMsgDTO.EVENT_USER_ENTER_TEMP_SESSION)) {
|
|
|
- this.kfSessionUserUpdateSave(kfAppletMsgDTO, gameApplet);
|
|
|
+
|
|
|
+ if (Objects.equals(kfAppletMsgDTO.getMsgType(), KfAppletMsgDTO.MSG_TYPE_EVENT)) {
|
|
|
+ this.eventMsgHandle(gameApplet, kfAppletMsgDTO);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -109,9 +114,26 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
|
.eq(KfRoom::getOpenId, kfAppletMsgDTO.getFromUserName())
|
|
|
.eq(KfRoom::getGameId, gameApplet.getGameId())
|
|
|
.eq(KfRoom::getOnline, Boolean.TRUE));
|
|
|
-
|
|
|
+
|
|
|
KfWebSocketMsgDTO.MsgContentBean msgContent = this.getMsgContent(kfAppletMsgDTO);
|
|
|
KfRoomMsg kfRoomMsg = this.transform(kfAppletMsgDTO, gameApplet, kfRoom, postData, msgContent);
|
|
|
+
|
|
|
+ String orderId = redisUtil.getCache(RedisKeyConstant.GAME_CUSTOM_PAY + kfAppletMsgDTO.getFromUserName());
|
|
|
+ if (Strings.isNotBlank(orderId) && Objects.equals(kfAppletMsgDTO.getContent(), KfAppletMsgDTO.MSG_CONTENT_PAY)) {
|
|
|
+ Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
|
|
|
+ .eq(Order::getOrderId, orderId)
|
|
|
+ .and(qw -> qw.eq(Order::getStatus, OrderStatusEnum.READY_PAY.getValue())
|
|
|
+ .or().eq(Order::getStatus, OrderStatusEnum.WAIT_PAY.getValue())
|
|
|
+ )
|
|
|
+ );
|
|
|
+ if (order != null) {
|
|
|
+ this.sendCustomPayMessage(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoom, order);
|
|
|
+ kfRoomMsg.setReadStatus(Boolean.TRUE);
|
|
|
+ kfRoomMsgService.save(kfRoomMsg);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
kfRoomMsgService.save(kfRoomMsg);
|
|
|
|
|
|
if (kfRoom == null) {
|
|
@@ -125,6 +147,37 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
|
this.pushMessage(this.transform(kfRoom, gameApplet.getGameId(), kfRoomMsg, msgContent));
|
|
|
}
|
|
|
|
|
|
+ private void eventMsgHandle(GameApplet gameApplet, KfAppletMsgDTO kfAppletMsgDTO) {
|
|
|
+
|
|
|
+ String event = kfAppletMsgDTO.getEvent();
|
|
|
+
|
|
|
+ if (!Objects.equals(event, KfAppletMsgDTO.EVENT_USER_ENTER_TEMP_SESSION)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.kfSessionUserUpdateSave(kfAppletMsgDTO, gameApplet);
|
|
|
+
|
|
|
+ String customPaySign = RedisKeyConstant.GAME_CUSTOM_PAY_SIGN + kfAppletMsgDTO.getFromUserName();
|
|
|
+ String orderId = redisUtil.getCache(customPaySign);
|
|
|
+ if (Strings.isBlank(orderId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
|
|
|
+ .eq(Order::getOrderId, orderId)
|
|
|
+ .and(qw -> qw.eq(Order::getStatus, OrderStatusEnum.READY_PAY.getValue())
|
|
|
+ .or().eq(Order::getStatus, OrderStatusEnum.WAIT_PAY.getValue())
|
|
|
+ )
|
|
|
+ );
|
|
|
+ if (order == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.sendCustomPayMessage(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), null, order);
|
|
|
+ redisUtil.deleteCache(customPaySign);
|
|
|
+ redisUtil.setCache(RedisKeyConstant.GAME_CUSTOM_PAY + kfAppletMsgDTO.getFromUserName(),
|
|
|
+ orderId, ExpireTimeEnum.FIVE_MIN.getTime());
|
|
|
+ }
|
|
|
+
|
|
|
private KfWebSocketMsgDTO transform(KfRoom kfRoom, Long gameId, KfRoomMsg kfRoomMsg, KfWebSocketMsgDTO.MsgContentBean msgContent) {
|
|
|
|
|
|
KfWebSocketMsgEnum kfWebSocketMsgEnum = kfRoom == null ? KfWebSocketMsgEnum.WEBSOCKET_MSG_WAIT_LIST
|
|
@@ -238,7 +291,7 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
|
return this.realmName + "image/" + fileName;
|
|
|
}
|
|
|
|
|
|
- private void sendSystemMessage(Long gameId, String openId, Order order) {
|
|
|
+ private void sendCustomPayMessage(Long gameId, String openId, KfRoom kfRoom, Order order) {
|
|
|
|
|
|
GamePayWay gamePayWay = gamePayWayService.getById(order.getGamePayWayId());
|
|
|
|
|
@@ -265,12 +318,31 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
|
linkMap.put("description", "点我充值" + amount + "元,用于购买" + amount + "元档充值");
|
|
|
linkMap.put("url", url);
|
|
|
linkMap.put("thumb_url", thumbUrl);
|
|
|
-
|
|
|
+
|
|
|
Map<String, Object> msgParamMap = new HashMap<>(3);
|
|
|
msgParamMap.put("touser", openId);
|
|
|
msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_LINK.getValue());
|
|
|
msgParamMap.put(KfRoomMsgTypeEnum.KF_MSG_TYPE_LINK.getValue(), linkMap);
|
|
|
kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
|
|
|
+
|
|
|
+ kfRoomMsgService.save(this.transform(openId, gameId, kfRoom, JsonUtil.toString(msgParamMap)));
|
|
|
+ }
|
|
|
+
|
|
|
+ private KfRoomMsg transform(String openId, Long gameId, KfRoom kfRoom, String msgContent) {
|
|
|
+ return KfRoomMsg.builder()
|
|
|
+ .msgId(UUID.randomUUID().toString().replace("-", ""))
|
|
|
+ .msgType(KfRoomMsgTypeEnum.KF_MSG_TYPE_LINK.getValue())
|
|
|
+ .gameId(gameId)
|
|
|
+ .openId(openId)
|
|
|
+ .readStatus(kfRoom != null)
|
|
|
+ .roomId(kfRoom == null ? null : kfRoom.getId())
|
|
|
+ .kfUserId(kfRoom == null ? null : kfRoom.getKfUserId())
|
|
|
+ .msgOwner(KfRoomMsgOwnerEnum.KF_MSG_OWNER_SYSTEM.getValue())
|
|
|
+ .content(msgContent)
|
|
|
+ .source(msgContent)
|
|
|
+ .createTime(LocalDateTime.now())
|
|
|
+ .updateTime(LocalDateTime.now())
|
|
|
+ .build();
|
|
|
}
|
|
|
|
|
|
|