PayProxy.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Newtonsoft.Json.Linq;
  6. using UnityEngine;
  7. /// <summary>
  8. /// 消费相关
  9. /// </summary>
  10. class PayProxy : ProxyBase<PayProxy>
  11. {
  12. #region 构造函数
  13. public PayProxy() => this.opeCode = OpeCode.ope_pay;
  14. #endregion
  15. /// <summary>
  16. /// [8802] 领取首付礼包
  17. /// </summary>
  18. /// <param name="callback">成功回调函数(参数int: 游戏币余额)</param>
  19. public void DrawFirstPayGift(Action<JObject> callback)
  20. {
  21. Post(CmdCode.cmd_mpay_drawFirstPayGift, new object[] { }, resp => callback?.Invoke(resp.result));
  22. }
  23. /// <summary>
  24. /// [8808] 查询账号游戏币余额
  25. /// </summary>
  26. /// <param name="callback">成功回调函数(参数int: 游戏币余额)</param>
  27. public void GetBalance(string cporderid, Action<JObject> callback)
  28. {
  29. Post(CmdCode.cmd_mpay_get_balance, new object[] { cporderid }, resp => callback?.Invoke(resp.result));
  30. }
  31. /// <summary>
  32. /// [8807] 购买商城物品
  33. /// /// 返回值: array(# # 成功后将最新的玩家数据返回给客户端
  34. ///'gold' => $user->gold,
  35. ///'tili' => $user->tili,
  36. ///'cash' => $user->cash,
  37. //));
  38. /// </summary>
  39. public void Shop_BuyItem(int paytype, int itemid, int num, Action<JObject> callback)
  40. {
  41. Post(CmdCode.cmd_mpay_pay, new object[] { paytype, itemid, num }, resp => callback?.Invoke(resp.result));
  42. }
  43. /// <summary>
  44. /// [8809] [动态商城] 购买物品
  45. /// 返回值: array(# # 成功后将最新的玩家数据返回给客户端
  46. //'gold' => $user->gold,
  47. //'tili' => $user->tili,
  48. //'cash' => $user->cash,
  49. //'uss' => $userSecretshop, # # 当前神秘商城数据 <UserSecretShopDataStruct>
  50. //));
  51. /// </summary>
  52. [Obsolete]
  53. public void SecretShop_BuyItem(int itemid, Action<JObject> callback)
  54. {
  55. Post(CmdCode.cmd_mpay_buySecretShopItem, new object[] { itemid }, resp => callback?.Invoke(resp.result));
  56. }
  57. /// <summary>
  58. /// [8810] 动态商城 - 获取商品列表
  59. /// 返回值: array(# # 成功后将最新的玩家数据返回给客户端
  60. ///'gold' => $user->gold,
  61. ///'tili' => $user->tili,
  62. ///'cash' => $user->cash,
  63. ///'uss' => $userSecretshop, # # 当前神秘商城数据 UserSecretShopDataStruct
  64. ///));
  65. /// </summary>
  66. ///<param name="type">0 不刷 1是免费刷 2 钻石刷</param>
  67. public void SecretShop_GetItems(int type, Action<JObject> callback)
  68. {
  69. Post(CmdCode.cmd_mpay_getSecretShopItems, new object[] { type }, resp => callback?.Invoke(resp.result));
  70. }
  71. /// <summary>
  72. /// 获取充值信息
  73. /// </summary>
  74. /// <returns></returns>
  75. public List<RechargeVo> GetRecharge()
  76. {
  77. List<RechargeVo> list = new List<RechargeVo>();
  78. Dictionary<int, sm_recharge> recharge = GameConfigData.Ins.recharge;
  79. foreach (KeyValuePair<int, sm_recharge> kv in recharge)
  80. {
  81. RechargeVo vo = new RechargeVo(kv.Key);
  82. list.Add(vo);
  83. }
  84. return list;
  85. }
  86. /// <summary>
  87. /// [8813] 充值
  88. /// </summary>
  89. /// <param name="cpOrderId"></param>
  90. /// <param name="callback"></param>
  91. public void PayDeliverGoods(long cpOrderId, Action<List<ItemVo>> callback)
  92. {
  93. Post(CmdCode.cmd_mpay_PayDeliverGoods, new object[] { cpOrderId }, resp =>
  94. {
  95. var p = UserProxy.Instance.player;
  96. p.InitFromStore((JObject)resp.result["store"]);
  97. p.baseInfo = resp.result["base"].ToObject<Info_UserBase>();
  98. p.shopdata = resp.result["shopdata"].ToObject<Info_UserShop>();
  99. p.payInfo.Initlize(resp.result["pay"]);
  100. List<ItemVo> list = new List<ItemVo>();
  101. if (resp.result["ret"].ToString() != "")
  102. {
  103. JArray jprizeArr = JArray.Parse(resp.result["ret"].ToString());
  104. foreach (JToken item in jprizeArr)
  105. {
  106. //List<ItemVo> list = ItemVo.ParsItemContentStr(item.ToString());
  107. string[] arr = item.ToString().Split(';');
  108. foreach (string n in arr)
  109. {
  110. string[] ctx = n.Split(',');
  111. ItemVo vo = new ItemVo();
  112. vo.typeId = ctx[0];
  113. vo.count = int.Parse(ctx[1]);
  114. list.Add(vo);
  115. }
  116. }
  117. }
  118. callback?.Invoke(list);
  119. });
  120. }
  121. /// <summary>
  122. /// [8814] 充值奖励领取
  123. /// </summary>
  124. /// <param name="callback"></param>
  125. public void UserRechargeDrawPrize(Enum_Recharge type, int typeId, Action<List<ItemVo>> callback)
  126. {
  127. UserRechargeDrawPrize(type, typeId.ToString(), callback);
  128. }
  129. /// <summary>
  130. /// [8814] 充值奖励领取
  131. /// </summary>
  132. /// <param name="callback"></param>
  133. public void UserRechargeDrawPrize(Enum_Recharge type, string typeId, Action<List<ItemVo>> callback)
  134. {
  135. Post(CmdCode.cmd_mpay_UserRechargeDrawPrize, new object[] { type, typeId }, resp =>
  136. {
  137. var p = UserProxy.Instance.player;
  138. p.InitFromStore((JObject)resp.result["store"]);
  139. p.shopdata = resp.result.TryGetValue("shopdata", out var jo) ? jo.ToObject<Info_UserShop>() : new Info_UserShop();
  140. p.baseInfo = resp.result["base"].ToObject<Info_UserBase>();
  141. p.payInfo.Initlize(resp.result["pay"]);
  142. List<ItemVo> list = new List<ItemVo>();
  143. if (resp.result["ret"].ToString() != "")
  144. {
  145. JArray jprizeArr = JArray.Parse(resp.result["ret"].ToString());
  146. foreach (JToken item in jprizeArr)
  147. {
  148. //List<ItemVo> list = ItemVo.ParsItemContentStr(item.ToString());
  149. string[] arr = item.ToString().Split(';');
  150. foreach (string n in arr)
  151. {
  152. string[] ctx = n.Split(',');
  153. ItemVo vo = new ItemVo();
  154. vo.typeId = ctx[0];
  155. vo.count = int.Parse(ctx[1]);
  156. list.Add(vo);
  157. }
  158. }
  159. }
  160. callback?.Invoke(list);
  161. });
  162. }
  163. /// <summary>
  164. /// 获取首冲界面信息
  165. /// </summary>
  166. /// <param name="callback"></param>
  167. public void GetShopAccumulateInfoVo(CallBack<ShopAccumulateUI> callback)
  168. {
  169. Post(CmdCode.cmd_mpay_NewFirstRecharge, new object[] {}, resp =>
  170. {
  171. //var p = UserProxy.Instance.player;
  172. //p.InitFromStore((JObject)resp.result["store"]);
  173. //p.shopdata = resp.result.TryGetValue("shopdata", out var jo) ? jo.ToObject<Info_UserShop>() : new Info_UserShop();
  174. //p.baseInfo = resp.result["base"].ToObject<Info_UserBase>();
  175. //p.payInfo.Initlize(resp.result["pay"]);
  176. int curTs = resp.ts;
  177. callback?.Invoke(new ShopAccumulateUI(curTs));
  178. });
  179. }
  180. #region 数据结构定义
  181. /// <summary>
  182. /// 首充功能接口 【原来是累充的接口改成首充了】
  183. /// </summary>
  184. public class ShopAccumulateUI
  185. {
  186. public ShopAccumulateUI(int ts)
  187. {
  188. PayProxy.ShopAccumulateUI.curTs = ts;
  189. }
  190. /// <summary>
  191. /// 玩家数据引用
  192. /// </summary>
  193. private static Player p => UserProxy.Instance.player;
  194. /// <summary>
  195. /// 当前时间
  196. /// </summary>
  197. public static int curTs { get; set; }
  198. public List<TabByDay> Tabs = new List<int> { 1, 2, 3 }.ConvertAll(x => new TabByDay(x));
  199. public class TabByDay
  200. {
  201. public TabByDay(int day)
  202. {
  203. Day = day;
  204. }
  205. public int Day { get; private set; }
  206. public List<Card> Cards
  207. {
  208. get
  209. {
  210. List<Card> list = new List<Card>();
  211. Dictionary<int, sm_shop_accumulating> shop_accumulating = GameConfigData.Ins.shop_accumulating;
  212. foreach (KeyValuePair<int,sm_shop_accumulating>kv in shop_accumulating)
  213. {
  214. if (kv.Value.day == this.Day)
  215. {
  216. Card vo = new Card(kv.Value);
  217. list.Add(vo);
  218. }
  219. }
  220. return list;
  221. }
  222. }
  223. /// <summary>
  224. /// 是否有可以领取的奖励 true:有
  225. /// </summary>
  226. public bool HasNewReward => Cards.Exists(card => card.CanGet);
  227. }
  228. public class Card
  229. {
  230. public Card(sm_shop_accumulating mo)
  231. {
  232. this.Mo = mo;
  233. }
  234. /// <summary>
  235. /// 礼包金额()
  236. /// </summary>
  237. public int amount
  238. {
  239. get
  240. {
  241. return this.Mo.amount;
  242. }
  243. }
  244. public string productname
  245. {
  246. get
  247. {
  248. return this.Mo.name;
  249. }
  250. }
  251. public string productdesc
  252. {
  253. get
  254. {
  255. return this.Mo.desc;
  256. }
  257. }
  258. /// <summary>
  259. /// 礼包typeId
  260. /// </summary>
  261. public string TypeId
  262. {
  263. get
  264. {
  265. return this.Mo.typeId.ToString();
  266. }
  267. }
  268. /// <summary>
  269. /// 道具列表,(第一个大图标)
  270. /// </summary>
  271. public List<ItemVo> items => ItemVo.ParsItemContentStr(Mo.goods);
  272. /// <summary>
  273. /// 是否已经领取 true:已经领取
  274. /// </summary>
  275. public bool HasGeted
  276. {
  277. get
  278. {
  279. bool tag = false;
  280. Dictionary<int, List<int>> fRechargeRecord = p.shopdata.fRechargeRecord;
  281. foreach (KeyValuePair<int,List<int>>kv in fRechargeRecord)
  282. {
  283. if (kv.Value.Contains(int.Parse(this.TypeId)))
  284. {
  285. tag = true;
  286. break;
  287. }
  288. }
  289. return tag;
  290. }
  291. }
  292. /// <summary>
  293. /// 是否可以领取 true:可以; false:不可以
  294. /// </summary>
  295. public bool CanGet
  296. {
  297. get
  298. {
  299. int amcount = this.Mo.amount;
  300. //是否充值过该档位的
  301. if (!p.shopdata.fRechargeTime.ContainsKey(amcount))
  302. {
  303. return false;
  304. }
  305. //校验是否已经领取
  306. Dictionary<int, List<int>> fRechargeRecord = p.shopdata.fRechargeRecord;
  307. if (fRechargeRecord.ContainsKey(amcount) && fRechargeRecord[amcount].Contains(int.Parse(this.TypeId)))
  308. {
  309. return false;
  310. }
  311. //查看当前时间是否允许购买
  312. int buyDay = p.shopdata.fRechargeTime[amcount];
  313. int ts = Card.tsDay() - buyDay;
  314. if (ts + 1 < this.Mo.day)
  315. {
  316. return false;
  317. }
  318. long t = PayProxy.ShopAccumulateUI.curTs;
  319. int hour = DateTimeOffset.FromUnixTimeSeconds(t).Hour;
  320. if (hour < 5 && this.Mo.day > 1)//5点之后领取
  321. {
  322. return false;
  323. }
  324. return true;
  325. }
  326. }
  327. /// <summary>
  328. /// 是否可以购买 true:可以买
  329. /// </summary>
  330. public bool CanBuy
  331. {
  332. get
  333. {
  334. int amcount = this.Mo.amount;
  335. //是否充值过该档位的
  336. if (p.shopdata.fRechargeTime.ContainsKey(amcount))
  337. {
  338. return false;
  339. }
  340. return true;
  341. }
  342. }
  343. /// <summary>
  344. /// 时间戳转成天
  345. /// </summary>
  346. /// <returns></returns>
  347. private static int tsDay()
  348. {
  349. return (int)((DateTimeOffset.Now.ToUnixTimeSeconds() + 28800) / 86400);
  350. }
  351. private sm_shop_accumulating Mo { get; set; }
  352. }
  353. }
  354. /// <summary>
  355. /// 首充功能接口
  356. /// </summary>
  357. public class ShopAccumulateUI_old
  358. {
  359. /// <summary>
  360. /// 玩家数据引用
  361. /// </summary>
  362. private static Player p => UserProxy.Instance.player;
  363. /// <summary>
  364. /// 商城模块底层数据
  365. /// </summary>
  366. private static Ins_ShopAccumulate Acc => p.shopdata.shopAccumulateData;
  367. public List<TabByDay> Tabs = new List<int> { 1, 2, 3 }.ConvertAll(x => new TabByDay(x));
  368. public class TabByDay
  369. {
  370. public TabByDay(int day)
  371. {
  372. Day = day;
  373. }
  374. public int Day { get; private set; }
  375. public List<Card> Cards => Ins_ShopAccumulate.amountLst.ConvertAll(amt => new Card(amt, Day));
  376. /// <summary>
  377. /// 是否有可以领取的奖励
  378. /// </summary>
  379. public bool HasNewReward => Cards.Exists(card => card.CanGet);
  380. }
  381. /// <summary>
  382. /// 卡片
  383. /// </summary>
  384. public class Card
  385. {
  386. /// <summary>
  387. /// 时间戳转成天
  388. /// </summary>
  389. /// <returns></returns>
  390. private static int tsDay()
  391. {
  392. return (int)((DateTimeOffset.Now.ToUnixTimeSeconds() + 28800) / 86400);
  393. }
  394. /// <summary>
  395. /// 道具列表,(第一个大图标)*
  396. /// </summary>
  397. public List<ItemVo> items => ItemVo.ParsItemContentStr(Mo.goods);
  398. /// <summary>
  399. /// 是否已经领取
  400. /// </summary>
  401. public bool HasGeted => Acc.IsDrawed(_amount, _day);
  402. /// <summary>
  403. /// 是否可以领取*
  404. /// </summary>
  405. public bool CanGet
  406. {
  407. get
  408. {
  409. return true;
  410. }
  411. }
  412. private sm_shop_accumulating Mo
  413. {
  414. get
  415. {
  416. return null;
  417. }
  418. }
  419. /// <summary>
  420. /// 点击后领取接口的typeid取这个值.
  421. /// </summary>
  422. public string TypeId => $"{_amount}-{_day}";
  423. public Card(int amount, int day)
  424. {
  425. _amount = amount;
  426. _day = day;
  427. }
  428. private int _amount;
  429. private int _day;
  430. }
  431. }
  432. #endregion
  433. }
  434. #region 数据结构定义
  435. /// <summary>
  436. /// 玩家神秘商城数据
  437. /// </summary>
  438. public class UserSecretShopDataStruct
  439. {
  440. /// <summary>
  441. /// @var object {itemid:cishu,itemid:cishu,...} 当前商品列表
  442. /// </summary>
  443. public Dictionary<int, int> currentItems;
  444. /// <summary>
  445. /// @var int 上次刷新时间戳
  446. /// </summary>
  447. public int lastRefreshTs = 0;
  448. /// <summary>
  449. /// @var int 当天付费刷新次数
  450. /// </summary>
  451. public int refreshedTimes = 0;
  452. }
  453. #endregion