ShopProc.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * Description of ShopProc
  5. * 商城
  6. * @author gwang
  7. * @version 1.0.0 Created. 2020.8.19 -gwang
  8. */
  9. class ShopProc {
  10. /**
  11. * 逻辑分发
  12. * 所有的Proc中必须有这样一个方法
  13. */
  14. public static function procMain() {
  15. switch (req()->cmd) {
  16. case CmdCode::shop_limit_maininfo:
  17. return self::GetLimitMainInfo();
  18. case CmdCode::shop_limit_buy:
  19. return self::BuyLimitPackage();
  20. case CmdCode::shop_monthlyVIP_Info:
  21. return self::GetMonthlyVipInfo();
  22. case CmdCode::shop_monthlyVIP_Buy:
  23. return self::BuyMonthlyVip();
  24. default:
  25. Err(ErrCode::cmd_err);
  26. }
  27. }
  28. public static function GetMonthlyVipInfo() {
  29. return Resp::ok(array(
  30. "shopdata" => req()->userInfo->game->shopdata
  31. ));
  32. }
  33. public static function BuyMonthlyVip() {
  34. $packageId = req()->paras[0]; # 参数; 礼包id
  35. $shopdata = new Info_UserShop(req()->userInfo->game->shopdata);
  36. $packageCfg = GameConfig::shop_monthVIP_getItem($packageId);
  37. my_Assert(null != $packageCfg, ErrCode::err_const_no);
  38. if ($packageCfg->subType == 4) {
  39. my_Assert($shopdata->monthlyVIP1_ts + $packageCfg->ExpireTs * 3600 * 24 < now(), ErrCode::shop_monthlyvip_buyed);
  40. } elseif ($packageCfg->subType == 5) {
  41. my_Assert($shopdata->monthlyVIP2_ts + $packageCfg->ExpireTs * 3600 * 24 < now(), ErrCode::shop_monthlyvip_buyed);
  42. }
  43. $err = StoreProc::AddMultiItemInStore($packageCfg->pri_reward); # 发放一次性奖励
  44. my_Assert(ErrCode::ok == $err, $err);
  45. if ($packageCfg->subType == 4) {
  46. $shopdata->monthlyVIP1_ts = 3600 * 24 * (tsDay() + 1) - 1;
  47. } elseif ($packageCfg->subType == 5) {
  48. $shopdata->monthlyVIP2_ts = 3600 * 24 * (tsDay() + 1) - 1;
  49. }
  50. req()->userInfo->game->shopdata = $shopdata; # 回写数据
  51. UserProc::updateUserInfo();
  52. $user = req()->userInfo->game;
  53. return Resp::ok(array(
  54. "reward" => $packageCfg->pri_reward,
  55. "shopdata" => $shopdata,
  56. 'gold' => $user->baseInfo->gold,
  57. 'cash' => $user->baseInfo->cash,
  58. 'tili' => $user->baseInfo->tili,
  59. 'store' => $user->store,
  60. 'hero' => $user->heros
  61. ));
  62. }
  63. /**
  64. * 【7101】限购礼包主界面
  65. */
  66. public static function GetLimitMainInfo() {
  67. return Resp::ok(array(
  68. "shopdata" => req()->userInfo->game->shopdata
  69. ));
  70. }
  71. /**
  72. * 【7102】 购买限购礼包
  73. */
  74. public static function BuyLimitPackage() {
  75. $packageId = req()->paras[0]; # 参数; 礼包id
  76. $shopdata = new Info_UserShop(req()->userInfo->game->shopdata);
  77. $packageCfg = GameConfig::shop_limit_getItem($packageId);
  78. my_Assert(null != $packageCfg, ErrCode::err_const_no);
  79. $arr = array();
  80. switch ((int) $packageCfg->subType) {
  81. case 1:
  82. $shopdata->purchasedDailyLimitPackages[] = $packageId;
  83. $arr = $shopdata->purchasedDailyLimitPackages;
  84. break;
  85. case 2:
  86. $shopdata->purchasedWeeklyLimitPackages[] = $packageId;
  87. $arr = $shopdata->purchasedWeeklyLimitPackages;
  88. break;
  89. case 3:
  90. $shopdata->purchasedMonthlyLimitPackages[] = $packageId;
  91. $arr = $shopdata->purchasedMonthlyLimitPackages;
  92. break;
  93. default:
  94. Err(ErrCode::err_innerfault);
  95. }
  96. $hasN = count(array_filter($arr, function ($val)use ($packageId) {
  97. return $val == $packageId;
  98. }));
  99. my_Assert($hasN <= $packageCfg->limit_num, ErrCode::shop_limit_max);
  100. $itemid = explode(',', $packageCfg->reward)[0]; # 奖励礼包Id
  101. $itemMO = GameConfig::item_package_getItem($itemid);
  102. my_Assert(null != $itemMO, ErrCode::err_const_no);
  103. $err = StoreProc::AddMultiItemInStore($itemMO->contents); # 发放奖励
  104. my_Assert(ErrCode::ok == $err, $err);
  105. req()->userInfo->game->shopdata = $shopdata; # 回写数据
  106. UserProc::updateUserInfo();
  107. $user = req()->userInfo->game;
  108. return Resp::ok(array(
  109. "reward" => $itemMO->contents,
  110. "shopdata" => $shopdata,
  111. 'gold' => $user->baseInfo->gold,
  112. 'cash' => $user->baseInfo->cash,
  113. 'tili' => $user->baseInfo->tili,
  114. 'store' => $user->store,
  115. 'hero' => $user->heros
  116. ));
  117. }
  118. /**
  119. * 每日检查
  120. */
  121. static function DailyCheck() {
  122. CLog::info("shop-每日检查-清除每日/周限量礼包购买记录");
  123. $zoneid = req()->zoneid;
  124. $uid = req()->uid;
  125. $shopdata = new Info_UserShop(req()->userInfo->game->shopdata);
  126. $shopdata->purchasedDailyLimitPackages = array(); # 每天重置
  127. if (date("N") == 1) { # 周一重置
  128. $shopdata->purchasedWeeklyLimitPackages = array();
  129. }
  130. if (date("d") == 1) { # 1号重置
  131. $shopdata->purchasedMonthlyLimitPackages = array();
  132. }
  133. if ($shopdata->monthlyVIP1_ts + 30 * 24 * 3600 > now()) {
  134. $id = 901001;
  135. $card1 = GameConfig::shop_monthVIP_getItem($id);
  136. my_Assert(null != $card1, ErrCode::err_const_no);
  137. EmailProc::SendMonthlyVIPDailyReward($zoneid, $uid, $card1->name, $card1->daily_reward);
  138. }
  139. if ($shopdata->monthlyVIP2_ts + 30 * 24 * 3600 > now()) {
  140. $id = 901002;
  141. $card2 = GameConfig::shop_monthVIP_getItem($id);
  142. my_Assert(null != $card2, ErrCode::err_const_no);
  143. EmailProc::SendMonthlyVIPDailyReward($zoneid, $uid, $card2->name, $card2->daily_reward);
  144. }
  145. }
  146. }