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.
277 lines
9.3 KiB
277 lines
9.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Threading.Tasks;
|
|
|
|
using Sog;
|
|
using ProtoCSStruct;
|
|
|
|
namespace Game
|
|
{
|
|
public static class PlayerPayUtil
|
|
{
|
|
// 返回剩余天数时向下取整, 例如剩余0天23小时, 会返回0天
|
|
// 返回0天不代表月卡已经到期, 月卡到期要用nowSec >= ExpireTime判断
|
|
public static int GetMonthlyCardRemainDays(PlayerOnGame player, int cardId)
|
|
{
|
|
for (int i = 0; i < player.RoleData.PayData.MonthlyCard.Count; i++)
|
|
{
|
|
ref var cardData = ref player.RoleData.PayData.MonthlyCard[i];
|
|
if (cardData.CardId == cardId)
|
|
{
|
|
long nowSec = GameServerUtils.GetTimeSecond();
|
|
if (cardData.ExpireTime <= nowSec)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
return AppTime.GetDayElapse(cardData.ExpireTime, nowSec);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
public static PayType GetPlayerPayType(PlayerOnGame player)
|
|
{
|
|
// 英雄支付, 和安卓谷歌支付不同之处就是由英雄的SDK服务器通知支付成功
|
|
if (player.AccountInfo.AccountType == (int)AccountType.AccountType_Huawei)
|
|
{
|
|
return PayType.Huawei;
|
|
}
|
|
if (player.AccountInfo.AccountType == (int)AccountType.AccountType_WXMini)
|
|
{
|
|
return PayType.MiniPay;
|
|
}
|
|
// 缺省是英雄
|
|
return PayType.Hero;
|
|
}
|
|
|
|
//此道具第一次支付
|
|
public static bool IsFirstPayThisItem(PlayerOnGame player, PayDiamondDesc desc)
|
|
{
|
|
//有折扣的要加上算正常的那个
|
|
for (int i = 0; i < player.RoleData.PayData.PayItemRecord.Count; i++)
|
|
{
|
|
ref var record = ref player.RoleData.PayData.PayItemRecord[i];
|
|
if (record.ItemId == desc.itemID && record.PaySuccessCount > 1)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//首次支付
|
|
public static bool IsFirstPayUser(PlayerOnGame player)
|
|
{
|
|
return player.RoleData.PayData.TotalPayMoney == 0;
|
|
}
|
|
|
|
public static void ResetPaySuccessCount(PlayerOnGame player, string itemId, int itemEndTime)
|
|
{
|
|
for (int i = 0; i < player.RoleData.PayData.PayItemRecord.Count; i++)
|
|
{
|
|
ref var record = ref player.RoleData.PayData.PayItemRecord[i];
|
|
if (record.ItemId.Equals(itemId))
|
|
{
|
|
record.PaySuccessCount = 0;
|
|
record.PayCountToday = 0;
|
|
record.PayCountWeek = 0;
|
|
record.PayCountMonth = 0;
|
|
record.LastUpdateRecordTime = (int)GameServerUtils.GetTimeSecond();
|
|
// -1表示不设置
|
|
if (itemEndTime != -1)
|
|
{
|
|
record.EndTime = itemEndTime;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static int GetPaySuccessRecordIndex(PlayerOnGame player, int payitemid)
|
|
{
|
|
for (int i = 0; i < player.RoleData.PayData.PayItemRecord.Count; i++)
|
|
{
|
|
ref var record = ref player.RoleData.PayData.PayItemRecord[i];
|
|
if (record.ItemId.Equals(payitemid))
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
public static ref DBRolePayItemRecord GetPayItemRecordByIndex(PlayerOnGame player, int index)
|
|
{
|
|
return ref player.RoleData.PayData.PayItemRecord[index];
|
|
}
|
|
|
|
// 数据接口, 不要在里面写插入数据之外的逻辑
|
|
public static int AddPaySuccRecordIfNotExist(PlayerOnGame player, PayDiamondDesc desc)
|
|
{
|
|
// 使用itemId作为key效率非常低!!!
|
|
for (int i = 0; i < player.RoleData.PayData.PayItemRecord.Count; i++)
|
|
{
|
|
ref var record = ref player.RoleData.PayData.PayItemRecord[i];
|
|
if (record.ItemId.Equals(desc.itemID))
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
int index = -1;
|
|
if (player.RoleData.PayData.PayItemRecord.Count < player.RoleData.PayData.PayItemRecord.GetMaxCount())
|
|
{
|
|
DBRolePayItemRecord record = new DBRolePayItemRecord { };
|
|
record.LastUpdateRecordTime = (int)GameServerUtils.GetTimeSecond();
|
|
record.ItemId = desc.itemID;
|
|
|
|
|
|
player.RoleData.PayData.PayItemRecord.Add(ref record);
|
|
player.MakeDirty();
|
|
|
|
index = player.RoleData.PayData.PayItemRecord.Count - 1;
|
|
player.Debug("PlayerPayUtil.AddPaySuccRecordIfNotExist uid {0} itemId {1} index {2} succ"
|
|
, player.UserID, desc.itemID, index);
|
|
}
|
|
|
|
return index;
|
|
}
|
|
|
|
public static int GetTotalPaySuccessCount(PlayerOnGame player)
|
|
{
|
|
int count = 0;
|
|
|
|
for (int i = 0; i < player.RoleData.PayData.PayItemRecord.Count; i++)
|
|
{
|
|
ref var record = ref player.RoleData.PayData.PayItemRecord[i];
|
|
count += record.PaySuccessCount;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
public static int GetMonthlyCardDataIndex(PlayerOnGame player, int cardId)
|
|
{
|
|
for (int i = 0; i < player.RoleData.PayData.MonthlyCard.Count; i++)
|
|
{
|
|
ref var card = ref player.RoleData.PayData.MonthlyCard[i];
|
|
if (card.CardId == cardId)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
public static ref MonthlyCardData GetMonthlyCardDataByIndex(PlayerOnGame player, int index)
|
|
{
|
|
return ref player.RoleData.PayData.MonthlyCard[index];
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static int GetPaySuccLockIndex(PlayerOnGame player, int itemId)
|
|
{
|
|
for (int i = 0; i < player.RoleData.PayData.PaySuccLock.Count; i++)
|
|
{
|
|
if (player.RoleData.PayData.PaySuccLock[i].ItemID == itemId)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public static ref PaySuccLock GetPaySuccLockByIndex(PlayerOnGame player, int index)
|
|
{
|
|
return ref player.RoleData.PayData.PaySuccLock[index];
|
|
}
|
|
|
|
public static int CreatePaySuccLockIfNotExist(PlayerOnGame player, int itemId,
|
|
string orderId, string order3rd)
|
|
{
|
|
for (int i = 0; i < player.RoleData.PayData.PaySuccLock.Count; i++)
|
|
{
|
|
if (player.RoleData.PayData.PaySuccLock[i].ItemID.Equals(itemId))
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
if (player.RoleData.PayData.PaySuccLock.Count >= player.RoleData.PayData.PaySuccLock.GetMaxCount())
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
var lockOne = new PaySuccLock();
|
|
lockOne.ItemID = itemId;
|
|
lockOne.OrderId.SetString(orderId);
|
|
lockOne.OrderId3rd.SetString(order3rd);
|
|
|
|
player.RoleData.PayData.PaySuccLock.Add(ref lockOne);
|
|
return player.RoleData.PayData.PaySuccLock.Count - 1;
|
|
}
|
|
|
|
public static void DeletePaySuccWaitAddRole(PlayerOnGame player)
|
|
{
|
|
long nowSec = GameServerUtils.GetTimeSecond();
|
|
for (int i = player.RoleData.PayData.PaySuccWaitAddRole.Count-1; i >= 0; i--)
|
|
{
|
|
ref var item = ref player.RoleData.PayData.PaySuccWaitAddRole[i];
|
|
|
|
// 发货成功24小时后统一删除waitAddRole数据
|
|
if (item.AddItemSuccTime > 0 && (nowSec - item.AddItemSuccTime) >= 86400)
|
|
{
|
|
player.Debug("PlayerPayUtil.DeletePaySuccWaitAddRole uid {0} orderId {1} succTime {2}"
|
|
, player.UserID, item.OrderId.GetString(), item.AddItemSuccTime);
|
|
|
|
player.RoleData.PayData.PaySuccWaitAddRole.RemoveAt(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 删除最早的发货成功的waitAddRole数据
|
|
public static void DeleteEarliestPaySuccWaitAddRole(PlayerOnGame player)
|
|
{
|
|
int idx = -1;
|
|
int minTime = int.MaxValue;
|
|
for (int i = 0; i < player.RoleData.PayData.PaySuccWaitAddRole.Count; i++)
|
|
{
|
|
ref var item = ref player.RoleData.PayData.PaySuccWaitAddRole[i];
|
|
if (item.AddItemSuccTime > 0 && item.AddItemSuccTime < minTime)
|
|
{
|
|
idx = i;
|
|
minTime = item.AddItemSuccTime;
|
|
}
|
|
}
|
|
|
|
if (idx != -1)
|
|
{
|
|
ref var item = ref player.RoleData.PayData.PaySuccWaitAddRole[idx];
|
|
player.Debug("PlayerPayUtil.DeleteEarliestPaySuccWaitAddRole uid {0} orderId {1} succTime {2}"
|
|
, player.UserID, item.OrderId.GetString(), item.AddItemSuccTime);
|
|
|
|
player.RoleData.PayData.PaySuccWaitAddRole.RemoveAt(idx);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|