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