补单逻辑

master_zzxx
grimm 2024-07-01 17:47:18 +08:00
parent 739b8e3e92
commit 2a1c31613f
6 changed files with 174 additions and 3 deletions

View File

@ -381,6 +381,10 @@ public class RedisKey {
public static final String NEW_ARENA_REFRESH_FIRST_MARK = "NEW_ARENA_REFRESH_FIRST_MARK";//新竞技场第一次匹配标记
// public static final String NEW_ARENA_FIRST_PUSH = "NEW_ARENA_FIRST_PUSH";//竞技场第一名推送标记
// 唯一key生成
public static final String UUID_KEY = "UUID_KEY";//唯一key
// 补单
public static final String ANEW_RECHARGE_ORDER = "ANEW_RECHARGE_ORDER";//补单订单
//进程排行 合区统一
public static Set<String> newAreaCacChe = new HashSet<>();

View File

@ -0,0 +1,24 @@
package com.ljsd.jieling.handler.store;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.store.BuyGoodsNewLogic;
import com.ljsd.jieling.network.session.ISession;
import org.springframework.stereotype.Component;
import rpc.protocols.MessageTypeProto;
import rpc.protocols.PlayerInfoProto;
/**
*
*/
@Component
public class AnewRechargeOrderHandler extends BaseHandler<PlayerInfoProto.AnewRechargeOrderRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.AnewRechargeOrderRequest;
}
@Override
public void processWithProto(ISession iSession, PlayerInfoProto.AnewRechargeOrderRequest proto) throws Exception {
BuyGoodsNewLogic.anewRecharge(iSession);
}
}

View File

@ -0,0 +1,96 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.jieling.util.KeyGenUtils;
import com.ljsd.jieling.util.UUIDEnum;
public class Order {
private String id;
private int uid;
private String sdkGoodsId;
private String openId;
private String orderId;
private long orderTime;
private long amount;
public Order() {
}
public Order(int uid, String sdkGoodsId, String openId, String orderId, long orderTime, long amount) {
this.id = KeyGenUtils.produceIdByModuleNew(UUIDEnum.Recharge, uid);
this.uid = uid;
this.sdkGoodsId = sdkGoodsId;
this.openId = openId;
this.orderId = orderId;
this.orderTime = orderTime;
this.amount = amount;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getSdkGoodsId() {
return sdkGoodsId;
}
public void setSdkGoodsId(String sdkGoodsId) {
this.sdkGoodsId = sdkGoodsId;
}
public String getOpenId() {
return openId;
}
public void setOpenId(String openId) {
this.openId = openId;
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public long getOrderTime() {
return orderTime;
}
public void setOrderTime(long orderTime) {
this.orderTime = orderTime;
}
public long getAmount() {
return amount;
}
public void setAmount(long amount) {
this.amount = amount;
}
@Override
public String toString() {
return "Order{" +
"id='" + id + '\'' +
", uid=" + uid +
", sdkGoodsId='" + sdkGoodsId + '\'' +
", openId='" + openId + '\'' +
", orderId='" + orderId + '\'' +
", orderTime=" + orderTime +
", amount=" + amount +
'}';
}
}

View File

@ -20,6 +20,7 @@ import com.ljsd.jieling.logic.activity.ActivityType;
import com.ljsd.jieling.logic.activity.ActivityTypeEnum;
import com.ljsd.jieling.logic.activity.activityLogic.GmSingleActivityLogic;
import com.ljsd.jieling.logic.activity.event.*;
import com.ljsd.jieling.logic.dao.Order;
import com.ljsd.jieling.logic.dao.PlayerManager;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.VipInfo;
@ -247,8 +248,14 @@ public class BuyGoodsNewLogic {
resultRes.setResultCode(0);
ISession session = OnlineUserManager.getSessionByUid(uid);
if (session == null) {
Order order = new Order(uid, sdkGoodsId, openId, orderId, orderTime, amount);
String key = RedisKey.ANEW_RECHARGE_ORDER + ":" + uid;
RedisUtil.getInstence().putmap(key, order.getId(), order);
RedisUtil.getInstence().expireMills(key, TimeUtils.DAY * 30);
LOGGER.error("sendGoods 玩家不在缓存中,补单信息已放入redis缓存 uid={}order{}",uid, order);
resultRes.setResultCode(1);
resultRes.setResultMsg("Session is null");
LOGGER.error("sendGoods 玩家不在缓存中, uid={}",uid);
return resultRes;
}
if (!StringUtil.isNumeric(sdkGoodsId)){
@ -344,6 +351,29 @@ public class BuyGoodsNewLogic {
return resultRes;
}
/**
*
*/
public static void anewRecharge(ISession session) throws Exception {
String key = RedisKey.ANEW_RECHARGE_ORDER + ":" + session.getUid();
Map<String, Order> orderMap = RedisUtil.getInstence().getmapvaluekeyclass(key, String.class, Order.class);
if (orderMap == null || orderMap.isEmpty()){
return;
}
for (Map.Entry<String, Order> entry : orderMap.entrySet()) {
Order order = entry.getValue();
if (order == null) {
continue;
}
LOGGER.info("补单信息:{}", order);
sendGoods(order.getUid(), order.getSdkGoodsId(), order.getOpenId(), order.getOrderId(), order.getOrderTime(), (int) order.getAmount());
}
RedisUtil.getInstence().del(key);
// PlayerInfoProto.AnewRechargeOrderResponse.Builder builder = PlayerInfoProto.AnewRechargeOrderResponse.newBuilder();
// MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.AnewRechargeOrderResponse_VALUE, builder.build(), true);
}
public static void setFirstRecharge(int uid){
RedisUtil.getInstence().putmap(RedisKey.First_Recharge, String.valueOf(uid), TimeUtils.now());
}

View File

@ -1,5 +1,9 @@
package com.ljsd.jieling.util;
import com.ljsd.GameApplication;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
public class KeyGenUtils {
//机器码
private static String machineNum;
@ -35,15 +39,27 @@ public class KeyGenUtils {
//不是用format仅仅是为了提高效率
if(index < 10){
stringBuffer.append("000");
} else if(index < 100){
}
else if(index < 100){
stringBuffer.append("00");
} else if(index < 1000){
}
else if(index < 1000){
stringBuffer.append("0");
}
stringBuffer.append(index);
return stringBuffer.toString();
}
public synchronized static String produceIdByModuleNew(UUIDEnum uuidEnum, int userId){
StringBuilder stringBuffer = new StringBuilder();
stringBuffer.append(userId);
stringBuffer.append(GameApplication.serverId);
stringBuffer.append(uuidEnum.getValue());
stringBuffer.append(System.currentTimeMillis()/1000);
stringBuffer.append(RedisUtil.getInstence().increment(RedisKey.UUID_KEY));
return stringBuffer.toString();
}
public static void setMachineNum(int machineNum) {
if(machineNum/10 == 0){
KeyGenUtils.machineNum = "0" + machineNum;

View File

@ -19,6 +19,7 @@ public enum UUIDEnum {
FourChallenge(16),//四灵试炼
Faxiang(17),//法相
MagicSoldier(18),//神兵
Recharge(19),//订单
;
private final int value;