You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
381 lines
16 KiB
381 lines
16 KiB
using Sog;
|
|
using ProtoCSStruct;
|
|
|
|
namespace DB
|
|
{
|
|
public static class PayOp
|
|
{
|
|
|
|
public static void OnPayGoogleReq(uint remoteAppID, StructPacket packet, DBOperator dbOperator)
|
|
{
|
|
ref SSPayGoogleReq req = ref packet.GetMessage<SSPayGoogleReq>();
|
|
|
|
int ret = dbOperator.InsertPayReq(ref req) ? 0 : -1;
|
|
TraceLog.Debug("PayOp.OnGooglePayReq uid {0} itemId {1} orderId {2} ret {3}", req.Uid, req.ItemID, req.OrderId, ret);
|
|
|
|
if (ret != 0)
|
|
{
|
|
TraceLog.Error("PayOp.OnGooglePayReq uid {0} itemId {1} orderId {2} DBOperator.InsertPayReq failed"
|
|
, req.Uid, req.ItemID, req.OrderId);
|
|
}
|
|
|
|
SSPayGoogleRes res = new SSPayGoogleRes();
|
|
res.Ret = ret;
|
|
res.Uid = req.Uid;
|
|
res.ItemID = req.ItemID;
|
|
res.OrderId = req.OrderId;
|
|
res.Diamond = req.Diamond;
|
|
res.Money = req.Money;
|
|
res.GmTestPay = req.GmTestPay;
|
|
res.PayType = req.PayType;
|
|
res.HttpCtxId = req.HttpCtxId;
|
|
res.WorldId = req.WorldId;
|
|
res.PaymentId = req.PaymentId;
|
|
res.JsApiPay = req.JsApiPay;
|
|
for (int i = 0; i < req.SelectItems.Count; i++)
|
|
{
|
|
res.SelectItems.Add(ref req.SelectItems[i]);
|
|
}
|
|
res.SessionKey.CopyFrom(ref req.SessionKey);
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.PayGoogleRes, ref res, packet.ObjectID);
|
|
}
|
|
|
|
public static void OnPayGoogleSuccessReq(uint remoteAppID, StructPacket packet, DBOperator dbOperator)
|
|
{
|
|
ref SSPayGoogleSuccessReq req = ref packet.GetMessage<SSPayGoogleSuccessReq>();
|
|
|
|
SSPayGoogleSuccessRes res = new SSPayGoogleSuccessRes
|
|
{
|
|
Ret = -1,
|
|
Uid = req.Uid,
|
|
PayType = req.PayType,
|
|
HttpCtxId = req.HttpCtxId,
|
|
PayParam1 = req.PayParam1,
|
|
PayParam2 = req.PayParam2,
|
|
PayTime3rd = req.PayTime3rd,
|
|
GmTestPay = req.GmTestPay,
|
|
Amount = req.Amount,
|
|
SubPayType = req.SubPayType,
|
|
Sandbox = req.Sandbox,
|
|
};
|
|
res.ItemID = req.ItemID;
|
|
res.OrderId.SetString(req.OrderId.GetPtr());
|
|
res.OrderId3rd.SetString(req.OrderId3rd.GetPtr());
|
|
res.Currency.SetString(req.Currency.GetPtr());
|
|
res.PurchaseToken.SetString(req.PurchaseToken.GetPtr());
|
|
res.CpCustomMsg.SetString(req.CpCustomMsg.GetPtr());
|
|
|
|
tbpay record = dbOperator.SelectPayRecord(req.Uid, req.OrderId.GetString());
|
|
if (record != null && record.ProductID == 0)
|
|
{
|
|
// 正常情况DB中的ProductID不会是0, ProductID是0的肯定是之前的bug导致的
|
|
string[] split = record.OrderID.Split('-');
|
|
int.TryParse(split[4], out int itemId);
|
|
|
|
if (itemId > 0)
|
|
{
|
|
record.ProductID = itemId;
|
|
dbOperator.UpdatePayProductId(req.Uid, req.OrderId.GetString(), itemId);
|
|
}
|
|
}
|
|
|
|
res.Ret = ChecktbRecordOnPayGoogleSuccessReq(record, ref req);
|
|
if (res.Ret != 0)
|
|
{
|
|
TraceLog.Error("PayOp.OnPayGoogleSuccessReq ChecktbRecordOnPayGoogleSuccessReq failed uid {0}, orderid {1} ret {2}"
|
|
, req.Uid, req.OrderId, res.Ret);
|
|
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.PayGoogleSuccessRes, ref res, packet.ObjectID);
|
|
return;
|
|
}
|
|
|
|
TraceLog.Error("PayOp.OnPayGoogleSuccessReq uid {0} orderid {1} status {2} itemid {3} money {4}"
|
|
, req.Uid, req.OrderId, record.Status, record.ProductID, record.Money);
|
|
|
|
// 这段代码应该是要确保OrderID和OrderId3rd是一对一的关系, 目前是由英雄回调通知, 暂时没用了
|
|
//if (req.OrderId3rd.Count > 5)
|
|
//{
|
|
// tbPay record3rd = dbOperator.SelectPayRecordByOrderId3rd(req.OrderId3rd.GetString());
|
|
// if (record3rd != null && record3rd.OrderID != req.OrderId.GetString())
|
|
// {
|
|
// res.Ret = -2;
|
|
// TraceLog.Error("PayOp.OnPayGoogleSuccessReq uid {0}, record3rd {1} already exist, it's orderId is {2}"
|
|
// , req.Uid, req.OrderId3rd, record3rd.OrderID);
|
|
|
|
// DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.PayGoogleSuccessRes, ref res, packet.ObjectID);
|
|
// return;
|
|
// }
|
|
//}
|
|
|
|
|
|
//有可能是1,这是允许的,game那边会判断,不会重复加钻石
|
|
if (record.Status == 0)
|
|
{
|
|
//成功的话更新数据库的状态为1
|
|
TraceLog.Error("PayOp.OnPayGoogleSuccessReq UpdatePayStatus uid {0}, orderid {1} orderId3rd {2}"
|
|
, req.Uid, req.OrderId, res.OrderId3rd);
|
|
|
|
bool bUpdateSuccess = dbOperator.UpdatePayStatus(req.Uid, req.OrderId.GetString(), 1
|
|
, res.OrderId3rd.GetString(), req.PayTime3rd, req.Amount, req.GmTestPay
|
|
, req.Currency.GetString(), req.SubPayType);
|
|
|
|
if (bUpdateSuccess == false)
|
|
{
|
|
res.Ret = -99;
|
|
|
|
TraceLog.Error("PayOp.OnPayGoogleSuccessReq UpdatePayStatus failed uid {0}, orderid {1} orderId3rd {2}"
|
|
, req.Uid, req.OrderId, res.OrderId3rd.GetString());
|
|
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
|
|
(int)SSGameMsgID.PayGoogleSuccessRes, ref res, packet.ObjectID);
|
|
return;
|
|
}
|
|
|
|
record.Status = 1;
|
|
}
|
|
|
|
res.Status = record.Status;
|
|
|
|
TraceLog.Error("PayOp.OnPayGoogleSuccessReq uid {0} orderid {1} amount {2} status {3} succ"
|
|
, req.Uid, req.OrderId, res.Amount, res.Status);
|
|
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.PayGoogleSuccessRes, ref res, packet.ObjectID);
|
|
}
|
|
|
|
private static int ChecktbRecordOnPayGoogleSuccessReq(tbpay record, ref SSPayGoogleSuccessReq req)
|
|
{
|
|
if (record == null)
|
|
{
|
|
TraceLog.Error("PayOp.ChecktbRecordOnPayGoogleSuccessReq failed uid {0}, orderid {1}, no record"
|
|
, req.Uid, req.OrderId);
|
|
return -1;
|
|
}
|
|
|
|
//去掉这个校验,签名成功就行了,实际使用中的确存在这种情况,游客换手机支付,但是是相同的google帐号
|
|
if (record.Uid != req.Uid)
|
|
{
|
|
TraceLog.Error("PayOp.ChecktbRecordOnPayGoogleSuccessReq failed uid {0}, orderid {1}, invalid uid {2}", req.Uid, req.OrderId, record.Uid);
|
|
//return -2;
|
|
}
|
|
|
|
if (record.PayType != req.PayType)
|
|
{
|
|
TraceLog.Error("PayOp.ChecktbRecordOnPayGoogleSuccessReq failed uid {0}, orderid {1}, payType {2} != req.payType {3}"
|
|
, req.Uid, req.OrderId, record.PayType, req.PayType);
|
|
return -4;
|
|
}
|
|
|
|
// 购买物品不一致
|
|
if (req.ItemID != record.ProductID)
|
|
{
|
|
TraceLog.Error("PayOp.ChecktbRecordOnPayGoogleSuccessReq failed uid {0}, orderid {1}, item {2} != req.item {3}"
|
|
, req.Uid, req.OrderId, record.ProductID, req.ItemID);
|
|
return (int)CSErrCode.PayItemIdNotEqual;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
public static void OnPayDBAddDiamondStatusReq(uint remoteAppID, StructPacket packet, DBOperator dbOperator)
|
|
{
|
|
ref SSPayDBAddDiamondStatusReq req = ref packet.GetMessage<SSPayDBAddDiamondStatusReq>();
|
|
long uid = req.Uid;
|
|
|
|
var res = new SSPayDBAddDiamondStatusRes { Uid = uid, Diamond = req.Diamond };
|
|
res.OrderId.SetString(req.OrderId.GetPtr());
|
|
|
|
tbpay record = dbOperator.SelectPayRecord(req.Uid, req.OrderId.GetString());
|
|
//按理说不可能为空
|
|
if (record == null)
|
|
{
|
|
TraceLog.Error("PayOp.OnPayDBAddDiamondStatusReq uid {0} orderId {1} not in DB", uid, req.OrderId);
|
|
res.Ret = -1;
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.PayDbAddDiamondStatusRes, ref res, uid);
|
|
return;
|
|
}
|
|
|
|
TraceLog.Debug("PayOp.OnPayDBAddDiamondStatusReq uid {0} orderId {1} status {2} select item num {3}"
|
|
, uid, req.OrderId, record.Status, record.ExData.PlayerSelectItem.Count);
|
|
|
|
for (int i = 0; i < record.ExData.PlayerSelectItem.Count; i++)
|
|
{
|
|
if (res.SelectItems.Count < res.SelectItems.GetMaxCount())
|
|
{
|
|
res.SelectItems.Add(ref record.ExData.PlayerSelectItem[i]);
|
|
}
|
|
}
|
|
|
|
//按理说不可能为0和2,但是继续,也许是gamesvr回档了或者数据库回档?
|
|
if (record.Status == 0 || record.Status == 2)
|
|
{
|
|
TraceLog.Error("PayOp.OnPayDBAddDiamondStatusReq uid {0} orderId {1} status {2}, should be 1"
|
|
, uid, req.OrderId, record.Status);
|
|
}
|
|
|
|
res.Status = record.Status;
|
|
|
|
// 已经添加钻石
|
|
if (record.Status == 2)
|
|
{
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.PayDbAddDiamondStatusRes, ref res, uid);
|
|
return;
|
|
}
|
|
|
|
// 更新数据库状态为2, 实际添加的钻石数量
|
|
bool bUpdateSuccess = dbOperator.UpdatePayStatus(req.Uid, req.OrderId.GetString(), 2, req.AmountExchange, req.DiamondExchange, req.ReplaceItemId, req.Money);
|
|
|
|
if (bUpdateSuccess == false)
|
|
{
|
|
TraceLog.Error("PayOp.OnPayDBAddDiamondStatusReq UpdatePayStatus failed, uid {0} orderid {1}", uid, req.OrderId);
|
|
|
|
res.Ret = -1;
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.PayDbAddDiamondStatusRes, ref res, uid);
|
|
return;
|
|
}
|
|
|
|
TraceLog.Debug("PayOp.OnPayDBAddDiamondStatusReq uid {0} orderId {1} diamond {2} succ"
|
|
, uid, req.OrderId, req.Diamond);
|
|
|
|
res.Status = 2;
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.PayDbAddDiamondStatusRes, ref res, uid);
|
|
}
|
|
|
|
|
|
public static void OnQueryPayGoogleSuccOrder(uint remoteAppID, StructPacket packet, DBOperator dbOperator)
|
|
{
|
|
ref SSQueryPayGoogleSuccOrder query = ref packet.GetMessage<SSQueryPayGoogleSuccOrder>();
|
|
long uid = query.Uid;
|
|
|
|
var paySuccList = dbOperator.SelectPaySuccRecord(uid);
|
|
if (paySuccList == null || paySuccList.Count == 0)
|
|
{
|
|
TraceLog.Trace("PayOp.OnQueryPayGoogleSuccOrder uid {0} no pay succ record", uid);
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < paySuccList.Count; i++)
|
|
{
|
|
tbpay pay = paySuccList[i];
|
|
|
|
SSPayGoogleSuccessRes res = new SSPayGoogleSuccessRes
|
|
{
|
|
Uid = uid,
|
|
Amount = (uint)pay.Amount,
|
|
PayType = (uint)pay.PayType,
|
|
SubPayType = pay.SubPayType,
|
|
Status = pay.Status,
|
|
HttpCtxId = 0,
|
|
PayTime3rd = pay.PayTime3rd,
|
|
GmTestPay = pay.IsTestPay == 1,
|
|
};
|
|
res.ItemID = pay.ProductID;
|
|
res.OrderId.SetString(pay.OrderID);
|
|
res.OrderId3rd.SetString(pay.OrderId3rd);
|
|
res.Currency.SetString(pay.Currency);
|
|
|
|
var str = res.OrderId.GetString();
|
|
var arr = str.Split('-');
|
|
if (arr.Length >= 7)
|
|
{
|
|
int.TryParse(arr[5], out res.PayParam1);
|
|
int.TryParse(arr[6], out res.PayParam2);
|
|
}
|
|
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.PayGoogleSuccessRes, ref res, uid);
|
|
}
|
|
}
|
|
|
|
|
|
public static void OnGmQueryUserPayRecordReq(uint remoteAppID, StructPacket packet, DBOperator dbOperator)
|
|
{
|
|
ref SSGmQueryUserPayRecordReq req = ref packet.GetMessage<SSGmQueryUserPayRecordReq>();
|
|
|
|
long uid = packet.ObjectID;
|
|
|
|
TraceLog.Debug("PayOp.OnGmQueryUserPayRecordReq uid {0}", uid);
|
|
|
|
|
|
SSGmQueryUserPayRecordRes res = new SSGmQueryUserPayRecordRes();
|
|
//最大页大小限制 防止超出
|
|
if (req.Pagesize> res.Records.GetMaxCount())
|
|
{
|
|
req.Pagesize = res.Records.GetMaxCount();
|
|
}
|
|
|
|
var recordList = dbOperator.SelectAllPayRecords(req);
|
|
TraceLog.Debug("PayOp.OnGmQueryUserPayRecordReq uid {0}, count {1}"
|
|
, uid, recordList.Item2);
|
|
|
|
|
|
res.Id = req.Guid;
|
|
res.PageTotal = (ulong)recordList.Item1;
|
|
foreach (var record in recordList.Item2)
|
|
{
|
|
res.Records.Add(record);
|
|
}
|
|
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID,
|
|
(int)SSGameMsgID.GmQueryUserPayRecordRes, ref res, packet.ObjectID, packet.ServerID);
|
|
}
|
|
|
|
public static void OnPaySendDBRefundReq(uint remoteAppID, StructPacket packet, DBOperator dbOperator)
|
|
{
|
|
ref var req = ref packet.GetMessage<SSPaySendDBRefundReq>();
|
|
|
|
SSPaySendDBRefundRes res = new SSPaySendDBRefundRes
|
|
{
|
|
Uid = req.Uid,
|
|
HttpCtxId = req.HttpCtxId,
|
|
RefundTime = req.RefundTime
|
|
};
|
|
res.OrderId.SetString(req.OrderId.GetPtr());
|
|
res.OrderId3rd.SetString(req.OrderId3rd.GetPtr());
|
|
|
|
if (!dbOperator.SetRefundTime(req.Uid, req.OrderId.GetString(), req.OrderId3rd.GetString(), req.RefundTime))
|
|
{
|
|
res.Ret = -1;
|
|
}
|
|
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.PaySendDbRefundRes, ref res, packet.ObjectID);
|
|
}
|
|
|
|
public static void OnSaveHttpContentReq(uint remoteAppID, StructPacket packet, DBOperator dbOperator)
|
|
{
|
|
ref var req = ref packet.GetMessage<SSPayHeroSaveHttpContentReq>();
|
|
|
|
if (dbOperator.ReplacePayHttpContent(ref req))
|
|
{
|
|
string orderId = req.Http.OrderId.GetString();
|
|
|
|
var res = new SSPayHeroSaveHttpContentRes();
|
|
res.Http.Uid = req.Http.Uid;
|
|
res.Http.Method = req.Http.Method;
|
|
res.Http.Content.SetString(req.Http.Content.GetPtr());
|
|
res.Http.Url.SetString(req.Http.Url.GetPtr());
|
|
res.Http.OrderId.SetString(orderId);
|
|
res.Http.IsTestPay = req.Http.IsTestPay;
|
|
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.PayHeroSaveHttpContentRes, ref res, req.Http.Uid);
|
|
}
|
|
}
|
|
|
|
public static void OnSelectHttpContentReq(uint remoteAppID, StructPacket packet, DBOperator dbOperator)
|
|
{
|
|
var res = new SSPayHeroSelectHttpContentRes();
|
|
dbOperator.SelectPayHttpContent(ref res);
|
|
|
|
TraceLog.Trace("PayOp.OnSelectHttpContentReq http count {0}", res.Http.Count);
|
|
if (res.Http.Count > 0)
|
|
{
|
|
DBServerUtils.GetPacketSender().SendToServerByID(remoteAppID, (int)SSGameMsgID.PayHeroSelectHttpContentRes, ref res, 0);
|
|
}
|
|
}
|
|
|
|
public static void OnDeleteHttpContentNotify(uint remoteAppID, StructPacket packet, DBOperator dbOperator)
|
|
{
|
|
ref var notify = ref packet.GetMessage<SSPayHeroDeleteHttpContentNotify>();
|
|
dbOperator.DeletePayHttpContent(ref notify);
|
|
}
|
|
}
|
|
}
|
|
|