using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using UnityEngine;
///
/// 消费相关
///
class PayProxy : ProxyBase
{
#region 构造函数
public PayProxy() => this.opeCode = OpeCode.ope_pay;
#endregion
///
/// [8802] 领取首付礼包
///
/// 成功回调函数(参数int: 游戏币余额)
public void DrawFirstPayGift(Action callback)
{
Post(CmdCode.cmd_mpay_drawFirstPayGift, new object[] { }, resp => callback?.Invoke(resp.result));
}
///
/// [8808] 查询账号游戏币余额
///
/// 成功回调函数(参数int: 游戏币余额)
public void GetBalance(string cporderid, Action callback)
{
Post(CmdCode.cmd_mpay_get_balance, new object[] { cporderid }, resp => callback?.Invoke(resp.result));
}
///
/// [8807] 购买商城物品
/// /// 返回值: array(# # 成功后将最新的玩家数据返回给客户端
///'gold' => $user->gold,
///'tili' => $user->tili,
///'cash' => $user->cash,
//));
///
public void Shop_BuyItem(int paytype, int itemid, int num, Action callback)
{
Post(CmdCode.cmd_mpay_pay, new object[] { paytype, itemid, num }, resp => callback?.Invoke(resp.result));
}
///
/// [8809] [动态商城] 购买物品
/// 返回值: array(# # 成功后将最新的玩家数据返回给客户端
//'gold' => $user->gold,
//'tili' => $user->tili,
//'cash' => $user->cash,
//'uss' => $userSecretshop, # # 当前神秘商城数据
//));
///
[Obsolete]
public void SecretShop_BuyItem(int itemid, Action callback)
{
Post(CmdCode.cmd_mpay_buySecretShopItem, new object[] { itemid }, resp => callback?.Invoke(resp.result));
}
///
/// [8810] 动态商城 - 获取商品列表
/// 返回值: array(# # 成功后将最新的玩家数据返回给客户端
///'gold' => $user->gold,
///'tili' => $user->tili,
///'cash' => $user->cash,
///'uss' => $userSecretshop, # # 当前神秘商城数据 UserSecretShopDataStruct
///));
///
///0 不刷 1是免费刷 2 钻石刷
public void SecretShop_GetItems(int type, Action callback)
{
Post(CmdCode.cmd_mpay_getSecretShopItems, new object[] { type }, resp => callback?.Invoke(resp.result));
}
///
/// 获取充值信息
///
///
public List GetRecharge()
{
List list = new List();
Dictionary recharge = GameConfigData.Ins.recharge;
foreach (KeyValuePair kv in recharge)
{
RechargeVo vo = new RechargeVo(kv.Key);
list.Add(vo);
}
return list;
}
///
/// [8813] 充值
///
///
///
public void PayDeliverGoods(long cpOrderId, Action> callback)
{
Post(CmdCode.cmd_mpay_PayDeliverGoods, new object[] { cpOrderId }, resp =>
{
var p = UserProxy.Instance.player;
p.InitFromStore((JObject)resp.result["store"]);
p.baseInfo = resp.result["base"].ToObject();
p.shopdata = resp.result["shopdata"].ToObject();
p.payInfo.Initlize(resp.result["pay"]);
List list = new List();
if (resp.result["ret"].ToString() != "")
{
JArray jprizeArr = JArray.Parse(resp.result["ret"].ToString());
foreach (JToken item in jprizeArr)
{
//List list = ItemVo.ParsItemContentStr(item.ToString());
string[] arr = item.ToString().Split(';');
foreach (string n in arr)
{
string[] ctx = n.Split(',');
ItemVo vo = new ItemVo();
vo.typeId = ctx[0];
vo.count = int.Parse(ctx[1]);
list.Add(vo);
}
}
}
callback?.Invoke(list);
});
}
///
/// [8814] 充值奖励领取
///
///
public void UserRechargeDrawPrize(Enum_Recharge type, int typeId, Action> callback)
{
UserRechargeDrawPrize(type, typeId.ToString(), callback);
}
///
/// [8814] 充值奖励领取
///
///
public void UserRechargeDrawPrize(Enum_Recharge type, string typeId, Action> callback)
{
Post(CmdCode.cmd_mpay_UserRechargeDrawPrize, new object[] { type, typeId }, resp =>
{
var p = UserProxy.Instance.player;
p.InitFromStore((JObject)resp.result["store"]);
p.shopdata = resp.result.TryGetValue("shopdata", out var jo) ? jo.ToObject() : new Info_UserShop();
p.baseInfo = resp.result["base"].ToObject();
p.payInfo.Initlize(resp.result["pay"]);
List list = new List();
if (resp.result["ret"].ToString() != "")
{
JArray jprizeArr = JArray.Parse(resp.result["ret"].ToString());
foreach (JToken item in jprizeArr)
{
//List list = ItemVo.ParsItemContentStr(item.ToString());
string[] arr = item.ToString().Split(';');
foreach (string n in arr)
{
string[] ctx = n.Split(',');
ItemVo vo = new ItemVo();
vo.typeId = ctx[0];
vo.count = int.Parse(ctx[1]);
list.Add(vo);
}
}
}
callback?.Invoke(list);
});
}
///
/// 获取首冲界面信息
///
///
public void GetShopAccumulateInfoVo(CallBack callback)
{
Post(CmdCode.cmd_mpay_NewFirstRecharge, new object[] {}, resp =>
{
//var p = UserProxy.Instance.player;
//p.InitFromStore((JObject)resp.result["store"]);
//p.shopdata = resp.result.TryGetValue("shopdata", out var jo) ? jo.ToObject() : new Info_UserShop();
//p.baseInfo = resp.result["base"].ToObject();
//p.payInfo.Initlize(resp.result["pay"]);
int curTs = resp.ts;
callback?.Invoke(new ShopAccumulateUI(curTs));
});
}
#region 数据结构定义
///
/// 首充功能接口 【原来是累充的接口改成首充了】
///
public class ShopAccumulateUI
{
public ShopAccumulateUI(int ts)
{
PayProxy.ShopAccumulateUI.curTs = ts;
}
///
/// 玩家数据引用
///
private static Player p => UserProxy.Instance.player;
///
/// 当前时间
///
public static int curTs { get; set; }
public List Tabs = new List { 1, 2, 3 }.ConvertAll(x => new TabByDay(x));
public class TabByDay
{
public TabByDay(int day)
{
Day = day;
}
public int Day { get; private set; }
public List Cards
{
get
{
List list = new List();
Dictionary shop_accumulating = GameConfigData.Ins.shop_accumulating;
foreach (KeyValuePairkv in shop_accumulating)
{
if (kv.Value.day == this.Day)
{
Card vo = new Card(kv.Value);
list.Add(vo);
}
}
return list;
}
}
///
/// 是否有可以领取的奖励 true:有
///
public bool HasNewReward => Cards.Exists(card => card.CanGet);
}
public class Card
{
public Card(sm_shop_accumulating mo)
{
this.Mo = mo;
}
///
/// 礼包金额()
///
public int amount
{
get
{
return this.Mo.amount;
}
}
public string productname
{
get
{
return this.Mo.name;
}
}
public string productdesc
{
get
{
return this.Mo.desc;
}
}
///
/// 礼包typeId
///
public string TypeId
{
get
{
return this.Mo.typeId.ToString();
}
}
///
/// 道具列表,(第一个大图标)
///
public List items => ItemVo.ParsItemContentStr(Mo.goods);
///
/// 是否已经领取 true:已经领取
///
public bool HasGeted
{
get
{
bool tag = false;
Dictionary> fRechargeRecord = p.shopdata.fRechargeRecord;
foreach (KeyValuePair>kv in fRechargeRecord)
{
if (kv.Value.Contains(int.Parse(this.TypeId)))
{
tag = true;
break;
}
}
return tag;
}
}
///
/// 是否可以领取 true:可以; false:不可以
///
public bool CanGet
{
get
{
int amcount = this.Mo.amount;
//是否充值过该档位的
if (!p.shopdata.fRechargeTime.ContainsKey(amcount))
{
return false;
}
//校验是否已经领取
Dictionary> fRechargeRecord = p.shopdata.fRechargeRecord;
if (fRechargeRecord.ContainsKey(amcount) && fRechargeRecord[amcount].Contains(int.Parse(this.TypeId)))
{
return false;
}
//查看当前时间是否允许购买
int buyDay = p.shopdata.fRechargeTime[amcount];
int ts = Card.tsDay() - buyDay;
if (ts + 1 < this.Mo.day)
{
return false;
}
long t = PayProxy.ShopAccumulateUI.curTs;
int hour = DateTimeOffset.FromUnixTimeSeconds(t).Hour;
if (hour < 5 && this.Mo.day > 1)//5点之后领取
{
return false;
}
return true;
}
}
///
/// 是否可以购买 true:可以买
///
public bool CanBuy
{
get
{
int amcount = this.Mo.amount;
//是否充值过该档位的
if (p.shopdata.fRechargeTime.ContainsKey(amcount))
{
return false;
}
return true;
}
}
///
/// 时间戳转成天
///
///
private static int tsDay()
{
return (int)((DateTimeOffset.Now.ToUnixTimeSeconds() + 28800) / 86400);
}
private sm_shop_accumulating Mo { get; set; }
}
}
///
/// 首充功能接口
///
public class ShopAccumulateUI_old
{
///
/// 玩家数据引用
///
private static Player p => UserProxy.Instance.player;
///
/// 商城模块底层数据
///
private static Ins_ShopAccumulate Acc => p.shopdata.shopAccumulateData;
public List Tabs = new List { 1, 2, 3 }.ConvertAll(x => new TabByDay(x));
public class TabByDay
{
public TabByDay(int day)
{
Day = day;
}
public int Day { get; private set; }
public List Cards => Ins_ShopAccumulate.amountLst.ConvertAll(amt => new Card(amt, Day));
///
/// 是否有可以领取的奖励
///
public bool HasNewReward => Cards.Exists(card => card.CanGet);
}
///
/// 卡片
///
public class Card
{
///
/// 时间戳转成天
///
///
private static int tsDay()
{
return (int)((DateTimeOffset.Now.ToUnixTimeSeconds() + 28800) / 86400);
}
///
/// 道具列表,(第一个大图标)*
///
public List items => ItemVo.ParsItemContentStr(Mo.goods);
///
/// 是否已经领取
///
public bool HasGeted => Acc.IsDrawed(_amount, _day);
///
/// 是否可以领取*
///
public bool CanGet
{
get
{
return true;
}
}
private sm_shop_accumulating Mo
{
get
{
return null;
}
}
///
/// 点击后领取接口的typeid取这个值.
///
public string TypeId => $"{_amount}-{_day}";
public Card(int amount, int day)
{
_amount = amount;
_day = day;
}
private int _amount;
private int _day;
}
}
#endregion
}
#region 数据结构定义
///
/// 玩家神秘商城数据
///
public class UserSecretShopDataStruct
{
///
/// @var object {itemid:cishu,itemid:cishu,...} 当前商品列表
///
public Dictionary currentItems;
///
/// @var int 上次刷新时间戳
///
public int lastRefreshTs = 0;
///
/// @var int 当天付费刷新次数
///
public int refreshedTimes = 0;
}
#endregion